@@ -54,6 +54,7 @@ static struct json_object* json_object_new(enum json_type o_type);
static json_object_to_json_string_fn json_object_object_to_json_string;
static json_object_to_json_string_fn json_object_object_to_json_string;
static json_object_to_json_string_fn json_object_boolean_to_json_string;
static json_object_to_json_string_fn json_object_boolean_to_json_string;
static json_object_to_json_string_fn json_object_double_to_json_string_default;
static json_object_to_json_string_fn json_object_int_to_json_string;
static json_object_to_json_string_fn json_object_int_to_json_string;
static json_object_to_json_string_fn json_object_string_to_json_string;
static json_object_to_json_string_fn json_object_string_to_json_string;
static json_object_to_json_string_fn json_object_array_to_json_string;
static json_object_to_json_string_fn json_object_array_to_json_string;
@@ -261,7 +262,7 @@ void json_object_set_serializer(json_object *jso,
jso->_to_json_string = &json_object_boolean_to_json_string;
jso->_to_json_string = &json_object_boolean_to_json_string;
break;
break;
case json_type_double:
case json_type_double:
jso->_to_json_string = &json_object_double_to_json_string;
jso->_to_json_string = &json_object_double_to_json_string_default ;
break;
break;
case json_type_int:
case json_type_int:
jso->_to_json_string = &json_object_int_to_json_string;
jso->_to_json_string = &json_object_int_to_json_string;
@@ -643,10 +644,11 @@ int64_t json_object_get_int64(const struct json_object *jso)
/* json_object_double */
/* json_object_double */
int json_object_double_to_json_string(struct json_object* jso,
struct printbuf *pb,
int level,
int flags)
static int json_object_double_to_json_string_format(struct json_object* jso,
struct printbuf *pb,
int level,
int flags,
const char *format)
{
{
char buf[128], *p, *q;
char buf[128], *p, *q;
int size;
int size;
@@ -663,7 +665,7 @@ int json_object_double_to_json_string(struct json_object* jso,
size = snprintf(buf, sizeof(buf), "-Infinity");
size = snprintf(buf, sizeof(buf), "-Infinity");
else
else
size = snprintf(buf, sizeof(buf),
size = snprintf(buf, sizeof(buf),
jso->_userdata ? (const char*) jso->_userdata : "%.17g", jso->o.c_double);
format ? format : "%.17g", jso->o.c_double);
p = strchr(buf, ',');
p = strchr(buf, ',');
if (p) {
if (p) {
@@ -685,12 +687,30 @@ int json_object_double_to_json_string(struct json_object* jso,
return size;
return size;
}
}
static int json_object_double_to_json_string_default(struct json_object* jso,
struct printbuf *pb,
int level,
int flags)
{
return json_object_double_to_json_string_format(jso, pb, level, flags,
NULL);
}
int json_object_double_to_json_string(struct json_object* jso,
struct printbuf *pb,
int level,
int flags)
{
return json_object_double_to_json_string_format(jso, pb, level, flags,
jso->_userdata);
}
struct json_object* json_object_new_double(double d)
struct json_object* json_object_new_double(double d)
{
{
struct json_object *jso = json_object_new(json_type_double);
struct json_object *jso = json_object_new(json_type_double);
if (!jso)
if (!jso)
return NULL;
return NULL;
jso->_to_json_string = &json_object_double_to_json_string;
jso->_to_json_string = &json_object_double_to_json_string_default ;
jso->o.c_double = d;
jso->o.c_double = d;
return jso;
return jso;
}
}