|
template<unsigned parseFlags, typename Stream , typename Handler > |
void | ParseObject (Stream &stream, Handler &handler) |
|
template<unsigned parseFlags, typename Stream , typename Handler > |
void | ParseArray (Stream &stream, Handler &handler) |
|
template<unsigned parseFlags, typename Stream , typename Handler > |
void | ParseNaNNull_ (Stream &stream, Handler &handler) |
|
template<unsigned parseFlags, typename Stream , typename Handler > |
void | ParseInfinity (Stream &stream, Handler &handler) |
|
template<unsigned parseFlags, typename Stream , typename Handler > |
void | ParseTrue (Stream &stream, Handler &handler) |
|
template<unsigned parseFlags, typename Stream , typename Handler > |
void | ParseFalse (Stream &stream, Handler &handler) |
|
template<typename Stream > |
unsigned | ParseHex4 (Stream &stream) |
|
template<class Ch > |
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) |
|
template<unsigned parseFlags, typename Stream , typename Handler > |
void | ParseString (Stream &stream, Handler &handler) |
|
template<unsigned parseFlags, typename Stream , typename Handler > |
void | ParseNumber (Stream &stream, Handler &handler) |
|
template<unsigned parseFlags, typename Stream , typename Handler > |
void | ParseValue (Stream &stream, Handler &handler) |
|
template<typename Encoding, typename Allocator = MemoryPoolAllocator<>>
class rapidjson::GenericReader< Encoding, Allocator >
SAX-style JSON parser. Use Reader for UTF8 encoding and default allocator.
GenericReader parses JSON text from a stream, and send events synchronously to an object implementing Handler concept.
It needs to allocate a stack for storing a single decoded string during non-destructive parsing.
For in-situ parsing, the decoded string is directly written to the source text string, no temporary buffer is required.
A GenericReader object can be reused for parsing multiple JSON text.
- Template Parameters
-
Encoding | Encoding of both the stream and the parse output. |
Allocator | Allocator type for stack. |
template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>
template<unsigned parseFlags, typename Stream , typename Handler >
Parse JSON text.
- Template Parameters
-
parseFlags | Combination of ParseFlag. |
Stream | Type of input stream. |
Handler | Type of handler which must implement Handler concept. |
- Parameters
-
stream | Input stream to be parsed. |
handler | The handler to receive events. |
- Returns
- Whether the parsing is successful.
255 #pragma warning(push)
256 #pragma warning(disable : 4611)
268 if (stream.Peek() ==
'\0')
271 switch (stream.Peek()) {
272 case '{': ParseObject<parseFlags>(stream, handler);
break;
273 case '[': ParseArray<parseFlags>(stream, handler);
break;
278 if (stream.Peek() !=
'\0' && stream.Peek() !=
static_cast<Ch>(std::char_traits<Ch>::eof()))
jmp_buf jmpbuf_
setjmp buffer for fast exit from nested parsing function calls.
Definition: reader.h:759
Encoding::Ch Ch
Definition: reader.h:233
void SkipWhitespace(Stream &stream)
Skip the JSON white spaces in a stream.
Definition: reader.h:130
#define RAPIDJSON_PARSE_ERROR(msg, offset)
Definition: reader.h:54
References rapidjson::GenericReader< Encoding, Allocator >::errorOffset_, rapidjson::GenericReader< Encoding, Allocator >::jmpbuf_, rapidjson::GenericReader< Encoding, Allocator >::parseError_, RAPIDJSON_PARSE_ERROR, rapidjson::SkipWhitespace(), and rapidjson::GenericReader< Encoding, Allocator >::stack_.
template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>
template<unsigned parseFlags, typename Stream , typename Handler >
565 if (s.Peek() ==
'-') {
572 bool try64bit =
false;
573 if (s.Peek() ==
'0') {
577 else if (s.Peek() >=
'1' && s.Peek() <=
'9') {
581 while (s.Peek() >=
'0' && s.Peek() <=
'9') {
582 if (
i >= 214748364) {
583 if (
i != 214748364 || s.Peek() >
'8') {
588 i =
i * 10 + (s.Take() -
'0');
591 while (s.Peek() >=
'0' && s.Peek() <=
'9') {
592 if (
i >= 429496729) {
593 if (
i != 429496729 || s.Peek() >
'5') {
598 i =
i * 10 + (s.Take() -
'0');
608 bool useDouble =
false;
612 while (s.Peek() >=
'0' && s.Peek() <=
'9') {
613 if (i64 >= 922337203685477580uLL)
614 if (i64 != 922337203685477580uLL || s.Peek() >
'8') {
618 i64 = i64 * 10 + (s.Take() -
'0');
621 while (s.Peek() >=
'0' && s.Peek() <=
'9') {
622 if (i64 >= 1844674407370955161uLL)
623 if (i64 != 1844674407370955161uLL || s.Peek() >
'5') {
627 i64 = i64 * 10 + (s.Take() -
'0');
635 while (s.Peek() >=
'0' && s.Peek() <=
'9') {
640 d = d * 10 + (s.Take() -
'0');
646 if (s.Peek() ==
'.') {
648 d = try64bit ? (
double)i64 : (
double)
i;
653 if (s.Peek() >=
'0' && s.Peek() <=
'9') {
654 d = d * 10 + (s.Take() -
'0');
662 while (s.Peek() >=
'0' && s.Peek() <=
'9') {
664 d = d * 10 + (s.Peek() -
'0');
673 if (s.Peek() ==
'e' || s.Peek() ==
'E') {
675 d = try64bit ? (
double)i64 : (
double)
i;
680 bool expMinus =
false;
683 else if (s.Peek() ==
'-') {
688 if (s.Peek() >=
'0' && s.Peek() <=
'9') {
689 exp = s.Take() -
'0';
690 while (s.Peek() >=
'0' && s.Peek() <=
'9') {
691 exp =
exp * 10 + (s.Take() -
'0');
694 std::stringstream ss;
695 ss.precision( std::numeric_limits<double>::max_digits10 );
701 if( std::fpclassify( dd ) == FP_SUBNORMAL )
702 handler.Double( dd );
722 handler.Double(minus ? -d : d);
727 handler.Int64(-(int64_t)i64);
733 handler.Int(-(
int)
i);
Mdouble exp(Mdouble Exponent)
Definition: ExtendedMath.cc:84
double Pow10(int n)
Computes integer powers of 10 in double (10.0^n).
Definition: pow10.h:37
References mathsFunc::exp(), constants::i, rapidjson::internal::Pow10(), and RAPIDJSON_PARSE_ERROR.
template<typename Encoding , typename Allocator = MemoryPoolAllocator<>>
template<unsigned parseFlags, typename Stream , typename Handler >
464 #define Z16 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
465 static const Ch escape[256] = {
466 Z16,
Z16, 0, 0,
'\"', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
'/',
467 Z16,
Z16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
'\\', 0, 0, 0,
468 0, 0,
'\b', 0, 0, 0,
'\f', 0, 0, 0, 0, 0, 0, 0,
'\n', 0,
469 0, 0,
'\r', 0,
'\t', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
484 #define RAPIDJSON_PUT(x) \
486 if (parseFlags & kParseInsituFlag) \
489 *stack_.template Push<Ch>() = x; \
498 if ((
sizeof(
Ch) == 1 ||
characterOk(e)) && escape[(
unsigned char)e])
502 if (codepoint >= 0xD800 && codepoint <= 0xDBFF) {
503 if (s.Take() !=
'\\' || s.Take() !=
'u') {
508 if (codepoint2 < 0xDC00 || codepoint2 > 0xDFFF) {
512 codepoint = (((codepoint - 0xD800) << 10) | (codepoint2 - 0xDC00)) + 0x10000;
516 SizeType count =
SizeType(Encoding::Encode(buffer, codepoint) - &buffer[0]);
522 memcpy(
stack_.template Push<Ch>(count), buffer, count *
sizeof(
Ch));
533 size_t length = s.PutEnd(head);
536 handler.String(head,
SizeType(length),
false);
540 handler.String(
stack_.template Pop<Ch>(len), len - 1,
true);
545 else if (c ==
'\0') {
549 else if ((
unsigned)c < 0x20) {
unsigned ParseHex4(Stream &stream)
Definition: reader.h:409
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: reader.h:457
@ kParseInsituFlag
In-situ(destructive) parsing.
Definition: reader.h:69
References rapidjson::GenericReader< Encoding, Allocator >::characterOk(), constants::i, rapidjson::kParseInsituFlag, rapidjson::GenericReader< Encoding, Allocator >::ParseHex4(), RAPIDJSON_ASSERT, RAPIDJSON_PARSE_ERROR, RAPIDJSON_PUT, rapidjson::GenericReader< Encoding, Allocator >::stack_, and Z16.