mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +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
|
@ -6,7 +6,7 @@
|
|||
//!
|
||||
//! [attr]: https://dom.spec.whatwg.org/#interface-attr
|
||||
|
||||
use {Atom, Prefix, Namespace, LocalName};
|
||||
use {Atom, LocalName, Namespace, Prefix};
|
||||
use app_units::Au;
|
||||
use cssparser::{self, Color, RGBA};
|
||||
use euclid::num::Zero;
|
||||
|
@ -17,7 +17,7 @@ use servo_arc::Arc;
|
|||
use servo_url::ServoUrl;
|
||||
use shared_lock::Locked;
|
||||
use std::str::FromStr;
|
||||
use str::{HTML_SPACE_CHARACTERS, read_exponent, read_fraction};
|
||||
use str::{read_exponent, read_fraction, HTML_SPACE_CHARACTERS};
|
||||
use str::{read_numbers, split_commas, split_html_space_chars};
|
||||
use str::str_join;
|
||||
use values::specified::Length;
|
||||
|
@ -64,18 +64,19 @@ pub enum AttrValue {
|
|||
/// Note that we don't necessarily need to do that (we could just clone the
|
||||
/// declaration block), but that avoids keeping a refcounted
|
||||
/// declarationblock for longer than needed.
|
||||
Declaration(String,
|
||||
#[ignore_malloc_size_of = "Arc"]
|
||||
Arc<Locked<PropertyDeclarationBlock>>)
|
||||
Declaration(
|
||||
String,
|
||||
#[ignore_malloc_size_of = "Arc"] Arc<Locked<PropertyDeclarationBlock>>,
|
||||
),
|
||||
}
|
||||
|
||||
/// Shared implementation to parse an integer according to
|
||||
/// <https://html.spec.whatwg.org/multipage/#rules-for-parsing-integers> or
|
||||
/// <https://html.spec.whatwg.org/multipage/#rules-for-parsing-non-negative-integers>
|
||||
fn do_parse_integer<T: Iterator<Item=char>>(input: T) -> Result<i64, ()> {
|
||||
let mut input = input.skip_while(|c| {
|
||||
HTML_SPACE_CHARACTERS.iter().any(|s| s == c)
|
||||
}).peekable();
|
||||
fn do_parse_integer<T: Iterator<Item = char>>(input: T) -> Result<i64, ()> {
|
||||
let mut input = input
|
||||
.skip_while(|c| HTML_SPACE_CHARACTERS.iter().any(|s| s == c))
|
||||
.peekable();
|
||||
|
||||
let sign = match input.peek() {
|
||||
None => return Err(()),
|
||||
|
@ -97,18 +98,14 @@ fn do_parse_integer<T: Iterator<Item=char>>(input: T) -> Result<i64, ()> {
|
|||
|
||||
/// Parse an integer according to
|
||||
/// <https://html.spec.whatwg.org/multipage/#rules-for-parsing-integers>.
|
||||
pub fn parse_integer<T: Iterator<Item=char>>(input: T) -> Result<i32, ()> {
|
||||
do_parse_integer(input).and_then(|result| {
|
||||
result.to_i32().ok_or(())
|
||||
})
|
||||
pub fn parse_integer<T: Iterator<Item = char>>(input: T) -> Result<i32, ()> {
|
||||
do_parse_integer(input).and_then(|result| result.to_i32().ok_or(()))
|
||||
}
|
||||
|
||||
/// Parse an integer according to
|
||||
/// <https://html.spec.whatwg.org/multipage/#rules-for-parsing-non-negative-integers>
|
||||
pub fn parse_unsigned_integer<T: Iterator<Item=char>>(input: T) -> Result<u32, ()> {
|
||||
do_parse_integer(input).and_then(|result| {
|
||||
result.to_u32().ok_or(())
|
||||
})
|
||||
pub fn parse_unsigned_integer<T: Iterator<Item = char>>(input: T) -> Result<u32, ()> {
|
||||
do_parse_integer(input).and_then(|result| result.to_u32().ok_or(()))
|
||||
}
|
||||
|
||||
/// Parse a floating-point number according to
|
||||
|
@ -122,26 +119,35 @@ pub fn parse_double(string: &str) -> Result<f64, ()> {
|
|||
Some(&'-') => {
|
||||
input.next();
|
||||
(-1f64, -1f64, 1)
|
||||
}
|
||||
},
|
||||
Some(&'+') => {
|
||||
input.next();
|
||||
(1f64, 1f64, 1)
|
||||
}
|
||||
_ => (1f64, 1f64, 0)
|
||||
},
|
||||
_ => (1f64, 1f64, 0),
|
||||
};
|
||||
|
||||
let (value, value_digits) = if let Some(&'.') = input.peek() {
|
||||
(0f64, 0)
|
||||
} else {
|
||||
let (read_val, read_digits) = read_numbers(input);
|
||||
(value * read_val.and_then(|result| result.to_f64()).unwrap_or(1f64), read_digits)
|
||||
(
|
||||
value * read_val.and_then(|result| result.to_f64()).unwrap_or(1f64),
|
||||
read_digits,
|
||||
)
|
||||
};
|
||||
|
||||
let input = trimmed.chars().skip(value_digits + chars_skipped).peekable();
|
||||
let input = trimmed
|
||||
.chars()
|
||||
.skip(value_digits + chars_skipped)
|
||||
.peekable();
|
||||
|
||||
let (mut value, fraction_digits) = read_fraction(input, divisor, value);
|
||||
|
||||
let input = trimmed.chars().skip(value_digits + chars_skipped + fraction_digits).peekable();
|
||||
let input = trimmed
|
||||
.chars()
|
||||
.skip(value_digits + chars_skipped + fraction_digits)
|
||||
.peekable();
|
||||
|
||||
if let Some(exp) = read_exponent(input) {
|
||||
value *= 10f64.powi(exp)
|
||||
|
@ -152,22 +158,27 @@ pub fn parse_double(string: &str) -> Result<f64, ()> {
|
|||
|
||||
impl AttrValue {
|
||||
pub fn from_serialized_tokenlist(tokens: String) -> AttrValue {
|
||||
let atoms =
|
||||
split_html_space_chars(&tokens)
|
||||
.map(Atom::from)
|
||||
.fold(vec![], |mut acc, atom| {
|
||||
if !acc.contains(&atom) { acc.push(atom) }
|
||||
let atoms = split_html_space_chars(&tokens).map(Atom::from).fold(
|
||||
vec![],
|
||||
|mut acc, atom| {
|
||||
if !acc.contains(&atom) {
|
||||
acc.push(atom)
|
||||
}
|
||||
acc
|
||||
});
|
||||
},
|
||||
);
|
||||
AttrValue::TokenList(tokens, atoms)
|
||||
}
|
||||
|
||||
pub fn from_comma_separated_tokenlist(tokens: String) -> AttrValue {
|
||||
let atoms = split_commas(&tokens).map(Atom::from)
|
||||
.fold(vec![], |mut acc, atom| {
|
||||
if !acc.contains(&atom) { acc.push(atom) }
|
||||
acc
|
||||
});
|
||||
let atoms = split_commas(&tokens)
|
||||
.map(Atom::from)
|
||||
.fold(vec![], |mut acc, atom| {
|
||||
if !acc.contains(&atom) {
|
||||
acc.push(atom)
|
||||
}
|
||||
acc
|
||||
});
|
||||
AttrValue::TokenList(tokens, atoms)
|
||||
}
|
||||
|
||||
|
@ -407,7 +418,7 @@ pub fn parse_nonzero_length(value: &str) -> LengthOrPercentageOrAuto {
|
|||
pub fn parse_legacy_color(mut input: &str) -> Result<RGBA, ()> {
|
||||
// Steps 1 and 2.
|
||||
if input.is_empty() {
|
||||
return Err(())
|
||||
return Err(());
|
||||
}
|
||||
|
||||
// Step 3.
|
||||
|
@ -415,7 +426,7 @@ pub fn parse_legacy_color(mut input: &str) -> Result<RGBA, ()> {
|
|||
|
||||
// Step 4.
|
||||
if input.eq_ignore_ascii_case("transparent") {
|
||||
return Err(())
|
||||
return Err(());
|
||||
}
|
||||
|
||||
// Step 5.
|
||||
|
@ -425,12 +436,13 @@ pub fn parse_legacy_color(mut input: &str) -> Result<RGBA, ()> {
|
|||
|
||||
// Step 6.
|
||||
if input.len() == 4 {
|
||||
if let (b'#', Ok(r), Ok(g), Ok(b)) =
|
||||
(input.as_bytes()[0],
|
||||
hex(input.as_bytes()[1] as char),
|
||||
hex(input.as_bytes()[2] as char),
|
||||
hex(input.as_bytes()[3] as char)) {
|
||||
return Ok(RGBA::new(r * 17, g * 17, b * 17, 255))
|
||||
if let (b'#', Ok(r), Ok(g), Ok(b)) = (
|
||||
input.as_bytes()[0],
|
||||
hex(input.as_bytes()[1] as char),
|
||||
hex(input.as_bytes()[2] as char),
|
||||
hex(input.as_bytes()[3] as char),
|
||||
) {
|
||||
return Ok(RGBA::new(r * 17, g * 17, b * 17, 255));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -449,7 +461,7 @@ pub fn parse_legacy_color(mut input: &str) -> Result<RGBA, ()> {
|
|||
for (char_count, (index, _)) in input.char_indices().enumerate() {
|
||||
if char_count == 128 {
|
||||
input = &input[..index];
|
||||
break
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -476,9 +488,11 @@ pub fn parse_legacy_color(mut input: &str) -> Result<RGBA, ()> {
|
|||
|
||||
// Step 12.
|
||||
let mut length = input.len() / 3;
|
||||
let (mut red, mut green, mut blue) = (&input[..length],
|
||||
&input[length..length * 2],
|
||||
&input[length * 2..]);
|
||||
let (mut red, mut green, mut blue) = (
|
||||
&input[..length],
|
||||
&input[length..length * 2],
|
||||
&input[length * 2..],
|
||||
);
|
||||
|
||||
// Step 13.
|
||||
if length > 8 {
|
||||
|
@ -497,10 +511,12 @@ pub fn parse_legacy_color(mut input: &str) -> Result<RGBA, ()> {
|
|||
}
|
||||
|
||||
// Steps 15-20.
|
||||
return Ok(RGBA::new(hex_string(red).unwrap(),
|
||||
hex_string(green).unwrap(),
|
||||
hex_string(blue).unwrap(),
|
||||
255));
|
||||
return Ok(RGBA::new(
|
||||
hex_string(red).unwrap(),
|
||||
hex_string(green).unwrap(),
|
||||
hex_string(blue).unwrap(),
|
||||
255,
|
||||
));
|
||||
|
||||
fn hex(ch: char) -> Result<u8, ()> {
|
||||
match ch {
|
||||
|
@ -519,7 +535,7 @@ pub fn parse_legacy_color(mut input: &str) -> Result<RGBA, ()> {
|
|||
let upper = hex(string[0] as char)?;
|
||||
let lower = hex(string[1] as char)?;
|
||||
Ok((upper << 4) | lower)
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -536,7 +552,7 @@ pub fn parse_length(mut value: &str) -> LengthOrPercentageOrAuto {
|
|||
|
||||
// Step 4
|
||||
if value.is_empty() {
|
||||
return LengthOrPercentageOrAuto::Auto
|
||||
return LengthOrPercentageOrAuto::Auto;
|
||||
}
|
||||
|
||||
// Step 5
|
||||
|
@ -565,16 +581,16 @@ pub fn parse_length(mut value: &str) -> LengthOrPercentageOrAuto {
|
|||
'%' => {
|
||||
found_percent = true;
|
||||
end_index = i;
|
||||
break
|
||||
}
|
||||
break;
|
||||
},
|
||||
'.' if !found_full_stop => {
|
||||
found_full_stop = true;
|
||||
continue
|
||||
}
|
||||
continue;
|
||||
},
|
||||
_ => {
|
||||
end_index = i;
|
||||
break
|
||||
}
|
||||
break;
|
||||
},
|
||||
}
|
||||
}
|
||||
value = &value[..end_index];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue