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