Skip to main content

probe_encoding

Function probe_encoding 

Source
pub fn probe_encoding(data: &[u8]) -> ProbeResult
Expand description

Probe the encoding of an XML document from its initial bytes.

Inspects up to the first ~128 bytes for:

  1. Byte Order Mark (BOM): UTF-8, UTF-16 LE/BE, UTF-32 LE/BE
  2. XML declaration <?xml ... encoding="..."?>

The main parser assumes UTF-8. Callers that need to support other encodings should use this function to detect the encoding and transcode before feeding data to Reader::parse().

Returns Encoding::Unknown if the input is too short to determine encoding.