mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
style: Multiple style nits across parsing code.
This commit is contained in:
parent
726f918b46
commit
705ecb4557
5 changed files with 98 additions and 85 deletions
|
@ -442,7 +442,7 @@ impl Length {
|
|||
/// Parse a non-negative length
|
||||
#[inline]
|
||||
pub fn parse_non_negative(input: &mut Parser) -> Result<Length, ()> {
|
||||
Length::parse_internal(input, AllowedNumericType::NonNegative)
|
||||
Self::parse_internal(input, AllowedNumericType::NonNegative)
|
||||
}
|
||||
|
||||
/// Get an absolute length from a px value.
|
||||
|
@ -462,7 +462,7 @@ impl Length {
|
|||
|
||||
impl Parse for Length {
|
||||
fn parse(_context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
|
||||
Length::parse_internal(input, AllowedNumericType::All)
|
||||
Self::parse_internal(input, AllowedNumericType::All)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1049,7 +1049,7 @@ impl LengthOrPercentage {
|
|||
/// Parse a non-negative length.
|
||||
#[inline]
|
||||
pub fn parse_non_negative(input: &mut Parser) -> Result<LengthOrPercentage, ()> {
|
||||
LengthOrPercentage::parse_internal(input, AllowedNumericType::NonNegative)
|
||||
Self::parse_internal(input, AllowedNumericType::NonNegative)
|
||||
}
|
||||
|
||||
/// Parse a length, treating dimensionless numbers as pixels
|
||||
|
@ -1057,11 +1057,13 @@ impl LengthOrPercentage {
|
|||
/// https://www.w3.org/TR/SVG2/types.html#presentation-attribute-css-value
|
||||
pub fn parse_numbers_are_pixels(input: &mut Parser) -> Result<LengthOrPercentage, ()> {
|
||||
if let Ok(lop) = input.try(|i| Self::parse_internal(i, AllowedNumericType::All)) {
|
||||
Ok(lop)
|
||||
} else {
|
||||
let num = input.expect_number()?;
|
||||
Ok(LengthOrPercentage::Length(NoCalcLength::Absolute(Au((AU_PER_PX * num) as i32))))
|
||||
return Ok(lop)
|
||||
}
|
||||
|
||||
// TODO(emilio): Probably should use Number::parse_non_negative to
|
||||
// handle calc()?
|
||||
let num = input.expect_number()?;
|
||||
Ok(LengthOrPercentage::Length(NoCalcLength::Absolute(Au((AU_PER_PX * num) as i32))))
|
||||
}
|
||||
|
||||
/// Parse a non-negative length, treating dimensionless numbers as pixels
|
||||
|
@ -1069,14 +1071,16 @@ impl LengthOrPercentage {
|
|||
/// This is nonstandard behavior used by Firefox for SVG
|
||||
pub fn parse_numbers_are_pixels_non_negative(input: &mut Parser) -> Result<LengthOrPercentage, ()> {
|
||||
if let Ok(lop) = input.try(|i| Self::parse_internal(i, AllowedNumericType::NonNegative)) {
|
||||
Ok(lop)
|
||||
return Ok(lop)
|
||||
}
|
||||
|
||||
// TODO(emilio): Probably should use Number::parse_non_negative to
|
||||
// handle calc()?
|
||||
let num = input.expect_number()?;
|
||||
if num >= 0. {
|
||||
Ok(LengthOrPercentage::Length(NoCalcLength::Absolute(Au((AU_PER_PX * num) as i32))))
|
||||
} else {
|
||||
let num = input.expect_number()?;
|
||||
if num >= 0. {
|
||||
Ok(LengthOrPercentage::Length(NoCalcLength::Absolute(Au((AU_PER_PX * num) as i32))))
|
||||
} else {
|
||||
Err(())
|
||||
}
|
||||
Err(())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1092,7 +1096,7 @@ impl LengthOrPercentage {
|
|||
impl Parse for LengthOrPercentage {
|
||||
#[inline]
|
||||
fn parse(_context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
|
||||
LengthOrPercentage::parse_internal(input, AllowedNumericType::All)
|
||||
Self::parse_internal(input, AllowedNumericType::All)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1168,7 +1172,7 @@ impl LengthOrPercentageOrAuto {
|
|||
/// Parse a non-negative length, percentage, or auto.
|
||||
#[inline]
|
||||
pub fn parse_non_negative(input: &mut Parser) -> Result<LengthOrPercentageOrAuto, ()> {
|
||||
LengthOrPercentageOrAuto::parse_internal(input, AllowedNumericType::NonNegative)
|
||||
Self::parse_internal(input, AllowedNumericType::NonNegative)
|
||||
}
|
||||
|
||||
/// Parse a non-negative length, percentage, or auto.
|
||||
|
@ -1183,7 +1187,7 @@ impl LengthOrPercentageOrAuto {
|
|||
impl Parse for LengthOrPercentageOrAuto {
|
||||
#[inline]
|
||||
fn parse(_context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
|
||||
LengthOrPercentageOrAuto::parse_internal(input, AllowedNumericType::All)
|
||||
Self::parse_internal(input, AllowedNumericType::All)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1241,15 +1245,15 @@ impl LengthOrPercentageOrNone {
|
|||
}
|
||||
/// Parse a non-negative LengthOrPercentageOrNone.
|
||||
#[inline]
|
||||
pub fn parse_non_negative(input: &mut Parser) -> Result<LengthOrPercentageOrNone, ()> {
|
||||
LengthOrPercentageOrNone::parse_internal(input, AllowedNumericType::NonNegative)
|
||||
pub fn parse_non_negative(input: &mut Parser) -> Result<Self, ()> {
|
||||
Self::parse_internal(input, AllowedNumericType::NonNegative)
|
||||
}
|
||||
}
|
||||
|
||||
impl Parse for LengthOrPercentageOrNone {
|
||||
#[inline]
|
||||
fn parse(_context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
|
||||
LengthOrPercentageOrNone::parse_internal(input, AllowedNumericType::All)
|
||||
Self::parse_internal(input, AllowedNumericType::All)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1341,15 +1345,15 @@ pub type LengthOrNumber = Either<Length, Number>;
|
|||
|
||||
impl LengthOrNumber {
|
||||
/// Parse a non-negative LengthOrNumber.
|
||||
pub fn parse_non_negative(_context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
|
||||
// We try to parse as a Number first because, for cases like LengthOrNumber,
|
||||
// we want "0" to be parsed as a plain Number rather than a Length (0px); this
|
||||
// matches the behaviour of all major browsers
|
||||
pub fn parse_non_negative(_: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
|
||||
// We try to parse as a Number first because, for cases like
|
||||
// LengthOrNumber, we want "0" to be parsed as a plain Number rather
|
||||
// than a Length (0px); this matches the behaviour of all major browsers
|
||||
if let Ok(v) = input.try(Number::parse_non_negative) {
|
||||
Ok(Either::Second(v))
|
||||
} else {
|
||||
Length::parse_non_negative(input).map(Either::First)
|
||||
return Ok(Either::Second(v))
|
||||
}
|
||||
|
||||
Length::parse_non_negative(input).map(Either::First)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue