| 231 | } |
| 232 | |
| 233 | absl::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 | |
| 269 | absl::optional<int64_t> StringValue::IndexOf(const absl::Cord& string) const { |
| 270 | return value_.Visit(absl::Overload( |