MCPcopy Create free account
hub / github.com/Netis/cloud-probe / parse_array

Function parse_array

cpworker/src/cJSON/cJSON.c:1454–1549  ·  view source on GitHub ↗

Build an array from input text. */

Source from the content-addressed store, hash-verified

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

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