15 #ifndef RAPIDJSON_WRITER_H_
16 #define RAPIDJSON_WRITER_H_
26 #if RAPIDJSON_HAS_STDSTRING
32 RAPIDJSON_DIAG_OFF(4127)
53 template<
typename OutputStream,
typename SourceEncoding = UTF8<>,
typename TargetEncoding = UTF8<>,
typename StackAllocator = CrtAllocator>
56 typedef typename SourceEncoding::Ch
Ch;
128 #if RAPIDJSON_HAS_STDSTRING
129 bool String(
const std::basic_string<Ch>& str) {
191 os_->Put(
'n');
os_->Put(
'u');
os_->Put(
'l');
os_->Put(
'l');
return true;
196 os_->Put(
't');
os_->Put(
'r');
os_->Put(
'u');
os_->Put(
'e');
199 os_->Put(
'f');
os_->Put(
'a');
os_->Put(
'l');
os_->Put(
's');
os_->Put(
'e');
207 for (
const char* p = buffer; p != end; ++p)
215 for (
const char* p = buffer; p != end; ++p)
223 for (
const char* p = buffer; p != end; ++p)
231 for (
char* p = buffer; p != end; ++p)
239 for (
char* p = buffer; p != end; ++p)
245 static const char hexDigits[16] = {
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'A',
'B',
'C',
'D',
'E',
'F' };
246 static const char escape[256] = {
247 #define Z16 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
249 'u',
'u',
'u',
'u',
'u',
'u',
'u',
'u',
'b',
't',
'n',
'u',
'f',
'r',
'u',
'u',
250 'u',
'u',
'u',
'u',
'u',
'u',
'u',
'u',
'u',
'u',
'u',
'u',
'u',
'u',
'u',
'u',
251 0, 0,
'"', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
253 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
'\\', 0, 0, 0,
261 const Ch c = is.
Peek();
262 if (!TargetEncoding::supportUnicode && (
unsigned)c >= 0x80) {
265 if (!SourceEncoding::Decode(is, &codepoint))
269 if (codepoint <= 0xD7FF || (codepoint >= 0xE000 && codepoint <= 0xFFFF)) {
270 os_->Put(hexDigits[(codepoint >> 12) & 15]);
271 os_->Put(hexDigits[(codepoint >> 8) & 15]);
272 os_->Put(hexDigits[(codepoint >> 4) & 15]);
273 os_->Put(hexDigits[(codepoint ) & 15]);
278 unsigned s = codepoint - 0x010000;
279 unsigned lead = (s >> 10) + 0xD800;
280 unsigned trail = (s & 0x3FF) + 0xDC00;
281 os_->Put(hexDigits[(lead >> 12) & 15]);
282 os_->Put(hexDigits[(lead >> 8) & 15]);
283 os_->Put(hexDigits[(lead >> 4) & 15]);
284 os_->Put(hexDigits[(lead ) & 15]);
287 os_->Put(hexDigits[(trail >> 12) & 15]);
288 os_->Put(hexDigits[(trail >> 8) & 15]);
289 os_->Put(hexDigits[(trail >> 4) & 15]);
290 os_->Put(hexDigits[(trail ) & 15]);
293 else if ((
sizeof(Ch) == 1 || (
unsigned)c < 256) && escape[(
unsigned char)c]) {
296 os_->Put(escape[(
unsigned char)c]);
297 if (escape[(
unsigned char)c] ==
'u') {
300 os_->Put(hexDigits[(
unsigned char)c >> 4]);
301 os_->Put(hexDigits[(
unsigned char)c & 0xF]);
351 char *buffer = os_->Push(11);
353 os_->Pop(11 - (end - buffer));
359 char *buffer = os_->Push(10);
361 os_->Pop(10 - (end - buffer));
367 char *buffer = os_->Push(21);
369 os_->Pop(21 - (end - buffer));
375 char *buffer = os_->Push(20);
377 os_->Pop(20 - (end - buffer));
383 char *buffer = os_->Push(25);
385 os_->Pop(25 - (end - buffer));
395 #endif // RAPIDJSON_RAPIDJSON_H_
bool IsComplete() const
Checks whether the output is a complete JSON.
Definition: writer.h:99
char * u64toa(uint64_t value, char *buffer)
Definition: itoa.h:123
Encoding conversion.
Definition: encodings.h:586
Ch Take()
Definition: rapidjson.h:577
RAPIDJSON_NAMESPACE_BEGIN typedef unsigned SizeType
Size type (for string lengths, array sizes, etc.)
Definition: rapidjson.h:322
Level(bool inArray_)
Definition: writer.h:183
bool WriteInt(int i)
Definition: writer.h:204
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:344
bool StartArray()
Definition: writer.h:153
Writer(OutputStream &os, StackAllocator *stackAllocator=0, size_t levelDepth=kDefaultLevelDepth)
Constructor.
Definition: writer.h:64
JSON writer.
Definition: writer.h:54
object
Definition: rapidjson.h:646
Read-only string stream.
Definition: rapidjson.h:571
bool EndObject(SizeType memberCount=0)
Definition: writer.h:142
void Prefix(Type type)
Definition: writer.h:317
#define RAPIDJSON_NAMESPACE_END
provide custom rapidjson namespace (closing expression)
Definition: rapidjson.h:119
array
Definition: rapidjson.h:647
bool WriteStartArray()
Definition: writer.h:314
bool StartObject()
Definition: writer.h:134
static const size_t kDefaultLevelDepth
Definition: writer.h:188
false
Definition: rapidjson.h:644
size_t valueCount
number of values in this level
Definition: writer.h:184
#define false
Definition: CascPort.h:18
bool Empty() const
Definition: stack.h:128
bool WriteBool(bool b)
Definition: writer.h:194
Ch Peek() const
Definition: rapidjson.h:576
bool Null()
Definition: writer.h:108
void Clear()
Definition: stack.h:84
signed __int64 int64_t
Definition: stdint.h:89
#define RAPIDJSON_NAMESPACE_BEGIN
provide custom rapidjson namespace (opening expression)
Definition: rapidjson.h:116
bool Int64(int64_t i64)
Definition: writer.h:112
bool Bool(bool b)
Definition: writer.h:109
internal::Stack< StackAllocator > level_stack_
Definition: writer.h:338
Writer(StackAllocator *allocator=0, size_t levelDepth=kDefaultLevelDepth)
Definition: writer.h:68
Information for each nested level.
Definition: writer.h:182
bool WriteEndArray()
Definition: writer.h:315
SourceEncoding::Ch Ch
Definition: writer.h:56
string
Definition: rapidjson.h:648
bool hasRoot_
Definition: writer.h:339
bool String(const Ch *str, SizeType length, bool copy=false)
Definition: writer.h:122
bool WriteDouble(double d)
Definition: writer.h:236
bool Uint64(uint64_t u64)
Definition: writer.h:113
bool WriteString(const Ch *str, SizeType length)
Definition: writer.h:244
unsigned __int64 uint64_t
Definition: stdint.h:90
bool WriteEndObject()
Definition: writer.h:313
void Reset(OutputStream &os)
Reset the writer with a new stream.
Definition: writer.h:89
bool Uint(unsigned u)
Definition: writer.h:111
number
Definition: rapidjson.h:649
size_t GetSize() const
Definition: stack.h:129
OutputStream * os_
Definition: writer.h:337
bool WriteStartObject()
Definition: writer.h:312
char * u32toa(uint32_t value, char *buffer)
Definition: itoa.h:39
bool Int(int i)
Definition: writer.h:110
float length(float v)
Definition: vectorMath.h:208
char * dtoa(double value, char *buffer)
Definition: dtoa.h:189
bool inArray
true if in array, otherwise in object
Definition: writer.h:185
bool Double(double d)
Writes the given double value to the stream.
Definition: writer.h:120
bool EndArray(SizeType elementCount=0)
Definition: writer.h:159
static std::string escape(const std::string &string)
Definition: TextOutput.cpp:77
bool String(const Ch *str)
Simpler but slower overload.
Definition: writer.h:175
common definitions and configuration
Writer & operator=(const Writer &)
true
Definition: rapidjson.h:645
bool WriteUint64(uint64_t u64)
Definition: writer.h:228
SizeType StrLen(const Ch *s)
Custom strlen() which works on different character types.
Definition: strfunc.h:30
bool Key(const Ch *str, SizeType length, bool copy=false)
Definition: writer.h:140
bool WriteNull()
Definition: writer.h:190
bool WriteUint(unsigned u)
Definition: writer.h:212
Type
Type of JSON value.
Definition: rapidjson.h:642
size_t Tell() const
Definition: rapidjson.h:578
char * i64toa(int64_t value, char *buffer)
Definition: itoa.h:291
bool Key(const Ch *str)
Definition: writer.h:176
char * i32toa(int32_t value, char *buffer)
Definition: itoa.h:113
null
Definition: rapidjson.h:643
bool WriteInt64(int64_t i64)
Definition: writer.h:220