Lines Matching defs:item
94 /* Parse the input text to generate a number, and populate the result into item.
96 static const char *parse_number(cJSON *item, const char *num) {
124 item->valuedouble = n;
125 item->valueint = (int)n;
126 item->type = cJSON_Number;
174 /* Render the number nicely from the given item into a string. */
175 static char *print_number(cJSON *item, printbuffer *p) {
178 double d = item->valuedouble;
182 str = ensure(item->pAllocator, p, str_buf_size);
184 str = (char *)cJSON_malloc(item->pAllocator, str_buf_size);
186 } else if (fabs(((double)item->valueint) - d) <= DBL_EPSILON && d <= INT_MAX && d >= INT_MIN) {
189 str = ensure(item->pAllocator, p, str_buf_size);
191 str = (char *)cJSON_malloc(item->pAllocator, str_buf_size);
192 if (str) snprintf(str, str_buf_size, "%d", item->valueint);
196 str = ensure(item->pAllocator, p, str_buf_size);
198 str = (char *)cJSON_malloc(item->pAllocator, str_buf_size);
254 /* Parse the input text into an unescaped cstring, and populate item. */
256 static const char *parse_string(cJSON *item, const char *str, bool *out_of_memory) {
270 out = (char *)cJSON_malloc(item->pAllocator, len + 1); /* This is how long we need for the string, roughly. */
342 item->valuestring = out;
343 item->type = cJSON_String;
442 /* Invoke print_string_ptr (which is useful) on an item. */
443 static char *print_string(cJSON *item, printbuffer *p) { return print_string_ptr(item->pAllocator, item->valuestring, p); }
446 static const char *parse_value(cJSON *item, const char *value, bool *out_of_memory);
447 static char *print_value(cJSON *item, int depth, int fmt, printbuffer *p);
448 static const char *parse_array(cJSON *item, const char *value, bool *out_of_memory);
449 static char *print_array(cJSON *item, int depth, int fmt, printbuffer *p);
450 static const char *parse_object(cJSON *item, const char *value, bool *out_of_memory);
451 static char *print_object(cJSON *item, int depth, int fmt, printbuffer *p);
494 /* Render a cJSON item/entity/structure to text. */
495 char *loader_cJSON_Print(cJSON *item) { return print_value(item, 0, 1, 0); }
496 char *loader_cJSON_PrintUnformatted(cJSON *item) { return print_value(item, 0, 0, 0); }
499 static const char *parse_value(cJSON *item, const char *value, bool *out_of_memory) {
502 item->type = cJSON_NULL;
506 item->type = cJSON_False;
510 item->type = cJSON_True;
511 item->valueint = 1;
515 return parse_string(item, value, out_of_memory);
518 return parse_number(item, value);
521 return parse_array(item, value, out_of_memory);
524 return parse_object(item, value, out_of_memory);
532 static char *print_value(cJSON *item, int depth, int fmt, printbuffer *p) {
534 if (!item) return 0;
536 switch ((item->type) & 255) {
538 out = ensure(item->pAllocator, p, 5);
543 out = ensure(item->pAllocator, p, 6);
548 out = ensure(item->pAllocator, p, 5);
553 out = print_number(item, p);
556 out = print_string(item, p);
559 out = print_array(item, depth, fmt, p);
562 out = print_object(item, depth, fmt, p);
566 switch ((item->type) & 255) {
568 out = cJSON_strdup(item->pAllocator, "null");
571 out = cJSON_strdup(item->pAllocator, "false");
574 out = cJSON_strdup(item->pAllocator, "true");
577 out = print_number(item, 0);
580 out = print_string(item, 0);
583 out = print_array(item, depth, fmt, 0);
586 out = print_object(item, depth, fmt, 0);
594 static const char *parse_array(cJSON *item, const char *value, bool *out_of_memory) {
601 item->type = cJSON_Array;
605 item->child = child = cJSON_New_Item(item->pAllocator);
606 if (!item->child) {
615 new_item = cJSON_New_Item(item->pAllocator);
633 static char *print_array(cJSON *item, int depth, int fmt, printbuffer *p) {
637 cJSON *child = item->child;
646 out = ensure(item->pAllocator, p, 3);
648 out = (char *)cJSON_malloc(item->pAllocator, 3);
656 ptr = ensure(item->pAllocator, p, 1);
660 child = item->child;
666 ptr = ensure(item->pAllocator, p, len + 1);
675 ptr = ensure(item->pAllocator, p, 2);
682 entries = (char **)cJSON_malloc(item->pAllocator, numentries * sizeof(char *));
686 child = item->child;
698 if (!fail) out = (char *)cJSON_malloc(item->pAllocator, len);
705 if (entries[j]) cJSON_Free(item->pAllocator, entries[j]);
706 cJSON_Free(item->pAllocator, entries);
723 cJSON_Free(item->pAllocator, entries[j]);
725 cJSON_Free(item->pAllocator, entries);
733 static const char *parse_object(cJSON *item, const char *value, bool *out_of_memory) {
740 item->type = cJSON_Object;
744 item->child = child = cJSON_New_Item(item->pAllocator);
745 if (!item->child) {
762 new_item = cJSON_New_Item(item->pAllocator);
788 static char *print_object(cJSON *item, int depth, int fmt, printbuffer *p) {
792 cJSON *child = item->child;
800 out = ensure(item->pAllocator, p, fmt ? depth + 4 : 3);
802 out = (char *)cJSON_malloc(item->pAllocator, fmt ? depth + 4 : 3);
818 ptr = ensure(item->pAllocator, p, len + 1);
824 child = item->child;
828 ptr = ensure(item->pAllocator, p, depth);
833 print_string_ptr(item->pAllocator, child->string, p);
837 ptr = ensure(item->pAllocator, p, len);
847 ptr = ensure(item->pAllocator, p, len + 1);
855 ptr = ensure(item->pAllocator, p, fmt ? (depth + 1) : 2);
864 entries = (char **)cJSON_malloc(item->pAllocator, numentries * sizeof(char *));
866 names = (char **)cJSON_malloc(item->pAllocator, numentries * sizeof(char *));
868 cJSON_Free(item->pAllocator, entries);
875 child = item->child;
879 names[i] = str = print_string_ptr(item->pAllocator, child->string, 0);
889 if (!fail) out = (char *)cJSON_malloc(item->pAllocator, len);
895 if (names[i]) cJSON_Free(item->pAllocator, names[j]);
896 if (entries[j]) cJSON_Free(item->pAllocator, entries[j]);
898 cJSON_Free(item->pAllocator, names);
899 cJSON_Free(item->pAllocator, entries);
922 cJSON_Free(item->pAllocator, names[j]);
923 cJSON_Free(item->pAllocator, entries[j]);
926 cJSON_Free(item->pAllocator, names);
927 cJSON_Free(item->pAllocator, entries);
936 /* Get Array size/item / object item. */
943 cJSON *loader_cJSON_GetArrayItem(cJSON *array, int item) {
945 while (c && item > 0) item--, c = c->next;
1041 cJSON *item = loader_cJSON_GetObjectItem(object, key);
1042 if (NULL == item) {
1046 char *str = loader_cJSON_Print(item);
1061 cJSON *item = loader_cJSON_GetObjectItem(object, key);
1062 if (NULL == item) {
1066 char *str = loader_cJSON_Print(item);
1078 cJSON *item = loader_cJSON_GetObjectItem(object, key);
1079 if (NULL == item) {
1083 uint32_t count = loader_cJSON_GetArraySize(item);
1093 cJSON *element = loader_cJSON_GetArrayItem(item, i);