mirror of
https://github.com/microsoft/regorus.git
synced 2026-08-05 02:16:11 +00:00
strings: concat and contains
Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
This commit is contained in:
committed by
Anand Krishnamoorthi
parent
89e26e37a2
commit
27c5afd8ee
@@ -13,6 +13,7 @@ use anyhow::Result;
|
||||
|
||||
pub fn register(m: &mut HashMap<&'static str, builtins::BuiltinFcn>) {
|
||||
m.insert("concat", concat);
|
||||
m.insert("contains", contains);
|
||||
}
|
||||
|
||||
fn concat(span: &Span, params: &[Expr], args: &[Value]) -> Result<Value> {
|
||||
@@ -22,3 +23,11 @@ fn concat(span: &Span, params: &[Expr], args: &[Value]) -> Result<Value> {
|
||||
let collection = ensure_string_collection(name, ¶ms[1], &args[1])?;
|
||||
Ok(Value::String(collection.join(&delimiter)))
|
||||
}
|
||||
|
||||
fn contains(span: &Span, params: &[Expr], args: &[Value]) -> Result<Value> {
|
||||
let name = "contains";
|
||||
ensure_args_count(span, name, params, args, 2)?;
|
||||
let s1 = ensure_string(name, ¶ms[0], &args[0])?;
|
||||
let s2 = ensure_string(name, ¶ms[1], &args[1])?;
|
||||
Ok(Value::Bool(s1.contains(&s2)))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user