mirror of
https://github.com/microsoft/regorus.git
synced 2026-08-05 02:16:11 +00:00
feat: Update to opa v0.67.0 (#286)
Implement strings.count builtin Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
This commit is contained in:
committed by
GitHub
parent
7095e269b7
commit
6599ce6001
@@ -28,6 +28,7 @@ pub fn register(m: &mut builtins::BuiltinsMap<&'static str, builtins::BuiltinFcn
|
||||
m.insert("startswith", (startswith, 2));
|
||||
m.insert("strings.any_prefix_match", (any_prefix_match, 2));
|
||||
m.insert("strings.any_suffix_match", (any_suffix_match, 2));
|
||||
m.insert("strings.count", (strings_count, 2));
|
||||
m.insert("strings.replace_n", (replace_n, 2));
|
||||
m.insert("strings.reverse", (reverse, 1));
|
||||
m.insert("substring", (substring, 3));
|
||||
@@ -512,6 +513,27 @@ fn any_suffix_match(
|
||||
))
|
||||
}
|
||||
|
||||
fn strings_count(
|
||||
span: &Span,
|
||||
params: &[Ref<Expr>],
|
||||
args: &[Value],
|
||||
_strict: bool,
|
||||
) -> Result<Value> {
|
||||
let name = "strings.count";
|
||||
ensure_args_count(span, name, params, args, 2)?;
|
||||
|
||||
let search = ensure_string(name, ¶ms[0], &args[0])?;
|
||||
let substring = ensure_string(name, ¶ms[0], &args[1])?;
|
||||
|
||||
Ok(Value::from(
|
||||
search
|
||||
.as_bytes()
|
||||
.windows(substring.len())
|
||||
.filter(|&w| w == substring.as_bytes())
|
||||
.count(),
|
||||
))
|
||||
}
|
||||
|
||||
fn startswith(span: &Span, params: &[Ref<Expr>], args: &[Value], _strict: bool) -> Result<Value> {
|
||||
let name = "startswith";
|
||||
ensure_args_count(span, name, params, args, 2)?;
|
||||
|
||||
@@ -13,7 +13,7 @@ use serde::{Deserialize, Serialize};
|
||||
use walkdir::WalkDir;
|
||||
|
||||
const OPA_REPO: &str = "https://github.com/open-policy-agent/opa";
|
||||
const OPA_BRANCH: &str = "v0.66.0";
|
||||
const OPA_BRANCH: &str = "v0.67.0";
|
||||
|
||||
#[derive(Serialize, Deserialize, PartialEq, Debug)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
|
||||
Reference in New Issue
Block a user