ass_core/utils/utf8/encoding/info.rs
1//! Encoding information type with confidence scoring.
2//!
3//! Defines [`EncodingInfo`], the result type produced by encoding detection,
4//! carrying the detected encoding name, confidence level, and BOM details.
5
6use super::super::bom::BomType;
7use alloc::string::String;
8
9/// Detected text encoding information with confidence scoring
10///
11/// Contains the results of encoding detection analysis including
12/// the detected encoding name, confidence level, and BOM information.
13#[derive(Debug, Clone, PartialEq)]
14pub struct EncodingInfo {
15 /// Detected encoding name (e.g., "UTF-8", "Windows-1252")
16 pub encoding: String,
17 /// Confidence level (0.0 to 1.0)
18 pub confidence: f32,
19 /// Whether a BOM was detected
20 pub has_bom: bool,
21 /// BOM type if detected
22 pub bom_type: Option<BomType>,
23 /// Whether the text appears to be valid in this encoding
24 pub is_valid: bool,
25}
26
27impl EncodingInfo {
28 /// Create new encoding info with basic parameters
29 ///
30 /// # Arguments
31 ///
32 /// * `encoding` - Name of the detected encoding
33 /// * `confidence` - Confidence level (0.0 to 1.0)
34 #[must_use]
35 pub const fn new(encoding: String, confidence: f32) -> Self {
36 Self {
37 encoding,
38 confidence,
39 has_bom: false,
40 bom_type: None,
41 is_valid: true,
42 }
43 }
44
45 /// Create encoding info with BOM information
46 ///
47 /// # Arguments
48 ///
49 /// * `encoding` - Name of the detected encoding
50 /// * `confidence` - Confidence level (0.0 to 1.0)
51 /// * `bom_type` - Type of BOM detected
52 #[must_use]
53 pub const fn with_bom(encoding: String, confidence: f32, bom_type: BomType) -> Self {
54 Self {
55 encoding,
56 confidence,
57 has_bom: true,
58 bom_type: Some(bom_type),
59 is_valid: true,
60 }
61 }
62}