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

Function ReplaceAll

extensions/regex_ext.cc:147–172  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

145}
146
147Value 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(&regex_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
174Value ReplaceN(int regex_max_program_size, const StringValue& target,
175 const StringValue& regex, const StringValue& replacement,

Callers 1

ReplaceNFunction · 0.85

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