Continue adding string functions
This commit is contained in:
parent
ab4c8922b1
commit
799875a55d
@ -157,8 +157,25 @@ impl StringFunction {
|
|||||||
|
|
||||||
Ok(Value::List(List::with_items(bytes)))
|
Ok(Value::List(List::with_items(bytes)))
|
||||||
}
|
}
|
||||||
StringFunction::EndsWith => todo!(),
|
StringFunction::EndsWith => {
|
||||||
StringFunction::Find => todo!(),
|
Error::expect_argument_amount(self.name(), 2, arguments.len())?;
|
||||||
|
|
||||||
|
let string = arguments.get(0).unwrap().as_string()?;
|
||||||
|
let pattern = arguments.get(1).unwrap().as_string()?;
|
||||||
|
|
||||||
|
Ok(Value::Boolean(string.ends_with(pattern)))
|
||||||
|
}
|
||||||
|
StringFunction::Find => {
|
||||||
|
Error::expect_argument_amount(self.name(), 2, arguments.len())?;
|
||||||
|
|
||||||
|
let string = arguments.get(0).unwrap().as_string()?;
|
||||||
|
let pattern = arguments.get(1).unwrap().as_string()?;
|
||||||
|
let find = string
|
||||||
|
.find(pattern)
|
||||||
|
.map(|index| Box::new(Value::Integer(index as i64)));
|
||||||
|
|
||||||
|
Ok(Value::Option(find))
|
||||||
|
}
|
||||||
StringFunction::IsAscii => todo!(),
|
StringFunction::IsAscii => todo!(),
|
||||||
StringFunction::IsEmpty => todo!(),
|
StringFunction::IsEmpty => todo!(),
|
||||||
StringFunction::Lines => todo!(),
|
StringFunction::Lines => todo!(),
|
||||||
|
Loading…
Reference in New Issue
Block a user