| 145 | } |
| 146 | |
| 147 | Value ReplaceAll(int regex_max_program_size, const StringValue& target, |
| 148 | const StringValue& regex, const StringValue& replacement, |
| 149 | const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool, |
| 150 | google::protobuf::MessageFactory* absl_nonnull message_factory, |
| 151 | google::protobuf::Arena* absl_nonnull arena) { |
| 152 | std::string target_scratch; |
| 153 | std::string regex_scratch; |
| 154 | std::string replacement_scratch; |
| 155 | absl::string_view target_view = target.ToStringView(&target_scratch); |
| 156 | absl::string_view regex_view = regex.ToStringView(®ex_scratch); |
| 157 | absl::string_view replacement_view = |
| 158 | replacement.ToStringView(&replacement_scratch); |
| 159 | RE2 re2(regex_view, cel::internal::MakeRE2Options()); |
| 160 | CEL_RETURN_IF_ERROR(cel::internal::CheckRE2(re2, regex_max_program_size)) |
| 161 | .With(ErrorValueReturn()); |
| 162 | std::string error_string; |
| 163 | if (!re2.CheckRewriteString(replacement_view, &error_string)) { |
| 164 | return ErrorValue(absl::InvalidArgumentError( |
| 165 | absl::StrFormat("invalid replacement string: %s", error_string))); |
| 166 | } |
| 167 | |
| 168 | std::string output(target_view); |
| 169 | RE2::GlobalReplace(&output, re2, replacement_view); |
| 170 | |
| 171 | return StringValue::From(std::move(output), arena); |
| 172 | } |
| 173 | |
| 174 | Value ReplaceN(int regex_max_program_size, const StringValue& target, |
| 175 | const StringValue& regex, const StringValue& replacement, |
no test coverage detected