From 9ae2cc7cd17f45c42eba5901d334d7bd2eac9e96 Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Mon, 17 May 2021 19:02:08 +0100 Subject: [PATCH] Implement contains operator functionality --- src/fnc/operate.rs | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/fnc/operate.rs b/src/fnc/operate.rs index 7cdc3c2d..2cfde74f 100644 --- a/src/fnc/operate.rs +++ b/src/fnc/operate.rs @@ -237,8 +237,17 @@ pub fn more_than_or_equal(a: &Literal, b: &Literal) -> Result { pub fn contain(a: &Literal, b: &Literal) -> Result { match a { - Literal::Array(v) => todo!(), - Literal::Strand(v) => todo!(), + Literal::Array(v) => match v.value.iter().any(|x| match x { + Value::Literal(v) => equal(v, b).is_ok(), + _ => unreachable!(), + }) { + true => Ok(Literal::True), + false => Ok(Literal::False), + }, + Literal::Strand(v) => match b { + Literal::Strand(w) => Ok(Literal::from(v.value.contains(w.value.as_str()) == true)), + _ => Ok(Literal::from(v.value.contains(&b.as_strand().value.as_str()) == true)), + }, Literal::Polygon(v) => todo!(), _ => Ok(Literal::False), } @@ -246,8 +255,17 @@ pub fn contain(a: &Literal, b: &Literal) -> Result { pub fn not_contain(a: &Literal, b: &Literal) -> Result { match a { - Literal::Array(v) => todo!(), - Literal::Strand(v) => todo!(), + Literal::Array(v) => match v.value.iter().any(|x| match x { + Value::Literal(v) => equal(v, b).is_ok(), + _ => unreachable!(), + }) { + true => Ok(Literal::False), + false => Ok(Literal::True), + }, + Literal::Strand(v) => match b { + Literal::Strand(w) => Ok(Literal::from(v.value.contains(w.value.as_str()) == false)), + _ => Ok(Literal::from(v.value.contains(&b.as_strand().value.as_str()) == false)), + }, Literal::Polygon(v) => todo!(), _ => Ok(Literal::False), }