mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
style: Clean up extended_filtering a bit.
This commit is contained in:
parent
524794c09a
commit
094052c544
1 changed files with 20 additions and 25 deletions
|
@ -616,53 +616,48 @@ impl<E: Element<Impl=SelectorImpl> + Debug> ElementExt for E {
|
||||||
/// Returns whether the language is matched, as defined by
|
/// Returns whether the language is matched, as defined by
|
||||||
/// [RFC 4647](https://tools.ietf.org/html/rfc4647#section-3.3.2).
|
/// [RFC 4647](https://tools.ietf.org/html/rfc4647#section-3.3.2).
|
||||||
pub fn extended_filtering(tag: &str, range: &str) -> bool {
|
pub fn extended_filtering(tag: &str, range: &str) -> bool {
|
||||||
let lang_ranges: Vec<&str> = range.split(',').collect();
|
range.split(',').any(|lang_range| {
|
||||||
|
|
||||||
lang_ranges.iter().any(|&lang_range| {
|
|
||||||
// step 1
|
// step 1
|
||||||
let range_subtags: Vec<&str> = lang_range.split('\x2d').collect();
|
let mut range_subtags = lang_range.split('\x2d');
|
||||||
let tag_subtags: Vec<&str> = tag.split('\x2d').collect();
|
let mut tag_subtags = tag.split('\x2d');
|
||||||
|
|
||||||
let mut range_iter = range_subtags.iter();
|
|
||||||
let mut tag_iter = tag_subtags.iter();
|
|
||||||
|
|
||||||
// step 2
|
// step 2
|
||||||
// Note: [Level-4 spec](https://drafts.csswg.org/selectors/#lang-pseudo) check for wild card
|
// Note: [Level-4 spec](https://drafts.csswg.org/selectors/#lang-pseudo) check for wild card
|
||||||
if let (Some(range_subtag), Some(tag_subtag)) = (range_iter.next(), tag_iter.next()) {
|
if let (Some(range_subtag), Some(tag_subtag)) = (range_subtags.next(), tag_subtags.next()) {
|
||||||
if !(range_subtag.eq_ignore_ascii_case(tag_subtag) || range_subtag.eq_ignore_ascii_case("*")) {
|
if !(range_subtag.eq_ignore_ascii_case(tag_subtag) || range_subtag.eq_ignore_ascii_case("*")) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut current_tag_subtag = tag_iter.next();
|
let mut current_tag_subtag = tag_subtags.next();
|
||||||
|
|
||||||
// step 3
|
// step 3
|
||||||
for range_subtag in range_iter {
|
for range_subtag in range_subtags {
|
||||||
// step 3a
|
// step 3a
|
||||||
if range_subtag.eq_ignore_ascii_case("*") {
|
if range_subtag == "*" {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
match current_tag_subtag.clone() {
|
match current_tag_subtag.clone() {
|
||||||
Some(tag_subtag) => {
|
Some(tag_subtag) => {
|
||||||
// step 3c
|
// step 3c
|
||||||
if range_subtag.eq_ignore_ascii_case(tag_subtag) {
|
if range_subtag.eq_ignore_ascii_case(tag_subtag) {
|
||||||
current_tag_subtag = tag_iter.next();
|
current_tag_subtag = tag_subtags.next();
|
||||||
continue;
|
continue;
|
||||||
} else {
|
}
|
||||||
// step 3d
|
// step 3d
|
||||||
if tag_subtag.len() == 1 {
|
if tag_subtag.len() == 1 {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
}
|
||||||
// else step 3e - continue with loop
|
// else step 3e - continue with loop
|
||||||
current_tag_subtag = tag_iter.next();
|
current_tag_subtag = tag_subtags.next();
|
||||||
if current_tag_subtag.is_none() {
|
if current_tag_subtag.is_none() {
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// step 3b
|
// step 3b
|
||||||
None => { return false; }
|
None => {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// step 4
|
// step 4
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue