From 02420543f145f59fd15c87b9720a97a54c088edd Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Sun, 8 Aug 2021 18:04:33 -0400 Subject: [PATCH] Treat Symbols more uniformly like Strings --- implementations/rust/preserves-path/src/step.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/implementations/rust/preserves-path/src/step.rs b/implementations/rust/preserves-path/src/step.rs index 3dddb62..ad483a9 100644 --- a/implementations/rust/preserves-path/src/step.rs +++ b/implementations/rust/preserves-path/src/step.rs @@ -175,7 +175,7 @@ impl Step for AxisStep { } } path::Axis::At { key } => match value.value() { - Value::String(s) => + Value::String(s) | Value::Symbol(s) => step_index(path.step(value), s.chars(), &key, |c| IOValue::new(String::from(c)), &mut self.step), Value::Record(r) => step_index(path.step(value), r.fields().iter(), &key, |v| v.clone(), &mut self.step), @@ -192,9 +192,9 @@ impl Step for AxisStep { self.step.accept(path.step(value), r.label()) }, path::Axis::Keys => match value.value() { - Value::String(s) => step_keys(path.step(value), s.len(), &mut self.step), + Value::String(s) | Value::Symbol(s) => + step_keys(path.step(value), s.len(), &mut self.step), Value::ByteString(bs) => step_keys(path.step(value), bs.len(), &mut self.step), - Value::Symbol(s) => step_keys(path.step(value), s.len(), &mut self.step), Value::Record(r) => step_keys(path.step(value), r.arity(), &mut self.step), Value::Sequence(vs) => step_keys(path.step(value), vs.len(), &mut self.step), Value::Dictionary(d) => { @@ -206,9 +206,9 @@ impl Step for AxisStep { _ => (), }, path::Axis::Length => match value.value() { - Value::String(s) => self.step.accept(path.step(value), &IOValue::new(s.len())), + Value::String(s) | Value::Symbol(s) => + self.step.accept(path.step(value), &IOValue::new(s.len())), Value::ByteString(bs) => self.step.accept(path.step(value), &IOValue::new(bs.len())), - Value::Symbol(s) => self.step.accept(path.step(value), &IOValue::new(s.len())), Value::Record(r) => self.step.accept(path.step(value), &IOValue::new(r.arity())), Value::Sequence(vs) => self.step.accept(path.step(value), &IOValue::new(vs.len())), Value::Dictionary(d) => self.step.accept(path.step(value), &IOValue::new(d.len())), @@ -304,9 +304,10 @@ impl Step for CompareStep { impl Step for RegexStep { fn accept(&mut self, path: Rc, value: &IOValue) { match value.value() { - Value::String(s) => if self.regex.is_match(s) { self.step.accept(path, value) }, - Value::Symbol(s) => if self.regex.is_match(s) { self.step.accept(path, value) }, - _ => (), + Value::String(s) | Value::Symbol(s) => + if self.regex.is_match(s) { self.step.accept(path, value) }, + _ => + (), } }