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

Method Contains

common/values/parsed_json_list_value.cc:373–470  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

371} // namespace
372
373absl::Status ParsedJsonListValue::Contains(
374 const Value& other,
375 const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool,
376 google::protobuf::MessageFactory* absl_nonnull message_factory,
377 google::protobuf::Arena* absl_nonnull arena, Value* absl_nonnull result) const {
378 ABSL_DCHECK(descriptor_pool != nullptr);
379 ABSL_DCHECK(message_factory != nullptr);
380 ABSL_DCHECK(arena != nullptr);
381 ABSL_DCHECK(result != nullptr);
382
383 if (value_ == nullptr) {
384 *result = FalseValue();
385 return absl::OkStatus();
386 }
387 if (ABSL_PREDICT_FALSE(other.IsError() || other.IsUnknown())) {
388 *result = other;
389 return absl::OkStatus();
390 }
391 // Other must be comparable to `null`, `double`, `string`, `list`, or `map`.
392 const auto reflection =
393 well_known_types::GetListValueReflectionOrDie(value_->GetDescriptor());
394 if (reflection.ValuesSize(*value_) > 0) {
395 const auto value_reflection = well_known_types::GetValueReflectionOrDie(
396 reflection.GetValueDescriptor());
397 if (other.IsNull()) {
398 for (const auto& element : reflection.Values(*value_)) {
399 const auto element_kind_case = value_reflection.GetKindCase(element);
400 if (element_kind_case == google::protobuf::Value::KIND_NOT_SET ||
401 element_kind_case == google::protobuf::Value::kNullValue) {
402 *result = TrueValue();
403 return absl::OkStatus();
404 }
405 }
406 } else if (const auto other_value = other.AsBool(); other_value) {
407 for (const auto& element : reflection.Values(*value_)) {
408 if (value_reflection.GetKindCase(element) ==
409 google::protobuf::Value::kBoolValue &&
410 value_reflection.GetBoolValue(element) == *other_value) {
411 *result = TrueValue();
412 return absl::OkStatus();
413 }
414 }
415 } else if (const auto other_value = AsNumber(other); other_value) {
416 for (const auto& element : reflection.Values(*value_)) {
417 if (value_reflection.GetKindCase(element) ==
418 google::protobuf::Value::kNumberValue &&
419 internal::Number::FromDouble(
420 value_reflection.GetNumberValue(element)) == *other_value) {
421 *result = TrueValue();
422 return absl::OkStatus();
423 }
424 }
425 } else if (const auto other_value = other.AsString(); other_value) {
426 std::string scratch;
427 for (const auto& element : reflection.Values(*value_)) {
428 if (value_reflection.GetKindCase(element) ==
429 google::protobuf::Value::kStringValue &&
430 absl::visit(

Callers

nothing calls this directly

Calls 15

FalseValueFunction · 0.85
GetValueReflectionOrDieFunction · 0.85
TrueValueFunction · 0.85
AsNumberFunction · 0.85
ValuesMethod · 0.80
IsTrueMethod · 0.80
ParsedJsonListValueClass · 0.70
ParsedJsonMapValueClass · 0.70
IsErrorMethod · 0.45
IsUnknownMethod · 0.45
GetDescriptorMethod · 0.45

Tested by

no test coverage detected