* json_count_array_elements * * Returns number of array elements in lex context at start of array token * until end of array token at same nesting level. * * Designed to be called from array_start routines. */
| 216 | * Designed to be called from array_start routines. |
| 217 | */ |
| 218 | JsonParseErrorType |
| 219 | json_count_array_elements(JsonLexContext *lex, int *elements) |
| 220 | { |
| 221 | JsonLexContext copylex; |
| 222 | int count; |
| 223 | JsonParseErrorType result; |
| 224 | |
| 225 | /* |
| 226 | * It's safe to do this with a shallow copy because the lexical routines |
| 227 | * don't scribble on the input. They do scribble on the other pointers |
| 228 | * etc, so doing this with a copy makes that safe. |
| 229 | */ |
| 230 | memcpy(©lex, lex, sizeof(JsonLexContext)); |
| 231 | copylex.strval = NULL; /* not interested in values here */ |
| 232 | copylex.lex_level++; |
| 233 | |
| 234 | count = 0; |
| 235 | result = lex_expect(JSON_PARSE_ARRAY_START, ©lex, |
| 236 | JSON_TOKEN_ARRAY_START); |
| 237 | if (result != JSON_SUCCESS) |
| 238 | return result; |
| 239 | if (lex_peek(©lex) != JSON_TOKEN_ARRAY_END) |
| 240 | { |
| 241 | while (1) |
| 242 | { |
| 243 | count++; |
| 244 | result = parse_array_element(©lex, &nullSemAction); |
| 245 | if (result != JSON_SUCCESS) |
| 246 | return result; |
| 247 | if (copylex.token_type != JSON_TOKEN_COMMA) |
| 248 | break; |
| 249 | result = json_lex(©lex); |
| 250 | if (result != JSON_SUCCESS) |
| 251 | return result; |
| 252 | } |
| 253 | } |
| 254 | result = lex_expect(JSON_PARSE_ARRAY_NEXT, ©lex, |
| 255 | JSON_TOKEN_ARRAY_END); |
| 256 | if (result != JSON_SUCCESS) |
| 257 | return result; |
| 258 | |
| 259 | *elements = count; |
| 260 | return JSON_SUCCESS; |
| 261 | } |
| 262 | |
| 263 | /* |
| 264 | * Recursive Descent parse routines. There is one for each structural |
no test coverage detected