1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//! Universal character encoding detector.
//!
//! `charset-norm` is a Rust implementation of
//! [charset_normalizer](https://github.com/jawah/charset_normalizer). It
//! finds the encodings a payload was plausibly written in by decoding it with
//! every supported code page, measuring how noisy the result looks ("chaos")
//! and how well it matches known languages ("coherence").
//!
//! Decoding reproduces `CPython`'s codecs byte for byte, so results agree with
//! the Python package.
//!
//! ```
//! let results = charset_norm::from_bytes("Ça va très bien, merci.".as_bytes());
//! let best = results.best().expect("text payload");
//! assert_eq!(best.encoding(), "utf_8");
//! assert_eq!(best.decoded().unwrap(), "Ça va très bien, merci.");
//! ```
//!
//! Tune detection with [`DetectionOptions`] and [`from_bytes_with`]; route
//! diagnostics through a [`Logger`] (enable the `log` feature to forward
//! them to the `log` crate).
pub use ;
pub use Error;
pub use ;
pub use ;
/// Payloads shorter than this are considered too small for reliable detection.
pub const TOO_SMALL_SEQUENCE: usize = 32;
/// Payloads at least this long are sampled rather than fully decoded.
pub const TOO_BIG_SEQUENCE: usize = 10_000_000;