[librsvg: 27/48] Defs::lookup() - Use Reference::parse() instead of doing the parsing here
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 27/48] Defs::lookup() - Use Reference::parse() instead of doing the parsing here
- Date: Sat, 17 Nov 2018 10:22:18 +0000 (UTC)
commit 2e75b99196ff9242d70e5b0a3965802dfa69e5f4
Author: Federico Mena Quintero <federico gnome org>
Date: Mon Sep 10 13:49:15 2018 -0500
Defs::lookup() - Use Reference::parse() instead of doing the parsing here
rsvg_internals/src/defs.rs | 27 ++++++++++++++++++---------
1 file changed, 18 insertions(+), 9 deletions(-)
---
diff --git a/rsvg_internals/src/defs.rs b/rsvg_internals/src/defs.rs
index f0589320..731e2880 100644
--- a/rsvg_internals/src/defs.rs
+++ b/rsvg_internals/src/defs.rs
@@ -29,18 +29,27 @@ impl Defs {
self.nodes.entry(id.to_string()).or_insert(node.clone());
}
+ /// Returns a node from an URI reference, or `None`
+ ///
+ /// This may return a node within the same RSVG handle, or a node in a secondary RSVG
+ /// handle that is referenced by the current one. If the element's id is not found,
+ /// returns `None`.
pub fn lookup(&mut self, name: &str) -> Option<&Rc<Node>> {
- match name.rfind('#') {
- None => None,
- Some(p) if p == 0 => self.nodes.get(&name[1..]),
- Some(p) => {
- let handle = self.get_extern_handle(&name[..p]);
- if handle.is_null() {
- None
- } else {
- handle::get_defs(handle).nodes.get(&name[(p + 1)..])
+ if let Ok(reference) = Reference::parse(name) {
+ match reference {
+ Reference::PlainUri(_) => None,
+ Reference::FragmentId(fragment) => self.nodes.get(fragment),
+ Reference::UriWithFragmentId(uri, fragment) => {
+ let handle = self.get_extern_handle(uri);
+ if handle.is_null() {
+ None
+ } else {
+ handle::get_defs(handle).nodes.get(fragment)
+ }
}
}
+ } else {
+ None
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]