Import with #import "std/utf8".

Continuation :: (byte: u8) -> bool
Decoded :: struct { value: u32; after: s32; valid: bool; }
CopyResult :: struct { count: s64; complete: bool; }
Decode :: (text: string, at: s32) -> Decoded

Decode one scalar. A malformed sequence consumes its lead byte and yields U+FFFD so callers can continue scanning without splitting valid text.

Valid :: (text: string) -> bool

Validate every byte without allocating or decoding ordinary ASCII scalars. Multibyte windows borrow at most four bytes, keeping Decode's absolute 32-bit offset independent of the size of the complete string.

Count :: (value: string) -> s32
Copy :: (source: []u8, destination: []u8) -> CopyResult

Copy valid UTF-8 byte-for-byte into a separate bounded destination. Invalid input follows Decode: consume only the malformed lead byte and append one UTF-8 replacement character. Stop before a source sequence or replacement would be split; report the bytes written and whether all input was consumed.

DecodeReplace :: (source: []u8) -> Text

Decode a whole byte string with Python UTF-8 errors='replace' consumption: replace each maximal valid prefix of an ill-formed sequence once. A valid but truncated E2 82 is one replacement; forbidden ED A0 80 is three. The result has independent immutable storage and is always valid UTF-8. Decode and Copy retain their consume-one-malformed-lead contracts.

Source ↗ · All modules