pub fn encode_u16(v: &[u16]) -> String
Expand description
Encode UTF-16 as STFU-8, escaping all non-printable or ill-formed UTF-16 characters.
Also check out:
§Examples
let mut ill: Vec<u16> = "fooÿ\nbar"
.encode_utf16()
.collect();
// Make it ill formed UTF-16
ill.push(0xD800); // surrogate pair lead
ill.push(b' ' as u16); // NOT a trail
ill.push(0xDEED); // Trail... with no lead
ill.push(b' ' as u16);
ill.push(0xDABA); // lead... but end of str
let encoded = stfu8::encode_u16(ill.as_slice());
// Note that 0xFF is the valid character "ÿ"
// and the ill-formed characters are escaped.
assert_eq!(
encoded,
r"fooÿ\nbar\u00D800 \u00DEED \u00DABA"
);