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

Function LookupInList

eval/eval/container_access_step.cc:161–200  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

159}
160
161void LookupInList(const ListValue& cel_list, const Value& key,
162 ExecutionFrameBase& frame, Value& result) {
163 absl::optional<int64_t> maybe_idx;
164 if (frame.options().enable_heterogeneous_equality) {
165 auto number = CelNumberFromValue(key);
166 if (number.has_value() && number->LosslessConvertibleToInt()) {
167 maybe_idx = number->AsInt();
168 }
169 } else if (InstanceOf<IntValue>(key)) {
170 maybe_idx = key.GetInt().NativeValue();
171 }
172
173 if (!maybe_idx.has_value()) {
174 result = cel::ErrorValue(absl::UnknownError(
175 absl::StrCat("Index error: expected integer type, got ",
176 cel::KindToString(ValueKindToKind(key->kind())))));
177 return;
178 }
179
180 int64_t idx = *maybe_idx;
181 auto size = cel_list.Size();
182 if (!size.ok()) {
183 result = cel::ErrorValue(size.status());
184 return;
185 }
186 if (idx < 0 || idx >= *size) {
187 result = cel::ErrorValue(absl::UnknownError(
188 absl::StrCat("Index error: index=", idx, " size=", *size)));
189 return;
190 }
191
192 absl::Status lookup =
193 cel_list.Get(idx, frame.descriptor_pool(), frame.message_factory(),
194 frame.arena(), &result);
195
196 if (!lookup.ok()) {
197 result = cel::ErrorValue(std::move(lookup));
198 }
199 ABSL_DCHECK(!result.IsUnknown());
200}
201
202void LookupInContainer(const Value& container, const Value& key,
203 ExecutionFrameBase& frame, Value& result) {

Callers 1

LookupInContainerFunction · 0.85

Calls 15

CelNumberFromValueFunction · 0.85
ErrorValueFunction · 0.85
ValueKindToKindFunction · 0.85
KindToStringFunction · 0.50
has_valueMethod · 0.45
AsIntMethod · 0.45
NativeValueMethod · 0.45
GetIntMethod · 0.45
kindMethod · 0.45
SizeMethod · 0.45
okMethod · 0.45

Tested by

no test coverage detected