Render an object to text. */
| 1608 | |
| 1609 | /* Render an object to text. */ |
| 1610 | static cJSON_bool print_object(const cJSON * const item, printbuffer * const output_buffer) |
| 1611 | { |
| 1612 | unsigned char *output_pointer = NULL; |
| 1613 | size_t length = 0; |
| 1614 | cJSON *current_item = item->child; |
| 1615 | |
| 1616 | if (output_buffer == NULL) |
| 1617 | { |
| 1618 | return false; |
| 1619 | } |
| 1620 | |
| 1621 | /* Compose the output: */ |
| 1622 | length = (size_t) (output_buffer->format ? 2 : 1); /* fmt: {\n */ |
| 1623 | output_pointer = ensure(output_buffer, length + 1); |
| 1624 | if (output_pointer == NULL) |
| 1625 | { |
| 1626 | return false; |
| 1627 | } |
| 1628 | |
| 1629 | *output_pointer++ = '{'; |
| 1630 | output_buffer->depth++; |
| 1631 | if (output_buffer->format) |
| 1632 | { |
| 1633 | *output_pointer++ = '\n'; |
| 1634 | } |
| 1635 | output_buffer->offset += length; |
| 1636 | |
| 1637 | while (current_item) |
| 1638 | { |
| 1639 | if (output_buffer->format) |
| 1640 | { |
| 1641 | size_t i; |
| 1642 | output_pointer = ensure(output_buffer, output_buffer->depth); |
| 1643 | if (output_pointer == NULL) |
| 1644 | { |
| 1645 | return false; |
| 1646 | } |
| 1647 | for (i = 0; i < output_buffer->depth; i++) |
| 1648 | { |
| 1649 | *output_pointer++ = '\t'; |
| 1650 | } |
| 1651 | output_buffer->offset += output_buffer->depth; |
| 1652 | } |
| 1653 | |
| 1654 | /* print key */ |
| 1655 | if (!print_string_ptr((unsigned char*)current_item->string, output_buffer)) |
| 1656 | { |
| 1657 | return false; |
| 1658 | } |
| 1659 | update_offset(output_buffer); |
| 1660 | |
| 1661 | length = (size_t) (output_buffer->format ? 2 : 1); |
| 1662 | output_pointer = ensure(output_buffer, length); |
| 1663 | if (output_pointer == NULL) |
| 1664 | { |
| 1665 | return false; |
| 1666 | } |
| 1667 | *output_pointer++ = ':'; |
no test coverage detected