#include <ucw-json/json.h>
#include <float.h>
-#include <math.h>
#include <stdio.h>
void json_set_output(struct json_context *js, struct fastbuf *fb)
else if (u < 0x110000)
bprintf(fb, "\\u%04x\\u%04x", 0xd800 + ((u - 0x10000) >> 10), 0xdc00 + (u & 0x3ff));
else
- ASSERT(0);
+ bprintf(fb, "\\u%04x", UNI_REPLACEMENT);
}
else
bput_utf8_32(fb, u);
static void write_number(struct fastbuf *fb, double val)
{
- ASSERT(isfinite(val));
- bprintf(fb, "%.*g", DBL_DIG, val);
+ bprintf(fb, "%.*g", DBL_DIG+1, val);
}
static bool want_indent_p(struct json_context *js)
{
if (!GARY_SIZE(n->pairs))
bputs(fb, "{}");
- bputc(fb, '{');
- js->out_indent++;
- for (size_t i=0; i < GARY_SIZE(n->pairs); i++)
+ else
{
- if (i)
- bputc(fb, ',');
+ bputc(fb, '{');
+ js->out_indent++;
+ for (size_t i=0; i < GARY_SIZE(n->pairs); i++)
+ {
+ if (i)
+ bputc(fb, ',');
+ write_space(js);
+ struct json_pair *p = &n->pairs[i];
+ write_string(js, p->key);
+ bputs(fb, ": ");
+ json_write_value(js, p->value);
+ }
+ js->out_indent--;
write_space(js);
- struct json_pair *p = &n->pairs[i];
- write_string(js, p->key);
- bputs(fb, ": ");
- json_write_value(js, p->value);
+ bputc(fb, '}');
}
- js->out_indent--;
- write_space(js);
- bputc(fb, '}');
break;
}
default: