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
//! UTS-46.
use crate*;
/// A UTS46 normalizer.
pub static UTS46: Uts46MapperBorrowed = new;
/// Do UTS46 mapping and normalization, in-place if possible.
///
/// Effectively a wrapper [`icu_normalizer::uts46::Uts46MapperBorrowed`] that should in theory be faster for ASCII input.
///
/// See [`uts46_classify_map_normalize`] if you're using this for domain/IPv4 stuff.
/// # Examples
/// ```
/// use better_url::util::*;
///
/// assert_eq!(uts46_map_normalize("a" ), (false, "a" .into()));
/// assert_eq!(uts46_map_normalize("A" ), (true , "a" .into()));
/// assert_eq!(uts46_map_normalize("3" ), (false, "3" .into()));
/// assert_eq!(uts46_map_normalize("-" ), (false, "-" .into()));
/// assert_eq!(uts46_map_normalize("--" ), (false, "--" .into()));
/// assert_eq!(uts46_map_normalize("London" ), (true , "london" .into()));
/// assert_eq!(uts46_map_normalize("Lloyd-Atkinson" ), (true , "lloyd-atkinson" .into()));
/// assert_eq!(uts46_map_normalize("This has spaces" ), (true , "this has spaces" .into()));
/// assert_eq!(uts46_map_normalize("-> $1.00 <-" ), (false, "-> $1.00 <-" .into()));
/// assert_eq!(uts46_map_normalize("Б" ), (true , "б" .into()));
/// assert_eq!(uts46_map_normalize("ü" ), (false, "ü" .into()));
/// assert_eq!(uts46_map_normalize("α" ), (false, "α" .into()));
/// assert_eq!(uts46_map_normalize("例" ), (false, "例" .into()));
/// assert_eq!(uts46_map_normalize("😉" ), (false, "😉" .into()));
/// assert_eq!(uts46_map_normalize("αβγ" ), (false, "αβγ" .into()));
/// assert_eq!(uts46_map_normalize("München" ), (true , "münchen" .into()));
/// assert_eq!(uts46_map_normalize("Mnchen-3ya" ), (true , "mnchen-3ya" .into()));
/// assert_eq!(uts46_map_normalize("München-Ost" ), (true , "münchen-ost" .into()));
/// assert_eq!(uts46_map_normalize("Bahnhof München-Ost"), (true , "bahnhof münchen-ost".into()));
/// assert_eq!(uts46_map_normalize("abæcdöef" ), (false, "abæcdöef" .into()));
/// assert_eq!(uts46_map_normalize("Αθήνα" ), (true , "αθήνα" .into()));
/// assert_eq!(uts46_map_normalize("правда" ), (false, "правда" .into()));
/// assert_eq!(uts46_map_normalize("ยจฆฟคฏข" ), (false, "ยจฆฟคฏข" .into()));
/// assert_eq!(uts46_map_normalize("도메인" ), (false, "도메인" .into()));
/// assert_eq!(uts46_map_normalize("ドメイン名例" ), (false, "ドメイン名例" .into()));
/// assert_eq!(uts46_map_normalize("MajiでKoiする5秒前" ), (true , "majiでkoiする5秒前" .into()));
/// assert_eq!(uts46_map_normalize("「bücher」" ), (false, "「bücher」" .into()));
/// ```
/// Like [`uts46_map_normalize`] but returns the "class" of the input.
///
/// The "class" is the result of the bitwise OR of each byte's value in [`DOMAIN_BYTE_CLASS_DATA`].
///
/// ***Please*** note that this is about the ***input***.
///
/// If the unicode bit is set, you can't assume the output will be described by the class.
///
/// This function exists because:
///
/// 1. To fast path ASCII input, this function already has to compute the "contains Unicode" and "contains ASCII uppercase" bits of the class.
///
/// 2. It is free to compute up to 8 bits of information.
///
/// 3. The extra computed bits are useful elsewhere for additional fast paths.