[librsvg] parsers::list_of_points() - take a &str, not a &[u8]



commit c354bf77ad484884500be707ddd894e0a2ae78c7
Author: Federico Mena Quintero <federico gnome org>
Date:   Wed Jul 19 12:10:30 2017 -0500

    parsers::list_of_points() - take a &str, not a &[u8]
    
    We'll move away from nom, to reduce the number of parsing libraries.

 rust/src/parsers.rs |   20 ++++++++++----------
 rust/src/shapes.rs  |    2 +-
 2 files changed, 11 insertions(+), 11 deletions(-)
---
diff --git a/rust/src/parsers.rs b/rust/src/parsers.rs
index 1d84709..c9bf64a 100644
--- a/rust/src/parsers.rs
+++ b/rust/src/parsers.rs
@@ -190,8 +190,8 @@ named! (list_of_points_impl<Vec<(f64, f64)>>,
         terminated! (separated_list! (comma_wsp, coordinate_pair),
                      eof! ()));
 
-pub fn list_of_points (string: &[u8]) -> Result <Vec<(f64, f64)>, ParseError> {
-    list_of_points_impl (string)
+pub fn list_of_points (string: &str) -> Result <Vec<(f64, f64)>, ParseError> {
+    list_of_points_impl (string.as_bytes ())
         .to_full_result ()
         .map_err (|_| ParseError::new ("invalid syntax for list of points"))
     /*
@@ -424,18 +424,18 @@ mod tests {
     #[test]
     fn parses_list_of_points () {
         // FIXME: we are missing optional whitespace at the beginning and end of the list
-        assert_eq! (list_of_points (b"1 2"),      Ok (vec! [(1.0, 2.0)]));
-        assert_eq! (list_of_points (b"1 2 3 4"),  Ok (vec! [(1.0, 2.0), (3.0, 4.0)]));
-        assert_eq! (list_of_points (b"1,2,3,4"),  Ok (vec! [(1.0, 2.0), (3.0, 4.0)]));
-        assert_eq! (list_of_points (b"1,2 3,4"),  Ok (vec! [(1.0, 2.0), (3.0, 4.0)]));
-        assert_eq! (list_of_points (b"1,2 -3,4"), Ok (vec! [(1.0, 2.0), (-3.0, 4.0)]));
-        assert_eq! (list_of_points (b"1,2,-3,4"), Ok (vec! [(1.0, 2.0), (-3.0, 4.0)]));
+        assert_eq! (list_of_points ("1 2"),      Ok (vec! [(1.0, 2.0)]));
+        assert_eq! (list_of_points ("1 2 3 4"),  Ok (vec! [(1.0, 2.0), (3.0, 4.0)]));
+        assert_eq! (list_of_points ("1,2,3,4"),  Ok (vec! [(1.0, 2.0), (3.0, 4.0)]));
+        assert_eq! (list_of_points ("1,2 3,4"),  Ok (vec! [(1.0, 2.0), (3.0, 4.0)]));
+        assert_eq! (list_of_points ("1,2 -3,4"), Ok (vec! [(1.0, 2.0), (-3.0, 4.0)]));
+        assert_eq! (list_of_points ("1,2,-3,4"), Ok (vec! [(1.0, 2.0), (-3.0, 4.0)]));
     }
 
     #[test]
     fn errors_on_invalid_list_of_points () {
-        assert! (list_of_points (b"-1-2-3-4").is_err ());
-        assert! (list_of_points (b"1 2-3,-4").is_err ());
+        assert! (list_of_points ("-1-2-3-4").is_err ());
+        assert! (list_of_points ("1 2-3,-4").is_err ());
     }
 
     #[test]
diff --git a/rust/src/shapes.rs b/rust/src/shapes.rs
index cb4e645..61dd917 100644
--- a/rust/src/shapes.rs
+++ b/rust/src/shapes.rs
@@ -138,7 +138,7 @@ impl NodeTrait for NodePoly {
 
         for name in vec! ["verts", "points"] {
             if let Some (value) = property_bag::lookup (pbag, name) {
-                let result = parsers::list_of_points (value.trim ().as_bytes ());
+                let result = parsers::list_of_points (value.trim ());
 
                 match result {
                     Ok (v) => {


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