MCPcopy Create free account
hub / github.com/apache/cloudberry / json_count_array_elements

Function json_count_array_elements

src/common/jsonapi.c:218–261  ·  view source on GitHub ↗

* 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. */

Source from the content-addressed store, hash-verified

216 * Designed to be called from array_start routines.
217 */
218JsonParseErrorType
219json_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(&copylex, 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, &copylex,
236 JSON_TOKEN_ARRAY_START);
237 if (result != JSON_SUCCESS)
238 return result;
239 if (lex_peek(&copylex) != JSON_TOKEN_ARRAY_END)
240 {
241 while (1)
242 {
243 count++;
244 result = parse_array_element(&copylex, &nullSemAction);
245 if (result != JSON_SUCCESS)
246 return result;
247 if (copylex.token_type != JSON_TOKEN_COMMA)
248 break;
249 result = json_lex(&copylex);
250 if (result != JSON_SUCCESS)
251 return result;
252 }
253 }
254 result = lex_expect(JSON_PARSE_ARRAY_NEXT, &copylex,
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

Callers 1

get_array_startFunction · 0.85

Calls 4

lex_expectFunction · 0.85
lex_peekFunction · 0.85
parse_array_elementFunction · 0.85
json_lexFunction · 0.85

Tested by

no test coverage detected