MCPcopy Create free account
hub / github.com/OpenFodder/openfodder / contains

Function contains

Source/Utils/json.hpp:12194–12263  ·  view source on GitHub ↗

! @throw parse_error.106 if an array index begins with '0' @throw parse_error.109 if an array index was not a number */

Source from the content-addressed store, hash-verified

12192 @throw parse_error.109 if an array index was not a number
12193 */
12194 bool contains(const BasicJsonType* ptr) const
12195 {
12196 for (const auto& reference_token : reference_tokens)
12197 {
12198 switch (ptr->type())
12199 {
12200 case detail::value_t::object:
12201 {
12202 if (!ptr->contains(reference_token))
12203 {
12204 // we did not find the key in the object
12205 return false;
12206 }
12207
12208 ptr = &ptr->operator[](reference_token);
12209 break;
12210 }
12211
12212 case detail::value_t::array:
12213 {
12214 if (JSON_HEDLEY_UNLIKELY(reference_token == "-"))
12215 {
12216 // "-" always fails the range check
12217 return false;
12218 }
12219 if (JSON_HEDLEY_UNLIKELY(reference_token.size() == 1 && !("0" <= reference_token && reference_token <= "9")))
12220 {
12221 // invalid char
12222 return false;
12223 }
12224 if (JSON_HEDLEY_UNLIKELY(reference_token.size() > 1))
12225 {
12226 if (JSON_HEDLEY_UNLIKELY(!('1' <= reference_token[0] && reference_token[0] <= '9')))
12227 {
12228 // first char should be between '1' and '9'
12229 return false;
12230 }
12231 for (std::size_t i = 1; i < reference_token.size(); i++)
12232 {
12233 if (JSON_HEDLEY_UNLIKELY(!('0' <= reference_token[i] && reference_token[i] <= '9')))
12234 {
12235 // other char should be between '0' and '9'
12236 return false;
12237 }
12238 }
12239 }
12240
12241 const auto idx = array_index(reference_token);
12242 if (idx >= ptr->size())
12243 {
12244 // index out of range
12245 return false;
12246 }
12247
12248 ptr = &ptr->operator[](idx);
12249 break;
12250 }
12251

Callers

nothing calls this directly

Calls 6

is_objectFunction · 0.85
typeMethod · 0.80
findMethod · 0.80
operator[]Method · 0.45
sizeMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected