19 #ifndef RAPIDJSON_READER_H_ 20 #define RAPIDJSON_READER_H_ 33 #if defined(RAPIDJSON_SIMD) && defined(_MSC_VER) 35 #pragma intrinsic(_BitScanForward) 37 #ifdef RAPIDJSON_SSE42 38 #include <nmmintrin.h> 39 #elif defined(RAPIDJSON_SSE2) 40 #include <emmintrin.h> 41 #elif defined(RAPIDJSON_NEON) 47 RAPIDJSON_DIAG_OFF(old - style - cast)
48 RAPIDJSON_DIAG_OFF(padded)
49 RAPIDJSON_DIAG_OFF(switch - enum)
50 #elif defined(_MSC_VER) 52 RAPIDJSON_DIAG_OFF(4127)
53 RAPIDJSON_DIAG_OFF(4702)
58 RAPIDJSON_DIAG_OFF(effc++)
62 #define RAPIDJSON_NOTHING 63 #ifndef RAPIDJSON_PARSE_ERROR_EARLY_RETURN 64 #define RAPIDJSON_PARSE_ERROR_EARLY_RETURN(value) \ 65 RAPIDJSON_MULTILINEMACRO_BEGIN \ 66 if (RAPIDJSON_UNLIKELY(HasParseError())) { \ 69 RAPIDJSON_MULTILINEMACRO_END 71 #define RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID \ 72 RAPIDJSON_PARSE_ERROR_EARLY_RETURN(RAPIDJSON_NOTHING) 105 #ifndef RAPIDJSON_PARSE_ERROR_NORETURN 106 #define RAPIDJSON_PARSE_ERROR_NORETURN(parseErrorCode, offset) \ 107 RAPIDJSON_MULTILINEMACRO_BEGIN \ 108 RAPIDJSON_ASSERT(!HasParseError()); \ 109 SetParseError(parseErrorCode, offset); \ 110 RAPIDJSON_MULTILINEMACRO_END 124 #ifndef RAPIDJSON_PARSE_ERROR 125 #define RAPIDJSON_PARSE_ERROR(parseErrorCode, offset) \ 126 RAPIDJSON_MULTILINEMACRO_BEGIN \ 127 RAPIDJSON_PARSE_ERROR_NORETURN(parseErrorCode, offset); \ 128 RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID; \ 129 RAPIDJSON_MULTILINEMACRO_END 145 #ifndef RAPIDJSON_PARSE_DEFAULT_FLAGS 146 #define RAPIDJSON_PARSE_DEFAULT_FLAGS kParseNoFlags 212 template <
typename Encoding = UTF8<>,
typename Derived =
void>
214 typedef typename Encoding::Ch
Ch;
217 typename internal::SelectIf<internal::IsSame<Derived, void>,
221 bool Null() {
return static_cast<Override &
>(*this).Default(); }
222 bool Bool(
bool) {
return static_cast<Override &
>(*this).Default(); }
223 bool Int(
int) {
return static_cast<Override &
>(*this).Default(); }
224 bool Uint(
unsigned) {
return static_cast<Override &
>(*this).Default(); }
225 bool Int64(
int64_t) {
return static_cast<Override &
>(*this).Default(); }
227 bool Double(
double) {
return static_cast<Override &
>(*this).Default(); }
231 return static_cast<Override &
>(*this).String(str, len, copy);
234 return static_cast<Override &
>(*this).Default();
236 bool StartObject() {
return static_cast<Override &
>(*this).Default(); }
238 return static_cast<Override &
>(*this).String(str, len, copy);
241 bool StartArray() {
return static_cast<Override &
>(*this).Default(); }
250 template <typename Stream, int = StreamTraits<Stream>::copyOptimization>
254 template <
typename Stream>
269 template <
typename Stream>
289 template <
typename InputStream>
292 InputStream &
s(copy.s);
294 typename InputStream::Ch c;
295 while ((c = s.Peek()) ==
' ' || c ==
'\n' || c ==
'\r' || c ==
'\t') s.Take();
299 while (p != end && (*p ==
' ' || *p ==
'\n' || *p ==
'\r' || *p ==
'\t')) ++p;
303 #ifdef RAPIDJSON_SSE42 304 inline const char *SkipWhitespace_SIMD(
const char *p) {
308 if (*p ==
' ' || *p ==
'\n' || *p ==
'\r' || *p ==
'\t')
314 const char *nextAligned =
reinterpret_cast<const char *
>(
315 (
reinterpret_cast<size_t>(p) + 15) &
static_cast<size_t>(~15));
316 while (p != nextAligned)
317 if (*p ==
' ' || *p ==
'\n' || *p ==
'\r' || *p ==
'\t')
323 static const char whitespace[16] =
" \n\r\t";
325 _mm_loadu_si128(reinterpret_cast<const __m128i *>(&whitespace[0]));
328 const __m128i
s = _mm_load_si128(reinterpret_cast<const __m128i *>(p));
329 const int r = _mm_cmpistri(w, s, _SIDD_UBYTE_OPS | _SIDD_CMP_EQUAL_ANY |
330 _SIDD_LEAST_SIGNIFICANT |
331 _SIDD_NEGATIVE_POLARITY);
337 inline const char *SkipWhitespace_SIMD(
const char *p,
const char *end) {
339 if (p != end && (*p ==
' ' || *p ==
'\n' || *p ==
'\r' || *p ==
'\t'))
345 static const char whitespace[16] =
" \n\r\t";
347 _mm_loadu_si128(reinterpret_cast<const __m128i *>(&whitespace[0]));
349 for (; p <= end - 16; p += 16) {
350 const __m128i
s = _mm_loadu_si128(reinterpret_cast<const __m128i *>(p));
351 const int r = _mm_cmpistri(w, s, _SIDD_UBYTE_OPS | _SIDD_CMP_EQUAL_ANY |
352 _SIDD_LEAST_SIGNIFICANT |
353 _SIDD_NEGATIVE_POLARITY);
361 #elif defined(RAPIDJSON_SSE2) 365 inline const char *SkipWhitespace_SIMD(
const char *p) {
367 if (*p ==
' ' || *p ==
'\n' || *p ==
'\r' || *p ==
'\t')
373 const char *nextAligned =
reinterpret_cast<const char *
>(
374 (
reinterpret_cast<size_t>(p) + 15) &
static_cast<size_t>(~15));
375 while (p != nextAligned)
376 if (*p ==
' ' || *p ==
'\n' || *p ==
'\r' || *p ==
'\t')
383 { c, c, c, c, c, c, c, c, c, c, c, c, c, c, c, c } 384 static const char whitespaces[4][16] = {C16(
' '), C16(
'\n'), C16(
'\r'),
389 _mm_loadu_si128(reinterpret_cast<const __m128i *>(&whitespaces[0][0]));
391 _mm_loadu_si128(reinterpret_cast<const __m128i *>(&whitespaces[1][0]));
393 _mm_loadu_si128(reinterpret_cast<const __m128i *>(&whitespaces[2][0]));
395 _mm_loadu_si128(reinterpret_cast<const __m128i *>(&whitespaces[3][0]));
398 const __m128i
s = _mm_load_si128(reinterpret_cast<const __m128i *>(p));
399 __m128i
x = _mm_cmpeq_epi8(s, w0);
400 x = _mm_or_si128(x, _mm_cmpeq_epi8(s, w1));
401 x = _mm_or_si128(x, _mm_cmpeq_epi8(s, w2));
402 x = _mm_or_si128(x, _mm_cmpeq_epi8(s, w3));
403 unsigned short r =
static_cast<unsigned short>(~_mm_movemask_epi8(x));
405 #ifdef _MSC_VER // Find the index of first non-whitespace 406 unsigned long offset;
407 _BitScanForward(&offset, r);
410 return p + __builtin_ffs(r) - 1;
416 inline const char *SkipWhitespace_SIMD(
const char *p,
const char *end) {
418 if (p != end && (*p ==
' ' || *p ==
'\n' || *p ==
'\r' || *p ==
'\t'))
425 { c, c, c, c, c, c, c, c, c, c, c, c, c, c, c, c } 426 static const char whitespaces[4][16] = {C16(
' '), C16(
'\n'), C16(
'\r'),
431 _mm_loadu_si128(reinterpret_cast<const __m128i *>(&whitespaces[0][0]));
433 _mm_loadu_si128(reinterpret_cast<const __m128i *>(&whitespaces[1][0]));
435 _mm_loadu_si128(reinterpret_cast<const __m128i *>(&whitespaces[2][0]));
437 _mm_loadu_si128(reinterpret_cast<const __m128i *>(&whitespaces[3][0]));
439 for (; p <= end - 16; p += 16) {
440 const __m128i
s = _mm_loadu_si128(reinterpret_cast<const __m128i *>(p));
441 __m128i
x = _mm_cmpeq_epi8(s, w0);
442 x = _mm_or_si128(x, _mm_cmpeq_epi8(s, w1));
443 x = _mm_or_si128(x, _mm_cmpeq_epi8(s, w2));
444 x = _mm_or_si128(x, _mm_cmpeq_epi8(s, w3));
445 unsigned short r =
static_cast<unsigned short>(~_mm_movemask_epi8(x));
447 #ifdef _MSC_VER // Find the index of first non-whitespace 448 unsigned long offset;
449 _BitScanForward(&offset, r);
452 return p + __builtin_ffs(r) - 1;
460 #elif defined(RAPIDJSON_NEON) 464 inline const char *SkipWhitespace_SIMD(
const char *p) {
466 if (*p ==
' ' || *p ==
'\n' || *p ==
'\r' || *p ==
'\t')
472 const char *nextAligned =
reinterpret_cast<const char *
>(
473 (
reinterpret_cast<size_t>(p) + 15) &
static_cast<size_t>(~15));
474 while (p != nextAligned)
475 if (*p ==
' ' || *p ==
'\n' || *p ==
'\r' || *p ==
'\t')
480 const uint8x16_t w0 = vmovq_n_u8(
' ');
481 const uint8x16_t w1 = vmovq_n_u8(
'\n');
482 const uint8x16_t w2 = vmovq_n_u8(
'\r');
483 const uint8x16_t w3 = vmovq_n_u8(
'\t');
486 const uint8x16_t
s = vld1q_u8(reinterpret_cast<const uint8_t *>(p));
487 uint8x16_t
x = vceqq_u8(s, w0);
488 x = vorrq_u8(x, vceqq_u8(s, w1));
489 x = vorrq_u8(x, vceqq_u8(s, w2));
490 x = vorrq_u8(x, vceqq_u8(s, w3));
494 uint64_t low = vgetq_lane_u64(vreinterpretq_u64_u8(x), 0);
495 uint64_t high = vgetq_lane_u64(vreinterpretq_u64_u8(x), 1);
500 return p + 8 + (lz >> 3);
504 return p + (lz >> 3);
509 inline const char *SkipWhitespace_SIMD(
const char *p,
const char *end) {
511 if (p != end && (*p ==
' ' || *p ==
'\n' || *p ==
'\r' || *p ==
'\t'))
516 const uint8x16_t w0 = vmovq_n_u8(
' ');
517 const uint8x16_t w1 = vmovq_n_u8(
'\n');
518 const uint8x16_t w2 = vmovq_n_u8(
'\r');
519 const uint8x16_t w3 = vmovq_n_u8(
'\t');
521 for (; p <= end - 16; p += 16) {
522 const uint8x16_t
s = vld1q_u8(reinterpret_cast<const uint8_t *>(p));
523 uint8x16_t
x = vceqq_u8(s, w0);
524 x = vorrq_u8(x, vceqq_u8(s, w1));
525 x = vorrq_u8(x, vceqq_u8(s, w2));
526 x = vorrq_u8(x, vceqq_u8(s, w3));
530 uint64_t low = vgetq_lane_u64(vreinterpretq_u64_u8(x), 0);
531 uint64_t high = vgetq_lane_u64(vreinterpretq_u64_u8(x), 1);
536 return p + 8 + (lz >> 3);
540 return p + (lz >> 3);
547 #endif // RAPIDJSON_NEON 549 #ifdef RAPIDJSON_SIMD 553 is.
src_ =
const_cast<char *
>(SkipWhitespace_SIMD(is.
src_));
559 is.
src_ = SkipWhitespace_SIMD(is.
src_);
564 is.is_.
src_ = SkipWhitespace_SIMD(is.is_.
src_, is.is_.end_);
566 #endif // RAPIDJSON_SIMD 588 template <
typename SourceEncoding,
typename TargetEncoding,
592 typedef typename SourceEncoding::Ch
Ch;
601 size_t stackCapacity = kDefaultStackCapacity)
602 : stack_(stackAllocator, stackCapacity),
604 state_(IterativeParsingStartState) {}
614 template <
unsigned parseFlags,
typename InputStream,
typename Handler>
617 return IterativeParse<parseFlags>(is, handler);
619 parseResult_.
Clear();
623 SkipWhitespaceAndComments<parseFlags>(is);
624 RAPIDJSON_PARSE_ERROR_EARLY_RETURN(parseResult_);
628 RAPIDJSON_PARSE_ERROR_EARLY_RETURN(parseResult_);
630 ParseValue<parseFlags>(is, handler);
631 RAPIDJSON_PARSE_ERROR_EARLY_RETURN(parseResult_);
634 SkipWhitespaceAndComments<parseFlags>(is);
635 RAPIDJSON_PARSE_ERROR_EARLY_RETURN(parseResult_);
640 RAPIDJSON_PARSE_ERROR_EARLY_RETURN(parseResult_);
655 template <
typename InputStream,
typename Handler>
657 return Parse<kParseDefaultFlags>(is, handler);
664 parseResult_.Clear();
665 state_ = IterativeParsingStartState;
675 template <
unsigned parseFlags,
typename InputStream,
typename Handler>
678 SkipWhitespaceAndComments<parseFlags>(is);
680 Token t = Tokenize(is.Peek());
687 if (d == IterativeParsingErrorState) {
688 HandleError(state_, is);
699 SkipWhitespaceAndComments<parseFlags>(is);
700 if (is.Peek() !=
'\0') {
702 HandleError(state_, is);
716 if (!IsIterativeParsingDelimiterState(n))
return true;
722 if (state_ != IterativeParsingFinishState) {
723 HandleError(state_, is);
734 return IsIterativeParsingCompleteState(state_);
748 parseResult_.Set(code, offset);
769 template <
unsigned parseFlags,
typename InputStream>
775 if (Consume(is,
'*')) {
780 else if (Consume(is,
'*')) {
781 if (Consume(is,
'/'))
break;
786 while (is.Peek() !=
'\0' && is.Take() !=
'\n') {
797 template <
unsigned parseFlags,
typename InputStream,
typename Handler>
805 SkipWhitespaceAndComments<parseFlags>(is);
806 RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
808 if (Consume(is,
'}')) {
818 ParseString<parseFlags>(is, handler,
true);
819 RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
821 SkipWhitespaceAndComments<parseFlags>(is);
822 RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
827 SkipWhitespaceAndComments<parseFlags>(is);
828 RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
830 ParseValue<parseFlags>(is, handler);
831 RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
833 SkipWhitespaceAndComments<parseFlags>(is);
834 RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
841 SkipWhitespaceAndComments<parseFlags>(is);
842 RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
857 if (is.Peek() ==
'}') {
868 template <
unsigned parseFlags,
typename InputStream,
typename Handler>
876 SkipWhitespaceAndComments<parseFlags>(is);
877 RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
879 if (Consume(is,
']')) {
886 ParseValue<parseFlags>(is, handler);
887 RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
890 SkipWhitespaceAndComments<parseFlags>(is);
891 RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
893 if (Consume(is,
',')) {
894 SkipWhitespaceAndComments<parseFlags>(is);
895 RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
896 }
else if (Consume(is,
']')) {
905 if (is.Peek() ==
']') {
915 template <
unsigned parseFlags,
typename InputStream,
typename Handler>
928 template <
unsigned parseFlags,
typename InputStream,
typename Handler>
941 template <
unsigned parseFlags,
typename InputStream,
typename Handler>
947 Consume(is,
's') && Consume(is,
'e'))) {
954 template <
typename InputStream>
955 RAPIDJSON_FORCEINLINE
static bool Consume(InputStream &is,
956 typename InputStream::Ch expect) {
966 template <
typename InputStream>
967 unsigned ParseHex4(InputStream &is,
size_t escapeOffset) {
968 unsigned codepoint = 0;
969 for (
int i = 0; i < 4; i++) {
972 codepoint +=
static_cast<unsigned>(c);
973 if (c >=
'0' && c <=
'9')
975 else if (c >=
'A' && c <=
'F')
976 codepoint -=
'A' - 10;
977 else if (c >=
'a' && c <=
'f')
978 codepoint -=
'a' - 10;
982 RAPIDJSON_PARSE_ERROR_EARLY_RETURN(0);
989 template <
typename CharType>
995 : stack_(stack), length_(0) {}
996 RAPIDJSON_FORCEINLINE
void Put(Ch c) {
997 *stack_.template Push<Ch>() = c;
1003 return stack_.template Push<Ch>(count);
1008 Ch *
Pop() {
return stack_.template Pop<Ch>(length_); }
1020 template <
unsigned parseFlags,
typename InputStream,
typename Handler>
1021 void ParseString(InputStream &is, Handler &handler,
bool isKey =
false) {
1023 InputStream &
s(copy.s);
1028 bool success =
false;
1030 typename InputStream::Ch *head = s.PutBegin();
1031 ParseStringToStream<parseFlags, SourceEncoding, SourceEncoding>(s, s);
1032 RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
1033 size_t length = s.PutEnd(head) - 1;
1035 const typename TargetEncoding::Ch *
const str =
1036 reinterpret_cast<typename TargetEncoding::Ch *
>(head);
1037 success = (isKey ? handler.Key(str,
SizeType(length),
false)
1038 : handler.String(str,
SizeType(length),
false));
1041 ParseStringToStream<parseFlags, SourceEncoding, TargetEncoding>(
1043 RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
1045 const typename TargetEncoding::Ch *
const str = stackStream.
Pop();
1046 success = (isKey ? handler.Key(str, length,
true)
1047 : handler.String(str, length,
true));
1056 template <
unsigned parseFlags,
typename SEncoding,
typename TEncoding,
1057 typename InputStream,
typename OutputStream>
1061 #define Z16 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 1062 static const char escape[256] = {
1063 Z16,
Z16, 0, 0,
'\"', 0, 0, 0, 0, 0, 0, 0, 0,
1064 0, 0, 0, 0,
'/',
Z16,
Z16, 0, 0, 0, 0, 0, 0,
1065 0, 0, 0, 0, 0, 0,
'\\', 0, 0, 0, 0, 0,
'\b',
1066 0, 0, 0,
'\f', 0, 0, 0, 0, 0, 0, 0,
'\n', 0,
1067 0, 0,
'\r', 0,
'\t', 0, 0, 0, 0, 0, 0, 0, 0,
1068 0, 0, 0,
Z16,
Z16,
Z16,
Z16,
Z16,
Z16,
Z16, Z16};
1076 ScanCopyUnescapedString(is, os);
1080 size_t escapeOffset = is.Tell();
1084 if ((
sizeof(Ch) == 1 ||
unsigned(e) < 256) &&
1087 os.Put(static_cast<typename TEncoding::Ch>(
1088 escape[static_cast<unsigned char>(e)]));
1091 unsigned codepoint = ParseHex4(is, escapeOffset);
1092 RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
1098 unsigned codepoint2 = ParseHex4(is, escapeOffset);
1099 RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
1103 codepoint = (((codepoint - 0xD800) << 10) | (codepoint2 - 0xDC00)) +
1106 TEncoding::Encode(os, codepoint);
1121 size_t offset = is.Tell();
1123 (parseFlags & kParseValidateEncodingFlag
1131 template <
typename InputStream,
typename OutputStream>
1137 #if defined(RAPIDJSON_SSE2) || defined(RAPIDJSON_SSE42) 1139 static RAPIDJSON_FORCEINLINE
void ScanCopyUnescapedString(
1141 const char *p = is.
src_;
1145 const char *nextAligned =
reinterpret_cast<const char *
>(
1146 (
reinterpret_cast<size_t>(p) + 15) &
static_cast<size_t>(~15));
1147 while (p != nextAligned)
1156 static const char dquote[16] = {
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
1157 '\"',
'\"',
'\"',
'\"',
'\"',
'\"',
1158 '\"',
'\"',
'\"',
'\"'};
1159 static const char bslash[16] = {
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
1160 '\\',
'\\',
'\\',
'\\',
'\\',
'\\',
1161 '\\',
'\\',
'\\',
'\\'};
1162 static const char space[16] = {0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F,
1163 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F,
1164 0x1F, 0x1F, 0x1F, 0x1F};
1166 _mm_loadu_si128(reinterpret_cast<const __m128i *>(&dquote[0]));
1168 _mm_loadu_si128(reinterpret_cast<const __m128i *>(&bslash[0]));
1170 _mm_loadu_si128(reinterpret_cast<const __m128i *>(&space[0]));
1173 const __m128i
s = _mm_load_si128(reinterpret_cast<const __m128i *>(p));
1174 const __m128i t1 = _mm_cmpeq_epi8(s, dq);
1175 const __m128i t2 = _mm_cmpeq_epi8(s, bs);
1176 const __m128i t3 = _mm_cmpeq_epi8(
1177 _mm_max_epu8(s, sp), sp);
1178 const __m128i
x = _mm_or_si128(_mm_or_si128(t1, t2), t3);
1179 unsigned short r =
static_cast<unsigned short>(_mm_movemask_epi8(x));
1182 #ifdef _MSC_VER // Find the index of first escaped 1183 unsigned long offset;
1184 _BitScanForward(&offset, r);
1187 length =
static_cast<SizeType>(__builtin_ffs(r) - 1);
1190 char *q =
reinterpret_cast<char *
>(os.
Push(length));
1191 for (
size_t i = 0; i < length; i++) q[i] = p[i];
1197 _mm_storeu_si128(reinterpret_cast<__m128i *>(os.
Push(16)), s);
1204 static RAPIDJSON_FORCEINLINE
void ScanCopyUnescapedString(
1210 SkipUnescapedString(is);
1219 const char *nextAligned =
reinterpret_cast<const char *
>(
1220 (
reinterpret_cast<size_t>(p) + 15) &
static_cast<size_t>(~15));
1221 while (p != nextAligned)
1231 static const char dquote[16] = {
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
1232 '\"',
'\"',
'\"',
'\"',
'\"',
'\"',
1233 '\"',
'\"',
'\"',
'\"'};
1234 static const char bslash[16] = {
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
1235 '\\',
'\\',
'\\',
'\\',
'\\',
'\\',
1236 '\\',
'\\',
'\\',
'\\'};
1237 static const char space[16] = {0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F,
1238 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F,
1239 0x1F, 0x1F, 0x1F, 0x1F};
1241 _mm_loadu_si128(reinterpret_cast<const __m128i *>(&dquote[0]));
1243 _mm_loadu_si128(reinterpret_cast<const __m128i *>(&bslash[0]));
1245 _mm_loadu_si128(reinterpret_cast<const __m128i *>(&space[0]));
1247 for (;; p += 16, q += 16) {
1248 const __m128i
s = _mm_load_si128(reinterpret_cast<const __m128i *>(p));
1249 const __m128i t1 = _mm_cmpeq_epi8(s, dq);
1250 const __m128i t2 = _mm_cmpeq_epi8(s, bs);
1251 const __m128i t3 = _mm_cmpeq_epi8(
1252 _mm_max_epu8(s, sp), sp);
1253 const __m128i
x = _mm_or_si128(_mm_or_si128(t1, t2), t3);
1254 unsigned short r =
static_cast<unsigned short>(_mm_movemask_epi8(x));
1257 #ifdef _MSC_VER // Find the index of first escaped 1258 unsigned long offset;
1259 _BitScanForward(&offset, r);
1262 length =
static_cast<size_t>(__builtin_ffs(r) - 1);
1264 for (
const char *pend = p + length; p != pend;) *q++ = *p++;
1267 _mm_storeu_si128(reinterpret_cast<__m128i *>(q), s);
1276 static RAPIDJSON_FORCEINLINE
void SkipUnescapedString(
1283 const char *nextAligned =
reinterpret_cast<const char *
>(
1284 (
reinterpret_cast<size_t>(p) + 15) &
static_cast<size_t>(~15));
1285 for (; p != nextAligned; p++)
1293 static const char dquote[16] = {
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
1294 '\"',
'\"',
'\"',
'\"',
'\"',
'\"',
1295 '\"',
'\"',
'\"',
'\"'};
1296 static const char bslash[16] = {
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
1297 '\\',
'\\',
'\\',
'\\',
'\\',
'\\',
1298 '\\',
'\\',
'\\',
'\\'};
1299 static const char space[16] = {0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F,
1300 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F,
1301 0x1F, 0x1F, 0x1F, 0x1F};
1303 _mm_loadu_si128(reinterpret_cast<const __m128i *>(&dquote[0]));
1305 _mm_loadu_si128(reinterpret_cast<const __m128i *>(&bslash[0]));
1307 _mm_loadu_si128(reinterpret_cast<const __m128i *>(&space[0]));
1310 const __m128i
s = _mm_load_si128(reinterpret_cast<const __m128i *>(p));
1311 const __m128i t1 = _mm_cmpeq_epi8(s, dq);
1312 const __m128i t2 = _mm_cmpeq_epi8(s, bs);
1313 const __m128i t3 = _mm_cmpeq_epi8(
1314 _mm_max_epu8(s, sp), sp);
1315 const __m128i
x = _mm_or_si128(_mm_or_si128(t1, t2), t3);
1316 unsigned short r =
static_cast<unsigned short>(_mm_movemask_epi8(x));
1319 #ifdef _MSC_VER // Find the index of first escaped 1320 unsigned long offset;
1321 _BitScanForward(&offset, r);
1324 length =
static_cast<size_t>(__builtin_ffs(r) - 1);
1333 #elif defined(RAPIDJSON_NEON) 1335 static RAPIDJSON_FORCEINLINE
void ScanCopyUnescapedString(
1337 const char *p = is.
src_;
1341 const char *nextAligned =
reinterpret_cast<const char *
>(
1342 (
reinterpret_cast<size_t>(p) + 15) &
static_cast<size_t>(~15));
1343 while (p != nextAligned)
1352 const uint8x16_t s0 = vmovq_n_u8(
'"');
1353 const uint8x16_t s1 = vmovq_n_u8(
'\\');
1354 const uint8x16_t s2 = vmovq_n_u8(
'\b');
1355 const uint8x16_t s3 = vmovq_n_u8(32);
1358 const uint8x16_t
s = vld1q_u8(reinterpret_cast<const uint8_t *>(p));
1359 uint8x16_t
x = vceqq_u8(s, s0);
1360 x = vorrq_u8(x, vceqq_u8(s, s1));
1361 x = vorrq_u8(x, vceqq_u8(s, s2));
1362 x = vorrq_u8(x, vcltq_u8(s, s3));
1365 uint64_t low = vgetq_lane_u64(vreinterpretq_u64_u8(x), 0);
1366 uint64_t high = vgetq_lane_u64(vreinterpretq_u64_u8(x), 1);
1369 bool escaped =
false;
1373 length = 8 + (lz >> 3);
1383 char *q =
reinterpret_cast<char *
>(os.
Push(length));
1384 for (
size_t i = 0; i < length; i++) q[i] = p[i];
1390 vst1q_u8(reinterpret_cast<uint8_t *>(os.
Push(16)), s);
1397 static RAPIDJSON_FORCEINLINE
void ScanCopyUnescapedString(
1403 SkipUnescapedString(is);
1412 const char *nextAligned =
reinterpret_cast<const char *
>(
1413 (
reinterpret_cast<size_t>(p) + 15) &
static_cast<size_t>(~15));
1414 while (p != nextAligned)
1424 const uint8x16_t s0 = vmovq_n_u8(
'"');
1425 const uint8x16_t s1 = vmovq_n_u8(
'\\');
1426 const uint8x16_t s2 = vmovq_n_u8(
'\b');
1427 const uint8x16_t s3 = vmovq_n_u8(32);
1429 for (;; p += 16, q += 16) {
1430 const uint8x16_t
s = vld1q_u8(reinterpret_cast<uint8_t *>(p));
1431 uint8x16_t
x = vceqq_u8(s, s0);
1432 x = vorrq_u8(x, vceqq_u8(s, s1));
1433 x = vorrq_u8(x, vceqq_u8(s, s2));
1434 x = vorrq_u8(x, vcltq_u8(s, s3));
1437 uint64_t low = vgetq_lane_u64(vreinterpretq_u64_u8(x), 0);
1438 uint64_t high = vgetq_lane_u64(vreinterpretq_u64_u8(x), 1);
1441 bool escaped =
false;
1445 length = 8 + (lz >> 3);
1454 for (
const char *pend = p + length; p != pend;) {
1459 vst1q_u8(reinterpret_cast<uint8_t *>(q), s);
1468 static RAPIDJSON_FORCEINLINE
void SkipUnescapedString(
1475 const char *nextAligned =
reinterpret_cast<const char *
>(
1476 (
reinterpret_cast<size_t>(p) + 15) &
static_cast<size_t>(~15));
1477 for (; p != nextAligned; p++)
1485 const uint8x16_t s0 = vmovq_n_u8(
'"');
1486 const uint8x16_t s1 = vmovq_n_u8(
'\\');
1487 const uint8x16_t s2 = vmovq_n_u8(
'\b');
1488 const uint8x16_t s3 = vmovq_n_u8(32);
1491 const uint8x16_t
s = vld1q_u8(reinterpret_cast<uint8_t *>(p));
1492 uint8x16_t
x = vceqq_u8(s, s0);
1493 x = vorrq_u8(x, vceqq_u8(s, s1));
1494 x = vorrq_u8(x, vceqq_u8(s, s2));
1495 x = vorrq_u8(x, vcltq_u8(s, s3));
1498 uint64_t low = vgetq_lane_u64(vreinterpretq_u64_u8(x), 0);
1499 uint64_t high = vgetq_lane_u64(vreinterpretq_u64_u8(x), 1);
1516 #endif // RAPIDJSON_NEON 1518 template <
typename InputStream,
bool backup,
bool pushOnTake>
1521 template <
typename InputStream>
1524 typedef typename InputStream::Ch
Ch;
1530 RAPIDJSON_FORCEINLINE Ch
Peek()
const {
return is.
Peek(); }
1533 RAPIDJSON_FORCEINLINE
void Push(
char) {}
1537 const char *
Pop() {
return 0; }
1545 template <
typename InputStream>
1552 : Base(reader, is), stackStream(reader.stack_) {}
1555 stackStream.Put(static_cast<char>(Base::is.Peek()));
1556 return Base::is.Take();
1559 RAPIDJSON_FORCEINLINE
void Push(
char c) { stackStream.Put(c); }
1561 size_t Length() {
return stackStream.Length(); }
1564 stackStream.Put(
'\0');
1565 return stackStream.Pop();
1572 template <
typename InputStream>
1580 RAPIDJSON_FORCEINLINE Ch
Take() {
return Base::TakePush(); }
1583 template <
unsigned parseFlags,
typename InputStream,
typename Handler>
1594 size_t startOffset =
s.Tell();
1596 bool useNanOrInf =
false;
1599 bool minus = Consume(
s,
'-');
1604 bool use64bit =
false;
1605 int significandDigit = 0;
1610 i =
static_cast<unsigned>(
s.TakePush() -
'0');
1621 i = i * 10 +
static_cast<unsigned>(
s.TakePush() -
'0');
1633 i = i * 10 +
static_cast<unsigned>(
s.TakePush() -
'0');
1640 if (Consume(
s,
'N')) {
1641 if (Consume(
s,
'a') && Consume(
s,
'N')) {
1642 d = std::numeric_limits<double>::quiet_NaN();
1646 if (Consume(
s,
'n') && Consume(
s,
'f')) {
1647 d = (minus ? -std::numeric_limits<double>::infinity()
1648 : std::numeric_limits<double>::infinity());
1652 !(Consume(
s,
'i') && Consume(
s,
'n') &&
1653 Consume(
s,
'i') && Consume(
s,
't') &&
1654 Consume(
s,
'y')))) {
1667 bool useDouble =
false;
1674 0x0CCCCCCC, 0xCCCCCCCC)))
1678 d =
static_cast<double>(i64);
1682 i64 = i64 * 10 +
static_cast<unsigned>(
s.TakePush() -
'0');
1694 d =
static_cast<double>(i64);
1698 i64 = i64 * 10 +
static_cast<unsigned>(
s.TakePush() -
'0');
1706 d = d * 10 + (
s.TakePush() -
'0');
1712 size_t decimalPosition;
1713 if (Consume(
s,
'.')) {
1714 decimalPosition =
s.Length();
1722 if (!use64bit) i64 = i;
1729 i64 = i64 * 10 +
static_cast<unsigned>(
s.TakePush() -
'0');
1731 if (i64 != 0) significandDigit++;
1735 d =
static_cast<double>(i64);
1738 d =
static_cast<double>(use64bit ? i64 : i);
1744 if (significandDigit < 17) {
1745 d = d * 10.0 + (
s.TakePush() -
'0');
1752 decimalPosition =
s.Length();
1756 if (Consume(
s,
'e') || Consume(
s,
'E')) {
1758 d =
static_cast<double>(use64bit ? i64 : i);
1762 bool expMinus =
false;
1763 if (Consume(
s,
'+'))
1765 else if (Consume(
s,
'-'))
1769 exp =
static_cast<int>(
s.Take() -
'0');
1778 int maxExp = (expFrac + 2147483639) / 10;
1781 exp = exp * 10 +
static_cast<int>(
s.Take() -
'0');
1790 int maxExp = 308 - expFrac;
1792 exp = exp * 10 +
static_cast<int>(
s.Take() -
'0');
1800 if (expMinus) exp = -exp;
1807 if (parseFlags & kParseInsituFlag) {
1809 typename InputStream::Ch *head = is.PutBegin();
1810 const size_t length =
s.Tell() - startOffset;
1814 const typename TargetEncoding::Ch *
const str =
1815 reinterpret_cast<typename TargetEncoding::Ch *
>(head);
1816 cont = handler.RawNumber(str,
SizeType(length),
false);
1821 while (numCharsToCopy--) {
1824 dstStream.Put(
'\0');
1825 const typename TargetEncoding::Ch *str = dstStream.Pop();
1827 cont = handler.RawNumber(str,
SizeType(length),
true);
1831 const char *decimal =
1835 int p = exp + expFrac;
1838 decimalPosition, exp);
1843 if (d > (std::numeric_limits<double>::max)()) {
1849 cont = handler.Double(minus ? -d : d);
1850 }
else if (useNanOrInf) {
1851 cont = handler.Double(d);
1855 cont = handler.Int64(static_cast<int64_t>(~i64 + 1));
1857 cont = handler.Uint64(i64);
1860 cont = handler.Int(static_cast<int32_t>(~i + 1));
1862 cont = handler.Uint(i);
1871 template <
unsigned parseFlags,
typename InputStream,
typename Handler>
1873 switch (is.Peek()) {
1875 ParseNull<parseFlags>(is, handler);
1878 ParseTrue<parseFlags>(is, handler);
1881 ParseFalse<parseFlags>(is, handler);
1884 ParseString<parseFlags>(is, handler);
1887 ParseObject<parseFlags>(is, handler);
1890 ParseArray<parseFlags>(is, handler);
1893 ParseNumber<parseFlags>(is, handler);
1902 IterativeParsingFinishState = 0,
1925 cIterativeParsingStateCount
1930 LeftBracketToken = 0,
1950 #define N NumberToken 1951 #define N16 N, N, N, N, N, N, N, N, N, N, N, N, N, N, N, N 1953 static const unsigned char tokenMap[256] = {
1978 N, LeftBracketToken,
1979 N, RightBracketToken,
1994 N, LeftCurlyBracketToken,
1995 N, RightCurlyBracketToken,
2006 if (
sizeof(Ch) == 1 || static_cast<unsigned>(c) < 256)
2007 return static_cast<Token>(tokenMap[
static_cast<unsigned char>(c)]);
2015 static const char G[cIterativeParsingStateCount][kTokenCount] = {
2017 {IterativeParsingErrorState, IterativeParsingErrorState,
2018 IterativeParsingErrorState, IterativeParsingErrorState,
2019 IterativeParsingErrorState, IterativeParsingErrorState,
2020 IterativeParsingErrorState, IterativeParsingErrorState,
2021 IterativeParsingErrorState, IterativeParsingErrorState,
2022 IterativeParsingErrorState},
2024 {IterativeParsingErrorState, IterativeParsingErrorState,
2025 IterativeParsingErrorState, IterativeParsingErrorState,
2026 IterativeParsingErrorState, IterativeParsingErrorState,
2027 IterativeParsingErrorState, IterativeParsingErrorState,
2028 IterativeParsingErrorState, IterativeParsingErrorState,
2029 IterativeParsingErrorState},
2032 IterativeParsingArrayInitialState,
2033 IterativeParsingErrorState,
2034 IterativeParsingObjectInitialState,
2035 IterativeParsingErrorState,
2036 IterativeParsingErrorState,
2037 IterativeParsingErrorState,
2038 IterativeParsingValueState,
2039 IterativeParsingValueState,
2040 IterativeParsingValueState,
2041 IterativeParsingValueState,
2042 IterativeParsingValueState
2046 IterativeParsingErrorState,
2047 IterativeParsingErrorState,
2048 IterativeParsingErrorState,
2049 IterativeParsingObjectFinishState,
2050 IterativeParsingErrorState,
2051 IterativeParsingErrorState,
2052 IterativeParsingMemberKeyState,
2053 IterativeParsingErrorState,
2054 IterativeParsingErrorState,
2055 IterativeParsingErrorState,
2056 IterativeParsingErrorState
2060 IterativeParsingErrorState,
2061 IterativeParsingErrorState,
2062 IterativeParsingErrorState,
2063 IterativeParsingErrorState,
2064 IterativeParsingErrorState,
2065 IterativeParsingKeyValueDelimiterState,
2066 IterativeParsingErrorState,
2067 IterativeParsingErrorState,
2068 IterativeParsingErrorState,
2069 IterativeParsingErrorState,
2070 IterativeParsingErrorState
2074 IterativeParsingErrorState,
2075 IterativeParsingErrorState,
2076 IterativeParsingErrorState,
2077 IterativeParsingObjectFinishState,
2078 IterativeParsingMemberDelimiterState,
2079 IterativeParsingErrorState,
2080 IterativeParsingErrorState,
2081 IterativeParsingErrorState,
2082 IterativeParsingErrorState,
2083 IterativeParsingErrorState,
2084 IterativeParsingErrorState
2087 {IterativeParsingErrorState, IterativeParsingErrorState,
2088 IterativeParsingErrorState, IterativeParsingErrorState,
2089 IterativeParsingErrorState, IterativeParsingErrorState,
2090 IterativeParsingErrorState, IterativeParsingErrorState,
2091 IterativeParsingErrorState, IterativeParsingErrorState,
2092 IterativeParsingErrorState},
2095 IterativeParsingArrayInitialState,
2097 IterativeParsingArrayFinishState,
2098 IterativeParsingObjectInitialState,
2100 IterativeParsingErrorState,
2101 IterativeParsingErrorState,
2102 IterativeParsingErrorState,
2103 IterativeParsingElementState,
2104 IterativeParsingElementState,
2105 IterativeParsingElementState,
2106 IterativeParsingElementState,
2107 IterativeParsingElementState
2111 IterativeParsingErrorState,
2112 IterativeParsingArrayFinishState,
2113 IterativeParsingErrorState,
2114 IterativeParsingErrorState,
2115 IterativeParsingElementDelimiterState,
2116 IterativeParsingErrorState,
2117 IterativeParsingErrorState,
2118 IterativeParsingErrorState,
2119 IterativeParsingErrorState,
2120 IterativeParsingErrorState,
2121 IterativeParsingErrorState
2124 {IterativeParsingErrorState, IterativeParsingErrorState,
2125 IterativeParsingErrorState, IterativeParsingErrorState,
2126 IterativeParsingErrorState, IterativeParsingErrorState,
2127 IterativeParsingErrorState, IterativeParsingErrorState,
2128 IterativeParsingErrorState, IterativeParsingErrorState,
2129 IterativeParsingErrorState},
2131 {IterativeParsingErrorState, IterativeParsingErrorState,
2132 IterativeParsingErrorState, IterativeParsingErrorState,
2133 IterativeParsingErrorState, IterativeParsingErrorState,
2134 IterativeParsingErrorState, IterativeParsingErrorState,
2135 IterativeParsingErrorState, IterativeParsingErrorState,
2136 IterativeParsingErrorState},
2139 IterativeParsingArrayInitialState,
2141 IterativeParsingArrayFinishState,
2142 IterativeParsingObjectInitialState,
2144 IterativeParsingErrorState,
2145 IterativeParsingErrorState,
2146 IterativeParsingErrorState,
2147 IterativeParsingElementState,
2148 IterativeParsingElementState,
2149 IterativeParsingElementState,
2150 IterativeParsingElementState,
2151 IterativeParsingElementState
2155 IterativeParsingErrorState,
2156 IterativeParsingErrorState,
2157 IterativeParsingErrorState,
2158 IterativeParsingObjectFinishState,
2159 IterativeParsingErrorState,
2160 IterativeParsingErrorState,
2161 IterativeParsingMemberKeyState,
2162 IterativeParsingErrorState,
2163 IterativeParsingErrorState,
2164 IterativeParsingErrorState,
2165 IterativeParsingErrorState
2169 IterativeParsingArrayInitialState,
2171 IterativeParsingErrorState,
2172 IterativeParsingObjectInitialState,
2174 IterativeParsingErrorState,
2175 IterativeParsingErrorState,
2176 IterativeParsingErrorState,
2177 IterativeParsingMemberValueState,
2178 IterativeParsingMemberValueState,
2179 IterativeParsingMemberValueState,
2180 IterativeParsingMemberValueState,
2181 IterativeParsingMemberValueState
2191 template <
unsigned parseFlags,
typename InputStream,
typename Handler>
2200 case IterativeParsingErrorState:
2203 case IterativeParsingObjectInitialState:
2204 case IterativeParsingArrayInitialState: {
2209 if (src == IterativeParsingArrayInitialState ||
2210 src == IterativeParsingElementDelimiterState)
2211 n = IterativeParsingElementState;
2212 else if (src == IterativeParsingKeyValueDelimiterState)
2213 n = IterativeParsingMemberValueState;
2215 *stack_.template Push<SizeType>(1) = n;
2217 *stack_.template Push<SizeType>(1) = 0;
2219 bool hr = (dst == IterativeParsingObjectInitialState)
2220 ? handler.StartObject()
2221 : handler.StartArray();
2225 return IterativeParsingErrorState;
2232 case IterativeParsingMemberKeyState:
2233 ParseString<parseFlags>(is, handler,
true);
2234 if (HasParseError())
2235 return IterativeParsingErrorState;
2239 case IterativeParsingKeyValueDelimiterState:
2244 case IterativeParsingMemberValueState:
2247 ParseValue<parseFlags>(is, handler);
2248 if (HasParseError()) {
2249 return IterativeParsingErrorState;
2253 case IterativeParsingElementState:
2256 ParseValue<parseFlags>(is, handler);
2257 if (HasParseError()) {
2258 return IterativeParsingErrorState;
2262 case IterativeParsingMemberDelimiterState:
2263 case IterativeParsingElementDelimiterState:
2266 *stack_.template Top<SizeType>() = *stack_.template Top<SizeType>() + 1;
2269 case IterativeParsingObjectFinishState: {
2273 src == IterativeParsingMemberDelimiterState) {
2275 return IterativeParsingErrorState;
2278 SizeType c = *stack_.template Pop<SizeType>(1);
2280 if (src == IterativeParsingMemberValueState) ++c;
2283 *stack_.template Pop<SizeType>(1));
2285 if (n == IterativeParsingStartState) n = IterativeParsingFinishState;
2287 bool hr = handler.EndObject(c);
2291 return IterativeParsingErrorState;
2298 case IterativeParsingArrayFinishState: {
2302 src == IterativeParsingElementDelimiterState) {
2304 return IterativeParsingErrorState;
2307 SizeType c = *stack_.template Pop<SizeType>(1);
2309 if (src == IterativeParsingElementState) ++c;
2312 *stack_.template Pop<SizeType>(1));
2314 if (n == IterativeParsingStartState) n = IterativeParsingFinishState;
2316 bool hr = handler.EndArray(c);
2320 return IterativeParsingErrorState;
2344 ParseValue<parseFlags>(is, handler);
2345 if (HasParseError()) {
2346 return IterativeParsingErrorState;
2348 return IterativeParsingFinishState;
2352 template <
typename InputStream>
2354 if (HasParseError()) {
2360 case IterativeParsingStartState:
2363 case IterativeParsingFinishState:
2366 case IterativeParsingObjectInitialState:
2367 case IterativeParsingMemberDelimiterState:
2370 case IterativeParsingMemberKeyState:
2373 case IterativeParsingMemberValueState:
2377 case IterativeParsingKeyValueDelimiterState:
2378 case IterativeParsingArrayInitialState:
2379 case IterativeParsingElementDelimiterState:
2392 return s >= IterativeParsingElementDelimiterState;
2397 return s <= IterativeParsingErrorState;
2400 template <
unsigned parseFlags,
typename InputStream,
typename Handler>
2402 parseResult_.
Clear();
2406 SkipWhitespaceAndComments<parseFlags>(is);
2407 RAPIDJSON_PARSE_ERROR_EARLY_RETURN(parseResult_);
2408 while (is.Peek() !=
'\0') {
2409 Token t = Tokenize(is.Peek());
2413 if (d == IterativeParsingErrorState) {
2414 HandleError(state, is);
2422 state == IterativeParsingFinishState)
2425 SkipWhitespaceAndComments<parseFlags>(is);
2426 RAPIDJSON_PARSE_ERROR_EARLY_RETURN(parseResult_);
2430 if (state != IterativeParsingFinishState) HandleError(state, is);
2432 return parseResult_;
2435 static const size_t kDefaultStackCapacity =
2450 #if defined(__clang__) || defined(_MSC_VER) 2458 #endif // RAPIDJSON_READER_H_
bool RawNumber(const Ch *str, SizeType len, bool copy)
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.)
Represents an in-memory input byte stream.
#define RAPIDJSON_ASSERT(x)
Assertion.
#define RAPIDJSON_UINT64_C2(high32, low32)
Construct a 64-bit literal by a pair of 32-bit integer.
RAPIDJSON_FORCEINLINE bool IsIterativeParsingDelimiterState(IterativeParsingState s) const
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.
bool String(const Ch *, SizeType, bool)
ParseErrorCode GetParseErrorCode() const
Get the ParseErrorCode of last parsing.
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.
internal::Stack< StackAllocator > & stack_
A read-write string stream.
Number too big to be stored in double.
Parse all numbers (ints/doubles) as strings.
SourceEncoding::Ch Ch
SourceEncoding character type.
unsigned ParseHex4(InputStream &is, size_t escapeOffset)
Parse number in full precision (but slower).
void ParseTrue(InputStream &is, Handler &handler)
bool HasParseError() const
Whether a parse error has occurred 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_
bool IterativeParseNext(InputStream &is, Handler &handler)
Parse one token from JSON text.
void ParseFalse(InputStream &is, Handler &handler)
TFSIMD_FORCE_INLINE const tfScalar & x() const
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 IsIterativeParsingCompleteState(IterativeParsingState s) const
C-runtime library allocator.
void SkipWhitespace(InputStream &is)
Skip the JSON white spaces in a stream.
TFSIMD_FORCE_INLINE const tfScalar & w() const
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_
#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)
TFSIMD_FORCE_INLINE tfScalar length(const Quaternion &q)
void IterativeParseInit()
Initialize JSON text token-by-token parsing.
void ParseNull(InputStream &is, Handler &handler)
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.
static RAPIDJSON_FORCEINLINE void ScanCopyUnescapedString(InputStream &, OutputStream &)
RAPIDJSON_FORCEINLINE Token Tokenize(Ch c) const
RAPIDJSON_FORCEINLINE IterativeParsingState Predict(IterativeParsingState state, Token token) const
In-situ(destructive) parsing.
RAPIDJSON_FORCEINLINE bool IterativeParseComplete() const
Check if token-by-token parsing JSON text is complete.
Allow one-line (//) and multi-line (/**/) comments.