strut

package
v0.14.8 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package strut provides high-level, ergonomic str(ing) ut(lites).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FromMutable

func FromMutable(seq iter.Seq[Mutable]) iter.Seq[string]

FromMutable provides a clear, legible operation to convert iterators of Mutable instances to iterators of strings.

Types

type Buffer

type Buffer struct{ bytes.Buffer }

Buffer provides the same interface as Builder but wraps 'bytes.Buffer'.

func BufPrint

func BufPrint(args ...any) *Buffer

BufPrint formats args using default formatting and returns a new Buffer containing the result. Analogous to fmt.Sprint.

func BufPrintf

func BufPrintf(tpl string, args ...any) *Buffer

BufPrintf formats according to tpl and returns a new Buffer containing the result. Analogous to fmt.Sprintf.

func BufPrintln

func BufPrintln(args ...any) *Buffer

BufPrintln formats args using default formatting, appends a newline, and returns a new Buffer containing the result. Analogous to fmt.Sprintln.

func MakeBuffer

func MakeBuffer(capacity int) *Buffer

MakeBuffer retrieves a Buffer from the pool and ensures it has at least the specified capacity. The returned Buffer has zero length. Call Release() when done to return it to the pool for reuse.

func NewBuffer

func NewBuffer(buf []byte) *Buffer

NewBuffer constructs a new 'strut.Buffer' using the provided 'buf' as the basis of the buffer.

func (*Buffer) Bprint added in v0.14.8

func (b *Buffer) Bprint(args ...any) *Buffer

Bprint formats its arguments using default formatting and writes to the buffer. Analogous to fmt.Print, fmt.Fprint, and fmt.Sprint.

func (*Buffer) Bprintf added in v0.14.8

func (b *Buffer) Bprintf(tpl string, args ...any) *Buffer

Bprintf formats according to a format specifier and writes to the buffer. The 'tpl' parameter is the format string, and 'args' are the values to format. Analgous to fmt.Printf, fmt.Sprintf, and fmt.Fprintf.

func (*Buffer) Bprintln added in v0.14.8

func (b *Buffer) Bprintln(args ...any) *Buffer

Bprintln formats its arguments using default formatting, adds a newline, and writes to the buffer. Analogous to fmt.Println, fmt.Sprintln, fmt.Fprintln.

func (*Buffer) Concat

func (b *Buffer) Concat(strs ...string)

Concat writes all provided strings consecutively to the buffer without any separator.

func (*Buffer) Extend

func (b *Buffer) Extend(seq iter.Seq[string])

Extend writes all strings from the iterator 'seq' consecutively to the buffer.

func (*Buffer) ExtendBytes

func (b *Buffer) ExtendBytes(seq iter.Seq[[]byte])

ExtendBytes writes all strings from the iterator 'seq' consecutively to the buffer.

func (*Buffer) ExtendBytesJoin

func (b *Buffer) ExtendBytesJoin(seq iter.Seq[[]byte], sep []byte)

ExtendBytesJoin writes all strings from the iterator 'seq' to the buffer, separated by 'sep'. The first string is not preceded by a separator.

func (*Buffer) ExtendBytesLines

func (b *Buffer) ExtendBytesLines(seq iter.Seq[[]byte])

ExtendBytesLines writes all strings from the iterator 'seq' consecutively to the buffer, interspersing a newline character.

func (*Buffer) ExtendJoin

func (b *Buffer) ExtendJoin(seq iter.Seq[string], sep string)

ExtendJoin writes all strings from the iterator 'seq' to the buffer, separated by 'sep'. The first string is not preceded by a separator.

func (*Buffer) ExtendLines

func (b *Buffer) ExtendLines(seq iter.Seq[string])

ExtendLines writes each string from the iterator 'seq' on its own line to the buffer. Each string is followed by a newline character.

func (*Buffer) ExtendMutable

func (b *Buffer) ExtendMutable(seq iter.Seq[Mutable])

ExtendMutable writes all Mutable byte slices from the iterator 'seq' consecutively to the buffer.

func (*Buffer) ExtendMutableJoin

func (b *Buffer) ExtendMutableJoin(seq iter.Seq[Mutable], sep Mutable)

ExtendMutableJoin writes all Mutable byte slices from the iterator 'seq' to the buffer, separated by 'sep'. The first element is not preceded by a separator.

func (*Buffer) ExtendMutableLines

func (b *Buffer) ExtendMutableLines(seq iter.Seq[Mutable])

ExtendMutableLines writes each Mutable byte slice from the iterator 'seq' on its own line to the buffer. Each element is followed by a newline character.

func (*Buffer) Format

func (b *Buffer) Format(state fmt.State, _ rune)

Format implements fmt.Formatter, writing the buffer's contents directly to the formatter state without allocating an intermediate string.

func (*Buffer) Join

func (b *Buffer) Join(s []string, sep string)

Join writes all strings from the slice 's', separated by 'sep', to the buffer. This is analogous to strings.Join but writes directly to the buffer.

func (*Buffer) Line

func (b *Buffer) Line()

Line writes a single newline character to the buffer.

func (*Buffer) Mutable

func (b *Buffer) Mutable() Mutable

Mutable returns the buffer's contents as a Mutable byte slice.

func (*Buffer) NLines

func (b *Buffer) NLines(n int)

NLines writes 'n' newline characters to the buffer. If 'n' is negative, the operaton is a no-op.

func (*Buffer) NTabs

func (b *Buffer) NTabs(n int)

NTabs writes 'n' tabs characters to the buffer. If 'n' is negative, the operaton is a no-op.

func (*Buffer) Print

func (b *Buffer) Print()

Print writes the buffer's contents to standard output.

func (*Buffer) Println

func (b *Buffer) Println()

Println writes the buffer's contents to standard output followed by a newline.

func (*Buffer) PushBool added in v0.14.8

func (b *Buffer) PushBool(v bool)

PushBool writes "true" or "false" according to the value of 'v' to the buffer. PushInt writes the decimal string representation of 'num' to the buffer.

func (*Buffer) PushBytes added in v0.14.8

func (b *Buffer) PushBytes(buf []byte)

PushBytes writes the byte slice 'buf' to the buffer. This is a convenience wrapper around Write.

func (*Buffer) PushComplex added in v0.14.8

func (b *Buffer) PushComplex(n complex128, tpl byte, prec, size int)

PushComplex writes the string representation of the complex number 'n' to the buffer. The 'tpl' parameter is the format ('b', 'e', 'E', 'f', 'g', 'G', 'x', 'X'), 'prec' controls precision, and 'size' is the total number of bits (64 or 128).

func (*Buffer) PushFloat added in v0.14.8

func (b *Buffer) PushFloat(f float64, tpl byte, prec, size int)

PushFloat writes the string representation of the floating-point number 'f' to the buffer. The 'tpl' parameter is the format ('b', 'e', 'E', 'f', 'g', 'G', 'x', 'X'), 'prec' controls precision, and 'size' is the number of bits (32 or 64).

func (*Buffer) PushInt added in v0.14.8

func (b *Buffer) PushInt(num int)

PushInt writes the string representation of the integer 'num' to the buffer.

func (*Buffer) PushInt64 added in v0.14.8

func (b *Buffer) PushInt64(n int64, base int)

PushInt64 writes the string representation of 'n' in the given 'base' to the buffer. The 'base' must be between 2 and 36 inclusive.

func (*Buffer) PushQuote added in v0.14.8

func (b *Buffer) PushQuote(str string)

PushQuote writes a double-quoted Go string literal representing 'str' to the buffer. The output includes surrounding quotes and uses Go escape sequences.

func (*Buffer) PushQuoteASCII added in v0.14.8

func (b *Buffer) PushQuoteASCII(str string)

PushQuoteASCII writes a double-quoted Go string literal representing 'str' to the buffer. Non-ASCII characters are escaped using \u or \U sequences.

func (*Buffer) PushQuoteGrapic added in v0.14.8

func (b *Buffer) PushQuoteGrapic(str string)

PushQuoteGrapic writes a double-quoted Go string literal representing 'str' to the buffer. Non-graphic characters as defined by unicode.IsGraphic are escaped.

func (*Buffer) PushQuoteRune added in v0.14.8

func (b *Buffer) PushQuoteRune(r rune)

PushQuoteRune writes a single-quoted Go character literal representing 'r' to the buffer. The output includes surrounding single quotes and uses Go escape sequences.

func (*Buffer) PushQuoteRuneASCII added in v0.14.8

func (b *Buffer) PushQuoteRuneASCII(r rune)

PushQuoteRuneASCII writes a single-quoted Go character literal representing 'r' to the buffer. Non-ASCII characters are escaped using \u or \U sequences.

func (*Buffer) PushQuoteRuneGrapic added in v0.14.8

func (b *Buffer) PushQuoteRuneGrapic(r rune)

PushQuoteRuneGrapic writes a single-quoted Go character literal representing 'r' to the buffer. Non-graphic characters as defined by unicode.IsGraphic are escaped.

func (*Buffer) PushReplace added in v0.14.8

func (b *Buffer) PushReplace(s, old, new []byte, n int)

PushReplace writes 's' with the first 'n' non-overlapping instances of 'old' replaced by 'new' to the buffer. If 'n' is negative, all instances are replaced.

func (*Buffer) PushReplaceAll added in v0.14.8

func (b *Buffer) PushReplaceAll(s, old, new []byte)

PushReplaceAll writes 's' with all non-overlapping instances of 'old' replaced by 'new' to the buffer.

func (*Buffer) PushString added in v0.14.8

func (b *Buffer) PushString(s string)

PushString appends string 's' to the buffer.

func (*Buffer) PushTrimLeft added in v0.14.8

func (b *Buffer) PushTrimLeft(str []byte, cut string)

PushTrimLeft writes 'str' with all leading characters contained in 'cut' removed to the buffer.

func (*Buffer) PushTrimPrefix added in v0.14.8

func (b *Buffer) PushTrimPrefix(s []byte, prefix []byte)

PushTrimPrefix writes 's' with the leading 'prefix' string removed to the buffer. If 's' doesn't start with 'prefix', 's' is written unchanged.

func (*Buffer) PushTrimRight added in v0.14.8

func (b *Buffer) PushTrimRight(str []byte, cut string)

PushTrimRight writes 'str' with all trailing characters contained in 'cut' removed to the buffer.

func (*Buffer) PushTrimSpace added in v0.14.8

func (b *Buffer) PushTrimSpace(str []byte)

PushTrimSpace writes 'str' with all leading and trailing whitespace removed to the buffer.

func (*Buffer) PushTrimSuffix added in v0.14.8

func (b *Buffer) PushTrimSuffix(s []byte, suffix []byte)

PushTrimSuffix writes 's' with the trailing 'suffix' string removed to the buffer. If 's' doesn't end with 'suffix', 's' is written unchanged.

func (*Buffer) PushUint64 added in v0.14.8

func (b *Buffer) PushUint64(n uint64, base int)

PushUint64 writes the string representation of 'n' in the given 'base' to the buffer. The 'base' must be between 2 and 36 inclusive.

func (*Buffer) Release

func (b *Buffer) Release()

Release resets the Buffer and returns it to the pool for reuse. Buffers larger than 64KB are not pooled to prevent excessive memory retention. After calling Release, the Buffer should not be used again.

func (*Buffer) Repeat

func (b *Buffer) Repeat(ln string, n int)

Repeat writes the string 'ln' to the buffer 'n' times. The 'n' parameter must be non-negative.

func (*Buffer) RepeatByte

func (b *Buffer) RepeatByte(char byte, n int)

RepeatByte writes the byte 'char' to the buffer 'n' times. The 'n' parameter must be non-negative.

func (*Buffer) RepeatLine

func (b *Buffer) RepeatLine(ln string, n int)

RepeatLine writes the string 'ln' followed by a newline to the buffer 'n' times. The 'n' parameter must be non-negative. Each repetition is on its own line.

func (*Buffer) RepeatRune

func (b *Buffer) RepeatRune(r rune, n int)

RepeatRune writes the rune 'r' to the buffer 'n' times. The 'n' parameter must be non-negative.

func (*Buffer) Tab

func (b *Buffer) Tab()

Tab writes a single tab character to the buffer.

func (*Buffer) WhenBprint added in v0.14.8

func (b *Buffer) WhenBprint(cond bool, args ...any) *Buffer

WhenBprint calls Bprint with 'args' if 'cond' is true and is a no-op otherwise.

func (*Buffer) WhenBprintf added in v0.14.8

func (b *Buffer) WhenBprintf(cond bool, tpl string, args ...any) *Buffer

WhenBprintf calls Bprintf with 'tpl' and 'args' if 'cond' is true and is a no-op otherwise.

func (*Buffer) WhenBprintln added in v0.14.8

func (b *Buffer) WhenBprintln(cond bool, args ...any) *Buffer

WhenBprintln calls Bprintln with 'args' if 'cond' is true and is a no-op otherwise.

func (*Buffer) WhenConcat

func (b *Buffer) WhenConcat(cond bool, strs ...string)

WhenConcat concatenates all strings in 'strs' if 'cond' is true and is a no-op otherwise.

func (*Buffer) WhenJoin

func (b *Buffer) WhenJoin(cond bool, sl []string, sep string)

WhenJoin joins all strings from 'sl' with 'sep' if 'cond' is true and is a no-op otherwise.

func (*Buffer) WhenLine

func (b *Buffer) WhenLine(cond bool)

WhenLine writes a newline if 'cond' is true and is a no-op otherwise.

func (*Buffer) WhenNLines

func (b *Buffer) WhenNLines(cond bool, n int)

WhenNLines writes 'n' newlines if 'cond' is true and is a no-op otherwise.

func (*Buffer) WhenNTabs

func (b *Buffer) WhenNTabs(cond bool, n int)

WhenNTabs writes 'n' tabs if 'cond' is true and is a no-op otherwise.

func (*Buffer) WhenTab

func (b *Buffer) WhenTab(cond bool)

WhenTab writes a tab character if 'cond' is true and is a no-op otherwise.

func (*Buffer) WhenWrite

func (b *Buffer) WhenWrite(cond bool, buf []byte)

WhenWrite writes the byte slice 'buf' if 'cond' is true and is a no-op otherwise.

func (*Buffer) WhenWriteByte

func (b *Buffer) WhenWriteByte(cond bool, bt byte)

WhenWriteByte writes the byte 'bt' if 'cond' is true and is a no-op otherwise.

func (*Buffer) WhenWriteLine

func (b *Buffer) WhenWriteLine(cond bool, ln string)

WhenWriteLine writes the string 'ln' followed by a newline if 'cond' is true and is a no-op otherwise.

func (*Buffer) WhenWriteLines

func (b *Buffer) WhenWriteLines(cond bool, lns ...string)

WhenWriteLines writes each string in 'lns' on its own line if 'cond' is true and is a no-op otherwise.

func (*Buffer) WhenWriteMutable

func (b *Buffer) WhenWriteMutable(cond bool, m Mutable)

WhenWriteMutable writes the Mutable byte slice 'm' if 'cond' is true and is a no-op otherwise.

func (*Buffer) WhenWriteMutableLine

func (b *Buffer) WhenWriteMutableLine(cond bool, m Mutable)

WhenWriteMutableLine writes the Mutable byte slice 'm' followed by a newline if 'cond' is true and is a no-op otherwise.

func (*Buffer) WhenWriteMutableLines

func (b *Buffer) WhenWriteMutableLines(cond bool, ms ...Mutable)

WhenWriteMutableLines writes each Mutable byte slice in 'ms' on its own line if 'cond' is true and is a no-op otherwise.

func (*Buffer) WhenWriteRune

func (b *Buffer) WhenWriteRune(cond bool, r rune)

WhenWriteRune writes the rune 'r' if 'cond' is true and is a no-op otherwise.

func (*Buffer) WhenWriteString

func (b *Buffer) WhenWriteString(cond bool, s string)

WhenWriteString writes the string 's' if 'cond' is true and is a no-op otherwise.

func (*Buffer) WithReplace

func (b *Buffer) WithReplace(s, old, new string, n int)

WithReplace writes 's' with the first 'n' non-overlapping instances of 'old' replaced by 'new' to the buffer. If 'n' is negative, all instances are replaced.

func (*Buffer) WithReplaceAll

func (b *Buffer) WithReplaceAll(s, old, new string)

WithReplaceAll writes 's' with all non-overlapping instances of 'old' replaced by 'new' to the buffer.

func (*Buffer) WithTrimLeft

func (b *Buffer) WithTrimLeft(str string, cut string)

WithTrimLeft writes 'str' with all leading characters contained in 'cut' removed to the buffer.

func (*Buffer) WithTrimPrefix

func (b *Buffer) WithTrimPrefix(s string, prefix string)

WithTrimPrefix writes 's' with the leading 'prefix' string removed to the buffer. If 's' doesn't start with 'prefix', 's' is written unchanged.

func (*Buffer) WithTrimRight

func (b *Buffer) WithTrimRight(str string, cut string)

WithTrimRight writes 'str' with all trailing characters contained in 'cut' removed to the buffer.

func (*Buffer) WithTrimSpace

func (b *Buffer) WithTrimSpace(str string)

WithTrimSpace writes 'str' with all leading and trailing whitespace removed to the buffer.

func (*Buffer) WithTrimSuffix

func (b *Buffer) WithTrimSuffix(s string, suffix string)

WithTrimSuffix writes 's' with the trailing 'suffix' string removed to the buffer. If 's' doesn't end with 'suffix', 's' is written unchanged.

func (*Buffer) WriteBytesLine

func (b *Buffer) WriteBytesLine(ln []byte)

WriteBytesLine writes the string 'ln' followed by a newline character to the buffer.

func (*Buffer) WriteBytesLines

func (b *Buffer) WriteBytesLines(lns ...[]byte)

WriteBytesLines writes each string in 'lns' followed by a newline character to the buffer. Each string is written on its own line.

func (*Buffer) WriteLine

func (b *Buffer) WriteLine(ln string)

WriteLine writes the string 'ln' followed by a newline character to the buffer.

func (*Buffer) WriteLines

func (b *Buffer) WriteLines(lns ...string)

WriteLines writes each string in 'lns' followed by a newline character to the buffer. Each string is written on its own line.

func (*Buffer) WriteMutable

func (b *Buffer) WriteMutable(in Mutable)

WriteMutable writes the Mutable byte slice 'in' to the buffer.

func (*Buffer) WriteMutableLine

func (b *Buffer) WriteMutableLine(in Mutable)

WriteMutableLine writes the Mutable byte slice 'in' followed by a newline character to the buffer.

func (*Buffer) WriteMutableLines

func (b *Buffer) WriteMutableLines(in ...Mutable)

WriteMutableLines writes each Mutable byte slice in 'in' followed by a newline character to the buffer. Each element is written on its own line.

type Builder

type Builder struct{ strings.Builder }

Builder is a wrapper around strings.Builder, that provides additional higher-level methods for building strings.

func Bprint

func Bprint(args ...any) *Builder

Bprint formats args using default formatting and returns a new Builder containing the result. Analogous to fmt.Sprint.

func Bprintf

func Bprintf(tpl string, args ...any) *Builder

Bprintf formats according to tpl and returns a new Builder containing the result. Analogous to fmt.Sprintf.

func Bprintln

func Bprintln(args ...any) *Builder

Bprintln formats args using default formatting, appends a newline, and returns a new Builder containing the result. Analogous to fmt.Sprintln.

func MakeBuilder

func MakeBuilder(capacity int) *Builder

MakeBuilder constructs a new Builder with at least the specified capacity preallocated, avoiding early reallocation for known-size outputs.

func (*Builder) Bprint added in v0.14.8

func (b *Builder) Bprint(args ...any) *Builder

Bprint formats its arguments using default formatting and writes to the builder. Analogous to fmt.Print, fmt.Fprint, and fmt.Sprint.

func (*Builder) Bprintf added in v0.14.8

func (b *Builder) Bprintf(tpl string, args ...any) *Builder

Bprintf formats according to a format specifier and writes to the builder. The 'tpl' parameter is the format string, and 'args' are the values to format. Analgous to fmt.Printf, fmt.Sprintf, and fmt.Fprintf.

func (*Builder) Bprintln added in v0.14.8

func (b *Builder) Bprintln(args ...any) *Builder

Bprintln formats its arguments using default formatting, adds a newline, and writes to the builder. Analogous to fmt.Println, fmt.Sprintln, fmt.Fprintln.

func (*Builder) Bytes

func (b *Builder) Bytes() []byte

Bytes returns the builder's accumulated content as a byte slice.

func (*Builder) Concat

func (b *Builder) Concat(strs ...string)

Concat writes all provided strings consecutively to the builder without any separator.

func (*Builder) Extend

func (b *Builder) Extend(seq iter.Seq[string])

Extend writes all strings from the iterator 'seq' consecutively to the builder.

func (*Builder) ExtendBytes

func (b *Builder) ExtendBytes(seq iter.Seq[[]byte])

ExtendBytes writes all byte slices from the iterator 'seq' consecutively to the builder. Each byte slice is copied during the write operation. This is the byte slice equivalent of Extend.

func (*Builder) ExtendBytesJoin

func (b *Builder) ExtendBytesJoin(seq iter.Seq[[]byte], sep []byte)

ExtendBytesJoin writes all byte slices from the iterator 'seq' to the builder, separated by 'sep'. The first byte slice is not preceded by a separator. Each byte slice is copied during the write operation. This is the byte slice equivalent of ExtendJoin.

func (*Builder) ExtendBytesLines

func (b *Builder) ExtendBytesLines(seq iter.Seq[[]byte])

ExtendBytesLines writes all byte slices from the iterator 'seq' to the builder, each followed by a newline character. Each byte slice is written on its own line. Each byte slice is copied during the write operation. This is the byte slice equivalent of ExtendLines.

func (*Builder) ExtendJoin

func (b *Builder) ExtendJoin(seq iter.Seq[string], sep string)

ExtendJoin writes all strings from the iterator 'seq' to the builder, separated by 'sep'. The first string is not preceded by a separator.

func (*Builder) ExtendLines

func (b *Builder) ExtendLines(seq iter.Seq[string])

ExtendLines writes each string from the iterator 'seq' on its own line to the builder. Each string is followed by a newline character.

func (*Builder) ExtendMutable

func (b *Builder) ExtendMutable(seq iter.Seq[Mutable])

ExtendMutable writes all Mutable byte slices from the iterator 'seq' consecutively to the builder.

func (*Builder) ExtendMutableJoin

func (b *Builder) ExtendMutableJoin(seq iter.Seq[Mutable], sep Mutable)

ExtendMutableJoin writes all Mutable byte slices from the iterator 'seq' to the builder, separated by 'sep'. The first element is not preceded by a separator.

func (*Builder) ExtendMutableLines

func (b *Builder) ExtendMutableLines(seq iter.Seq[Mutable])

ExtendMutableLines writes each Mutable byte slice from the iterator 'seq' on its own line to the builder. Each element is followed by a newline character.

func (*Builder) Format

func (b *Builder) Format(state fmt.State, _ rune)

Format implements fmt.Formatter, writing the builder's contents directly to the formatter state without allocating an intermediate string.

func (*Builder) Join

func (b *Builder) Join(s []string, sep string)

Join writes all strings from the slice 's', separated by 'sep', to the builder. This is analogous to strings.Join but writes directly to the builder.

func (*Builder) Line

func (b *Builder) Line()

Line writes a single newline character to the builder.

func (*Builder) Mutable

func (b *Builder) Mutable() Mutable

Mutable returns the builder's contents as a Mutable byte slice.

func (*Builder) NLines

func (b *Builder) NLines(n int)

NLines writes 'n' newline characters to the builder. If 'n' is negative, the operaton is a no-op.

func (*Builder) NTabs

func (b *Builder) NTabs(n int)

NTabs writes 'n' tabs characters to the builder. If 'n' is negative, the operaton is a no-op.

func (*Builder) Print

func (b *Builder) Print()

Print writes the builder's contents to standard output.

func (*Builder) Println

func (b *Builder) Println()

Println writes the builder's contents to standard output followed by a newline.

func (*Builder) PushBool added in v0.14.8

func (b *Builder) PushBool(v bool)

PushBool writes "true" or "false" according to the value of 'v' to the builder. PushInt writes the decimal string representation of 'num' to the builder.

func (*Builder) PushBytes added in v0.14.8

func (b *Builder) PushBytes(buf []byte)

PushBytes writes the byte slice 'buf' to the builder. The byte slice is copied during the write operation; the caller retains ownership of 'buf' and may modify it after this call returns. This is a convenience wrapper around Write.

func (*Builder) PushComplex added in v0.14.8

func (b *Builder) PushComplex(n complex128, tpl byte, prec, size int)

PushComplex writes the string representation of the complex number 'n' to the builder. The 'tpl' parameter is the format ('b', 'e', 'E', 'f', 'g', 'G', 'x', 'X'), 'prec' controls precision, and 'size' is the total number of bits (64 or 128).

func (*Builder) PushFloat added in v0.14.8

func (b *Builder) PushFloat(f float64, tpl byte, prec, size int)

PushFloat writes the string representation of the floating-point number 'f' to the builder. The 'tpl' parameter is the format ('b', 'e', 'E', 'f', 'g', 'G', 'x', 'X'), 'prec' controls precision, and 'size' is the number of bits (32 or 64).

func (*Builder) PushInt added in v0.14.8

func (b *Builder) PushInt(num int)

PushInt writes the string representation of the integer 'num' to the builder.

func (*Builder) PushInt64 added in v0.14.8

func (b *Builder) PushInt64(n int64, base int)

PushInt64 writes the string representation of 'n' in the given 'base' to the builder. The 'base' must be between 2 and 36 inclusive.

func (*Builder) PushQuote added in v0.14.8

func (b *Builder) PushQuote(str string)

PushQuote writes a double-quoted Go string literal representing 'str' to the builder. The output includes surrounding quotes and uses Go escape sequences.

func (*Builder) PushQuoteASCII added in v0.14.8

func (b *Builder) PushQuoteASCII(str string)

PushQuoteASCII writes a double-quoted Go string literal representing 'str' to the builder. Non-ASCII characters are escaped using \u or \U sequences.

func (*Builder) PushQuoteGrapic added in v0.14.8

func (b *Builder) PushQuoteGrapic(str string)

PushQuoteGrapic writes a double-quoted Go string literal representing 'str' to the builder. Non-graphic characters as defined by unicode.IsGraphic are escaped.

func (*Builder) PushQuoteRune added in v0.14.8

func (b *Builder) PushQuoteRune(r rune)

PushQuoteRune writes a single-quoted Go character literal representing 'r' to the builder. The output includes surrounding single quotes and uses Go escape sequences.

func (*Builder) PushQuoteRuneASCII added in v0.14.8

func (b *Builder) PushQuoteRuneASCII(r rune)

PushQuoteRuneASCII writes a single-quoted Go character literal representing 'r' to the builder. Non-ASCII characters are escaped using \u or \U sequences.

func (*Builder) PushQuoteRuneGrapic added in v0.14.8

func (b *Builder) PushQuoteRuneGrapic(r rune)

PushQuoteRuneGrapic writes a single-quoted Go character literal representing 'r' to the builder. Non-graphic characters as defined by unicode.IsGraphic are escaped.

func (*Builder) PushReplace added in v0.14.8

func (b *Builder) PushReplace(s, old, new []byte, n int)

PushReplace writes the byte slice 's' with the first 'n' non-overlapping instances of 'old' replaced by 'new' to the builder. If 'n' is negative, all instances are replaced. The input 's' is not modified; a transformed copy is written. This is the byte slice equivalent of WithReplace.

func (*Builder) PushReplaceAll added in v0.14.8

func (b *Builder) PushReplaceAll(s, old, new []byte)

PushReplaceAll writes the byte slice 's' with all non-overlapping instances of 'old' replaced by 'new' to the builder. The input 's' is not modified; a transformed copy is written. This is the byte slice equivalent of WithReplaceAll.

func (*Builder) PushString added in v0.14.8

func (b *Builder) PushString(s string)

PushString appends string 's' to the builder.

func (*Builder) PushTrimLeft added in v0.14.8

func (b *Builder) PushTrimLeft(str []byte, cut string)

PushTrimLeft writes the byte slice 'str' with all leading characters contained in 'cut' removed to the builder. The input 'str' is not modified; a transformed copy is written. This is the byte slice equivalent of WithTrimLeft.

func (*Builder) PushTrimPrefix added in v0.14.8

func (b *Builder) PushTrimPrefix(s []byte, prefix []byte)

PushTrimPrefix writes the byte slice 's' with the leading 'prefix' removed to the builder. If 's' doesn't start with 'prefix', 's' is written unchanged. The input 's' is not modified; a transformed copy is written. This is the byte slice equivalent of WithTrimPrefix.

func (*Builder) PushTrimRight added in v0.14.8

func (b *Builder) PushTrimRight(str []byte, cut string)

PushTrimRight writes the byte slice 'str' with all trailing characters contained in 'cut' removed to the builder. The input 'str' is not modified; a transformed copy is written. This is the byte slice equivalent of WithTrimRight.

func (*Builder) PushTrimSpace added in v0.14.8

func (b *Builder) PushTrimSpace(str []byte)

PushTrimSpace writes the byte slice 'str' with all leading and trailing whitespace removed to the builder. The input 'str' is not modified; a transformed copy is written. This is the byte slice equivalent of WithTrimSpace.

func (*Builder) PushTrimSuffix added in v0.14.8

func (b *Builder) PushTrimSuffix(s []byte, suffix []byte)

PushTrimSuffix writes the byte slice 's' with the trailing 'suffix' removed to the builder. If 's' doesn't end with 'suffix', 's' is written unchanged. The input 's' is not modified; a transformed copy is written. This is the byte slice equivalent of WithTrimSuffix.

func (*Builder) PushUint64 added in v0.14.8

func (b *Builder) PushUint64(n uint64, base int)

PushUint64 writes the string representation of 'n' in the given 'base' to the builder. The 'base' must be between 2 and 36 inclusive.

func (*Builder) Repeat

func (b *Builder) Repeat(ln string, n int)

Repeat writes the string 'ln' to the builder 'n' times. The 'n' parameter must be non-negative.

func (*Builder) RepeatByte

func (b *Builder) RepeatByte(char byte, n int)

RepeatByte writes the byte 'char' to the builder 'n' times. The 'n' parameter must be non-negative.

func (*Builder) RepeatLine

func (b *Builder) RepeatLine(ln string, n int)

RepeatLine writes the string 'ln' followed by a newline to the builder 'n' times. The 'n' parameter must be non-negative. Each repetition is on its own line.

func (*Builder) RepeatRune

func (b *Builder) RepeatRune(r rune, n int)

RepeatRune writes the rune 'r' to the builder 'n' times. The 'n' parameter must be non-negative.

func (*Builder) Tab

func (b *Builder) Tab()

Tab writes a single tab character to the builder.

func (*Builder) WhenBprint added in v0.14.8

func (b *Builder) WhenBprint(cond bool, args ...any) *Builder

WhenBprint calls Bprint with 'args' if 'cond' is true and is a no-op otherwise.

func (*Builder) WhenBprintf added in v0.14.8

func (b *Builder) WhenBprintf(cond bool, tpl string, args ...any) *Builder

WhenBprintf calls Bprintf with 'tpl' and 'args' if 'cond' is true and is a no-op otherwise.

func (*Builder) WhenBprintln added in v0.14.8

func (b *Builder) WhenBprintln(cond bool, args ...any) *Builder

WhenBprintln calls Bprintln with 'args' if 'cond' is true and is a no-op otherwise.

func (*Builder) WhenConcat

func (b *Builder) WhenConcat(cond bool, strs ...string)

WhenConcat concatenates all strings in 'strs' if 'cond' is true and is a no-op otherwise.

func (*Builder) WhenJoin

func (b *Builder) WhenJoin(cond bool, sl []string, sep string)

WhenJoin joins all strings from 'sl' with 'sep' if 'cond' is true and is a no-op otherwise.

func (*Builder) WhenLine

func (b *Builder) WhenLine(cond bool)

WhenLine writes a newline if 'cond' is true and is a no-op otherwise.

func (*Builder) WhenNLines

func (b *Builder) WhenNLines(cond bool, n int)

WhenNLines writes 'n' newlines if 'cond' is true and is a no-op otherwise.

func (*Builder) WhenNTabs

func (b *Builder) WhenNTabs(cond bool, n int)

WhenNTabs writes 'n' tabs if 'cond' is true and is a no-op otherwise.

func (*Builder) WhenTab

func (b *Builder) WhenTab(cond bool)

WhenTab writes a tab character if 'cond' is true and is a no-op otherwise.

func (*Builder) WhenWrite

func (b *Builder) WhenWrite(cond bool, buf []byte)

WhenWrite writes the byte slice 'buf' if 'cond' is true and is a no-op otherwise.

func (*Builder) WhenWriteByte

func (b *Builder) WhenWriteByte(cond bool, bt byte)

WhenWriteByte writes the byte 'bt' if 'cond' is true and is a no-op otherwise.

func (*Builder) WhenWriteLine

func (b *Builder) WhenWriteLine(cond bool, ln string)

WhenWriteLine writes the string 'ln' followed by a newline if 'cond' is true and is a no-op otherwise.

func (*Builder) WhenWriteLines

func (b *Builder) WhenWriteLines(cond bool, lns ...string)

WhenWriteLines writes each string in 'lns' on its own line if 'cond' is true and is a no-op otherwise.

func (*Builder) WhenWriteMutable

func (b *Builder) WhenWriteMutable(cond bool, m Mutable)

WhenWriteMutable writes the Mutable byte slice 'm' if 'cond' is true and is a no-op otherwise.

func (*Builder) WhenWriteMutableLine

func (b *Builder) WhenWriteMutableLine(cond bool, m Mutable)

WhenWriteMutableLine writes the Mutable byte slice 'm' followed by a newline if 'cond' is true and is a no-op otherwise.

func (*Builder) WhenWriteMutableLines

func (b *Builder) WhenWriteMutableLines(cond bool, ms ...Mutable)

WhenWriteMutableLines writes each Mutable byte slice in 'ms' on its own line if 'cond' is true and is a no-op otherwise.

func (*Builder) WhenWriteRune

func (b *Builder) WhenWriteRune(cond bool, r rune)

WhenWriteRune writes the rune 'r' if 'cond' is true and is a no-op otherwise.

func (*Builder) WhenWriteString

func (b *Builder) WhenWriteString(cond bool, s string)

WhenWriteString writes the string 's' if 'cond' is true and is a no-op otherwise.

func (*Builder) WithReplace

func (b *Builder) WithReplace(s, old, new string, n int)

WithReplace writes 's' with the first 'n' non-overlapping instances of 'old' replaced by 'new' to the builder. If 'n' is negative, all instances are replaced.

func (*Builder) WithReplaceAll

func (b *Builder) WithReplaceAll(s, old, new string)

WithReplaceAll writes 's' with all non-overlapping instances of 'old' replaced by 'new' to the builder.

func (*Builder) WithTrimLeft

func (b *Builder) WithTrimLeft(str string, cut string)

WithTrimLeft writes 'str' with all leading characters contained in 'cut' removed to the builder.

func (*Builder) WithTrimPrefix

func (b *Builder) WithTrimPrefix(s string, prefix string)

WithTrimPrefix writes 's' with the leading 'prefix' string removed to the builder. If 's' doesn't start with 'prefix', 's' is written unchanged.

func (*Builder) WithTrimRight

func (b *Builder) WithTrimRight(str string, cut string)

WithTrimRight writes 'str' with all trailing characters contained in 'cut' removed to the builder.

func (*Builder) WithTrimSpace

func (b *Builder) WithTrimSpace(str string)

WithTrimSpace writes 'str' with all leading and trailing whitespace removed to the builder.

func (*Builder) WithTrimSuffix

func (b *Builder) WithTrimSuffix(s string, suffix string)

WithTrimSuffix writes 's' with the trailing 'suffix' string removed to the builder. If 's' doesn't end with 'suffix', 's' is written unchanged.

func (*Builder) WriteBytesLine

func (b *Builder) WriteBytesLine(ln []byte)

WriteBytesLine writes the byte slice 'ln' followed by a newline character to the builder. The byte slice is copied during the write operation.

func (*Builder) WriteBytesLines

func (b *Builder) WriteBytesLines(lns ...[]byte)

WriteBytesLines writes each byte slice in 'lns' followed by a newline character to the builder. Each byte slice is written on its own line. Each byte slice is copied during the write operation.

func (*Builder) WriteLine

func (b *Builder) WriteLine(ln string)

WriteLine writes the string 'ln' followed by a newline character to the builder.

func (*Builder) WriteLines

func (b *Builder) WriteLines(lns ...string)

WriteLines writes each string in 'lns' followed by a newline character to the builder. Each string is written on its own line.

func (*Builder) WriteMutable

func (b *Builder) WriteMutable(in Mutable)

WriteMutable writes the Mutable byte slice 'in' to the builder.

func (*Builder) WriteMutableLine

func (b *Builder) WriteMutableLine(in Mutable)

WriteMutableLine writes the Mutable byte slice 'in' followed by a newline character to the builder.

func (*Builder) WriteMutableLines

func (b *Builder) WriteMutableLines(in ...Mutable)

WriteMutableLines writes each Mutable byte slice in 'in' followed by a newline character to the builder. Each element is written on its own line.

type Mutable

type Mutable []byte

Mutable provides a pooled, mutable byte slice type for efficient string manipulation. Methods mirror the bytes package API with zero-allocation optimizations for in-place operations and iterator-based splitting. Pointer receiver methods mutate in place; value receiver methods are read-only. The type implements io.Writer and fmt.Formatter.

While it is safe to create Mutable values using `var name Mutable` and `name := Mutable{}`, the NewMutable() constructor takes advantage of a buffer pool, and buffers can be returned to the pool using Release(). Buffers larger than 64KB are not pooled, following the example of the implementation of the buffers in the stdlib fmt package.

Mutake attempts, when possible to, to provide efficient in-place operations and avoids allocation when possible. Split and Fields methods return iter.Seq iterators for zero-allocation iteration.

func MakeMutable

func MakeMutable(capacity int) *Mutable

MakeMutable retrieves a Mutable from the pool and ensures it has at least the specified capacity. The returned Mutable has zero length and at least the specified capacity. Like NewMutable, the returned Mutable should be released with Release() when no longer needed.

func Mprint

func Mprint(a ...any) *Mutable

Mprint formats using the default formats for its operands and returns the resulting string as a Mutable. Spaces are added between operands when neither is a string. The returned Mutable is obtained from the pool and should be released with Release() when no longer needed.

func Mprintf

func Mprintf(format string, a ...any) *Mutable

Mprintf formats according to a format specifier and returns the resulting string as a Mutable. The returned Mutable is obtained from the pool and should be released with Release() when no longer needed. Preallocates based on format string length plus estimated argument size.

func Mprintln

func Mprintln(a ...any) *Mutable

Mprintln formats using the default formats for its operands and returns the resulting string as a Mutable. Spaces are always added between operands and a newline is appended. The returned Mutable is obtained from the pool and should be released with Release() when no longer needed.

func NewMutable

func NewMutable() *Mutable

NewMutable retrieves a Mutable from the pool. The returned Mutable should be released with Release() when no longer needed to enable reuse. The initial content is empty but may have non-zero capacity.

func (Mutable) Bytes

func (mut Mutable) Bytes() []byte

Bytes returns the underlying byte slice. No allocation.

func (Mutable) Cap

func (mut Mutable) Cap() int

Cap returns the capacity of the underlying byte slice.

func (Mutable) Clone

func (mut Mutable) Clone() *Mutable

Clone returns a copy of the mutable string. Allocates a new Mutable with the same content.

func (Mutable) Compare

func (mut Mutable) Compare(b []byte) int

Compare returns an integer comparing two byte slices lexicographically.

func (Mutable) CompareString

func (mut Mutable) CompareString(s string) int

CompareString returns an integer comparing the mutable string with 's' lexicographically.

func (*Mutable) Concat added in v0.14.8

func (mut *Mutable) Concat(strs ...string)

Concat writes all strings in strs consecutively to the mutable.

func (Mutable) Contains

func (mut Mutable) Contains(subslice []byte) bool

Contains reports whether 'subslice' is within the mutable string.

func (Mutable) ContainsAny

func (mut Mutable) ContainsAny(chars string) bool

ContainsAny reports whether any UTF-8 encoded code points in 'chars' are within the mutable string.

func (Mutable) ContainsRune

func (mut Mutable) ContainsRune(r rune) bool

ContainsRune reports whether rune 'r' is contained in the mutable string.

func (Mutable) ContainsString

func (mut Mutable) ContainsString(s string) bool

ContainsString reports whether string 's' is within the mutable string.

func (Mutable) Copy

func (mut Mutable) Copy(dst *Mutable) error

Copy copies the contents of this mutable string to 'dst', resizing 'dst' as needed. This overwrites the content of 'dst', reusing the underlying storage if it has sufficient capacity.

func (Mutable) CopyTo

func (mut Mutable) CopyTo(dst []byte) error

CopyTo copies the contents of this mutable string to 'dst'. Returns an error if 'dst' is too small to hold the contents.

func (Mutable) Count

func (mut Mutable) Count(sep []byte) int

Count counts the number of non-overlapping instances of 'sep' in the mutable string.

func (Mutable) CountString

func (mut Mutable) CountString(sep string) int

CountString counts the number of non-overlapping instances of 'sep' in the mutable string.

func (Mutable) Cut

func (mut Mutable) Cut(sep []byte) (before, after []byte, found bool)

Cut slices the mutable string around the first instance of 'sep', returning the text before and after 'sep'.

func (Mutable) CutPrefix

func (mut Mutable) CutPrefix(prefix []byte) (after []byte, found bool)

CutPrefix returns the mutable string without the provided leading 'prefix' and reports whether it found the prefix.

func (Mutable) CutPrefixString

func (mut Mutable) CutPrefixString(prefix string) (after []byte, found bool)

CutPrefixString returns the mutable string without the provided leading 'prefix' and reports whether it found the prefix.

func (Mutable) CutString

func (mut Mutable) CutString(sep string) (before, after []byte, found bool)

CutString slices the mutable string around the first instance of 'sep', returning the text before and after 'sep'.

func (Mutable) CutSuffix

func (mut Mutable) CutSuffix(suffix []byte) (before []byte, found bool)

CutSuffix returns the mutable string without the provided ending 'suffix' and reports whether it found the suffix.

func (Mutable) CutSuffixString

func (mut Mutable) CutSuffixString(suffix string) (before []byte, found bool)

CutSuffixString returns the mutable string without the provided ending 'suffix' and reports whether it found the suffix.

func (Mutable) Equal

func (mut Mutable) Equal(b []byte) bool

Equal reports whether the mutable string and 'b' are the same length and contain the same bytes.

func (Mutable) EqualFold

func (mut Mutable) EqualFold(s []byte) bool

EqualFold reports whether the mutable string and 's' are equal under Unicode case-folding.

func (Mutable) EqualFoldString

func (mut Mutable) EqualFoldString(s string) bool

EqualFoldString reports whether the mutable string and 's' are equal under Unicode case-folding.

func (Mutable) EqualString

func (mut Mutable) EqualString(s string) bool

EqualString reports whether the mutable string and 's' are the same length and contain the same bytes.

func (*Mutable) Extend

func (mut *Mutable) Extend(seq iter.Seq[Mutable]) *Mutable

Extend appends all Mutable values from seq to the receiver. May allocate if capacity is insufficient.

func (*Mutable) ExtendBytes

func (mut *Mutable) ExtendBytes(seq iter.Seq[[]byte]) *Mutable

ExtendBytes appends all byte slices from seq to the receiver. May allocate if capacity is insufficient.

func (*Mutable) ExtendBytesJoin

func (mut *Mutable) ExtendBytesJoin(seq iter.Seq[[]byte], sep []byte) *Mutable

ExtendBytesJoin appends []byte values from seq separated by sep. May allocate if capacity is insufficient.

func (*Mutable) ExtendBytesLines added in v0.14.8

func (mut *Mutable) ExtendBytesLines(seq iter.Seq[[]byte])

ExtendBytesLines writes each byte slice from seq on its own line to the mutable.

func (*Mutable) ExtendJoin

func (mut *Mutable) ExtendJoin(seq iter.Seq[Mutable], sep Mutable) *Mutable

ExtendJoin appends Mutable values from seq separated by sep. May allocate if capacity is insufficient.

func (*Mutable) ExtendLines added in v0.14.8

func (mut *Mutable) ExtendLines(seq iter.Seq[Mutable])

ExtendLines writes each Mutable from seq on its own line to the mutable.

func (*Mutable) ExtendStrings

func (mut *Mutable) ExtendStrings(seq iter.Seq[string]) *Mutable

ExtendStrings appends all strings from seq to the receiver. May allocate if capacity is insufficient.

func (*Mutable) ExtendStringsJoin

func (mut *Mutable) ExtendStringsJoin(seq iter.Seq[string], sep string) *Mutable

ExtendStringsJoin appends strings from seq separated by sep. May allocate if capacity is insufficient.

func (*Mutable) ExtendStringsLines added in v0.14.8

func (mut *Mutable) ExtendStringsLines(seq iter.Seq[string])

ExtendStringsLines writes each string from seq on its own line to the mutable.

func (Mutable) Fields

func (mut Mutable) Fields() iter.Seq[Mutable]

Fields splits the mutable string around each instance of one or more consecutive white space characters, as defined by unicode.IsSpace, returning an iterator that yields each field. Zero allocation for the iterator itself.

func (Mutable) FieldsFunc

func (mut Mutable) FieldsFunc(f func(rune) bool) iter.Seq[Mutable]

FieldsFunc splits the mutable string at each run of code points 'c' satisfying 'f(c)', returning an iterator. Zero allocation for the iterator itself.

func (Mutable) Format

func (mut Mutable) Format(state fmt.State, _ rune)

Format implements fmt.Formatter, allowing Mutable to be used directly in formatted output. Writes the underlying bytes to the formatter's state.

func (*Mutable) Grow

func (mut *Mutable) Grow(n int)

Grow increases the capacity of the mutable string by 'n' bytes. May allocate a new underlying array if additional capacity is needed.

func (Mutable) HasPrefix

func (mut Mutable) HasPrefix(prefix []byte) bool

HasPrefix tests whether the mutable string begins with 'prefix'.

func (Mutable) HasPrefixString

func (mut Mutable) HasPrefixString(prefix string) bool

HasPrefixString tests whether the mutable string begins with 'prefix'.

func (Mutable) HasSuffix

func (mut Mutable) HasSuffix(suffix []byte) bool

HasSuffix tests whether the mutable string ends with 'suffix'.

func (Mutable) HasSuffixString

func (mut Mutable) HasSuffixString(suffix string) bool

HasSuffixString tests whether the mutable string ends with 'suffix'.

func (Mutable) Index

func (mut Mutable) Index(sep []byte) int

Index returns the index of the first instance of 'sep' in the mutable string, or -1 if 'sep' is not present.

func (Mutable) IndexAny

func (mut Mutable) IndexAny(chars string) int

IndexAny returns the index of the first instance of any code point from 'chars' in the mutable string.

func (Mutable) IndexByte

func (mut Mutable) IndexByte(c byte) int

IndexByte returns the index of the first instance of 'c' in the mutable string, or -1 if 'c' is not present.

func (Mutable) IndexRune

func (mut Mutable) IndexRune(r rune) int

IndexRune returns the index of the first instance of rune 'r', or -1 if the rune is not present.

func (Mutable) IndexString

func (mut Mutable) IndexString(sep string) int

IndexString returns the index of the first instance of 'sep' in the mutable string, or -1 if 'sep' is not present.

func (Mutable) IsASCII

func (mut Mutable) IsASCII() bool

IsASCII reports whether all bytes in the mutable string are valid ASCII (values 0-127).

func (Mutable) IsNullTerminated

func (mut Mutable) IsNullTerminated() bool

IsNullTerminated reports whether the mutable string ends with a null byte (0x00), indicating C-style null termination.

func (Mutable) IsUnicode

func (mut Mutable) IsUnicode() bool

IsUnicode reports whether the mutable string contains only valid UTF-8 encoded Unicode characters.

func (*Mutable) Join

func (mut *Mutable) Join(mutables []Mutable, sep Mutable) *Mutable

Join appends all mutables from the slice separated by sep. Delegates to ExtendJoin(slices.Values(mutables), sep).

func (*Mutable) JoinStrings added in v0.14.8

func (mut *Mutable) JoinStrings(s []string, sep string)

JoinStrings writes all strings from s separated by sep to the mutable.

func (Mutable) LastIndex

func (mut Mutable) LastIndex(sep []byte) int

LastIndex returns the index of the last instance of 'sep' in the mutable string, or -1 if 'sep' is not present.

func (Mutable) LastIndexAny

func (mut Mutable) LastIndexAny(chars string) int

LastIndexAny returns the index of the last instance of any code point from 'chars' in the mutable string.

func (Mutable) LastIndexByte

func (mut Mutable) LastIndexByte(c byte) int

LastIndexByte returns the index of the last instance of 'c' in the mutable string, or -1 if 'c' is not present.

func (Mutable) LastIndexString

func (mut Mutable) LastIndexString(sep string) int

LastIndexString returns the index of the last instance of 'sep' in the mutable string, or -1 if 'sep' is not present.

func (Mutable) Len

func (mut Mutable) Len() int

Len returns the length of the mutable string.

func (*Mutable) Line added in v0.14.8

func (mut *Mutable) Line()

Line writes a single newline character to the mutable.

func (*Mutable) Map

func (mut *Mutable) Map(mapping func(rune) rune) *Mutable

Map modifies all characters according to the 'mapping' function, mutating in place. May allocate new storage if character widths change.

func (*Mutable) Mprint added in v0.14.8

func (mut *Mutable) Mprint(args ...any) *Mutable

Mprint formats args using default formatting and writes to the mutable. Analogous to fmt.Fprint.

func (*Mutable) Mprintf added in v0.14.8

func (mut *Mutable) Mprintf(tpl string, args ...any) *Mutable

Mprintf formats according to tpl and writes to the mutable. Analogous to fmt.Fprintf.

func (*Mutable) Mprintln added in v0.14.8

func (mut *Mutable) Mprintln(args ...any) *Mutable

Mprintln formats args using default formatting, appends a newline, and writes to the mutable. Analogous to fmt.Fprintln.

func (*Mutable) NLines added in v0.14.8

func (mut *Mutable) NLines(n int)

NLines writes n newline characters to the mutable. If n is negative, it is a no-op.

func (*Mutable) NTabs added in v0.14.8

func (mut *Mutable) NTabs(n int)

NTabs writes n tab characters to the mutable. If n is negative, it is a no-op.

func (Mutable) Print

func (mut Mutable) Print()

Print writes the contents of the mutable string to standard output.

func (Mutable) Println

func (mut Mutable) Println()

Println writes the context of the Mutable to standard output, adding a new line at the end.

func (*Mutable) Push added in v0.14.8

func (mut *Mutable) Push(next *Mutable) *Mutable

Push appends the contents of 'next' to this mutable string, mutating in place. May allocate if capacity is insufficient. Returns the receiver for method chaining.

func (*Mutable) PushBool added in v0.14.8

func (mut *Mutable) PushBool(v bool)

PushBool writes "true" or "false" to the mutable.

func (*Mutable) PushBytes added in v0.14.8

func (mut *Mutable) PushBytes(p []byte)

PushBytes appends the byte slice 'p' to the mutable string. May allocate if capacity is insufficient.

func (*Mutable) PushComplex added in v0.14.8

func (mut *Mutable) PushComplex(n complex128, tpl byte, prec, size int)

PushComplex writes the string representation of n to the mutable. The tpl parameter is the format ('b', 'e', 'E', 'f', 'g', 'G', 'x', 'X'), prec controls precision, and size is the total number of bits (64 or 128).

func (*Mutable) PushFloat added in v0.14.8

func (mut *Mutable) PushFloat(f float64, tpl byte, prec, size int)

PushFloat writes the string representation of f to the mutable. The tpl parameter is the format ('b', 'e', 'E', 'f', 'g', 'G', 'x', 'X'), prec controls precision, and size is the number of bits (32 or 64).

func (*Mutable) PushInt added in v0.14.8

func (mut *Mutable) PushInt(num int)

PushInt writes the decimal string representation of num to the mutable.

func (*Mutable) PushInt64 added in v0.14.8

func (mut *Mutable) PushInt64(n int64, base int)

PushInt64 writes the string representation of n in the given base to the mutable.

func (*Mutable) PushQuote added in v0.14.8

func (mut *Mutable) PushQuote(str string)

PushQuote writes a double-quoted Go string literal for str to the mutable.

func (*Mutable) PushQuoteASCII added in v0.14.8

func (mut *Mutable) PushQuoteASCII(str string)

PushQuoteASCII writes a double-quoted Go string literal for str, escaping non-ASCII.

func (*Mutable) PushQuoteGrapic added in v0.14.8

func (mut *Mutable) PushQuoteGrapic(str string)

PushQuoteGrapic writes a double-quoted Go string literal for str, escaping non-graphic chars.

func (*Mutable) PushQuoteRune added in v0.14.8

func (mut *Mutable) PushQuoteRune(r rune)

PushQuoteRune writes a single-quoted Go character literal for r to the mutable.

func (*Mutable) PushQuoteRuneASCII added in v0.14.8

func (mut *Mutable) PushQuoteRuneASCII(r rune)

PushQuoteRuneASCII writes a single-quoted Go character literal for r, escaping non-ASCII.

func (*Mutable) PushQuoteRuneGrapic added in v0.14.8

func (mut *Mutable) PushQuoteRuneGrapic(r rune)

PushQuoteRuneGrapic writes a single-quoted Go character literal for r, escaping non-graphic chars.

func (*Mutable) PushReplace added in v0.14.8

func (mut *Mutable) PushReplace(s, old, new []byte, n int)

PushReplace writes s with the first n non-overlapping instances of old replaced by new. If n is negative, all instances are replaced.

func (*Mutable) PushReplaceAll added in v0.14.8

func (mut *Mutable) PushReplaceAll(s, old, new []byte)

PushReplaceAll writes s with all non-overlapping instances of old replaced by new.

func (*Mutable) PushString added in v0.14.8

func (mut *Mutable) PushString(s string)

PushString appends string 's' to the mutable string. May allocate if capacity is insufficient.

func (*Mutable) PushTrimLeft added in v0.14.8

func (mut *Mutable) PushTrimLeft(str []byte, cut string)

PushTrimLeft writes str with leading characters in cut removed. bytes.TrimLeft returns a subslice of str (no allocation).

func (*Mutable) PushTrimPrefix added in v0.14.8

func (mut *Mutable) PushTrimPrefix(s, prefix []byte)

PushTrimPrefix writes s with the leading prefix removed. bytes.TrimPrefix returns a subslice of s (no allocation).

func (*Mutable) PushTrimRight added in v0.14.8

func (mut *Mutable) PushTrimRight(str []byte, cut string)

PushTrimRight writes str with trailing characters in cut removed. bytes.TrimRight returns a subslice of str (no allocation).

func (*Mutable) PushTrimSpace added in v0.14.8

func (mut *Mutable) PushTrimSpace(str []byte)

PushTrimSpace writes str with all leading and trailing whitespace removed. bytes.TrimSpace returns a subslice of str (no allocation).

func (*Mutable) PushTrimSuffix added in v0.14.8

func (mut *Mutable) PushTrimSuffix(s, suffix []byte)

PushTrimSuffix writes s with the trailing suffix removed. bytes.TrimSuffix returns a subslice of s (no allocation).

func (*Mutable) PushUint64 added in v0.14.8

func (mut *Mutable) PushUint64(n uint64, base int)

PushUint64 writes the string representation of n in the given base to the mutable.

func (Mutable) Reader

func (mut Mutable) Reader() io.Reader

Reader provides access to an io.Reader for reading from the mutable string.) Does not copy the underlying data.

func (*Mutable) Release

func (mut *Mutable) Release()

Release resets the Mutable and returns it to the pool for reuse. Any Mutable instance can be released, whether obtained from NewMutable(), MakeMutable(), or created directly. Buffers larger than 64KB are not returned to the pool to prevent excessive memory retention. After calling Release, the Mutable should not be used again.

func (*Mutable) Repeat

func (mut *Mutable) Repeat(count int) *Mutable

Repeat repeats the mutable string 'count' times, mutating in place. Uses zero-allocation in-place copy when sufficient capacity exists; otherwise allocates new storage for the repeated content.

func (*Mutable) RepeatByte added in v0.14.8

func (mut *Mutable) RepeatByte(char byte, n int)

RepeatByte writes byte 'char' to the mutable 'n' times. If 'n' is non-positive, the operation is a no-op.

func (*Mutable) RepeatLine added in v0.14.8

func (mut *Mutable) RepeatLine(ln string, n int)

RepeatLine writes string 'ln' followed by a newline to the mutable 'n' times. If 'n' is non-positive, the operation is a no-op.

func (*Mutable) RepeatRune added in v0.14.8

func (mut *Mutable) RepeatRune(r rune, n int)

RepeatRune writes rune 'r' to the mutable 'n' times. If 'n' is non-positive, the operation is a no-op.

func (*Mutable) Replace

func (mut *Mutable) Replace(old, new []byte, n int) *Mutable

Replace replaces the first 'n' non-overlapping instances of 'old' with 'new', mutating in place. Uses zero-allocation in-place replacement when sufficient capacity exists and replacement is same-length or smaller; otherwise allocates new storage.

func (*Mutable) ReplaceAll

func (mut *Mutable) ReplaceAll(old, new []byte) *Mutable

ReplaceAll replaces all non-overlapping instances of 'old' with 'new', mutating in place. Uses zero-allocation in-place replacement when sufficient capacity exists; otherwise allocates new storage.

func (*Mutable) ReplaceAllString

func (mut *Mutable) ReplaceAllString(old, new string) *Mutable

ReplaceAllString replaces all non-overlapping instances of 'old' with 'new', mutating in place. Uses zero-allocation in-place replacement when sufficient capacity exists; otherwise allocates.

func (*Mutable) ReplaceString

func (mut *Mutable) ReplaceString(old, new string, n int) *Mutable

ReplaceString replaces the first 'n' non-overlapping instances of 'old' with 'new', mutating in place. Uses zero-allocation in-place replacement when sufficient capacity exists; otherwise allocates.

func (*Mutable) Reset

func (mut *Mutable) Reset()

Reset resets the mutable string to be empty but retains the underlying storage.

func (Mutable) Split

func (mut Mutable) Split(sep Mutable) iter.Seq[Mutable]

Split returns an iterator that yields subslices separated by 'sep'. Zero allocation for the iterator itself; each yielded slice is a subslice of the original data (no copying).

func (Mutable) SplitAfter

func (mut Mutable) SplitAfter(sep Mutable) iter.Seq[Mutable]

SplitAfter returns an iterator that yields subslices after each instance of 'sep'. Each yielded slice includes the separator. Zero allocation for the iterator itself.

func (Mutable) SplitAfterString

func (mut Mutable) SplitAfterString(sep string) iter.Seq[Mutable]

SplitAfterString returns an iterator that yields subslices after each instance of 'sep'. Each yielded slice includes the separator. Zero allocation for the iterator itself.

func (Mutable) SplitString

func (mut Mutable) SplitString(sep string) iter.Seq[Mutable]

SplitString returns an iterator that yields subslices separated by 'sep'. Zero allocation for the iterator itself; each yielded slice is a subslice of the original data (no copying).

func (Mutable) String

func (mut Mutable) String() string

String returns the mutable string as a regular string. Allocates and copies the underlying bytes.

func (*Mutable) Tab added in v0.14.8

func (mut *Mutable) Tab()

Tab writes a single tab character to the mutable.

func (*Mutable) ToLower

func (mut *Mutable) ToLower() *Mutable

ToLower converts all Unicode letters to their lower case, mutating in place. Uses zero-allocation ASCII fast path when possible; only allocates new storage for non-ASCII Unicode content.

func (*Mutable) ToTitle

func (mut *Mutable) ToTitle() *Mutable

ToTitle converts all Unicode letters to their title case, mutating in place. Uses zero-allocation ASCII fast path when possible; only allocates new storage for non-ASCII Unicode content.

func (*Mutable) ToUpper

func (mut *Mutable) ToUpper() *Mutable

ToUpper converts all Unicode letters to their upper case, mutating in place. Uses zero-allocation ASCII fast path when possible; only allocates new storage for non-ASCII Unicode content.

func (*Mutable) Trim

func (mut *Mutable) Trim(cutset string) *Mutable

Trim slices off all leading and trailing UTF-8-encoded code points contained in 'cutset', mutating in place. Returns a subslice, no allocation.

func (*Mutable) TrimFunc

func (mut *Mutable) TrimFunc(f func(rune) bool) *Mutable

TrimFunc slices off all leading and trailing code points 'c' satisfying 'f(c)', mutating in place. Returns a subslice, no allocation.

func (*Mutable) TrimLeft

func (mut *Mutable) TrimLeft(cutset string) *Mutable

TrimLeft slices off all leading UTF-8-encoded code points contained in 'cutset', mutating in place. Returns a subslice, no allocation.

func (*Mutable) TrimLeftFunc

func (mut *Mutable) TrimLeftFunc(f func(rune) bool) *Mutable

TrimLeftFunc slices off all leading code points 'c' satisfying 'f(c)', mutating in place. Returns a subslice, no allocation.

func (*Mutable) TrimPrefix

func (mut *Mutable) TrimPrefix(prefix []byte) *Mutable

TrimPrefix removes the provided leading 'prefix', mutating in place. Returns a subslice, no allocation.

func (*Mutable) TrimPrefixString

func (mut *Mutable) TrimPrefixString(prefix string) *Mutable

TrimPrefixString removes the provided leading 'prefix' string, mutating in place. Returns a subslice, no allocation.

func (*Mutable) TrimRight

func (mut *Mutable) TrimRight(cutset string) *Mutable

TrimRight slices off all trailing UTF-8-encoded code points contained in 'cutset', mutating in place. Returns a subslice, no allocation.

func (*Mutable) TrimRightFunc

func (mut *Mutable) TrimRightFunc(f func(rune) bool) *Mutable

TrimRightFunc slices off all trailing code points 'c' satisfying 'f(c)', mutating in place. Returns a subslice, no allocation.

func (*Mutable) TrimSpace

func (mut *Mutable) TrimSpace() *Mutable

TrimSpace slices off all leading and trailing white space, mutating in place. Returns a subslice, no allocation.

func (*Mutable) TrimSuffix

func (mut *Mutable) TrimSuffix(suffix []byte) *Mutable

TrimSuffix removes the provided trailing 'suffix', mutating in place. Returns a subslice, no allocation.

func (*Mutable) TrimSuffixString

func (mut *Mutable) TrimSuffixString(suffix string) *Mutable

TrimSuffixString removes the provided trailing 'suffix' string, mutating in place. Returns a subslice, no allocation.

func (*Mutable) WhenConcat added in v0.14.8

func (mut *Mutable) WhenConcat(cond bool, strs ...string)

WhenConcat writes all strings in strs consecutively if cond is true.

func (*Mutable) WhenJoin added in v0.14.8

func (mut *Mutable) WhenJoin(cond bool, sl []string, sep string)

WhenJoin writes strings from sl joined by sep if cond is true.

func (*Mutable) WhenLine added in v0.14.8

func (mut *Mutable) WhenLine(cond bool)

WhenLine writes a newline if cond is true.

func (*Mutable) WhenMprint added in v0.14.8

func (mut *Mutable) WhenMprint(cond bool, args ...any) *Mutable

WhenMprint calls Mprint with args if cond is true.

func (*Mutable) WhenMprintf added in v0.14.8

func (mut *Mutable) WhenMprintf(cond bool, tpl string, args ...any) *Mutable

WhenMprintf calls Mprintf with tpl and args if cond is true.

func (*Mutable) WhenMprintln added in v0.14.8

func (mut *Mutable) WhenMprintln(cond bool, args ...any) *Mutable

WhenMprintln calls Mprintln with args if cond is true.

func (*Mutable) WhenNLines added in v0.14.8

func (mut *Mutable) WhenNLines(cond bool, n int)

WhenNLines writes n newlines if cond is true.

func (*Mutable) WhenNTabs added in v0.14.8

func (mut *Mutable) WhenNTabs(cond bool, n int)

WhenNTabs writes n tabs if cond is true.

func (*Mutable) WhenTab added in v0.14.8

func (mut *Mutable) WhenTab(cond bool)

WhenTab writes a tab if cond is true.

func (*Mutable) WhenWrite added in v0.14.8

func (mut *Mutable) WhenWrite(cond bool, buf []byte)

WhenWrite writes buf if cond is true.

func (*Mutable) WhenWriteByte added in v0.14.8

func (mut *Mutable) WhenWriteByte(cond bool, bt byte)

WhenWriteByte writes bt if cond is true.

func (*Mutable) WhenWriteLine added in v0.14.8

func (mut *Mutable) WhenWriteLine(cond bool, ln string)

WhenWriteLine writes ln followed by a newline if cond is true.

func (*Mutable) WhenWriteLines added in v0.14.8

func (mut *Mutable) WhenWriteLines(cond bool, lns ...string)

WhenWriteLines writes each string in lns on its own line if cond is true.

func (*Mutable) WhenWriteMutable added in v0.14.8

func (mut *Mutable) WhenWriteMutable(cond bool, m Mutable)

WhenWriteMutable writes m if cond is true.

func (*Mutable) WhenWriteMutableLine added in v0.14.8

func (mut *Mutable) WhenWriteMutableLine(cond bool, m Mutable)

WhenWriteMutableLine writes m followed by a newline if cond is true.

func (*Mutable) WhenWriteMutableLines added in v0.14.8

func (mut *Mutable) WhenWriteMutableLines(cond bool, ms ...Mutable)

WhenWriteMutableLines writes each Mutable in ms on its own line if cond is true.

func (*Mutable) WhenWriteRune added in v0.14.8

func (mut *Mutable) WhenWriteRune(cond bool, r rune)

WhenWriteRune writes r if cond is true.

func (*Mutable) WhenWriteString added in v0.14.8

func (mut *Mutable) WhenWriteString(cond bool, s string)

WhenWriteString writes s if cond is true.

func (*Mutable) WithReplace added in v0.14.8

func (mut *Mutable) WithReplace(s, old, new string, n int)

WithReplace writes s with the first n non-overlapping instances of old replaced by new. If n is negative, all instances are replaced.

func (*Mutable) WithReplaceAll added in v0.14.8

func (mut *Mutable) WithReplaceAll(s, old, new string)

WithReplaceAll writes s with all non-overlapping instances of old replaced by new.

func (*Mutable) WithTrimLeft added in v0.14.8

func (mut *Mutable) WithTrimLeft(str, cut string)

WithTrimLeft writes str with leading characters in cut removed.

func (*Mutable) WithTrimPrefix added in v0.14.8

func (mut *Mutable) WithTrimPrefix(s, prefix string)

WithTrimPrefix writes s with the leading prefix removed.

func (*Mutable) WithTrimRight added in v0.14.8

func (mut *Mutable) WithTrimRight(str, cut string)

WithTrimRight writes str with trailing characters in cut removed.

func (*Mutable) WithTrimSpace added in v0.14.8

func (mut *Mutable) WithTrimSpace(str string)

WithTrimSpace writes str with all leading and trailing whitespace removed.

func (*Mutable) WithTrimSuffix added in v0.14.8

func (mut *Mutable) WithTrimSuffix(s, suffix string)

WithTrimSuffix writes s with the trailing suffix removed.

func (*Mutable) Write

func (mut *Mutable) Write(p []byte) (n int, err error)

Write implements io.Writer, appending the contents of 'p' to the mutable string. May allocate if capacity is insufficient.

func (*Mutable) WriteByte

func (mut *Mutable) WriteByte(c byte) error

WriteByte appends a single byte 'c' to the mutable string. May allocate if capacity is insufficient.

func (*Mutable) WriteBytesLine added in v0.14.8

func (mut *Mutable) WriteBytesLine(ln []byte)

WriteBytesLine writes the byte slice ln followed by a newline to the mutable.

func (*Mutable) WriteBytesLines added in v0.14.8

func (mut *Mutable) WriteBytesLines(lns ...[]byte)

WriteBytesLines writes each byte slice in lns followed by a newline to the mutable.

func (*Mutable) WriteLine added in v0.14.8

func (mut *Mutable) WriteLine(ln string)

WriteLine writes string ln followed by a newline to the mutable.

func (*Mutable) WriteLines added in v0.14.8

func (mut *Mutable) WriteLines(lns ...string)

WriteLines writes each string in lns followed by a newline to the mutable.

func (*Mutable) WriteMutable added in v0.14.8

func (mut *Mutable) WriteMutable(m Mutable)

WriteMutable writes the Mutable m to the mutable.

func (*Mutable) WriteMutableLine added in v0.14.8

func (mut *Mutable) WriteMutableLine(m Mutable)

WriteMutableLine writes m followed by a newline to the mutable.

func (*Mutable) WriteMutableLines added in v0.14.8

func (mut *Mutable) WriteMutableLines(ms ...Mutable)

WriteMutableLines writes each Mutable in ms followed by a newline to the mutable.

func (*Mutable) WriteRune

func (mut *Mutable) WriteRune(r rune) (n int, err error)

WriteRune appends the UTF-8 encoding of rune 'r' to the mutable string. May allocate if capacity is insufficient.

func (*Mutable) WriteString

func (mut *Mutable) WriteString(s string) (n int, err error)

WriteString appends string 's' to the mutable string. May allocate if capacity is insufficient.

Jump to

Keyboard shortcuts

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