charset-norm
Universal character encoding detector for Rust: a Rust implementation of charset_normalizer.
It decodes a payload with every supported code page, measures how noisy each result looks (chaos) and how well it matches known languages (coherence), and ranks the plausible encodings. Decoding reproduces CPython's codecs byte for byte (98 code pages, including the CJK and ISO-2022 families), so results agree with the Python package.
Usage
[]
= "4.1"
let payload = read?;
let results = from_bytes;
match results.best
Detection can be tuned and observed:
use ;
let options = DetectionOptions ;
let results = from_bytes_with;
The building blocks are public too: codecs (CPython-compatible decoders and
encoders), encoding (names, BOMs, declared charsets), mess, coherence
and unicode.
Features
log: forward detection diagnostics to thelogcrate throughcharset_norm::log::LogCrate.hotpath: instrument the detector's stages (decoding, chunk sampling, mess and coherence scoring, ...) with hotpath probes. They report into the profile of any binary annotated with#[hotpath::main], and do nothing otherwise.hotpath-allocreports allocations instead of timings. Without these features the probes compile to nothing.
Profiling
The profile example runs detection over a directory of files and prints a
hotpath report:
# Allocations instead of timings:
License
MIT. Based on charset_normalizer by Ahmed TAHRI.