A11 (C++ runtime)
Native C++ implementation of the A11 streaming action runtime
Loading...
Searching...
No Matches
a11::utf8 Namespace Reference

Functions

bool IsContinuation (char byte)
 Whether byte is a continuation byte – the middle of a character.
 
size_t SequenceWidth (char lead)
 Bytes in the sequence lead starts, from the lead byte alone.
 
size_t Utf16Units (char lead)
 UTF-16 code units the character at lead occupies: 2 above the BMP, else.
 
bool IsValid (std::string_view text)
 Whether text is well-formed UTF-8.
 

Function Documentation

◆ IsContinuation()

bool a11::utf8::IsContinuation ( char  byte)
inline

Whether byte is a continuation byte – the middle of a character.

◆ IsValid()

bool a11::utf8::IsValid ( std::string_view  text)
inline

Whether text is well-formed UTF-8.

Strict: overlong encodings, surrogate halves and anything above U+10FFFF are rejected, which is the definition Python's bytes.decode("utf-8"), Kotlin's String(bytes) and JavaScript's TextDecoder with fatal all enforce. See a11::IsValidUtf8 in a11/json_codec.h for why A11 refuses such bytes on the way out rather than letting a peer fail on them.

◆ SequenceWidth()

size_t a11::utf8::SequenceWidth ( char  lead)
inline

Bytes in the sequence lead starts, from the lead byte alone.

1 for ASCII and for a malformed lead, so that walking a document that is not quite UTF-8 advances rather than stalling or running off the end. A caller that must reject malformed input wants IsValid instead.

◆ Utf16Units()

size_t a11::utf8::Utf16Units ( char  lead)
inline

UTF-16 code units the character at lead occupies: 2 above the BMP, else.