Skip to content

Commit

Permalink
Use matches! macro and chars.skip(2). Remove unused error code.
Browse files Browse the repository at this point in the history
  • Loading branch information
valenting committed Jan 18, 2016
1 parent 9801e28 commit eb3846d
Showing 1 changed file with 12 additions and 27 deletions.
39 changes: 12 additions & 27 deletions src/idna.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,10 @@ fn passes_bidi(label: &str, transitional_processing: bool) -> bool {
match chars.next() {
Some(c) => {
let c = bidi_class(c);
if !(c == BidiClass::L ||
c == BidiClass::EN ||
c == BidiClass::ES ||
c == BidiClass::CS ||
c == BidiClass::ET ||
c == BidiClass::ON ||
c == BidiClass::BN ||
c == BidiClass::NSM) {
if !matches!(c, BidiClass::L | BidiClass::EN |
BidiClass::ES | BidiClass::CS |
BidiClass::ET | BidiClass::ON |
BidiClass::BN | BidiClass::NSM) {
return false;
}
},
Expand Down Expand Up @@ -152,16 +148,11 @@ fn passes_bidi(label: &str, transitional_processing: bool) -> bool {
found_an = true;
}

if !(char_class == BidiClass::R ||
char_class == BidiClass::AL ||
char_class == BidiClass::AN ||
char_class == BidiClass::EN ||
char_class == BidiClass::ES ||
char_class == BidiClass::CS ||
char_class == BidiClass::ET ||
char_class == BidiClass::ON ||
char_class == BidiClass::BN ||
char_class == BidiClass::NSM) {
if !matches!(char_class, BidiClass::R | BidiClass::AL |
BidiClass::AN | BidiClass::EN |
BidiClass::ES | BidiClass::CS |
BidiClass::ET | BidiClass::ON |
BidiClass::BN | BidiClass::NSM) {
return false;
}
},
Expand All @@ -181,10 +172,8 @@ fn passes_bidi(label: &str, transitional_processing: bool) -> bool {
}
}
match last {
Some(c) if bidi_class(c) == BidiClass::R
|| bidi_class(c) == BidiClass::AL
|| bidi_class(c) == BidiClass::EN
|| bidi_class(c) == BidiClass::AN => {},
Some(c) if matches!(bidi_class(c), BidiClass::R | BidiClass::AL |
BidiClass::EN | BidiClass::AN) => {},
_ => { return false; }
}

Expand All @@ -207,12 +196,9 @@ fn validate(label: &str, flags: Uts46Flags) -> Result<(), Error> {
return Err(Error::ValidityCriteria);
}

// Input is from nfc(), so it must be in NFC?
// Can not contain '.' since the input is from .split('.')
if {
let mut chars = label.chars();
let _first = chars.next();
let _first = chars.next();
let mut chars = label.chars().skip(2);
let third = chars.next();
let fourth = chars.next();
(third, fourth) == (Some('-'), Some('-'))
Expand Down Expand Up @@ -279,7 +265,6 @@ pub enum Error {
DissallowedMappedInStd3,
DissallowedCharacter,
TooLongForDns,
EmptyLabel,
}

/// http://www.unicode.org/reports/tr46/#ToASCII
Expand Down

0 comments on commit eb3846d

Please sign in to comment.