MCPcopy Index your code
hub / github.com/armink/struct2json / parse_array

Function parse_array

struct2json/src/cJSON.c:407–432  ·  view source on GitHub ↗

Build an array from input text. */

Source from the content-addressed store, hash-verified

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

Callers 1

parse_valueFunction · 0.85

Calls 3

skipFunction · 0.85
cJSON_New_ItemFunction · 0.85
parse_valueFunction · 0.85

Tested by

no test coverage detected