MCPcopy Create free account
hub / github.com/binbyu/Reader / parse_array

Function parse_array

opensrc/cjson/cJSON.c:1343–1434  ·  view source on GitHub ↗

Build an array from input text. */

Source from the content-addressed store, hash-verified

1341
1342/* Build an array from input text. */
1343static cJSON_bool parse_array(cJSON * const item, parse_buffer * const input_buffer)
1344{
1345 cJSON *head = NULL; /* head of the linked list */
1346 cJSON *current_item = NULL;
1347
1348 if (input_buffer->depth >= CJSON_NESTING_LIMIT)
1349 {
1350 return false; /* to deeply nested */
1351 }
1352 input_buffer->depth++;
1353
1354 if (buffer_at_offset(input_buffer)[0] != '[')
1355 {
1356 /* not an array */
1357 goto fail;
1358 }
1359
1360 input_buffer->offset++;
1361 buffer_skip_whitespace(input_buffer);
1362 if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == ']'))
1363 {
1364 /* empty array */
1365 goto success;
1366 }
1367
1368 /* check if we skipped to the end of the buffer */
1369 if (cannot_access_at_index(input_buffer, 0))
1370 {
1371 input_buffer->offset--;
1372 goto fail;
1373 }
1374
1375 /* step back to character in front of the first element */
1376 input_buffer->offset--;
1377 /* loop through the comma separated array elements */
1378 do
1379 {
1380 /* allocate next item */
1381 cJSON *new_item = cJSON_New_Item(&(input_buffer->hooks));
1382 if (new_item == NULL)
1383 {
1384 goto fail; /* allocation failure */
1385 }
1386
1387 /* attach next item to list */
1388 if (head == NULL)
1389 {
1390 /* start the linked list */
1391 current_item = head = new_item;
1392 }
1393 else
1394 {
1395 /* add to the end and advance */
1396 current_item->next = new_item;
1397 new_item->prev = current_item;
1398 current_item = new_item;
1399 }
1400

Callers 1

parse_valueFunction · 0.85

Calls 4

buffer_skip_whitespaceFunction · 0.85
cJSON_New_ItemFunction · 0.85
parse_valueFunction · 0.85
cJSON_DeleteFunction · 0.85

Tested by

no test coverage detected