Build an array from input text. */
| 431 | |
| 432 | /* Build an array from input text. */ |
| 433 | static const char *parse_array(cJSON *item, const char *value) { |
| 434 | cJSON *child; |
| 435 | if (*value != '[') { |
| 436 | ep = value; |
| 437 | return 0; |
| 438 | } /* not an array! */ |
| 439 | |
| 440 | item->type = cJSON_Array; |
| 441 | value = skip(value + 1); |
| 442 | if (*value == ']') return value + 1; /* empty array. */ |
| 443 | |
| 444 | item->child = child = cJSON_New_Item(); |
| 445 | if (!item->child) return 0; /* memory fail */ |
| 446 | value = skip(parse_value(child, skip(value))); /* skip any spacing, get the value. */ |
| 447 | if (!value) return 0; |
| 448 | |
| 449 | while (*value == ',') { |
| 450 | cJSON *new_item; |
| 451 | if (!(new_item = cJSON_New_Item())) return 0; /* memory fail */ |
| 452 | child->next = new_item; |
| 453 | new_item->prev = child; |
| 454 | child = new_item; |
| 455 | value = skip(parse_value(child, skip(value + 1))); |
| 456 | if (!value) return 0; /* memory fail */ |
| 457 | } |
| 458 | |
| 459 | if (*value == ']') return value + 1; /* end of array */ |
| 460 | ep = value; |
| 461 | return 0; /* malformed. */ |
| 462 | } |
| 463 | |
| 464 | /* Render an array to text */ |
| 465 | static char *print_array(cJSON *item, int depth, int fmt) { |
no test coverage detected