MCPcopy Create free account
hub / github.com/Bwar/CJsonObject / parse_array

Function parse_array

cJSON.c:533–571  ·  view source on GitHub ↗

Build an array from input text. */

Source from the content-addressed store, hash-verified

531
532/* Build an array from input text. */
533static const char *parse_array(cJSON *item, const char *value, const char **ep)
534{
535 cJSON *child;
536 if (*value != '[')
537 {
538 *ep = value;
539 return 0;
540 } /* not an array! */
541
542 item->type = cJSON_Array;
543 value = skip(value + 1);
544 if (*value == ']')
545 return value + 1; /* empty array. */
546
547 item->child = child = cJSON_New_Item();
548 if (!item->child)
549 return 0; /* memory fail */
550 value = skip(parse_value(child, skip(value), ep)); /* skip any spacing, get the value. */
551 if (!value)
552 return 0;
553
554 while (*value == ',')
555 {
556 cJSON *new_item;
557 if (!(new_item = cJSON_New_Item()))
558 return 0; /* memory fail */
559 child->next = new_item;
560 new_item->prev = child;
561 child = new_item;
562 value = skip(parse_value(child, skip(value + 1), ep));
563 if (!value)
564 return 0; /* memory fail */
565 }
566
567 if (*value == ']')
568 return value + 1; /* end of array */
569 *ep = value;
570 return 0; /* malformed. */
571}
572
573/* Render an array to text */
574static char *print_array(cJSON *item, int depth, int fmt)

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