Skip to content

Commit

Permalink
Add strlen builtin
Browse files Browse the repository at this point in the history
  • Loading branch information
MineRobber9000 authored and hlorenzi committed Dec 2, 2023
1 parent 1172abe commit a793015
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/expr/builtin_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub fn resolve_builtin_fn(
"utf16le" => Some(eval_builtin_utf16le),
"utf32be" => Some(eval_builtin_utf32be),
"utf32le" => Some(eval_builtin_utf32le),
"strlen" => Some(eval_builtin_strlen),
_ => None,
}
}
Expand Down Expand Up @@ -55,6 +56,7 @@ pub fn get_statically_known_value_builtin_fn(
"utf16le" => true,
"utf32be" => true,
"utf32le" => true,
"strlen" => true,
_ => false,
}
}
Expand Down Expand Up @@ -210,4 +212,19 @@ pub fn eval_builtin_utf32le(
-> Result<expr::Value, ()>
{
eval_builtin_string_encoding("utf32le", query)
}
}


pub fn eval_builtin_strlen(
query: &mut expr::EvalFunctionQuery)
-> Result<expr::Value, ()>
{
query.ensure_arg_number(1)?;

let s = query.args[0].value.expect_string(
query.report,
query.args[0].span)?;

Ok(expr::Value::make_integer(s.utf8_contents.len()))

}

0 comments on commit a793015

Please sign in to comment.