mirror of
https://github.com/servo/servo.git
synced 2025-08-04 21:20:23 +01:00
parent
77553ab42c
commit
4a3addb72f
1 changed files with 7 additions and 7 deletions
|
@ -35,13 +35,13 @@ pub enum AttrValue {
|
||||||
/// Shared implementation to parse an integer according to
|
/// 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-integers> or
|
||||||
/// <https://html.spec.whatwg.org/multipage/#rules-for-parsing-non-negative-integers>
|
/// <https://html.spec.whatwg.org/multipage/#rules-for-parsing-non-negative-integers>
|
||||||
fn do_parse_integer<T: Iterator<Item=char>>(input: T) -> Option<i64> {
|
fn do_parse_integer<T: Iterator<Item=char>>(input: T) -> Result<i64, ()> {
|
||||||
let mut input = input.skip_while(|c| {
|
let mut input = input.skip_while(|c| {
|
||||||
HTML_SPACE_CHARACTERS.iter().any(|s| s == c)
|
HTML_SPACE_CHARACTERS.iter().any(|s| s == c)
|
||||||
}).peekable();
|
}).peekable();
|
||||||
|
|
||||||
let sign = match input.peek() {
|
let sign = match input.peek() {
|
||||||
None => return None,
|
None => return Err(()),
|
||||||
Some(&'-') => {
|
Some(&'-') => {
|
||||||
input.next();
|
input.next();
|
||||||
-1
|
-1
|
||||||
|
@ -55,23 +55,23 @@ fn do_parse_integer<T: Iterator<Item=char>>(input: T) -> Option<i64> {
|
||||||
|
|
||||||
let (value, _) = read_numbers(input);
|
let (value, _) = read_numbers(input);
|
||||||
|
|
||||||
value.and_then(|value| value.checked_mul(sign))
|
value.and_then(|value| value.checked_mul(sign)).ok_or(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parse an integer according to
|
/// Parse an integer according to
|
||||||
/// <https://html.spec.whatwg.org/multipage/#rules-for-parsing-integers>.
|
/// <https://html.spec.whatwg.org/multipage/#rules-for-parsing-integers>.
|
||||||
pub fn parse_integer<T: Iterator<Item=char>>(input: T) -> Result<i32, ()> {
|
pub fn parse_integer<T: Iterator<Item=char>>(input: T) -> Result<i32, ()> {
|
||||||
do_parse_integer(input).and_then(|result| {
|
do_parse_integer(input).and_then(|result| {
|
||||||
result.to_i32()
|
result.to_i32().ok_or(())
|
||||||
}).ok_or(())
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parse an integer according to
|
/// Parse an integer according to
|
||||||
/// <https://html.spec.whatwg.org/multipage/#rules-for-parsing-non-negative-integers>
|
/// <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, ()> {
|
pub fn parse_unsigned_integer<T: Iterator<Item=char>>(input: T) -> Result<u32, ()> {
|
||||||
do_parse_integer(input).and_then(|result| {
|
do_parse_integer(input).and_then(|result| {
|
||||||
result.to_u32()
|
result.to_u32().ok_or(())
|
||||||
}).ok_or(())
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parse a floating-point number according to
|
/// Parse a floating-point number according to
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue