@@ -46,12 +46,6 @@ pub enum QuickCheck {
46
46
Maybe ,
47
47
}
48
48
49
- /// Result of quickly checking if a string is normalized.
50
- pub type QuickResult = Result < QuickCheck , NormalizationError > ;
51
-
52
- /// Result of authoritatively checking if a string is normalized.
53
- pub type FullResult = Result < ( ) , NormalizationError > ;
54
-
55
49
/// Normalization status of single character.
56
50
pub ( crate ) enum IsNormalized {
57
51
Yes ,
@@ -61,7 +55,11 @@ pub(crate) enum IsNormalized {
61
55
62
56
// https://unicode.org/reports/tr15/#Detecting_Normalization_Forms
63
57
#[ inline]
64
- fn quick_check < F , I > ( s : I , is_allowed : F , stream_safe : bool ) -> QuickResult
58
+ fn quick_check < F , I > (
59
+ s : I ,
60
+ is_allowed : F ,
61
+ stream_safe : bool ,
62
+ ) -> Result < QuickCheck , NormalizationError >
65
63
where
66
64
I : Iterator < Item = ( usize , char ) > ,
67
65
F : Fn ( char ) -> IsNormalized ,
@@ -111,7 +109,7 @@ where
111
109
fn full_check < I : Iterator < Item = ( usize , char ) > , J : Iterator < Item = char > > (
112
110
check : I ,
113
111
normalized : J ,
114
- ) -> FullResult {
112
+ ) -> Result < ( ) , NormalizationError > {
115
113
check. zip ( normalized) . try_for_each ( |( ( idx, lhs) , rhs) | {
116
114
if lhs == rhs {
117
115
Ok ( ( ) )
@@ -123,43 +121,43 @@ fn full_check<I: Iterator<Item = (usize, char)>, J: Iterator<Item = char>>(
123
121
124
122
/// Quickly check if a string is in NFC.
125
123
#[ inline]
126
- pub fn check_nfc_quick ( s : & str ) -> QuickResult {
124
+ pub fn check_nfc_quick ( s : & str ) -> Result < QuickCheck , NormalizationError > {
127
125
quick_check ( s. char_indices ( ) , tables:: qc_nfc, false )
128
126
}
129
127
130
128
/// Quickly check if a string is in NFKC.
131
129
#[ inline]
132
- pub fn check_nfkc_quick ( s : & str ) -> QuickResult {
130
+ pub fn check_nfkc_quick ( s : & str ) -> Result < QuickCheck , NormalizationError > {
133
131
quick_check ( s. char_indices ( ) , tables:: qc_nfkc, false )
134
132
}
135
133
136
134
/// Quickly check if a string is in NFD.
137
135
#[ inline]
138
- pub fn check_nfd_quick ( s : & str ) -> QuickResult {
136
+ pub fn check_nfd_quick ( s : & str ) -> Result < QuickCheck , NormalizationError > {
139
137
quick_check ( s. char_indices ( ) , tables:: qc_nfd, false )
140
138
}
141
139
142
140
/// Quickly check if a string is in NFKD.
143
141
#[ inline]
144
- pub fn check_nfkd_quick ( s : & str ) -> QuickResult {
142
+ pub fn check_nfkd_quick ( s : & str ) -> Result < QuickCheck , NormalizationError > {
145
143
quick_check ( s. char_indices ( ) , tables:: qc_nfkd, false )
146
144
}
147
145
148
146
/// Quickly check if a string is Stream-Safe NFC.
149
147
#[ inline]
150
- pub fn check_nfc_stream_safe_quick ( s : & str ) -> QuickResult {
148
+ pub fn check_nfc_stream_safe_quick ( s : & str ) -> Result < QuickCheck , NormalizationError > {
151
149
quick_check ( s. char_indices ( ) , tables:: qc_nfc, true )
152
150
}
153
151
154
152
/// Quickly check if a string is Stream-Safe NFD.
155
153
#[ inline]
156
- pub fn check_nfd_stream_safe_quick ( s : & str ) -> QuickResult {
154
+ pub fn check_nfd_stream_safe_quick ( s : & str ) -> Result < QuickCheck , NormalizationError > {
157
155
quick_check ( s. char_indices ( ) , tables:: qc_nfd, true )
158
156
}
159
157
160
158
/// Authoritatively check if a string is in NFC.
161
159
#[ inline]
162
- pub fn check_nfc ( s : & str ) -> FullResult {
160
+ pub fn check_nfc ( s : & str ) -> Result < ( ) , NormalizationError > {
163
161
match check_nfc_quick ( s) ? {
164
162
QuickCheck :: Yes => Ok ( ( ) ) ,
165
163
QuickCheck :: Maybe => full_check ( s. char_indices ( ) , s. chars ( ) . nfc ( ) ) ,
@@ -174,7 +172,7 @@ pub fn is_nfc(s: &str) -> bool {
174
172
175
173
/// Authoritatively check if a string is in NFKC.
176
174
#[ inline]
177
- pub fn check_nfkc ( s : & str ) -> FullResult {
175
+ pub fn check_nfkc ( s : & str ) -> Result < ( ) , NormalizationError > {
178
176
match check_nfkc_quick ( s) ? {
179
177
QuickCheck :: Yes => Ok ( ( ) ) ,
180
178
QuickCheck :: Maybe => full_check ( s. char_indices ( ) , s. chars ( ) . nfkc ( ) ) ,
@@ -189,7 +187,7 @@ pub fn is_nfkc(s: &str) -> bool {
189
187
190
188
/// Authoritatively check if a string is in NFD.
191
189
#[ inline]
192
- pub fn check_nfd ( s : & str ) -> FullResult {
190
+ pub fn check_nfd ( s : & str ) -> Result < ( ) , NormalizationError > {
193
191
match check_nfd_quick ( s) ? {
194
192
QuickCheck :: Yes => Ok ( ( ) ) ,
195
193
QuickCheck :: Maybe => full_check ( s. char_indices ( ) , s. chars ( ) . nfd ( ) ) ,
@@ -204,7 +202,7 @@ pub fn is_nfd(s: &str) -> bool {
204
202
205
203
/// Authoritatively check if a string is in NFKD.
206
204
#[ inline]
207
- pub fn check_nfkd ( s : & str ) -> FullResult {
205
+ pub fn check_nfkd ( s : & str ) -> Result < ( ) , NormalizationError > {
208
206
match check_nfkd_quick ( s) ? {
209
207
QuickCheck :: Yes => Ok ( ( ) ) ,
210
208
QuickCheck :: Maybe => full_check ( s. char_indices ( ) , s. chars ( ) . nfkd ( ) ) ,
@@ -219,7 +217,7 @@ pub fn is_nfkd(s: &str) -> bool {
219
217
220
218
/// Authoritatively check if a string is Stream-Safe NFC.
221
219
#[ inline]
222
- pub fn check_nfc_stream_safe ( s : & str ) -> FullResult {
220
+ pub fn check_nfc_stream_safe ( s : & str ) -> Result < ( ) , NormalizationError > {
223
221
match check_nfc_stream_safe_quick ( s) ? {
224
222
QuickCheck :: Yes => Ok ( ( ) ) ,
225
223
QuickCheck :: Maybe => full_check ( s. char_indices ( ) , s. chars ( ) . stream_safe ( ) . nfc ( ) ) ,
@@ -234,7 +232,7 @@ pub fn is_nfc_stream_safe(s: &str) -> bool {
234
232
235
233
/// Authoritatively check if a string is Stream-Safe NFD.
236
234
#[ inline]
237
- pub fn check_nfd_stream_safe ( s : & str ) -> FullResult {
235
+ pub fn check_nfd_stream_safe ( s : & str ) -> Result < ( ) , NormalizationError > {
238
236
match check_nfd_stream_safe_quick ( s) ? {
239
237
QuickCheck :: Yes => Ok ( ( ) ) ,
240
238
QuickCheck :: Maybe => full_check ( s. char_indices ( ) , s. chars ( ) . stream_safe ( ) . nfd ( ) ) ,
0 commit comments