diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-19 09:26:03 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-19 09:26:03 +0000 |
commit | 9918693037dce8aa4bb6f08741b6812923486c18 (patch) | |
tree | 21d2b40bec7e6a7ea664acee056eb3d08e15a1cf /vendor/jsonpath_lib/src | |
parent | Releasing progress-linux version 1.75.0+dfsg1-5~progress7.99u1. (diff) | |
download | rustc-9918693037dce8aa4bb6f08741b6812923486c18.tar.xz rustc-9918693037dce8aa4bb6f08741b6812923486c18.zip |
Merging upstream version 1.76.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/jsonpath_lib/src')
-rw-r--r-- | vendor/jsonpath_lib/src/lib.rs | 2 | ||||
-rw-r--r-- | vendor/jsonpath_lib/src/parser/mod.rs | 6 | ||||
-rw-r--r-- | vendor/jsonpath_lib/src/select/cmp.rs | 39 | ||||
-rw-r--r-- | vendor/jsonpath_lib/src/select/expr_term.rs | 11 | ||||
-rw-r--r-- | vendor/jsonpath_lib/src/select/mod.rs | 2 | ||||
-rw-r--r-- | vendor/jsonpath_lib/src/select/value_walker.rs | 11 |
6 files changed, 48 insertions, 23 deletions
diff --git a/vendor/jsonpath_lib/src/lib.rs b/vendor/jsonpath_lib/src/lib.rs index 55ac51943..1258a010f 100644 --- a/vendor/jsonpath_lib/src/lib.rs +++ b/vendor/jsonpath_lib/src/lib.rs @@ -122,9 +122,7 @@ //! &json!({"category" : "fiction","author" : "Herman Melville","title" : "Moby Dick","isbn" : "0-553-21311-3","price" : 8.99}) //! ]); //! ``` -extern crate array_tool; extern crate core; -extern crate env_logger; #[macro_use] extern crate log; extern crate serde; diff --git a/vendor/jsonpath_lib/src/parser/mod.rs b/vendor/jsonpath_lib/src/parser/mod.rs index 91cd8960b..5a28b730d 100644 --- a/vendor/jsonpath_lib/src/parser/mod.rs +++ b/vendor/jsonpath_lib/src/parser/mod.rs @@ -80,7 +80,7 @@ pub struct Parser; impl Parser { pub fn compile(input: &str) -> ParseResult<Node> { let mut tokenizer = TokenReader::new(input); - Ok(Self::json_path(&mut tokenizer)?) + Self::json_path(&mut tokenizer) } fn json_path(tokenizer: &mut TokenReader) -> ParseResult<Node> { @@ -145,6 +145,7 @@ impl Parser { } } + #[allow(clippy::unnecessary_wraps)] fn path_leaves_key(prev: Node, tokenizer: &mut TokenReader) -> ParseResult<Node> { debug!("#path_leaves_key"); Ok(Node { @@ -154,6 +155,7 @@ impl Parser { }) } + #[allow(clippy::unnecessary_wraps)] fn path_leaves_all(prev: Node, tokenizer: &mut TokenReader) -> ParseResult<Node> { debug!("#path_leaves_all"); Self::eat_token(tokenizer); @@ -164,6 +166,7 @@ impl Parser { }) } + #[allow(clippy::unnecessary_wraps)] fn path_in_all(prev: Node, tokenizer: &mut TokenReader) -> ParseResult<Node> { debug!("#path_in_all"); Self::eat_token(tokenizer); @@ -174,6 +177,7 @@ impl Parser { }) } + #[allow(clippy::unnecessary_wraps)] fn path_in_key(prev: Node, tokenizer: &mut TokenReader) -> ParseResult<Node> { debug!("#path_in_key"); Ok(Node { diff --git a/vendor/jsonpath_lib/src/select/cmp.rs b/vendor/jsonpath_lib/src/select/cmp.rs index 209e67298..6d2eaef17 100644 --- a/vendor/jsonpath_lib/src/select/cmp.rs +++ b/vendor/jsonpath_lib/src/select/cmp.rs @@ -1,4 +1,3 @@ -use array_tool::vec::{Intersect, Union}; use serde_json::Value; pub(super) trait Cmp { @@ -31,7 +30,17 @@ impl Cmp for CmpEq { } fn cmp_json<'a>(&self, v1: &[&'a Value], v2: &[&'a Value]) -> Vec<&'a Value> { - v1.to_vec().intersect(v2.to_vec()) + let mut ret = vec![]; + + for a in v1 { + for b in v2 { + if a == b { + ret.push(*a); + } + } + } + + ret } } @@ -51,7 +60,17 @@ impl Cmp for CmpNe { } fn cmp_json<'a>(&self, v1: &[&'a Value], v2: &[&'a Value]) -> Vec<&'a Value> { - v1.to_vec().intersect_if(v2.to_vec(), |a, b| a != b) + let mut ret = vec![]; + + for a in v1 { + for b in v2 { + if a != b { + ret.push(*a); + } + } + } + + ret } } @@ -151,7 +170,7 @@ impl Cmp for CmpAnd { } fn cmp_json<'a>(&self, v1: &[&'a Value], v2: &[&'a Value]) -> Vec<&'a Value> { - v1.to_vec().intersect(v2.to_vec()) + CmpEq.cmp_json(v1, v2) } } @@ -171,7 +190,17 @@ impl Cmp for CmpOr { } fn cmp_json<'a>(&self, v1: &[&'a Value], v2: &[&'a Value]) -> Vec<&'a Value> { - v1.to_vec().union(v2.to_vec()) + let mut ret = [v1, v2].concat(); + + for x in (0..ret.len()).rev() { + for y in (x+1..ret.len()).rev() { + if ret[x] == ret[y] { + ret.remove(y); + } + } + } + + ret } } diff --git a/vendor/jsonpath_lib/src/select/expr_term.rs b/vendor/jsonpath_lib/src/select/expr_term.rs index ddbf64e53..f777880ab 100644 --- a/vendor/jsonpath_lib/src/select/expr_term.rs +++ b/vendor/jsonpath_lib/src/select/expr_term.rs @@ -186,10 +186,10 @@ impl<'a> ExprTerm<'a> { } } -impl<'a> Into<ExprTerm<'a>> for &Vec<&'a Value> { - fn into(self) -> ExprTerm<'a> { - if self.len() == 1 { - match &self[0] { +impl<'a> From<&Vec<&'a Value>> for ExprTerm<'a> { + fn from(vec: &Vec<&'a Value>) -> Self { + if vec.len() == 1 { + match &vec[0] { Value::Number(v) => return ExprTerm::Number(v.clone()), Value::String(v) => return ExprTerm::String(v.clone()), Value::Bool(v) => return ExprTerm::Bool(*v), @@ -197,11 +197,10 @@ impl<'a> Into<ExprTerm<'a>> for &Vec<&'a Value> { } } - ExprTerm::Json(None, None, self.to_vec()) + ExprTerm::Json(None, None, vec.to_vec()) } } - #[cfg(test)] mod expr_term_inner_tests { use serde_json::{Number, Value}; diff --git a/vendor/jsonpath_lib/src/select/mod.rs b/vendor/jsonpath_lib/src/select/mod.rs index a3d0ec43f..9217b5b5e 100644 --- a/vendor/jsonpath_lib/src/select/mod.rs +++ b/vendor/jsonpath_lib/src/select/mod.rs @@ -44,6 +44,8 @@ pub enum JsonPathError { Serde(String), } +impl std::error::Error for JsonPathError {} + impl fmt::Debug for JsonPathError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self) diff --git a/vendor/jsonpath_lib/src/select/value_walker.rs b/vendor/jsonpath_lib/src/select/value_walker.rs index e7b4de0e0..87a0defff 100644 --- a/vendor/jsonpath_lib/src/select/value_walker.rs +++ b/vendor/jsonpath_lib/src/select/value_walker.rs @@ -6,11 +6,7 @@ pub(super) struct ValueWalker; impl<'a> ValueWalker { pub fn all_with_num(vec: &[&'a Value], tmp: &mut Vec<&'a Value>, index: f64) { Self::walk(vec, tmp, &|v| if v.is_array() { - if let Some(item) = v.get(index as usize) { - Some(vec![item]) - } else { - None - } + v.get(index as usize).map(|item| vec![item]) } else { None }); @@ -24,10 +20,7 @@ impl<'a> ValueWalker { }); } else { Self::walk(vec, tmp, &|v| match v { - Value::Object(map) => match map.get(key) { - Some(v) => Some(vec![v]), - _ => None, - }, + Value::Object(map) => map.get(key).map(|v| vec![v]), _ => None, }); } |