Skip to content
FutureBlitz

    Install

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

    std/text/builder.fb, line 31

    • Public New() constructor #

      An empty one.

    • Public New(text: String) constructor #

      One that starts with text.

    • Public Property Length: Int property #

      How many bytes its text has, which is also the position just past its end.

    • @PanicsAtCaller Public Method Append(text: String): StringBuilder method #

      Adds text at the end, and gives the StringBuilder, for another call after it. Each Append, AppendLine, Insert, and [] that makes the text longer than a String holds panics.

    • @PanicsAtCaller Public Method Append(c: Char): StringBuilder method #

      Adds c at the end.

    • @PanicsAtCaller Public Method Append<T: Printable>(value: T): StringBuilder method #

      Adds the value's text at the end, as "{value}" shows it.

    • @PanicsAtCaller Public Method AppendLine(text: String = ""): StringBuilder method #

      Adds text, then a line break, "\n", at the end.

    • @PanicsAtCaller Public Method Insert(at: Int, text: String): StringBuilder method #

      Puts text in at the position at. Panics unless at is a position in the text, between two characters.

    • @PanicsAtCaller Public Method Remove(start: Int, finish: Int): StringBuilder method #

      Takes out the text from start up to finish. Panics unless both are positions in the text, between characters, with start no later than finish.

    • @PanicsAtCaller Public Method Replace(old: String, replacement: String): StringBuilder method #

      Replaces each old, from the start, with replacement. An empty old panics.

    • Public Method Clear(): StringBuilder method #

      Takes out all its text, and the first bytes of a character Write has had.

    • Public Method Write(from: Buffer<UInt8>) Throws IOError method #

      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.

    • Public Method Flush() Throws IOError method #

      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.

    • @PanicsAtCaller Public Method Reserve(bytes: Int) method #

      Makes room for bytes bytes of text in all, so adding up to that many needs no more memory. A negative count panics.

    • Public Method ToString(): String method #

      The text it has built.

    • @PanicsAtCaller Operator [](at: Int): Char operator #

      The Char whose first byte is at the position at. Panics unless at is a position in the text, between characters, before its end.

    • @PanicsAtCaller Operator []=(at: Int, value: Char) operator #

      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.