MCPcopy Create free account
hub / github.com/Tencent/TAD_Sim / parse_array

Function parse_array

common/map_sdk/transmission/src/cJSON.cpp:433–462  ·  view source on GitHub ↗

Build an array from input text. */

Source from the content-addressed store, hash-verified

431
432/* Build an array from input text. */
433static 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 */
465static 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