string/builder

sourcestring/builder.sx

ensure_cap

private
fn ensure_cap(ptr: ref void, needed: i64) void = trust { ... }

Ensure capacity (private helper)

StringBuilder

pub type StringBuilder = { ptr: ref u8, len: i64, cap: i64 }

The almighty str.String builder

Fields

NameType
ptrref u8
leni64
capi64

new

pub fn (StringBuilder) new() StringBuilder

Create a new empty StringBuilder

append

pub fn (StringBuilder) append(sb: StringBuilder, v: str.StringView) void = trust { ... }

Append a borrowed string view to the builder.

append_string

pub fn (StringBuilder) append_string(sb: StringBuilder, s: str.String) void = trust { ... }

Append an owned str.String to the builder.

append_cstr

pub fn (StringBuilder) append_cstr(sb: StringBuilder, cstr: ref u8) void = trust { ... }

Append a C string to the builder

build

pub fn (StringBuilder) build(sb: StringBuilder) str.String = trust { ... }

Build — returns a new heap-allocated str.String with the accumulated content

free

pub fn (StringBuilder) free(sb: StringBuilder) void = trust { ... }

Free the StringBuilder's internal buffer and header

append_char

pub fn (StringBuilder) append_char(sb: StringBuilder, c: u8) void = trust { ... }

Append a single byte character

clear

pub fn (StringBuilder) clear(sb: StringBuilder) void = trust { ... }

Clear the builder (reset length to 0, keep allocation)