|
@@ -899,37 +899,82 @@ static const char *parse_value(cJSON *item, const char *value, const char **ep)
|
|
|
}
|
|
|
|
|
|
/* Render a value to text. */
|
|
|
-static char *print_value(cJSON *item,int depth,int fmt,printbuffer *p)
|
|
|
+static char *print_value(cJSON *item, int depth, int fmt, printbuffer *p)
|
|
|
{
|
|
|
- char *out=0;
|
|
|
- if (!item) return 0;
|
|
|
- if (p)
|
|
|
- {
|
|
|
- switch ((item->type)&255)
|
|
|
- {
|
|
|
- case cJSON_NULL: {out=ensure(p,5); if (out) strcpy(out,"null"); break;}
|
|
|
- case cJSON_False: {out=ensure(p,6); if (out) strcpy(out,"false"); break;}
|
|
|
- case cJSON_True: {out=ensure(p,5); if (out) strcpy(out,"true"); break;}
|
|
|
- case cJSON_Number: out=print_number(item,p);break;
|
|
|
- case cJSON_String: out=print_string(item,p);break;
|
|
|
- case cJSON_Array: out=print_array(item,depth,fmt,p);break;
|
|
|
- case cJSON_Object: out=print_object(item,depth,fmt,p);break;
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- switch ((item->type)&255)
|
|
|
- {
|
|
|
- case cJSON_NULL: out=cJSON_strdup("null"); break;
|
|
|
- case cJSON_False: out=cJSON_strdup("false");break;
|
|
|
- case cJSON_True: out=cJSON_strdup("true"); break;
|
|
|
- case cJSON_Number: out=print_number(item,0);break;
|
|
|
- case cJSON_String: out=print_string(item,0);break;
|
|
|
- case cJSON_Array: out=print_array(item,depth,fmt,0);break;
|
|
|
- case cJSON_Object: out=print_object(item,depth,fmt,0);break;
|
|
|
- }
|
|
|
- }
|
|
|
- return out;
|
|
|
+ char *out = 0;
|
|
|
+
|
|
|
+ if (!item)
|
|
|
+ {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ if (p)
|
|
|
+ {
|
|
|
+ switch ((item->type) & 255)
|
|
|
+ {
|
|
|
+ case cJSON_NULL:
|
|
|
+ out = ensure(p, 5);
|
|
|
+ if (out)
|
|
|
+ {
|
|
|
+ strcpy(out, "null");
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case cJSON_False:
|
|
|
+ out = ensure(p, 6);
|
|
|
+ if (out)
|
|
|
+ {
|
|
|
+ strcpy(out, "false");
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case cJSON_True:
|
|
|
+ out = ensure(p, 5);
|
|
|
+ if (out)
|
|
|
+ {
|
|
|
+ strcpy(out, "true");
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case cJSON_Number:
|
|
|
+ out = print_number(item, p);
|
|
|
+ break;
|
|
|
+ case cJSON_String:
|
|
|
+ out = print_string(item, p);
|
|
|
+ break;
|
|
|
+ case cJSON_Array:
|
|
|
+ out = print_array(item, depth, fmt, p);
|
|
|
+ break;
|
|
|
+ case cJSON_Object:
|
|
|
+ out = print_object(item, depth, fmt, p);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ switch ((item->type) & 255)
|
|
|
+ {
|
|
|
+ case cJSON_NULL:
|
|
|
+ out = cJSON_strdup("null");
|
|
|
+ break;
|
|
|
+ case cJSON_False:
|
|
|
+ out = cJSON_strdup("false");
|
|
|
+ break;
|
|
|
+ case cJSON_True:
|
|
|
+ out = cJSON_strdup("true");
|
|
|
+ break;
|
|
|
+ case cJSON_Number:
|
|
|
+ out = print_number(item, 0);
|
|
|
+ break;
|
|
|
+ case cJSON_String:
|
|
|
+ out = print_string(item, 0);
|
|
|
+ break;
|
|
|
+ case cJSON_Array:
|
|
|
+ out = print_array(item, depth, fmt, 0);
|
|
|
+ break;
|
|
|
+ case cJSON_Object:
|
|
|
+ out = print_object(item, depth, fmt, 0);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return out;
|
|
|
}
|
|
|
|
|
|
/* Build an array from input text. */
|