Render an object to text. */
| 1778 | |
| 1779 | /* Render an object to text. */ |
| 1780 | static cJSON_bool print_object(const cJSON * const item, printbuffer * const output_buffer) |
| 1781 | { |
| 1782 | unsigned char *output_pointer = NULL; |
| 1783 | size_t length = 0; |
| 1784 | cJSON *current_item = item->child; |
| 1785 | |
| 1786 | if (output_buffer == NULL) |
| 1787 | { |
| 1788 | return false; |
| 1789 | } |
| 1790 | |
| 1791 | if (output_buffer->depth >= CJSON_NESTING_LIMIT) |
| 1792 | { |
| 1793 | return false; /* nesting is too deep */ |
| 1794 | } |
| 1795 | |
| 1796 | /* Compose the output: */ |
| 1797 | length = (size_t) (output_buffer->format ? 2 : 1); /* fmt: {\n */ |
| 1798 | output_pointer = ensure(output_buffer, length + 1); |
| 1799 | if (output_pointer == NULL) |
| 1800 | { |
| 1801 | return false; |
| 1802 | } |
| 1803 | |
| 1804 | *output_pointer++ = '{'; |
| 1805 | output_buffer->depth++; |
| 1806 | if (output_buffer->format) |
| 1807 | { |
| 1808 | *output_pointer++ = '\n'; |
| 1809 | } |
| 1810 | output_buffer->offset += length; |
| 1811 | |
| 1812 | while (current_item) |
| 1813 | { |
| 1814 | if (output_buffer->format) |
| 1815 | { |
| 1816 | size_t i; |
| 1817 | output_pointer = ensure(output_buffer, output_buffer->depth); |
| 1818 | if (output_pointer == NULL) |
| 1819 | { |
| 1820 | return false; |
| 1821 | } |
| 1822 | for (i = 0; i < output_buffer->depth; i++) |
| 1823 | { |
| 1824 | *output_pointer++ = '\t'; |
| 1825 | } |
| 1826 | output_buffer->offset += output_buffer->depth; |
| 1827 | } |
| 1828 | |
| 1829 | /* print key */ |
| 1830 | if (!print_string_ptr((unsigned char*)current_item->string, output_buffer)) |
| 1831 | { |
| 1832 | return false; |
| 1833 | } |
| 1834 | update_offset(output_buffer); |
| 1835 | |
| 1836 | length = (size_t) (output_buffer->format ? 2 : 1); |
| 1837 | output_pointer = ensure(output_buffer, length); |
no test coverage detected