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

Function CheckPattern

validator/regex_validator.cc:34–69  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

32namespace {
33
34bool CheckPattern(ValidationContext& context, const NavigableAstNode& node,
35 int arg_index) {
36 ABSL_DCHECK(node.expr()->has_call_expr());
37 const auto& call_expr = node.expr()->call_expr();
38
39 const Expr* pattern_expr = nullptr;
40
41 if (call_expr.has_target()) {
42 if (arg_index == 0) {
43 pattern_expr = &call_expr.target();
44 } else if (call_expr.args().size() > arg_index - 1) {
45 pattern_expr = &call_expr.args()[arg_index - 1];
46 }
47 } else if (call_expr.args().size() > arg_index) {
48 pattern_expr = &call_expr.args()[arg_index];
49 }
50
51 if (pattern_expr == nullptr || !pattern_expr->has_const_expr()) {
52 return true;
53 }
54
55 const auto& const_expr = pattern_expr->const_expr();
56 if (!const_expr.has_string_value()) {
57 return true;
58 }
59
60 absl::string_view pattern_string = const_expr.string_value();
61 RE2 re(pattern_string, internal::MakeRE2Options());
62 if (!re.ok()) {
63 context.ReportErrorAt(
64 pattern_expr->id(),
65 absl::StrCat("invalid regular expression: ", re.error()));
66 return false;
67 }
68 return true;
69}
70
71} // namespace
72

Callers 1

RegexPatternValidatorFunction · 0.85

Calls 10

MakeRE2OptionsFunction · 0.85
has_call_exprMethod · 0.80
has_targetMethod · 0.80
argsMethod · 0.80
has_const_exprMethod · 0.80
exprMethod · 0.45
sizeMethod · 0.45
okMethod · 0.45
ReportErrorAtMethod · 0.45
idMethod · 0.45

Tested by

no test coverage detected