MCPcopy Create free account
hub / github.com/cel-expr/cel-cpp / RegisterRegexFunctions

Function RegisterRegexFunctions

runtime/standard/regex_functions.cc:30–54  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

28namespace {} // namespace
29
30absl::Status RegisterRegexFunctions(FunctionRegistry& registry,
31 const RuntimeOptions& options) {
32 if (options.enable_regex) {
33 auto regex_matches = [max_size = options.regex_max_program_size](
34 const StringValue& target,
35 const StringValue& regex) -> Value {
36 RE2 re2(regex.ToString(), cel::internal::MakeRE2Options());
37 CEL_RETURN_IF_ERROR(cel::internal::CheckRE2(re2, max_size))
38 .With(ErrorValueReturn());
39 return BoolValue(RE2::PartialMatch(target.ToString(), re2));
40 };
41
42 // bind str.matches(re) and matches(str, re)
43 for (bool receiver_style : {true, false}) {
44 using MatchFnAdapter =
45 BinaryFunctionAdapter<Value, const StringValue&, const StringValue&>;
46 CEL_RETURN_IF_ERROR(
47 registry.Register(MatchFnAdapter::CreateDescriptor(
48 cel::builtin::kRegexMatch, receiver_style),
49 MatchFnAdapter::WrapFunction(regex_matches)));
50 }
51 } // if options.enable_regex
52
53 return absl::OkStatus();
54}
55
56} // namespace cel

Callers 2

TESTFunction · 0.70

Calls 8

MakeRE2OptionsFunction · 0.85
CheckRE2Function · 0.85
ErrorValueReturnClass · 0.85
CreateDescriptorFunction · 0.85
WithMethod · 0.80
BoolValueClass · 0.50
ToStringMethod · 0.45
RegisterMethod · 0.45

Tested by 1

TESTFunction · 0.56