1
0
mirror of https://github.com/DaveGamble/cJSON synced 2025-05-10 20:17:58 +00:00

reformatting: print_value

This commit is contained in:
Max Bruckner 2016-09-28 20:50:57 +07:00
parent c5f635d24a
commit de4dc19e72

83
cJSON.c
View File

@ -899,36 +899,81 @@ static const char *parse_value(cJSON *item, const char *value, const char **ep)
} }
/* Render a value to text. */ /* 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; char *out = 0;
if (!item) return 0;
if (!item)
{
return 0;
}
if (p) if (p)
{ {
switch ((item->type)&255) switch ((item->type) & 255)
{ {
case cJSON_NULL: {out=ensure(p,5); if (out) strcpy(out,"null"); break;} case cJSON_NULL:
case cJSON_False: {out=ensure(p,6); if (out) strcpy(out,"false"); break;} out = ensure(p, 5);
case cJSON_True: {out=ensure(p,5); if (out) strcpy(out,"true"); break;} if (out)
case cJSON_Number: out=print_number(item,p);break; {
case cJSON_String: out=print_string(item,p);break; strcpy(out, "null");
case cJSON_Array: out=print_array(item,depth,fmt,p);break; }
case cJSON_Object: out=print_object(item,depth,fmt,p);break; 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 else
{ {
switch ((item->type)&255) switch ((item->type) & 255)
{ {
case cJSON_NULL: out=cJSON_strdup("null"); break; case cJSON_NULL:
case cJSON_False: out=cJSON_strdup("false");break; out = cJSON_strdup("null");
case cJSON_True: out=cJSON_strdup("true"); break; break;
case cJSON_Number: out=print_number(item,0);break; case cJSON_False:
case cJSON_String: out=print_string(item,0);break; out = cJSON_strdup("false");
case cJSON_Array: out=print_array(item,depth,fmt,0);break; break;
case cJSON_Object: out=print_object(item,depth,fmt,0);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; return out;
} }