[librsvg] Move all the RsvgLength::check_nonnegative() calls to the validation function



commit d7d38937e569486ac447ca0835b48469b73a190b
Author: Federico Mena Quintero <federico gnome org>
Date:   Tue Sep 5 08:58:40 2017 -0500

    Move all the RsvgLength::check_nonnegative() calls to the validation function
    
    This lets us remove the duplicated code that validates nonnegative
    lengths and converts the result to the appropriate error.

 rust/src/marker.rs    |    8 ++------
 rust/src/shapes.rs    |   15 ++++++---------
 rust/src/structure.rs |   33 ++++++---------------------------
 3 files changed, 14 insertions(+), 42 deletions(-)
---
diff --git a/rust/src/marker.rs b/rust/src/marker.rs
index 3c82461..ddac9e7 100644
--- a/rust/src/marker.rs
+++ b/rust/src/marker.rs
@@ -200,16 +200,12 @@ impl NodeTrait for NodeMarker {
         self.width.set (property_bag::parse_or_value (pbag, "markerWidth",
                                                       LengthDir::Horizontal,
                                                       NodeMarker::get_default_size (LengthDir::Horizontal),
-                                                      None)?
-                        .check_nonnegative ()
-                        .map_err (|e| NodeError::attribute_error ("markerWidth", e))?);
+                                                      Some(RsvgLength::check_nonnegative))?);
 
         self.height.set (property_bag::parse_or_value (pbag, "markerHeight",
                                                        LengthDir::Vertical,
                                                        NodeMarker::get_default_size (LengthDir::Vertical),
-                                                       None)?
-                         .check_nonnegative ()
-                         .map_err (|e| NodeError::attribute_error ("markerHeight", e))?);
+                                                       Some(RsvgLength::check_nonnegative))?);
 
         self.orient.set (property_bag::parse_or_default (pbag, "orient", (), None)?);
         self.aspect.set (property_bag::parse_or_default (pbag, "preserveAspectRatio", (), None)?);
diff --git a/rust/src/shapes.rs b/rust/src/shapes.rs
index 6705d75..3827702 100644
--- a/rust/src/shapes.rs
+++ b/rust/src/shapes.rs
@@ -436,9 +436,8 @@ impl NodeTrait for NodeCircle {
         self.cx.set (property_bag::parse_or_default (pbag, "cx", LengthDir::Horizontal, None)?);
         self.cy.set (property_bag::parse_or_default (pbag, "cy", LengthDir::Vertical, None)?);
 
-        self.r.set  (property_bag::parse_or_default (pbag, "r", LengthDir::Both, None)
-                     .and_then (|l: RsvgLength| l.check_nonnegative ()
-                                .map_err (|e| NodeError::attribute_error ("r", e)))?);
+        self.r.set  (property_bag::parse_or_default (pbag, "r", LengthDir::Both,
+                                                     Some(RsvgLength::check_nonnegative))?);
 
         Ok (())
     }
@@ -481,13 +480,11 @@ impl NodeTrait for NodeEllipse {
         self.cx.set (property_bag::parse_or_default (pbag, "cx", LengthDir::Horizontal, None)?);
         self.cy.set (property_bag::parse_or_default (pbag, "cy", LengthDir::Vertical, None)?);
 
-        self.rx.set (property_bag::parse_or_default (pbag, "rx", LengthDir::Horizontal, None)
-                     .and_then (|l: RsvgLength| l.check_nonnegative ()
-                                .map_err (|e| NodeError::attribute_error ("rx", e)))?);
+        self.rx.set (property_bag::parse_or_default (pbag, "rx", LengthDir::Horizontal,
+                                                     Some(RsvgLength::check_nonnegative))?);
 
-        self.ry.set (property_bag::parse_or_default (pbag, "ry", LengthDir::Vertical, None)
-                     .and_then (|l: RsvgLength| l.check_nonnegative ()
-                                .map_err (|e| NodeError::attribute_error ("ry", e)))?);
+        self.ry.set (property_bag::parse_or_default (pbag, "ry", LengthDir::Vertical,
+                                                     Some(RsvgLength::check_nonnegative))?);
 
         Ok (())
     }
diff --git a/rust/src/structure.rs b/rust/src/structure.rs
index c9edbb3..d54986a 100644
--- a/rust/src/structure.rs
+++ b/rust/src/structure.rs
@@ -149,17 +149,13 @@ impl NodeTrait for NodeSvg {
                                                   "width",
                                                   LengthDir::Horizontal,
                                                   RsvgLength::parse ("100%", LengthDir::Horizontal).unwrap 
(),
-                                                  None)
-                    .and_then (|l| l.check_nonnegative ()
-                               .map_err (|e| NodeError::attribute_error ("width", e)))?);
+                                                  Some(RsvgLength::check_nonnegative))?);
 
         self.h.set (property_bag::parse_or_value (pbag,
                                                   "height",
                                                   LengthDir::Vertical,
                                                   RsvgLength::parse ("100%", LengthDir::Vertical).unwrap (),
-                                                  None)
-                    .and_then (|l| l.check_nonnegative ()
-                               .map_err (|e| NodeError::attribute_error ("height", e)))?);
+                                                  Some(RsvgLength::check_nonnegative))?);
 
         self.vbox.set (property_bag::parse_or_none (pbag, "viewBox", (), None)?);
 
@@ -276,28 +272,11 @@ impl NodeTrait for NodeUse {
         self.x.set (property_bag::parse_or_default (pbag, "x", LengthDir::Horizontal, None)?);
         self.y.set (property_bag::parse_or_default (pbag, "y", LengthDir::Vertical, None)?);
 
-        let opt_w: Option<RsvgLength> = property_bag::parse_or_none (pbag, "width", LengthDir::Horizontal, 
None)?;
-        self.w.set (match opt_w {
-            Some (w) => {
-                Some (w.check_nonnegative ().map_err (|e| NodeError::attribute_error ("width", e))?)
-            },
+        self.w.set (property_bag::parse_or_none (pbag, "width", LengthDir::Horizontal,
+                                                 Some(RsvgLength::check_nonnegative))?);
 
-            None => {
-                None
-            }
-        });
-
-        let opt_h: Option<RsvgLength> = property_bag::parse_or_none (pbag, "height", LengthDir::Vertical, 
None)?;
-        let h = match opt_h {
-            Some (h) => {
-                Some (h.check_nonnegative ().map_err (|e| NodeError::attribute_error ("height", e))?)
-            },
-
-            None => {
-                None
-            }
-        };
-        self.h.set (h);
+        self.h.set (property_bag::parse_or_none (pbag, "height", LengthDir::Vertical,
+                                                 Some(RsvgLength::check_nonnegative))?);
 
         Ok (())
     }


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