[librsvg] rsvg-load.c: Strip the namespaces in the Rust code
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg] rsvg-load.c: Strip the namespaces in the Rust code
- Date: Wed, 5 Dec 2018 19:11:44 +0000 (UTC)
commit 939644a1e5d3f67023d5113bd5f4c1a3c90a4b8a
Author: Federico Mena Quintero <federico gnome org>
Date: Wed Dec 5 09:50:03 2018 -0600
rsvg-load.c: Strip the namespaces in the Rust code
librsvg/rsvg-load.c | 21 +++------------------
rsvg_internals/src/xml.rs | 22 ++++++++++++++++++++++
2 files changed, 25 insertions(+), 18 deletions(-)
---
diff --git a/librsvg/rsvg-load.c b/librsvg/rsvg-load.c
index 887175a2..9ddd6ed3 100644
--- a/librsvg/rsvg-load.c
+++ b/librsvg/rsvg-load.c
@@ -311,20 +311,13 @@ rsvg_load_handle_xml_xinclude (RsvgHandle *handle, const char *href)
/* end xinclude */
static void
-sax_start_element_cb (void *data, const xmlChar * name, const xmlChar ** atts)
+sax_start_element_cb (void *data, const xmlChar *name, const xmlChar **atts)
{
RsvgPropertyBag bag;
RsvgLoad *load = data;
- const char *tempname;
bag = rsvg_property_bag_new ((const char **) atts);
- for (tempname = (const char *) name; *tempname != '\0'; tempname++) {
- if (*tempname == ':') {
- name = (const xmlChar *) (tempname + 1);
- }
- }
-
rsvg_xml_state_start_element (load->xml.rust_state,
load->handle,
(const char *) name,
@@ -334,19 +327,11 @@ sax_start_element_cb (void *data, const xmlChar * name, const xmlChar ** atts)
}
static void
-sax_end_element_cb (void *data, const xmlChar * xmlname)
+sax_end_element_cb (void *data, const xmlChar *name)
{
RsvgLoad *load = data;
- const char *name = (const char *) xmlname;
- const char *tempname;
-
- for (tempname = name; *tempname != '\0'; tempname++) {
- if (*tempname == ':') {
- name = tempname + 1;
- }
- }
- rsvg_xml_state_end_element (load->xml.rust_state, load->handle, name);
+ rsvg_xml_state_end_element (load->xml.rust_state, load->handle, (const char *) name);
}
static void
diff --git a/rsvg_internals/src/xml.rs b/rsvg_internals/src/xml.rs
index 2f0eb745..6c007ad1 100644
--- a/rsvg_internals/src/xml.rs
+++ b/rsvg_internals/src/xml.rs
@@ -164,6 +164,9 @@ impl XmlState {
return;
}
+ // FIXME: we should deal with namespaces at some point
+ let name = skip_namespace(name);
+
let new_context = match context.kind {
ContextKind::Start => self.element_creation_start_element(handle, name, pbag),
ContextKind::ElementCreation => self.element_creation_start_element(handle, name, pbag),
@@ -186,6 +189,9 @@ impl XmlState {
return;
}
+ // FIXME: we should deal with namespaces at some point
+ let name = skip_namespace(name);
+
assert!(context.element_name == name);
match context.kind {
@@ -549,6 +555,10 @@ impl Drop for XmlState {
}
}
+fn skip_namespace(s: &str) -> &str {
+ s.find(':').map_or(s, |pos| &s[pos + 1..])
+}
+
// https://www.w3.org/TR/xml-stylesheet/
//
// The syntax for the xml-stylesheet processing instruction we support
@@ -752,3 +762,15 @@ pub unsafe extern "C" fn rsvg_xml_state_tree_is_valid(
false.to_glib()
}
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn skips_namespaces() {
+ assert_eq!(skip_namespace("foo"), "foo");
+ assert_eq!(skip_namespace("foo:bar"), "bar");
+ assert_eq!(skip_namespace("foo:bar:baz"), "bar:baz");
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]