15 #ifndef RAPIDJSON_READER_H_ 16 #define RAPIDJSON_READER_H_ 28 #if defined(RAPIDJSON_SIMD) && defined(_MSC_VER) 30 #pragma intrinsic(_BitScanForward) 33 #include <nmmintrin.h> 34 #elif defined(RAPIDJSON_SSE2) 35 #include <emmintrin.h> 36 #elif defined(RAPIDJSON_NEON) 42 RAPIDJSON_DIAG_OFF(old - style - cast)
43 RAPIDJSON_DIAG_OFF(padded)
44 RAPIDJSON_DIAG_OFF(switch - enum)
45 #elif defined(_MSC_VER) 47 RAPIDJSON_DIAG_OFF(4127)
48 RAPIDJSON_DIAG_OFF(4702)
53 RAPIDJSON_DIAG_OFF(effc++)
57 #define RAPIDJSON_NOTHING 58 #ifndef RAPIDJSON_PARSE_ERROR_EARLY_RETURN 59 #define RAPIDJSON_PARSE_ERROR_EARLY_RETURN(value) \ 60 RAPIDJSON_MULTILINEMACRO_BEGIN \ 61 if (RAPIDJSON_UNLIKELY(HasParseError())) \ 65 RAPIDJSON_MULTILINEMACRO_END 67 #define RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID 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 201 template <
typename Encoding = UTF8<>,
typename Derived =
void>
204 typedef typename Encoding::Ch
Ch;
214 return static_cast<Override&
>(*this).Default();
218 return static_cast<Override&
>(*this).Default();
222 return static_cast<Override&
>(*this).Default();
226 return static_cast<Override&
>(*this).Default();
230 return static_cast<Override&
>(*this).Default();
234 return static_cast<Override&
>(*this).Default();
238 return static_cast<Override&
>(*this).Default();
243 return static_cast<Override&
>(*this).String(str, len, copy);
247 return static_cast<Override&
>(*this).Default();
251 return static_cast<Override&
>(*this).Default();
255 return static_cast<Override&
>(*this).String(str, len, copy);
259 return static_cast<Override&
>(*this).Default();
263 return static_cast<Override&
>(*this).Default();
267 return static_cast<Override&
>(*this).Default();
276 template <typename Stream, int = StreamTraits<Stream>::copyOptimization>
280 template <
typename Stream>
301 template <
typename Stream>
324 template <
typename InputStream>
328 InputStream&
s(copy.s);
330 typename InputStream::Ch c;
331 while ((c = s.Peek()) ==
' ' || c ==
'\n' || c ==
'\r' || c ==
'\t')
337 while (p != end && (*p ==
' ' || *p ==
'\n' || *p ==
'\r' || *p ==
'\t'))
343 inline const char* SkipWhitespace_SIMD(
const char* p)
347 if (*p ==
' ' || *p ==
'\n' || *p ==
'\r' || *p ==
'\t')
353 const char* nextAligned =
354 reinterpret_cast<const char*
>((
reinterpret_cast<size_t>(p) + 15) &
static_cast<size_t>(~15));
355 while (p != nextAligned)
356 if (*p ==
' ' || *p ==
'\n' || *p ==
'\r' || *p ==
'\t')
362 static const char whitespace[16] =
" \n\r\t";
363 const __m128i w = _mm_loadu_si128(reinterpret_cast<const __m128i*>(&whitespace[0]));
367 const __m128i
s = _mm_load_si128(reinterpret_cast<const __m128i*>(p));
369 _mm_cmpistri(w, s, _SIDD_UBYTE_OPS | _SIDD_CMP_EQUAL_ANY | _SIDD_LEAST_SIGNIFICANT | _SIDD_NEGATIVE_POLARITY);
375 inline const char* SkipWhitespace_SIMD(
const char* p,
const char* end)
378 if (p != end && (*p ==
' ' || *p ==
'\n' || *p ==
'\r' || *p ==
'\t'))
384 static const char whitespace[16] =
" \n\r\t";
385 const __m128i w = _mm_loadu_si128(reinterpret_cast<const __m128i*>(&whitespace[0]));
387 for (; p <= end - 16; p += 16)
389 const __m128i
s = _mm_loadu_si128(reinterpret_cast<const __m128i*>(p));
391 _mm_cmpistri(w, s, _SIDD_UBYTE_OPS | _SIDD_CMP_EQUAL_ANY | _SIDD_LEAST_SIGNIFICANT | _SIDD_NEGATIVE_POLARITY);
399 #elif defined(RAPIDJSON_SSE2) 402 inline const char* SkipWhitespace_SIMD(
const char* p)
405 if (*p ==
' ' || *p ==
'\n' || *p ==
'\r' || *p ==
'\t')
411 const char* nextAligned =
412 reinterpret_cast<const char*
>((
reinterpret_cast<size_t>(p) + 15) &
static_cast<size_t>(~15));
413 while (p != nextAligned)
414 if (*p ==
' ' || *p ==
'\n' || *p ==
'\r' || *p ==
'\t')
422 c, c, c, c, c, c, c, c, c, c, c, c, c, c, c, c \ 424 static const char whitespaces[4][16] = { C16(
' '), C16(
'\n'), C16(
'\r'), C16(
'\t') };
427 const __m128i w0 = _mm_loadu_si128(reinterpret_cast<const __m128i*>(&whitespaces[0][0]));
428 const __m128i w1 = _mm_loadu_si128(reinterpret_cast<const __m128i*>(&whitespaces[1][0]));
429 const __m128i w2 = _mm_loadu_si128(reinterpret_cast<const __m128i*>(&whitespaces[2][0]));
430 const __m128i w3 = _mm_loadu_si128(reinterpret_cast<const __m128i*>(&whitespaces[3][0]));
434 const __m128i
s = _mm_load_si128(reinterpret_cast<const __m128i*>(p));
435 __m128i x = _mm_cmpeq_epi8(s, w0);
436 x = _mm_or_si128(x, _mm_cmpeq_epi8(s, w1));
437 x = _mm_or_si128(x, _mm_cmpeq_epi8(s, w2));
438 x = _mm_or_si128(x, _mm_cmpeq_epi8(s, w3));
439 unsigned short r =
static_cast<unsigned short>(~_mm_movemask_epi8(x));
442 #if _MSC_VER // Find the index of first non-whitespace 443 unsigned long offset;
444 _BitScanForward(&offset, r);
447 return p + __builtin_ffs(r) - 1;
453 inline const char* SkipWhitespace_SIMD(
const char* p,
const char* end)
456 if (p != end && (*p ==
' ' || *p ==
'\n' || *p ==
'\r' || *p ==
'\t'))
464 c, c, c, c, c, c, c, c, c, c, c, c, c, c, c, c \ 466 static const char whitespaces[4][16] = { C16(
' '), C16(
'\n'), C16(
'\r'), C16(
'\t') };
469 const __m128i w0 = _mm_loadu_si128(reinterpret_cast<const __m128i*>(&whitespaces[0][0]));
470 const __m128i w1 = _mm_loadu_si128(reinterpret_cast<const __m128i*>(&whitespaces[1][0]));
471 const __m128i w2 = _mm_loadu_si128(reinterpret_cast<const __m128i*>(&whitespaces[2][0]));
472 const __m128i w3 = _mm_loadu_si128(reinterpret_cast<const __m128i*>(&whitespaces[3][0]));
474 for (; p <= end - 16; p += 16)
476 const __m128i
s = _mm_loadu_si128(reinterpret_cast<const __m128i*>(p));
477 __m128i x = _mm_cmpeq_epi8(s, w0);
478 x = _mm_or_si128(x, _mm_cmpeq_epi8(s, w1));
479 x = _mm_or_si128(x, _mm_cmpeq_epi8(s, w2));
480 x = _mm_or_si128(x, _mm_cmpeq_epi8(s, w3));
481 unsigned short r =
static_cast<unsigned short>(~_mm_movemask_epi8(x));
484 #if _MSC_VER // Find the index of first non-whitespace 485 unsigned long offset;
486 _BitScanForward(&offset, r);
489 return p + __builtin_ffs(r) - 1;
497 #elif defined(RAPIDJSON_NEON) 500 inline const char* SkipWhitespace_SIMD(
const char* p)
503 if (*p ==
' ' || *p ==
'\n' || *p ==
'\r' || *p ==
'\t')
509 const char* nextAligned =
510 reinterpret_cast<const char*
>((
reinterpret_cast<size_t>(p) + 15) &
static_cast<size_t>(~15));
511 while (p != nextAligned)
512 if (*p ==
' ' || *p ==
'\n' || *p ==
'\r' || *p ==
'\t')
517 const uint8x16_t w0 = vmovq_n_u8(
' ');
518 const uint8x16_t w1 = vmovq_n_u8(
'\n');
519 const uint8x16_t w2 = vmovq_n_u8(
'\r');
520 const uint8x16_t w3 = vmovq_n_u8(
'\t');
524 const uint8x16_t
s = vld1q_u8(reinterpret_cast<const uint8_t*>(p));
525 uint8x16_t x = vceqq_u8(s, w0);
526 x = vorrq_u8(x, vceqq_u8(s, w1));
527 x = vorrq_u8(x, vceqq_u8(s, w2));
528 x = vorrq_u8(x, vceqq_u8(s, w3));
532 uint64_t low = vgetq_lane_u64(reinterpret_cast<uint64x2_t>(x), 0);
533 uint64_t high = vgetq_lane_u64(reinterpret_cast<uint64x2_t>(x), 1);
539 int lz = __builtin_clzll(high);
541 return p + 8 + (lz >> 3);
546 int lz = __builtin_clzll(low);
548 return p + (lz >> 3);
553 inline const char* SkipWhitespace_SIMD(
const char* p,
const char* end)
556 if (p != end && (*p ==
' ' || *p ==
'\n' || *p ==
'\r' || *p ==
'\t'))
561 const uint8x16_t w0 = vmovq_n_u8(
' ');
562 const uint8x16_t w1 = vmovq_n_u8(
'\n');
563 const uint8x16_t w2 = vmovq_n_u8(
'\r');
564 const uint8x16_t w3 = vmovq_n_u8(
'\t');
566 for (; p <= end - 16; p += 16)
568 const uint8x16_t
s = vld1q_u8(reinterpret_cast<const uint8_t*>(p));
569 uint8x16_t x = vceqq_u8(s, w0);
570 x = vorrq_u8(x, vceqq_u8(s, w1));
571 x = vorrq_u8(x, vceqq_u8(s, w2));
572 x = vorrq_u8(x, vceqq_u8(s, w3));
576 uint64_t low = vgetq_lane_u64(reinterpret_cast<uint64x2_t>(x), 0);
577 uint64_t high = vgetq_lane_u64(reinterpret_cast<uint64x2_t>(x), 1);
583 int lz = __builtin_clzll(high);
584 return p + 8 + (lz >> 3);
589 int lz = __builtin_clzll(low);
590 return p + (lz >> 3);
597 #endif // RAPIDJSON_NEON 604 is.
src_ =
const_cast<char*
>(SkipWhitespace_SIMD(is.
src_));
611 is.
src_ = SkipWhitespace_SIMD(is.
src_);
617 is.is_.
src_ = SkipWhitespace_SIMD(is.is_.
src_, is.is_.end_);
619 #endif // RAPIDJSON_SIMD 640 template <
typename SourceEncoding,
typename TargetEncoding,
typename StackAllocator = CrtAllocator>
644 typedef typename SourceEncoding::Ch
Ch;
651 GenericReader(StackAllocator* stackAllocator = 0,
size_t stackCapacity = kDefaultStackCapacity)
652 : stack_(stackAllocator, stackCapacity), parseResult_(), state_(IterativeParsingStartState)
664 template <
unsigned parseFlags,
typename InputStream,
typename Handler>
668 return IterativeParse<parseFlags>(is, handler);
670 parseResult_.
Clear();
674 SkipWhitespaceAndComments<parseFlags>(is);
675 RAPIDJSON_PARSE_ERROR_EARLY_RETURN(parseResult_);
680 RAPIDJSON_PARSE_ERROR_EARLY_RETURN(parseResult_);
684 ParseValue<parseFlags>(is, handler);
685 RAPIDJSON_PARSE_ERROR_EARLY_RETURN(parseResult_);
689 SkipWhitespaceAndComments<parseFlags>(is);
690 RAPIDJSON_PARSE_ERROR_EARLY_RETURN(parseResult_);
695 RAPIDJSON_PARSE_ERROR_EARLY_RETURN(parseResult_);
710 template <
typename InputStream,
typename Handler>
713 return Parse<kParseDefaultFlags>(is, handler);
721 parseResult_.Clear();
722 state_ = IterativeParsingStartState;
732 template <
unsigned parseFlags,
typename InputStream,
typename Handler>
737 SkipWhitespaceAndComments<parseFlags>(is);
739 Token t = Tokenize(is.Peek());
747 if (d == IterativeParsingErrorState)
749 HandleError(state_, is);
761 SkipWhitespaceAndComments<parseFlags>(is);
762 if (is.Peek() !=
'\0')
765 HandleError(state_, is);
778 if (!IsIterativeParsingDelimiterState(n))
785 if (state_ != IterativeParsingFinishState)
787 HandleError(state_, is);
799 return IsIterativeParsingCompleteState(state_);
805 return parseResult_.IsError();
811 return parseResult_.Code();
817 return parseResult_.Offset();
823 parseResult_.Set(code, offset);
853 template <
unsigned parseFlags,
typename InputStream>
862 if (Consume(is,
'*'))
868 else if (Consume(is,
'*'))
870 if (Consume(is,
'/'))
878 while (is.Peek() !=
'\0' && is.Take() !=
'\n')
890 template <
unsigned parseFlags,
typename InputStream,
typename Handler>
899 SkipWhitespaceAndComments<parseFlags>(is);
900 RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
902 if (Consume(is,
'}'))
914 ParseString<parseFlags>(is, handler,
true);
915 RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
917 SkipWhitespaceAndComments<parseFlags>(is);
918 RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
923 SkipWhitespaceAndComments<parseFlags>(is);
924 RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
926 ParseValue<parseFlags>(is, handler);
927 RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
929 SkipWhitespaceAndComments<parseFlags>(is);
930 RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
938 SkipWhitespaceAndComments<parseFlags>(is);
939 RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
953 if (is.Peek() ==
'}')
965 template <
unsigned parseFlags,
typename InputStream,
typename Handler>
974 SkipWhitespaceAndComments<parseFlags>(is);
975 RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
977 if (Consume(is,
']'))
986 ParseValue<parseFlags>(is, handler);
987 RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
990 SkipWhitespaceAndComments<parseFlags>(is);
991 RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
993 if (Consume(is,
','))
995 SkipWhitespaceAndComments<parseFlags>(is);
996 RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
998 else if (Consume(is,
']'))
1009 if (is.Peek() ==
']')
1020 template <
unsigned parseFlags,
typename InputStream,
typename Handler>
1026 if (
RAPIDJSON_LIKELY(Consume(is,
'u') && Consume(is,
'l') && Consume(is,
'l')))
1035 template <
unsigned parseFlags,
typename InputStream,
typename Handler>
1041 if (
RAPIDJSON_LIKELY(Consume(is,
'r') && Consume(is,
'u') && Consume(is,
'e')))
1050 template <
unsigned parseFlags,
typename InputStream,
typename Handler>
1056 if (
RAPIDJSON_LIKELY(Consume(is,
'a') && Consume(is,
'l') && Consume(is,
's') && Consume(is,
'e')))
1065 template <
typename InputStream>
1066 RAPIDJSON_FORCEINLINE
static bool Consume(InputStream& is,
typename InputStream::Ch expect)
1078 template <
typename InputStream>
1081 unsigned codepoint = 0;
1082 for (
int i = 0; i < 4; i++)
1086 codepoint +=
static_cast<unsigned>(c);
1087 if (c >=
'0' && c <=
'9')
1089 else if (c >=
'A' && c <=
'F')
1090 codepoint -=
'A' - 10;
1091 else if (c >=
'a' && c <=
'f')
1092 codepoint -=
'a' - 10;
1096 RAPIDJSON_PARSE_ERROR_EARLY_RETURN(0);
1103 template <
typename CharType>
1112 RAPIDJSON_FORCEINLINE
void Put(Ch c)
1114 *stack_.template Push<Ch>() = c;
1121 return stack_.template Push<Ch>(
count);
1131 return stack_.template Pop<Ch>(length_);
1143 template <
unsigned parseFlags,
typename InputStream,
typename Handler>
1144 void ParseString(InputStream& is, Handler& handler,
bool isKey =
false)
1147 InputStream&
s(copy.s);
1152 bool success =
false;
1155 typename InputStream::Ch* head = s.PutBegin();
1156 ParseStringToStream<parseFlags, SourceEncoding, SourceEncoding>(s, s);
1157 RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
1158 size_t length = s.PutEnd(head) - 1;
1160 const typename TargetEncoding::Ch*
const str =
reinterpret_cast<typename TargetEncoding::Ch*
>(head);
1161 success = (isKey ? handler.Key(str,
SizeType(length),
false) : handler.String(str,
SizeType(length),
false));
1166 ParseStringToStream<parseFlags, SourceEncoding, TargetEncoding>(s, stackStream);
1167 RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
1169 const typename TargetEncoding::Ch*
const str = stackStream.
Pop();
1170 success = (isKey ? handler.Key(str, length,
true) : handler.String(str, length,
true));
1178 template <
unsigned parseFlags,
typename SEncoding,
typename TEncoding,
typename InputStream,
typename OutputStream>
1182 #define Z16 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 1183 static const char escape[256] = {
Z16,
Z16, 0, 0,
'\"', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1184 0,
'/',
Z16,
Z16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1185 '\\', 0, 0, 0, 0, 0,
'\b', 0, 0, 0,
'\f', 0, 0, 0, 0, 0,
1186 0, 0,
'\n', 0, 0, 0,
'\r', 0,
'\t', 0, 0, 0, 0, 0, 0, 0,
1187 0, 0, 0, 0,
Z16,
Z16,
Z16,
Z16,
Z16,
Z16,
Z16, Z16 };
1195 ScanCopyUnescapedString(is, os);
1200 size_t escapeOffset = is.Tell();
1203 if ((
sizeof(Ch) == 1 ||
unsigned(e) < 256) &&
RAPIDJSON_LIKELY(escape[static_cast<unsigned char>(e)]))
1206 os.Put(static_cast<typename TEncoding::Ch>(escape[static_cast<unsigned char>(e)]));
1211 unsigned codepoint = ParseHex4(is, escapeOffset);
1212 RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
1218 unsigned codepoint2 = ParseHex4(is, escapeOffset);
1219 RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
1222 codepoint = (((codepoint - 0xD800) << 10) | (codepoint2 - 0xDC00)) + 0x10000;
1224 TEncoding::Encode(os, codepoint);
1244 size_t offset = is.Tell();
1253 template <
typename InputStream,
typename OutputStream>
1259 #if defined(RAPIDJSON_SSE2) || defined(RAPIDJSON_SSE42) 1263 const char* p = is.
src_;
1266 const char* nextAligned =
1267 reinterpret_cast<const char*
>((
reinterpret_cast<size_t>(p) + 15) &
static_cast<size_t>(~15));
1268 while (p != nextAligned)
1279 static const char dquote[16] = {
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
1280 '\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"' };
1281 static const char bslash[16] = {
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
1282 '\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\' };
1283 static const char space[16] = { 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F,
1284 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F };
1285 const __m128i dq = _mm_loadu_si128(reinterpret_cast<const __m128i*>(&dquote[0]));
1286 const __m128i bs = _mm_loadu_si128(reinterpret_cast<const __m128i*>(&bslash[0]));
1287 const __m128i sp = _mm_loadu_si128(reinterpret_cast<const __m128i*>(&space[0]));
1291 const __m128i
s = _mm_load_si128(reinterpret_cast<const __m128i*>(p));
1292 const __m128i t1 = _mm_cmpeq_epi8(s, dq);
1293 const __m128i t2 = _mm_cmpeq_epi8(s, bs);
1294 const __m128i t3 = _mm_cmpeq_epi8(_mm_max_epu8(s, sp), sp);
1295 const __m128i x = _mm_or_si128(_mm_or_si128(t1, t2), t3);
1296 unsigned short r =
static_cast<unsigned short>(_mm_movemask_epi8(x));
1300 #if _MSC_VER // Find the index of first escaped 1301 unsigned long offset;
1302 _BitScanForward(&offset, r);
1305 length =
static_cast<SizeType>(__builtin_ffs(r) - 1);
1309 char* q =
reinterpret_cast<char*
>(os.
Push(length));
1310 for (
size_t i = 0; i < length; i++)
1317 _mm_storeu_si128(reinterpret_cast<__m128i*>(os.
Push(16)), s);
1331 SkipUnescapedString(is);
1339 const char* nextAligned =
1340 reinterpret_cast<const char*
>((
reinterpret_cast<size_t>(p) + 15) &
static_cast<size_t>(~15));
1341 while (p != nextAligned)
1353 static const char dquote[16] = {
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
1354 '\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"' };
1355 static const char bslash[16] = {
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
1356 '\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\' };
1357 static const char space[16] = { 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F,
1358 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F };
1359 const __m128i dq = _mm_loadu_si128(reinterpret_cast<const __m128i*>(&dquote[0]));
1360 const __m128i bs = _mm_loadu_si128(reinterpret_cast<const __m128i*>(&bslash[0]));
1361 const __m128i sp = _mm_loadu_si128(reinterpret_cast<const __m128i*>(&space[0]));
1363 for (;; p += 16, q += 16)
1365 const __m128i
s = _mm_load_si128(reinterpret_cast<const __m128i*>(p));
1366 const __m128i t1 = _mm_cmpeq_epi8(s, dq);
1367 const __m128i t2 = _mm_cmpeq_epi8(s, bs);
1368 const __m128i t3 = _mm_cmpeq_epi8(_mm_max_epu8(s, sp), sp);
1369 const __m128i x = _mm_or_si128(_mm_or_si128(t1, t2), t3);
1370 unsigned short r =
static_cast<unsigned short>(_mm_movemask_epi8(x));
1374 #if _MSC_VER // Find the index of first escaped 1375 unsigned long offset;
1376 _BitScanForward(&offset, r);
1379 length =
static_cast<size_t>(__builtin_ffs(r) - 1);
1381 for (
const char* pend = p + length; p != pend;)
1385 _mm_storeu_si128(reinterpret_cast<__m128i*>(q), s);
1399 const char* nextAligned =
1400 reinterpret_cast<const char*
>((
reinterpret_cast<size_t>(p) + 15) &
static_cast<size_t>(~15));
1401 for (; p != nextAligned; p++)
1410 static const char dquote[16] = {
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
1411 '\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"' };
1412 static const char bslash[16] = {
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
1413 '\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\' };
1414 static const char space[16] = { 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F,
1415 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F };
1416 const __m128i dq = _mm_loadu_si128(reinterpret_cast<const __m128i*>(&dquote[0]));
1417 const __m128i bs = _mm_loadu_si128(reinterpret_cast<const __m128i*>(&bslash[0]));
1418 const __m128i sp = _mm_loadu_si128(reinterpret_cast<const __m128i*>(&space[0]));
1422 const __m128i
s = _mm_load_si128(reinterpret_cast<const __m128i*>(p));
1423 const __m128i t1 = _mm_cmpeq_epi8(s, dq);
1424 const __m128i t2 = _mm_cmpeq_epi8(s, bs);
1425 const __m128i t3 = _mm_cmpeq_epi8(_mm_max_epu8(s, sp), sp);
1426 const __m128i x = _mm_or_si128(_mm_or_si128(t1, t2), t3);
1427 unsigned short r =
static_cast<unsigned short>(_mm_movemask_epi8(x));
1431 #if _MSC_VER // Find the index of first escaped 1432 unsigned long offset;
1433 _BitScanForward(&offset, r);
1436 length =
static_cast<size_t>(__builtin_ffs(r) - 1);
1445 #elif defined(RAPIDJSON_NEON) 1449 const char* p = is.
src_;
1452 const char* nextAligned =
1453 reinterpret_cast<const char*
>((
reinterpret_cast<size_t>(p) + 15) &
static_cast<size_t>(~15));
1454 while (p != nextAligned)
1465 const uint8x16_t s0 = vmovq_n_u8(
'"');
1466 const uint8x16_t s1 = vmovq_n_u8(
'\\');
1467 const uint8x16_t s2 = vmovq_n_u8(
'\b');
1468 const uint8x16_t s3 = vmovq_n_u8(32);
1472 const uint8x16_t
s = vld1q_u8(reinterpret_cast<const uint8_t*>(p));
1473 uint8x16_t x = vceqq_u8(s, s0);
1474 x = vorrq_u8(x, vceqq_u8(s, s1));
1475 x = vorrq_u8(x, vceqq_u8(s, s2));
1476 x = vorrq_u8(x, vcltq_u8(s, s3));
1479 uint64_t low = vgetq_lane_u64(reinterpret_cast<uint64x2_t>(x), 0);
1480 uint64_t high = vgetq_lane_u64(reinterpret_cast<uint64x2_t>(x), 1);
1483 bool escaped =
false;
1488 unsigned lz = (unsigned)__builtin_clzll(high);
1490 length = 8 + (lz >> 3);
1496 unsigned lz = (unsigned)__builtin_clzll(low);
1505 char* q =
reinterpret_cast<char*
>(os.
Push(length));
1506 for (
size_t i = 0; i < length; i++)
1513 vst1q_u8(reinterpret_cast<uint8_t*>(os.
Push(16)), s);
1527 SkipUnescapedString(is);
1535 const char* nextAligned =
1536 reinterpret_cast<const char*
>((
reinterpret_cast<size_t>(p) + 15) &
static_cast<size_t>(~15));
1537 while (p != nextAligned)
1549 const uint8x16_t s0 = vmovq_n_u8(
'"');
1550 const uint8x16_t s1 = vmovq_n_u8(
'\\');
1551 const uint8x16_t s2 = vmovq_n_u8(
'\b');
1552 const uint8x16_t s3 = vmovq_n_u8(32);
1554 for (;; p += 16, q += 16)
1556 const uint8x16_t
s = vld1q_u8(reinterpret_cast<uint8_t*>(p));
1557 uint8x16_t x = vceqq_u8(s, s0);
1558 x = vorrq_u8(x, vceqq_u8(s, s1));
1559 x = vorrq_u8(x, vceqq_u8(s, s2));
1560 x = vorrq_u8(x, vcltq_u8(s, s3));
1563 uint64_t low = vgetq_lane_u64(reinterpret_cast<uint64x2_t>(x), 0);
1564 uint64_t high = vgetq_lane_u64(reinterpret_cast<uint64x2_t>(x), 1);
1567 bool escaped =
false;
1572 unsigned lz = (unsigned)__builtin_clzll(high);
1573 length = 8 + (lz >> 3);
1579 unsigned lz = (unsigned)__builtin_clzll(low);
1585 for (
const char* pend = p + length; p != pend;)
1591 vst1q_u8(reinterpret_cast<uint8_t*>(q), s);
1605 const char* nextAligned =
1606 reinterpret_cast<const char*
>((
reinterpret_cast<size_t>(p) + 15) &
static_cast<size_t>(~15));
1607 for (; p != nextAligned; p++)
1616 const uint8x16_t s0 = vmovq_n_u8(
'"');
1617 const uint8x16_t s1 = vmovq_n_u8(
'\\');
1618 const uint8x16_t s2 = vmovq_n_u8(
'\b');
1619 const uint8x16_t s3 = vmovq_n_u8(32);
1623 const uint8x16_t
s = vld1q_u8(reinterpret_cast<uint8_t*>(p));
1624 uint8x16_t x = vceqq_u8(s, s0);
1625 x = vorrq_u8(x, vceqq_u8(s, s1));
1626 x = vorrq_u8(x, vceqq_u8(s, s2));
1627 x = vorrq_u8(x, vcltq_u8(s, s3));
1630 uint64_t low = vgetq_lane_u64(reinterpret_cast<uint64x2_t>(x), 0);
1631 uint64_t high = vgetq_lane_u64(reinterpret_cast<uint64x2_t>(x), 1);
1637 int lz = __builtin_clzll(high);
1644 int lz = __builtin_clzll(low);
1652 #endif // RAPIDJSON_NEON 1654 template <
typename InputStream,
bool backup,
bool pushOnTake>
1657 template <
typename InputStream>
1661 typedef typename InputStream::Ch
Ch;
1668 RAPIDJSON_FORCEINLINE Ch
Peek()
const 1680 RAPIDJSON_FORCEINLINE
void Push(
char)
1703 template <
typename InputStream>
1715 stackStream.Put(static_cast<char>(Base::is.Peek()));
1716 return Base::is.Take();
1719 RAPIDJSON_FORCEINLINE
void Push(
char c)
1726 return stackStream.Length();
1731 stackStream.Put(
'\0');
1732 return stackStream.Pop();
1739 template <
typename InputStream>
1751 return Base::TakePush();
1755 template <
unsigned parseFlags,
typename InputStream,
typename Handler>
1765 size_t startOffset =
s.Tell();
1767 bool useNanOrInf =
false;
1770 bool minus = Consume(
s,
'-');
1775 bool use64bit =
false;
1776 int significandDigit = 0;
1784 i =
static_cast<unsigned>(
s.TakePush() -
'0');
1798 i = i * 10 +
static_cast<unsigned>(
s.TakePush() -
'0');
1813 i = i * 10 +
static_cast<unsigned>(
s.TakePush() -
'0');
1820 if (Consume(
s,
'N'))
1822 if (Consume(
s,
'a') && Consume(
s,
'N'))
1824 d = std::numeric_limits<double>::quiet_NaN();
1830 if (Consume(
s,
'n') && Consume(
s,
'f'))
1832 d = (minus ? -std::numeric_limits<double>::infinity() : std::numeric_limits<double>::infinity());
1837 !(Consume(
s,
'i') && Consume(
s,
'n') && Consume(
s,
'i') && Consume(
s,
't') && Consume(
s,
'y'))))
1853 bool useDouble =
false;
1862 d =
static_cast<double>(i64);
1866 i64 = i64 * 10 +
static_cast<unsigned>(
s.TakePush() -
'0');
1876 d =
static_cast<double>(i64);
1880 i64 = i64 * 10 +
static_cast<unsigned>(
s.TakePush() -
'0');
1890 d = d * 10 + (
s.TakePush() -
'0');
1896 size_t decimalPosition;
1897 if (Consume(
s,
'.'))
1899 decimalPosition =
s.Length();
1917 i64 = i64 * 10 +
static_cast<unsigned>(
s.TakePush() -
'0');
1924 d =
static_cast<double>(i64);
1927 d =
static_cast<double>(use64bit ? i64 : i);
1934 if (significandDigit < 17)
1936 d = d * 10.0 + (
s.TakePush() -
'0');
1946 decimalPosition =
s.Length();
1950 if (Consume(
s,
'e') || Consume(
s,
'E'))
1954 d =
static_cast<double>(use64bit ? i64 : i);
1958 bool expMinus =
false;
1959 if (Consume(
s,
'+'))
1961 else if (Consume(
s,
'-'))
1966 exp =
static_cast<int>(
s.Take() -
'0');
1976 int maxExp = (expFrac + 2147483639) / 10;
1980 exp = exp * 10 +
static_cast<int>(
s.Take() -
'0');
1990 int maxExp = 308 - expFrac;
1993 exp = exp * 10 +
static_cast<int>(
s.Take() -
'0');
2011 if (parseFlags & kParseInsituFlag)
2014 typename InputStream::Ch* head = is.PutBegin();
2015 const size_t length =
s.Tell() - startOffset;
2018 const typename TargetEncoding::Ch*
const str =
reinterpret_cast<typename TargetEncoding::Ch*
>(head);
2019 cont = handler.RawNumber(str,
SizeType(length),
false);
2026 while (numCharsToCopy--)
2030 dstStream.Put(
'\0');
2031 const typename TargetEncoding::Ch* str = dstStream.Pop();
2033 cont = handler.RawNumber(str,
SizeType(length),
true);
2038 size_t length =
s.Length();
2039 const char* decimal =
s.Pop();
2043 int p = exp + expFrac;
2050 if (d > (std::numeric_limits<double>::max)())
2057 cont = handler.Double(minus ? -d : d);
2059 else if (useNanOrInf)
2061 cont = handler.Double(d);
2068 cont = handler.Int64(static_cast<int64_t>(~i64 + 1));
2070 cont = handler.Uint64(i64);
2075 cont = handler.Int(static_cast<int32_t>(~i + 1));
2077 cont = handler.Uint(i);
2086 template <
unsigned parseFlags,
typename InputStream,
typename Handler>
2092 ParseNull<parseFlags>(is, handler);
2095 ParseTrue<parseFlags>(is, handler);
2098 ParseFalse<parseFlags>(is, handler);
2101 ParseString<parseFlags>(is, handler);
2104 ParseObject<parseFlags>(is, handler);
2107 ParseArray<parseFlags>(is, handler);
2110 ParseNumber<parseFlags>(is, handler);
2120 IterativeParsingFinishState = 0,
2143 cIterativeParsingStateCount
2149 LeftBracketToken = 0,
2170 #define N NumberToken 2171 #define N16 N, N, N, N, N, N, N, N, N, N, N, N, N, N, N, N 2173 static const unsigned char tokenMap[256] = {
2198 N, LeftBracketToken,
2199 N, RightBracketToken,
2214 N, LeftCurlyBracketToken,
2215 N, RightCurlyBracketToken,
2226 if (
sizeof(Ch) == 1 || static_cast<unsigned>(c) < 256)
2227 return static_cast<Token>(tokenMap[
static_cast<unsigned char>(c)]);
2235 static const char G[cIterativeParsingStateCount][kTokenCount] = {
2237 { IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState,
2238 IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState,
2239 IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState },
2241 { IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState,
2242 IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState,
2243 IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState },
2246 IterativeParsingArrayInitialState,
2247 IterativeParsingErrorState,
2248 IterativeParsingObjectInitialState,
2249 IterativeParsingErrorState,
2250 IterativeParsingErrorState,
2251 IterativeParsingErrorState,
2252 IterativeParsingValueState,
2253 IterativeParsingValueState,
2254 IterativeParsingValueState,
2255 IterativeParsingValueState,
2256 IterativeParsingValueState
2260 IterativeParsingErrorState,
2261 IterativeParsingErrorState,
2262 IterativeParsingErrorState,
2263 IterativeParsingObjectFinishState,
2264 IterativeParsingErrorState,
2265 IterativeParsingErrorState,
2266 IterativeParsingMemberKeyState,
2267 IterativeParsingErrorState,
2268 IterativeParsingErrorState,
2269 IterativeParsingErrorState,
2270 IterativeParsingErrorState
2274 IterativeParsingErrorState,
2275 IterativeParsingErrorState,
2276 IterativeParsingErrorState,
2277 IterativeParsingErrorState,
2278 IterativeParsingErrorState,
2279 IterativeParsingKeyValueDelimiterState,
2280 IterativeParsingErrorState,
2281 IterativeParsingErrorState,
2282 IterativeParsingErrorState,
2283 IterativeParsingErrorState,
2284 IterativeParsingErrorState
2288 IterativeParsingErrorState,
2289 IterativeParsingErrorState,
2290 IterativeParsingErrorState,
2291 IterativeParsingObjectFinishState,
2292 IterativeParsingMemberDelimiterState,
2293 IterativeParsingErrorState,
2294 IterativeParsingErrorState,
2295 IterativeParsingErrorState,
2296 IterativeParsingErrorState,
2297 IterativeParsingErrorState,
2298 IterativeParsingErrorState
2301 { IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState,
2302 IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState,
2303 IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState },
2306 IterativeParsingArrayInitialState,
2307 IterativeParsingArrayFinishState,
2308 IterativeParsingObjectInitialState,
2309 IterativeParsingErrorState,
2310 IterativeParsingErrorState,
2311 IterativeParsingErrorState,
2312 IterativeParsingElementState,
2313 IterativeParsingElementState,
2314 IterativeParsingElementState,
2315 IterativeParsingElementState,
2316 IterativeParsingElementState
2320 IterativeParsingErrorState,
2321 IterativeParsingArrayFinishState,
2322 IterativeParsingErrorState,
2323 IterativeParsingErrorState,
2324 IterativeParsingElementDelimiterState,
2325 IterativeParsingErrorState,
2326 IterativeParsingErrorState,
2327 IterativeParsingErrorState,
2328 IterativeParsingErrorState,
2329 IterativeParsingErrorState,
2330 IterativeParsingErrorState
2333 { IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState,
2334 IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState,
2335 IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState },
2337 { IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState,
2338 IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState,
2339 IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState },
2342 IterativeParsingArrayInitialState,
2343 IterativeParsingArrayFinishState,
2344 IterativeParsingObjectInitialState,
2345 IterativeParsingErrorState,
2346 IterativeParsingErrorState,
2347 IterativeParsingErrorState,
2348 IterativeParsingElementState,
2349 IterativeParsingElementState,
2350 IterativeParsingElementState,
2351 IterativeParsingElementState,
2352 IterativeParsingElementState
2356 IterativeParsingErrorState,
2357 IterativeParsingErrorState,
2358 IterativeParsingErrorState,
2359 IterativeParsingObjectFinishState,
2360 IterativeParsingErrorState,
2361 IterativeParsingErrorState,
2362 IterativeParsingMemberKeyState,
2363 IterativeParsingErrorState,
2364 IterativeParsingErrorState,
2365 IterativeParsingErrorState,
2366 IterativeParsingErrorState
2370 IterativeParsingArrayInitialState,
2371 IterativeParsingErrorState,
2372 IterativeParsingObjectInitialState,
2373 IterativeParsingErrorState,
2374 IterativeParsingErrorState,
2375 IterativeParsingErrorState,
2376 IterativeParsingMemberValueState,
2377 IterativeParsingMemberValueState,
2378 IterativeParsingMemberValueState,
2379 IterativeParsingMemberValueState,
2380 IterativeParsingMemberValueState
2390 template <
unsigned parseFlags,
typename InputStream,
typename Handler>
2392 InputStream& is, Handler& handler)
2398 case IterativeParsingErrorState:
2401 case IterativeParsingObjectInitialState:
2402 case IterativeParsingArrayInitialState:
2407 if (src == IterativeParsingArrayInitialState || src == IterativeParsingElementDelimiterState)
2408 n = IterativeParsingElementState;
2409 else if (src == IterativeParsingKeyValueDelimiterState)
2410 n = IterativeParsingMemberValueState;
2412 *stack_.template Push<SizeType>(1) = n;
2414 *stack_.template Push<SizeType>(1) = 0;
2416 bool hr = (dst == IterativeParsingObjectInitialState) ? handler.StartObject() : handler.StartArray();
2421 return IterativeParsingErrorState;
2430 case IterativeParsingMemberKeyState:
2431 ParseString<parseFlags>(is, handler,
true);
2432 if (HasParseError())
2433 return IterativeParsingErrorState;
2437 case IterativeParsingKeyValueDelimiterState:
2442 case IterativeParsingMemberValueState:
2444 ParseValue<parseFlags>(is, handler);
2445 if (HasParseError())
2447 return IterativeParsingErrorState;
2451 case IterativeParsingElementState:
2453 ParseValue<parseFlags>(is, handler);
2454 if (HasParseError())
2456 return IterativeParsingErrorState;
2460 case IterativeParsingMemberDelimiterState:
2461 case IterativeParsingElementDelimiterState:
2464 *stack_.template Top<SizeType>() = *stack_.template Top<SizeType>() + 1;
2467 case IterativeParsingObjectFinishState:
2473 return IterativeParsingErrorState;
2476 SizeType c = *stack_.template Pop<SizeType>(1);
2478 if (src == IterativeParsingMemberValueState)
2483 if (n == IterativeParsingStartState)
2484 n = IterativeParsingFinishState;
2486 bool hr = handler.EndObject(c);
2491 return IterativeParsingErrorState;
2500 case IterativeParsingArrayFinishState:
2506 return IterativeParsingErrorState;
2509 SizeType c = *stack_.template Pop<SizeType>(1);
2511 if (src == IterativeParsingElementState)
2516 if (n == IterativeParsingStartState)
2517 n = IterativeParsingFinishState;
2519 bool hr = handler.EndArray(c);
2524 return IterativeParsingErrorState;
2547 ParseValue<parseFlags>(is, handler);
2548 if (HasParseError())
2550 return IterativeParsingErrorState;
2552 return IterativeParsingFinishState;
2556 template <
typename InputStream>
2559 if (HasParseError())
2567 case IterativeParsingStartState:
2570 case IterativeParsingFinishState:
2573 case IterativeParsingObjectInitialState:
2574 case IterativeParsingMemberDelimiterState:
2577 case IterativeParsingMemberKeyState:
2580 case IterativeParsingMemberValueState:
2583 case IterativeParsingKeyValueDelimiterState:
2584 case IterativeParsingArrayInitialState:
2585 case IterativeParsingElementDelimiterState:
2597 return s >= IterativeParsingElementDelimiterState;
2602 return s <= IterativeParsingErrorState;
2605 template <
unsigned parseFlags,
typename InputStream,
typename Handler>
2608 parseResult_.
Clear();
2612 SkipWhitespaceAndComments<parseFlags>(is);
2613 RAPIDJSON_PARSE_ERROR_EARLY_RETURN(parseResult_);
2614 while (is.Peek() !=
'\0')
2616 Token t = Tokenize(is.Peek());
2620 if (d == IterativeParsingErrorState)
2622 HandleError(state, is);
2632 SkipWhitespaceAndComments<parseFlags>(is);
2633 RAPIDJSON_PARSE_ERROR_EARLY_RETURN(parseResult_);
2637 if (state != IterativeParsingFinishState)
2638 HandleError(state, is);
2640 return parseResult_;
2643 static const size_t kDefaultStackCapacity =
2656 #if defined(__clang__) || defined(_MSC_VER) 2664 #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.
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.
Missing a comma or ']' after an array element.
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.
Allow parsing NaN, Inf, Infinity, -Inf and -Infinity as doubles.
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)
SAX-style JSON parser. Use Reader for UTF8 encoding and default allocator.
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)
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
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_
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 &)
RAPIDJSON_FORCEINLINE Token Tokenize(Ch c) const
RAPIDJSON_FORCEINLINE IterativeParsingState Predict(IterativeParsingState state, Token token) const
The document root must not follow by other values.
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.