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
//! The two things every subtag door does before it reaches a registry: read the STRUCTURE, and put
//! the text in the case the tables are keyed by.
//!
//! Neither is language knowledge, which is why they are written here rather than generated: a
//! subtag's shape is BCP 47's grammar — so many letters, or so many digits — and its case is a
//! spelling convention. What each type admits, and which case it folds onto, is the type's own
//! subject and is stated there.
//!
//! # Eight bytes is the widest thing that can reach any of this
//!
//! BCP 47's longest primary subtag is eight ALPHA, and a script is four while a region is two or
//! three. So [`Cased`] is a stack buffer of eight and every fold below is allocation-free — which
//! matters because these run once per tag on the way in from a container, and a media library has
//! one per track.
/// The widest subtag BCP 47's grammar admits, and therefore the width of [`Cased`]'s buffer.
///
/// Eight, from `language = 2*3ALPHA / 4ALPHA / 5*8ALPHA`. Nothing longer can be a subtag, so a text
/// longer than this is refused on its LENGTH before any case fold is attempted — which is what
/// makes the buffer a fixed one.
pub const MAX: usize = 8;
/// One subtag in a canonical case, held in a stack buffer.
///
/// Every fold here is ASCII-only — deliberately, and safely: the caller has already refused
/// anything that is not ASCII letters or digits, so there is no character whose case fold is
/// locale-dependent, expands to two characters, or straddles a byte boundary. `İ` never reaches
/// this.
pub
/// The first character of `text` that is not an ASCII letter, or [`None`] where every one is.
///
/// It answers with the CHARACTER rather than a `bool` so a refusal can name what it found: `zh_CN`
/// is refused for its underscore and `dé` for its `é`, and a client told only that its input was
/// malformed has to guess which.
pub
/// The first character of `text` that is neither an ASCII letter nor an ASCII digit, or [`None`]
/// where every one is.
///
/// A region has TWO grammars, so its door cannot ask a single-class question: what it needs to tell
/// a client is whether the input left the alphanumeric alphabet altogether — `zh_CN`'s underscore —
/// or stayed inside it and belonged to neither arm, which is `D1`.
pub