Import std.text.builder
std.text.builder
StringBuilder: text built up a piece at a time, in a buffer of its UTF-8 bytes that grows as pieces come, so building a String of many pieces takes time in proportion to its length, where joining them one by one would copy it each time. Positions are byte offsets, as a String's are, and one inside a character panics. It's a std.io Writer too, whose bytes it adds as text.
std/text/builder.fb
Types
StringBuilder
class
Public Class StringBuilder Implements Printable, Writer
Text built up a piece at a time, in a buffer of its UTF-8 bytes that grows as pieces come.
Examples
Local text = StringBuilder()
For i = 1 To 3
text.Append(i).Append(i < 3 ? ", " : "")
End For
Expect(text.ToString() == "1, 2, 3")-
An empty one.
-
One that starts with
text. -
How many bytes its text has, which is also the position just past its end.
-
Adds
textat the end, and gives the StringBuilder, for another call after it. Each Append, AppendLine, Insert, and [] that makes thetextlonger than a String holds panics. -
Adds
cat the end. -
Adds the
value's text at the end, as "{value}" shows it. -
Adds
text, then a line break, "\n", at the end. -
Puts
textin at the position at. Panics unless at is a position in thetext, between two characters. -
Takes out the text from
startup tofinish. Panics unless both are positions in the text, between characters, withstartno later thanfinish. -
Replaces each old, from the start, with
replacement. An emptyoldpanics. -
Takes out all its text, and the first bytes of a character Write has had.
-
Adds from's bytes as text, U+FFFD for each one that doesn't start well-formed UTF-8, as std.io's StringWriter reads them. A character whose bytes two Writes split is added once its last byte comes; until then, Flush, or a change of another kind, adds what came of it as U+FFFD. Throws an IOError past the most a String holds, adding none of it.
-
Adds what Write has had of a character whose last bytes haven't come, as U+FFFD. Throws an IOError past the most a String holds, as Write does, keeping them.
-
Makes room for
bytesbytes of text in all, so adding up to that many needs no more memory. A negative count panics. -
The text it has built.
-
The Char whose first byte is at the position at. Panics unless at is a position in the text, between characters, before its end.
-
Replaces the Char at the position at with value, whose bytes may be more or fewer. Panics unless at is a position in the text, between characters, before its end.
Report an issue with this page or with FutureBlitz on GitHub.