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(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())) { return value; } \ 62 RAPIDJSON_MULTILINEMACRO_END 64 #define RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID \ 65 RAPIDJSON_PARSE_ERROR_EARLY_RETURN(RAPIDJSON_NOTHING) 98 #ifndef RAPIDJSON_PARSE_ERROR_NORETURN 99 #define RAPIDJSON_PARSE_ERROR_NORETURN(parseErrorCode, offset) \ 100 RAPIDJSON_MULTILINEMACRO_BEGIN \ 101 RAPIDJSON_ASSERT(!HasParseError()); \ 102 SetParseError(parseErrorCode, offset); \ 103 RAPIDJSON_MULTILINEMACRO_END 117 #ifndef RAPIDJSON_PARSE_ERROR 118 #define RAPIDJSON_PARSE_ERROR(parseErrorCode, offset) \ 119 RAPIDJSON_MULTILINEMACRO_BEGIN \ 120 RAPIDJSON_PARSE_ERROR_NORETURN(parseErrorCode, offset); \ 121 RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID; \ 122 RAPIDJSON_MULTILINEMACRO_END 138 #ifndef RAPIDJSON_PARSE_DEFAULT_FLAGS 139 #define RAPIDJSON_PARSE_DEFAULT_FLAGS kParseNoFlags 178 bool RawNumber(const Ch* str, SizeType length, bool copy);
179 bool String(const Ch* str, SizeType length, bool copy);
181 bool Key(const Ch* str, SizeType length, bool copy);
182 bool EndObject(SizeType memberCount);
184 bool EndArray(SizeType elementCount);
195 template<
typename Encoding = UTF8<>,
typename Derived =
void>
197 typedef typename Encoding::Ch
Ch;
202 bool Null() {
return static_cast<Override&
>(*this).Default(); }
203 bool Bool(
bool) {
return static_cast<Override&
>(*this).Default(); }
204 bool Int(
int) {
return static_cast<Override&
>(*this).Default(); }
205 bool Uint(
unsigned) {
return static_cast<Override&
>(*this).Default(); }
206 bool Int64(
int64_t) {
return static_cast<Override&
>(*this).Default(); }
208 bool Double(
double) {
return static_cast<Override&
>(*this).Default(); }
211 bool String(
const Ch*,
SizeType,
bool) {
return static_cast<Override&
>(*this).Default(); }
212 bool StartObject() {
return static_cast<Override&
>(*this).Default(); }
213 bool Key(
const Ch*
str,
SizeType len,
bool copy) {
return static_cast<Override&
>(*this).String(str, len, copy); }
215 bool StartArray() {
return static_cast<Override&
>(*this).Default(); }
224 template<typename Stream, int = StreamTraits<Stream>::copyOptimization>
228 template<
typename Stream>
243 template<
typename Stream>
263 template<
typename InputStream>
266 InputStream&
s(copy.s);
268 typename InputStream::Ch
c;
269 while ((c = s.Peek()) ==
' ' || c ==
'\n' || c ==
'\r' || c ==
'\t')
274 while (p != end && (*p ==
' ' || *p ==
'\n' || *p ==
'\r' || *p ==
'\t'))
279 #ifdef RAPIDJSON_SSE42 281 inline const char *SkipWhitespace_SIMD(
const char*
p) {
283 if (*p ==
' ' || *p ==
'\n' || *p ==
'\r' || *p ==
'\t')
289 const char* nextAligned =
reinterpret_cast<const char*
>((
reinterpret_cast<size_t>(
p) + 15) &
static_cast<size_t>(~15));
290 while (p != nextAligned)
291 if (*p ==
' ' || *p ==
'\n' || *p ==
'\r' || *p ==
'\t')
297 static const char whitespace[16] =
" \n\r\t";
298 const __m128i
w = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&whitespace[0]));
301 const __m128i
s = _mm_load_si128(reinterpret_cast<const __m128i *>(p));
302 const int r = _mm_cmpistri(w, s, _SIDD_UBYTE_OPS | _SIDD_CMP_EQUAL_ANY | _SIDD_LEAST_SIGNIFICANT | _SIDD_NEGATIVE_POLARITY);
308 inline const char *SkipWhitespace_SIMD(
const char* p,
const char*
end) {
310 if (p != end && (*p ==
' ' || *p ==
'\n' || *p ==
'\r' || *p ==
'\t'))
316 static const char whitespace[16] =
" \n\r\t";
317 const __m128i
w = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&whitespace[0]));
319 for (; p <= end - 16; p += 16) {
320 const __m128i
s = _mm_loadu_si128(reinterpret_cast<const __m128i *>(p));
321 const int r = _mm_cmpistri(w, s, _SIDD_UBYTE_OPS | _SIDD_CMP_EQUAL_ANY | _SIDD_LEAST_SIGNIFICANT | _SIDD_NEGATIVE_POLARITY);
329 #elif defined(RAPIDJSON_SSE2) 332 inline const char *SkipWhitespace_SIMD(
const char* p) {
334 if (*p ==
' ' || *p ==
'\n' || *p ==
'\r' || *p ==
'\t')
340 const char* nextAligned =
reinterpret_cast<const char*
>((
reinterpret_cast<size_t>(
p) + 15) &
static_cast<size_t>(~15));
341 while (p != nextAligned)
342 if (*p ==
' ' || *p ==
'\n' || *p ==
'\r' || *p ==
'\t')
348 #define C16(c) { c, c, c, c, c, c, c, c, c, c, c, c, c, c, c, c } 349 static const char whitespaces[4][16] = { C16(
' '), C16(
'\n'), C16(
'\r'), C16(
'\t') };
352 const __m128i w0 = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&whitespaces[0][0]));
353 const __m128i w1 = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&whitespaces[1][0]));
354 const __m128i w2 = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&whitespaces[2][0]));
355 const __m128i w3 = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&whitespaces[3][0]));
358 const __m128i
s = _mm_load_si128(reinterpret_cast<const __m128i *>(p));
359 __m128i
x = _mm_cmpeq_epi8(s, w0);
360 x = _mm_or_si128(x, _mm_cmpeq_epi8(s, w1));
361 x = _mm_or_si128(x, _mm_cmpeq_epi8(s, w2));
362 x = _mm_or_si128(x, _mm_cmpeq_epi8(s, w3));
363 unsigned short r =
static_cast<unsigned short>(~_mm_movemask_epi8(x));
365 #ifdef _MSC_VER // Find the index of first non-whitespace 366 unsigned long offset;
367 _BitScanForward(&offset, r);
370 return p + __builtin_ffs(r) - 1;
376 inline const char *SkipWhitespace_SIMD(
const char* p,
const char* end) {
378 if (p != end && (*p ==
' ' || *p ==
'\n' || *p ==
'\r' || *p ==
'\t'))
384 #define C16(c) { c, c, c, c, c, c, c, c, c, c, c, c, c, c, c, c } 385 static const char whitespaces[4][16] = { C16(
' '), C16(
'\n'), C16(
'\r'), C16(
'\t') };
388 const __m128i w0 = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&whitespaces[0][0]));
389 const __m128i w1 = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&whitespaces[1][0]));
390 const __m128i w2 = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&whitespaces[2][0]));
391 const __m128i w3 = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&whitespaces[3][0]));
393 for (; p <= end - 16; p += 16) {
394 const __m128i
s = _mm_loadu_si128(reinterpret_cast<const __m128i *>(p));
395 __m128i
x = _mm_cmpeq_epi8(s, w0);
396 x = _mm_or_si128(x, _mm_cmpeq_epi8(s, w1));
397 x = _mm_or_si128(x, _mm_cmpeq_epi8(s, w2));
398 x = _mm_or_si128(x, _mm_cmpeq_epi8(s, w3));
399 unsigned short r =
static_cast<unsigned short>(~_mm_movemask_epi8(x));
401 #ifdef _MSC_VER // Find the index of first non-whitespace 402 unsigned long offset;
403 _BitScanForward(&offset, r);
406 return p + __builtin_ffs(r) - 1;
414 #elif defined(RAPIDJSON_NEON) 417 inline const char *SkipWhitespace_SIMD(
const char* p) {
419 if (*p ==
' ' || *p ==
'\n' || *p ==
'\r' || *p ==
'\t')
425 const char* nextAligned =
reinterpret_cast<const char*
>((
reinterpret_cast<size_t>(
p) + 15) &
static_cast<size_t>(~15));
426 while (p != nextAligned)
427 if (*p ==
' ' || *p ==
'\n' || *p ==
'\r' || *p ==
'\t')
432 const uint8x16_t w0 = vmovq_n_u8(
' ');
433 const uint8x16_t w1 = vmovq_n_u8(
'\n');
434 const uint8x16_t w2 = vmovq_n_u8(
'\r');
435 const uint8x16_t w3 = vmovq_n_u8(
'\t');
438 const uint8x16_t
s = vld1q_u8(reinterpret_cast<const uint8_t *>(p));
439 uint8x16_t
x = vceqq_u8(s, w0);
440 x = vorrq_u8(x, vceqq_u8(s, w1));
441 x = vorrq_u8(x, vceqq_u8(s, w2));
442 x = vorrq_u8(x, vceqq_u8(s, w3));
446 uint64_t low = vgetq_lane_u64(reinterpret_cast<uint64x2_t>(x), 0);
447 uint64_t high = vgetq_lane_u64(reinterpret_cast<uint64x2_t>(x), 1);
451 int lz =__builtin_clzll(high);;
452 return p + 8 + (lz >> 3);
455 int lz = __builtin_clzll(low);;
456 return p + (lz >> 3);
461 inline const char *SkipWhitespace_SIMD(
const char* p,
const char* end) {
463 if (p != end && (*p ==
' ' || *p ==
'\n' || *p ==
'\r' || *p ==
'\t'))
468 const uint8x16_t w0 = vmovq_n_u8(
' ');
469 const uint8x16_t w1 = vmovq_n_u8(
'\n');
470 const uint8x16_t w2 = vmovq_n_u8(
'\r');
471 const uint8x16_t w3 = vmovq_n_u8(
'\t');
473 for (; p <= end - 16; p += 16) {
474 const uint8x16_t
s = vld1q_u8(reinterpret_cast<const uint8_t *>(p));
475 uint8x16_t
x = vceqq_u8(s, w0);
476 x = vorrq_u8(x, vceqq_u8(s, w1));
477 x = vorrq_u8(x, vceqq_u8(s, w2));
478 x = vorrq_u8(x, vceqq_u8(s, w3));
482 uint64_t low = vgetq_lane_u64(reinterpret_cast<uint64x2_t>(x), 0);
483 uint64_t high = vgetq_lane_u64(reinterpret_cast<uint64x2_t>(x), 1);
487 int lz = __builtin_clzll(high);
488 return p + 8 + (lz >> 3);
491 int lz = __builtin_clzll(low);
492 return p + (lz >> 3);
499 #endif // RAPIDJSON_NEON 501 #ifdef RAPIDJSON_SIMD 504 is.
src_ =
const_cast<char*
>(SkipWhitespace_SIMD(is.
src_));
509 is.
src_ = SkipWhitespace_SIMD(is.
src_);
513 is.is_.
src_ = SkipWhitespace_SIMD(is.is_.
src_, is.is_.end_);
515 #endif // RAPIDJSON_SIMD 536 template <
typename SourceEncoding,
typename TargetEncoding,
typename StackAllocator = CrtAllocator>
539 typedef typename SourceEncoding::Ch
Ch;
545 GenericReader(StackAllocator* stackAllocator = 0,
size_t stackCapacity = kDefaultStackCapacity) :
546 stack_(stackAllocator, stackCapacity), parseResult_(), state_(IterativeParsingStartState) {}
556 template <
unsigned parseFlags,
typename InputStream,
typename Handler>
559 return IterativeParse<parseFlags>(is,
handler);
561 parseResult_.
Clear();
563 ClearStackOnExit
scope(*
this);
565 SkipWhitespaceAndComments<parseFlags>(is);
566 RAPIDJSON_PARSE_ERROR_EARLY_RETURN(parseResult_);
570 RAPIDJSON_PARSE_ERROR_EARLY_RETURN(parseResult_);
573 ParseValue<parseFlags>(is,
handler);
574 RAPIDJSON_PARSE_ERROR_EARLY_RETURN(parseResult_);
577 SkipWhitespaceAndComments<parseFlags>(is);
578 RAPIDJSON_PARSE_ERROR_EARLY_RETURN(parseResult_);
582 RAPIDJSON_PARSE_ERROR_EARLY_RETURN(parseResult_);
597 template <
typename InputStream,
typename Handler>
599 return Parse<kParseDefaultFlags>(is,
handler);
606 parseResult_.Clear();
607 state_ = IterativeParsingStartState;
617 template <
unsigned parseFlags,
typename InputStream,
typename Handler>
620 SkipWhitespaceAndComments<parseFlags>(is);
622 Token t = Tokenize(is.Peek());
629 if (d == IterativeParsingErrorState) {
630 HandleError(state_, is);
641 SkipWhitespaceAndComments<parseFlags>(is);
642 if (is.Peek() !=
'\0') {
644 HandleError(state_, is);
657 if (!IsIterativeParsingDelimiterState(n))
664 if (state_ != IterativeParsingFinishState) {
665 HandleError(state_, is);
676 return IsIterativeParsingCompleteState(state_);
708 template<
unsigned parseFlags,
typename InputStream>
714 if (Consume(is,
'*')) {
718 else if (Consume(is,
'*')) {
719 if (Consume(is,
'/'))
727 while (is.Peek() !=
'\0' && is.Take() !=
'\n') {}
737 template<
unsigned parseFlags,
typename InputStream,
typename Handler>
745 SkipWhitespaceAndComments<parseFlags>(is);
746 RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
748 if (Consume(is,
'}')) {
758 ParseString<parseFlags>(is,
handler,
true);
759 RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
761 SkipWhitespaceAndComments<parseFlags>(is);
762 RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
767 SkipWhitespaceAndComments<parseFlags>(is);
768 RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
770 ParseValue<parseFlags>(is,
handler);
771 RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
773 SkipWhitespaceAndComments<parseFlags>(is);
774 RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
781 SkipWhitespaceAndComments<parseFlags>(is);
782 RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
794 if (is.Peek() ==
'}') {
805 template<
unsigned parseFlags,
typename InputStream,
typename Handler>
813 SkipWhitespaceAndComments<parseFlags>(is);
814 RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
816 if (Consume(is,
']')) {
823 ParseValue<parseFlags>(is,
handler);
824 RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
827 SkipWhitespaceAndComments<parseFlags>(is);
828 RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
830 if (Consume(is,
',')) {
831 SkipWhitespaceAndComments<parseFlags>(is);
832 RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
834 else if (Consume(is,
']')) {
843 if (is.Peek() ==
']') {
853 template<
unsigned parseFlags,
typename InputStream,
typename Handler>
858 if (
RAPIDJSON_LIKELY(Consume(is,
'u') && Consume(is,
'l') && Consume(is,
'l'))) {
866 template<
unsigned parseFlags,
typename InputStream,
typename Handler>
871 if (
RAPIDJSON_LIKELY(Consume(is,
'r') && Consume(is,
'u') && Consume(is,
'e'))) {
879 template<
unsigned parseFlags,
typename InputStream,
typename Handler>
884 if (
RAPIDJSON_LIKELY(Consume(is,
'a') && Consume(is,
'l') && Consume(is,
's') && Consume(is,
'e'))) {
892 template<
typename InputStream>
893 RAPIDJSON_FORCEINLINE
static bool Consume(InputStream& is,
typename InputStream::Ch expect) {
903 template<
typename InputStream>
904 unsigned ParseHex4(InputStream& is,
size_t escapeOffset) {
905 unsigned codepoint = 0;
906 for (
int i = 0; i < 4; i++) {
909 codepoint +=
static_cast<unsigned>(
c);
910 if (c >=
'0' && c <=
'9')
912 else if (c >=
'A' && c <=
'F')
913 codepoint -=
'A' - 10;
914 else if (c >=
'a' && c <=
'f')
915 codepoint -=
'a' - 10;
918 RAPIDJSON_PARSE_ERROR_EARLY_RETURN(0);
925 template <
typename CharType>
931 RAPIDJSON_FORCEINLINE
void Put(Ch
c) {
932 *stack_.template Push<Ch>() = c;
938 return stack_.template Push<Ch>(count);
941 size_t Length()
const {
return length_; }
944 return stack_.template Pop<Ch>(length_);
956 template<
unsigned parseFlags,
typename InputStream,
typename Handler>
959 InputStream&
s(copy.s);
964 bool success =
false;
966 typename InputStream::Ch *head = s.PutBegin();
967 ParseStringToStream<parseFlags, SourceEncoding, SourceEncoding>(
s,
s);
968 RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
969 size_t length = s.PutEnd(head) - 1;
971 const typename TargetEncoding::Ch*
const str =
reinterpret_cast<typename TargetEncoding::Ch*
>(head);
972 success = (isKey ? handler.Key(str,
SizeType(length),
false) : handler.String(str,
SizeType(length),
false));
975 StackStream<typename TargetEncoding::Ch> stackStream(stack_);
976 ParseStringToStream<parseFlags, SourceEncoding, TargetEncoding>(
s, stackStream);
977 RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
979 const typename TargetEncoding::Ch*
const str = stackStream.Pop();
980 success = (isKey ? handler.Key(str, length,
true) : handler.String(str, length,
true));
988 template<
unsigned parseFlags,
typename SEncoding,
typename TEncoding,
typename InputStream,
typename OutputStream>
991 #define Z16 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 992 static const char escape[256] = {
993 Z16,
Z16, 0, 0,
'\"', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
'/',
994 Z16,
Z16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
'\\', 0, 0, 0,
995 0, 0,
'\b', 0, 0, 0,
'\f', 0, 0, 0, 0, 0, 0, 0,
'\n', 0,
996 0, 0,
'\r', 0,
'\t', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1005 ScanCopyUnescapedString(is, os);
1009 size_t escapeOffset = is.Tell();
1012 if ((
sizeof(Ch) == 1 ||
unsigned(e) < 256) &&
RAPIDJSON_LIKELY(escape[static_cast<unsigned char>(e)])) {
1014 os.Put(static_cast<typename TEncoding::Ch>(escape[static_cast<unsigned char>(e)]));
1018 unsigned codepoint = ParseHex4(is, escapeOffset);
1019 RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
1024 unsigned codepoint2 = ParseHex4(is, escapeOffset);
1025 RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
1028 codepoint = (((codepoint - 0xD800) << 10) | (codepoint2 - 0xDC00)) + 0x10000;
1030 TEncoding::Encode(os, codepoint);
1047 size_t offset = is.Tell();
1056 template<
typename InputStream,
typename OutputStream>
1061 #if defined(RAPIDJSON_SSE2) || defined(RAPIDJSON_SSE42) 1063 static RAPIDJSON_FORCEINLINE
void ScanCopyUnescapedString(
StringStream& is, StackStream<char>& os) {
1064 const char* p = is.
src_;
1067 const char* nextAligned =
reinterpret_cast<const char*
>((
reinterpret_cast<size_t>(
p) + 15) &
static_cast<size_t>(~15));
1068 while (p != nextAligned)
1077 static const char dquote[16] = {
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"' };
1078 static const char bslash[16] = {
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\' };
1079 static const char space[16] = { 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F };
1080 const __m128i dq = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&dquote[0]));
1081 const __m128i bs = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&bslash[0]));
1082 const __m128i sp = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&space[0]));
1085 const __m128i
s = _mm_load_si128(reinterpret_cast<const __m128i *>(p));
1086 const __m128i
t1 = _mm_cmpeq_epi8(s, dq);
1087 const __m128i t2 = _mm_cmpeq_epi8(s, bs);
1088 const __m128i t3 = _mm_cmpeq_epi8(_mm_max_epu8(s, sp), sp);
1089 const __m128i
x = _mm_or_si128(_mm_or_si128(t1, t2), t3);
1090 unsigned short r =
static_cast<unsigned short>(_mm_movemask_epi8(x));
1093 #ifdef _MSC_VER // Find the index of first escaped 1094 unsigned long offset;
1095 _BitScanForward(&offset, r);
1098 length =
static_cast<SizeType>(__builtin_ffs(r) - 1);
1101 char* q =
reinterpret_cast<char*
>(os.Push(length));
1102 for (
size_t i = 0; i < length; i++)
1109 _mm_storeu_si128(reinterpret_cast<__m128i *>(os.Push(16)), s);
1121 SkipUnescapedString(is);
1129 const char* nextAligned =
reinterpret_cast<const char*
>((
reinterpret_cast<size_t>(
p) + 15) &
static_cast<size_t>(~15));
1130 while (p != nextAligned)
1140 static const char dquote[16] = {
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"' };
1141 static const char bslash[16] = {
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\' };
1142 static const char space[16] = { 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F };
1143 const __m128i dq = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&dquote[0]));
1144 const __m128i bs = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&bslash[0]));
1145 const __m128i sp = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&space[0]));
1147 for (;; p += 16, q += 16) {
1148 const __m128i
s = _mm_load_si128(reinterpret_cast<const __m128i *>(p));
1149 const __m128i
t1 = _mm_cmpeq_epi8(s, dq);
1150 const __m128i t2 = _mm_cmpeq_epi8(s, bs);
1151 const __m128i t3 = _mm_cmpeq_epi8(_mm_max_epu8(s, sp), sp);
1152 const __m128i
x = _mm_or_si128(_mm_or_si128(t1, t2), t3);
1153 unsigned short r =
static_cast<unsigned short>(_mm_movemask_epi8(x));
1156 #ifdef _MSC_VER // Find the index of first escaped 1157 unsigned long offset;
1158 _BitScanForward(&offset, r);
1161 length =
static_cast<size_t>(__builtin_ffs(r) - 1);
1163 for (
const char* pend = p + length; p != pend; )
1167 _mm_storeu_si128(reinterpret_cast<__m128i *>(q), s);
1180 const char* nextAligned =
reinterpret_cast<const char*
>((
reinterpret_cast<size_t>(
p) + 15) &
static_cast<size_t>(~15));
1181 for (; p != nextAligned; p++)
1188 static const char dquote[16] = {
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"' };
1189 static const char bslash[16] = {
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\' };
1190 static const char space[16] = { 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F };
1191 const __m128i dq = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&dquote[0]));
1192 const __m128i bs = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&bslash[0]));
1193 const __m128i sp = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&space[0]));
1196 const __m128i
s = _mm_load_si128(reinterpret_cast<const __m128i *>(p));
1197 const __m128i
t1 = _mm_cmpeq_epi8(s, dq);
1198 const __m128i t2 = _mm_cmpeq_epi8(s, bs);
1199 const __m128i t3 = _mm_cmpeq_epi8(_mm_max_epu8(s, sp), sp);
1200 const __m128i
x = _mm_or_si128(_mm_or_si128(t1, t2), t3);
1201 unsigned short r =
static_cast<unsigned short>(_mm_movemask_epi8(x));
1204 #ifdef _MSC_VER // Find the index of first escaped 1205 unsigned long offset;
1206 _BitScanForward(&offset, r);
1209 length =
static_cast<size_t>(__builtin_ffs(r) - 1);
1218 #elif defined(RAPIDJSON_NEON) 1220 static RAPIDJSON_FORCEINLINE
void ScanCopyUnescapedString(
StringStream& is, StackStream<char>& os) {
1221 const char* p = is.
src_;
1224 const char* nextAligned =
reinterpret_cast<const char*
>((
reinterpret_cast<size_t>(
p) + 15) &
static_cast<size_t>(~15));
1225 while (p != nextAligned)
1234 const uint8x16_t s0 = vmovq_n_u8(
'"');
1235 const uint8x16_t s1 = vmovq_n_u8(
'\\');
1236 const uint8x16_t s2 = vmovq_n_u8(
'\b');
1237 const uint8x16_t s3 = vmovq_n_u8(32);
1240 const uint8x16_t
s = vld1q_u8(reinterpret_cast<const uint8_t *>(p));
1241 uint8x16_t
x = vceqq_u8(s, s0);
1242 x = vorrq_u8(x, vceqq_u8(s, s1));
1243 x = vorrq_u8(x, vceqq_u8(s, s2));
1244 x = vorrq_u8(x, vcltq_u8(s, s3));
1247 uint64_t low = vgetq_lane_u64(reinterpret_cast<uint64x2_t>(x), 0);
1248 uint64_t high = vgetq_lane_u64(reinterpret_cast<uint64x2_t>(x), 1);
1251 bool escaped =
false;
1254 unsigned lz = (unsigned)__builtin_clzll(high);;
1255 length = 8 + (lz >> 3);
1259 unsigned lz = (unsigned)__builtin_clzll(low);;
1265 char* q =
reinterpret_cast<char*
>(os.Push(length));
1266 for (
size_t i = 0; i < length; i++)
1273 vst1q_u8(reinterpret_cast<uint8_t *>(os.Push(16)), s);
1285 SkipUnescapedString(is);
1293 const char* nextAligned =
reinterpret_cast<const char*
>((
reinterpret_cast<size_t>(
p) + 15) &
static_cast<size_t>(~15));
1294 while (p != nextAligned)
1304 const uint8x16_t s0 = vmovq_n_u8(
'"');
1305 const uint8x16_t s1 = vmovq_n_u8(
'\\');
1306 const uint8x16_t s2 = vmovq_n_u8(
'\b');
1307 const uint8x16_t s3 = vmovq_n_u8(32);
1309 for (;; p += 16, q += 16) {
1310 const uint8x16_t
s = vld1q_u8(reinterpret_cast<uint8_t *>(p));
1311 uint8x16_t
x = vceqq_u8(s, s0);
1312 x = vorrq_u8(x, vceqq_u8(s, s1));
1313 x = vorrq_u8(x, vceqq_u8(s, s2));
1314 x = vorrq_u8(x, vcltq_u8(s, s3));
1317 uint64_t low = vgetq_lane_u64(reinterpret_cast<uint64x2_t>(x), 0);
1318 uint64_t high = vgetq_lane_u64(reinterpret_cast<uint64x2_t>(x), 1);
1321 bool escaped =
false;
1324 unsigned lz = (unsigned)__builtin_clzll(high);
1325 length = 8 + (lz >> 3);
1329 unsigned lz = (unsigned)__builtin_clzll(low);
1334 for (
const char* pend = p + length; p != pend; ) {
1339 vst1q_u8(reinterpret_cast<uint8_t *>(q), s);
1352 const char* nextAligned =
reinterpret_cast<const char*
>((
reinterpret_cast<size_t>(
p) + 15) &
static_cast<size_t>(~15));
1353 for (; p != nextAligned; p++)
1360 const uint8x16_t s0 = vmovq_n_u8(
'"');
1361 const uint8x16_t s1 = vmovq_n_u8(
'\\');
1362 const uint8x16_t s2 = vmovq_n_u8(
'\b');
1363 const uint8x16_t s3 = vmovq_n_u8(32);
1366 const uint8x16_t
s = vld1q_u8(reinterpret_cast<uint8_t *>(p));
1367 uint8x16_t
x = vceqq_u8(s, s0);
1368 x = vorrq_u8(x, vceqq_u8(s, s1));
1369 x = vorrq_u8(x, vceqq_u8(s, s2));
1370 x = vorrq_u8(x, vcltq_u8(s, s3));
1373 uint64_t low = vgetq_lane_u64(reinterpret_cast<uint64x2_t>(x), 0);
1374 uint64_t high = vgetq_lane_u64(reinterpret_cast<uint64x2_t>(x), 1);
1378 int lz = __builtin_clzll(high);
1383 int lz = __builtin_clzll(low);
1391 #endif // RAPIDJSON_NEON 1393 template<
typename InputStream,
bool backup,
bool pushOnTake>
1396 template<
typename InputStream>
1399 typedef typename InputStream::Ch
Ch;
1403 RAPIDJSON_FORCEINLINE Ch
Peek()
const {
return is.
Peek(); }
1406 RAPIDJSON_FORCEINLINE
void Push(
char) {}
1410 const char*
Pop() {
return 0; }
1418 template<
typename InputStream>
1425 stackStream.Put(static_cast<char>(Base::is.Peek()));
1426 return Base::is.Take();
1429 RAPIDJSON_FORCEINLINE
void Push(
char c) {
1433 size_t Length() {
return stackStream.Length(); }
1436 stackStream.Put(
'\0');
1437 return stackStream.Pop();
1444 template<
typename InputStream>
1450 RAPIDJSON_FORCEINLINE Ch
Take() {
return Base::TakePush(); }
1453 template<
unsigned parseFlags,
typename InputStream,
typename Handler>
1456 NumberStream<InputStream,
1463 size_t startOffset =
s.Tell();
1465 bool useNanOrInf =
false;
1468 bool minus = Consume(
s,
'-');
1473 bool use64bit =
false;
1474 int significandDigit = 0;
1480 i =
static_cast<unsigned>(
s.TakePush() -
'0');
1491 i = i * 10 +
static_cast<unsigned>(
s.TakePush() -
'0');
1503 i = i * 10 +
static_cast<unsigned>(
s.TakePush() -
'0');
1509 if (Consume(
s,
'N')) {
1510 if (Consume(
s,
'a') && Consume(
s,
'N')) {
1511 d = std::numeric_limits<double>::quiet_NaN();
1516 if (Consume(
s,
'n') && Consume(
s,
'f')) {
1517 d = (minus ? -std::numeric_limits<double>::infinity() : std::numeric_limits<double>::infinity());
1521 && Consume(
s,
'i') && Consume(
s,
't') && Consume(
s,
'y')))) {
1535 bool useDouble =
false;
1541 d =
static_cast<double>(i64);
1545 i64 = i64 * 10 +
static_cast<unsigned>(
s.TakePush() -
'0');
1552 d =
static_cast<double>(i64);
1556 i64 = i64 * 10 +
static_cast<unsigned>(
s.TakePush() -
'0');
1564 d = d * 10 + (
s.TakePush() -
'0');
1570 size_t decimalPosition;
1571 if (Consume(
s,
'.')) {
1572 decimalPosition =
s.Length();
1587 i64 = i64 * 10 +
static_cast<unsigned>(
s.TakePush() -
'0');
1594 d =
static_cast<double>(i64);
1597 d =
static_cast<double>(use64bit ? i64 : i);
1603 if (significandDigit < 17) {
1604 d = d * 10.0 + (
s.TakePush() -
'0');
1614 decimalPosition =
s.Length();
1618 if (Consume(
s,
'e') || Consume(
s,
'E')) {
1620 d =
static_cast<double>(use64bit ? i64 : i);
1624 bool expMinus =
false;
1625 if (Consume(
s,
'+'))
1627 else if (Consume(
s,
'-'))
1631 exp =
static_cast<int>(
s.Take() -
'0');
1640 int maxExp = (expFrac + 2147483639) / 10;
1643 exp = exp * 10 +
static_cast<int>(
s.Take() -
'0');
1651 int maxExp = 308 - expFrac;
1653 exp = exp * 10 +
static_cast<int>(
s.Take() -
'0');
1670 if (parseFlags & kParseInsituFlag) {
1672 typename InputStream::Ch* head = is.PutBegin();
1673 const size_t length =
s.Tell() - startOffset;
1676 const typename TargetEncoding::Ch*
const str =
reinterpret_cast<typename TargetEncoding::Ch*
>(head);
1677 cont = handler.RawNumber(str,
SizeType(length),
false);
1682 StackStream<typename TargetEncoding::Ch> dstStream(stack_);
1683 while (numCharsToCopy--) {
1686 dstStream.Put(
'\0');
1687 const typename TargetEncoding::Ch*
str = dstStream.Pop();
1689 cont = handler.RawNumber(str,
SizeType(length),
true);
1693 size_t length =
s.Length();
1694 const char* decimal =
s.Pop();
1697 int p = exp + expFrac;
1710 cont = handler.Double(minus ? -d : d);
1712 else if (useNanOrInf) {
1713 cont = handler.Double(d);
1718 cont = handler.Int64(static_cast<int64_t>(~i64 + 1));
1720 cont = handler.Uint64(i64);
1724 cont = handler.Int(static_cast<int32_t>(~i + 1));
1726 cont = handler.Uint(i);
1735 template<
unsigned parseFlags,
typename InputStream,
typename Handler>
1737 switch (is.Peek()) {
1738 case 'n': ParseNull <parseFlags>(is,
handler);
break;
1739 case 't': ParseTrue <parseFlags>(is,
handler);
break;
1740 case 'f': ParseFalse <parseFlags>(is,
handler);
break;
1741 case '"': ParseString<parseFlags>(is,
handler);
break;
1742 case '{': ParseObject<parseFlags>(is,
handler);
break;
1743 case '[': ParseArray <parseFlags>(is,
handler);
break;
1745 ParseNumber<parseFlags>(is,
handler);
1755 IterativeParsingFinishState = 0,
1778 cIterativeParsingStateCount
1783 LeftBracketToken = 0,
1804 #define N NumberToken 1805 #define N16 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N 1807 static const unsigned char tokenMap[256] = {
1810 N,
N, StringToken,
N,
N,
N,
N,
N,
N,
N,
N,
N, CommaToken,
N,
N,
N,
1811 N,
N,
N,
N,
N,
N,
N,
N,
N,
N, ColonToken,
N,
N,
N,
N,
N,
1813 N,
N,
N,
N,
N,
N,
N,
N,
N,
N,
N, LeftBracketToken,
N, RightBracketToken,
N,
N,
1814 N,
N,
N,
N,
N,
N, FalseToken,
N,
N,
N,
N,
N,
N,
N, NullToken,
N,
1815 N,
N,
N,
N, TrueToken,
N,
N,
N,
N,
N,
N, LeftCurlyBracketToken,
N, RightCurlyBracketToken,
N,
N,
1816 N16, N16, N16, N16, N16, N16, N16, N16
1822 if (
sizeof(Ch) == 1 || static_cast<unsigned>(c) < 256)
1823 return static_cast<Token>(tokenMap[
static_cast<unsigned char>(
c)]);
1830 static const char G[cIterativeParsingStateCount][kTokenCount] = {
1833 IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState,
1834 IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState,
1835 IterativeParsingErrorState
1839 IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState,
1840 IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState,
1841 IterativeParsingErrorState
1845 IterativeParsingArrayInitialState,
1846 IterativeParsingErrorState,
1847 IterativeParsingObjectInitialState,
1848 IterativeParsingErrorState,
1849 IterativeParsingErrorState,
1850 IterativeParsingErrorState,
1851 IterativeParsingValueState,
1852 IterativeParsingValueState,
1853 IterativeParsingValueState,
1854 IterativeParsingValueState,
1855 IterativeParsingValueState
1859 IterativeParsingErrorState,
1860 IterativeParsingErrorState,
1861 IterativeParsingErrorState,
1862 IterativeParsingObjectFinishState,
1863 IterativeParsingErrorState,
1864 IterativeParsingErrorState,
1865 IterativeParsingMemberKeyState,
1866 IterativeParsingErrorState,
1867 IterativeParsingErrorState,
1868 IterativeParsingErrorState,
1869 IterativeParsingErrorState
1873 IterativeParsingErrorState,
1874 IterativeParsingErrorState,
1875 IterativeParsingErrorState,
1876 IterativeParsingErrorState,
1877 IterativeParsingErrorState,
1878 IterativeParsingKeyValueDelimiterState,
1879 IterativeParsingErrorState,
1880 IterativeParsingErrorState,
1881 IterativeParsingErrorState,
1882 IterativeParsingErrorState,
1883 IterativeParsingErrorState
1887 IterativeParsingErrorState,
1888 IterativeParsingErrorState,
1889 IterativeParsingErrorState,
1890 IterativeParsingObjectFinishState,
1891 IterativeParsingMemberDelimiterState,
1892 IterativeParsingErrorState,
1893 IterativeParsingErrorState,
1894 IterativeParsingErrorState,
1895 IterativeParsingErrorState,
1896 IterativeParsingErrorState,
1897 IterativeParsingErrorState
1901 IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState,
1902 IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState,
1903 IterativeParsingErrorState
1907 IterativeParsingArrayInitialState,
1908 IterativeParsingArrayFinishState,
1909 IterativeParsingObjectInitialState,
1910 IterativeParsingErrorState,
1911 IterativeParsingErrorState,
1912 IterativeParsingErrorState,
1913 IterativeParsingElementState,
1914 IterativeParsingElementState,
1915 IterativeParsingElementState,
1916 IterativeParsingElementState,
1917 IterativeParsingElementState
1921 IterativeParsingErrorState,
1922 IterativeParsingArrayFinishState,
1923 IterativeParsingErrorState,
1924 IterativeParsingErrorState,
1925 IterativeParsingElementDelimiterState,
1926 IterativeParsingErrorState,
1927 IterativeParsingErrorState,
1928 IterativeParsingErrorState,
1929 IterativeParsingErrorState,
1930 IterativeParsingErrorState,
1931 IterativeParsingErrorState
1935 IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState,
1936 IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState,
1937 IterativeParsingErrorState
1941 IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState,
1942 IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState,
1943 IterativeParsingErrorState
1947 IterativeParsingArrayInitialState,
1948 IterativeParsingArrayFinishState,
1949 IterativeParsingObjectInitialState,
1950 IterativeParsingErrorState,
1951 IterativeParsingErrorState,
1952 IterativeParsingErrorState,
1953 IterativeParsingElementState,
1954 IterativeParsingElementState,
1955 IterativeParsingElementState,
1956 IterativeParsingElementState,
1957 IterativeParsingElementState
1961 IterativeParsingErrorState,
1962 IterativeParsingErrorState,
1963 IterativeParsingErrorState,
1964 IterativeParsingObjectFinishState,
1965 IterativeParsingErrorState,
1966 IterativeParsingErrorState,
1967 IterativeParsingMemberKeyState,
1968 IterativeParsingErrorState,
1969 IterativeParsingErrorState,
1970 IterativeParsingErrorState,
1971 IterativeParsingErrorState
1975 IterativeParsingArrayInitialState,
1976 IterativeParsingErrorState,
1977 IterativeParsingObjectInitialState,
1978 IterativeParsingErrorState,
1979 IterativeParsingErrorState,
1980 IterativeParsingErrorState,
1981 IterativeParsingMemberValueState,
1982 IterativeParsingMemberValueState,
1983 IterativeParsingMemberValueState,
1984 IterativeParsingMemberValueState,
1985 IterativeParsingMemberValueState
1994 template <
unsigned parseFlags,
typename InputStream,
typename Handler>
1999 case IterativeParsingErrorState:
2002 case IterativeParsingObjectInitialState:
2003 case IterativeParsingArrayInitialState:
2008 if (src == IterativeParsingArrayInitialState || src == IterativeParsingElementDelimiterState)
2009 n = IterativeParsingElementState;
2010 else if (src == IterativeParsingKeyValueDelimiterState)
2011 n = IterativeParsingMemberValueState;
2013 *stack_.template Push<SizeType>(1) = n;
2015 *stack_.template Push<SizeType>(1) = 0;
2017 bool hr = (dst == IterativeParsingObjectInitialState) ? handler.StartObject() : handler.StartArray();
2021 return IterativeParsingErrorState;
2029 case IterativeParsingMemberKeyState:
2030 ParseString<parseFlags>(is,
handler,
true);
2031 if (HasParseError())
2032 return IterativeParsingErrorState;
2036 case IterativeParsingKeyValueDelimiterState:
2041 case IterativeParsingMemberValueState:
2043 ParseValue<parseFlags>(is,
handler);
2044 if (HasParseError()) {
2045 return IterativeParsingErrorState;
2049 case IterativeParsingElementState:
2051 ParseValue<parseFlags>(is,
handler);
2052 if (HasParseError()) {
2053 return IterativeParsingErrorState;
2057 case IterativeParsingMemberDelimiterState:
2058 case IterativeParsingElementDelimiterState:
2061 *stack_.template Top<SizeType>() = *stack_.template Top<SizeType>() + 1;
2064 case IterativeParsingObjectFinishState:
2069 return IterativeParsingErrorState;
2072 SizeType c = *stack_.template Pop<SizeType>(1);
2074 if (src == IterativeParsingMemberValueState)
2079 if (n == IterativeParsingStartState)
2080 n = IterativeParsingFinishState;
2082 bool hr = handler.EndObject(c);
2086 return IterativeParsingErrorState;
2094 case IterativeParsingArrayFinishState:
2099 return IterativeParsingErrorState;
2102 SizeType c = *stack_.template Pop<SizeType>(1);
2104 if (src == IterativeParsingElementState)
2109 if (n == IterativeParsingStartState)
2110 n = IterativeParsingFinishState;
2112 bool hr = handler.EndArray(c);
2116 return IterativeParsingErrorState;
2138 ParseValue<parseFlags>(is,
handler);
2139 if (HasParseError()) {
2140 return IterativeParsingErrorState;
2142 return IterativeParsingFinishState;
2146 template <
typename InputStream>
2148 if (HasParseError()) {
2156 case IterativeParsingObjectInitialState:
2160 case IterativeParsingKeyValueDelimiterState:
2161 case IterativeParsingArrayInitialState:
2168 return s >= IterativeParsingElementDelimiterState;
2172 return s <= IterativeParsingErrorState;
2175 template <
unsigned parseFlags,
typename InputStream,
typename Handler>
2177 parseResult_.
Clear();
2178 ClearStackOnExit
scope(*
this);
2181 SkipWhitespaceAndComments<parseFlags>(is);
2182 RAPIDJSON_PARSE_ERROR_EARLY_RETURN(parseResult_);
2183 while (is.Peek() !=
'\0') {
2184 Token t = Tokenize(is.Peek());
2188 if (d == IterativeParsingErrorState) {
2189 HandleError(state, is);
2199 SkipWhitespaceAndComments<parseFlags>(is);
2200 RAPIDJSON_PARSE_ERROR_EARLY_RETURN(parseResult_);
2204 if (state != IterativeParsingFinishState)
2205 HandleError(state, is);
2207 return parseResult_;
2210 static const size_t kDefaultStackCapacity = 256;
2221 #if defined(__clang__) || defined(_MSC_VER) 2230 #endif // RAPIDJSON_READER_H_
bool RawNumber(const Ch *str, SizeType len, bool copy)
enabled via kParseNumbersAsStringsFlag, string is not null-terminated (use length) ...
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
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.
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 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.
CodeOutputInterface * code
void ParseFalse(InputStream &is, Handler &handler)
Invalid escape character in string.
static int max(int a, int b)
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_
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)
static msg_handler handler
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.
std::string escape(std::string const &str)
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.