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]);
353 os_->Pop(static_cast<size_t>(11 - (end - buffer)));
361 os_->Pop(static_cast<size_t>(10 - (end - buffer)));
369 os_->Pop(static_cast<size_t>(21 - (end - buffer)));
377 os_->Pop(static_cast<size_t>(20 - (end - buffer)));
385 os_->Pop(static_cast<size_t>(25 - (end - buffer)));
395 #endif // RAPIDJSON_RAPIDJSON_H_
internal::Stack< StackAllocator > level_stack_
char * u64toa(uint64_t value, char *buffer)
Writer & operator=(const Writer &)
RAPIDJSON_NAMESPACE_BEGIN typedef unsigned SizeType
Size type (for string lengths, array sizes, etc.)
bool WriteInt64(int64_t i64)
GLuint GLuint GLsizei GLenum type
void Reset(OutputStream &os)
Reset the writer with a new stream.
bool String(const Ch *str, SizeType length, bool copy=false)
bool Double(double d)
Writes the given double value to the stream.
bool WriteString(const Ch *str, SizeType length)
#define RAPIDJSON_NAMESPACE_BEGIN
provide custom rapidjson namespace (opening expression)
typedef void(GLAPIENTRY *PFNGLCOPYTEXSUBIMAGE3DPROC)(GLenum target
static const size_t kDefaultLevelDepth
GLuint GLsizei GLsizei * length
GLdouble GLdouble GLdouble b
bool WriteUint64(uint64_t u64)
size_t valueCount
number of values in this level
Writer(OutputStream &os, StackAllocator *stackAllocator=0, size_t levelDepth=kDefaultLevelDepth)
Constructor.
bool EndArray(SizeType elementCount=0)
unsigned __int64 uint64_t
#define RAPIDJSON_NAMESPACE_END
provide custom rapidjson namespace (closing expression)
bool WriteUint(unsigned u)
char * u32toa(uint32_t value, char *buffer)
bool Uint64(uint64_t u64)
bool String(const Ch *str)
Simpler but slower overload.
char * dtoa(double value, char *buffer)
Information for each nested level.
bool EndObject(SizeType memberCount=0)
common definitions and configuration
Writer(StackAllocator *allocator=0, size_t levelDepth=kDefaultLevelDepth)
bool WriteDouble(double d)
SizeType StrLen(const Ch *s)
Custom strlen() which works on different character types.
bool IsComplete() const
Checks whether the output is a complete JSON.
char * i64toa(int64_t value, char *buffer)
bool inArray
true if in array, otherwise in object
char * i32toa(int32_t value, char *buffer)
#define RAPIDJSON_ASSERT(x)
Assertion.
bool Key(const Ch *str, SizeType length, bool copy=false)