Expand description
Utilities for WTF-8 encoding and decoding. Reference: https://simonsapin.github.io/wtf-8/ See also the standard library version: https://doc.rust-lang.org/src/std/sys_common/wtf8.rs.html
TODO?: This could have some more optional features added for other uses:
- Allow encoding of values above U+10FFFF (up to U+7FFFFFFF) as 6-byte sequences.
- Allow retaining surrogates unpaired when encoding, in which case it would be CESU-8 implementation.
Functionsยง
- decode_
wtf8_ single - Decode one WTF-8 codepoint from a byte array slice. Returns Ok((codepoint, length)) or Err on error.
- decode_
wtf8_ to_ scalars - Decode a WTF-8 byte array into a
Vec<u16>(UCS-2). - decode_
wtf8_ to_ ucs2 - Decode a WTF-8 byte array into a
Vec<u16>(UCS-2). - encode_
wtf8_ from_ scalars - More concise
encode_wtf8usingucs2decode/encode_wtf8_singlelogic. Encodes a slice of Unicode scalar codepoints to WTF-8 bytes. Surrogate pairs are combined and encoded as a single codepoint. Unpaired surrogates are encoded as 3-byte WTF-8 sequences. Values higher than 0x10FFFF are not supported. - encode_
wtf8_ from_ ucs2 - WTF-8 encode a UTF-16/UCS-2/JS string (as &u16) into
Vec<u8>. Uses ucs2decode to convert to codepoints, then encodes as WTF-8. - encode_
wtf8_ single - Encode a single Unicode codepoint as WTF-8 byte array.
Returns a
Vec<u8>containing the WTF-8 encoding of the codepoint. Surrogates and non-scalar values are encoded as WTF-8 allows. Values higher than 0x10FFFF are not supported. - is_
unpackable_ wtf8 - Returns true if the given slice is a valid WTF-8 single codepoint sequence.