std.strings
arena-backed StringBuilder (also a Writer) and byte-string helpers
StringBuilder
Section titled “StringBuilder”pub StringBuilder :: struct { arena: *Arena, buf: []u8, n: usize, indent_level: usize,}buf: backing storage; cap == buf.lenn: bytes written; notlen, that’s the methodindent_level: indentation depth (no indent/dedent fns exist)
builder
Section titled “builder”pub builder :: fn(a: *Arena) -> StringBuilderstorage lives in a, outlives the builder
builder_cap
Section titled “builder_cap”pub builder_cap :: fn(a: *Arena, cap: usize) -> StringBuilderreserves at least cap bytes
pub from :: fn(a: *Arena, s: []const u8) -> StringBuilderstarts with a copy of s
sb_grow
Section titled “sb_grow”pub sb_grow :: fn(self: *StringBuilder, extra: usize)room for extra more bytes; doubles, or grows to fit
append
Section titled “append”pub append :: fn(self: *StringBuilder, s: []const u8)append_byte
Section titled “append_byte”pub append_byte :: fn(self: *StringBuilder, c: u8)append_repeat
Section titled “append_repeat”pub append_repeat :: fn(self: *StringBuilder, c: u8, n: usize)n copies of c
append_rune
Section titled “append_rune”pub append_rune :: fn(self: *StringBuilder, cp: u32)utf-8 encoded; U+FFFD for a surrogate or past U+10FFFF
append_u64
Section titled “append_u64”pub append_u64 :: fn(self: *StringBuilder, v: u64)append_i64
Section titled “append_i64”pub append_i64 :: fn(self: *StringBuilder, v: i64)append_base
Section titled “append_base”pub append_base :: fn(self: *StringBuilder, v: u64, base: u8)base 2..36
append_hex
Section titled “append_hex”pub append_hex :: fn(self: *StringBuilder, v: u64)append_bin
Section titled “append_bin”pub append_bin :: fn(self: *StringBuilder, v: u64)append_hex_byte
Section titled “append_hex_byte”pub append_hex_byte :: fn(self: *StringBuilder, v: u8)always two lowercase hex digits
append_u64_pad
Section titled “append_u64_pad”pub append_u64_pad :: fn(self: *StringBuilder, v: u64, width: usize, pad: u8)decimal, left-padded with pad to width
append_bool
Section titled “append_bool”pub append_bool :: fn(self: *StringBuilder, b: bool)pub str :: fn(self: *StringBuilder) -> []const u8view into the buffer; invalid after the next grow
pub len :: fn(self: *StringBuilder) -> usizepub cap :: fn(self: *StringBuilder) -> usizeis_empty
Section titled “is_empty”pub is_empty :: fn(self: *StringBuilder) -> boolbyte_at
Section titled “byte_at”pub byte_at :: fn(self: *StringBuilder, i: usize) -> u8pub clear :: fn(self: *StringBuilder)keeps capacity
truncate
Section titled “truncate”pub truncate :: fn(self: *StringBuilder, n: usize)keeps the first n bytes
pub pop :: fn(self: *StringBuilder) -> ?u8null if empty
set_byte
Section titled “set_byte”pub set_byte :: fn(self: *StringBuilder, i: usize, c: u8)append_f64
Section titled “append_f64”pub append_f64 :: fn(self: *StringBuilder, v: f64)6 places, truncating; not shortest round-trip
append_f64_prec
Section titled “append_f64_prec”pub append_f64_prec :: fn(self: *StringBuilder, v: f64, prec: usize)append_f64_min
Section titled “append_f64_min”pub append_f64_min :: fn(self: *StringBuilder, v: f64)append_f64 without trailing zeros or bare dot (2.0 -> “2”); minimal json numbers
str_eq
Section titled “str_eq”pub str_eq :: fn(a: []const u8, b: []const u8) -> boolstr_starts_with
Section titled “str_starts_with”pub str_starts_with :: fn(s: []const u8, prefix: []const u8) -> boolstr_ends_with
Section titled “str_ends_with”pub str_ends_with :: fn(s: []const u8, suffix: []const u8) -> boolstr_index_of
Section titled “str_index_of”pub str_index_of :: fn(s: []const u8, needle: []const u8) -> ?usizefirst index of needle, or null
str_contains
Section titled “str_contains”pub str_contains :: fn(s: []const u8, needle: []const u8) -> boolstr_count_byte
Section titled “str_count_byte”pub str_count_byte :: fn(s: []const u8, c: u8) -> usizeis_digit
Section titled “is_digit”pub is_digit :: fn(c: u8) -> boolis_upper
Section titled “is_upper”pub is_upper :: fn(c: u8) -> boolis_lower
Section titled “is_lower”pub is_lower :: fn(c: u8) -> boolis_alpha
Section titled “is_alpha”pub is_alpha :: fn(c: u8) -> boolis_alnum
Section titled “is_alnum”pub is_alnum :: fn(c: u8) -> boolis_space
Section titled “is_space”pub is_space :: fn(c: u8) -> boolto_upper_byte
Section titled “to_upper_byte”pub to_upper_byte :: fn(c: u8) -> u8to_lower_byte
Section titled “to_lower_byte”pub to_lower_byte :: fn(c: u8) -> u8str_trim_left
Section titled “str_trim_left”pub str_trim_left :: fn(s: []const u8) -> []const u8str_trim_right
Section titled “str_trim_right”pub str_trim_right :: fn(s: []const u8) -> []const u8str_trim
Section titled “str_trim”pub str_trim :: fn(s: []const u8) -> []const u8str_eq_ignore_case
Section titled “str_eq_ignore_case”pub str_eq_ignore_case :: fn(a: []const u8, b: []const u8) -> boolstr_dup
Section titled “str_dup”pub str_dup :: fn(a: *Arena, s: []const u8) -> []const u8str_concat
Section titled “str_concat”pub str_concat :: fn(a: *Arena, x: []const u8, y: []const u8) -> []const u8str_repeat
Section titled “str_repeat”pub str_repeat :: fn(a: *Arena, s: []const u8, count: usize) -> []const u8str_upper
Section titled “str_upper”pub str_upper :: fn(a: *Arena, s: []const u8) -> []const u8str_lower
Section titled “str_lower”pub str_lower :: fn(a: *Arena, s: []const u8) -> []const u8str_replace
Section titled “str_replace”pub str_replace :: fn(a: *Arena, s: []const u8, from: []const u8, to: []const u8) -> []const u8left to right, non-overlapping
str_join
Section titled “str_join”pub str_join :: fn(a: *Arena, parts: []const []const u8, sep: []const u8) -> []const u8str_last_index_of
Section titled “str_last_index_of”pub str_last_index_of :: fn(s: []const u8, needle: []const u8) -> ?usizestr_count
Section titled “str_count”pub str_count :: fn(s: []const u8, needle: []const u8) -> usizenon-overlapping
pub split :: fn(s: []const u8, sep: []const u8) -> mem::Split(u8)parts between seps, empty ones included
fields
Section titled “fields”pub fields :: fn(s: []const u8) -> mem::Tokens(u8)words between runs of spaces, tabs, line breaks
pub Lines :: struct { rest: []const u8,}lines without \n or \r\n; no empty line after a final break
Lines.next
Section titled “Lines.next”pub next :: fn(self: *Self) -> ?[]const u8pub lines :: fn(s: []const u8) -> Lines