strut

package
v0.14.7 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 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) Append

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

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

func (*Buffer) AppendBool

func (b *Buffer) AppendBool(v bool)

AppendBool writes "true" or "false" according to the value of 'v' to the buffer.

func (*Buffer) AppendFloat

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

AppendFloat 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) AppendInt64

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

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

func (*Buffer) AppendPrint

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

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

func (*Buffer) AppendPrintf

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

AppendPrintf 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) AppendPrintln

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

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

func (*Buffer) AppendQuote

func (b *Buffer) AppendQuote(str string)

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

func (*Buffer) AppendQuoteASCII

func (b *Buffer) AppendQuoteASCII(str string)

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

func (*Buffer) AppendQuoteGrapic

func (b *Buffer) AppendQuoteGrapic(str string)

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

func (*Buffer) AppendQuoteRune

func (b *Buffer) AppendQuoteRune(r rune)

AppendQuoteRune 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) AppendQuoteRuneASCII

func (b *Buffer) AppendQuoteRuneASCII(r rune)

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

func (*Buffer) AppendQuoteRuneGrapic

func (b *Buffer) AppendQuoteRuneGrapic(r rune)

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

func (*Buffer) AppendReplace

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

AppendReplace 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) AppendReplaceAll

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

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

func (*Buffer) AppendTrimLeft

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

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

func (*Buffer) AppendTrimPrefix

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

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

func (*Buffer) AppendTrimRight

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

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

func (*Buffer) AppendTrimSpace

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

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

func (*Buffer) AppendTrimSuffix

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

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

func (*Buffer) AppendUint64

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

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

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) FormatBool

func (b *Buffer) FormatBool(v bool)

FormatBool writes "true" or "false" according to the value of 'v' to the buffer.

func (*Buffer) FormatComplex

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

FormatComplex 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) FormatFloat

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

FormatFloat 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) FormatInt64

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

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

func (*Buffer) FormatUint64

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

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

func (*Buffer) Int

func (b *Buffer) Int(num int)

Int writes the decimal string representation of 'num' to the buffer.

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) Quote

func (b *Buffer) Quote(str string)

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

func (*Buffer) QuoteASCII

func (b *Buffer) QuoteASCII(str string)

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

func (*Buffer) QuoteGrapic

func (b *Buffer) QuoteGrapic(str string)

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

func (*Buffer) QuoteRune

func (b *Buffer) QuoteRune(r rune)

QuoteRune 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) QuoteRuneASCII

func (b *Buffer) QuoteRuneASCII(r rune)

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

func (*Buffer) QuoteRuneGrapic

func (b *Buffer) QuoteRuneGrapic(r rune)

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

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) WhenAppendPrint

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

WhenAppendPrint calls AppendPrint with 'args' if 'cond' is true and is a no-op otherwise.

func (*Buffer) WhenAppendPrintf

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

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

func (*Buffer) WhenAppendPrintln

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

WhenAppendPrintln calls AppendPrintln 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) Append

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

Append 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) AppendBool

func (b *Builder) AppendBool(v bool)

AppendBool writes "true" or "false" according to the value of 'v' to the builder. This method uses strconv.AppendBool which may be more efficient than FormatBool for avoiding intermediate string allocations in some cases. Functionally equivalent to FormatBool.

func (*Builder) AppendFloat

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

AppendFloat 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). This method uses strconv.AppendFloat which may be more efficient than FormatFloat for avoiding intermediate string allocations in some cases. Functionally equivalent to FormatFloat.

func (*Builder) AppendInt64

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

AppendInt64 writes the string representation of 'n' in the given 'base' to the builder. The 'base' must be between 2 and 36 inclusive. This method uses strconv.AppendInt which may be more efficient than FormatInt64 for avoiding intermediate string allocations in some cases. Functionally equivalent to FormatInt64.

func (*Builder) AppendPrint

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

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

func (*Builder) AppendPrintf

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

AppendPrintf 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) AppendPrintln

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

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

func (*Builder) AppendQuote

func (b *Builder) AppendQuote(str string)

AppendQuote writes a double-quoted Go string literal representing 'str' to the builder. The output includes surrounding quotes and uses Go escape sequences. This method uses strconv.AppendQuote which may be more efficient than Quote for avoiding intermediate string allocations in some cases.

func (*Builder) AppendQuoteASCII

func (b *Builder) AppendQuoteASCII(str string)

AppendQuoteASCII writes a double-quoted Go string literal representing 'str' to the builder. Non-ASCII characters are escaped using \u or \U sequences. This method uses strconv.AppendQuoteToASCII which may be more efficient than QuoteASCII for avoiding intermediate string allocations in some cases.

func (*Builder) AppendQuoteGrapic

func (b *Builder) AppendQuoteGrapic(str string)

AppendQuoteGrapic writes a double-quoted Go string literal representing 'str' to the builder. Non-graphic characters as defined by unicode.IsGraphic are escaped. This method uses strconv.AppendQuoteToGraphic which may be more efficient than QuoteGrapic for avoiding intermediate string allocations in some cases.

func (*Builder) AppendQuoteRune

func (b *Builder) AppendQuoteRune(r rune)

AppendQuoteRune writes a single-quoted Go character literal representing 'r' to the builder. The output includes surrounding single quotes and uses Go escape sequences. This method uses strconv.AppendQuoteRune which may be more efficient than QuoteRune for avoiding intermediate string allocations in some cases.

func (*Builder) AppendQuoteRuneASCII

func (b *Builder) AppendQuoteRuneASCII(r rune)

AppendQuoteRuneASCII writes a single-quoted Go character literal representing 'r' to the builder. Non-ASCII characters are escaped using \u or \U sequences. This method uses strconv.AppendQuoteRuneToASCII which may be more efficient than QuoteRuneASCII for avoiding intermediate string allocations in some cases.

func (*Builder) AppendQuoteRuneGrapic

func (b *Builder) AppendQuoteRuneGrapic(r rune)

AppendQuoteRuneGrapic writes a single-quoted Go character literal representing 'r' to the builder. Non-graphic characters as defined by unicode.IsGraphic are escaped. This method uses strconv.AppendQuoteRuneToGraphic which may be more efficient than QuoteRuneGrapic for avoiding intermediate string allocations in some cases.

func (*Builder) AppendReplace

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

AppendReplace 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) AppendReplaceAll

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

AppendReplaceAll 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) AppendTrimLeft

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

AppendTrimLeft 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) AppendTrimPrefix

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

AppendTrimPrefix 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) AppendTrimRight

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

AppendTrimRight 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) AppendTrimSpace

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

AppendTrimSpace 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) AppendTrimSuffix

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

AppendTrimSuffix 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) AppendUint64

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

AppendUint64 writes the string representation of 'n' in the given 'base' to the builder. The 'base' must be between 2 and 36 inclusive. This method uses strconv.AppendUint which may be more efficient than FormatUint64 for avoiding intermediate string allocations in some cases. Functionally equivalent to FormatUint64.

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) FormatBool

func (b *Builder) FormatBool(v bool)

FormatBool writes "true" or "false" according to the value of 'v' to the builder.

func (*Builder) FormatComplex

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

FormatComplex 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) FormatFloat

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

FormatFloat 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) FormatInt64

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

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

func (*Builder) FormatUint64

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

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

func (*Builder) Int

func (b *Builder) Int(num int)

Int writes the decimal string representation of 'num' to the builder.

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) Quote

func (b *Builder) Quote(str string)

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

func (*Builder) QuoteASCII

func (b *Builder) QuoteASCII(str string)

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

func (*Builder) QuoteGrapic

func (b *Builder) QuoteGrapic(str string)

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

func (*Builder) QuoteRune

func (b *Builder) QuoteRune(r rune)

QuoteRune 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) QuoteRuneASCII

func (b *Builder) QuoteRuneASCII(r rune)

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

func (*Builder) QuoteRuneGrapic

func (b *Builder) QuoteRuneGrapic(r rune)

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

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) WhenAppendPrint

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

WhenAppendPrint calls AppendPrint with 'args' if 'cond' is true and is a no-op otherwise.

func (*Builder) WhenAppendPrintf

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

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

func (*Builder) WhenAppendPrintln

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

WhenAppendPrintln calls AppendPrintln 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) Append

func (mut *Mutable) Append(next *Mutable) *Mutable

Append 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) 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) 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) 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) 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) 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) 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) 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) 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) 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) 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) 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) 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) 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