Function widestring::decode_utf16_lossy
source · pub fn decode_utf16_lossy<I: IntoIterator<Item = u16>>(
iter: I,
) -> DecodeUtf16Lossy<I::IntoIter> ⓘ
Expand description
Creates a lossy decoder iterator over the possibly ill-formed UTF-16 encoded code points in
iter
.
This is equivalent to char::decode_utf16
except that any unpaired
UTF-16 surrogate values are replaced by
U+FFFD REPLACEMENT_CHARACTER
(�) instead of returning
errors.
§Examples
use widestring::decode_utf16_lossy;
// 𝄞mus<invalid>ic<invalid>
let v = [
0xD834, 0xDD1E, 0x006d, 0x0075, 0x0073, 0xDD1E, 0x0069, 0x0063, 0xD834,
];
assert_eq!(
decode_utf16_lossy(v.iter().copied()).collect::<String>(),
"𝄞mus�ic�"
);