Build an array from input text. */
| 1442 | |
| 1443 | /* Build an array from input text. */ |
| 1444 | static 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 |
no test coverage detected