MCPcopy Create free account
hub / github.com/TheForceEngine/TheForceEngine / parse_array

Function parse_array

TheForceEngine/TFE_System/cJSON.c:1446–1541  ·  view source on GitHub ↗

Build an array from input text. */

Source from the content-addressed store, hash-verified

1444
1445/* Build an array from input text. */
1446static cJSON_bool parse_array(cJSON * const item, parse_buffer * const input_buffer)
1447{
1448 cJSON *head = NULL; /* head of the linked list */
1449 cJSON *current_item = NULL;
1450
1451 if (input_buffer->depth >= CJSON_NESTING_LIMIT)
1452 {
1453 return false; /* to deeply nested */
1454 }
1455 input_buffer->depth++;
1456
1457 if (buffer_at_offset(input_buffer)[0] != '[')
1458 {
1459 /* not an array */
1460 goto fail;
1461 }
1462
1463 input_buffer->offset++;
1464 buffer_skip_whitespace(input_buffer);
1465 if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == ']'))
1466 {
1467 /* empty array */
1468 goto success;
1469 }
1470
1471 /* check if we skipped to the end of the buffer */
1472 if (cannot_access_at_index(input_buffer, 0))
1473 {
1474 input_buffer->offset--;
1475 goto fail;
1476 }
1477
1478 /* step back to character in front of the first element */
1479 input_buffer->offset--;
1480 /* loop through the comma separated array elements */
1481 do
1482 {
1483 /* allocate next item */
1484 cJSON *new_item = cJSON_New_Item(&(input_buffer->hooks));
1485 if (new_item == NULL)
1486 {
1487 goto fail; /* allocation failure */
1488 }
1489
1490 /* attach next item to list */
1491 if (head == NULL)
1492 {
1493 /* start the linked list */
1494 current_item = head = new_item;
1495 }
1496 else
1497 {
1498 /* add to the end and advance */
1499 current_item->next = new_item;
1500 new_item->prev = current_item;
1501 current_item = new_item;
1502 }
1503

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