[librsvg: 4/20] PropertyBag: allow storing two kinds of data internally



commit 8670abf187cb48231d39e3a4fccffb036ed18bd2
Author: Federico Mena Quintero <federico gnome org>
Date:   Tue May 28 17:54:32 2019 -0500

    PropertyBag: allow storing two kinds of data internally
    
    The usual one is a CStr, built from the (name, value) pairs that
    libxml2's startElementSAXFunc gives us.
    
    The new one will be built from the (localname, prefix, URI, value,
    end) from startElementNsSAX2Func, the version with XML namespace support.

 rsvg_internals/src/property_bag.rs | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)
---
diff --git a/rsvg_internals/src/property_bag.rs b/rsvg_internals/src/property_bag.rs
index 5bf1940a..eccd937b 100644
--- a/rsvg_internals/src/property_bag.rs
+++ b/rsvg_internals/src/property_bag.rs
@@ -6,9 +6,14 @@ use std::str;
 
 use markup5ever::LocalName;
 
-pub struct PropertyBag<'a>(Vec<(LocalName, &'a CStr)>);
+enum Attribute<'a> {
+    CStr(&'a CStr),
+    Unterminated(&'a str),
+}
+
+pub struct PropertyBag<'a>(Vec<(LocalName, Attribute<'a>)>);
 
-pub struct PropertyBagIter<'a>(slice::Iter<'a, (LocalName, &'a CStr)>);
+pub struct PropertyBagIter<'a>(slice::Iter<'a, (LocalName, Attribute<'a>)>);
 
 trait Utf8CStrToStr {
     fn to_str_utf8(&self) -> &str;
@@ -58,7 +63,7 @@ impl<'a> PropertyBag<'a> {
                     let val_str = CStr::from_ptr(val);
 
                     let attr = LocalName::from(key_str.to_str_utf8());
-                    array.push((attr, val_str));
+                    array.push((attr, Attribute::CStr(val_str)));
                 } else {
                     break;
                 }
@@ -83,7 +88,12 @@ impl<'a> Iterator for PropertyBagIter<'a> {
     type Item = (LocalName, &'a str);
 
     fn next(&mut self) -> Option<Self::Item> {
-        self.0.next().map(|(a, v)| (a.clone(), v.to_str_utf8()))
+        self.0.next().map(|(a, v)| {
+            match *v {
+                Attribute::CStr(ref v) => (a.clone(), v.to_str_utf8()),
+                Attribute::Unterminated(v) => (a.clone(), v),
+            }
+        })
     }
 }
 


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