Skip to main content

detect

Function detect 

Source
pub fn detect(input: &[u8]) -> &'static Encoding
Available on crate feature encoding only.
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");