detect_encoding

Function detect_encoding 

Source
pub fn detect_encoding(data: &[u8]) -> &'static str
Expand description

Detect character encoding from byte data

Detection order:

  1. BOM (Byte Order Mark)
  2. XML declaration ()
  3. Default to UTF-8

§Arguments

  • data - Raw byte data

§Returns

Detected encoding name (e.g., “utf-8”, “iso-8859-1”)

§Examples

use feedparser_rs::util::encoding::detect_encoding;

// UTF-8 with BOM
let data = b"\xEF\xBB\xBF<?xml version=\"1.0\"?>";
assert_eq!(detect_encoding(data), "UTF-8");

// XML declaration
let data = b"<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>";
assert_eq!(detect_encoding(data), "windows-1252");