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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
//! [`LanguageTag`] — RFC 5646's SYNTAX, and the structural reduction the lane gate's first step is.
use crate::;
/// **A LANGUAGE TAG, REDUCED TO WHAT A LANE CAN BE KEYED ON** — a primary subtag and an optional
/// script, with everything a lane does not partition on dropped.
///
/// ```
/// use ingraph::{LanguageTag, WritingSystem};
///
/// let reduced = LanguageTag::parse("zh-Hant-TW").expect("a well-formed tag");
///
/// assert_eq!(reduced.language(), "zh");
/// assert_eq!(reduced.script_subtag(), Some("Hant"));
/// // The region went, because no lane is keyed on where a speaker lives.
/// assert_eq!(LanguageTag::parse("en-Latn-US-posix").unwrap().language(), "en");
/// ```
///
/// # SYNTAX ONLY, and the registry deliberately absent
///
/// RFC 5646 has two halves: a grammar, and the IANA subtag registry that says which words the
/// grammar's slots may hold. This reads the GRAMMAR and carries no registry at all, which is the
/// ruling's own division — `sw`, `zzz` and `qaa` all parse here, and whether any of them names a
/// lane is the roster's question rather than a registry's.
///
/// The alternative was a table of nine thousand subtags that goes stale on IANA's schedule, to
/// answer a question the roster answers better: a tag naming a language nobody declared a lane for
/// is refused either way, and refused with a more useful sentence by the party that knows the
/// roster.
///
/// # WHAT IT DROPS, and why each
///
/// | subtag | kept | why |
/// |---|---|---|
/// | primary language | **yes** | it is what a lane is keyed on |
/// | extlang | no | `zh-cmn` is a variety of `zh`, and the lane is `zh` |
/// | script | **yes** | `zh-Hans` and `zh-Hant` may be two lanes or one, and only the roster decides |
/// | region | no | `en-US` and `en-GB` are one analyzer's problem |
/// | variant, extension, private use | no | none of them changes which tokenizer a text wants |
///
/// The script is kept and nothing else optional is, and that asymmetry is the whole reason the
/// reduction is not just *take the first subtag*: a deployment that genuinely needs simplified and
/// traditional in separate lanes has to be able to say so, and a deployment that does not folds them
/// with an alias.
///
/// # IT BORROWS, and the case is the FOLD's business
///
/// The subtags are slices of the tag handed in, spelled however its author spelled them, because
/// materialising a canonical form would be a second authority on what two spellings mean. What
/// decides that is this crate's ONE fold, spent at [`matches`](Self::matches) — so `zh-Hant`,
/// `zh_hant` and `ZH-HANT` are one tag without any of them being rewritten.
///
/// `_` is accepted as a separator beside `-`, which is the *broad in* half of the gate meeting
/// reality: BCP-47 writes `zh-Hant`, POSIX and Java write `zh_Hant`, and a declaration writing a
/// lane's aliases in Rust-ish spelling writes the second.
/// Whether `subtag` is `low` to `high` ASCII letters and nothing else.
///
/// The one shape test the grammar needs, and it is BYTE-WISE because RFC 5646's alphabet is: a
/// subtag is ASCII by the standard's own definition, so a multi-byte character in one is not a
/// subtag whose case might fold — it is not a subtag.