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