Captures the first unnamed/named group value NOTE: For capturing all the groups, use CaptureStringN instead
| 78 | // Captures the first unnamed/named group value |
| 79 | // NOTE: For capturing all the groups, use CaptureStringN instead |
| 80 | Value 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(®ex_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: |
nothing calls this directly
no test coverage detected