[librsvg: 10/43] Convert UnitInterval / all the *Opacity properties to CssParseError



commit 16146845d64f4a5b5c6b80e7e7ee70d864bf1115
Author: Federico Mena Quintero <federico gnome org>
Date:   Thu Dec 19 20:44:35 2019 -0600

    Convert UnitInterval / all the *Opacity properties to CssParseError

 rsvg_internals/src/properties.rs    | 10 +++++-----
 rsvg_internals/src/property_defs.rs | 10 +++++-----
 rsvg_internals/src/unit_interval.rs | 26 +++++++++++++-------------
 3 files changed, 23 insertions(+), 23 deletions(-)
---
diff --git a/rsvg_internals/src/properties.rs b/rsvg_internals/src/properties.rs
index 58340a1f..7dab4883 100644
--- a/rsvg_internals/src/properties.rs
+++ b/rsvg_internals/src/properties.rs
@@ -258,7 +258,7 @@ pub fn parse_property<'i>(prop_name: &QualName, input: &mut Parser<'i, '_>, acce
             Ok(ParsedProperty::Fill(parse_input(input)?)),
 
         expanded_name!(svg "fill-opacity") =>
-            Ok(ParsedProperty::FillOpacity(parse_input(input)?)),
+            Ok(ParsedProperty::FillOpacity(parse_input_to_parse_error(input)?)),
 
         expanded_name!(svg "fill-rule") =>
             Ok(ParsedProperty::FillRule(parse_input_to_parse_error(input)?)),
@@ -270,7 +270,7 @@ pub fn parse_property<'i>(prop_name: &QualName, input: &mut Parser<'i, '_>, acce
             Ok(ParsedProperty::FloodColor(parse_input_to_parse_error(input)?)),
 
         expanded_name!(svg "flood-opacity") =>
-            Ok(ParsedProperty::FloodOpacity(parse_input(input)?)),
+            Ok(ParsedProperty::FloodOpacity(parse_input_to_parse_error(input)?)),
 
         expanded_name!(svg "font-family") =>
             Ok(ParsedProperty::FontFamily(parse_input_to_parse_error(input)?)),
@@ -317,7 +317,7 @@ pub fn parse_property<'i>(prop_name: &QualName, input: &mut Parser<'i, '_>, acce
             Ok(ParsedProperty::Mask(parse_input(input)?)),
 
         expanded_name!(svg "opacity") =>
-            Ok(ParsedProperty::Opacity(parse_input(input)?)),
+            Ok(ParsedProperty::Opacity(parse_input_to_parse_error(input)?)),
 
         expanded_name!(svg "overflow") =>
             Ok(ParsedProperty::Overflow(parse_input_to_parse_error(input)?)),
@@ -329,7 +329,7 @@ pub fn parse_property<'i>(prop_name: &QualName, input: &mut Parser<'i, '_>, acce
             Ok(ParsedProperty::StopColor(parse_input_to_parse_error(input)?)),
 
         expanded_name!(svg "stop-opacity") =>
-            Ok(ParsedProperty::StopOpacity(parse_input(input)?)),
+            Ok(ParsedProperty::StopOpacity(parse_input_to_parse_error(input)?)),
 
         expanded_name!(svg "stroke") =>
             Ok(ParsedProperty::Stroke(parse_input(input)?)),
@@ -350,7 +350,7 @@ pub fn parse_property<'i>(prop_name: &QualName, input: &mut Parser<'i, '_>, acce
             Ok(ParsedProperty::StrokeMiterlimit(parse_input(input)?)),
 
         expanded_name!(svg "stroke-opacity") =>
-            Ok(ParsedProperty::StrokeOpacity(parse_input(input)?)),
+            Ok(ParsedProperty::StrokeOpacity(parse_input_to_parse_error(input)?)),
 
         expanded_name!(svg "stroke-width") =>
             Ok(ParsedProperty::StrokeWidth(parse_input(input)?)),
diff --git a/rsvg_internals/src/property_defs.rs b/rsvg_internals/src/property_defs.rs
index c32a47f6..178877d9 100644
--- a/rsvg_internals/src/property_defs.rs
+++ b/rsvg_internals/src/property_defs.rs
@@ -175,7 +175,7 @@ make_property!(
     FillOpacity,
     default: UnitInterval(1.0),
     inherits_automatically: true,
-    newtype_parse: UnitInterval,
+    newtype_parse_to_parse_error: UnitInterval,
 );
 
 // https://www.w3.org/TR/SVG/painting.html#FillRuleProperty
@@ -214,7 +214,7 @@ make_property!(
     FloodOpacity,
     default: UnitInterval(1.0),
     inherits_automatically: false,
-    newtype_parse: UnitInterval,
+    newtype_parse_to_parse_error: UnitInterval,
 );
 
 // https://www.w3.org/TR/SVG/text.html#FontFamilyProperty
@@ -378,7 +378,7 @@ make_property!(
     Opacity,
     default: UnitInterval(1.0),
     inherits_automatically: false,
-    newtype_parse: UnitInterval,
+    newtype_parse_to_parse_error: UnitInterval,
 );
 
 // https://www.w3.org/TR/SVG/masking.html#OverflowProperty
@@ -424,7 +424,7 @@ make_property!(
     StopOpacity,
     default: UnitInterval(1.0),
     inherits_automatically: false,
-    newtype_parse: UnitInterval,
+    newtype_parse_to_parse_error: UnitInterval,
 );
 
 // https://www.w3.org/TR/SVG/painting.html#StrokeProperty
@@ -495,7 +495,7 @@ make_property!(
     StrokeOpacity,
     default: UnitInterval(1.0),
     inherits_automatically: true,
-    newtype_parse: UnitInterval,
+    newtype_parse_to_parse_error: UnitInterval,
 );
 
 // https://www.w3.org/TR/SVG/painting.html#StrokeWidthProperty
diff --git a/rsvg_internals/src/unit_interval.rs b/rsvg_internals/src/unit_interval.rs
index 6b7e9d20..34575692 100644
--- a/rsvg_internals/src/unit_interval.rs
+++ b/rsvg_internals/src/unit_interval.rs
@@ -3,7 +3,7 @@
 use cssparser::Parser;
 
 use crate::error::*;
-use crate::parsers::Parse;
+use crate::parsers::ParseToParseError;
 use crate::util;
 
 #[derive(Debug, Default, Copy, Clone, PartialEq, PartialOrd)]
@@ -15,9 +15,9 @@ impl UnitInterval {
     }
 }
 
-impl Parse for UnitInterval {
-    fn parse(parser: &mut Parser<'_, '_>) -> Result<UnitInterval, ValueErrorKind> {
-        let x = f64::parse(parser)?;
+impl ParseToParseError for UnitInterval {
+    fn parse_to_parse_error<'i>(parser: &mut Parser<'i, '_>) -> Result<UnitInterval, CssParseError<'i>> {
+        let x = f64::parse_to_parse_error(parser)?;
         Ok(UnitInterval::clamp(x))
     }
 }
@@ -44,23 +44,23 @@ mod tests {
 
     #[test]
     fn parses_number() {
-        assert_eq!(UnitInterval::parse_str("0"), Ok(UnitInterval(0.0)));
-        assert_eq!(UnitInterval::parse_str("1"), Ok(UnitInterval(1.0)));
-        assert_eq!(UnitInterval::parse_str("0.5"), Ok(UnitInterval(0.5)));
+        assert_eq!(UnitInterval::parse_str_to_parse_error("0"), Ok(UnitInterval(0.0)));
+        assert_eq!(UnitInterval::parse_str_to_parse_error("1"), Ok(UnitInterval(1.0)));
+        assert_eq!(UnitInterval::parse_str_to_parse_error("0.5"), Ok(UnitInterval(0.5)));
     }
 
     #[test]
     fn parses_out_of_range_number() {
-        assert_eq!(UnitInterval::parse_str("-10"), Ok(UnitInterval(0.0)));
-        assert_eq!(UnitInterval::parse_str("10"), Ok(UnitInterval(1.0)));
+        assert_eq!(UnitInterval::parse_str_to_parse_error("-10"), Ok(UnitInterval(0.0)));
+        assert_eq!(UnitInterval::parse_str_to_parse_error("10"), Ok(UnitInterval(1.0)));
     }
 
     #[test]
     fn errors_on_invalid_input() {
-        assert!(is_parse_error(&UnitInterval::parse_str("")));
-        assert!(is_parse_error(&UnitInterval::parse_str("foo")));
-        assert!(is_parse_error(&UnitInterval::parse_str("-x")));
-        assert!(is_parse_error(&UnitInterval::parse_str("0.0foo")));
+        assert!(UnitInterval::parse_str_to_parse_error("").is_err());
+        assert!(UnitInterval::parse_str_to_parse_error("foo").is_err());
+        assert!(UnitInterval::parse_str_to_parse_error("-x").is_err());
+        assert!(UnitInterval::parse_str_to_parse_error("0.0foo").is_err());
     }
 
     #[test]


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]