Expand description
WTF-8 / UTF-8 → UTF-16 codec helpers, faithfully copied from the subset of
hermes_parser::utf8 (itself ported from include/hermes/Support/UTF8.h) that is
needed by JSONEmitter and the forthcoming AST-dumper port.
Keeping this copy in support means json_emitter and the AST-dumper can
use it without taking a dependency on the parser crate, and without
duplicating logic. The module is zero-unsafe (the support crate
forbids unsafe_code).
Functions§
- convert_
utf8_ with_ surrogates_ to_ utf16 - Decode a UTF-8 sequence, which is assumed to be valid, but may possibly
contain explicitly encoded surrogate pairs, into a UTF-16 sequence. Port of
convertUTF8WithSurrogatesToUTF16(UTF8.h:216-225). - decode_
utf8 - Decode a sequence of UTF8 encoded bytes into a Unicode codepoint, ASCII fast
path. Port of
decodeUTF8(UTF8.h:187-193). In case of decoding errors, the provided callback is invoked with an appropriate message and UNICODE_REPLACEMENT_CHARACTER is returned. - decode_
utf8_ slow_ path - Decode a sequence of UTF8 encoded bytes when it is known that the first byte
is a start of a UTF8 sequence. Port of
_decodeUTF8SlowPath(UTF8.h:77-162), readingbytesfrom*iand advancing*ipast the consumed bytes. On malformed input it invokeserrorand returns the replacement character. - encode_
utf16 - Encode a 32-bit value into UTF-16, appending to
out. If the value is a part of a surrogate pair, it is encoded without any conversion. Port ofencodeUTF16(UTF8.h:197-210). - is_
utf8_ start - Check whether a byte is a regular ASCII or a UTF8 starting byte. \return true if it is UTF8 starting byte.