Lines Matching +full:copy +full:- +full:item
2 Copyright (c) 2009-2017 Dave Gamble and cJSON contributors
4 Permission is hereby granted, free of charge, to any person obtaining a copy
7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
78 #define isinf(d) (isnan((d - d)) && !isnan(d))
98 #define LLONG_MIN (-LLONG_MAX - 1LL)
106 CJSON_PUBLIC(char *) cJSON_GetStringValue(cJSON *item) in cJSON_GetStringValue() argument
108 if (!cJSON_IsString(item)) in cJSON_GetStringValue()
113 return item->valuestring; in cJSON_GetStringValue()
116 CJSON_PUBLIC(double) cJSON_GetNumberValue(cJSON *item) in cJSON_GetNumberValue() argument
118 if (!cJSON_IsNumber(item)) in cJSON_GetNumberValue()
123 return item->valuedouble; in cJSON_GetNumberValue()
126 /* This is a safeguard to prevent copy-pasters from using incompatible C and header files */
160 return tolower(*string1) - tolower(*string2); in case_insensitive_strcmp()
191 #define static_strlen(string_literal) (sizeof(string_literal) - sizeof(""))
198 unsigned char *copy = NULL; in cJSON_strdup() local
206 copy = (unsigned char*)hooks->allocate(length); in cJSON_strdup()
207 if (copy == NULL) in cJSON_strdup()
211 memcpy(copy, string, length); in cJSON_strdup()
213 return copy; in cJSON_strdup()
228 if (hooks->malloc_fn != NULL) in cJSON_InitHooks()
230 global_hooks.allocate = hooks->malloc_fn; in cJSON_InitHooks()
234 if (hooks->free_fn != NULL) in cJSON_InitHooks()
236 global_hooks.deallocate = hooks->free_fn; in cJSON_InitHooks()
250 cJSON* node = (cJSON*)hooks->allocate(sizeof(cJSON)); in cJSON_New_Item()
260 CJSON_PUBLIC(void) cJSON_Delete(cJSON *item) in cJSON_Delete() argument
263 while (item != NULL) in cJSON_Delete()
265 next = item->next; in cJSON_Delete()
266 if (!(item->type & cJSON_IsReference) && (item->child != NULL)) in cJSON_Delete()
268 cJSON_Delete(item->child); in cJSON_Delete()
270 if (!(item->type & cJSON_IsReference) && (item->valuestring != NULL)) in cJSON_Delete()
272 global_hooks.deallocate(item->valuestring); in cJSON_Delete()
274 if (!(item->type & cJSON_StringIsConst) && (item->string != NULL)) in cJSON_Delete()
276 global_hooks.deallocate(item->string); in cJSON_Delete()
278 global_hooks.deallocate(item); in cJSON_Delete()
279 item = next; in cJSON_Delete()
288 return (unsigned char) lconv->decimal_point[0]; in get_decimal_point()
304 #define can_read(buffer, size) ((buffer != NULL) && (((buffer)->offset + size) <= (buffer)->length))
306 …access_at_index(buffer, index) ((buffer != NULL) && (((buffer)->offset + index) < (buffer)->length…
309 #define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset)
311 /* Parse the input text to generate a number, and populate the result into item. */
312 static cJSON_bool parse_number(cJSON * const item, parse_buffer * const input_buffer) in parse_number() argument
320 if ((input_buffer == NULL) || (input_buffer->content == NULL)) in parse_number()
325 /* copy the number into a temporary buffer and replace '.' with the decimal point in parse_number()
328 for (i = 0; (i < (sizeof(number_c_string) - 1)) && can_access_at_index(input_buffer, i); i++) in parse_number()
343 case '-': in parse_number()
366 item->valuedouble = number; in parse_number()
371 item->valueint = LLONG_MAX; in parse_number()
375 item->valueint = LLONG_MIN; in parse_number()
379 item->valueint = (int64_t)number; in parse_number()
382 item->type = cJSON_Number; in parse_number()
384 input_buffer->offset += (size_t)(after_end - number_c_string); in parse_number()
393 object->valueint = LLONG_MAX; in cJSON_SetNumberHelper()
397 object->valueint = LLONG_MIN; in cJSON_SetNumberHelper()
401 object->valueint = (int64_t)number; in cJSON_SetNumberHelper()
404 return object->valuedouble = number; in cJSON_SetNumberHelper()
409 char *copy = NULL; in cJSON_SetValuestring() local
411 if (!(object->type & cJSON_String) || (object->type & cJSON_IsReference)) in cJSON_SetValuestring()
415 if (strlen(valuestring) <= strlen(object->valuestring)) in cJSON_SetValuestring()
417 strcpy(object->valuestring, valuestring); in cJSON_SetValuestring()
418 return object->valuestring; in cJSON_SetValuestring()
420 copy = (char*) cJSON_strdup((const unsigned char*)valuestring, &global_hooks); in cJSON_SetValuestring()
421 if (copy == NULL) in cJSON_SetValuestring()
425 if (object->valuestring != NULL) in cJSON_SetValuestring()
427 cJSON_free(object->valuestring); in cJSON_SetValuestring()
429 object->valuestring = copy; in cJSON_SetValuestring()
431 return copy; in cJSON_SetValuestring()
451 if ((p == NULL) || (p->buffer == NULL)) in ensure()
456 if ((p->length > 0) && (p->offset >= p->length)) in ensure()
468 needed += p->offset + 1; in ensure()
469 if (needed <= p->length) in ensure()
471 return p->buffer + p->offset; in ensure()
474 if (p->noalloc) { in ensure()
496 if (p->hooks.reallocate != NULL) in ensure()
499 newbuffer = (unsigned char*)p->hooks.reallocate(p->buffer, newsize); in ensure()
502 p->hooks.deallocate(p->buffer); in ensure()
503 p->length = 0; in ensure()
504 p->buffer = NULL; in ensure()
512 newbuffer = (unsigned char*)p->hooks.allocate(newsize); in ensure()
515 p->hooks.deallocate(p->buffer); in ensure()
516 p->length = 0; in ensure()
517 p->buffer = NULL; in ensure()
523 memcpy(newbuffer, p->buffer, p->offset + 1); in ensure()
525 p->hooks.deallocate(p->buffer); in ensure()
527 p->length = newsize; in ensure()
528 p->buffer = newbuffer; in ensure()
530 return newbuffer + p->offset; in ensure()
537 if ((buffer == NULL) || (buffer->buffer == NULL)) in update_offset()
541 buffer_pointer = buffer->buffer + buffer->offset; in update_offset()
543 buffer->offset += strlen((const char*)buffer_pointer); in update_offset()
546 /* securely comparison of floating-point variables */
550 return (fabs(a - b) <= maxVal * DBL_EPSILON); in compare_double()
553 /* Render the number nicely from the given item into a string. */
554 static cJSON_bool print_number(const cJSON * const item, printbuffer * const output_buffer) in print_number() argument
557 double d = item->valuedouble; in print_number()
588 if ((length < 0) || (length > (int)(sizeof(number_buffer) - 1))) in print_number()
600 /* copy the printed number to the output and replace locale in print_number()
614 output_buffer->offset += (size_t)length; in print_number()
630 h += (unsigned int) input[i] - '0'; in parse_hex4()
634 h += (unsigned int) 10 + input[i] - 'A'; in parse_hex4()
638 h += (unsigned int) 10 + input[i] - 'a'; in parse_hex4()
655 /* converts a UTF-16 literal to UTF-8
667 if ((input_end - first_sequence) < 6) in utf16_literal_to_utf8()
689 if ((input_end - second_sequence) < 6) in utf16_literal_to_utf8()
720 /* encode as UTF-8 in utf16_literal_to_utf8()
753 for (utf8_position = (unsigned char)(utf8_length - 1); utf8_position > 0; utf8_position--) in utf16_literal_to_utf8()
777 /* Parse the input text into an unescaped cinput, and populate item. */
778 static cJSON_bool parse_string(cJSON * const item, parse_buffer * const input_buffer) in parse_string() argument
795 …while (((size_t)(input_end - input_buffer->content) < input_buffer->length) && (*input_end != '\"'… in parse_string()
800 if ((size_t)(input_end + 1 - input_buffer->content) >= input_buffer->length) in parse_string()
810 … if (((size_t)(input_end - input_buffer->content) >= input_buffer->length) || (*input_end != '\"')) in parse_string()
816 allocation_length = (size_t) (input_end - buffer_at_offset(input_buffer)) - skipped_bytes; in parse_string()
817 output = (unsigned char*)input_buffer->hooks.allocate(allocation_length + sizeof("")); in parse_string()
836 if ((input_end - input_pointer) < 1) in parse_string()
864 /* UTF-16 literal */ in parse_string()
869 /* failed to convert UTF16-literal to UTF-8 */ in parse_string()
884 item->type = cJSON_String; in parse_string()
885 item->valuestring = (char*)output; in parse_string()
887 input_buffer->offset = (size_t) (input_end - input_buffer->content); in parse_string()
888 input_buffer->offset++; in parse_string()
895 input_buffer->hooks.deallocate(output); in parse_string()
900 input_buffer->offset = (size_t)(input_pointer - input_buffer->content); in parse_string()
952 /* UTF-16 escape sequence uXXXX */ in print_string_ptr()
958 output_length = (size_t)(input_pointer - input) + escape_characters; in print_string_ptr()
979 /* copy the string */ in print_string_ptr()
984 /* normal character, copy */ in print_string_ptr()
1028 /* Invoke print_string_ptr (which is useful) on an item. */
1029 static cJSON_bool print_string(const cJSON * const item, printbuffer * const p) in print_string() argument
1031 return print_string_ptr((unsigned char*)item->valuestring, p); in print_string()
1035 static cJSON_bool parse_value(cJSON * const item, parse_buffer * const input_buffer);
1036 static cJSON_bool print_value(const cJSON * const item, printbuffer * const output_buffer);
1037 static cJSON_bool parse_array(cJSON * const item, parse_buffer * const input_buffer);
1038 static cJSON_bool print_array(const cJSON * const item, printbuffer * const output_buffer);
1039 static cJSON_bool parse_object(cJSON * const item, parse_buffer * const input_buffer);
1040 static cJSON_bool print_object(const cJSON * const item, printbuffer * const output_buffer);
1045 if ((buffer == NULL) || (buffer->content == NULL)) in buffer_skip_whitespace()
1057 buffer->offset++; in buffer_skip_whitespace()
1060 if (buffer->offset == buffer->length) in buffer_skip_whitespace()
1062 buffer->offset--; in buffer_skip_whitespace()
1068 /* skip the UTF-8 BOM (byte order mark) if it is at the beginning of a buffer */
1071 if ((buffer == NULL) || (buffer->content == NULL) || (buffer->offset != 0)) in skip_utf8_bom()
1078 buffer->offset += 3; in skip_utf8_bom()
1099 /* Parse an object - create a new root, and populate. */
1103 cJSON *item = NULL; in cJSON_ParseWithLengthOpts() local
1119 item = cJSON_New_Item(&global_hooks); in cJSON_ParseWithLengthOpts()
1120 if (item == NULL) /* memory fail */ in cJSON_ParseWithLengthOpts()
1125 if (!parse_value(item, buffer_skip_whitespace(skip_utf8_bom(&buffer)))) in cJSON_ParseWithLengthOpts()
1131 …/* if we require null-terminated JSON without appended garbage, skip and then check for a null ter… in cJSON_ParseWithLengthOpts()
1145 return item; in cJSON_ParseWithLengthOpts()
1148 if (item != NULL) in cJSON_ParseWithLengthOpts()
1150 cJSON_Delete(item); in cJSON_ParseWithLengthOpts()
1165 local_error.position = buffer.length - 1; in cJSON_ParseWithLengthOpts()
1192 static unsigned char *print(const cJSON * const item, cJSON_bool format, const internal_hooks * con… in print() argument
1201 buffer->buffer = (unsigned char*) hooks->allocate(default_buffer_size); in print()
1202 buffer->length = default_buffer_size; in print()
1203 buffer->format = format; in print()
1204 buffer->hooks = *hooks; in print()
1205 if (buffer->buffer == NULL) in print()
1211 if (!print_value(item, buffer)) in print()
1218 if (hooks->reallocate != NULL) in print()
1220 printed = (unsigned char*) hooks->reallocate(buffer->buffer, buffer->offset + 1); in print()
1224 buffer->buffer = NULL; in print()
1226 else /* otherwise copy the JSON over to a new buffer */ in print()
1228 printed = (unsigned char*) hooks->allocate(buffer->offset + 1); in print()
1233 memcpy(printed, buffer->buffer, cjson_min(buffer->length, buffer->offset + 1)); in print()
1234 printed[buffer->offset] = '\0'; /* just to be sure */ in print()
1237 hooks->deallocate(buffer->buffer); in print()
1243 if (buffer->buffer != NULL) in print()
1245 hooks->deallocate(buffer->buffer); in print()
1250 hooks->deallocate(printed); in print()
1256 /* Render a cJSON item/entity/structure to text. */
1257 CJSON_PUBLIC(char *) cJSON_Print(const cJSON *item) in cJSON_Print() argument
1259 return (char*)print(item, true, &global_hooks); in cJSON_Print()
1262 CJSON_PUBLIC(char *) cJSON_PrintUnformatted(const cJSON *item) in cJSON_PrintUnformatted() argument
1264 return (char*)print(item, false, &global_hooks); in cJSON_PrintUnformatted()
1267 CJSON_PUBLIC(char *) cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt) in cJSON_PrintBuffered() argument
1288 if (!print_value(item, &p)) in cJSON_PrintBuffered()
1297 CJSON_PUBLIC(cJSON_bool) cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length, const… in cJSON_PrintPreallocated() argument
1313 return print_value(item, &p); in cJSON_PrintPreallocated()
1316 /* Parser core - when encountering text, process appropriately. */
1317 static cJSON_bool parse_value(cJSON * const item, parse_buffer * const input_buffer) in parse_value() argument
1319 if ((input_buffer == NULL) || (input_buffer->content == NULL)) in parse_value()
1328 item->type = cJSON_NULL; in parse_value()
1329 input_buffer->offset += 4; in parse_value()
1335 item->type = cJSON_False; in parse_value()
1336 input_buffer->offset += 5; in parse_value()
1342 item->type = cJSON_True; in parse_value()
1343 item->valueint = 1; in parse_value()
1344 input_buffer->offset += 4; in parse_value()
1350 return parse_string(item, input_buffer); in parse_value()
1353 …if (can_access_at_index(input_buffer, 0) && ((buffer_at_offset(input_buffer)[0] == '-') || ((buffe… in parse_value()
1355 return parse_number(item, input_buffer); in parse_value()
1360 return parse_array(item, input_buffer); in parse_value()
1365 return parse_object(item, input_buffer); in parse_value()
1372 static cJSON_bool print_value(const cJSON * const item, printbuffer * const output_buffer) in print_value() argument
1376 if ((item == NULL) || (output_buffer == NULL)) in print_value()
1381 switch ((item->type) & 0xFF) in print_value()
1411 return print_number(item, output_buffer); in print_value()
1416 if (item->valuestring == NULL) in print_value()
1421 raw_length = strlen(item->valuestring) + sizeof(""); in print_value()
1427 memcpy(output, item->valuestring, raw_length); in print_value()
1432 return print_string(item, output_buffer); in print_value()
1435 return print_array(item, output_buffer); in print_value()
1438 return print_object(item, output_buffer); in print_value()
1446 static cJSON_bool parse_array(cJSON * const item, parse_buffer * const input_buffer) in parse_array() argument
1451 if (input_buffer->depth >= CJSON_NESTING_LIMIT) in parse_array()
1455 input_buffer->depth++; in parse_array()
1463 input_buffer->offset++; in parse_array()
1474 input_buffer->offset--; in parse_array()
1479 input_buffer->offset--; in parse_array()
1483 /* allocate next item */ in parse_array()
1484 cJSON *new_item = cJSON_New_Item(&(input_buffer->hooks)); in parse_array()
1490 /* attach next item to list */ in parse_array()
1499 current_item->next = new_item; in parse_array()
1500 new_item->prev = current_item; in parse_array()
1505 input_buffer->offset++; in parse_array()
1521 input_buffer->depth--; in parse_array()
1523 item->type = cJSON_Array; in parse_array()
1524 item->child = head; in parse_array()
1526 input_buffer->offset++; in parse_array()
1540 static cJSON_bool print_array(const cJSON * const item, printbuffer * const output_buffer) in print_array() argument
1544 cJSON *current_element = item->child; in print_array()
1560 output_buffer->offset++; in print_array()
1561 output_buffer->depth++; in print_array()
1570 if (current_element->next) in print_array()
1572 length = (size_t) (output_buffer->format ? 2 : 1); in print_array()
1579 if(output_buffer->format) in print_array()
1584 output_buffer->offset += length; in print_array()
1586 current_element = current_element->next; in print_array()
1596 output_buffer->depth--; in print_array()
1602 static cJSON_bool parse_object(cJSON * const item, parse_buffer * const input_buffer) in parse_object() argument
1607 if (input_buffer->depth >= CJSON_NESTING_LIMIT) in parse_object()
1611 input_buffer->depth++; in parse_object()
1618 input_buffer->offset++; in parse_object()
1628 input_buffer->offset--; in parse_object()
1633 input_buffer->offset--; in parse_object()
1637 /* allocate next item */ in parse_object()
1638 cJSON *new_item = cJSON_New_Item(&(input_buffer->hooks)); in parse_object()
1644 /* attach next item to list */ in parse_object()
1653 current_item->next = new_item; in parse_object()
1654 new_item->prev = current_item; in parse_object()
1659 input_buffer->offset++; in parse_object()
1668 current_item->string = current_item->valuestring; in parse_object()
1669 current_item->valuestring = NULL; in parse_object()
1677 input_buffer->offset++; in parse_object()
1693 input_buffer->depth--; in parse_object()
1695 item->type = cJSON_Object; in parse_object()
1696 item->child = head; in parse_object()
1698 input_buffer->offset++; in parse_object()
1711 static cJSON_bool print_object(const cJSON * const item, printbuffer * const output_buffer) in print_object() argument
1715 cJSON *current_item = item->child; in print_object()
1723 length = (size_t) (output_buffer->format ? 2 : 1); /* fmt: {\n */ in print_object()
1731 output_buffer->depth++; in print_object()
1732 if (output_buffer->format) in print_object()
1736 output_buffer->offset += length; in print_object()
1740 if (output_buffer->format) in print_object()
1743 output_pointer = ensure(output_buffer, output_buffer->depth); in print_object()
1748 for (i = 0; i < output_buffer->depth; i++) in print_object()
1752 output_buffer->offset += output_buffer->depth; in print_object()
1756 if (!print_string_ptr((unsigned char*)current_item->string, output_buffer)) in print_object()
1762 length = (size_t) (output_buffer->format ? 2 : 1); in print_object()
1769 if (output_buffer->format) in print_object()
1773 output_buffer->offset += length; in print_object()
1783 length = ((size_t)(output_buffer->format ? 1 : 0) + (size_t)(current_item->next ? 1 : 0)); in print_object()
1789 if (current_item->next) in print_object()
1794 if (output_buffer->format) in print_object()
1799 output_buffer->offset += length; in print_object()
1801 current_item = current_item->next; in print_object()
1804 output_pointer = ensure(output_buffer, output_buffer->format ? (output_buffer->depth + 1) : 2); in print_object()
1809 if (output_buffer->format) in print_object()
1812 for (i = 0; i < (output_buffer->depth - 1); i++) in print_object()
1819 output_buffer->depth--; in print_object()
1824 /* Get Array size/item / object item. */
1835 child = array->child; in cJSON_GetArraySize()
1840 child = child->next; in cJSON_GetArraySize()
1857 current_child = array->child; in get_array_item()
1860 index--; in get_array_item()
1861 current_child = current_child->next; in get_array_item()
1886 current_element = object->child; in get_object_item()
1889 …hile ((current_element != NULL) && (current_element->string != NULL) && (strcmp(name, current_elem… in get_object_item()
1891 current_element = current_element->next; in get_object_item()
1896 …ensitive_strcmp((const unsigned char*)name, (const unsigned char*)(current_element->string)) != 0)) in get_object_item()
1898 current_element = current_element->next; in get_object_item()
1902 if ((current_element == NULL) || (current_element->string == NULL)) { in get_object_item()
1925 static void suffix_object(cJSON *prev, cJSON *item) in suffix_object() argument
1927 prev->next = item; in suffix_object()
1928 item->prev = prev; in suffix_object()
1932 static cJSON *create_reference(const cJSON *item, const internal_hooks * const hooks) in create_reference() argument
1935 if (item == NULL) in create_reference()
1946 memcpy(reference, item, sizeof(cJSON)); in create_reference()
1947 reference->string = NULL; in create_reference()
1948 reference->type |= cJSON_IsReference; in create_reference()
1949 reference->next = reference->prev = NULL; in create_reference()
1953 static cJSON_bool add_item_to_array(cJSON *array, cJSON *item) in add_item_to_array() argument
1957 if ((item == NULL) || (array == NULL) || (array == item)) in add_item_to_array()
1962 child = array->child; in add_item_to_array()
1964 * To find the last item in array quickly, we use prev in array in add_item_to_array()
1969 array->child = item; in add_item_to_array()
1970 item->prev = item; in add_item_to_array()
1971 item->next = NULL; in add_item_to_array()
1976 if (child->prev) in add_item_to_array()
1978 suffix_object(child->prev, item); in add_item_to_array()
1979 array->child->prev = item; in add_item_to_array()
1983 while (child->next) in add_item_to_array()
1985 child = child->next; in add_item_to_array()
1987 suffix_object(child, item); in add_item_to_array()
1988 array->child->prev = item; in add_item_to_array()
1995 /* Add item to array/object. */
1996 CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToArray(cJSON *array, cJSON *item) in cJSON_AddItemToArray() argument
1998 return add_item_to_array(array, item); in cJSON_AddItemToArray()
2005 #pragma GCC diagnostic ignored "-Wcast-qual"
2017 …_to_object(cJSON * const object, const char * const string, cJSON * const item, const internal_hoo… in add_item_to_object() argument
2022 if ((object == NULL) || (string == NULL) || (item == NULL) || (object == item)) in add_item_to_object()
2030 new_type = item->type | cJSON_StringIsConst; in add_item_to_object()
2040 new_type = item->type & ~cJSON_StringIsConst; in add_item_to_object()
2043 if (!(item->type & cJSON_StringIsConst) && (item->string != NULL)) in add_item_to_object()
2045 hooks->deallocate(item->string); in add_item_to_object()
2048 item->string = new_key; in add_item_to_object()
2049 item->type = new_type; in add_item_to_object()
2051 return add_item_to_array(object, item); in add_item_to_object()
2054 CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item) in cJSON_AddItemToObject() argument
2056 return add_item_to_object(object, string, item, &global_hooks, false); in cJSON_AddItemToObject()
2059 /* Add an item to an object with constant string as key */
2060 CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item) in cJSON_AddItemToObjectCS() argument
2062 return add_item_to_object(object, string, item, &global_hooks, true); in cJSON_AddItemToObjectCS()
2065 CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item) in cJSON_AddItemReferenceToArray() argument
2072 return add_item_to_array(array, create_reference(item, &global_hooks)); in cJSON_AddItemReferenceToArray()
2075 …N_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item) in cJSON_AddItemReferenceToObject() argument
2082 …return add_item_to_object(object, string, create_reference(item, &global_hooks), &global_hooks, fa… in cJSON_AddItemReferenceToObject()
2193 CJSON_PUBLIC(cJSON *) cJSON_DetachItemViaPointer(cJSON *parent, cJSON * const item) in cJSON_DetachItemViaPointer() argument
2195 if ((parent == NULL) || (item == NULL)) in cJSON_DetachItemViaPointer()
2200 if (item != parent->child) in cJSON_DetachItemViaPointer()
2203 item->prev->next = item->next; in cJSON_DetachItemViaPointer()
2205 if (item->next != NULL) in cJSON_DetachItemViaPointer()
2208 item->next->prev = item->prev; in cJSON_DetachItemViaPointer()
2211 if (item == parent->child) in cJSON_DetachItemViaPointer()
2214 parent->child = item->next; in cJSON_DetachItemViaPointer()
2216 /* make sure the detached item doesn't point anywhere anymore */ in cJSON_DetachItemViaPointer()
2217 item->prev = NULL; in cJSON_DetachItemViaPointer()
2218 item->next = NULL; in cJSON_DetachItemViaPointer()
2220 return item; in cJSON_DetachItemViaPointer()
2278 newitem->next = after_inserted; in cJSON_InsertItemInArray()
2279 newitem->prev = after_inserted->prev; in cJSON_InsertItemInArray()
2280 after_inserted->prev = newitem; in cJSON_InsertItemInArray()
2281 if (after_inserted == array->child) in cJSON_InsertItemInArray()
2283 array->child = newitem; in cJSON_InsertItemInArray()
2287 newitem->prev->next = newitem; in cJSON_InsertItemInArray()
2292 CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON * const item, cJSO… in cJSON_ReplaceItemViaPointer() argument
2294 if ((parent == NULL) || (replacement == NULL) || (item == NULL)) in cJSON_ReplaceItemViaPointer()
2299 if (replacement == item) in cJSON_ReplaceItemViaPointer()
2304 replacement->next = item->next; in cJSON_ReplaceItemViaPointer()
2305 replacement->prev = item->prev; in cJSON_ReplaceItemViaPointer()
2307 if (replacement->next != NULL) in cJSON_ReplaceItemViaPointer()
2309 replacement->next->prev = replacement; in cJSON_ReplaceItemViaPointer()
2311 if (parent->child == item) in cJSON_ReplaceItemViaPointer()
2313 parent->child = replacement; in cJSON_ReplaceItemViaPointer()
2317 * To find the last item in array quickly, we use prev in array. in cJSON_ReplaceItemViaPointer()
2318 * We can't modify the last item's next pointer where this item was the parent's child in cJSON_ReplaceItemViaPointer()
2320 if (replacement->prev != NULL) in cJSON_ReplaceItemViaPointer()
2322 replacement->prev->next = replacement; in cJSON_ReplaceItemViaPointer()
2326 item->next = NULL; in cJSON_ReplaceItemViaPointer()
2327 item->prev = NULL; in cJSON_ReplaceItemViaPointer()
2328 cJSON_Delete(item); in cJSON_ReplaceItemViaPointer()
2351 if (!(replacement->type & cJSON_StringIsConst) && (replacement->string != NULL)) in replace_item_in_object()
2353 cJSON_free(replacement->string); in replace_item_in_object()
2355 replacement->string = (char*)cJSON_strdup((const unsigned char*)string, &global_hooks); in replace_item_in_object()
2356 replacement->type &= ~cJSON_StringIsConst; in replace_item_in_object()
2374 cJSON *item = cJSON_New_Item(&global_hooks); in cJSON_CreateNull() local
2375 if(item) in cJSON_CreateNull()
2377 item->type = cJSON_NULL; in cJSON_CreateNull()
2380 return item; in cJSON_CreateNull()
2385 cJSON *item = cJSON_New_Item(&global_hooks); in cJSON_CreateTrue() local
2386 if(item) in cJSON_CreateTrue()
2388 item->type = cJSON_True; in cJSON_CreateTrue()
2391 return item; in cJSON_CreateTrue()
2396 cJSON *item = cJSON_New_Item(&global_hooks); in cJSON_CreateFalse() local
2397 if(item) in cJSON_CreateFalse()
2399 item->type = cJSON_False; in cJSON_CreateFalse()
2402 return item; in cJSON_CreateFalse()
2407 cJSON *item = cJSON_New_Item(&global_hooks); in cJSON_CreateBool() local
2408 if(item) in cJSON_CreateBool()
2410 item->type = boolean ? cJSON_True : cJSON_False; in cJSON_CreateBool()
2413 return item; in cJSON_CreateBool()
2418 cJSON *item = cJSON_New_Item(&global_hooks); in cJSON_CreateNumber() local
2419 if(item) in cJSON_CreateNumber()
2421 item->type = cJSON_Number; in cJSON_CreateNumber()
2422 item->valuedouble = num; in cJSON_CreateNumber()
2427 item->valueint = LLONG_MAX; in cJSON_CreateNumber()
2431 item->valueint = LLONG_MIN; in cJSON_CreateNumber()
2435 item->valueint = (int64_t)num; in cJSON_CreateNumber()
2439 return item; in cJSON_CreateNumber()
2444 cJSON *item = cJSON_New_Item(&global_hooks); in cJSON_CreateString() local
2445 if(item) in cJSON_CreateString()
2447 item->type = cJSON_String; in cJSON_CreateString()
2448 item->valuestring = (char*)cJSON_strdup((const unsigned char*)string, &global_hooks); in cJSON_CreateString()
2449 if(!item->valuestring) in cJSON_CreateString()
2451 cJSON_Delete(item); in cJSON_CreateString()
2456 return item; in cJSON_CreateString()
2461 cJSON *item = cJSON_New_Item(&global_hooks); in cJSON_CreateStringReference() local
2462 if (item != NULL) in cJSON_CreateStringReference()
2464 item->type = cJSON_String | cJSON_IsReference; in cJSON_CreateStringReference()
2465 item->valuestring = (char*)cast_away_const(string); in cJSON_CreateStringReference()
2468 return item; in cJSON_CreateStringReference()
2473 cJSON *item = cJSON_New_Item(&global_hooks); in cJSON_CreateObjectReference() local
2474 if (item != NULL) { in cJSON_CreateObjectReference()
2475 item->type = cJSON_Object | cJSON_IsReference; in cJSON_CreateObjectReference()
2476 item->child = (cJSON*)cast_away_const(child); in cJSON_CreateObjectReference()
2479 return item; in cJSON_CreateObjectReference()
2483 cJSON *item = cJSON_New_Item(&global_hooks); in cJSON_CreateArrayReference() local
2484 if (item != NULL) { in cJSON_CreateArrayReference()
2485 item->type = cJSON_Array | cJSON_IsReference; in cJSON_CreateArrayReference()
2486 item->child = (cJSON*)cast_away_const(child); in cJSON_CreateArrayReference()
2489 return item; in cJSON_CreateArrayReference()
2494 cJSON *item = cJSON_New_Item(&global_hooks); in cJSON_CreateRaw() local
2495 if(item) in cJSON_CreateRaw()
2497 item->type = cJSON_Raw; in cJSON_CreateRaw()
2498 item->valuestring = (char*)cJSON_strdup((const unsigned char*)raw, &global_hooks); in cJSON_CreateRaw()
2499 if(!item->valuestring) in cJSON_CreateRaw()
2501 cJSON_Delete(item); in cJSON_CreateRaw()
2506 return item; in cJSON_CreateRaw()
2511 cJSON *item = cJSON_New_Item(&global_hooks); in cJSON_CreateArray() local
2512 if(item) in cJSON_CreateArray()
2514 item->type=cJSON_Array; in cJSON_CreateArray()
2517 return item; in cJSON_CreateArray()
2522 cJSON *item = cJSON_New_Item(&global_hooks); in cJSON_CreateObject() local
2523 if (item) in cJSON_CreateObject()
2525 item->type = cJSON_Object; in cJSON_CreateObject()
2528 return item; in cJSON_CreateObject()
2555 a->child = n; in cJSON_CreateIntArray()
2591 a->child = n; in cJSON_CreateFloatArray()
2627 a->child = n; in cJSON_CreateDoubleArray()
2663 a->child = n; in cJSON_CreateStringArray()
2676 CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *item, cJSON_bool recurse) in cJSON_Duplicate() argument
2684 if (!item) in cJSON_Duplicate()
2688 /* Create new item */ in cJSON_Duplicate()
2694 /* Copy over all vars */ in cJSON_Duplicate()
2695 newitem->type = item->type & (~cJSON_IsReference); in cJSON_Duplicate()
2696 newitem->valueint = item->valueint; in cJSON_Duplicate()
2697 newitem->valuedouble = item->valuedouble; in cJSON_Duplicate()
2698 if (item->valuestring) in cJSON_Duplicate()
2700 … newitem->valuestring = (char*)cJSON_strdup((unsigned char*)item->valuestring, &global_hooks); in cJSON_Duplicate()
2701 if (!newitem->valuestring) in cJSON_Duplicate()
2706 if (item->string) in cJSON_Duplicate()
2708 …newitem->string = (item->type&cJSON_StringIsConst) ? item->string : (char*)cJSON_strdup((unsigned … in cJSON_Duplicate()
2709 if (!newitem->string) in cJSON_Duplicate()
2714 /* If non-recursive, then we're done! */ in cJSON_Duplicate()
2719 /* Walk the ->next chain for the child. */ in cJSON_Duplicate()
2720 child = item->child; in cJSON_Duplicate()
2723 …newchild = cJSON_Duplicate(child, true); /* Duplicate (with recurse) each item in the ->next chain… in cJSON_Duplicate()
2730 /* If newitem->child already set, then crosswire ->prev and ->next and move on */ in cJSON_Duplicate()
2731 next->next = newchild; in cJSON_Duplicate()
2732 newchild->prev = next; in cJSON_Duplicate()
2737 /* Set newitem->child and move to it */ in cJSON_Duplicate()
2738 newitem->child = newchild; in cJSON_Duplicate()
2741 child = child->next; in cJSON_Duplicate()
2848 /* and null-terminate. */ in cJSON_Minify()
2852 CJSON_PUBLIC(cJSON_bool) cJSON_IsInvalid(const cJSON * const item) in cJSON_IsInvalid() argument
2854 if (item == NULL) in cJSON_IsInvalid()
2859 return (item->type & 0xFF) == cJSON_Invalid; in cJSON_IsInvalid()
2862 CJSON_PUBLIC(cJSON_bool) cJSON_IsFalse(const cJSON * const item) in cJSON_IsFalse() argument
2864 if (item == NULL) in cJSON_IsFalse()
2869 return (item->type & 0xFF) == cJSON_False; in cJSON_IsFalse()
2872 CJSON_PUBLIC(cJSON_bool) cJSON_IsTrue(const cJSON * const item) in cJSON_IsTrue() argument
2874 if (item == NULL) in cJSON_IsTrue()
2879 return (item->type & 0xff) == cJSON_True; in cJSON_IsTrue()
2883 CJSON_PUBLIC(cJSON_bool) cJSON_IsBool(const cJSON * const item) in cJSON_IsBool() argument
2885 if (item == NULL) in cJSON_IsBool()
2890 return (item->type & (cJSON_True | cJSON_False)) != 0; in cJSON_IsBool()
2892 CJSON_PUBLIC(cJSON_bool) cJSON_IsNull(const cJSON * const item) in cJSON_IsNull() argument
2894 if (item == NULL) in cJSON_IsNull()
2899 return (item->type & 0xFF) == cJSON_NULL; in cJSON_IsNull()
2902 CJSON_PUBLIC(cJSON_bool) cJSON_IsNumber(const cJSON * const item) in cJSON_IsNumber() argument
2904 if (item == NULL) in cJSON_IsNumber()
2909 return (item->type & 0xFF) == cJSON_Number; in cJSON_IsNumber()
2912 CJSON_PUBLIC(cJSON_bool) cJSON_IsString(const cJSON * const item) in cJSON_IsString() argument
2914 if (item == NULL) in cJSON_IsString()
2919 return (item->type & 0xFF) == cJSON_String; in cJSON_IsString()
2922 CJSON_PUBLIC(cJSON_bool) cJSON_IsArray(const cJSON * const item) in cJSON_IsArray() argument
2924 if (item == NULL) in cJSON_IsArray()
2929 return (item->type & 0xFF) == cJSON_Array; in cJSON_IsArray()
2932 CJSON_PUBLIC(cJSON_bool) cJSON_IsObject(const cJSON * const item) in cJSON_IsObject() argument
2934 if (item == NULL) in cJSON_IsObject()
2939 return (item->type & 0xFF) == cJSON_Object; in cJSON_IsObject()
2942 CJSON_PUBLIC(cJSON_bool) cJSON_IsRaw(const cJSON * const item) in cJSON_IsRaw() argument
2944 if (item == NULL) in cJSON_IsRaw()
2949 return (item->type & 0xFF) == cJSON_Raw; in cJSON_IsRaw()
2954 if ((a == NULL) || (b == NULL) || ((a->type & 0xFF) != (b->type & 0xFF)) || cJSON_IsInvalid(a)) in cJSON_Compare()
2960 switch (a->type & 0xFF) in cJSON_Compare()
2982 switch (a->type & 0xFF) in cJSON_Compare()
2991 if (compare_double(a->valuedouble, b->valuedouble)) in cJSON_Compare()
2999 if ((a->valuestring == NULL) || (b->valuestring == NULL)) in cJSON_Compare()
3003 if (strcmp(a->valuestring, b->valuestring) == 0) in cJSON_Compare()
3012 cJSON *a_element = a->child; in cJSON_Compare()
3013 cJSON *b_element = b->child; in cJSON_Compare()
3022 a_element = a_element->next; in cJSON_Compare()
3023 b_element = b_element->next; in cJSON_Compare()
3041 b_element = get_object_item(b, a_element->string, case_sensitive); in cJSON_Compare()
3057 a_element = get_object_item(a, b_element->string, case_sensitive); in cJSON_Compare()