#include <stddef.h>
#include <wchar.h>
-#include <ostream>
#include <iomanip>
+#include <ostream>
+#include <string>
class JSONWriter
size -= 3;
++written;
- if (written >= 76/4) {
+ if (written >= 76/4 && size) {
os << "\n";
written = 0;
}
if (size > 0) {
c0 = bytes[0] >> 2;
c1 = ((bytes[0] & 0x03) << 4);
+ buf[2] = '=';
+ buf[3] = '=';
if (size > 1) {
c1 |= ((bytes[1] & 0xf0) >> 4);
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];
value = false;
}
+ inline void beginMember(const std::string &name) {
+ beginMember(name.c_str());
+ }
+
inline void endMember(void) {
assert(value);
value = true;
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);
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) {