X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=common%2Fjson.hpp;h=14ff501f5681777a19a56b8321643d2e68239388;hb=a27e272aac56c7869fe9dc0444ae124abafe35ac;hp=9e6b96004dc71be9dc96e85a6d4279f508c12765;hpb=ae2b4d32ed56e3ac193cc7205aeb58082c448ce8;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) {