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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// Bistun Linguistic Metadata Service (LMS)
// Copyright (C) 2026 Francis Xavier Wazeter IV
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//! # Orthographic Extension Mapper
//! Crate: `bistun-lms`
//! Ref: [004-LMS-EXT], [011-LMS-DTO]
//! Location: `crates/bistun-lms/src/core/extension/orthography.rs`
//!
//! **Why**: This module serves as Phase 3 (Override/Extension) of the pipeline. It parses user-requested `BCP 47` subtags (like `-u-`) and injects them into the decoupled `extensions` map.
//! **Impact**: If this module fails, user runtime overrides (like requesting a Latin calendar in an Arabic UI) will be ignored, breaking user experience and personalization logic.
//!
//! ### Glossary
//! * **Extension Subtag**: A `BCP 47` singleton (like `-u-` for Unicode or `-t-` for Transform) used to modify the default behavior of a locale.
use LmsError;
use CapabilityManifest;
/// Parses `BCP 47` `-u-` Unicode extensions and injects them into the manifest's `extensions` map.
///
/// Time: `O(N)` string traversal | Space: `O(1)`
///
/// # Logic Trace (Internal)
/// 1. Scan the `raw_tag` for the `-u-` singleton sequence.
/// 2. If the Unicode sequence is found, instantiate a zero-allocation string splitter.
/// 3. Extract recognized keys (`nu` for Numbers, `ca` for Calendar) and map their values into `manifest.extensions`.
/// 4. Return successful completion without mutating the `traits` map.
///
/// # Examples
/// ```rust
/// # use bistun_core::manifest::CapabilityManifest;
/// # use bistun_lms::core::extension::orthography::apply_extensions;
/// let mut manifest = CapabilityManifest::new("ar-EG-u-nu-latn".to_string());
/// apply_extensions(&mut manifest, "ar-EG-u-nu-latn-ca-gregory")
/// .expect("LMS-TEST: Failed to apply extensions");
/// assert_eq!(manifest.extensions.get("nu").expect("LMS-TEST: Missing key"), "latn");
/// ```
///
/// # Arguments
/// * `manifest` (&mut `CapabilityManifest`): The mutable `DTO` being hydrated through the pipeline.
/// * `raw_tag` (&str): The raw `BCP 47` language tag requested, parsed for Unicode extensions.
///
/// # Returns
/// * `Result<(), LmsError>`: Returns `Ok(())` upon successful parsing and injection.
///
/// # Golden I/O
/// * **Input**: `manifest`, `"ar-EG-u-nu-latn-ca-gregory"`
/// * **Output**: `Ok(())` (Manifest updated with `extensions: {"nu": "latn", "ca": "gregory"}`)
///
/// # Errors
/// * While the function signature allows for an `LmsError`, current parsing logic is internal and essentially infallible; future validation logic for subtag values may return `LmsError::ExtensionMappingFailure`.
///
/// # Panics
/// * None.
///
/// # Safety
/// * Safe synchronous execution with zero heap allocations for tag parsing.