X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=common%2Fjson.hpp;h=14ff501f5681777a19a56b8321643d2e68239388;hb=f4822bd1a2310e255d7b215bb70f5559aea50d3f;hp=9e6b96004dc71be9dc96e85a6d4279f508c12765;hpb=a8c164caecc408462d3e4c1626c87ab9974f6a48;p=apitrace diff --git a/common/json.hpp b/common/json.hpp index 9e6b960..14ff501 100644 --- a/common/json.hpp +++ b/common/json.hpp @@ -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(n); + value = true; + space = ' '; + } + + inline void writeNumber(unsigned char n) { + separator(); + os << std::dec << static_cast(n); + value = true; + space = ' '; + } + template inline void writeNumber(T n) { if (n != n) {