Build an array from input text. */
| 404 | |
| 405 | /* Build an array from input text. */ |
| 406 | static const char *parse_array(cJSON *item,const char *value) |
| 407 | { |
| 408 | cJSON *child; |
| 409 | if (*value!='[') {ep=value;return 0;} /* not an array! */ |
| 410 | |
| 411 | item->type=cJSON_Array; |
| 412 | value=skip(value+1); |
| 413 | if (*value==']') return value+1; /* empty array. */ |
| 414 | |
| 415 | item->child=child=cJSON_New_Item(); |
| 416 | if (!item->child) return 0; /* memory fail */ |
| 417 | value=skip(parse_value(child,skip(value))); /* skip any spacing, get the value. */ |
| 418 | if (!value) return 0; |
| 419 | |
| 420 | while (*value==',') |
| 421 | { |
| 422 | cJSON *new_item; |
| 423 | if (!(new_item=cJSON_New_Item())) return 0; /* memory fail */ |
| 424 | child->next=new_item;new_item->prev=child;child=new_item; |
| 425 | value=skip(parse_value(child,skip(value+1))); |
| 426 | if (!value) return 0; /* memory fail */ |
| 427 | } |
| 428 | |
| 429 | if (*value==']') return value+1; /* end of array */ |
| 430 | ep=value;return 0; /* malformed. */ |
| 431 | } |
| 432 | |
| 433 | /* Render an array to text */ |
| 434 | static char *print_array(cJSON *item,int depth,int fmt,printbuffer *p) |
no test coverage detected
searching dependent graphs…