Render an object to text. */
| 1723 | |
| 1724 | /* Render an object to text. */ |
| 1725 | static cJSON_bool print_object(const cJSON * const item, printbuffer * const output_buffer) |
| 1726 | { |
| 1727 | unsigned char *output_pointer = NULL; |
| 1728 | size_t length = 0; |
| 1729 | cJSON *current_item = item->child; |
| 1730 | |
| 1731 | if (output_buffer == NULL) |
| 1732 | { |
| 1733 | return false; |
| 1734 | } |
| 1735 | |
| 1736 | /* Compose the output: */ |
| 1737 | length = (size_t) (output_buffer->format ? 2 : 1); /* fmt: {\n */ |
| 1738 | output_pointer = ensure(output_buffer, length + 1); |
| 1739 | if (output_pointer == NULL) |
| 1740 | { |
| 1741 | return false; |
| 1742 | } |
| 1743 | |
| 1744 | *output_pointer++ = '{'; |
| 1745 | output_buffer->depth++; |
| 1746 | if (output_buffer->format) |
| 1747 | { |
| 1748 | *output_pointer++ = '\n'; |
| 1749 | } |
| 1750 | output_buffer->offset += length; |
| 1751 | |
| 1752 | while (current_item) |
| 1753 | { |
| 1754 | if (output_buffer->format) |
| 1755 | { |
| 1756 | size_t i; |
| 1757 | output_pointer = ensure(output_buffer, output_buffer->depth); |
| 1758 | if (output_pointer == NULL) |
| 1759 | { |
| 1760 | return false; |
| 1761 | } |
| 1762 | for (i = 0; i < output_buffer->depth; i++) |
| 1763 | { |
| 1764 | *output_pointer++ = '\t'; |
| 1765 | } |
| 1766 | output_buffer->offset += output_buffer->depth; |
| 1767 | } |
| 1768 | |
| 1769 | /* print key */ |
| 1770 | if (!print_string_ptr((unsigned char*)current_item->string, output_buffer)) |
| 1771 | { |
| 1772 | return false; |
| 1773 | } |
| 1774 | update_offset(output_buffer); |
| 1775 | |
| 1776 | length = (size_t) (output_buffer->format ? 2 : 1); |
| 1777 | output_pointer = ensure(output_buffer, length); |
| 1778 | if (output_pointer == NULL) |
| 1779 | { |
| 1780 | return false; |
| 1781 | } |
| 1782 | *output_pointer++ = ':'; |
no test coverage detected
searching dependent graphs…