]> git.cworth.org Git - apitrace/blobdiff - json.hpp
Change filterText to searchText
[apitrace] / json.hpp
index 9c491c552dcab93b94f09b6bef00a1636f0f7c8c..9e6b96004dc71be9dc96e85a6d4279f508c12765 100644 (file)
--- a/json.hpp
+++ b/json.hpp
@@ -34,8 +34,9 @@
 #include <stddef.h>
 #include <wchar.h>
 
-#include <ostream>
 #include <iomanip>
+#include <ostream>
+#include <string>
 
 
 class JSONWriter
@@ -169,7 +170,7 @@ private:
             size -= 3;
             ++written;
 
-            if (written >= 76/4) {
+            if (written >= 76/4 && size) {
                 os << "\n";
                 written = 0;
             }
@@ -178,6 +179,8 @@ private:
         if (size > 0) {
             c0 = bytes[0] >> 2;
             c1 = ((bytes[0] & 0x03) << 4);
+            buf[2] = '=';
+            buf[3] = '=';
             
             if (size > 1) {
                 c1 |= ((bytes[1] & 0xf0) >> 4);
@@ -186,13 +189,8 @@ private:
                     c2 |= ((bytes[2] & 0xc0) >> 6);
                     c3 = bytes[2] & 0x3f;
                     buf[3] = table64[c3];
-                } else {
-                    buf[3] = '=';
                 }
                 buf[2] = table64[c2];
-            } else {
-                buf[3] = '=';
-                buf[2] = '=';
             }
             buf[1] = table64[c1];
             buf[0] = table64[c0];
@@ -243,6 +241,10 @@ public:
         value = false;
     }
 
+    inline void beginMember(const std::string &name) {
+        beginMember(name.c_str());
+    }
+
     inline void endMember(void) {
         assert(value);
         value = true;
@@ -274,6 +276,10 @@ public:
         space = ' ';
     }
 
+    inline void writeString(const std::string &s) {
+        writeString(s.c_str());
+    }
+
     inline void writeBase64(const void *bytes, size_t size) {
         separator();
         encodeBase64String((const unsigned char *)bytes, size);
@@ -297,10 +303,15 @@ public:
 
     template<class T>
     inline void writeNumber(T n) {
-        separator();
-        os << std::dec << n;
-        value = true;
-        space = ' ';
+        if (n != n) {
+            // NaN
+            writeNull();
+        } else {
+            separator();
+            os << std::dec << std::setprecision(9) << n;
+            value = true;
+            space = ' ';
+        }
     }
     
     inline void writeStringMember(const char *name, const char *s) {