1
0
mirror of https://github.com/DaveGamble/cJSON synced 2025-05-11 20:47: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

105
cJSON.c
View File

@ -899,37 +899,82 @@ 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 (p) if (!item)
{ {
switch ((item->type)&255) return 0;
{ }
case cJSON_NULL: {out=ensure(p,5); if (out) strcpy(out,"null"); break;} if (p)
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;} switch ((item->type) & 255)
case cJSON_Number: out=print_number(item,p);break; {
case cJSON_String: out=print_string(item,p);break; case cJSON_NULL:
case cJSON_Array: out=print_array(item,depth,fmt,p);break; out = ensure(p, 5);
case cJSON_Object: out=print_object(item,depth,fmt,p);break; if (out)
} {
} strcpy(out, "null");
else }
{ break;
switch ((item->type)&255) case cJSON_False:
{ out = ensure(p, 6);
case cJSON_NULL: out=cJSON_strdup("null"); break; if (out)
case cJSON_False: out=cJSON_strdup("false");break; {
case cJSON_True: out=cJSON_strdup("true"); break; strcpy(out, "false");
case cJSON_Number: out=print_number(item,0);break; }
case cJSON_String: out=print_string(item,0);break; break;
case cJSON_Array: out=print_array(item,depth,fmt,0);break; case cJSON_True:
case cJSON_Object: out=print_object(item,depth,fmt,0);break; out = ensure(p, 5);
} if (out)
} {
return 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. */ /* Build an array from input text. */