MCPcopy Create free account
hub / github.com/alibaba/CicadaPlayer / print_array

Function print_array

framework/utils/cJSON.c:1435–1494  ·  view source on GitHub ↗

Render an array to text */

Source from the content-addressed store, hash-verified

1433
1434/* Render an array to text */
1435static cJSON_bool print_array(const cJSON * const item, printbuffer * const output_buffer)
1436{
1437 unsigned char *output_pointer = NULL;
1438 size_t length = 0;
1439 cJSON *current_element = item->child;
1440
1441 if (output_buffer == NULL)
1442 {
1443 return false;
1444 }
1445
1446 /* Compose the output array. */
1447 /* opening square bracket */
1448 output_pointer = ensure(output_buffer, 1);
1449 if (output_pointer == NULL)
1450 {
1451 return false;
1452 }
1453
1454 *output_pointer = '[';
1455 output_buffer->offset++;
1456 output_buffer->depth++;
1457
1458 while (current_element != NULL)
1459 {
1460 if (!print_value(current_element, output_buffer))
1461 {
1462 return false;
1463 }
1464 update_offset(output_buffer);
1465 if (current_element->next)
1466 {
1467 length = (size_t) (output_buffer->format ? 2 : 1);
1468 output_pointer = ensure(output_buffer, length + 1);
1469 if (output_pointer == NULL)
1470 {
1471 return false;
1472 }
1473 *output_pointer++ = ',';
1474 if(output_buffer->format)
1475 {
1476 *output_pointer++ = ' ';
1477 }
1478 *output_pointer = '\0';
1479 output_buffer->offset += length;
1480 }
1481 current_element = current_element->next;
1482 }
1483
1484 output_pointer = ensure(output_buffer, 2);
1485 if (output_pointer == NULL)
1486 {
1487 return false;
1488 }
1489 *output_pointer++ = ']';
1490 *output_pointer = '\0';
1491 output_buffer->depth--;
1492

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