Documentation ¶
Overview ¶
Package xfmt provides addons to std fmt and strconv packages with focus on formatting text without allocations.
For example if in fmt speak you have
s := fmt.Sprintf("hello %q %d %x", "world", 1, []byte("data"))
xfmt analog would be
buf := xfmt.Buffer{} buf .S("hello ") .Q("world") .C(' ') .D(1) .C(' ') .Xb([]byte("data")) s := buf.Bytes()
xfmt.Buffer can be reused several times via Buffer.Reset() .
Index ¶
- func Append(b []byte, x Stringer) []byte
- func AppendHex(b []byte, x []byte) []byte
- func AppendHex016(b []byte, x uint64) []byte
- func AppendQuotePy(buf []byte, s string) []byte
- func AppendQuotePyBytes(buf, b []byte) []byte
- func AppendRune(b []byte, r rune) []byte
- type Buffer
- func (b Buffer) Bytes() []byte
- func (b *Buffer) C(r rune) *Buffer
- func (b *Buffer) Cb(c byte) *Buffer
- func (b *Buffer) D(i int) *Buffer
- func (b *Buffer) D64(i int64) *Buffer
- func (b *Buffer) Q(s string) *Buffer
- func (b *Buffer) Qb(s []byte) *Buffer
- func (b *Buffer) Qc(c rune) *Buffer
- func (b *Buffer) Qcb(c byte) *Buffer
- func (b *Buffer) Qpy(s string) *Buffer
- func (b *Buffer) Qpyb(x []byte) *Buffer
- func (b *Buffer) Qpycb(c byte) *Buffer
- func (b *Buffer) Reset()
- func (b *Buffer) S(s string) *Buffer
- func (b *Buffer) Sb(x []byte) *Buffer
- func (b *Buffer) V(x Stringer) *Buffer
- func (b *Buffer) X(i int) *Buffer
- func (b *Buffer) X016(x uint64) *Buffer
- func (b *Buffer) Xb(x []byte) *Buffer
- func (b *Buffer) Xs(x string) *Buffer
- type Stringer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Append ¶
Append appends to b formatted x.
NOTE sadly since x is interface it makes real value substituted to it
escape to heap (not so a problem since usually they already are) but then also if x has non-pointer receiver convT2I _allocates_ memory for the value copy. -> always pass to append &object, even if object has non-pointer XFmtString receiver.
func AppendHex016 ¶
AppendHex016 appends to b x formatted 16-character hex string.
func AppendQuotePy ¶
AppendQuotePy appends to buf Python quoting of s.
func AppendQuotePyBytes ¶
AppendQuotePyBytes appends to buf Python quoting of b.
func AppendRune ¶
AppendRune appends to b UTF-8 encoding of r.
Types ¶
type Buffer ¶
type Buffer []byte
Buffer provides syntactic sugar for formatting mimicking fmt.Printf style.
XXX combine with bytes.Buffer ?
func (*Buffer) Reset ¶
func (b *Buffer) Reset()
Reset empties the buffer keeping underlying storage for future formattings.