27 #if !defined(_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER) 28 #define _CRT_SECURE_NO_DEPRECATE 32 #pragma GCC visibility push(default) 35 #pragma warning (push) 37 #pragma warning (disable : 4001) 55 #pragma GCC visibility pop 64 #define true ((cJSON_bool)1) 69 #define false ((cJSON_bool)0) 75 static error global_error = { NULL, 0 };
79 return (
const char*) (global_error.
json + global_error.
position);
83 if (!cJSON_IsString(item)) {
87 return item->valuestring;
91 #if (CJSON_VERSION_MAJOR != 1) || (CJSON_VERSION_MINOR != 7) || (CJSON_VERSION_PATCH != 11) 92 #error cJSON.h and cJSON.c have different versions. Make sure that both have the same. 104 static int case_insensitive_strcmp(
const unsigned char *string1,
const unsigned char *string2)
106 if ((string1 == NULL) || (string2 == NULL))
111 if (string1 == string2)
116 for(; tolower(*string1) == tolower(*string2); (void)string1++, string2++)
118 if (*string1 ==
'\0')
124 return tolower(*string1) - tolower(*string2);
131 void *(
CJSON_CDECL *reallocate)(
void *pointer,
size_t size);
134 #if defined(_MSC_VER) 146 return realloc(pointer, size);
149 #define internal_malloc malloc 150 #define internal_free free 151 #define internal_realloc realloc 155 #define static_strlen(string_literal) (sizeof(string_literal) - sizeof("")) 159 static unsigned char* cJSON_strdup(
const unsigned char*
string,
const internal_hooks *
const hooks)
162 unsigned char *copy = NULL;
169 length = strlen((
const char*)
string) +
sizeof(
"");
170 copy = (
unsigned char*)hooks->
allocate(length);
175 memcpy(copy,
string, length);
186 global_hooks.deallocate = free;
192 if (hooks->malloc_fn != NULL)
194 global_hooks.
allocate = hooks->malloc_fn;
197 global_hooks.deallocate = free;
198 if (hooks->free_fn != NULL)
200 global_hooks.deallocate = hooks->free_fn;
205 if ((global_hooks.
allocate == malloc) && (global_hooks.deallocate == free))
217 memset(node,
'\0',
sizeof(
cJSON));
232 cJSON_Delete(item->
child);
240 global_hooks.deallocate(item->
string);
242 global_hooks.deallocate(item);
248 static unsigned char get_decimal_point(
void)
250 #ifdef ENABLE_LOCALES 251 struct lconv *lconv = localeconv();
252 return (
unsigned char) lconv->decimal_point[0];
268 #define can_read(buffer, size) ((buffer != NULL) && (((buffer)->offset + size) <= (buffer)->length)) 270 #define can_access_at_index(buffer, index) ((buffer != NULL) && (((buffer)->offset + index) < (buffer)->length)) 271 #define cannot_access_at_index(buffer, index) (!can_access_at_index(buffer, index)) 273 #define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset) 279 unsigned char *after_end = NULL;
280 unsigned char number_c_string[64];
281 unsigned char decimal_point = get_decimal_point();
284 if ((input_buffer == NULL) || (input_buffer->
content == NULL))
292 for (i = 0; (i < (
sizeof(number_c_string) - 1)) &&
can_access_at_index(input_buffer, i); i++)
314 number_c_string[i] = decimal_point;
322 number_c_string[i] =
'\0';
324 number = strtod((
const char*)number_c_string, (
char**)&after_end);
325 if (number_c_string == after_end)
333 if (number >= INT_MAX)
337 else if (number <= (
double)INT_MIN)
348 input_buffer->
offset += (size_t)(after_end - number_c_string);
355 if (number >= INT_MAX)
357 object->valueint = INT_MAX;
359 else if (number <= (
double)INT_MIN)
361 object->valueint = INT_MIN;
365 object->valueint = (int)number;
368 return object->valuedouble =
number;
383 static unsigned char* ensure(
printbuffer *
const p,
size_t needed)
385 unsigned char *newbuffer = NULL;
388 if ((p == NULL) || (p->
buffer == NULL))
399 if (needed > INT_MAX)
416 if (needed > (INT_MAX / 2))
419 if (needed <= INT_MAX)
430 newsize = needed * 2;
437 if (newbuffer == NULL)
467 return newbuffer + p->
offset;
473 const unsigned char *buffer_pointer = NULL;
474 if ((buffer == NULL) || (buffer->
buffer == NULL))
480 buffer->
offset += strlen((
const char*)buffer_pointer);
486 unsigned char *output_pointer = NULL;
490 unsigned char number_buffer[26];
491 unsigned char decimal_point = get_decimal_point();
494 if (output_buffer == NULL)
502 length = sprintf((
char*)number_buffer,
"null");
507 length = sprintf((
char*)number_buffer,
"%1.15g", d);
510 if ((sscanf((
char*)number_buffer,
"%lg", &test) != 1) || ((
double)test != d))
513 length = sprintf((
char*)number_buffer,
"%1.17g", d);
518 if ((length < 0) || (length > (
int)(
sizeof(number_buffer) - 1)))
524 output_pointer = ensure(output_buffer, (
size_t)length +
sizeof(
""));
525 if (output_pointer == NULL)
532 for (i = 0; i < ((size_t)length); i++)
534 if (number_buffer[i] == decimal_point)
536 output_pointer[i] =
'.';
540 output_pointer[i] = number_buffer[i];
542 output_pointer[i] =
'\0';
544 output_buffer->
offset += (size_t)length;
550 static unsigned parse_hex4(
const unsigned char *
const input)
555 for (i = 0; i < 4; i++)
558 if ((input[i] >=
'0') && (input[i] <=
'9'))
560 h += (
unsigned int) input[i] -
'0';
562 else if ((input[i] >=
'A') && (input[i] <=
'F'))
564 h += (
unsigned int) 10 + input[i] -
'A';
566 else if ((input[i] >=
'a') && (input[i] <=
'f'))
568 h += (
unsigned int) 10 + input[i] -
'a';
587 static unsigned char utf16_literal_to_utf8(
const unsigned char *
const input_pointer,
const unsigned char *
const input_end,
unsigned char **output_pointer)
589 long unsigned int codepoint = 0;
590 unsigned int first_code = 0;
591 const unsigned char *first_sequence = input_pointer;
592 unsigned char utf8_length = 0;
593 unsigned char utf8_position = 0;
594 unsigned char sequence_length = 0;
595 unsigned char first_byte_mark = 0;
597 if ((input_end - first_sequence) < 6)
604 first_code = parse_hex4(first_sequence + 2);
607 if (((first_code >= 0xDC00) && (first_code <= 0xDFFF)))
613 if ((first_code >= 0xD800) && (first_code <= 0xDBFF))
615 const unsigned char *second_sequence = first_sequence + 6;
616 unsigned int second_code = 0;
617 sequence_length = 12;
619 if ((input_end - second_sequence) < 6)
625 if ((second_sequence[0] !=
'\\') || (second_sequence[1] !=
'u'))
632 second_code = parse_hex4(second_sequence + 2);
634 if ((second_code < 0xDC00) || (second_code > 0xDFFF))
642 codepoint = 0x10000 + (((first_code & 0x3FF) << 10) | (second_code & 0x3FF));
647 codepoint = first_code;
653 if (codepoint < 0x80)
658 else if (codepoint < 0x800)
662 first_byte_mark = 0xC0;
664 else if (codepoint < 0x10000)
668 first_byte_mark = 0xE0;
670 else if (codepoint <= 0x10FFFF)
674 first_byte_mark = 0xF0;
683 for (utf8_position = (
unsigned char)(utf8_length - 1); utf8_position > 0; utf8_position--)
686 (*output_pointer)[utf8_position] = (
unsigned char)((codepoint | 0x80) & 0xBF);
692 (*output_pointer)[0] = (
unsigned char)((codepoint | first_byte_mark) & 0xFF);
696 (*output_pointer)[0] = (
unsigned char)(codepoint & 0x7F);
699 *output_pointer += utf8_length;
701 return sequence_length;
712 unsigned char *output_pointer = NULL;
713 unsigned char *output = NULL;
723 size_t allocation_length = 0;
724 size_t skipped_bytes = 0;
725 while (((
size_t)(input_end - input_buffer->
content) < input_buffer->
length) && (*input_end !=
'\"'))
728 if (input_end[0] ==
'\\')
730 if ((
size_t)(input_end + 1 - input_buffer->
content) >= input_buffer->
length)
740 if (((
size_t)(input_end - input_buffer->
content) >= input_buffer->
length) || (*input_end !=
'\"'))
746 allocation_length = (size_t) (input_end -
buffer_at_offset(input_buffer)) - skipped_bytes;
747 output = (
unsigned char*)input_buffer->
hooks.
allocate(allocation_length +
sizeof(
""));
754 output_pointer = output;
756 while (input_pointer < input_end)
758 if (*input_pointer !=
'\\')
760 *output_pointer++ = *input_pointer++;
765 unsigned char sequence_length = 2;
766 if ((input_end - input_pointer) < 1)
771 switch (input_pointer[1])
774 *output_pointer++ =
'\b';
777 *output_pointer++ =
'\f';
780 *output_pointer++ =
'\n';
783 *output_pointer++ =
'\r';
786 *output_pointer++ =
'\t';
791 *output_pointer++ = input_pointer[1];
796 sequence_length = utf16_literal_to_utf8(input_pointer, input_end, &output_pointer);
797 if (sequence_length == 0)
807 input_pointer += sequence_length;
812 *output_pointer =
'\0';
817 input_buffer->
offset = (size_t) (input_end - input_buffer->
content);
825 input_buffer->
hooks.deallocate(output);
828 if (input_pointer != NULL)
830 input_buffer->
offset = (size_t)(input_pointer - input_buffer->
content);
837 static cJSON_bool print_string_ptr(
const unsigned char *
const input,
printbuffer *
const output_buffer)
839 const unsigned char *input_pointer = NULL;
840 unsigned char *output = NULL;
841 unsigned char *output_pointer = NULL;
842 size_t output_length = 0;
844 size_t escape_characters = 0;
846 if (output_buffer == NULL)
854 output = ensure(output_buffer,
sizeof(
"\"\""));
859 strcpy((
char*)output,
"\"\"");
865 for (input_pointer = input; *input_pointer; input_pointer++)
867 switch (*input_pointer)
880 if (*input_pointer < 32)
883 escape_characters += 5;
888 output_length = (size_t)(input_pointer - input) + escape_characters;
890 output = ensure(output_buffer, output_length +
sizeof(
"\"\""));
897 if (escape_characters == 0)
900 memcpy(output + 1, input, output_length);
901 output[output_length + 1] =
'\"';
902 output[output_length + 2] =
'\0';
908 output_pointer = output + 1;
910 for (input_pointer = input; *input_pointer !=
'\0'; (void)input_pointer++, output_pointer++)
912 if ((*input_pointer > 31) && (*input_pointer !=
'\"') && (*input_pointer !=
'\\'))
915 *output_pointer = *input_pointer;
920 *output_pointer++ =
'\\';
921 switch (*input_pointer)
924 *output_pointer =
'\\';
927 *output_pointer =
'\"';
930 *output_pointer =
'b';
933 *output_pointer =
'f';
936 *output_pointer =
'n';
939 *output_pointer =
'r';
942 *output_pointer =
't';
946 sprintf((
char*)output_pointer,
"u%04x", *input_pointer);
952 output[output_length + 1] =
'\"';
953 output[output_length + 2] =
'\0';
961 return print_string_ptr((
unsigned char*)item->
valuestring, p);
975 if ((buffer == NULL) || (buffer->
content == NULL))
996 if ((buffer == NULL) || (buffer->
content == NULL) || (buffer->
offset != 0))
1016 global_error.
json = NULL;
1024 buffer.
content = (
const unsigned char*)value;
1025 buffer.
length = strlen((
const char*)value) +
sizeof(
"");
1027 buffer.
hooks = global_hooks;
1029 item = cJSON_New_Item(&global_hooks);
1035 if (!parse_value(item, buffer_skip_whitespace(skip_utf8_bom(&buffer))))
1042 if (require_null_terminated)
1044 buffer_skip_whitespace(&buffer);
1050 if (return_parse_end)
1066 local_error.
json = (
const unsigned char*)value;
1073 else if (buffer.
length > 0)
1078 if (return_parse_end != NULL)
1080 *return_parse_end = (
const char*)local_error.
json + local_error.
position;
1083 global_error = local_error;
1092 return cJSON_ParseWithOpts(value, 0, 0);
1095 #define cjson_min(a, b) ((a < b) ? a : b) 1099 static const size_t default_buffer_size = 256;
1101 unsigned char *printed = NULL;
1103 memset(buffer, 0,
sizeof(buffer));
1106 buffer->
buffer = (
unsigned char*) hooks->
allocate(default_buffer_size);
1107 buffer->
length = default_buffer_size;
1109 buffer->
hooks = *hooks;
1110 if (buffer->
buffer == NULL)
1116 if (!print_value(item, buffer))
1120 update_offset(buffer);
1126 if (printed == NULL) {
1134 if (printed == NULL)
1139 printed[buffer->
offset] =
'\0';
1142 hooks->deallocate(buffer->
buffer);
1148 if (buffer->
buffer != NULL)
1150 hooks->deallocate(buffer->
buffer);
1153 if (printed != NULL)
1155 hooks->deallocate(printed);
1164 return (
char*)print(item,
true, &global_hooks);
1169 return (
char*)print(item,
false, &global_hooks);
1174 printbuffer p = { 0, 0, 0, 0, 0, 0, { 0, 0, 0 } };
1187 p.
length = (size_t)prebuffer;
1191 p.
hooks = global_hooks;
1193 if (!print_value(item, &p))
1195 global_hooks.deallocate(p.
buffer);
1204 printbuffer p = { 0, 0, 0, 0, 0, 0, { 0, 0, 0 } };
1206 if ((len < 0) || (buf == NULL))
1211 p.
buffer = (
unsigned char*)buf;
1216 p.
hooks = global_hooks;
1218 return print_value(item, &p);
1224 if ((input_buffer == NULL) || (input_buffer->
content == NULL))
1234 input_buffer->
offset += 4;
1241 input_buffer->
offset += 5;
1249 input_buffer->
offset += 4;
1255 return parse_string(item, input_buffer);
1260 return parse_number(item, input_buffer);
1265 return parse_array(item, input_buffer);
1270 return parse_object(item, input_buffer);
1279 unsigned char *output = NULL;
1281 if ((item == NULL) || (output_buffer == NULL))
1286 switch ((item->
type) & 0xFF)
1289 output = ensure(output_buffer, 5);
1294 strcpy((
char*)output,
"null");
1298 output = ensure(output_buffer, 6);
1303 strcpy((
char*)output,
"false");
1307 output = ensure(output_buffer, 5);
1312 strcpy((
char*)output,
"true");
1316 return print_number(item, output_buffer);
1320 size_t raw_length = 0;
1326 raw_length = strlen(item->
valuestring) +
sizeof(
"");
1327 output = ensure(output_buffer, raw_length);
1337 return print_string(item, output_buffer);
1340 return print_array(item, output_buffer);
1343 return print_object(item, output_buffer);
1354 cJSON *current_item = NULL;
1360 input_buffer->
depth++;
1369 buffer_skip_whitespace(input_buffer);
1389 cJSON *new_item = cJSON_New_Item(&(input_buffer->
hooks));
1390 if (new_item == NULL)
1399 current_item = head = new_item;
1404 current_item->
next = new_item;
1405 new_item->
prev = current_item;
1406 current_item = new_item;
1411 buffer_skip_whitespace(input_buffer);
1412 if (!parse_value(current_item, input_buffer))
1416 buffer_skip_whitespace(input_buffer);
1426 input_buffer->
depth--;
1447 unsigned char *output_pointer = NULL;
1451 if (output_buffer == NULL)
1458 output_pointer = ensure(output_buffer, 1);
1459 if (output_pointer == NULL)
1464 *output_pointer =
'[';
1466 output_buffer->
depth++;
1468 while (current_element != NULL)
1470 if (!print_value(current_element, output_buffer))
1474 update_offset(output_buffer);
1475 if (current_element->
next)
1477 length = (size_t) (output_buffer->
format ? 2 : 1);
1478 output_pointer = ensure(output_buffer, length + 1);
1479 if (output_pointer == NULL)
1483 *output_pointer++ =
',';
1484 if(output_buffer->
format)
1486 *output_pointer++ =
' ';
1488 *output_pointer =
'\0';
1491 current_element = current_element->
next;
1494 output_pointer = ensure(output_buffer, 2);
1495 if (output_pointer == NULL)
1499 *output_pointer++ =
']';
1500 *output_pointer =
'\0';
1501 output_buffer->
depth--;
1510 cJSON *current_item = NULL;
1516 input_buffer->
depth++;
1524 buffer_skip_whitespace(input_buffer);
1543 cJSON *new_item = cJSON_New_Item(&(input_buffer->
hooks));
1544 if (new_item == NULL)
1553 current_item = head = new_item;
1558 current_item->
next = new_item;
1559 new_item->
prev = current_item;
1560 current_item = new_item;
1565 buffer_skip_whitespace(input_buffer);
1566 if (!parse_string(current_item, input_buffer))
1570 buffer_skip_whitespace(input_buffer);
1583 buffer_skip_whitespace(input_buffer);
1584 if (!parse_value(current_item, input_buffer))
1588 buffer_skip_whitespace(input_buffer);
1598 input_buffer->
depth--;
1618 unsigned char *output_pointer = NULL;
1622 if (output_buffer == NULL)
1628 length = (size_t) (output_buffer->
format ? 2 : 1);
1629 output_pointer = ensure(output_buffer, length + 1);
1630 if (output_pointer == NULL)
1635 *output_pointer++ =
'{';
1636 output_buffer->
depth++;
1637 if (output_buffer->
format)
1639 *output_pointer++ =
'\n';
1643 while (current_item)
1645 if (output_buffer->
format)
1648 output_pointer = ensure(output_buffer, output_buffer->
depth);
1649 if (output_pointer == NULL)
1653 for (i = 0; i < output_buffer->
depth; i++)
1655 *output_pointer++ =
'\t';
1661 if (!print_string_ptr((
unsigned char*)current_item->
string, output_buffer))
1665 update_offset(output_buffer);
1667 length = (size_t) (output_buffer->
format ? 2 : 1);
1668 output_pointer = ensure(output_buffer, length);
1669 if (output_pointer == NULL)
1673 *output_pointer++ =
':';
1674 if (output_buffer->
format)
1676 *output_pointer++ =
'\t';
1681 if (!print_value(current_item, output_buffer))
1685 update_offset(output_buffer);
1688 length = ((size_t)(output_buffer->
format ? 1 : 0) + (size_t)(current_item->
next ? 1 : 0));
1689 output_pointer = ensure(output_buffer, length + 1);
1690 if (output_pointer == NULL)
1694 if (current_item->
next)
1696 *output_pointer++ =
',';
1699 if (output_buffer->
format)
1701 *output_pointer++ =
'\n';
1703 *output_pointer =
'\0';
1706 current_item = current_item->
next;
1709 output_pointer = ensure(output_buffer, output_buffer->
format ? (output_buffer->
depth + 1) : 2);
1710 if (output_pointer == NULL)
1714 if (output_buffer->
format)
1717 for (i = 0; i < (output_buffer->
depth - 1); i++)
1719 *output_pointer++ =
'\t';
1722 *output_pointer++ =
'}';
1723 *output_pointer =
'\0';
1724 output_buffer->
depth--;
1732 cJSON *child = NULL;
1740 child = array->
child;
1742 while(child != NULL)
1745 child = child->
next;
1755 cJSON *current_child = NULL;
1762 current_child = array->
child;
1763 while ((current_child != NULL) && (index > 0))
1766 current_child = current_child->
next;
1769 return current_child;
1779 return get_array_item(array, (
size_t)index);
1784 cJSON *current_element = NULL;
1786 if ((
object == NULL) || (
name == NULL))
1791 current_element =
object->
child;
1794 while ((current_element != NULL) && (current_element->
string != NULL) && (strcmp(
name, current_element->
string) != 0))
1796 current_element = current_element->
next;
1801 while ((current_element != NULL) && (case_insensitive_strcmp((
const unsigned char*)
name, (
const unsigned char*)(current_element->
string)) != 0))
1803 current_element = current_element->
next;
1807 if ((current_element == NULL) || (current_element->
string == NULL)) {
1811 return current_element;
1816 return get_object_item(
object,
string,
false);
1819 CJSON_PUBLIC(
cJSON *) cJSON_GetObjectItemCaseSensitive(
const cJSON *
const object,
const char *
const string)
1821 return get_object_item(
object,
string,
true);
1826 return cJSON_GetObjectItem(
object,
string) ? 1 : 0;
1830 static void suffix_object(
cJSON *prev,
cJSON *item)
1839 cJSON *reference = NULL;
1845 reference = cJSON_New_Item(hooks);
1846 if (reference == NULL)
1851 memcpy(reference, item,
sizeof(
cJSON));
1852 reference->
string = NULL;
1854 reference->
next = reference->
prev = NULL;
1860 cJSON *child = NULL;
1862 if ((item == NULL) || (array == NULL))
1867 child = array->
child;
1879 child = child->
next;
1881 suffix_object(child, item);
1890 add_item_to_array(array, item);
1893 #if defined(__clang__) || (defined(__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 5)))) 1894 #pragma GCC diagnostic push 1897 #pragma GCC diagnostic ignored "-Wcast-qual" 1900 static void* cast_away_const(
const void*
string)
1904 #if defined(__clang__) || (defined(__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 5)))) 1905 #pragma GCC diagnostic pop 1911 char *new_key = NULL;
1914 if ((
object == NULL) || (
string == NULL) || (item == NULL))
1921 new_key = (
char*)cast_away_const(
string);
1926 new_key = (
char*)cJSON_strdup((
const unsigned char*)
string, hooks);
1927 if (new_key == NULL)
1937 hooks->deallocate(item->
string);
1941 item->
type = new_type;
1943 return add_item_to_array(
object, item);
1948 add_item_to_object(
object,
string, item, &global_hooks,
false);
1954 add_item_to_object(
object,
string, item, &global_hooks,
true);
1964 add_item_to_array(array, create_reference(item, &global_hooks));
1969 if ((
object == NULL) || (
string == NULL))
1974 add_item_to_object(
object,
string, create_reference(item, &global_hooks), &global_hooks,
false);
1979 cJSON *null = cJSON_CreateNull();
1980 if (add_item_to_object(
object, name, null, &global_hooks,
false))
1991 cJSON *true_item = cJSON_CreateTrue();
1992 if (add_item_to_object(
object, name, true_item, &global_hooks,
false))
1997 cJSON_Delete(true_item);
2003 cJSON *false_item = cJSON_CreateFalse();
2004 if (add_item_to_object(
object, name, false_item, &global_hooks,
false))
2009 cJSON_Delete(false_item);
2015 cJSON *bool_item = cJSON_CreateBool(
boolean);
2016 if (add_item_to_object(
object,
name, bool_item, &global_hooks,
false))
2021 cJSON_Delete(bool_item);
2027 cJSON *number_item = cJSON_CreateNumber(number);
2028 if (add_item_to_object(
object,
name, number_item, &global_hooks,
false))
2033 cJSON_Delete(number_item);
2039 cJSON *string_item = cJSON_CreateString(
string);
2040 if (add_item_to_object(
object,
name, string_item, &global_hooks,
false))
2045 cJSON_Delete(string_item);
2051 cJSON *raw_item = cJSON_CreateRaw(raw);
2052 if (add_item_to_object(
object,
name, raw_item, &global_hooks,
false))
2057 cJSON_Delete(raw_item);
2063 cJSON *object_item = cJSON_CreateObject();
2064 if (add_item_to_object(
object, name, object_item, &global_hooks,
false))
2069 cJSON_Delete(object_item);
2075 cJSON *array = cJSON_CreateArray();
2076 if (add_item_to_object(
object, name, array, &global_hooks,
false))
2081 cJSON_Delete(array);
2087 if ((parent == NULL) || (item == NULL))
2092 if (item->
prev != NULL)
2097 if (item->
next != NULL)
2103 if (item == parent->
child)
2122 return cJSON_DetachItemViaPointer(array, get_array_item(array, (
size_t)which));
2127 cJSON_Delete(cJSON_DetachItemFromArray(array, which));
2132 cJSON *to_detach = cJSON_GetObjectItem(
object,
string);
2134 return cJSON_DetachItemViaPointer(
object, to_detach);
2139 cJSON *to_detach = cJSON_GetObjectItemCaseSensitive(
object,
string);
2141 return cJSON_DetachItemViaPointer(
object, to_detach);
2144 CJSON_PUBLIC(
void) cJSON_DeleteItemFromObject(
cJSON *
object,
const char *
string)
2146 cJSON_Delete(cJSON_DetachItemFromObject(
object,
string));
2149 CJSON_PUBLIC(
void) cJSON_DeleteItemFromObjectCaseSensitive(
cJSON *
object,
const char *
string)
2151 cJSON_Delete(cJSON_DetachItemFromObjectCaseSensitive(
object,
string));
2157 cJSON *after_inserted = NULL;
2164 after_inserted = get_array_item(array, (
size_t)
which);
2165 if (after_inserted == NULL)
2167 add_item_to_array(array, newitem);
2171 newitem->
next = after_inserted;
2172 newitem->
prev = after_inserted->
prev;
2174 if (after_inserted == array->
child)
2186 if ((parent == NULL) || (replacement == NULL) || (item == NULL))
2191 if (replacement == item)
2199 if (replacement->
next != NULL)
2203 if (replacement->
prev != NULL)
2207 if (parent->
child == item)
2226 cJSON_ReplaceItemViaPointer(array, get_array_item(array, (
size_t)
which), newitem);
2231 if ((replacement == NULL) || (
string == NULL))
2239 cJSON_free(replacement->
string);
2241 replacement->
string = (
char*)cJSON_strdup((
const unsigned char*)
string, &global_hooks);
2244 cJSON_ReplaceItemViaPointer(
object, get_object_item(
object,
string, case_sensitive), replacement);
2251 replace_item_in_object(
object,
string, newitem,
false);
2254 CJSON_PUBLIC(
void) cJSON_ReplaceItemInObjectCaseSensitive(
cJSON *
object,
const char *
string,
cJSON *newitem)
2256 replace_item_in_object(
object,
string, newitem,
true);
2262 cJSON *item = cJSON_New_Item(&global_hooks);
2273 cJSON *item = cJSON_New_Item(&global_hooks);
2284 cJSON *item = cJSON_New_Item(&global_hooks);
2295 cJSON *item = cJSON_New_Item(&global_hooks);
2306 cJSON *item = cJSON_New_Item(&global_hooks);
2317 else if (num <= (
double)INT_MIN)
2332 cJSON *item = cJSON_New_Item(&global_hooks);
2336 item->
valuestring = (
char*)cJSON_strdup((
const unsigned char*)
string, &global_hooks);
2349 cJSON *item = cJSON_New_Item(&global_hooks);
2353 item->
valuestring = (
char*)cast_away_const(
string);
2361 cJSON *item = cJSON_New_Item(&global_hooks);
2364 item->
child = (
cJSON*)cast_away_const(child);
2371 cJSON *item = cJSON_New_Item(&global_hooks);
2374 item->
child = (
cJSON*)cast_away_const(child);
2382 cJSON *item = cJSON_New_Item(&global_hooks);
2386 item->
valuestring = (
char*)cJSON_strdup((
const unsigned char*)
raw, &global_hooks);
2399 cJSON *item = cJSON_New_Item(&global_hooks);
2410 cJSON *item = cJSON_New_Item(&global_hooks);
2427 if ((count < 0) || (numbers == NULL))
2432 a = cJSON_CreateArray();
2433 for(i = 0; a && (i < (size_t)count); i++)
2435 n = cJSON_CreateNumber(numbers[i]);
2447 suffix_object(p, n);
2462 if ((count < 0) || (numbers == NULL))
2467 a = cJSON_CreateArray();
2469 for(i = 0; a && (i < (size_t)count); i++)
2471 n = cJSON_CreateNumber((
double)numbers[i]);
2483 suffix_object(p, n);
2498 if ((count < 0) || (numbers == NULL))
2503 a = cJSON_CreateArray();
2505 for(i = 0;a && (i < (size_t)count); i++)
2507 n = cJSON_CreateNumber(numbers[i]);
2519 suffix_object(p, n);
2534 if ((count < 0) || (strings == NULL))
2539 a = cJSON_CreateArray();
2541 for (i = 0; a && (i < (size_t)count); i++)
2543 n = cJSON_CreateString(strings[i]);
2566 cJSON *newitem = NULL;
2567 cJSON *child = NULL;
2569 cJSON *newchild = NULL;
2577 newitem = cJSON_New_Item(&global_hooks);
2608 child = item->
child;
2609 while (child != NULL)
2611 newchild = cJSON_Duplicate(child,
true);
2619 next->
next = newchild;
2620 newchild->
prev = next;
2626 newitem->
child = newchild;
2629 child = child->
next;
2635 if (newitem != NULL)
2637 cJSON_Delete(newitem);
2643 static void skip_oneline_comment(
char **input)
2647 for (; (*input)[0] !=
'\0'; ++(*input))
2649 if ((*input)[0] ==
'\n') {
2656 static void skip_multiline_comment(
char **input)
2660 for (; (*input)[0] !=
'\0'; ++(*input))
2662 if (((*input)[0] ==
'*') && ((*input)[1] ==
'/'))
2670 static void minify_string(
char **input,
char **output) {
2671 (*output)[0] = (*input)[0];
2676 for (; (*input)[0] !=
'\0'; (void)++(*input), ++(*output)) {
2677 (*output)[0] = (*input)[0];
2679 if ((*input)[0] ==
'\"') {
2680 (*output)[0] =
'\"';
2684 }
else if (((*input)[0] ==
'\\') && ((*input)[1] ==
'\"')) {
2685 (*output)[1] = (*input)[1];
2701 while (json[0] !=
'\0')
2715 skip_oneline_comment(&json);
2717 else if (json[1] ==
'*')
2719 skip_multiline_comment(&json);
2724 minify_string(&json, (
char**)&into);
2840 if ((a == NULL) || (b == NULL) || ((a->
type & 0xFF) != (b->
type & 0xFF)) || cJSON_IsInvalid(a))
2846 switch (a->
type & 0xFF)
2868 switch (a->
type & 0xFF)
2901 for (; (a_element != NULL) && (b_element != NULL);)
2903 if (!cJSON_Compare(a_element, b_element, case_sensitive))
2908 a_element = a_element->
next;
2909 b_element = b_element->
next;
2913 if (a_element != b_element) {
2922 cJSON *a_element = NULL;
2923 cJSON *b_element = NULL;
2927 b_element = get_object_item(b, a_element->
string, case_sensitive);
2928 if (b_element == NULL)
2933 if (!cJSON_Compare(a_element, b_element, case_sensitive))
2943 a_element = get_object_item(a, b_element->
string, case_sensitive);
2944 if (a_element == NULL)
2949 if (!cJSON_Compare(b_element, a_element, case_sensitive))
2965 return global_hooks.
allocate(size);
2970 global_hooks.deallocate(
object);
#define static_strlen(string_literal)
#define cJSON_ArrayForEach(element, array)
#define CJSON_VERSION_PATCH
#define can_read(buffer, size)
const unsigned char * content
cJSON *const cJSON * replacement
const char cJSON_bool require_null_terminated
const char *const const double number
#define can_access_at_index(buffer, index)
#define CJSON_NESTING_LIMIT
void *CJSON_CDECL * reallocate(void *pointer, size_t size)
#define CJSON_VERSION_MINOR
CJSON_PUBLIC(const char *)
void *CJSON_CDECL * allocate(size_t size)
const unsigned char * json
#define cannot_access_at_index(buffer, index)
const char ** return_parse_end
#define buffer_at_offset(buffer)
struct internal_hooks internal_hooks
#define cJSON_StringIsConst
#define cJSON_IsReference
const cJSON *const const cJSON_bool case_sensitive
char const int const cJSON_bool format
#define CJSON_VERSION_MAJOR
const char *const const char *const raw