[librsvg: 6/10] Properly revert reggresions this time.



commit 2409c588c6afcc639ffcc9ada567a90e37ef327a
Author: Jordan Petridis <jordanpetridis protonmail com>
Date:   Fri Dec 8 16:57:39 2017 +0200

    Properly revert reggresions this time.
    
    Revert "Use str.replace() instead to convert newlines into spaces."
    Revert "Use str.replace() instead of map/match/collect ."
    
    This reverts commit 4e79a87c1b6c3899bcfcecba927888b864657b29.
    This reverts commit cef86a9fe9a706ef32df863f826b325ceb022be7.

 rust/src/space.rs | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)
---
diff --git a/rust/src/space.rs b/rust/src/space.rs
index 5621365..36ddf55 100644
--- a/rust/src/space.rs
+++ b/rust/src/space.rs
@@ -32,7 +32,9 @@ pub fn xml_space_normalize(mode: XmlSpace, s: &str) -> String {
 // characters will be consolidated.
 fn normalize_default<'a, S: Into<Cow<'a, str>>>(s: S) -> String {
     let s = s.into();
-    s.replace('\n', "")
+    s.chars()
+        .filter(|ch| *ch != '\n')
+        .collect::<String>()
         // split at whitespace, also trims whitespace.
         .split_whitespace()
         .join(" ")
@@ -48,10 +50,16 @@ fn normalize_default<'a, S: Into<Cow<'a, str>>>(s: S) -> String {
 // xml:space="preserve", the string "a   b" (three spaces between "a"
 // and "b") will produce a larger separation between "a" and "b" than
 // "a b" (one space between "a" and "b").
-fn normalize_preserve<'a, S: Into<Cow<'a, str>>>(s: S) -> String {
-    let s = s.into();
-    let s = s.replace('\n', " ");
-    s.replace('\t', " ")
+fn normalize_preserve(s: &str) -> String {
+    s.chars()
+        .map(|ch| {
+            match ch {
+                '\n' | '\t' => ' ',
+
+                c => c
+            }
+        })
+        .collect()
 }
 
 #[no_mangle]


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