Render an array to text */
| 1531 | |
| 1532 | /* Render an array to text */ |
| 1533 | static cJSON_bool print_array(const cJSON * const item, printbuffer * const output_buffer) |
| 1534 | { |
| 1535 | unsigned char *output_pointer = NULL; |
| 1536 | size_t length = 0; |
| 1537 | cJSON *current_element = item->child; |
| 1538 | |
| 1539 | if (output_buffer == NULL) |
| 1540 | { |
| 1541 | return false; |
| 1542 | } |
| 1543 | |
| 1544 | /* Compose the output array. */ |
| 1545 | /* opening square bracket */ |
| 1546 | output_pointer = ensure(output_buffer, 1); |
| 1547 | if (output_pointer == NULL) |
| 1548 | { |
| 1549 | return false; |
| 1550 | } |
| 1551 | |
| 1552 | *output_pointer = '['; |
| 1553 | output_buffer->offset++; |
| 1554 | output_buffer->depth++; |
| 1555 | |
| 1556 | while (current_element != NULL) |
| 1557 | { |
| 1558 | if (!print_value(current_element, output_buffer)) |
| 1559 | { |
| 1560 | return false; |
| 1561 | } |
| 1562 | update_offset(output_buffer); |
| 1563 | if (current_element->next) |
| 1564 | { |
| 1565 | length = (size_t) (output_buffer->format ? 2 : 1); |
| 1566 | output_pointer = ensure(output_buffer, length + 1); |
| 1567 | if (output_pointer == NULL) |
| 1568 | { |
| 1569 | return false; |
| 1570 | } |
| 1571 | *output_pointer++ = ','; |
| 1572 | if(output_buffer->format) |
| 1573 | { |
| 1574 | *output_pointer++ = ' '; |
| 1575 | } |
| 1576 | *output_pointer = '\0'; |
| 1577 | output_buffer->offset += length; |
| 1578 | } |
| 1579 | current_element = current_element->next; |
| 1580 | } |
| 1581 | |
| 1582 | output_pointer = ensure(output_buffer, 2); |
| 1583 | if (output_pointer == NULL) |
| 1584 | { |
| 1585 | return false; |
| 1586 | } |
| 1587 | *output_pointer++ = ']'; |
| 1588 | *output_pointer = '\0'; |
| 1589 | output_buffer->depth--; |
| 1590 |
no test coverage detected