Crate ctb_formats_wtf8

Crate ctb_formats_wtf8 

Source
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_wtf8 using ucs2decode/encode_wtf8_single logic. 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.