Lines Matching refs:item

99 CJSON_PUBLIC(char *) cJSON_GetStringValue(const cJSON * const item)
101 if (!cJSON_IsString(item))
106 return item->valuestring;
110 CJSON_PUBLIC(long long *) cJSON_GetInt64NumberValue(cJSON * const item)
112 if (!cJSON_IsInt64Number(item))
117 return &(item->valueint);
121 CJSON_PUBLIC(double) cJSON_GetNumberValue(const cJSON * const item)
123 if (!cJSON_IsNumber(item))
128 return item->valuedouble;
265 CJSON_PUBLIC(void) cJSON_Delete(cJSON *item)
268 while (item != NULL)
270 next = item->next;
271 if (!(item->type & cJSON_IsReference) && (item->child != NULL))
273 cJSON_Delete(item->child);
275 if (!(item->type & cJSON_IsReference) && (item->valuestring != NULL))
277 global_hooks.deallocate(item->valuestring);
278 item->valuestring = NULL;
280 if (!(item->type & cJSON_StringIsConst) && (item->string != NULL))
282 global_hooks.deallocate(item->string);
283 item->string = NULL;
285 if (next == item)
289 global_hooks.deallocate(item);
290 item = next;
323 /* Parse the input text to generate a number, and populate the result into item. */
324 static cJSON_bool parse_number(cJSON * const item, parse_buffer * const input_buffer)
382 item->type = cJSON_Number | cJSON_IsInt64;
388 item->valueint = integer;
389 item->valuedouble = (double)integer;
399 item->valuedouble = number;
404 item->valueint = LLONG_MAX;
408 item->valueint = LLONG_MIN;
412 item->valueint = (long long)number;
415 item->type = cJSON_Number;
422 /* Parse the input text to generate a number, and populate the result into item. */
423 static cJSON_bool parse_number(cJSON * const item, parse_buffer * const input_buffer)
477 item->valuedouble = number;
482 item->valueint = INT_MAX;
486 item->valueint = INT_MIN;
490 item->valueint = (int)number;
493 item->type = cJSON_Number;
711 /* Render the number nicely from the given item into a string. */
712 static cJSON_bool print_number(const cJSON * const item, printbuffer * const output_buffer)
715 double d = item->valuedouble;
716 long long integer = item->valueint;
728 if (item->type & cJSON_IsInt64)
733 else /* item->type == cJSON_Number */
786 /* Render the number nicely from the given item into a string. */
787 static cJSON_bool print_number(const cJSON * const item, printbuffer * const output_buffer)
790 double d = item->valuedouble;
807 else if(d == (double)item->valueint)
809 length = sprintf((char*)number_buffer, "%d", item->valueint);
1015 /* Parse the input text into an unescaped cinput, and populate item. */
1016 static cJSON_bool parse_string(cJSON * const item, parse_buffer * const input_buffer)
1122 item->type = cJSON_String;
1123 item->valuestring = (char*)output;
1266 /* Invoke print_string_ptr (which is useful) on an item. */
1267 static cJSON_bool print_string(const cJSON * const item, printbuffer * const p)
1269 return print_string_ptr((unsigned char*)item->valuestring, p);
1273 static cJSON_bool parse_value(cJSON * const item, parse_buffer * const input_buffer);
1274 static cJSON_bool print_value(const cJSON * const item, printbuffer * const output_buffer);
1275 static cJSON_bool parse_array(cJSON * const item, parse_buffer * const input_buffer);
1276 static cJSON_bool print_array(const cJSON * const item, printbuffer * const output_buffer);
1277 static cJSON_bool parse_object(cJSON * const item, parse_buffer * const input_buffer);
1278 static cJSON_bool print_object(const cJSON * const item, printbuffer * const output_buffer);
1341 cJSON *item = NULL;
1357 item = cJSON_New_Item(&global_hooks);
1358 if (item == NULL) /* memory fail */
1363 if (!parse_value(item, buffer_skip_whitespace(skip_utf8_bom(&buffer))))
1383 return item;
1386 if (item != NULL)
1388 cJSON_Delete(item);
1430 static unsigned char *print(const cJSON * const item, cJSON_bool format, const internal_hooks * const hooks)
1449 if (!print_value(item, buffer))
1494 /* Render a cJSON item/entity/structure to text. */
1495 CJSON_PUBLIC(char *) cJSON_Print(const cJSON *item)
1497 return (char*)print(item, true, &global_hooks);
1500 CJSON_PUBLIC(char *) cJSON_PrintUnformatted(const cJSON *item)
1502 return (char*)print(item, false, &global_hooks);
1505 CJSON_PUBLIC(char *) cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt)
1526 if (!print_value(item, &p))
1535 CJSON_PUBLIC(cJSON_bool) cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length, const cJSON_bool format)
1551 return print_value(item, &p);
1555 static cJSON_bool parse_value(cJSON * const item, parse_buffer * const input_buffer)
1566 item->type = cJSON_NULL;
1573 item->type = cJSON_False;
1580 item->type = cJSON_True;
1581 item->valueint = 1;
1588 return parse_string(item, input_buffer);
1593 return parse_number(item, input_buffer);
1598 return parse_array(item, input_buffer);
1603 return parse_object(item, input_buffer);
1610 static cJSON_bool print_value(const cJSON * const item, printbuffer * const output_buffer)
1614 if ((item == NULL) || (output_buffer == NULL))
1619 switch ((item->type) & 0xFF)
1649 return print_number(item, output_buffer);
1654 if (item->valuestring == NULL)
1659 raw_length = strlen(item->valuestring) + sizeof("");
1665 memcpy(output, item->valuestring, raw_length);
1670 return print_string(item, output_buffer);
1673 return print_array(item, output_buffer);
1676 return print_object(item, output_buffer);
1684 static cJSON_bool parse_array(cJSON * const item, parse_buffer * const input_buffer)
1721 /* allocate next item */
1728 /* attach next item to list */
1765 item->type = cJSON_Array;
1766 item->child = head;
1782 static cJSON_bool print_array(const cJSON * const item, printbuffer * const output_buffer)
1786 cJSON *current_element = item->child;
1844 static cJSON_bool parse_object(cJSON * const item, parse_buffer * const input_buffer)
1879 /* allocate next item */
1886 /* attach next item to list */
1946 item->type = cJSON_Object;
1947 item->child = head;
1962 static cJSON_bool print_object(const cJSON * const item, printbuffer * const output_buffer)
1966 cJSON *current_item = item->child;
2075 /* Get Array size/item / object item. */
2176 static void suffix_object(cJSON *prev, cJSON *item)
2178 prev->next = item;
2179 item->prev = prev;
2183 static cJSON *create_reference(const cJSON *item, const internal_hooks * const hooks)
2186 if (item == NULL)
2197 memcpy(reference, item, sizeof(cJSON));
2204 static cJSON_bool add_item_to_array(cJSON *array, cJSON *item)
2208 if ((item == NULL) || (array == NULL) || (array == item))
2215 * To find the last item in array quickly, we use prev in array
2220 array->child = item;
2221 item->prev = item;
2222 item->next = NULL;
2229 suffix_object(child->prev, item);
2230 array->child->prev = item;
2237 /* Add item to array/object. */
2238 CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToArray(cJSON *array, cJSON *item)
2240 return add_item_to_array(array, item);
2259 static cJSON_bool add_item_to_object(cJSON * const object, const char * const string, cJSON * const item, const internal_hooks * const hooks, const cJSON_bool constant_key)
2264 if ((object == NULL) || (string == NULL) || (item == NULL) || (object == item))
2272 new_type = item->type | cJSON_StringIsConst;
2282 new_type = item->type & ~cJSON_StringIsConst;
2285 if (!(item->type & cJSON_StringIsConst) && (item->string != NULL))
2287 hooks->deallocate(item->string);
2290 item->string = new_key;
2291 item->type = new_type;
2293 return add_item_to_array(object, item);
2296 CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item)
2298 return add_item_to_object(object, string, item, &global_hooks, false);
2301 /* Add an item to an object with constant string as key */
2302 CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item)
2304 return add_item_to_object(object, string, item, &global_hooks, true);
2307 CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item)
2314 return add_item_to_array(array, create_reference(item, &global_hooks));
2317 CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item)
2324 return add_item_to_object(object, string, create_reference(item, &global_hooks), &global_hooks, false);
2449 CJSON_PUBLIC(cJSON *) cJSON_DetachItemViaPointer(cJSON *parent, cJSON * const item)
2451 if ((parent == NULL) || (item == NULL) || (item != parent->child && item->prev == NULL))
2456 if (item != parent->child)
2459 item->prev->next = item->next;
2461 if (item->next != NULL)
2464 item->next->prev = item->prev;
2467 if (item == parent->child)
2470 parent->child = item->next;
2472 else if (item->next == NULL)
2475 parent->child->prev = item->prev;
2478 /* make sure the detached item doesn't point anywhere anymore */
2479 item->prev = NULL;
2480 item->next = NULL;
2482 return item;
2541 /* return false if after_inserted is a corrupted array item */
2559 CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON * const item, cJSON * replacement)
2561 if ((parent == NULL) || (parent->child == NULL) || (replacement == NULL) || (item == NULL))
2566 if (replacement == item)
2571 replacement->next = item->next;
2572 replacement->prev = item->prev;
2578 if (parent->child == item)
2588 * To find the last item in array quickly, we use prev in array.
2589 * We can't modify the last item's next pointer where this item was the parent's child
2601 item->next = NULL;
2602 item->prev = NULL;
2603 cJSON_Delete(item);
2654 cJSON *item = cJSON_New_Item(&global_hooks);
2655 if(item)
2657 item->type = cJSON_NULL;
2660 return item;
2665 cJSON *item = cJSON_New_Item(&global_hooks);
2666 if(item)
2668 item->type = cJSON_True;
2671 return item;
2676 cJSON *item = cJSON_New_Item(&global_hooks);
2677 if(item)
2679 item->type = cJSON_False;
2682 return item;
2687 cJSON *item = cJSON_New_Item(&global_hooks);
2688 if(item)
2690 item->type = boolean ? cJSON_True : cJSON_False;
2693 return item;
2699 cJSON *item = cJSON_New_Item(&global_hooks);
2700 if(item)
2702 item->type = cJSON_Number | cJSON_IsInt64;
2703 item->valueint = integer;
2704 item->valuedouble = (double)integer;
2707 return item;
2714 cJSON *item = cJSON_New_Item(&global_hooks);
2715 if(item)
2717 item->type = cJSON_Number;
2718 item->valuedouble = num;
2724 item->valueint = LLONG_MAX;
2728 item->valueint = LLONG_MIN;
2732 item->valueint = (long long)num;
2736 return item;
2741 cJSON *item = cJSON_New_Item(&global_hooks);
2742 if(item)
2744 item->type = cJSON_Number;
2745 item->valuedouble = num;
2750 item->valueint = INT_MAX;
2754 item->valueint = INT_MIN;
2758 item->valueint = (int)num;
2762 return item;
2768 cJSON *item = cJSON_New_Item(&global_hooks);
2769 if(item)
2771 item->type = cJSON_String;
2772 item->valuestring = (char*)cJSON_strdup((const unsigned char*)string, &global_hooks);
2773 if(!item->valuestring)
2775 cJSON_Delete(item);
2780 return item;
2785 cJSON *item = cJSON_New_Item(&global_hooks);
2786 if (item != NULL)
2788 item->type = cJSON_String | cJSON_IsReference;
2789 item->valuestring = (char*)cast_away_const(string);
2792 return item;
2797 cJSON *item = cJSON_New_Item(&global_hooks);
2798 if (item != NULL) {
2799 item->type = cJSON_Object | cJSON_IsReference;
2800 item->child = (cJSON*)cast_away_const(child);
2803 return item;
2807 cJSON *item = cJSON_New_Item(&global_hooks);
2808 if (item != NULL) {
2809 item->type = cJSON_Array | cJSON_IsReference;
2810 item->child = (cJSON*)cast_away_const(child);
2813 return item;
2818 cJSON *item = cJSON_New_Item(&global_hooks);
2819 if(item)
2821 item->type = cJSON_Raw;
2822 item->valuestring = (char*)cJSON_strdup((const unsigned char*)raw, &global_hooks);
2823 if(!item->valuestring)
2825 cJSON_Delete(item);
2830 return item;
2835 cJSON *item = cJSON_New_Item(&global_hooks);
2836 if(item)
2838 item->type=cJSON_Array;
2841 return item;
2846 cJSON *item = cJSON_New_Item(&global_hooks);
2847 if (item)
2849 item->type = cJSON_Object;
2852 return item;
3017 CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *item, cJSON_bool recurse)
3025 if (!item)
3029 /* Create new item */
3036 newitem->type = item->type & (~cJSON_IsReference);
3037 newitem->valueint = item->valueint;
3038 newitem->valuedouble = item->valuedouble;
3039 if (item->valuestring)
3041 newitem->valuestring = (char*)cJSON_strdup((unsigned char*)item->valuestring, &global_hooks);
3047 if (item->string)
3049 newitem->string = (item->type&cJSON_StringIsConst) ? item->string : (char*)cJSON_strdup((unsigned char*)item->string, &global_hooks);
3061 child = item->child;
3064 newchild = cJSON_Duplicate(child, true); /* Duplicate (with recurse) each item in the ->next chain */
3197 CJSON_PUBLIC(cJSON_bool) cJSON_IsInvalid(const cJSON * const item)
3199 if (item == NULL)
3204 return (item->type & 0xFF) == cJSON_Invalid;
3207 CJSON_PUBLIC(cJSON_bool) cJSON_IsFalse(const cJSON * const item)
3209 if (item == NULL)
3214 return (item->type & 0xFF) == cJSON_False;
3217 CJSON_PUBLIC(cJSON_bool) cJSON_IsTrue(const cJSON * const item)
3219 if (item == NULL)
3224 return (item->type & 0xff) == cJSON_True;
3228 CJSON_PUBLIC(cJSON_bool) cJSON_IsBool(const cJSON * const item)
3230 if (item == NULL)
3235 return (item->type & (cJSON_True | cJSON_False)) != 0;
3237 CJSON_PUBLIC(cJSON_bool) cJSON_IsNull(const cJSON * const item)
3239 if (item == NULL)
3244 return (item->type & 0xFF) == cJSON_NULL;
3248 CJSON_PUBLIC(cJSON_bool) cJSON_IsInt64Number(const cJSON * const item)
3250 if (item == NULL)
3255 return cJSON_IsNumber(item) && (item->type & cJSON_IsInt64);
3259 CJSON_PUBLIC(cJSON_bool) cJSON_IsNumber(const cJSON * const item)
3261 if (item == NULL)
3266 return (item->type & 0xFF) == cJSON_Number;
3269 CJSON_PUBLIC(cJSON_bool) cJSON_IsString(const cJSON * const item)
3271 if (item == NULL)
3276 return (item->type & 0xFF) == cJSON_String;
3279 CJSON_PUBLIC(cJSON_bool) cJSON_IsArray(const cJSON * const item)
3281 if (item == NULL)
3286 return (item->type & 0xFF) == cJSON_Array;
3289 CJSON_PUBLIC(cJSON_bool) cJSON_IsObject(const cJSON * const item)
3291 if (item == NULL)
3296 return (item->type & 0xFF) == cJSON_Object;
3299 CJSON_PUBLIC(cJSON_bool) cJSON_IsRaw(const cJSON * const item)
3301 if (item == NULL)
3306 return (item->type & 0xFF) == cJSON_Raw;