mirror of
https://github.com/json-c/json-c.git
synced 2026-04-12 16:59:06 +08:00
Reformat json_object_double_to_json_string_format() to have consistent spacing.
This commit is contained in:
@@ -749,13 +749,17 @@ static int json_object_double_to_json_string_format(struct json_object* jso,
|
|||||||
NaN or Infinity as numeric values
|
NaN or Infinity as numeric values
|
||||||
ECMA 262 section 9.8.1 defines
|
ECMA 262 section 9.8.1 defines
|
||||||
how to handle these cases as strings */
|
how to handle these cases as strings */
|
||||||
if(isnan(jso->o.c_double))
|
if (isnan(jso->o.c_double))
|
||||||
|
{
|
||||||
size = snprintf(buf, sizeof(buf), "NaN");
|
size = snprintf(buf, sizeof(buf), "NaN");
|
||||||
else if(isinf(jso->o.c_double))
|
}
|
||||||
|
else if (isinf(jso->o.c_double))
|
||||||
|
{
|
||||||
if(jso->o.c_double > 0)
|
if(jso->o.c_double > 0)
|
||||||
size = snprintf(buf, sizeof(buf), "Infinity");
|
size = snprintf(buf, sizeof(buf), "Infinity");
|
||||||
else
|
else
|
||||||
size = snprintf(buf, sizeof(buf), "-Infinity");
|
size = snprintf(buf, sizeof(buf), "-Infinity");
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const char *std_format = "%.17g";
|
const char *std_format = "%.17g";
|
||||||
@@ -783,12 +787,12 @@ static int json_object_double_to_json_string_format(struct json_object* jso,
|
|||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
p = strchr(buf, ',');
|
p = strchr(buf, ',');
|
||||||
if (p) {
|
if (p)
|
||||||
*p = '.';
|
*p = '.';
|
||||||
} else {
|
else
|
||||||
p = strchr(buf, '.');
|
p = strchr(buf, '.');
|
||||||
}
|
if (p && (flags & JSON_C_TO_STRING_NOZERO))
|
||||||
if (p && (flags & JSON_C_TO_STRING_NOZERO)) {
|
{
|
||||||
/* last useful digit, always keep 1 zero */
|
/* last useful digit, always keep 1 zero */
|
||||||
p++;
|
p++;
|
||||||
for (q=p ; *q ; q++) {
|
for (q=p ; *q ; q++) {
|
||||||
|
|||||||
Reference in New Issue
Block a user