@@ -46,12 +46,6 @@ pub enum QuickCheck {
4646 Maybe ,
4747}
4848
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-
5549/// Normalization status of single character.
5650pub ( crate ) enum IsNormalized {
5751 Yes ,
@@ -61,7 +55,11 @@ pub(crate) enum IsNormalized {
6155
6256// https://unicode.org/reports/tr15/#Detecting_Normalization_Forms
6357#[ 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 >
6563where
6664 I : Iterator < Item = ( usize , char ) > ,
6765 F : Fn ( char ) -> IsNormalized ,
@@ -111,7 +109,7 @@ where
111109fn full_check < I : Iterator < Item = ( usize , char ) > , J : Iterator < Item = char > > (
112110 check : I ,
113111 normalized : J ,
114- ) -> FullResult {
112+ ) -> Result < ( ) , NormalizationError > {
115113 check. zip ( normalized) . try_for_each ( |( ( idx, lhs) , rhs) | {
116114 if lhs == rhs {
117115 Ok ( ( ) )
@@ -123,43 +121,43 @@ fn full_check<I: Iterator<Item = (usize, char)>, J: Iterator<Item = char>>(
123121
124122/// Quickly check if a string is in NFC.
125123#[ inline]
126- pub fn check_nfc_quick ( s : & str ) -> QuickResult {
124+ pub fn check_nfc_quick ( s : & str ) -> Result < QuickCheck , NormalizationError > {
127125 quick_check ( s. char_indices ( ) , tables:: qc_nfc, false )
128126}
129127
130128/// Quickly check if a string is in NFKC.
131129#[ inline]
132- pub fn check_nfkc_quick ( s : & str ) -> QuickResult {
130+ pub fn check_nfkc_quick ( s : & str ) -> Result < QuickCheck , NormalizationError > {
133131 quick_check ( s. char_indices ( ) , tables:: qc_nfkc, false )
134132}
135133
136134/// Quickly check if a string is in NFD.
137135#[ inline]
138- pub fn check_nfd_quick ( s : & str ) -> QuickResult {
136+ pub fn check_nfd_quick ( s : & str ) -> Result < QuickCheck , NormalizationError > {
139137 quick_check ( s. char_indices ( ) , tables:: qc_nfd, false )
140138}
141139
142140/// Quickly check if a string is in NFKD.
143141#[ inline]
144- pub fn check_nfkd_quick ( s : & str ) -> QuickResult {
142+ pub fn check_nfkd_quick ( s : & str ) -> Result < QuickCheck , NormalizationError > {
145143 quick_check ( s. char_indices ( ) , tables:: qc_nfkd, false )
146144}
147145
148146/// Quickly check if a string is Stream-Safe NFC.
149147#[ 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 > {
151149 quick_check ( s. char_indices ( ) , tables:: qc_nfc, true )
152150}
153151
154152/// Quickly check if a string is Stream-Safe NFD.
155153#[ 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 > {
157155 quick_check ( s. char_indices ( ) , tables:: qc_nfd, true )
158156}
159157
160158/// Authoritatively check if a string is in NFC.
161159#[ inline]
162- pub fn check_nfc ( s : & str ) -> FullResult {
160+ pub fn check_nfc ( s : & str ) -> Result < ( ) , NormalizationError > {
163161 match check_nfc_quick ( s) ? {
164162 QuickCheck :: Yes => Ok ( ( ) ) ,
165163 QuickCheck :: Maybe => full_check ( s. char_indices ( ) , s. chars ( ) . nfc ( ) ) ,
@@ -174,7 +172,7 @@ pub fn is_nfc(s: &str) -> bool {
174172
175173/// Authoritatively check if a string is in NFKC.
176174#[ inline]
177- pub fn check_nfkc ( s : & str ) -> FullResult {
175+ pub fn check_nfkc ( s : & str ) -> Result < ( ) , NormalizationError > {
178176 match check_nfkc_quick ( s) ? {
179177 QuickCheck :: Yes => Ok ( ( ) ) ,
180178 QuickCheck :: Maybe => full_check ( s. char_indices ( ) , s. chars ( ) . nfkc ( ) ) ,
@@ -189,7 +187,7 @@ pub fn is_nfkc(s: &str) -> bool {
189187
190188/// Authoritatively check if a string is in NFD.
191189#[ inline]
192- pub fn check_nfd ( s : & str ) -> FullResult {
190+ pub fn check_nfd ( s : & str ) -> Result < ( ) , NormalizationError > {
193191 match check_nfd_quick ( s) ? {
194192 QuickCheck :: Yes => Ok ( ( ) ) ,
195193 QuickCheck :: Maybe => full_check ( s. char_indices ( ) , s. chars ( ) . nfd ( ) ) ,
@@ -204,7 +202,7 @@ pub fn is_nfd(s: &str) -> bool {
204202
205203/// Authoritatively check if a string is in NFKD.
206204#[ inline]
207- pub fn check_nfkd ( s : & str ) -> FullResult {
205+ pub fn check_nfkd ( s : & str ) -> Result < ( ) , NormalizationError > {
208206 match check_nfkd_quick ( s) ? {
209207 QuickCheck :: Yes => Ok ( ( ) ) ,
210208 QuickCheck :: Maybe => full_check ( s. char_indices ( ) , s. chars ( ) . nfkd ( ) ) ,
@@ -219,7 +217,7 @@ pub fn is_nfkd(s: &str) -> bool {
219217
220218/// Authoritatively check if a string is Stream-Safe NFC.
221219#[ inline]
222- pub fn check_nfc_stream_safe ( s : & str ) -> FullResult {
220+ pub fn check_nfc_stream_safe ( s : & str ) -> Result < ( ) , NormalizationError > {
223221 match check_nfc_stream_safe_quick ( s) ? {
224222 QuickCheck :: Yes => Ok ( ( ) ) ,
225223 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 {
234232
235233/// Authoritatively check if a string is Stream-Safe NFD.
236234#[ inline]
237- pub fn check_nfd_stream_safe ( s : & str ) -> FullResult {
235+ pub fn check_nfd_stream_safe ( s : & str ) -> Result < ( ) , NormalizationError > {
238236 match check_nfd_stream_safe_quick ( s) ? {
239237 QuickCheck :: Yes => Ok ( ( ) ) ,
240238 QuickCheck :: Maybe => full_check ( s. char_indices ( ) , s. chars ( ) . stream_safe ( ) . nfd ( ) ) ,
0 commit comments