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