MCPcopy Index your code
hub / github.com/antirez/botlib / print_array

Function print_array

cJSON.c:1535–1594  ·  view source on GitHub ↗

Render an array to text */

Source from the content-addressed store, hash-verified

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

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