15 #ifndef RAPIDJSON_READER_H_ 16 #define RAPIDJSON_READER_H_ 28 #if defined(RAPIDJSON_SIMD) && defined(_MSC_VER) 30 #pragma intrinsic(_BitScanForward) 32 #ifdef RAPIDJSON_SSE42 33 #include <nmmintrin.h> 34 #elif defined(RAPIDJSON_SSE2) 35 #include <emmintrin.h> 36 #elif defined(RAPIDJSON_NEON) 42 RAPIDJSON_DIAG_OFF(4127)
43 RAPIDJSON_DIAG_OFF(4702)
48 RAPIDJSON_DIAG_OFF(old-style-cast)
49 RAPIDJSON_DIAG_OFF(padded)
50 RAPIDJSON_DIAG_OFF(switch-enum)
55 RAPIDJSON_DIAG_OFF(effc++)
59 #define RAPIDJSON_NOTHING 60 #ifndef RAPIDJSON_PARSE_ERROR_EARLY_RETURN 61 #define RAPIDJSON_PARSE_ERROR_EARLY_RETURN(value) \ 62 RAPIDJSON_MULTILINEMACRO_BEGIN \ 63 if (RAPIDJSON_UNLIKELY(HasParseError())) { return value; } \ 64 RAPIDJSON_MULTILINEMACRO_END 66 #define RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID \ 67 RAPIDJSON_PARSE_ERROR_EARLY_RETURN(RAPIDJSON_NOTHING) 100 #ifndef RAPIDJSON_PARSE_ERROR_NORETURN 101 #define RAPIDJSON_PARSE_ERROR_NORETURN(parseErrorCode, offset) \ 102 RAPIDJSON_MULTILINEMACRO_BEGIN \ 103 RAPIDJSON_ASSERT(!HasParseError()); \ 104 SetParseError(parseErrorCode, offset); \ 105 RAPIDJSON_MULTILINEMACRO_END 119 #ifndef RAPIDJSON_PARSE_ERROR 120 #define RAPIDJSON_PARSE_ERROR(parseErrorCode, offset) \ 121 RAPIDJSON_MULTILINEMACRO_BEGIN \ 122 RAPIDJSON_PARSE_ERROR_NORETURN(parseErrorCode, offset); \ 123 RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID; \ 124 RAPIDJSON_MULTILINEMACRO_END 140 #ifndef RAPIDJSON_PARSE_DEFAULT_FLAGS 141 #define RAPIDJSON_PARSE_DEFAULT_FLAGS kParseNoFlags 197 template<
typename Encoding = UTF8<>,
typename Derived =
void>
199 typedef typename Encoding::Ch
Ch;
204 bool Null() {
return static_cast<Override&
>(*this).Default(); }
205 bool Bool(
bool) {
return static_cast<Override&
>(*this).Default(); }
206 bool Int(
int) {
return static_cast<Override&
>(*this).Default(); }
207 bool Uint(
unsigned) {
return static_cast<Override&
>(*this).Default(); }
208 bool Int64(
int64_t) {
return static_cast<Override&
>(*this).Default(); }
210 bool Double(
double) {
return static_cast<Override&
>(*this).Default(); }
212 bool RawNumber(
const Ch* str,
SizeType len,
bool copy) {
return static_cast<Override&
>(*this).String(str, len, copy); }
213 bool String(
const Ch*,
SizeType,
bool) {
return static_cast<Override&
>(*this).Default(); }
214 bool StartObject() {
return static_cast<Override&
>(*this).Default(); }
215 bool Key(
const Ch* str,
SizeType len,
bool copy) {
return static_cast<Override&
>(*this).String(str, len, copy); }
217 bool StartArray() {
return static_cast<Override&
>(*this).Default(); }
226 template<typename Stream, int = StreamTraits<Stream>::copyOptimization>
230 template<
typename Stream>
245 template<
typename Stream>
265 template<
typename InputStream>
268 InputStream&
s(copy.s);
270 typename InputStream::Ch c;
271 while ((c = s.Peek()) ==
' ' || c ==
'\n' || c ==
'\r' || c ==
'\t')
276 while (p != end && (*p ==
' ' || *p ==
'\n' || *p ==
'\r' || *p ==
'\t'))
281 #ifdef RAPIDJSON_SSE42 282 inline const char *SkipWhitespace_SIMD(
const char* p) {
285 if (*p ==
' ' || *p ==
'\n' || *p ==
'\r' || *p ==
'\t')
291 const char* nextAligned =
reinterpret_cast<const char*
>((
reinterpret_cast<size_t>(p) + 15) &
static_cast<size_t>(~15));
292 while (p != nextAligned)
293 if (*p ==
' ' || *p ==
'\n' || *p ==
'\r' || *p ==
'\t')
299 static const char whitespace[16] =
" \n\r\t";
300 const __m128i w = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&whitespace[0]));
303 const __m128i
s = _mm_load_si128(reinterpret_cast<const __m128i *>(p));
304 const int r = _mm_cmpistri(w, s, _SIDD_UBYTE_OPS | _SIDD_CMP_EQUAL_ANY | _SIDD_LEAST_SIGNIFICANT | _SIDD_NEGATIVE_POLARITY);
310 inline const char *SkipWhitespace_SIMD(
const char* p,
const char* end) {
312 if (p != end && (*p ==
' ' || *p ==
'\n' || *p ==
'\r' || *p ==
'\t'))
318 static const char whitespace[16] =
" \n\r\t";
319 const __m128i w = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&whitespace[0]));
321 for (; p <= end - 16; p += 16) {
322 const __m128i
s = _mm_loadu_si128(reinterpret_cast<const __m128i *>(p));
323 const int r = _mm_cmpistri(w, s, _SIDD_UBYTE_OPS | _SIDD_CMP_EQUAL_ANY | _SIDD_LEAST_SIGNIFICANT | _SIDD_NEGATIVE_POLARITY);
331 #elif defined(RAPIDJSON_SSE2) 334 inline const char *SkipWhitespace_SIMD(
const char* p) {
336 if (*p ==
' ' || *p ==
'\n' || *p ==
'\r' || *p ==
'\t')
342 const char* nextAligned =
reinterpret_cast<const char*
>((
reinterpret_cast<size_t>(p) + 15) &
static_cast<size_t>(~15));
343 while (p != nextAligned)
344 if (*p ==
' ' || *p ==
'\n' || *p ==
'\r' || *p ==
'\t')
350 #define C16(c) { c, c, c, c, c, c, c, c, c, c, c, c, c, c, c, c } 351 static const char whitespaces[4][16] = { C16(
' '), C16(
'\n'), C16(
'\r'), C16(
'\t') };
354 const __m128i w0 = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&whitespaces[0][0]));
355 const __m128i w1 = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&whitespaces[1][0]));
356 const __m128i w2 = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&whitespaces[2][0]));
357 const __m128i w3 = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&whitespaces[3][0]));
360 const __m128i
s = _mm_load_si128(reinterpret_cast<const __m128i *>(p));
361 __m128i x = _mm_cmpeq_epi8(s, w0);
362 x = _mm_or_si128(x, _mm_cmpeq_epi8(s, w1));
363 x = _mm_or_si128(x, _mm_cmpeq_epi8(s, w2));
364 x = _mm_or_si128(x, _mm_cmpeq_epi8(s, w3));
365 unsigned short r =
static_cast<unsigned short>(~_mm_movemask_epi8(x));
367 #ifdef _MSC_VER // Find the index of first non-whitespace 368 unsigned long offset;
369 _BitScanForward(&offset, r);
372 return p + __builtin_ffs(r) - 1;
378 inline const char *SkipWhitespace_SIMD(
const char* p,
const char* end) {
380 if (p != end && (*p ==
' ' || *p ==
'\n' || *p ==
'\r' || *p ==
'\t'))
386 #define C16(c) { c, c, c, c, c, c, c, c, c, c, c, c, c, c, c, c } 387 static const char whitespaces[4][16] = { C16(
' '), C16(
'\n'), C16(
'\r'), C16(
'\t') };
390 const __m128i w0 = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&whitespaces[0][0]));
391 const __m128i w1 = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&whitespaces[1][0]));
392 const __m128i w2 = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&whitespaces[2][0]));
393 const __m128i w3 = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&whitespaces[3][0]));
395 for (; p <= end - 16; p += 16) {
396 const __m128i
s = _mm_loadu_si128(reinterpret_cast<const __m128i *>(p));
397 __m128i x = _mm_cmpeq_epi8(s, w0);
398 x = _mm_or_si128(x, _mm_cmpeq_epi8(s, w1));
399 x = _mm_or_si128(x, _mm_cmpeq_epi8(s, w2));
400 x = _mm_or_si128(x, _mm_cmpeq_epi8(s, w3));
401 unsigned short r =
static_cast<unsigned short>(~_mm_movemask_epi8(x));
403 #ifdef _MSC_VER // Find the index of first non-whitespace 404 unsigned long offset;
405 _BitScanForward(&offset, r);
408 return p + __builtin_ffs(r) - 1;
416 #elif defined(RAPIDJSON_NEON) 419 inline const char *SkipWhitespace_SIMD(
const char* p) {
421 if (*p ==
' ' || *p ==
'\n' || *p ==
'\r' || *p ==
'\t')
427 const char* nextAligned =
reinterpret_cast<const char*
>((
reinterpret_cast<size_t>(p) + 15) &
static_cast<size_t>(~15));
428 while (p != nextAligned)
429 if (*p ==
' ' || *p ==
'\n' || *p ==
'\r' || *p ==
'\t')
434 const uint8x16_t w0 = vmovq_n_u8(
' ');
435 const uint8x16_t w1 = vmovq_n_u8(
'\n');
436 const uint8x16_t w2 = vmovq_n_u8(
'\r');
437 const uint8x16_t w3 = vmovq_n_u8(
'\t');
440 const uint8x16_t
s = vld1q_u8(reinterpret_cast<const uint8_t *>(p));
441 uint8x16_t x = vceqq_u8(s, w0);
442 x = vorrq_u8(x, vceqq_u8(s, w1));
443 x = vorrq_u8(x, vceqq_u8(s, w2));
444 x = vorrq_u8(x, vceqq_u8(s, w3));
448 uint64_t low = vgetq_lane_u64(reinterpret_cast<uint64x2_t>(x), 0);
449 uint64_t high = vgetq_lane_u64(reinterpret_cast<uint64x2_t>(x), 1);
453 int lz =__builtin_clzll(high);;
454 return p + 8 + (lz >> 3);
457 int lz = __builtin_clzll(low);;
458 return p + (lz >> 3);
463 inline const char *SkipWhitespace_SIMD(
const char* p,
const char* end) {
465 if (p != end && (*p ==
' ' || *p ==
'\n' || *p ==
'\r' || *p ==
'\t'))
470 const uint8x16_t w0 = vmovq_n_u8(
' ');
471 const uint8x16_t w1 = vmovq_n_u8(
'\n');
472 const uint8x16_t w2 = vmovq_n_u8(
'\r');
473 const uint8x16_t w3 = vmovq_n_u8(
'\t');
475 for (; p <= end - 16; p += 16) {
476 const uint8x16_t
s = vld1q_u8(reinterpret_cast<const uint8_t *>(p));
477 uint8x16_t x = vceqq_u8(s, w0);
478 x = vorrq_u8(x, vceqq_u8(s, w1));
479 x = vorrq_u8(x, vceqq_u8(s, w2));
480 x = vorrq_u8(x, vceqq_u8(s, w3));
484 uint64_t low = vgetq_lane_u64(reinterpret_cast<uint64x2_t>(x), 0);
485 uint64_t high = vgetq_lane_u64(reinterpret_cast<uint64x2_t>(x), 1);
489 int lz = __builtin_clzll(high);
490 return p + 8 + (lz >> 3);
493 int lz = __builtin_clzll(low);
494 return p + (lz >> 3);
501 #endif // RAPIDJSON_NEON 503 #ifdef RAPIDJSON_SIMD 506 is.
src_ =
const_cast<char*
>(SkipWhitespace_SIMD(is.
src_));
511 is.
src_ = SkipWhitespace_SIMD(is.
src_);
515 is.is_.
src_ = SkipWhitespace_SIMD(is.is_.
src_, is.is_.end_);
517 #endif // RAPIDJSON_SIMD 538 template <
typename SourceEncoding,
typename TargetEncoding,
typename StackAllocator = CrtAllocator>
541 typedef typename SourceEncoding::Ch
Ch;
547 GenericReader(StackAllocator* stackAllocator = 0,
size_t stackCapacity = kDefaultStackCapacity) : stack_(stackAllocator, stackCapacity), parseResult_() {}
557 template <
unsigned parseFlags,
typename InputStream,
typename Handler>
560 return IterativeParse<parseFlags>(is, handler);
562 parseResult_.
Clear();
564 ClearStackOnExit scope(*
this);
566 SkipWhitespaceAndComments<parseFlags>(is);
567 RAPIDJSON_PARSE_ERROR_EARLY_RETURN(parseResult_);
571 RAPIDJSON_PARSE_ERROR_EARLY_RETURN(parseResult_);
574 ParseValue<parseFlags>(is, handler);
575 RAPIDJSON_PARSE_ERROR_EARLY_RETURN(parseResult_);
578 SkipWhitespaceAndComments<parseFlags>(is);
579 RAPIDJSON_PARSE_ERROR_EARLY_RETURN(parseResult_);
583 RAPIDJSON_PARSE_ERROR_EARLY_RETURN(parseResult_);
598 template <
typename InputStream,
typename Handler>
600 return Parse<kParseDefaultFlags>(is, handler);
607 parseResult_.Clear();
608 state_ = IterativeParsingStartState;
618 template <
unsigned parseFlags,
typename InputStream,
typename Handler>
621 SkipWhitespaceAndComments<parseFlags>(is);
623 Token t = Tokenize(is.Peek());
630 if (d == IterativeParsingErrorState) {
631 HandleError(state_, is);
642 SkipWhitespaceAndComments<parseFlags>(is);
643 if (is.Peek() !=
'\0') {
645 HandleError(state_, is);
658 if (!IsIterativeParsingDelimiterState(n))
665 if (state_ != IterativeParsingFinishState) {
666 HandleError(state_, is);
677 return IsIterativeParsingCompleteState(state_);
709 template<
unsigned parseFlags,
typename InputStream>
715 if (Consume(is,
'*')) {
719 else if (Consume(is,
'*')) {
720 if (Consume(is,
'/'))
728 while (is.Peek() !=
'\0' && is.Take() !=
'\n') {}
738 template<
unsigned parseFlags,
typename InputStream,
typename Handler>
746 SkipWhitespaceAndComments<parseFlags>(is);
747 RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
749 if (Consume(is,
'}')) {
759 ParseString<parseFlags>(is, handler,
true);
760 RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
762 SkipWhitespaceAndComments<parseFlags>(is);
763 RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
768 SkipWhitespaceAndComments<parseFlags>(is);
769 RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
771 ParseValue<parseFlags>(is, handler);
772 RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
774 SkipWhitespaceAndComments<parseFlags>(is);
775 RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
782 SkipWhitespaceAndComments<parseFlags>(is);
783 RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
795 if (is.Peek() ==
'}') {
806 template<
unsigned parseFlags,
typename InputStream,
typename Handler>
814 SkipWhitespaceAndComments<parseFlags>(is);
815 RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
817 if (Consume(is,
']')) {
824 ParseValue<parseFlags>(is, handler);
825 RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
828 SkipWhitespaceAndComments<parseFlags>(is);
829 RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
831 if (Consume(is,
',')) {
832 SkipWhitespaceAndComments<parseFlags>(is);
833 RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
835 else if (Consume(is,
']')) {
844 if (is.Peek() ==
']') {
854 template<
unsigned parseFlags,
typename InputStream,
typename Handler>
859 if (
RAPIDJSON_LIKELY(Consume(is,
'u') && Consume(is,
'l') && Consume(is,
'l'))) {
867 template<
unsigned parseFlags,
typename InputStream,
typename Handler>
872 if (
RAPIDJSON_LIKELY(Consume(is,
'r') && Consume(is,
'u') && Consume(is,
'e'))) {
880 template<
unsigned parseFlags,
typename InputStream,
typename Handler>
885 if (
RAPIDJSON_LIKELY(Consume(is,
'a') && Consume(is,
'l') && Consume(is,
's') && Consume(is,
'e'))) {
893 template<
typename InputStream>
894 RAPIDJSON_FORCEINLINE
static bool Consume(InputStream& is,
typename InputStream::Ch expect) {
904 template<
typename InputStream>
905 unsigned ParseHex4(InputStream& is,
size_t escapeOffset) {
906 unsigned codepoint = 0;
907 for (
int i = 0; i < 4; i++) {
910 codepoint +=
static_cast<unsigned>(c);
911 if (c >=
'0' && c <=
'9')
913 else if (c >=
'A' && c <=
'F')
914 codepoint -=
'A' - 10;
915 else if (c >=
'a' && c <=
'f')
916 codepoint -=
'a' - 10;
919 RAPIDJSON_PARSE_ERROR_EARLY_RETURN(0);
926 template <
typename CharType>
932 RAPIDJSON_FORCEINLINE
void Put(Ch c) {
933 *stack_.template Push<Ch>() = c;
939 return stack_.template Push<Ch>(count);
942 size_t Length()
const {
return length_; }
945 return stack_.template Pop<Ch>(length_);
957 template<
unsigned parseFlags,
typename InputStream,
typename Handler>
958 void ParseString(InputStream& is, Handler& handler,
bool isKey =
false) {
960 InputStream&
s(copy.s);
965 bool success =
false;
967 typename InputStream::Ch *head = s.PutBegin();
968 ParseStringToStream<parseFlags, SourceEncoding, SourceEncoding>(s, s);
969 RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
970 size_t length = s.PutEnd(head) - 1;
972 const typename TargetEncoding::Ch*
const str =
reinterpret_cast<typename TargetEncoding::Ch*
>(head);
973 success = (isKey ? handler.Key(str,
SizeType(length),
false) : handler.String(str,
SizeType(length),
false));
976 StackStream<typename TargetEncoding::Ch> stackStream(stack_);
977 ParseStringToStream<parseFlags, SourceEncoding, TargetEncoding>(s, stackStream);
978 RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
980 const typename TargetEncoding::Ch*
const str = stackStream.Pop();
981 success = (isKey ? handler.Key(str, length,
true) : handler.String(str, length,
true));
989 template<
unsigned parseFlags,
typename SEncoding,
typename TEncoding,
typename InputStream,
typename OutputStream>
992 #define Z16 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 993 static const char escape[256] = {
994 Z16,
Z16, 0, 0,
'\"', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
'/',
995 Z16,
Z16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
'\\', 0, 0, 0,
996 0, 0,
'\b', 0, 0, 0,
'\f', 0, 0, 0, 0, 0, 0, 0,
'\n', 0,
997 0, 0,
'\r', 0,
'\t', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1006 ScanCopyUnescapedString(is, os);
1010 size_t escapeOffset = is.Tell();
1013 if ((
sizeof(Ch) == 1 ||
unsigned(e) < 256) &&
RAPIDJSON_LIKELY(escape[static_cast<unsigned char>(e)])) {
1015 os.Put(static_cast<typename TEncoding::Ch>(escape[static_cast<unsigned char>(e)]));
1019 unsigned codepoint = ParseHex4(is, escapeOffset);
1020 RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
1025 unsigned codepoint2 = ParseHex4(is, escapeOffset);
1026 RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
1029 codepoint = (((codepoint - 0xD800) << 10) | (codepoint2 - 0xDC00)) + 0x10000;
1031 TEncoding::Encode(os, codepoint);
1048 size_t offset = is.Tell();
1057 template<
typename InputStream,
typename OutputStream>
1062 #if defined(RAPIDJSON_SSE2) || defined(RAPIDJSON_SSE42) 1064 static RAPIDJSON_FORCEINLINE
void ScanCopyUnescapedString(
StringStream& is, StackStream<char>& os) {
1065 const char* p = is.
src_;
1068 const char* nextAligned =
reinterpret_cast<const char*
>((
reinterpret_cast<size_t>(p) + 15) &
static_cast<size_t>(~15));
1069 while (p != nextAligned)
1078 static const char dquote[16] = {
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"' };
1079 static const char bslash[16] = {
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\' };
1080 static const char space[16] = { 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F };
1081 const __m128i dq = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&dquote[0]));
1082 const __m128i bs = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&bslash[0]));
1083 const __m128i sp = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&space[0]));
1086 const __m128i
s = _mm_load_si128(reinterpret_cast<const __m128i *>(p));
1087 const __m128i t1 = _mm_cmpeq_epi8(s, dq);
1088 const __m128i t2 = _mm_cmpeq_epi8(s, bs);
1089 const __m128i t3 = _mm_cmpeq_epi8(_mm_max_epu8(s, sp), sp);
1090 const __m128i x = _mm_or_si128(_mm_or_si128(t1, t2), t3);
1091 unsigned short r =
static_cast<unsigned short>(_mm_movemask_epi8(x));
1094 #ifdef _MSC_VER // Find the index of first escaped 1095 unsigned long offset;
1096 _BitScanForward(&offset, r);
1099 length =
static_cast<SizeType>(__builtin_ffs(r) - 1);
1102 char* q =
reinterpret_cast<char*
>(os.Push(length));
1103 for (
size_t i = 0; i < length; i++)
1110 _mm_storeu_si128(reinterpret_cast<__m128i *>(os.Push(16)), s);
1122 SkipUnescapedString(is);
1130 const char* nextAligned =
reinterpret_cast<const char*
>((
reinterpret_cast<size_t>(p) + 15) &
static_cast<size_t>(~15));
1131 while (p != nextAligned)
1141 static const char dquote[16] = {
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"' };
1142 static const char bslash[16] = {
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\' };
1143 static const char space[16] = { 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F };
1144 const __m128i dq = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&dquote[0]));
1145 const __m128i bs = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&bslash[0]));
1146 const __m128i sp = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&space[0]));
1148 for (;; p += 16, q += 16) {
1149 const __m128i
s = _mm_load_si128(reinterpret_cast<const __m128i *>(p));
1150 const __m128i t1 = _mm_cmpeq_epi8(s, dq);
1151 const __m128i t2 = _mm_cmpeq_epi8(s, bs);
1152 const __m128i t3 = _mm_cmpeq_epi8(_mm_max_epu8(s, sp), sp);
1153 const __m128i x = _mm_or_si128(_mm_or_si128(t1, t2), t3);
1154 unsigned short r =
static_cast<unsigned short>(_mm_movemask_epi8(x));
1157 #ifdef _MSC_VER // Find the index of first escaped 1158 unsigned long offset;
1159 _BitScanForward(&offset, r);
1162 length =
static_cast<size_t>(__builtin_ffs(r) - 1);
1164 for (
const char* pend = p + length; p != pend; )
1168 _mm_storeu_si128(reinterpret_cast<__m128i *>(q), s);
1181 const char* nextAligned =
reinterpret_cast<const char*
>((
reinterpret_cast<size_t>(p) + 15) &
static_cast<size_t>(~15));
1182 for (; p != nextAligned; p++)
1189 static const char dquote[16] = {
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"' };
1190 static const char bslash[16] = {
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\' };
1191 static const char space[16] = { 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F };
1192 const __m128i dq = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&dquote[0]));
1193 const __m128i bs = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&bslash[0]));
1194 const __m128i sp = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&space[0]));
1197 const __m128i
s = _mm_load_si128(reinterpret_cast<const __m128i *>(p));
1198 const __m128i t1 = _mm_cmpeq_epi8(s, dq);
1199 const __m128i t2 = _mm_cmpeq_epi8(s, bs);
1200 const __m128i t3 = _mm_cmpeq_epi8(_mm_max_epu8(s, sp), sp);
1201 const __m128i x = _mm_or_si128(_mm_or_si128(t1, t2), t3);
1202 unsigned short r =
static_cast<unsigned short>(_mm_movemask_epi8(x));
1205 #ifdef _MSC_VER // Find the index of first escaped 1206 unsigned long offset;
1207 _BitScanForward(&offset, r);
1210 length =
static_cast<size_t>(__builtin_ffs(r) - 1);
1219 #elif defined(RAPIDJSON_NEON) 1221 static RAPIDJSON_FORCEINLINE
void ScanCopyUnescapedString(
StringStream& is, StackStream<char>& os) {
1222 const char* p = is.
src_;
1225 const char* nextAligned =
reinterpret_cast<const char*
>((
reinterpret_cast<size_t>(p) + 15) &
static_cast<size_t>(~15));
1226 while (p != nextAligned)
1235 const uint8x16_t s0 = vmovq_n_u8(
'"');
1236 const uint8x16_t s1 = vmovq_n_u8(
'\\');
1237 const uint8x16_t s2 = vmovq_n_u8(
'\b');
1238 const uint8x16_t s3 = vmovq_n_u8(32);
1241 const uint8x16_t
s = vld1q_u8(reinterpret_cast<const uint8_t *>(p));
1242 uint8x16_t x = vceqq_u8(s, s0);
1243 x = vorrq_u8(x, vceqq_u8(s, s1));
1244 x = vorrq_u8(x, vceqq_u8(s, s2));
1245 x = vorrq_u8(x, vcltq_u8(s, s3));
1248 uint64_t low = vgetq_lane_u64(reinterpret_cast<uint64x2_t>(x), 0);
1249 uint64_t high = vgetq_lane_u64(reinterpret_cast<uint64x2_t>(x), 1);
1252 bool escaped =
false;
1255 unsigned lz = (unsigned)__builtin_clzll(high);;
1256 length = 8 + (lz >> 3);
1260 unsigned lz = (unsigned)__builtin_clzll(low);;
1266 char* q =
reinterpret_cast<char*
>(os.Push(length));
1267 for (
size_t i = 0; i < length; i++)
1274 vst1q_u8(reinterpret_cast<uint8_t *>(os.Push(16)), s);
1286 SkipUnescapedString(is);
1294 const char* nextAligned =
reinterpret_cast<const char*
>((
reinterpret_cast<size_t>(p) + 15) &
static_cast<size_t>(~15));
1295 while (p != nextAligned)
1305 const uint8x16_t s0 = vmovq_n_u8(
'"');
1306 const uint8x16_t s1 = vmovq_n_u8(
'\\');
1307 const uint8x16_t s2 = vmovq_n_u8(
'\b');
1308 const uint8x16_t s3 = vmovq_n_u8(32);
1310 for (;; p += 16, q += 16) {
1311 const uint8x16_t
s = vld1q_u8(reinterpret_cast<uint8_t *>(p));
1312 uint8x16_t x = vceqq_u8(s, s0);
1313 x = vorrq_u8(x, vceqq_u8(s, s1));
1314 x = vorrq_u8(x, vceqq_u8(s, s2));
1315 x = vorrq_u8(x, vcltq_u8(s, s3));
1318 uint64_t low = vgetq_lane_u64(reinterpret_cast<uint64x2_t>(x), 0);
1319 uint64_t high = vgetq_lane_u64(reinterpret_cast<uint64x2_t>(x), 1);
1322 bool escaped =
false;
1325 unsigned lz = (unsigned)__builtin_clzll(high);
1326 length = 8 + (lz >> 3);
1330 unsigned lz = (unsigned)__builtin_clzll(low);
1335 for (
const char* pend = p + length; p != pend; ) {
1340 vst1q_u8(reinterpret_cast<uint8_t *>(q), s);
1353 const char* nextAligned =
reinterpret_cast<const char*
>((
reinterpret_cast<size_t>(p) + 15) &
static_cast<size_t>(~15));
1354 for (; p != nextAligned; p++)
1361 const uint8x16_t s0 = vmovq_n_u8(
'"');
1362 const uint8x16_t s1 = vmovq_n_u8(
'\\');
1363 const uint8x16_t s2 = vmovq_n_u8(
'\b');
1364 const uint8x16_t s3 = vmovq_n_u8(32);
1367 const uint8x16_t
s = vld1q_u8(reinterpret_cast<uint8_t *>(p));
1368 uint8x16_t x = vceqq_u8(s, s0);
1369 x = vorrq_u8(x, vceqq_u8(s, s1));
1370 x = vorrq_u8(x, vceqq_u8(s, s2));
1371 x = vorrq_u8(x, vcltq_u8(s, s3));
1374 uint64_t low = vgetq_lane_u64(reinterpret_cast<uint64x2_t>(x), 0);
1375 uint64_t high = vgetq_lane_u64(reinterpret_cast<uint64x2_t>(x), 1);
1379 int lz = __builtin_clzll(high);
1384 int lz = __builtin_clzll(low);
1392 #endif // RAPIDJSON_NEON 1394 template<
typename InputStream,
bool backup,
bool pushOnTake>
1397 template<
typename InputStream>
1400 typedef typename InputStream::Ch
Ch;
1404 RAPIDJSON_FORCEINLINE Ch
Peek()
const {
return is.
Peek(); }
1407 RAPIDJSON_FORCEINLINE
void Push(
char) {}
1411 const char*
Pop() {
return 0; }
1419 template<
typename InputStream>
1426 stackStream.Put(static_cast<char>(Base::is.Peek()));
1427 return Base::is.Take();
1430 RAPIDJSON_FORCEINLINE
void Push(
char c) {
1434 size_t Length() {
return stackStream.Length(); }
1437 stackStream.Put(
'\0');
1438 return stackStream.Pop();
1445 template<
typename InputStream>
1451 RAPIDJSON_FORCEINLINE Ch
Take() {
return Base::TakePush(); }
1454 template<
unsigned parseFlags,
typename InputStream,
typename Handler>
1457 NumberStream<InputStream,
1464 size_t startOffset =
s.Tell();
1466 bool useNanOrInf =
false;
1469 bool minus = Consume(
s,
'-');
1474 bool use64bit =
false;
1475 int significandDigit = 0;
1481 i =
static_cast<unsigned>(
s.TakePush() -
'0');
1492 i = i * 10 +
static_cast<unsigned>(
s.TakePush() -
'0');
1504 i = i * 10 +
static_cast<unsigned>(
s.TakePush() -
'0');
1510 if (Consume(
s,
'N')) {
1511 if (Consume(
s,
'a') && Consume(
s,
'N')) {
1512 d = std::numeric_limits<double>::quiet_NaN();
1517 if (Consume(
s,
'n') && Consume(
s,
'f')) {
1518 d = (minus ? -std::numeric_limits<double>::infinity() : std::numeric_limits<double>::infinity());
1522 && Consume(
s,
'i') && Consume(
s,
't') && Consume(
s,
'y')))) {
1536 bool useDouble =
false;
1542 d =
static_cast<double>(i64);
1546 i64 = i64 * 10 +
static_cast<unsigned>(
s.TakePush() -
'0');
1553 d =
static_cast<double>(i64);
1557 i64 = i64 * 10 +
static_cast<unsigned>(
s.TakePush() -
'0');
1567 d = d * 10 + (
s.TakePush() -
'0');
1573 size_t decimalPosition;
1574 if (Consume(
s,
'.')) {
1575 decimalPosition =
s.Length();
1590 i64 = i64 * 10 +
static_cast<unsigned>(
s.TakePush() -
'0');
1597 d =
static_cast<double>(i64);
1600 d =
static_cast<double>(use64bit ? i64 : i);
1606 if (significandDigit < 17) {
1607 d = d * 10.0 + (
s.TakePush() -
'0');
1617 decimalPosition =
s.Length();
1621 if (Consume(
s,
'e') || Consume(
s,
'E')) {
1623 d =
static_cast<double>(use64bit ? i64 : i);
1627 bool expMinus =
false;
1628 if (Consume(
s,
'+'))
1630 else if (Consume(
s,
'-'))
1634 exp =
static_cast<int>(
s.Take() -
'0');
1637 exp = exp * 10 +
static_cast<int>(
s.Take() -
'0');
1638 if (exp >= 214748364) {
1645 int maxExp = 308 - expFrac;
1647 exp = exp * 10 +
static_cast<int>(
s.Take() -
'0');
1664 if (parseFlags & kParseInsituFlag) {
1666 typename InputStream::Ch* head = is.PutBegin();
1667 const size_t length =
s.Tell() - startOffset;
1670 const typename TargetEncoding::Ch*
const str =
reinterpret_cast<typename TargetEncoding::Ch*
>(head);
1671 cont = handler.RawNumber(str,
SizeType(length),
false);
1676 StackStream<typename TargetEncoding::Ch> dstStream(stack_);
1677 while (numCharsToCopy--) {
1680 dstStream.Put(
'\0');
1681 const typename TargetEncoding::Ch* str = dstStream.Pop();
1683 cont = handler.RawNumber(str,
SizeType(length),
true);
1687 size_t length =
s.Length();
1688 const char* decimal =
s.Pop();
1691 int p = exp + expFrac;
1697 cont = handler.Double(minus ? -d : d);
1699 else if (useNanOrInf) {
1700 cont = handler.Double(d);
1705 cont = handler.Int64(static_cast<int64_t>(~i64 + 1));
1707 cont = handler.Uint64(i64);
1711 cont = handler.Int(static_cast<int32_t>(~i + 1));
1713 cont = handler.Uint(i);
1722 template<
unsigned parseFlags,
typename InputStream,
typename Handler>
1724 switch (is.Peek()) {
1725 case 'n': ParseNull <parseFlags>(is, handler);
break;
1726 case 't': ParseTrue <parseFlags>(is, handler);
break;
1727 case 'f': ParseFalse <parseFlags>(is, handler);
break;
1728 case '"': ParseString<parseFlags>(is, handler);
break;
1729 case '{': ParseObject<parseFlags>(is, handler);
break;
1730 case '[': ParseArray <parseFlags>(is, handler);
break;
1732 ParseNumber<parseFlags>(is, handler);
1742 IterativeParsingFinishState = 0,
1765 cIterativeParsingStateCount
1770 LeftBracketToken = 0,
1791 #define N NumberToken 1792 #define N16 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N 1794 static const unsigned char tokenMap[256] = {
1797 N, N, StringToken, N, N, N, N, N, N, N, N, N, CommaToken, N, N, N,
1798 N, N, N, N, N, N, N, N, N, N, ColonToken, N, N, N, N, N,
1800 N, N, N, N, N, N, N, N, N, N, N, LeftBracketToken, N, RightBracketToken, N, N,
1801 N, N, N, N, N, N, FalseToken, N, N, N, N, N, N, N, NullToken, N,
1802 N, N, N, N, TrueToken, N, N, N, N, N, N, LeftCurlyBracketToken, N, RightCurlyBracketToken, N, N,
1803 N16, N16, N16, N16, N16, N16, N16, N16
1809 if (
sizeof(Ch) == 1 || static_cast<unsigned>(c) < 256)
1810 return static_cast<Token>(tokenMap[
static_cast<unsigned char>(c)]);
1817 static const char G[cIterativeParsingStateCount][kTokenCount] = {
1820 IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState,
1821 IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState,
1822 IterativeParsingErrorState
1826 IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState,
1827 IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState,
1828 IterativeParsingErrorState
1832 IterativeParsingArrayInitialState,
1833 IterativeParsingErrorState,
1834 IterativeParsingObjectInitialState,
1835 IterativeParsingErrorState,
1836 IterativeParsingErrorState,
1837 IterativeParsingErrorState,
1838 IterativeParsingValueState,
1839 IterativeParsingValueState,
1840 IterativeParsingValueState,
1841 IterativeParsingValueState,
1842 IterativeParsingValueState
1846 IterativeParsingErrorState,
1847 IterativeParsingErrorState,
1848 IterativeParsingErrorState,
1849 IterativeParsingObjectFinishState,
1850 IterativeParsingErrorState,
1851 IterativeParsingErrorState,
1852 IterativeParsingMemberKeyState,
1853 IterativeParsingErrorState,
1854 IterativeParsingErrorState,
1855 IterativeParsingErrorState,
1856 IterativeParsingErrorState
1860 IterativeParsingErrorState,
1861 IterativeParsingErrorState,
1862 IterativeParsingErrorState,
1863 IterativeParsingErrorState,
1864 IterativeParsingErrorState,
1865 IterativeParsingKeyValueDelimiterState,
1866 IterativeParsingErrorState,
1867 IterativeParsingErrorState,
1868 IterativeParsingErrorState,
1869 IterativeParsingErrorState,
1870 IterativeParsingErrorState
1874 IterativeParsingErrorState,
1875 IterativeParsingErrorState,
1876 IterativeParsingErrorState,
1877 IterativeParsingObjectFinishState,
1878 IterativeParsingMemberDelimiterState,
1879 IterativeParsingErrorState,
1880 IterativeParsingErrorState,
1881 IterativeParsingErrorState,
1882 IterativeParsingErrorState,
1883 IterativeParsingErrorState,
1884 IterativeParsingErrorState
1888 IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState,
1889 IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState,
1890 IterativeParsingErrorState
1894 IterativeParsingArrayInitialState,
1895 IterativeParsingArrayFinishState,
1896 IterativeParsingObjectInitialState,
1897 IterativeParsingErrorState,
1898 IterativeParsingErrorState,
1899 IterativeParsingErrorState,
1900 IterativeParsingElementState,
1901 IterativeParsingElementState,
1902 IterativeParsingElementState,
1903 IterativeParsingElementState,
1904 IterativeParsingElementState
1908 IterativeParsingErrorState,
1909 IterativeParsingArrayFinishState,
1910 IterativeParsingErrorState,
1911 IterativeParsingErrorState,
1912 IterativeParsingElementDelimiterState,
1913 IterativeParsingErrorState,
1914 IterativeParsingErrorState,
1915 IterativeParsingErrorState,
1916 IterativeParsingErrorState,
1917 IterativeParsingErrorState,
1918 IterativeParsingErrorState
1922 IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState,
1923 IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState,
1924 IterativeParsingErrorState
1928 IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState,
1929 IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState,
1930 IterativeParsingErrorState
1934 IterativeParsingArrayInitialState,
1935 IterativeParsingArrayFinishState,
1936 IterativeParsingObjectInitialState,
1937 IterativeParsingErrorState,
1938 IterativeParsingErrorState,
1939 IterativeParsingErrorState,
1940 IterativeParsingElementState,
1941 IterativeParsingElementState,
1942 IterativeParsingElementState,
1943 IterativeParsingElementState,
1944 IterativeParsingElementState
1948 IterativeParsingErrorState,
1949 IterativeParsingErrorState,
1950 IterativeParsingErrorState,
1951 IterativeParsingObjectFinishState,
1952 IterativeParsingErrorState,
1953 IterativeParsingErrorState,
1954 IterativeParsingMemberKeyState,
1955 IterativeParsingErrorState,
1956 IterativeParsingErrorState,
1957 IterativeParsingErrorState,
1958 IterativeParsingErrorState
1962 IterativeParsingArrayInitialState,
1963 IterativeParsingErrorState,
1964 IterativeParsingObjectInitialState,
1965 IterativeParsingErrorState,
1966 IterativeParsingErrorState,
1967 IterativeParsingErrorState,
1968 IterativeParsingMemberValueState,
1969 IterativeParsingMemberValueState,
1970 IterativeParsingMemberValueState,
1971 IterativeParsingMemberValueState,
1972 IterativeParsingMemberValueState
1981 template <
unsigned parseFlags,
typename InputStream,
typename Handler>
1986 case IterativeParsingErrorState:
1989 case IterativeParsingObjectInitialState:
1990 case IterativeParsingArrayInitialState:
1995 if (src == IterativeParsingArrayInitialState || src == IterativeParsingElementDelimiterState)
1996 n = IterativeParsingElementState;
1997 else if (src == IterativeParsingKeyValueDelimiterState)
1998 n = IterativeParsingMemberValueState;
2000 *stack_.template Push<SizeType>(1) = n;
2002 *stack_.template Push<SizeType>(1) = 0;
2004 bool hr = (dst == IterativeParsingObjectInitialState) ? handler.StartObject() : handler.StartArray();
2008 return IterativeParsingErrorState;
2016 case IterativeParsingMemberKeyState:
2017 ParseString<parseFlags>(is, handler,
true);
2018 if (HasParseError())
2019 return IterativeParsingErrorState;
2023 case IterativeParsingKeyValueDelimiterState:
2028 case IterativeParsingMemberValueState:
2030 ParseValue<parseFlags>(is, handler);
2031 if (HasParseError()) {
2032 return IterativeParsingErrorState;
2036 case IterativeParsingElementState:
2038 ParseValue<parseFlags>(is, handler);
2039 if (HasParseError()) {
2040 return IterativeParsingErrorState;
2044 case IterativeParsingMemberDelimiterState:
2045 case IterativeParsingElementDelimiterState:
2048 *stack_.template Top<SizeType>() = *stack_.template Top<SizeType>() + 1;
2051 case IterativeParsingObjectFinishState:
2056 return IterativeParsingErrorState;
2059 SizeType c = *stack_.template Pop<SizeType>(1);
2061 if (src == IterativeParsingMemberValueState)
2066 if (n == IterativeParsingStartState)
2067 n = IterativeParsingFinishState;
2069 bool hr = handler.EndObject(c);
2073 return IterativeParsingErrorState;
2081 case IterativeParsingArrayFinishState:
2086 return IterativeParsingErrorState;
2089 SizeType c = *stack_.template Pop<SizeType>(1);
2091 if (src == IterativeParsingElementState)
2096 if (n == IterativeParsingStartState)
2097 n = IterativeParsingFinishState;
2099 bool hr = handler.EndArray(c);
2103 return IterativeParsingErrorState;
2125 ParseValue<parseFlags>(is, handler);
2126 if (HasParseError()) {
2127 return IterativeParsingErrorState;
2129 return IterativeParsingFinishState;
2133 template <
typename InputStream>
2135 if (HasParseError()) {
2143 case IterativeParsingObjectInitialState:
2147 case IterativeParsingKeyValueDelimiterState:
2148 case IterativeParsingArrayInitialState:
2155 return s >= IterativeParsingElementDelimiterState;
2159 return s <= IterativeParsingErrorState;
2162 template <
unsigned parseFlags,
typename InputStream,
typename Handler>
2164 parseResult_.
Clear();
2165 ClearStackOnExit scope(*
this);
2168 SkipWhitespaceAndComments<parseFlags>(is);
2169 RAPIDJSON_PARSE_ERROR_EARLY_RETURN(parseResult_);
2170 while (is.Peek() !=
'\0') {
2171 Token t = Tokenize(is.Peek());
2175 if (d == IterativeParsingErrorState) {
2176 HandleError(state, is);
2186 SkipWhitespaceAndComments<parseFlags>(is);
2187 RAPIDJSON_PARSE_ERROR_EARLY_RETURN(parseResult_);
2191 if (state != IterativeParsingFinishState)
2192 HandleError(state, is);
2194 return parseResult_;
2197 static const size_t kDefaultStackCapacity = 256;
2221 #endif // RAPIDJSON_READER_H_
bool RawNumber(const Ch *str, SizeType len, bool copy)
enabled via kParseNumbersAsStringsFlag, string is not null-terminated (use length) ...
RAPIDJSON_FORCEINLINE void ParseStringToStream(InputStream &is, OutputStream &os)
StreamLocalCopy(Stream &original)
void HandleError(IterativeParsingState src, InputStream &is)
ParseResult Parse(InputStream &is, Handler &handler)
Parse JSON text.
double StrtodFullPrecision(double d, int p, const char *decimals, size_t length, size_t decimalPosition, int exp)
RAPIDJSON_NAMESPACE_BEGIN typedef unsigned SizeType
Size type (for string lengths, array sizes, etc.)
Iterative(constant complexity in terms of function call stack size) parsing.
Represents an in-memory input byte stream.
#define RAPIDJSON_ASSERT(x)
Assertion.
Missing a comma or '}' after an object member.
#define RAPIDJSON_UINT64_C2(high32, low32)
Construct a 64-bit literal by a pair of 32-bit integer.
Default implementation of Handler.
RAPIDJSON_FORCEINLINE IterativeParsingState Transit(IterativeParsingState src, Token token, IterativeParsingState dst, InputStream &is, Handler &handler)
StackStream(internal::Stack< StackAllocator > &stack)
#define RAPIDJSON_NAMESPACE_END
provide custom rapidjson namespace (closing expression)
GenericReader< UTF8<>, UTF8<> > Reader
Reader with UTF8 encoding and default allocator.
Missing a comma or ']' after an array element.
RAPIDJSON_FORCEINLINE IterativeParsingState Predict(IterativeParsingState state, Token token)
RAPIDJSON_FORCEINLINE bool IterativeParseComplete()
Check if token-by-token parsing JSON text is complete.
bool String(const Ch *, SizeType, bool)
ParseErrorCode GetParseErrorCode() const
Get the ParseErrorCode of last parsing.
RAPIDJSON_FORCEINLINE Token Tokenize(Ch c)
const Ch * src_
Current read position.
ParseResult Parse(InputStream &is, Handler &handler)
Parse JSON text (with kParseDefaultFlags)
void SetParseError(ParseErrorCode code, size_t offset)
void ParseString(InputStream &is, Handler &handler, bool isKey=false)
RAPIDJSON_FORCEINLINE void Put(Ch c)
Missing a name for object member.
Result of parsing (wraps ParseErrorCode)
Allow trailing commas at the end of objects and arrays.
void ParseValue(InputStream &is, Handler &handler)
void ParseArray(InputStream &is, Handler &handler)
#define RAPIDJSON_NAMESPACE_BEGIN
provide custom rapidjson namespace (opening expression)
internal::SelectIf< internal::IsSame< Derived, void >, BaseReaderHandler, Derived >::Type Override
#define RAPIDJSON_PARSE_ERROR_NORETURN(parseErrorCode, offset)
Macro to indicate a parse error.
Allow parsing NaN, Inf, Infinity, -Inf and -Infinity as doubles.
internal::Stack< StackAllocator > & stack_
Number too big to be stored in double.
Parse all numbers (ints/doubles) as strings.
After parsing a complete JSON root from stream, stop further processing the rest of stream...
SourceEncoding::Ch Ch
SourceEncoding character type.
unsigned ParseHex4(InputStream &is, size_t escapeOffset)
Default parse flags. Can be customized by defining RAPIDJSON_PARSE_DEFAULT_FLAGS. ...
Parse number in full precision (but slower).
void ParseTrue(InputStream &is, Handler &handler)
SAX-style JSON parser. Use Reader for UTF8 encoding and default allocator.
bool HasParseError() const
Whether a parse error has occured in the last parsing.
double StrtodNormalPrecision(double d, int p)
bool Key(const Ch *str, SizeType len, bool copy)
RAPIDJSON_FORCEINLINE void * Push(SizeType count)
ParseFlag
Combination of parseFlags.
ParseErrorCode
Error code of parsing.
void SkipWhitespaceAndComments(InputStream &is)
#define RAPIDJSON_PARSE_DEFAULT_FLAGS
unsigned __int64 uint64_t
IterativeParsingState state_
RAPIDJSON_FORCEINLINE bool IsIterativeParsingCompleteState(IterativeParsingState s)
bool IterativeParseNext(InputStream &is, Handler &handler)
Parse one token from JSON text.
void ParseFalse(InputStream &is, Handler &handler)
Invalid escape character in string.
Invalid encoding in string.
void ParseNumber(InputStream &is, Handler &handler)
#define RAPIDJSON_LIKELY(x)
Compiler branching hint for expression with high probability to be true.
RAPIDJSON_FORCEINLINE bool IsIterativeParsingDelimiterState(IterativeParsingState s)
void SkipWhitespace(InputStream &is)
Skip the JSON white spaces in a stream.
void ParseObject(InputStream &is, Handler &handler)
Validate encoding of JSON strings.
Miss fraction part in number.
size_t GetErrorOffset() const
Get the position of last parsing error in input, 0 otherwise.
internal::Stack< StackAllocator > stack_
A stack for storing decoded string temporarily during non-destructive parsing.
Incorrect hex digit after \u escape in string.
#define RAPIDJSON_PARSE_ERROR(parseErrorCode, offset)
(Internal) macro to indicate and handle a parse error.
void Clear()
Reset error code.
static RAPIDJSON_FORCEINLINE bool Consume(InputStream &is, typename InputStream::Ch expect)
void IterativeParseInit()
Initialize JSON text token-by-token parsing.
The surrogate pair in string is invalid.
void ParseNull(InputStream &is, Handler &handler)
Missing a colon after a name of object member.
ParseResult IterativeParse(InputStream &is, Handler &handler)
StreamLocalCopy(Stream &original)
GenericReader(StackAllocator *stackAllocator=0, size_t stackCapacity=kDefaultStackCapacity)
Constructor.
ClearStackOnExit(GenericReader &r)
#define RAPIDJSON_UNLIKELY(x)
Compiler branching hint for expression with low probability to be true.
Missing a closing quotation mark in string.
static RAPIDJSON_FORCEINLINE void ScanCopyUnescapedString(InputStream &, OutputStream &)
The document root must not follow by other values.
In-situ(destructive) parsing.
Allow one-line (//) and multi-line (/**/) comments.