]> mj.ucw.cz Git - libucw.git/blobdiff - ucw-json/format.c
UCW::Configure::Perl: Split off configuration of Perl paths
[libucw.git] / ucw-json / format.c
index 58526c84b2c470493bffda0d86818dd2742cc7a9..227a26b548e7573c399f48b71d6701f15f77915f 100644 (file)
@@ -15,7 +15,6 @@
 #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)
@@ -58,7 +57,7 @@ static void write_string(struct json_context *js, const char *p)
          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);
@@ -68,7 +67,6 @@ static void write_string(struct json_context *js, const char *p)
 
 static void write_number(struct fastbuf *fb, double val)
 {
-  ASSERT(isfinite(val));
   bprintf(fb, "%.*g", DBL_DIG+1, val);
 }
 
@@ -134,21 +132,24 @@ void json_write_value(struct json_context *js, struct json_node *n)
       {
        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: