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

Function CaptureString

extensions/regex_functions.cc:80–100  ·  view source on GitHub ↗

Captures the first unnamed/named group value NOTE: For capturing all the groups, use CaptureStringN instead

Source from the content-addressed store, hash-verified

78// Captures the first unnamed/named group value
79// NOTE: For capturing all the groups, use CaptureStringN instead
80Value CaptureString(int regex_max_program_size, const StringValue& target,
81 const StringValue& regex,
82 const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool,
83 google::protobuf::MessageFactory* absl_nonnull message_factory,
84 google::protobuf::Arena* absl_nonnull arena) {
85 std::string regex_scratch;
86 std::string target_scratch;
87 absl::string_view regex_view = regex.ToStringView(&regex_scratch);
88 absl::string_view target_view = target.ToStringView(&target_scratch);
89 RE2 re2(regex_view, cel::internal::MakeRE2Options());
90 CEL_RETURN_IF_ERROR(cel::internal::CheckRE2(re2, regex_max_program_size))
91 .With(ErrorValueReturn());
92 std::string output;
93 bool result = RE2::FullMatch(target_view, re2, &output);
94 if (!result) {
95 return ErrorValue(absl::InvalidArgumentError(
96 "Unable to capture groups for the given regex"));
97 } else {
98 return StringValue::From(std::move(output), arena);
99 }
100}
101
102// Does a FullMatchN on the given string and regex and returns a map with <key,
103// value> pairs as follows:

Callers

nothing calls this directly

Calls 6

MakeRE2OptionsFunction · 0.85
CheckRE2Function · 0.85
ErrorValueReturnClass · 0.85
ErrorValueFunction · 0.85
ToStringViewMethod · 0.80
WithMethod · 0.80

Tested by

no test coverage detected