go123: lab.nexedi.com/kirr/go123/xfmt Index | Files

package xfmt

import "lab.nexedi.com/kirr/go123/xfmt"

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() .


Package Files

fmt.go python.go

func Append Uses

func Append(b []byte, x Stringer) []byte

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 AppendHex Uses

func AppendHex(b []byte, x []byte) []byte

AppendHex appends to b hex representation of x.

func AppendHex016 Uses

func AppendHex016(b []byte, x uint64) []byte

AppendHex016 appends to b x formatted 16-character hex string.

func AppendQuotePy Uses

func AppendQuotePy(buf []byte, s string) []byte

AppendQuotePy appends to buf Python quoting of s.

func AppendQuotePyBytes Uses

func AppendQuotePyBytes(buf, b []byte) []byte

AppendQuotePyBytes appends to buf Python quoting of b.

func AppendRune Uses

func AppendRune(b []byte, r rune) []byte

AppendRune appends to b UTF-8 encoding of r.

type Buffer Uses

type Buffer []byte

Buffer provides syntactic sugar for formatting mimicking fmt.Printf style.

XXX combine with bytes.Buffer ?

func (Buffer) Bytes Uses

func (b Buffer) Bytes() []byte

Bytes returns buffer storage as []byte.

func (*Buffer) C Uses

func (b *Buffer) C(r rune) *Buffer

C appends rune formatted by %c.

func (*Buffer) Cb Uses

func (b *Buffer) Cb(c byte) *Buffer

Cb appends byte formatted by %c.

func (*Buffer) D Uses

func (b *Buffer) D(i int) *Buffer

D appends int formatted by %d.

func (*Buffer) D64 Uses

func (b *Buffer) D64(i int64) *Buffer

D64 appends int64 formatted by %d.

func (*Buffer) Q Uses

func (b *Buffer) Q(s string) *Buffer

Q appends string formatted by %q.

func (*Buffer) Qb Uses

func (b *Buffer) Qb(s []byte) *Buffer

Qb appends []byte formatted by %q.

func (*Buffer) Qc Uses

func (b *Buffer) Qc(c rune) *Buffer

Qc appends rune formatted by %q.

func (*Buffer) Qcb Uses

func (b *Buffer) Qcb(c byte) *Buffer

Qcb appends byte formatted by %q.

func (*Buffer) Qpy Uses

func (b *Buffer) Qpy(s string) *Buffer

Qpy appends string quoted as Python would do.

func (*Buffer) Qpyb Uses

func (b *Buffer) Qpyb(x []byte) *Buffer

Qpyb appends []byte quoted as Python would do.

func (*Buffer) Qpycb Uses

func (b *Buffer) Qpycb(c byte) *Buffer

Qpycb appends byte quoted as Python would do for a single-character string.

func (*Buffer) Reset Uses

func (b *Buffer) Reset()

Reset empties the buffer keeping underlying storage for future formattings.

func (*Buffer) S Uses

func (b *Buffer) S(s string) *Buffer

S appends string formatted by %s.

func (*Buffer) Sb Uses

func (b *Buffer) Sb(x []byte) *Buffer

Sb appends []byte formatted by %s.

func (*Buffer) V Uses

func (b *Buffer) V(x Stringer) *Buffer

V, similarly to %v, adds x formatted by default rules.

func (*Buffer) X Uses

func (b *Buffer) X(i int) *Buffer

X appends int formatted by %x.

func (*Buffer) X016 Uses

func (b *Buffer) X016(x uint64) *Buffer

X016, similarly to %016x, adds hex representation of uint64 x.

func (*Buffer) Xb Uses

func (b *Buffer) Xb(x []byte) *Buffer

Xb appends []byte formatted by %x.

func (*Buffer) Xs Uses

func (b *Buffer) Xs(x string) *Buffer

Xs appends string formatted by %x.

type Stringer Uses

type Stringer interface {
    // XFmtString method is used to append formatted value to destination buffer
    // The grown buffer have to be returned
    XFmtString(b []byte) []byte

Stringer is interface for natively formatting a value representation via xfmt.

Package xfmt imports 5 packages (graph) and is imported by 3 packages. Updated 2020-07-07. Refresh now. Tools for package owners.