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