]> git.cworth.org Git - apitrace/blobdiff - common/json.hpp
Factor out object swizzling.
[apitrace] / common / json.hpp
index 9e6b96004dc71be9dc96e85a6d4279f508c12765..14ff501f5681777a19a56b8321643d2e68239388 100644 (file)
@@ -270,6 +270,11 @@ public:
     }
 
     inline void writeString(const char *s) {
+        if (!s) {
+            writeNull();
+            return;
+        }
+
         separator();
         escapeUnicodeString(s);
         value = true;
@@ -301,6 +306,25 @@ public:
         space = ' ';
     }
 
+
+    /**
+     * Special case for char to prevent it to be written as a literal
+     * character.
+     */
+    inline void writeNumber(char n) {
+        separator();
+        os << std::dec << static_cast<int>(n);
+        value = true;
+        space = ' ';
+    }
+
+    inline void writeNumber(unsigned char n) {
+        separator();
+        os << std::dec << static_cast<unsigned>(n);
+        value = true;
+        space = ' ';
+    }
+
     template<class T>
     inline void writeNumber(T n) {
         if (n != n) {