REPLACEMENT_CHARACTER
pub val REPLACEMENT_CHARACTER = 0xfffdThe Unicode replacement character, U+FFFD.
pub val REPLACEMENT_CHARACTER = 0xfffdThe Unicode replacement character, U+FFFD.
pub val MAX_CODEPOINT = 0x10ffffThe largest valid Unicode code point, U+10FFFF.
pub val HIGH_SURROGATE_START = 0xd800The first high-surrogate code unit.
pub val LOW_SURROGATE_END = 0xdfffThe last low-surrogate code unit.
fn make_decoded(codepoint: u32, size: i64) u64pub fn decoded_codepoint(decoded: u64) u32Extract the code point from a value returned by utf8_decode or utf16_decode.
pub fn decoded_size(decoded: u64) i64Extract the number of UTF-8 bytes or UTF-16 code units consumed from a value returned by utf8_decode or utf16_decode.
pub enum UnicodeError = { InvalidUtf8, Truncated, InvalidCodepoint, InvalidUtf16, BufferTooSmall, InvalidIndex, OutOfMemory }Errors produced by the UTF-8 and UTF-16 routines.
InvalidUtf8TruncatedInvalidCodepointInvalidUtf16BufferTooSmallInvalidIndexOutOfMemorypub enum Category = { UppercaseLetter, LowercaseLetter, TitlecaseLetter, ModifierLetter, OtherLetter, NonspacingMark, SpacingMark, EnclosingMark, DecimalNumber, LetterNumber, OtherNumber, ConnectorPunctuation, DashPunctuation, OpenPunctuation, ClosePunctuation, InitialPunctuation, FinalPunctuation, OtherPunctuation, MathSymbol, CurrencySymbol, ModifierSymbol, OtherSymbol, SpaceSeparator, LineSeparator, ParagraphSeparator, Control, Format, Surrogate, PrivateUse, Unassigned }The Unicode general category of a code point.
UppercaseLetterLowercaseLetterTitlecaseLetterModifierLetterOtherLetterNonspacingMarkSpacingMarkEnclosingMarkDecimalNumberLetterNumberOtherNumberConnectorPunctuationDashPunctuationOpenPunctuationClosePunctuationInitialPunctuationFinalPunctuationOtherPunctuationMathSymbolCurrencySymbolModifierSymbolOtherSymbolSpaceSeparatorLineSeparatorParagraphSeparatorControlFormatSurrogatePrivateUseUnassignedfn is_continuation(byte: u32) boolpub fn is_valid_codepoint(cp: u32) boolReturn true when cp is a Unicode scalar value.
Surrogate code points and values above U+10FFFF are not scalar values.
pub fn is_surrogate(cp: u32) boolReturn true when cp is in the UTF-16 surrogate range.
pub fn is_ascii(cp: u32) boolReturn true when cp is an ASCII code point (U+0000..=U+007F).
pub fn is_ascii_digit(cp: u32) boolReturn true when cp is an ASCII decimal digit.
pub fn is_ascii_alpha(cp: u32) boolReturn true when cp is an ASCII letter.
pub fn is_ascii_alphanumeric(cp: u32) boolReturn true when cp is an ASCII letter or digit.
pub fn is_ascii_hex_digit(cp: u32) boolReturn true when cp is an ASCII hexadecimal digit.
pub fn is_ascii_whitespace(cp: u32) boolReturn true when cp is an ASCII whitespace character.
pub fn is_ascii_control(cp: u32) boolReturn true when cp is an ASCII control character.
fn category_code(cp: u32) u8pub fn category(cp: u32) CategoryReturn the Unicode general category of cp.
Unassigned code points and invalid scalar values both report Category.Unassigned.
pub fn is_letter(cp: u32) boolReturn true when cp is a letter (categories Lu, Ll, Lt, Lm, Lo).
pub fn is_alphabetic(cp: u32) boolAlias for is_letter.
pub fn is_uppercase(cp: u32) boolReturn true when cp is an uppercase letter.
pub fn is_lowercase(cp: u32) boolReturn true when cp is a lowercase letter.
pub fn is_digit(cp: u32) boolReturn true when cp is a decimal digit (category Nd).
pub fn is_decimal(cp: u32) boolAlias for is_digit.
pub fn is_numeric(cp: u32) boolReturn true when cp is any kind of numeric character (Nd, Nl, No).
pub fn is_alphanumeric(cp: u32) boolReturn true when cp is a letter or a number.
pub fn is_mark(cp: u32) boolReturn true when cp is a combining mark (Mn, Mc, Me).
pub fn is_punctuation(cp: u32) boolReturn true when cp is a punctuation character (category P*).
pub fn is_symbol(cp: u32) boolReturn true when cp is a symbol (category S*).
pub fn is_separator(cp: u32) boolReturn true when cp is a separator (category Z*).
pub fn is_control(cp: u32) boolReturn true when cp is a control character (category Cc).
pub fn is_format(cp: u32) boolReturn true when cp is a format character (category Cf).
pub fn is_private_use(cp: u32) boolReturn true when cp is a private-use character (category Co).
pub fn is_whitespace(cp: u32) boolReturn true when cp has the Unicode White_Space property.
pub fn is_space(cp: u32) boolAlias for is_whitespace.
fn find_upper(cp: u32) u32fn find_lower(cp: u32) u32fn find_title(cp: u32) u32fn find_fold(cp: u32) u32pub fn to_upper(cp: u32) u32Return the simple uppercase mapping of cp, or cp when it has none.
pub fn to_uppercase(cp: u32) u32Alias for to_upper.
pub fn to_lower(cp: u32) u32Return the simple lowercase mapping of cp, or cp when it has none.
pub fn to_lowercase(cp: u32) u32Alias for to_lower.
pub fn to_title(cp: u32) u32Return the simple titlecase mapping of cp, or cp when it has none.
pub fn to_titlecase(cp: u32) u32Alias for to_title.
pub fn to_casefold(cp: u32) u32Return the simple case-folded mapping of cp.
This is the single-code-point subset of Unicode case folding. A few characters have multi-code-point folds (for example U+00DF); this function leaves those unchanged.
pub fn utf8_decode(text: ref u8, len: i64, offset: i64) result[u64, UnicodeError]Decode one UTF-8 code point at offset.
len is the number of readable bytes at text. On success the result packs the code point and the number of bytes consumed; use decoded_codepoint and decoded_size to inspect it.
pub fn utf8_decode_cstr(text: ref u8, offset: i64) result[u64, UnicodeError]Decode one UTF-8 code point from a NUL-terminated string at offset.
pub fn utf8_next(text: ref u8, len: i64, offset: i64) result[u64, UnicodeError]Decode the next UTF-8 code point starting at offset.
This is an alias for utf8_decode that reads naturally in loops:
val first = unicode.utf8_next(text, len, 0)
pub fn utf8_validate(text: ref u8, len: i64) boolReturn true when every byte in text[0..len] is a valid UTF-8 sequence.
pub fn utf8_count(text: ref u8, len: i64) i64Count the Unicode code points in valid UTF-8 text.
Returns -1 when the input is not valid UTF-8.
pub fn utf8_codepoint_at(text: ref u8, len: i64, index: i64) result[u64, UnicodeError]Return the code point at Unicode index index as a u64.
index counts code points, not bytes. An out-of-range index yields UnicodeError.InvalidIndex. The value is widened to u64 so the result is portable across all compiler backends.
pub fn utf8_byte_index(text: ref u8, len: i64, index: i64) result[i64, UnicodeError]Return the byte offset of Unicode index index.
The returned offset may equal len, which denotes the end of the text.
pub fn utf8_encoded_len(cp: u32) i64Return the number of bytes needed to encode cp as UTF-8.
Returns 0 when cp is not a valid scalar value.
pub fn utf8_encode(cp: u32, out: ref u8) i64Encode cp as UTF-8 into out and return the number of bytes written.
Returns 0 for an invalid scalar value. The caller must provide at least utf8_encoded_len(cp) writable bytes. The result is not NUL-terminated.
pub fn utf8_encode_result(cp: u32, out: ref u8, cap: i64) result[i64, UnicodeError]Encode cp as UTF-8 into a bounded buffer.
pub fn utf8_encoded_size(codepoints: ref u32, count: i64) i64Return the number of bytes needed to encode count code points as UTF-8.
Returns -1 if any code point is invalid.
pub fn utf8_encode_codepoints(codepoints: ref u32, count: i64, out: ref u8, cap: i64) result[i64, UnicodeError]Encode count code points as UTF-8 into out.
Returns the number of bytes written, or BufferTooSmall when cap is not large enough. The output is not NUL-terminated.
pub fn utf8_from_codepoints[A: allocators.Allocator](ac: A, codepoints: ref u32, count: i64) result[str.String, UnicodeError]Encode count code points into an allocator-owned String.
The returned string is owned by ac; release it with the same allocator's deallocation operation (or by freeing the enclosing arena).
pub fn utf16_encoded_len(cp: u32) i64Return the number of UTF-16 code units needed to encode cp.
Returns 0 when cp is not a valid scalar value.
pub fn utf16_encode(cp: u32, out: ref u16) i64Encode cp as UTF-16 into out and return the number of code units written.
Returns 0 for an invalid scalar value.
pub fn utf16_decode(units: ref u16, len: i64, index: i64) result[u64, UnicodeError]Decode one UTF-16 code point at unit index index.
pub fn utf16_validate(units: ref u16, len: i64) boolReturn true when units[0..len] is valid UTF-16.
pub fn utf16_count(units: ref u16, len: i64) i64Count the Unicode code points in valid UTF-16 text.
Returns -1 when the input is not valid UTF-16.
pub fn utf8_to_codepoints[A: allocators.GeneralAllocator](ac: A, text: ref u8, len: i64) result[list[u64], UnicodeError]Decode valid UTF-8 into an allocator-owned list of code points.
pub fn utf16_to_codepoints[A: allocators.GeneralAllocator](ac: A, units: ref u16, len: i64) result[list[u64], UnicodeError]Decode valid UTF-16 into an allocator-owned list of code points.
pub fn utf8_validate_string(text: str.String) boolValidate a String as UTF-8.
pub fn utf8_count_string(text: str.String) i64Count code points in a String.
Returns -1 when the string is not valid UTF-8.
pub fn utf8_to_codepoints_string[A: allocators.GeneralAllocator](ac: A, text: str.String) result[list[u64], UnicodeError]Decode a String into an allocator-owned list of code points.