X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=json.hpp;h=9e6b96004dc71be9dc96e85a6d4279f508c12765;hb=2b1bd4f71daba2570525eb63aa7b3b66e27259a7;hp=24d9c873930d358980c7750572882c3365d7f631;hpb=63f6397f72aa2978c1b639e4b0da55e01138f1e2;p=apitrace diff --git a/json.hpp b/json.hpp index 24d9c87..9e6b960 100644 --- a/json.hpp +++ b/json.hpp @@ -34,8 +34,9 @@ #include #include -#include #include +#include +#include class JSONWriter @@ -240,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; @@ -271,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); @@ -294,10 +303,15 @@ public: template inline void writeNumber(T n) { - separator(); - os << std::dec << std::setprecision(9) << 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) {