Unicode module

utf8_next_character

procedure · 1 overloadSource

Decodes the first character of s and removes it from the start of s. Returns its code point and how decoding went, as character_utf8_to_utf32 does without strict.

utf8_next_character :: (s: *string) -> (code: u32, success: Unicode_Result)

At the end of the string the result is the replacement character and SOURCE_EXHAUSTED and s is not changed. A character cut short at the end of s also gives SOURCE_EXHAUSTED and takes all the bytes left. Malformed bytes give the replacement character and SOURCE_ILLEGAL, and at least one byte is removed.

Parameters

s: *string

Returns

code: u32
ExampleOpen in playground ↗
text := "a\xc3\xa9";
code, status := utf8_next_character(*text);
assert(status == .CONVERSION_OK && code == #char "a");
code, status = utf8_next_character(*text);
assert(status == .CONVERSION_OK && code == 0xe9 && text.count == 0);

See also