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

Method IndexOf

common/values/string_value.cc:233–267  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

231}
232
233absl::optional<int64_t> StringValue::IndexOf(absl::string_view string) const {
234 return value_.Visit(absl::Overload(
235 [&](absl::string_view lhs) -> absl::optional<int64_t> {
236 int64_t code_points = 0;
237 while (lhs.size() >= string.size()) {
238 if (absl::StartsWith(lhs, string)) {
239 return code_points;
240 }
241 if (lhs.size() == string.size()) {
242 break;
243 }
244 size_t code_units =
245 cel::internal::Utf8Decode(lhs, /*code_point=*/nullptr);
246 lhs.remove_prefix(code_units);
247 ++code_points;
248 }
249 return absl::nullopt;
250 },
251 [&](absl::Cord lhs) -> absl::optional<int64_t> {
252 int64_t code_points = 0;
253 while (lhs.size() >= string.size()) {
254 if (lhs.StartsWith(string)) {
255 return code_points;
256 }
257 if (lhs.size() == string.size()) {
258 break;
259 }
260 size_t code_units = cel::internal::Utf8Decode(lhs.char_begin(),
261 /*code_point=*/nullptr);
262 lhs.RemovePrefix(code_units);
263 ++code_points;
264 }
265 return absl::nullopt;
266 }));
267}
268
269absl::optional<int64_t> StringValue::IndexOf(const absl::Cord& string) const {
270 return value_.Visit(absl::Overload(

Callers 3

TEST_FFunction · 0.45
IndexOf2Function · 0.45
IndexOf3Function · 0.45

Calls 5

RemovePrefixMethod · 0.80
Utf8DecodeFunction · 0.50
VisitMethod · 0.45
sizeMethod · 0.45
StartsWithMethod · 0.45

Tested by 1

TEST_FFunction · 0.36