DefaultStringInterpolation

public struct DefaultStringInterpolation { /* private fields */ }

The default Interpolatable accumulator used for String interpolation.

Stores each literal and each formatted interpolation as a separate String part, then concatenates them in build(). The two-pass design lets build() size the result buffer exactly, avoiding the repeated reallocation cost a single-buffer accumulator would pay.

Examples

var acc = DefaultStringInterpolation(literalCapacity: 7, interpolationCount: 1); acc.appendLiteral("hello, "); acc.appendInterpolation("world", options: FormatOptions.default()); acc.build(); // "hello, world"

Representation

A single StringBuilder that accumulates all literal and formatted bytes in one buffer. Pre-sized using the compiler's capacity hints.

Initializers

public init(literalCapacity: Int64, interpolationCount: Int64)

Constructs an empty accumulator pre-sized from compile-time hints.

literalCapacity is the exact byte count of static segments; interpolationCount estimates ~16 bytes per hole.

Examples

var acc = DefaultStringInterpolation(literalCapacity: 0, interpolationCount: 0); acc.build(); // ""

Methods

public mutating func appendInterpolation[__opaque_0](__opaque_0, FormatOptions) where __opaque_0: Formattable

Formats one interpolation hole directly into the buffer.

public mutating func build() -> String

Transfers the buffer into a String without copying.

Examples

var acc = DefaultStringInterpolation(literalCapacity: 0, interpolationCount: 0); acc.appendLiteral("a"); acc.appendLiteral("b"); acc.build(); // "ab"

ImplementsInterpolatable

Initializers

init(literalCapacity: Int64, interpolationCount: Int64)

Constructs an empty accumulator with capacity hints derived from the literal at compile time.

literalCapacity is the total byte count of the static segments; interpolationCount is the number of \{...} holes. Implementors can use these to preallocate.

Methods

public mutating func appendLiteral(String)

Appends a static literal segment directly into the buffer.

ImplementsCloneable

Methods

public func clone() -> DefaultStringInterpolation

Returns a copy with a cloned builder buffer.

Defined in lang/std/text/format.ks