pub fn detect(input: &[u8]) -> &'static EncodingExpand description
Detect the character encoding of raw HTML bytes.
The detection order is:
- BOM โ UTF-8 (
EF BB BF), UTF-16 LE (FF FE), UTF-16 BE (FE FF) <meta charset="...">โ first occurrence in the first 1 KB<meta http-equiv="Content-Type" content="...charset=...">- Fallback โ UTF-8
ยงExample
use fhp_encoding::detect;
let html = b"\xEF\xBB\xBF<html>UTF-8 with BOM</html>";
assert_eq!(detect(html).name(), "UTF-8");