TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator > Class Template Reference

JSON writer. More...

#include <writer.h>

Classes

struct  Level
 Information for each nested level. More...
 

Public Types

typedef SourceEncoding::Ch Ch
 

Public Member Functions

 Writer (OutputStream &os, StackAllocator *stackAllocator=0, size_t levelDepth=kDefaultLevelDepth)
 Constructor. More...
 
 Writer (StackAllocator *allocator=0, size_t levelDepth=kDefaultLevelDepth)
 
void Reset (OutputStream &os)
 Reset the writer with a new stream. More...
 
bool IsComplete () const
 Checks whether the output is a complete JSON. More...
 
Implementation of Handler
See also
Handler
bool Null ()
 
bool Bool (bool b)
 
bool Int (int i)
 
bool Uint (unsigned u)
 
bool Int64 (int64_t i64)
 
bool Uint64 (uint64_t u64)
 
bool Double (double d)
 Writes the given double value to the stream. More...
 
bool String (const Ch *str, SizeType length, bool copy=false)
 
bool StartObject ()
 
bool Key (const Ch *str, SizeType length, bool copy=false)
 
bool EndObject (SizeType memberCount=0)
 
bool StartArray ()
 
bool EndArray (SizeType elementCount=0)
 
Convenience extensions
bool String (const Ch *str)
 Simpler but slower overload. More...
 
bool Key (const Ch *str)
 

Protected Member Functions

bool WriteNull ()
 
bool WriteBool (bool b)
 
bool WriteInt (int i)
 
bool WriteUint (unsigned u)
 
bool WriteInt64 (int64_t i64)
 
bool WriteUint64 (uint64_t u64)
 
bool WriteDouble (double d)
 
bool WriteString (const Ch *str, SizeType length)
 
bool WriteStartObject ()
 
bool WriteEndObject ()
 
bool WriteStartArray ()
 
bool WriteEndArray ()
 
void Prefix (Type type)
 
template<>
bool WriteInt (int i)
 
template<>
bool WriteUint (unsigned u)
 
template<>
bool WriteInt64 (int64_t i64)
 
template<>
bool WriteUint64 (uint64_t u)
 
template<>
bool WriteDouble (double d)
 

Protected Attributes

OutputStream * os_
 
internal::Stack< StackAllocator > level_stack_
 
bool hasRoot_
 

Static Protected Attributes

static const size_t kDefaultLevelDepth = 32
 

Private Member Functions

 Writer (const Writer &)
 
Writeroperator= (const Writer &)
 

Detailed Description

template<typename OutputStream, typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
class Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >

JSON writer.

Writer implements the concept Handler. It generates JSON text by events to an output os.

User may programmatically calls the functions of a writer to generate JSON text.

On the other side, a writer can also be passed to objects that generates events,

for example Reader::Parse() and Document::Accept().

Template Parameters
OutputStreamType of output stream.
SourceEncodingEncoding of source string.
TargetEncodingEncoding of output stream.
StackAllocatorType of allocator for allocating memory of stack.
Note
implements Handler concept

Member Typedef Documentation

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
typedef SourceEncoding::Ch Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::Ch

Constructor & Destructor Documentation

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::Writer ( OutputStream &  os,
StackAllocator *  stackAllocator = 0,
size_t  levelDepth = kDefaultLevelDepth 
)
inlineexplicit

Constructor.

Parameters
osOutput stream.
stackAllocatorUser supplied allocator. If it is null, it will create a private one.
levelDepthInitial capacity of stack.
64  :
65  os_(&os), level_stack_(stackAllocator, levelDepth * sizeof(Level)), hasRoot_(false) {}
internal::Stack< StackAllocator > level_stack_
Definition: writer.h:338
bool hasRoot_
Definition: writer.h:339
OutputStream * os_
Definition: writer.h:337
template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::Writer ( StackAllocator *  allocator = 0,
size_t  levelDepth = kDefaultLevelDepth 
)
inlineexplicit
68  :
69  os_(0), level_stack_(allocator, levelDepth * sizeof(Level)), hasRoot_(false) {}
internal::Stack< StackAllocator > level_stack_
Definition: writer.h:338
bool hasRoot_
Definition: writer.h:339
OutputStream * os_
Definition: writer.h:337
template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::Writer ( const Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator > &  )
private

Member Function Documentation

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::Bool ( bool  b)
inline
109 { Prefix(b ? kTrueType : kFalseType); return WriteBool(b); }
void Prefix(Type type)
Definition: writer.h:317
false
Definition: rapidjson.h:644
bool WriteBool(bool b)
Definition: writer.h:194
true
Definition: rapidjson.h:645

+ Here is the call graph for this function:

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::Double ( double  d)
inline

Writes the given double value to the stream.

Parameters
dThe value to be written.
Returns
Whether it is succeed.
120 { Prefix(kNumberType); return WriteDouble(d); }
void Prefix(Type type)
Definition: writer.h:317
bool WriteDouble(double d)
Definition: writer.h:236
number
Definition: rapidjson.h:649

+ Here is the call graph for this function:

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::EndArray ( SizeType  elementCount = 0)
inline
159  {
160  (void)elementCount;
161  RAPIDJSON_ASSERT(level_stack_.GetSize() >= sizeof(Level));
162  RAPIDJSON_ASSERT(level_stack_.template Top<Level>()->inArray);
163  level_stack_.template Pop<Level>(1);
164  bool ret = WriteEndArray();
165  if (level_stack_.Empty()) // end of json text
166  os_->Flush();
167  return ret;
168  }
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:344
bool Empty() const
Definition: stack.h:128
internal::Stack< StackAllocator > level_stack_
Definition: writer.h:338
bool WriteEndArray()
Definition: writer.h:315
size_t GetSize() const
Definition: stack.h:129
OutputStream * os_
Definition: writer.h:337

+ Here is the call graph for this function:

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::EndObject ( SizeType  memberCount = 0)
inline
142  {
143  (void)memberCount;
144  RAPIDJSON_ASSERT(level_stack_.GetSize() >= sizeof(Level));
145  RAPIDJSON_ASSERT(!level_stack_.template Top<Level>()->inArray);
146  level_stack_.template Pop<Level>(1);
147  bool ret = WriteEndObject();
148  if (level_stack_.Empty()) // end of json text
149  os_->Flush();
150  return ret;
151  }
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:344
bool Empty() const
Definition: stack.h:128
internal::Stack< StackAllocator > level_stack_
Definition: writer.h:338
bool WriteEndObject()
Definition: writer.h:313
size_t GetSize() const
Definition: stack.h:129
OutputStream * os_
Definition: writer.h:337

+ Here is the call graph for this function:

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::Int ( int  i)
inline
110 { Prefix(kNumberType); return WriteInt(i); }
bool WriteInt(int i)
Definition: writer.h:204
void Prefix(Type type)
Definition: writer.h:317
number
Definition: rapidjson.h:649

+ Here is the call graph for this function:

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::Int64 ( int64_t  i64)
inline
112 { Prefix(kNumberType); return WriteInt64(i64); }
void Prefix(Type type)
Definition: writer.h:317
number
Definition: rapidjson.h:649
bool WriteInt64(int64_t i64)
Definition: writer.h:220

+ Here is the call graph for this function:

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::IsComplete ( ) const
inline

Checks whether the output is a complete JSON.

A complete JSON has a complete root object or array.

99  {
100  return hasRoot_ && level_stack_.Empty();
101  }
bool Empty() const
Definition: stack.h:128
internal::Stack< StackAllocator > level_stack_
Definition: writer.h:338
bool hasRoot_
Definition: writer.h:339

+ Here is the call graph for this function:

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::Key ( const Ch str,
SizeType  length,
bool  copy = false 
)
inline
140 { return String(str, length, copy); }
bool String(const Ch *str, SizeType length, bool copy=false)
Definition: writer.h:122
float length(float v)
Definition: vectorMath.h:208

+ Here is the call graph for this function:

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::Key ( const Ch str)
inline
176 { return Key(str, internal::StrLen(str)); }
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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::Null ( )
inline
108 { Prefix(kNullType); return WriteNull(); }
void Prefix(Type type)
Definition: writer.h:317
bool WriteNull()
Definition: writer.h:190
null
Definition: rapidjson.h:643

+ Here is the call graph for this function:

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
Writer& Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::operator= ( const Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator > &  )
private
template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
void Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::Prefix ( Type  type)
inlineprotected
317  {
318  (void)type;
319  if (level_stack_.GetSize() != 0) { // this value is not at root
320  Level* level = level_stack_.template Top<Level>();
321  if (level->valueCount > 0) {
322  if (level->inArray)
323  os_->Put(','); // add comma if it is not the first element in array
324  else // in object
325  os_->Put((level->valueCount % 2 == 0) ? ',' : ':');
326  }
327  if (!level->inArray && level->valueCount % 2 == 0)
328  RAPIDJSON_ASSERT(type == kStringType); // if it's in object, then even number should be a name
329  level->valueCount++;
330  }
331  else {
332  RAPIDJSON_ASSERT(!hasRoot_); // Should only has one and only one root.
333  hasRoot_ = true;
334  }
335  }
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:344
internal::Stack< StackAllocator > level_stack_
Definition: writer.h:338
string
Definition: rapidjson.h:648
bool hasRoot_
Definition: writer.h:339
size_t GetSize() const
Definition: stack.h:129
OutputStream * os_
Definition: writer.h:337

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename OutputStream , typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
void Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::Reset ( OutputStream &  os)
inline

Reset the writer with a new stream.

This function reset the writer with a new stream and default settings, in order to make a Writer object reusable for output multiple JSONs.

Parameters
osNew output stream.
writer.StartObject();
// ...
writer.EndObject();
writer.Reset(os2);
writer.StartObject();
// ...
writer.EndObject();
89  {
90  os_ = &os;
91  hasRoot_ = false;
93  }
void Clear()
Definition: stack.h:84
internal::Stack< StackAllocator > level_stack_
Definition: writer.h:338
bool hasRoot_
Definition: writer.h:339
OutputStream * os_
Definition: writer.h:337

+ Here is the call graph for this function:

template<typename OutputStream, typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::StartArray ( )
inline
153  {
155  new (level_stack_.template Push<Level>()) Level(true);
156  return WriteStartArray();
157  }
void Prefix(Type type)
Definition: writer.h:317
array
Definition: rapidjson.h:647
bool WriteStartArray()
Definition: writer.h:314
internal::Stack< StackAllocator > level_stack_
Definition: writer.h:338

+ Here is the call graph for this function:

template<typename OutputStream, typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::StartObject ( )
inline
134  {
136  new (level_stack_.template Push<Level>()) Level(false);
137  return WriteStartObject();
138  }
object
Definition: rapidjson.h:646
void Prefix(Type type)
Definition: writer.h:317
internal::Stack< StackAllocator > level_stack_
Definition: writer.h:338
bool WriteStartObject()
Definition: writer.h:312

+ Here is the call graph for this function:

template<typename OutputStream, typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::String ( const Ch str,
SizeType  length,
bool  copy = false 
)
inline
122  {
123  (void)copy;
125  return WriteString(str, length);
126  }
void Prefix(Type type)
Definition: writer.h:317
string
Definition: rapidjson.h:648
bool WriteString(const Ch *str, SizeType length)
Definition: writer.h:244
float length(float v)
Definition: vectorMath.h:208

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename OutputStream, typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::String ( const Ch str)
inline

Simpler but slower overload.

175 { return String(str, internal::StrLen(str)); }
bool String(const Ch *str, SizeType length, bool copy=false)
Definition: writer.h:122
SizeType StrLen(const Ch *s)
Custom strlen() which works on different character types.
Definition: strfunc.h:30

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename OutputStream, typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::Uint ( unsigned  u)
inline
111 { Prefix(kNumberType); return WriteUint(u); }
void Prefix(Type type)
Definition: writer.h:317
number
Definition: rapidjson.h:649
bool WriteUint(unsigned u)
Definition: writer.h:212

+ Here is the call graph for this function:

template<typename OutputStream, typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::Uint64 ( uint64_t  u64)
inline
113 { Prefix(kNumberType); return WriteUint64(u64); }
void Prefix(Type type)
Definition: writer.h:317
number
Definition: rapidjson.h:649
bool WriteUint64(uint64_t u64)
Definition: writer.h:228

+ Here is the call graph for this function:

template<typename OutputStream, typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::WriteBool ( bool  b)
inlineprotected
194  {
195  if (b) {
196  os_->Put('t'); os_->Put('r'); os_->Put('u'); os_->Put('e');
197  }
198  else {
199  os_->Put('f'); os_->Put('a'); os_->Put('l'); os_->Put('s'); os_->Put('e');
200  }
201  return true;
202  }
OutputStream * os_
Definition: writer.h:337

+ Here is the caller graph for this function:

template<typename OutputStream, typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::WriteDouble ( double  d)
inlineprotected
236  {
237  char buffer[25];
238  char* end = internal::dtoa(d, buffer);
239  for (char* p = buffer; p != end; ++p)
240  os_->Put(*p);
241  return true;
242  }
OutputStream * os_
Definition: writer.h:337
char * dtoa(double value, char *buffer)
Definition: dtoa.h:189

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<>
bool Writer< StringBuffer >::WriteDouble ( double  d)
inlineprotected
382  {
383  char *buffer = os_->Push(25);
384  char* end = internal::dtoa(d, buffer);
385  os_->Pop(25 - (end - buffer));
386  return true;
387 }
OutputStream * os_
Definition: writer.h:337
char * dtoa(double value, char *buffer)
Definition: dtoa.h:189

+ Here is the call graph for this function:

template<typename OutputStream, typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::WriteEndArray ( )
inlineprotected
315 { os_->Put(']'); return true; }
OutputStream * os_
Definition: writer.h:337

+ Here is the caller graph for this function:

template<typename OutputStream, typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::WriteEndObject ( )
inlineprotected
313 { os_->Put('}'); return true; }
OutputStream * os_
Definition: writer.h:337

+ Here is the caller graph for this function:

template<typename OutputStream, typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::WriteInt ( int  i)
inlineprotected
204  {
205  char buffer[11];
206  const char* end = internal::i32toa(i, buffer);
207  for (const char* p = buffer; p != end; ++p)
208  os_->Put(*p);
209  return true;
210  }
OutputStream * os_
Definition: writer.h:337
char * i32toa(int32_t value, char *buffer)
Definition: itoa.h:113

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<>
bool Writer< StringBuffer >::WriteInt ( int  i)
inlineprotected
350  {
351  char *buffer = os_->Push(11);
352  const char* end = internal::i32toa(i, buffer);
353  os_->Pop(11 - (end - buffer));
354  return true;
355 }
OutputStream * os_
Definition: writer.h:337
char * i32toa(int32_t value, char *buffer)
Definition: itoa.h:113

+ Here is the call graph for this function:

template<typename OutputStream, typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::WriteInt64 ( int64_t  i64)
inlineprotected
220  {
221  char buffer[21];
222  const char* end = internal::i64toa(i64, buffer);
223  for (const char* p = buffer; p != end; ++p)
224  os_->Put(*p);
225  return true;
226  }
OutputStream * os_
Definition: writer.h:337
char * i64toa(int64_t value, char *buffer)
Definition: itoa.h:291

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<>
bool Writer< StringBuffer >::WriteInt64 ( int64_t  i64)
inlineprotected
366  {
367  char *buffer = os_->Push(21);
368  const char* end = internal::i64toa(i64, buffer);
369  os_->Pop(21 - (end - buffer));
370  return true;
371 }
OutputStream * os_
Definition: writer.h:337
char * i64toa(int64_t value, char *buffer)
Definition: itoa.h:291

+ Here is the call graph for this function:

template<typename OutputStream, typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::WriteNull ( )
inlineprotected
190  {
191  os_->Put('n'); os_->Put('u'); os_->Put('l'); os_->Put('l'); return true;
192  }
OutputStream * os_
Definition: writer.h:337

+ Here is the caller graph for this function:

template<typename OutputStream, typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::WriteStartArray ( )
inlineprotected
314 { os_->Put('['); return true; }
OutputStream * os_
Definition: writer.h:337

+ Here is the caller graph for this function:

template<typename OutputStream, typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::WriteStartObject ( )
inlineprotected
312 { os_->Put('{'); return true; }
OutputStream * os_
Definition: writer.h:337

+ Here is the caller graph for this function:

template<typename OutputStream, typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::WriteString ( const Ch str,
SizeType  length 
)
inlineprotected
244  {
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
248  //0 1 2 3 4 5 6 7 8 9 A B C D E F
249  'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'b', 't', 'n', 'u', 'f', 'r', 'u', 'u', // 00
250  'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', // 10
251  0, 0, '"', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 20
252  Z16, Z16, // 30~4F
253  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,'\\', 0, 0, 0, // 50
254  Z16, Z16, Z16, Z16, Z16, Z16, Z16, Z16, Z16, Z16 // 60~FF
255 #undef Z16
256  };
257 
258  os_->Put('\"');
260  while (is.Tell() < length) {
261  const Ch c = is.Peek();
262  if (!TargetEncoding::supportUnicode && (unsigned)c >= 0x80) {
263  // Unicode escaping
264  unsigned codepoint;
265  if (!SourceEncoding::Decode(is, &codepoint))
266  return false;
267  os_->Put('\\');
268  os_->Put('u');
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]);
274  }
275  else {
276  RAPIDJSON_ASSERT(codepoint >= 0x010000 && codepoint <= 0x10FFFF);
277  // Surrogate pair
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]);
285  os_->Put('\\');
286  os_->Put('u');
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]);
291  }
292  }
293  else if ((sizeof(Ch) == 1 || (unsigned)c < 256) && escape[(unsigned char)c]) {
294  is.Take();
295  os_->Put('\\');
296  os_->Put(escape[(unsigned char)c]);
297  if (escape[(unsigned char)c] == 'u') {
298  os_->Put('0');
299  os_->Put('0');
300  os_->Put(hexDigits[(unsigned char)c >> 4]);
301  os_->Put(hexDigits[(unsigned char)c & 0xF]);
302  }
303  }
304  else
306  return false;
307  }
308  os_->Put('\"');
309  return true;
310  }
Encoding conversion.
Definition: encodings.h:586
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:344
Read-only string stream.
Definition: rapidjson.h:571
SourceEncoding::Ch Ch
Definition: writer.h:56
OutputStream * os_
Definition: writer.h:337
float length(float v)
Definition: vectorMath.h:208
#define Z16
static std::string escape(const std::string &string)
Definition: TextOutput.cpp:77

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename OutputStream, typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::WriteUint ( unsigned  u)
inlineprotected
212  {
213  char buffer[10];
214  const char* end = internal::u32toa(u, buffer);
215  for (const char* p = buffer; p != end; ++p)
216  os_->Put(*p);
217  return true;
218  }
OutputStream * os_
Definition: writer.h:337
char * u32toa(uint32_t value, char *buffer)
Definition: itoa.h:39

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<>
bool Writer< StringBuffer >::WriteUint ( unsigned  u)
inlineprotected
358  {
359  char *buffer = os_->Push(10);
360  const char* end = internal::u32toa(u, buffer);
361  os_->Pop(10 - (end - buffer));
362  return true;
363 }
OutputStream * os_
Definition: writer.h:337
char * u32toa(uint32_t value, char *buffer)
Definition: itoa.h:39

+ Here is the call graph for this function:

template<typename OutputStream, typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::WriteUint64 ( uint64_t  u64)
inlineprotected
228  {
229  char buffer[20];
230  char* end = internal::u64toa(u64, buffer);
231  for (char* p = buffer; p != end; ++p)
232  os_->Put(*p);
233  return true;
234  }
char * u64toa(uint64_t value, char *buffer)
Definition: itoa.h:123
OutputStream * os_
Definition: writer.h:337

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<>
bool Writer< StringBuffer >::WriteUint64 ( uint64_t  u)
inlineprotected
374  {
375  char *buffer = os_->Push(20);
376  const char* end = internal::u64toa(u, buffer);
377  os_->Pop(20 - (end - buffer));
378  return true;
379 }
char * u64toa(uint64_t value, char *buffer)
Definition: itoa.h:123
OutputStream * os_
Definition: writer.h:337

+ Here is the call graph for this function:

Member Data Documentation

template<typename OutputStream, typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
bool Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::hasRoot_
protected
template<typename OutputStream, typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
const size_t Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::kDefaultLevelDepth = 32
staticprotected
template<typename OutputStream, typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
internal::Stack<StackAllocator> Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::level_stack_
protected
template<typename OutputStream, typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator>
OutputStream* Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator >::os_
protected

The documentation for this class was generated from the following file: