Implement contains operator functionality

This commit is contained in:
Tobie Morgan Hitchcock 2021-05-17 19:02:08 +01:00
parent bf9ceaf693
commit 9ae2cc7cd1

View file

@ -237,8 +237,17 @@ pub fn more_than_or_equal(a: &Literal, b: &Literal) -> Result<Literal, Error> {
pub fn contain(a: &Literal, b: &Literal) -> Result<Literal, Error> { pub fn contain(a: &Literal, b: &Literal) -> Result<Literal, Error> {
match a { match a {
Literal::Array(v) => todo!(), Literal::Array(v) => match v.value.iter().any(|x| match x {
Literal::Strand(v) => todo!(), 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!(), Literal::Polygon(v) => todo!(),
_ => Ok(Literal::False), _ => Ok(Literal::False),
} }
@ -246,8 +255,17 @@ pub fn contain(a: &Literal, b: &Literal) -> Result<Literal, Error> {
pub fn not_contain(a: &Literal, b: &Literal) -> Result<Literal, Error> { pub fn not_contain(a: &Literal, b: &Literal) -> Result<Literal, Error> {
match a { match a {
Literal::Array(v) => todo!(), Literal::Array(v) => match v.value.iter().any(|x| match x {
Literal::Strand(v) => todo!(), 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!(), Literal::Polygon(v) => todo!(),
_ => Ok(Literal::False), _ => Ok(Literal::False),
} }