Skip to content

std.utf8

strict utf-8 decode/encode/validate; a bad byte decodes as REPLACEMENT, len 1

pub REPLACEMENT :: 0xFFFDu32

U+FFFD, what a bad byte decodes to

pub Decoded :: struct {
rune: u32,
len: usize,
}

rune + bytes used

pub decode :: fn(s: []const u8) -> Decoded

rune at the start of s; REPLACEMENT, 1 for a bad sequence; s must not be empty

pub encoded_len :: fn(r: u32) -> usize

utf-8 length of r, 1..4; 0 if not a rune (surrogate or > U+10FFFF)

pub encode :: fn(out: []u8, r: u32) -> usize

encode r into out; its len, or 0 and nothing written if invalid or too short

pub valid :: fn(s: []const u8) -> bool

all of s is valid utf-8

pub count :: fn(s: []const u8) -> usize

rune count; each bad byte counts as one

pub Runes :: struct {
rest: []const u8,
}

iterator from runes

pub next :: fn(self: *Self) -> ?u32
pub runes :: fn(s: []const u8) -> Runes

iterate the runes of s

pub is_continuation :: fn(b: u8) -> bool

b is a continuation byte (10xxxxxx)