StringBuilder¶
No import is needed.
Read the usage guide for examples and common tasks. This reference lists the public declarations for this part of the library. See Reading API signatures for parameter and result notation.
StringBuilder¶
StringBuilder — growable UTF-16 string construction. Lives in the bootstrap core so every package (collections included) can build strings in O(n); always available without imports.
constructor¶
Allocates an empty builder with an initial backing buffer capacity in payload bytes (defaults to 16).
length¶
Number of UTF-16 code units appended so far (count is always even).
is_empty¶
True when nothing has been appended yet.
append_char¶
Appends a Unicode scalar as one or two UTF-16 units.
append¶
Appends every UTF-16 unit of text, growing at most once.
append¶
Appends the units a ReadOnlySpan<char> views, with no intermediate string.
append_utf8_slice¶
Appends byte_len payload bytes starting at byte index start of text.
append_int¶
Appends a decimal integer without allocating an intermediate string.
append_bool¶
Appends "true" or "false" without allocating an intermediate string.
append_long¶
Appends a decimal long without allocating an intermediate string.
append_double¶
Appends the same text as n.to_string() without allocating an intermediate string.
append_line¶
Appends text followed by a newline character.
clear¶
Removes every appended character, keeping the backing buffer for reuse.
as_span¶
A view of everything appended so far, without copying the units. Later appends and clear leave the view unchanged: it is a snapshot.
build¶
Snapshot into a new string. from_builder copies once; do not stage through a second byte[] (that doubled the finish memcpy).
to_string¶
Supplies text to object formatting. Use build() when finishing a builder.