Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions json-builder.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,16 @@
#include <string.h>
#include <assert.h>
#include <stdio.h>
#include <math.h>

#ifdef _MSC_VER
#define snprintf _snprintf
#endif

const static json_serialize_opts default_opts =
static double floor(double d) {
return d - ((int)d % 1);
}

static const json_serialize_opts default_opts =
{
json_serialize_mode_single_line,
0,
Expand Down Expand Up @@ -99,7 +102,7 @@ const int f_spaces_after_commas = (1 << 1);
const int f_spaces_after_colons = (1 << 2);
const int f_tabs = (1 << 3);

int get_serialize_flags (json_serialize_opts opts)
static int get_serialize_flags (json_serialize_opts opts)
{
int flags = 0;

Expand Down Expand Up @@ -357,7 +360,7 @@ json_value * json_boolean_new (int b)
return value;
}

json_value * json_null_new ()
json_value * json_null_new (void)
{
json_value * value = (json_value *) calloc (1, sizeof (json_builder_value));

Expand Down Expand Up @@ -885,7 +888,7 @@ void json_serialize_ex (json_char * buf, json_value * value, json_serialize_opts
{
*dot = '.';
}
else if (!strchr (ptr, '.'))
else if (!strchr (ptr, '.') && !strchr (ptr, 'e'))
{
*buf ++ = '.';
*buf ++ = '0';
Expand Down
2 changes: 1 addition & 1 deletion json-builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ json_value * json_string_new_nocopy (unsigned int length, json_char *);
json_value * json_integer_new (json_int_t);
json_value * json_double_new (double);
json_value * json_boolean_new (int);
json_value * json_null_new ();
json_value * json_null_new (void);


/*** Serializing
Expand Down
10 changes: 8 additions & 2 deletions test/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,17 @@ void test_buf (char * buffer, size_t size, int * num_failed)
char * buf = (char *) malloc (measured);
json_serialize (buf, value);

printf ("serialized len: %d\n", (int) strlen (buf) + 1);
size_t serialized = (int) strlen (buf) + 1;
printf ("serialized len: %d\n", serialized);

printf ("serialized:\n%s\n", buf);

if (! (value2 = json_parse_ex (&settings, buf, strlen(buf), error)))
if (serialized > measured)
{
printf ("Serialized more than measured\n");
++ *num_failed;
}
else if (! (value2 = json_parse_ex (&settings, buf, strlen(buf), error)))
{
printf ("Failed to re-parse: %s\n", error);
++ *num_failed;
Expand Down