@@ -81,13 +81,13 @@ fn find_char(codepoint: char) -> &'static Mapping {
81
81
. unwrap ( )
82
82
}
83
83
84
- fn map_char ( codepoint : char , flags : Flags , output : & mut String , errors : & mut Vec < Error > ) {
84
+ fn map_char ( codepoint : char , config : Config , output : & mut String , errors : & mut Vec < Error > ) {
85
85
match * find_char ( codepoint) {
86
86
Mapping :: Valid => output. push ( codepoint) ,
87
87
Mapping :: Ignored => { }
88
88
Mapping :: Mapped ( ref slice) => output. push_str ( decode_slice ( slice) ) ,
89
89
Mapping :: Deviation ( ref slice) => {
90
- if flags . transitional_processing {
90
+ if config . transitional_processing {
91
91
output. push_str ( decode_slice ( slice) )
92
92
} else {
93
93
output. push ( codepoint)
@@ -98,13 +98,13 @@ fn map_char(codepoint: char, flags: Flags, output: &mut String, errors: &mut Vec
98
98
output. push ( codepoint) ;
99
99
}
100
100
Mapping :: DisallowedStd3Valid => {
101
- if flags . use_std3_ascii_rules {
101
+ if config . use_std3_ascii_rules {
102
102
errors. push ( Error :: DissallowedByStd3AsciiRules ) ;
103
103
}
104
104
output. push ( codepoint)
105
105
}
106
106
Mapping :: DisallowedStd3Mapped ( ref slice) => {
107
- if flags . use_std3_ascii_rules {
107
+ if config . use_std3_ascii_rules {
108
108
errors. push ( Error :: DissallowedMappedInStd3 ) ;
109
109
}
110
110
output. push_str ( decode_slice ( slice) )
@@ -293,8 +293,8 @@ fn validate(label: &str, is_bidi_domain: bool, config: Config, errors: &mut Vec<
293
293
// V6: Check against Mapping Table
294
294
else if label. chars ( ) . any ( |c| match * find_char ( c) {
295
295
Mapping :: Valid => false ,
296
- Mapping :: Deviation ( _) => config. flags . transitional_processing ,
297
- Mapping :: DisallowedStd3Valid => config. flags . use_std3_ascii_rules ,
296
+ Mapping :: Deviation ( _) => config. transitional_processing ,
297
+ Mapping :: DisallowedStd3Valid => config. use_std3_ascii_rules ,
298
298
_ => true ,
299
299
} ) {
300
300
errors. push ( Error :: ValidityCriteria ) ;
@@ -315,7 +315,7 @@ fn validate(label: &str, is_bidi_domain: bool, config: Config, errors: &mut Vec<
315
315
fn processing ( domain : & str , config : Config , errors : & mut Vec < Error > ) -> String {
316
316
let mut mapped = String :: with_capacity ( domain. len ( ) ) ;
317
317
for c in domain. chars ( ) {
318
- map_char ( c, config. flags , & mut mapped, errors)
318
+ map_char ( c, config, & mut mapped, errors)
319
319
}
320
320
let mut normalized = String :: with_capacity ( mapped. len ( ) ) ;
321
321
normalized. extend ( mapped. nfc ( ) ) ;
@@ -371,35 +371,30 @@ fn processing(domain: &str, config: Config, errors: &mut Vec<Error>) -> String {
371
371
validated
372
372
}
373
373
374
- #[ derive( Clone , Copy ) ]
374
+ #[ derive( Clone , Copy , Default ) ]
375
375
pub struct Config {
376
- flags : Flags ,
376
+ use_std3_ascii_rules : bool ,
377
+ transitional_processing : bool ,
378
+ verify_dns_length : bool ,
377
379
check_hyphens : bool ,
378
380
}
379
381
380
- impl From < Flags > for Config {
381
- #[ inline]
382
- fn from ( flags : Flags ) -> Self {
383
- Self { flags, check_hyphens : true }
384
- }
385
- }
386
-
387
382
impl Config {
388
383
#[ inline]
389
384
pub fn use_std3_ascii_rules ( mut self , value : bool ) -> Self {
390
- self . flags . use_std3_ascii_rules = value;
385
+ self . use_std3_ascii_rules = value;
391
386
self
392
387
}
393
388
394
389
#[ inline]
395
390
pub fn transitional_processing ( mut self , value : bool ) -> Self {
396
- self . flags . transitional_processing = value;
391
+ self . transitional_processing = value;
397
392
self
398
393
}
399
394
400
395
#[ inline]
401
396
pub fn verify_dns_length ( mut self , value : bool ) -> Self {
402
- self . flags . verify_dns_length = value;
397
+ self . verify_dns_length = value;
403
398
self
404
399
}
405
400
@@ -432,7 +427,7 @@ impl Config {
432
427
}
433
428
}
434
429
435
- if self . flags . verify_dns_length {
430
+ if self . verify_dns_length {
436
431
let domain = if result. ends_with ( "." ) { & result[ ..result. len ( ) -1 ] } else { & * result } ;
437
432
if domain. len ( ) < 1 || domain. split ( '.' ) . any ( |label| label. len ( ) < 1 ) {
438
433
errors. push ( Error :: TooShortForDns )
@@ -462,13 +457,6 @@ impl Config {
462
457
463
458
}
464
459
465
- #[ derive( Copy , Clone ) ]
466
- pub struct Flags {
467
- pub use_std3_ascii_rules : bool ,
468
- pub transitional_processing : bool ,
469
- pub verify_dns_length : bool ,
470
- }
471
-
472
460
#[ derive( PartialEq , Eq , Clone , Copy , Debug ) ]
473
461
enum Error {
474
462
PunycodeError ,
@@ -486,16 +474,3 @@ enum Error {
486
474
/// More details may be exposed in the future.
487
475
#[ derive( Debug ) ]
488
476
pub struct Errors ( Vec < Error > ) ;
489
-
490
- /// http://www.unicode.org/reports/tr46/#ToASCII
491
- pub fn to_ascii ( domain : & str , flags : Flags ) -> Result < String , Errors > {
492
- Config :: from ( flags) . to_ascii ( domain)
493
- }
494
-
495
- /// http://www.unicode.org/reports/tr46/#ToUnicode
496
- ///
497
- /// Only `use_std3_ascii_rules` is used in `flags`.
498
- pub fn to_unicode ( domain : & str , mut flags : Flags ) -> ( String , Result < ( ) , Errors > ) {
499
- flags. transitional_processing = false ;
500
- Config :: from ( flags) . to_unicode ( domain)
501
- }
0 commit comments