mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Run rustfmt on selectors, servo_arc, and style.
This was generated with: ./mach cargo fmt --package selectors && ./mach cargo fmt --package servo_arc && ./mach cargo fmt --package style Using rustfmt 0.4.1-nightly (a4462d1 2018-03-26)
This commit is contained in:
parent
f7ae1a37e3
commit
c99bcdd4b8
181 changed files with 9981 additions and 7933 deletions
|
@ -19,9 +19,7 @@ impl<Impl: SelectorImpl> AttrSelectorWithNamespace<Impl> {
|
|||
pub fn namespace(&self) -> NamespaceConstraint<&Impl::NamespaceUrl> {
|
||||
match self.namespace {
|
||||
NamespaceConstraint::Any => NamespaceConstraint::Any,
|
||||
NamespaceConstraint::Specific((_, ref url)) => {
|
||||
NamespaceConstraint::Specific(url)
|
||||
}
|
||||
NamespaceConstraint::Specific((_, ref url)) => NamespaceConstraint::Specific(url),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -41,7 +39,7 @@ pub enum ParsedAttrSelectorOperation<AttrValue> {
|
|||
operator: AttrSelectorOperator,
|
||||
case_sensitivity: ParsedCaseSensitivity,
|
||||
expected_value: AttrValue,
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Clone, Eq, PartialEq)]
|
||||
|
@ -51,16 +49,25 @@ pub enum AttrSelectorOperation<AttrValue> {
|
|||
operator: AttrSelectorOperator,
|
||||
case_sensitivity: CaseSensitivity,
|
||||
expected_value: AttrValue,
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
impl<AttrValue> AttrSelectorOperation<AttrValue> {
|
||||
pub fn eval_str(&self, element_attr_value: &str) -> bool where AttrValue: AsRef<str> {
|
||||
pub fn eval_str(&self, element_attr_value: &str) -> bool
|
||||
where
|
||||
AttrValue: AsRef<str>,
|
||||
{
|
||||
match *self {
|
||||
AttrSelectorOperation::Exists => true,
|
||||
AttrSelectorOperation::WithValue { operator, case_sensitivity, ref expected_value } => {
|
||||
operator.eval_str(element_attr_value, expected_value.as_ref(), case_sensitivity)
|
||||
}
|
||||
AttrSelectorOperation::WithValue {
|
||||
operator,
|
||||
case_sensitivity,
|
||||
ref expected_value,
|
||||
} => operator.eval_str(
|
||||
element_attr_value,
|
||||
expected_value.as_ref(),
|
||||
case_sensitivity,
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -76,7 +83,10 @@ pub enum AttrSelectorOperator {
|
|||
}
|
||||
|
||||
impl ToCss for AttrSelectorOperator {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result
|
||||
where
|
||||
W: fmt::Write,
|
||||
{
|
||||
// https://drafts.csswg.org/cssom/#serializing-selectors
|
||||
// See "attribute selector".
|
||||
dest.write_str(match *self {
|
||||
|
@ -91,34 +101,30 @@ impl ToCss for AttrSelectorOperator {
|
|||
}
|
||||
|
||||
impl AttrSelectorOperator {
|
||||
pub fn eval_str(self, element_attr_value: &str, attr_selector_value: &str,
|
||||
case_sensitivity: CaseSensitivity) -> bool {
|
||||
pub fn eval_str(
|
||||
self,
|
||||
element_attr_value: &str,
|
||||
attr_selector_value: &str,
|
||||
case_sensitivity: CaseSensitivity,
|
||||
) -> bool {
|
||||
let e = element_attr_value.as_bytes();
|
||||
let s = attr_selector_value.as_bytes();
|
||||
let case = case_sensitivity;
|
||||
match self {
|
||||
AttrSelectorOperator::Equal => {
|
||||
case.eq(e, s)
|
||||
}
|
||||
AttrSelectorOperator::Prefix => {
|
||||
e.len() >= s.len() && case.eq(&e[..s.len()], s)
|
||||
}
|
||||
AttrSelectorOperator::Equal => case.eq(e, s),
|
||||
AttrSelectorOperator::Prefix => e.len() >= s.len() && case.eq(&e[..s.len()], s),
|
||||
AttrSelectorOperator::Suffix => {
|
||||
e.len() >= s.len() && case.eq(&e[(e.len() - s.len())..], s)
|
||||
}
|
||||
},
|
||||
AttrSelectorOperator::Substring => {
|
||||
case.contains(element_attr_value, attr_selector_value)
|
||||
}
|
||||
AttrSelectorOperator::Includes => {
|
||||
element_attr_value.split(SELECTOR_WHITESPACE)
|
||||
.any(|part| case.eq(part.as_bytes(), s))
|
||||
}
|
||||
},
|
||||
AttrSelectorOperator::Includes => element_attr_value
|
||||
.split(SELECTOR_WHITESPACE)
|
||||
.any(|part| case.eq(part.as_bytes(), s)),
|
||||
AttrSelectorOperator::DashMatch => {
|
||||
case.eq(e, s) || (
|
||||
e.get(s.len()) == Some(&b'-') &&
|
||||
case.eq(&e[..s.len()], s)
|
||||
)
|
||||
}
|
||||
case.eq(e, s) || (e.get(s.len()) == Some(&b'-') && case.eq(&e[..s.len()], s))
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -137,12 +143,13 @@ impl ParsedCaseSensitivity {
|
|||
pub fn to_unconditional(self, is_html_element_in_html_document: bool) -> CaseSensitivity {
|
||||
match self {
|
||||
ParsedCaseSensitivity::AsciiCaseInsensitiveIfInHtmlElementInHtmlDocument
|
||||
if is_html_element_in_html_document => {
|
||||
if is_html_element_in_html_document =>
|
||||
{
|
||||
CaseSensitivity::AsciiCaseInsensitive
|
||||
}
|
||||
},
|
||||
ParsedCaseSensitivity::AsciiCaseInsensitiveIfInHtmlElementInHtmlDocument => {
|
||||
CaseSensitivity::CaseSensitive
|
||||
}
|
||||
},
|
||||
ParsedCaseSensitivity::CaseSensitive => CaseSensitivity::CaseSensitive,
|
||||
ParsedCaseSensitivity::AsciiCaseInsensitive => CaseSensitivity::AsciiCaseInsensitive,
|
||||
}
|
||||
|
@ -170,14 +177,12 @@ impl CaseSensitivity {
|
|||
if let Some((&n_first_byte, n_rest)) = needle.as_bytes().split_first() {
|
||||
haystack.bytes().enumerate().any(|(i, byte)| {
|
||||
if !byte.eq_ignore_ascii_case(&n_first_byte) {
|
||||
return false
|
||||
return false;
|
||||
}
|
||||
let after_this_byte = &haystack.as_bytes()[i + 1..];
|
||||
match after_this_byte.get(..n_rest.len()) {
|
||||
None => false,
|
||||
Some(haystack_slice) => {
|
||||
haystack_slice.eq_ignore_ascii_case(n_rest)
|
||||
}
|
||||
Some(haystack_slice) => haystack_slice.eq_ignore_ascii_case(n_rest),
|
||||
}
|
||||
})
|
||||
} else {
|
||||
|
@ -185,7 +190,7 @@ impl CaseSensitivity {
|
|||
// though these cases should be handled with *NeverMatches and never go here.
|
||||
true
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue