tfmt

package module
v0.0.0-...-7da52ca Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 31, 2025 License: Apache-2.0 Imports: 4 Imported by: 0

README

Typed String Formatter

tfmt is like strings.Builder with typed methods for formatting builtin datatypes, making it much faster than fmt.Printf (benchmark results pending).

Usage:

import "fmt"
import "github.com/dmgard/tfmt"

func main() {
	f := tfmt.Fmt()
	
	f.Str("Let's print some integers: ")
	
	for i := range 10 {
		f.Int(i).Str(", ")
	}
	
	f.TrimRight(", ")
	
	fmt.Println(f.String())
}

Also has some helpful features for nested indentation:


f.Str("type someType struct {").Indent().Ln().
	Str("field1 type1").Ln().
	Str("field2 type2").Ln().
	Str("field3 type3")
f.OutdentLn().Str("}")

fmt.Println(f.String())

prints

type someType struct {
	field1 type1
	field2 type2
	field3 type3
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Tabs

func Tabs[I constraints.Integer](n I) string

Types

type ErrFmt

type ErrFmt Formatter

func (ErrFmt) Error

func (f ErrFmt) Error() string

type FmtMaybe

type FmtMaybe []*Formatter

func (FmtMaybe) MustUnwrap

func (f FmtMaybe) MustUnwrap() *Formatter

type FmtMaybeRecvr

type FmtMaybeRecvr interface {
	Fmt(...*Formatter) *Formatter
}

type FmtRecvr

type FmtRecvr interface {
	Fmt(*Formatter) *Formatter
}

type Fmter

type Fmter interface {
	Fmt(*Formatter)
	Parse(*Formatter)
}

type FmterSlice

type FmterSlice []Fmter

func (FmterSlice) Fmter

func (f FmterSlice) Fmter(i int) Fmter

type Fmters

type Fmters interface {
	Fmter(int) Fmter
}

type Formatter

type Formatter struct {
	FloatFmt  byte
	FloatPrec int
	// contains filtered or unexported fields
}

func Fmt

func Fmt() *Formatter

func Int

func Int[T ~int | ~int8 | ~int16 | ~int32 | ~int64](f *Formatter, i T) *Formatter

func Uint

func Uint[T ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64](f *Formatter, i T) *Formatter

func (*Formatter) Bool

func (f *Formatter) Bool(a bool) *Formatter

func (*Formatter) Buf

func (f *Formatter) Buf() []byte

func (*Formatter) Byte

func (f *Formatter) Byte(a byte) *Formatter

func (*Formatter) Bytes

func (f *Formatter) Bytes(a []byte) *Formatter

func (*Formatter) Clear

func (f *Formatter) Clear() *Formatter

func (*Formatter) Cln

func (f *Formatter) Cln() *Formatter

func (*Formatter) Clone

func (f *Formatter) Clone(g *Formatter)

func (*Formatter) ContainsRune

func (f *Formatter) ContainsRune(r rune) bool

func (*Formatter) Delete

func (f *Formatter) Delete(at, len int) *Formatter

func (*Formatter) Equals

func (f *Formatter) Equals(g *Formatter) bool

func (*Formatter) F32

func (f *Formatter) F32(a float32) *Formatter

func (*Formatter) F32f

func (f *Formatter) F32f(a float32, fmt byte, prec int) *Formatter

func (*Formatter) F64

func (f *Formatter) F64(a float64) *Formatter

func (*Formatter) F64f

func (f *Formatter) F64f(a float64, fmt byte, prec int) *Formatter

func (*Formatter) Fatalf

func (f *Formatter) Fatalf(fmt string, a ...interface{})

func (*Formatter) Fi

func (f *Formatter) Fi(b bool) *Formatter

func (*Formatter) Fmter

func (f *Formatter) Fmter(r interface{}) *Formatter

func (*Formatter) Free

func (f *Formatter) Free()

func (*Formatter) I8

func (f *Formatter) I8(a int8) *Formatter

func (*Formatter) I16

func (f *Formatter) I16(a int16) *Formatter

func (*Formatter) I32

func (f *Formatter) I32(a int32) *Formatter

func (*Formatter) I64

func (f *Formatter) I64(a int64) *Formatter

func (*Formatter) If

func (f *Formatter) If() *Formatter

func (*Formatter) Indent

func (f *Formatter) Indent() *Formatter

func (*Formatter) IndentSpaces

func (f *Formatter) IndentSpaces(n int) *Formatter

func (*Formatter) IndentTabs

func (f *Formatter) IndentTabs(n int) *Formatter

func (*Formatter) IndentTo

func (f *Formatter) IndentTo(depth int) *Formatter

func (*Formatter) InsertBytes

func (f *Formatter) InsertBytes(at int, b []byte) *Formatter

func (*Formatter) InsertString

func (f *Formatter) InsertString(at int, b string) *Formatter

func (*Formatter) Int

func (f *Formatter) Int(a int) *Formatter

func (*Formatter) Intf

func (f *Formatter) Intf(i int, base int) *Formatter

func (*Formatter) LastN

func (f *Formatter) LastN(n int) string

func (*Formatter) Len

func (f *Formatter) Len() int

func (*Formatter) Ln

func (f *Formatter) Ln() *Formatter

Ln TODO optionally take a number of lines

func (*Formatter) LnIfIndent

func (f *Formatter) LnIfIndent(depth int) *Formatter

func (*Formatter) Outdent

func (f *Formatter) Outdent() *Formatter

func (*Formatter) OutdentLn

func (f *Formatter) OutdentLn() *Formatter

func (*Formatter) OutdentSpaces

func (f *Formatter) OutdentSpaces(n int) *Formatter

func (*Formatter) OutdentTabs

func (f *Formatter) OutdentTabs(n int) *Formatter

func (Formatter) Pos

func (f Formatter) Pos() int

func (*Formatter) Printf

func (f *Formatter) Printf(fm string, a ...interface{}) *Formatter

func (*Formatter) Println

func (f *Formatter) Println(s string) *Formatter

func (*Formatter) Quote

func (f *Formatter) Quote(a string) *Formatter

func (*Formatter) RawQuote

func (f *Formatter) RawQuote(a string) *Formatter

func (*Formatter) ReplaceBytes

func (f *Formatter) ReplaceBytes(start, end int, b []byte) *Formatter

func (*Formatter) ReplaceIfDiff

func (f *Formatter) ReplaceIfDiff(fm Fmter) bool

func (*Formatter) ReplaceString

func (f *Formatter) ReplaceString(start, end int, b string) *Formatter

func (*Formatter) Reset

func (f *Formatter) Reset()

func (*Formatter) Rewind

func (f *Formatter) Rewind(to int) *Formatter

func (Formatter) Rewound

func (f Formatter) Rewound(to int) *Formatter

func (*Formatter) Rune

func (f *Formatter) Rune(a rune) *Formatter

func (*Formatter) RuneLit

func (f *Formatter) RuneLit(r rune) *Formatter

func (*Formatter) RuneQuote

func (f *Formatter) RuneQuote(a rune) *Formatter

func (*Formatter) Runes

func (f *Formatter) Runes() []rune

func (*Formatter) SetBuf

func (f *Formatter) SetBuf(buf []byte)

func (*Formatter) SetIndent

func (f *Formatter) SetIndent(depth int) *Formatter

func (*Formatter) Spaces

func (f *Formatter) Spaces(n int) *Formatter

func (*Formatter) Str

func (f *Formatter) Str(a string) *Formatter

func (Formatter) String

func (f Formatter) String() string

func (*Formatter) Stringer

func (f *Formatter) Stringer(a fmt.Stringer) *Formatter

func (*Formatter) Tab

func (f *Formatter) Tab() *Formatter

func (*Formatter) Tabs

func (f *Formatter) Tabs(n int) *Formatter

func (*Formatter) TrimRight

func (f *Formatter) TrimRight(s string) *Formatter

func (*Formatter) TrimRightCopiesN

func (f *Formatter) TrimRightCopiesN(s string, n int) *Formatter

func (*Formatter) U8

func (f *Formatter) U8(a uint8) *Formatter

func (*Formatter) U16

func (f *Formatter) U16(a uint16) *Formatter

func (*Formatter) U32

func (f *Formatter) U32(a uint32) *Formatter

func (*Formatter) U64

func (f *Formatter) U64(a uint64) *Formatter

func (*Formatter) Uint

func (f *Formatter) Uint(a uint) *Formatter

func (*Formatter) Write

func (f *Formatter) Write(b []byte) (n int, err error)

func (*Formatter) YetUnseen

func (f *Formatter) YetUnseen() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL