Lines Matching refs:item
91 /* Parse the input text to generate a number, and populate the result into item.
93 static const char *parse_number(cJSON *item, const char *num) {
127 item->valuedouble = n;
128 item->valueint = (int)n;
129 item->type = cJSON_Number;
181 /* Render the number nicely from the given item into a string. */
182 static char *print_number(cJSON *item, printbuffer *p) {
184 double d = item->valuedouble;
192 } else if (fabs(((double)item->valueint) - d) <= DBL_EPSILON &&
200 sprintf(str, "%d", item->valueint);
261 /* Parse the input text into an unescaped cstring, and populate item. */
264 static const char *parse_string(cJSON *item, const char *str) {
360 item->valuestring = out;
361 item->type = cJSON_String;
460 /* Invote print_string_ptr (which is useful) on an item. */
461 static char *print_string(cJSON *item, printbuffer *p) {
462 return print_string_ptr(item->valuestring, p);
466 static const char *parse_value(cJSON *item, const char *value);
467 static char *print_value(cJSON *item, int depth, int fmt, printbuffer *p);
468 static const char *parse_array(cJSON *item, const char *value);
469 static char *print_array(cJSON *item, int depth, int fmt, printbuffer *p);
470 static const char *parse_object(cJSON *item, const char *value);
471 static char *print_object(cJSON *item, int depth, int fmt, printbuffer *p);
514 /* Render a cJSON item/entity/structure to text. */
515 char *cJSON_Print(cJSON *item) { return print_value(item, 0, 1, 0); }
516 char *cJSON_PrintUnformatted(cJSON *item) { return print_value(item, 0, 0, 0); }
518 char *cJSON_PrintBuffered(cJSON *item, int prebuffer, int fmt) {
523 return print_value(item, 0, fmt, &p);
527 static const char *parse_value(cJSON *item, const char *value) {
531 item->type = cJSON_NULL;
535 item->type = cJSON_False;
539 item->type = cJSON_True;
540 item->valueint = 1;
544 return parse_string(item, value);
547 return parse_number(item, value);
550 return parse_array(item, value);
553 return parse_object(item, value);
561 static char *print_value(cJSON *item, int depth, int fmt, printbuffer *p) {
563 if (!item)
566 switch ((item->type) & 255) {
586 out = print_number(item, p);
589 out = print_string(item, p);
592 out = print_array(item, depth, fmt, p);
595 out = print_object(item, depth, fmt, p);
599 switch ((item->type) & 255) {
610 out = print_number(item, 0);
613 out = print_string(item, 0);
616 out = print_array(item, depth, fmt, 0);
619 out = print_object(item, depth, fmt, 0);
627 static const char *parse_array(cJSON *item, const char *value) {
634 item->type = cJSON_Array;
639 item->child = child = cJSON_New_Item();
640 if (!item->child)
666 static char *print_array(cJSON *item, int depth, int fmt, printbuffer *p) {
670 cJSON *child = item->child;
696 child = item->child;
726 child = item->child;
777 static const char *parse_object(cJSON *item, const char *value) {
784 item->type = cJSON_Object;
789 item->child = child = cJSON_New_Item();
790 if (!item->child)
835 static char *print_object(cJSON *item, int depth, int fmt, printbuffer *p) {
839 cJSON *child = item->child;
876 child = item->child;
937 child = item->child;
1008 /* Get Array size/item / object item. */
1016 cJSON *cJSON_GetArrayItem(cJSON *array, int item) {
1018 while (c && item > 0)
1019 item--, c = c->next;
1030 static void suffix_object(cJSON *prev, cJSON *item) {
1031 prev->next = item;
1032 item->prev = prev;
1035 static cJSON *create_reference(cJSON *item) {
1039 memcpy(ref, item, sizeof(cJSON));
1046 /* Add item to array/object. */
1047 void cJSON_AddItemToArray(cJSON *array, cJSON *item) {
1049 if (!item)
1052 array->child = item;
1056 suffix_object(c, item);
1059 void cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item) {
1060 if (!item)
1062 if (item->string)
1063 cJSON_free(item->string);
1064 item->string = cJSON_strdup(string);
1065 cJSON_AddItemToArray(object, item);
1067 void cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item) {
1068 if (!item)
1070 if (!(item->type & cJSON_StringIsConst) && item->string)
1071 cJSON_free(item->string);
1072 item->string = (char *)string;
1073 item->type |= cJSON_StringIsConst;
1074 cJSON_AddItemToArray(object, item);
1076 void cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item) {
1077 cJSON_AddItemToArray(array, create_reference(item));
1080 cJSON *item) {
1081 cJSON_AddItemToObject(object, string, create_reference(item));
1163 cJSON *item = cJSON_New_Item();
1164 if (item)
1165 item->type = cJSON_NULL;
1166 item;
1169 cJSON *item = cJSON_New_Item();
1170 if (item)
1171 item->type = cJSON_True;
1172 return item;
1175 cJSON *item = cJSON_New_Item();
1176 if (item)
1177 item->type = cJSON_False;
1178 return item;
1181 cJSON *item = cJSON_New_Item();
1182 if (item)
1183 item->type = b ? cJSON_True : cJSON_False;
1184 return item;
1187 cJSON *item = cJSON_New_Item();
1188 if (item) {
1189 item->type = cJSON_Number;
1190 item->valuedouble = num;
1191 item->valueint = (int)num;
1193 return item;
1196 cJSON *item = cJSON_New_Item();
1197 if (item) {
1198 item->type = cJSON_String;
1199 item->valuestring = cJSON_strdup(string);
1201 return item;
1204 cJSON *item = cJSON_New_Item();
1205 if (item)
1206 item->type = cJSON_Array;
1207 return item;
1210 cJSON *item = cJSON_New_Item();
1211 if (item)
1212 item->type = cJSON_Object;
1213 return item;
1271 cJSON *cJSON_Duplicate(cJSON *item, int recurse) {
1274 if (!item)
1276 /* Create new item */
1281 newitem->type = item->type & (~cJSON_IsReference),
1282 newitem->valueint = item->valueint,
1283 newitem->valuedouble = item->valuedouble;
1284 if (item->valuestring) {
1285 newitem->valuestring = cJSON_strdup(item->valuestring);
1291 if (item->string) {
1292 newitem->string = cJSON_strdup(item->string);
1302 cptr = item->child;
1306 1); /* Duplicate (with recurse) each item in the ->next chain */