Function widestring::decode_utf16_lossy [−][src]
pub fn decode_utf16_lossy<I>(
iter: I
) -> DecodeUtf16Lossy<<I as IntoIterator>::IntoIter>ⓘNotable traits for DecodeUtf16Lossy<I>impl<I> Iterator for DecodeUtf16Lossy<I> where
I: Iterator<Item = u16>, type Item = char;
where
I: IntoIterator<Item = u16>,
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�"
);