26 #ifndef RAPIDJSON_WRITER_H_
27 #define RAPIDJSON_WRITER_H_
38 #pragma warning(disable : 4127)
57 template<
typename Stream,
typename Encoding = UTF8<>,
typename Allocator = MemoryPoolAllocator<> >
60 typedef typename Encoding::Ch
Ch;
172 *p++ = (u % 10) +
'0';
179 }
while (p != buffer);
194 *p++ =
char(u64 % 10) +
'0';
201 }
while (p != buffer);
213 bool characterOk<char>(
Ch )
221 static constexpr
int to_int( T t ){
return t; }
224 typename std::enable_if <
to_int(std::numeric_limits<Ch>::max()) <
to_int(256),
bool>::type
231 typename std::enable_if<
to_int(std::numeric_limits<Ch>::max()) >=
to_int(256),
bool>::type
240 int ret = sprintf_s(buffer,
sizeof(buffer),
double_format, d);
242 int ret = snprintf(buffer,
sizeof(buffer),
double_format, d);
245 for (
int i = 0;
i < ret;
i++)
257 for (
int i = 0;
i < ret;
i++)
264 int ret = sprintf_s(buffer,
sizeof(buffer),
"%lld", d);
266 int ret = snprintf(buffer,
sizeof(buffer),
"%lld", d);
269 for (
int i = 0;
i < ret;
i++)
276 int ret = sprintf_s(buffer,
sizeof(buffer),
"%llu", d);
278 int ret = snprintf(buffer,
sizeof(buffer),
"%llu", d);
281 for (
int i = 0;
i < ret;
i++)
286 static const char hexDigits[] =
"0123456789ABCDEF";
287 static const char escape[256] = {
288 #define Z16 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
290 'u',
'u',
'u',
'u',
'u',
'u',
'u',
'u',
'b',
't',
'n',
'u',
'f',
'r',
'u',
'u',
291 'u',
'u',
'u',
'u',
'u',
'u',
'u',
'u',
'u',
'u',
'u',
'u',
'u',
'u',
'u',
'u',
292 0, 0,
'"', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
294 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
'\\', 0, 0, 0,
300 for (
const Ch* p = str; p != str + length; ++p) {
301 if ((
sizeof(
Ch) == 1 ||
characterOk(*p)) && escape[(
unsigned char)*p]) {
304 stream_.Put(escape[(
unsigned char)*p]);
305 if (escape[(
unsigned char)*p] ==
'u') {
308 stream_.Put(hexDigits[(*p) >> 4]);
309 stream_.Put(hexDigits[(*p) & 0xF]);
Concept for allocating, resizing and freeing memory block.
Concept for reading and writing characters.
JSON writer.
Definition: writer.h:58
Writer & Uint(unsigned u)
Definition: writer.h:86
void WriteULongLong(unsigned long long d)
Definition: writer.h:273
Writer & Double(double d)
Definition: writer.h:89
void WriteStartArray()
Definition: writer.h:320
Writer & operator=(const Writer &w)
Writer & LongDouble(long double d)
Definition: writer.h:90
Writer & String(const Ch *str, SizeType length, bool copy=false)
Definition: writer.h:94
Writer & ULongLong(unsigned long long d)
Definition: writer.h:92
Writer & Bool_(bool b)
Definition: writer.h:84
char double_format[32]
Definition: writer.h:76
void WriteString(const Ch *str, SizeType length)
Definition: writer.h:285
std::enable_if< to_int(std::numeric_limits< Ch >::max())< to_int(256), bool >::type characterOk(Ch) { return true;} template< class Ch > typename std::enable_if< to_int(std::numeric_limits< Ch >::max()) >=to_int(256), bool >::type characterOk(Ch c)
Definition: writer.h:232
static const size_t kDefaultLevelDepth
Definition: writer.h:145
static constexpr int to_int(T t)
Definition: writer.h:221
Writer & String(const Ch *str)
Simpler but slower overload.
Definition: writer.h:135
Writer(Stream &stream, int precision=20, Allocator *allocator=0, size_t levelDepth=kDefaultLevelDepth)
Definition: writer.h:62
Writer & EndObject(SizeType memberCount=0)
Definition: writer.h:108
void WriteDouble(double d)
Definition: writer.h:237
void WriteUint(unsigned u)
Definition: writer.h:168
Writer & StartArray()
Definition: writer.h:117
void WriteInt64(int64_t i64)
Definition: writer.h:182
void WriteStartObject()
Definition: writer.h:318
Writer & Uint64(uint64_t u64)
Definition: writer.h:88
Writer & Int64(int64_t i64)
Definition: writer.h:87
void WriteLongDouble(long double d)
Definition: writer.h:249
Encoding::Ch Ch
Definition: writer.h:60
void WriteBool_(bool b)
Definition: writer.h:151
Writer & StartObject()
Definition: writer.h:101
void WriteUint64(uint64_t u64)
Definition: writer.h:190
Writer & Int(int i)
Definition: writer.h:85
internal::Stack< Allocator > level_stack_
Definition: writer.h:342
Stream & stream_
Definition: writer.h:341
void WriteLongLong(long long d)
Definition: writer.h:261
void WriteNull_()
Definition: writer.h:147
void WriteEndObject()
Definition: writer.h:319
Writer & EndArray(SizeType elementCount=0)
Definition: writer.h:124
char long_double_format[32]
Definition: writer.h:77
Writer & LongLong(long long d)
Definition: writer.h:91
void Prefix(Type type)
Definition: writer.h:323
void WriteInt(int i)
Definition: writer.h:160
void WriteEndArray()
Definition: writer.h:321
Writer & Null_()
Definition: writer.h:83
A type-unsafe stack for storing different types of data.
Definition: stack.h:39
const std::complex< Mdouble > i
Definition: ExtendedMath.h:51
SizeType StrLen(const Ch *s)
Custom strlen() which works on different character types.
Definition: strfunc.h:39
Definition: document.h:38
unsigned SizeType
Use 32-bit array/string indices even for 64-bit platform, instead of using size_t.
Definition: rapidjson.h:92
Type
Type of JSON value.
Definition: rapidjson.h:538
@ kArrayType
array
Definition: rapidjson.h:543
@ kNull_Type
null
Definition: rapidjson.h:539
@ kTrueType
true
Definition: rapidjson.h:541
@ kFalseType
false
Definition: rapidjson.h:540
@ kNumberType
number
Definition: rapidjson.h:545
@ kObjectType
object
Definition: rapidjson.h:542
@ kStringType
string
Definition: rapidjson.h:544
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:105
Information for each nested level.
Definition: writer.h:139
Level(bool inArray_)
Definition: writer.h:140
size_t valueCount
number of values in this level
Definition: writer.h:142
bool inArray
true if in array, otherwise in object
Definition: writer.h:141