MCPcopy Create free account
hub / github.com/Netis/cloud-probe / print_array

Function print_array

cpworker/src/cJSON/cJSON.c:1552–1611  ·  view source on GitHub ↗

Render an array to text */

Source from the content-addressed store, hash-verified

1550
1551/* Render an array to text */
1552static cJSON_bool print_array(const cJSON * const item, printbuffer * const output_buffer)
1553{
1554 unsigned char *output_pointer = NULL;
1555 size_t length = 0;
1556 cJSON *current_element = item->child;
1557
1558 if (output_buffer == NULL)
1559 {
1560 return false;
1561 }
1562
1563 /* Compose the output array. */
1564 /* opening square bracket */
1565 output_pointer = ensure(output_buffer, 1);
1566 if (output_pointer == NULL)
1567 {
1568 return false;
1569 }
1570
1571 *output_pointer = '[';
1572 output_buffer->offset++;
1573 output_buffer->depth++;
1574
1575 while (current_element != NULL)
1576 {
1577 if (!print_value(current_element, output_buffer))
1578 {
1579 return false;
1580 }
1581 update_offset(output_buffer);
1582 if (current_element->next)
1583 {
1584 length = (size_t) (output_buffer->format ? 2 : 1);
1585 output_pointer = ensure(output_buffer, length + 1);
1586 if (output_pointer == NULL)
1587 {
1588 return false;
1589 }
1590 *output_pointer++ = ',';
1591 if(output_buffer->format)
1592 {
1593 *output_pointer++ = ' ';
1594 }
1595 *output_pointer = '\0';
1596 output_buffer->offset += length;
1597 }
1598 current_element = current_element->next;
1599 }
1600
1601 output_pointer = ensure(output_buffer, 2);
1602 if (output_pointer == NULL)
1603 {
1604 return false;
1605 }
1606 *output_pointer++ = ']';
1607 *output_pointer = '\0';
1608 output_buffer->depth--;
1609

Callers 1

print_valueFunction · 0.85

Calls 3

ensureFunction · 0.85
print_valueFunction · 0.85
update_offsetFunction · 0.85

Tested by

no test coverage detected