mirror of
https://github.com/DaveGamble/cJSON.git
synced 2023-08-10 21:13:26 +03:00
print_number: rename variables
This commit is contained in:
parent
61921498d0
commit
6815d96617
26
cJSON.c
26
cJSON.c
@ -320,12 +320,12 @@ static size_t update(const printbuffer *p)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Render the number nicely from the given item into a string. */
|
/* Render the number nicely from the given item into a string. */
|
||||||
static unsigned char *print_number(const cJSON *item, printbuffer *p)
|
static unsigned char *print_number(const cJSON * const item, printbuffer * const output_buffer)
|
||||||
{
|
{
|
||||||
unsigned char *str = NULL;
|
unsigned char *output_pointer = NULL;
|
||||||
double d = item->valuedouble;
|
double d = item->valuedouble;
|
||||||
|
|
||||||
if (p == NULL)
|
if (output_buffer == NULL)
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -334,40 +334,40 @@ static unsigned char *print_number(const cJSON *item, printbuffer *p)
|
|||||||
if ((fabs(((double)item->valueint) - d) <= DBL_EPSILON) && (d <= INT_MAX) && (d >= INT_MIN))
|
if ((fabs(((double)item->valueint) - d) <= DBL_EPSILON) && (d <= INT_MAX) && (d >= INT_MIN))
|
||||||
{
|
{
|
||||||
/* 2^64+1 can be represented in 21 chars. */
|
/* 2^64+1 can be represented in 21 chars. */
|
||||||
str = ensure(p, 21);
|
output_pointer = ensure(output_buffer, 21);
|
||||||
if (str != NULL)
|
if (output_pointer != NULL)
|
||||||
{
|
{
|
||||||
sprintf((char*)str, "%d", item->valueint);
|
sprintf((char*)output_pointer, "%d", item->valueint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* value is a floating point number */
|
/* value is a floating point number */
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* This is a nice tradeoff. */
|
/* This is a nice tradeoff. */
|
||||||
str = ensure(p, 64);
|
output_pointer = ensure(output_buffer, 64);
|
||||||
if (str != NULL)
|
if (output_pointer != NULL)
|
||||||
{
|
{
|
||||||
/* This checks for NaN and Infinity */
|
/* This checks for NaN and Infinity */
|
||||||
if ((d * 0) != 0)
|
if ((d * 0) != 0)
|
||||||
{
|
{
|
||||||
sprintf((char*)str, "null");
|
sprintf((char*)output_pointer, "null");
|
||||||
}
|
}
|
||||||
else if ((fabs(floor(d) - d) <= DBL_EPSILON) && (fabs(d) < 1.0e60))
|
else if ((fabs(floor(d) - d) <= DBL_EPSILON) && (fabs(d) < 1.0e60))
|
||||||
{
|
{
|
||||||
sprintf((char*)str, "%.0f", d);
|
sprintf((char*)output_pointer, "%.0f", d);
|
||||||
}
|
}
|
||||||
else if ((fabs(d) < 1.0e-6) || (fabs(d) > 1.0e9))
|
else if ((fabs(d) < 1.0e-6) || (fabs(d) > 1.0e9))
|
||||||
{
|
{
|
||||||
sprintf((char*)str, "%e", d);
|
sprintf((char*)output_pointer, "%e", d);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
sprintf((char*)str, "%f", d);
|
sprintf((char*)output_pointer, "%f", d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return str;
|
return output_pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* parse 4 digit hexadecimal number */
|
/* parse 4 digit hexadecimal number */
|
||||||
|
Loading…
Reference in New Issue
Block a user