MCPcopy Create free account
hub / github.com/SVF-tools/SVF / parse_array

Function parse_array

svf/lib/Util/cJSON.cpp:1444–1540  ·  view source on GitHub ↗

Build an array from input text. */

Source from the content-addressed store, hash-verified

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

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