servo: Merge #10870 - Return a Result<i64, ()> from do_parse_integer (from axitkhurana:do-parse-integer-return-value); r=KiChjang
authorAkshit Khurana <axitkhurana@gmail.com>
Tue, 26 Apr 2016 23:26:29 -0700
changeset 476807 6474f545ecfb56d178f678f4b6a67eaabae1fbbd
parent 476806 6781eefa0c48be0ddae339b8fd024ebbb9d1e922
child 476808 d4b4439e3b7cc40f39946c82be076b3638078949
push id44079
push userbmo:gps@mozilla.com
push dateSat, 04 Feb 2017 00:14:49 +0000
reviewersKiChjang
servo: Merge #10870 - Return a Result<i64, ()> from do_parse_integer (from axitkhurana:do-parse-integer-return-value); r=KiChjang Fixes #10860 Source-Repo: https://github.com/servo/servo Source-Revision: 55ea0d1133f2ccd63cb44f9e7ce613c07bcf613f
servo/components/style/attr.rs
--- a/servo/components/style/attr.rs
+++ b/servo/components/style/attr.rs
@@ -30,53 +30,53 @@ pub enum AttrValue {
     Color(DOMString, Option<RGBA>),
     Dimension(DOMString, LengthOrPercentageOrAuto),
     Url(DOMString, Option<Url>),
 }
 
 /// 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) -> Option<i64> {
+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 None,
+        None => return Err(()),
         Some(&'-') => {
             input.next();
             -1
         },
         Some(&'+') => {
             input.next();
             1
         },
         Some(_) => 1,
     };
 
     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
 /// <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(())
+        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(())
+        result.to_u32().ok_or(())
+    })
 }
 
 /// Parse a floating-point number according to
 /// <https://html.spec.whatwg.org/multipage/#rules-for-parsing-floating-point-number-values>
 pub fn parse_double(string: &DOMString) -> Result<f64, ()> {
     let trimmed = string.trim_matches(HTML_SPACE_CHARACTERS);
     let mut input = trimmed.chars().peekable();