Skip to main content

transcode_to_utf8

Function transcode_to_utf8 

Source
pub fn transcode_to_utf8(bytes: &[u8]) -> Result<Cow<'_, [u8]>, XmlError>
Expand description

Detect the encoding of bytes and transcode them into UTF-8.

For UTF-8 / US-ASCII input the result is Cow::Borrowed (zero copy). For Latin-1 / Windows-1252 it is Cow::Owned — these encodings produce UTF-8 about 1.0–1.5× the input size.

Does not verify that the inner <?xml ... encoding="X" ?> declaration agrees with the encoding detected from the bytes — for that, use transcode_to_utf8_strict.