std.utf8
strict utf-8 decode/encode/validate; a bad byte decodes as REPLACEMENT, len 1
REPLACEMENT
Section titled “REPLACEMENT”pub REPLACEMENT :: 0xFFFDu32U+FFFD, what a bad byte decodes to
Decoded
Section titled “Decoded”pub Decoded :: struct { rune: u32, len: usize,}rune + bytes used
decode
Section titled “decode”pub decode :: fn(s: []const u8) -> Decodedrune at the start of s; REPLACEMENT, 1 for a bad sequence; s must not be empty
encoded_len
Section titled “encoded_len”pub encoded_len :: fn(r: u32) -> usizeutf-8 length of r, 1..4; 0 if not a rune (surrogate or > U+10FFFF)
encode
Section titled “encode”pub encode :: fn(out: []u8, r: u32) -> usizeencode r into out; its len, or 0 and nothing written if invalid or too short
pub valid :: fn(s: []const u8) -> boolall of s is valid utf-8
pub count :: fn(s: []const u8) -> usizerune count; each bad byte counts as one
pub Runes :: struct { rest: []const u8,}iterator from runes
Runes.next
Section titled “Runes.next”pub next :: fn(self: *Self) -> ?u32pub runes :: fn(s: []const u8) -> Runesiterate the runes of s
is_continuation
Section titled “is_continuation”pub is_continuation :: fn(b: u8) -> boolb is a continuation byte (10xxxxxx)