Reformat json_object_double_to_json_string_format() to have consistent spacing.

This commit is contained in:
Eric Haszlakiewicz
2017-07-08 20:33:28 -07:00
parent 5e33dabda1
commit 5a99e527ff

View File

@@ -750,12 +750,16 @@ static int json_object_double_to_json_string_format(struct json_object* jso,
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++) {