Crate unicode_bom
source ·Expand description
Detects and classifies Unicode byte-order marks.
Usage
use unicode_bom::Bom;
// Detect the UTF-32 (little-endian) BOM in a file on disk
let bom: Bom = "fixtures/utf32-le.txt".parse().unwrap();
assert_eq!(bom, Bom::Utf32Le);
assert_eq!(bom.len(), 4);
// Detect the UTF-16 (little-endian) BOM in a file on disk
let bom: Bom = "fixtures/utf16-le.txt".parse().unwrap();
assert_eq!(bom, Bom::Utf16Le);
assert_eq!(bom.len(), 2);
// Detect no BOM in a file on disk
let bom: Bom = "fixtures/ascii.txt".parse().unwrap();
assert_eq!(bom, Bom::Null);
assert_eq!(bom.len(), 0);
// Detect the BOM in a byte array
let bytes = [0u8, 0u8, 0xfeu8, 0xffu8];
assert_eq!(Bom::from(&bytes[0..]), Bom::Utf32Be);
Enums
- Unicode byte-order mark (BOM) abstraction.