mirror of
https://github.com/mbilker/kbinxml-rs.git
synced 2026-09-09 19:15:27 -05:00
node: update pointer method in NodeCollection to match Node
This commit is contained in:
@@ -130,27 +130,20 @@ impl NodeCollection {
|
||||
Ok(node)
|
||||
}
|
||||
|
||||
pub fn pointer<'a>(&'a self, pointer: &str) -> Option<&'a NodeCollection> {
|
||||
if pointer == "" {
|
||||
pub fn pointer<'a>(&'a self, pointer: &[&str]) -> Option<&'a NodeCollection> {
|
||||
if pointer.is_empty() {
|
||||
return Some(self);
|
||||
}
|
||||
if !pointer.starts_with('/') {
|
||||
return None;
|
||||
}
|
||||
let tokens = pointer
|
||||
.split('/')
|
||||
.skip(1)
|
||||
.map(|x| x.replace("~1", "/").replace("~0", "~"));
|
||||
let mut target = self;
|
||||
|
||||
for token in tokens {
|
||||
let target_opt = if let Some(index) = parse_index(&token) {
|
||||
for token in pointer {
|
||||
let target_opt = if let Some(index) = parse_index(token) {
|
||||
eprintln!("index: {}", index);
|
||||
target.children().get(index)
|
||||
} else {
|
||||
eprintln!("token: {:?}", token);
|
||||
target.children().iter().find(|ref child| {
|
||||
child.base().key().ok().and_then(|x| x).expect("key not parseable") == token
|
||||
child.base().key().ok().and_then(|x| x).expect("key not parseable") == *token
|
||||
})
|
||||
};
|
||||
|
||||
|
||||
@@ -253,7 +253,7 @@ impl Node {
|
||||
None
|
||||
}
|
||||
|
||||
pub fn pointer(&self, pointer: &[&str]) -> Option<&Node> {
|
||||
pub fn pointer<'a>(&'a self, pointer: &[&str]) -> Option<&'a Node> {
|
||||
if pointer.is_empty() {
|
||||
return Some(self);
|
||||
}
|
||||
@@ -265,7 +265,7 @@ impl Node {
|
||||
None => return None,
|
||||
};
|
||||
|
||||
let target_opt = if let Some(index) = parse_index(&token) {
|
||||
let target_opt = if let Some(index) = parse_index(token) {
|
||||
eprintln!("index: {}", index);
|
||||
children.get(index)
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user