Skip to main content

detect

Function detect 

Source
pub fn detect(input: &[u8]) -> &'static Encoding
Expand description

Detect the character encoding of raw HTML bytes.

The detection order is:

  1. BOM โ€” UTF-8 (EF BB BF), UTF-16 LE (FF FE), UTF-16 BE (FE FF)
  2. <meta charset="..."> โ€” first occurrence in the first 1 KB
  3. <meta http-equiv="Content-Type" content="...charset=...">
  4. 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");