@@ -233,16 +233,16 @@ fn passes_bidi(label: &str, is_bidi_domain: bool) -> bool {
233
233
}
234
234
235
235
/// http://www.unicode.org/reports/tr46/#Validity_Criteria
236
- fn validate_full ( label : & str , is_bidi_domain : bool , flags : Flags , errors : & mut Vec < Error > ) {
236
+ fn validate_full ( label : & str , is_bidi_domain : bool , config : Config , errors : & mut Vec < Error > ) {
237
237
// V1: Must be in NFC form.
238
238
if label. nfc ( ) . ne ( label. chars ( ) ) {
239
239
errors. push ( Error :: ValidityCriteria ) ;
240
240
} else {
241
- validate ( label, is_bidi_domain, flags , errors) ;
241
+ validate ( label, is_bidi_domain, config , errors) ;
242
242
}
243
243
}
244
244
245
- fn validate ( label : & str , is_bidi_domain : bool , flags : Flags , errors : & mut Vec < Error > ) {
245
+ fn validate ( label : & str , is_bidi_domain : bool , config : Config , errors : & mut Vec < Error > ) {
246
246
let first_char = label. chars ( ) . next ( ) ;
247
247
if first_char == None {
248
248
// Empty string, pass
@@ -273,8 +273,8 @@ fn validate(label: &str, is_bidi_domain: bool, flags: Flags, errors: &mut Vec<Er
273
273
// V6: Check against Mapping Table
274
274
else if label. chars ( ) . any ( |c| match * find_char ( c) {
275
275
Mapping :: Valid => false ,
276
- Mapping :: Deviation ( _) => flags. transitional_processing ,
277
- Mapping :: DisallowedStd3Valid => flags. use_std3_ascii_rules ,
276
+ Mapping :: Deviation ( _) => config . flags . transitional_processing ,
277
+ Mapping :: DisallowedStd3Valid => config . flags . use_std3_ascii_rules ,
278
278
_ => true ,
279
279
} ) {
280
280
errors. push ( Error :: ValidityCriteria ) ;
@@ -294,10 +294,10 @@ fn validate(label: &str, is_bidi_domain: bool, flags: Flags, errors: &mut Vec<Er
294
294
}
295
295
296
296
/// http://www.unicode.org/reports/tr46/#Processing
297
- fn processing ( domain : & str , flags : Flags , errors : & mut Vec < Error > ) -> String {
297
+ fn processing ( domain : & str , config : Config , errors : & mut Vec < Error > ) -> String {
298
298
let mut mapped = String :: with_capacity ( domain. len ( ) ) ;
299
299
for c in domain. chars ( ) {
300
- map_char ( c, flags, & mut mapped, errors)
300
+ map_char ( c, config . flags , & mut mapped, errors)
301
301
}
302
302
let mut normalized = String :: with_capacity ( mapped. len ( ) ) ;
303
303
normalized. extend ( mapped. nfc ( ) ) ;
@@ -338,15 +338,15 @@ fn processing(domain: &str, flags: Flags, errors: &mut Vec<Error>) -> String {
338
338
if label. starts_with ( PUNYCODE_PREFIX ) {
339
339
match punycode:: decode_to_string ( & label[ PUNYCODE_PREFIX . len ( ) ..] ) {
340
340
Some ( decoded_label) => {
341
- let flags = Flags { transitional_processing : false , ..flags } ;
342
- validate_full ( & decoded_label, is_bidi_domain, flags , errors) ;
341
+ let config = config . transitional_processing ( false ) ;
342
+ validate_full ( & decoded_label, is_bidi_domain, config , errors) ;
343
343
validated. push_str ( & decoded_label)
344
344
}
345
345
None => errors. push ( Error :: PunycodeError )
346
346
}
347
347
} else {
348
348
// `normalized` is already `NFC` so we can skip that check
349
- validate ( label, is_bidi_domain, flags , errors) ;
349
+ validate ( label, is_bidi_domain, config , errors) ;
350
350
validated. push_str ( label)
351
351
}
352
352
}
@@ -389,7 +389,7 @@ impl Config {
389
389
let mut errors = Vec :: new ( ) ;
390
390
let mut result = String :: new ( ) ;
391
391
let mut first = true ;
392
- for label in processing ( domain, self . flags , & mut errors) . split ( '.' ) {
392
+ for label in processing ( domain, self , & mut errors) . split ( '.' ) {
393
393
if !first {
394
394
result. push ( '.' ) ;
395
395
}
@@ -426,7 +426,7 @@ impl Config {
426
426
/// http://www.unicode.org/reports/tr46/#ToUnicode
427
427
pub fn to_unicode ( self , domain : & str ) -> ( String , Result < ( ) , Errors > ) {
428
428
let mut errors = Vec :: new ( ) ;
429
- let domain = processing ( domain, self . flags , & mut errors) ;
429
+ let domain = processing ( domain, self , & mut errors) ;
430
430
let errors = if errors. is_empty ( ) {
431
431
Ok ( ( ) )
432
432
} else {
0 commit comments