pub fn detect(bytes: &[u8]) -> EncodingExpand description
Sniff the encoding of an XML document from its first bytes.
The algorithm:
- If a BOM is present, use it (currently only UTF-8 BOM is handled in
Tier 1; UTF-16 BOMs return
Encoding::Otheruntil we add UTF-16). - Otherwise, look for a
<?xml ... encoding="..."?>declaration in the first ~200 bytes. The XML spec guarantees the declaration is in an ASCII-compatible form for every encoding the spec mentions, so this lookahead works without knowing the encoding yet. - If neither is found, default to UTF-8.