[librsvg] length.rs: Make Length::parse()'s Result have a ParseError



commit 69cebc0e6a83c5bb27da7da39a70837ec01b1608
Author: Federico Mena Quintero <federico gnome org>
Date:   Wed Mar 15 21:52:10 2017 -0600

    length.rs: Make Length::parse()'s Result have a ParseError
    
    And fix some leftover cut&paste in shapes.rs

 rust/src/length.rs |   14 +++++++++-----
 rust/src/shapes.rs |    2 --
 2 files changed, 9 insertions(+), 7 deletions(-)
---
diff --git a/rust/src/length.rs b/rust/src/length.rs
index 112db76..3201cc6 100644
--- a/rust/src/length.rs
+++ b/rust/src/length.rs
@@ -8,6 +8,7 @@ use self::glib::translate::*;
 use drawing_ctx;
 use drawing_ctx::RsvgDrawingCtx;
 use parsers;
+use parsers::ParseError;
 
 /* Keep this in sync with ../../rsvg-private.h:LengthUnit */
 #[repr(C)]
@@ -95,11 +96,13 @@ pub extern fn rsvg_length_parse (string: *const libc::c_char, dir: LengthDir) ->
  * inside RsvgLength::normalize(), when it needs to know to what the
  * length refers.
  */
-#[derive(Debug, Copy, Clone, PartialEq)]
-pub struct ParseLengthError;
+
+fn make_err () -> ParseError {
+    ParseError::new ("expected length: number(\"em\" | \"ex\" | \"px\" | \"in\" | \"cm\" | \"mm\" | \"pt\" | 
\"pc\" | \"%\")?")
+}
 
 impl RsvgLength {
-    pub fn parse (string: &str, dir: LengthDir) -> Result <RsvgLength, ParseLengthError> {
+    pub fn parse (string: &str, dir: LengthDir) -> Result <RsvgLength, ParseError> {
         let r = parsers::number_and_units (string.as_bytes ()).to_full_result ();
 
         match r {
@@ -142,10 +145,11 @@ impl RsvgLength {
                                             unit:   LengthUnit::Default,
                                             dir:    dir }),
 
-                    _ => Err (ParseLengthError)
+                    _ => Err (make_err ())
                 }
             },
 
+            // FIXME: why are the following in Length?  They should be in FontSize
             _ => match string {
                 "larger" => Ok (RsvgLength { length: 0.0,
                                              unit:   LengthUnit::RelativeLarger,
@@ -165,7 +169,7 @@ impl RsvgLength {
                                                unit:   LengthUnit::Inch,
                                                dir:    dir }),
 
-                _ => Err (ParseLengthError)
+                _ => Err (make_err ())
             }
         }
     }
diff --git a/rust/src/shapes.rs b/rust/src/shapes.rs
index 2c22f00..1e9f4d0 100644
--- a/rust/src/shapes.rs
+++ b/rust/src/shapes.rs
@@ -265,7 +265,6 @@ impl NodeTrait for NodeRect {
         let v = property_bag::lookup (pbag, "rx");
         if let Some (val) = v {
             let rlength = RsvgLength::parse (&val, LengthDir::Horizontal);
-            rlength.map (|v| Some (v)).unwrap_or (None);
             self.rx.set (rlength.map (|v| Some (v)).unwrap_or (None));
         } else {
             self.rx.set (None);
@@ -274,7 +273,6 @@ impl NodeTrait for NodeRect {
         let v = property_bag::lookup (pbag, "ry");
         if let Some (val) = v {
             let rlength = RsvgLength::parse (&val, LengthDir::Vertical);
-            rlength.map (|v| Some (v)).unwrap_or (None);
             self.ry.set (rlength.map (|v| Some (v)).unwrap_or (None));
         } else {
             self.ry.set (None);


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