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

Function EvaluateInMap

eval/eval/equality_steps.cc:132–185  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

130};
131
132absl::StatusOr<Value> EvaluateInMap(ExecutionFrameBase& frame,
133 const Value& item,
134 const MapValue& container) {
135 switch (item.kind()) {
136 case ValueKind::kBool:
137 case ValueKind::kString:
138 case ValueKind::kInt:
139 case ValueKind::kUint:
140 case ValueKind::kDouble:
141 break;
142 default:
143 return cel::ErrorValue(
144 cel::runtime_internal::CreateNoMatchingOverloadError(
145 cel::builtin::kIn));
146 }
147 Value result;
148 CEL_RETURN_IF_ERROR(container.Has(item, frame.descriptor_pool(),
149 frame.message_factory(), frame.arena(),
150 &result));
151
152 if (result.IsTrue()) {
153 return result;
154 }
155
156 if (item.IsDouble() || item.IsUint()) {
157 Number number = item.IsDouble()
158 ? Number::FromDouble(item.GetDouble().NativeValue())
159 : Number::FromUint64(item.GetUint().NativeValue());
160 if (number.LosslessConvertibleToInt()) {
161 CEL_RETURN_IF_ERROR(
162 container.Has(IntValue(number.AsInt()), frame.descriptor_pool(),
163 frame.message_factory(), frame.arena(), &result));
164 if (result.IsTrue()) {
165 return result;
166 }
167 }
168 }
169
170 if (item.IsDouble() || item.IsInt()) {
171 Number number = item.IsDouble()
172 ? Number::FromDouble(item.GetDouble().NativeValue())
173 : Number::FromInt64(item.GetInt().NativeValue());
174 if (number.LosslessConvertibleToUint()) {
175 CEL_RETURN_IF_ERROR(
176 container.Has(UintValue(number.AsUint()), frame.descriptor_pool(),
177 frame.message_factory(), frame.arena(), &result));
178 if (result.IsTrue()) {
179 return result;
180 }
181 }
182 }
183
184 return BoolValue(false);
185}
186
187absl::StatusOr<Value> EvaluateIn(ExecutionFrameBase& frame, const Value& item,
188 const AttributeTrail& item_attr,

Callers 1

EvaluateInFunction · 0.85

Calls 15

ErrorValueFunction · 0.85
IsTrueMethod · 0.80
IntValueClass · 0.50
UintValueClass · 0.50
BoolValueClass · 0.50
kindMethod · 0.45
HasMethod · 0.45
descriptor_poolMethod · 0.45
message_factoryMethod · 0.45

Tested by

no test coverage detected