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> 40 RAPIDJSON_DIAG_OFF(4127)
41 RAPIDJSON_DIAG_OFF(4702)
46 RAPIDJSON_DIAG_OFF(old-style-
cast)
47 RAPIDJSON_DIAG_OFF(padded)
48 RAPIDJSON_DIAG_OFF(
switch-
enum)
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 195 template<
typename Encoding = UTF8<>,
typename Derived =
void>
197 typedef typename Encoding::Ch
Ch;
205 bool Uint(
unsigned) {
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 280 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_cvtsi128_si32(_mm_cmpistrm(
w,
s, _SIDD_UBYTE_OPS | _SIDD_CMP_EQUAL_ANY | _SIDD_BIT_MASK | _SIDD_NEGATIVE_POLARITY));
304 #ifdef _MSC_VER // Find the index of first non-whitespace 309 return p + __builtin_ffs(
r) - 1;
315 inline const char *SkipWhitespace_SIMD(
const char*
p,
const char*
end) {
317 if (
p !=
end && (*
p ==
' ' || *
p ==
'\n' || *
p ==
'\r' || *
p ==
'\t'))
323 static const char whitespace[16] =
" \n\r\t";
324 const __m128i
w = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&whitespace[0]));
326 for (;
p <=
end - 16;
p += 16) {
327 const __m128i
s = _mm_loadu_si128(reinterpret_cast<const __m128i *>(
p));
328 const int r = _mm_cvtsi128_si32(_mm_cmpistrm(
w,
s, _SIDD_UBYTE_OPS | _SIDD_CMP_EQUAL_ANY | _SIDD_BIT_MASK | _SIDD_NEGATIVE_POLARITY));
330 #ifdef _MSC_VER // Find the index of first non-whitespace 335 return p + __builtin_ffs(
r) - 1;
343 #elif defined(RAPIDJSON_SSE2) 346 inline const char *SkipWhitespace_SIMD(
const char*
p) {
348 if (*
p ==
' ' || *
p ==
'\n' || *
p ==
'\r' || *
p ==
'\t')
354 const char* nextAligned =
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 #define C16(c) { c, c, c, c, c, c, c, c, c, c, c, c, c, c, c, c } 363 static const char whitespaces[4][16] = { C16(
' '), C16(
'\n'), C16(
'\r'), C16(
'\t') };
366 const __m128i w0 = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&whitespaces[0][0]));
367 const __m128i
w1 = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&whitespaces[1][0]));
368 const __m128i
w2 = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&whitespaces[2][0]));
369 const __m128i w3 = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&whitespaces[3][0]));
372 const __m128i
s = _mm_load_si128(reinterpret_cast<const __m128i *>(
p));
373 __m128i
x = _mm_cmpeq_epi8(
s, w0);
374 x = _mm_or_si128(
x, _mm_cmpeq_epi8(
s,
w1));
375 x = _mm_or_si128(
x, _mm_cmpeq_epi8(
s,
w2));
376 x = _mm_or_si128(
x, _mm_cmpeq_epi8(
s, w3));
377 unsigned short r =
static_cast<unsigned short>(~_mm_movemask_epi8(
x));
379 #ifdef _MSC_VER // Find the index of first non-whitespace 384 return p + __builtin_ffs(
r) - 1;
390 inline const char *SkipWhitespace_SIMD(
const char*
p,
const char*
end) {
392 if (
p !=
end && (*
p ==
' ' || *
p ==
'\n' || *
p ==
'\r' || *
p ==
'\t'))
398 #define C16(c) { c, c, c, c, c, c, c, c, c, c, c, c, c, c, c, c } 399 static const char whitespaces[4][16] = { C16(
' '), C16(
'\n'), C16(
'\r'), C16(
'\t') };
402 const __m128i w0 = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&whitespaces[0][0]));
403 const __m128i
w1 = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&whitespaces[1][0]));
404 const __m128i
w2 = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&whitespaces[2][0]));
405 const __m128i w3 = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&whitespaces[3][0]));
407 for (;
p <=
end - 16;
p += 16) {
408 const __m128i
s = _mm_loadu_si128(reinterpret_cast<const __m128i *>(
p));
409 __m128i
x = _mm_cmpeq_epi8(
s, w0);
410 x = _mm_or_si128(
x, _mm_cmpeq_epi8(
s,
w1));
411 x = _mm_or_si128(
x, _mm_cmpeq_epi8(
s,
w2));
412 x = _mm_or_si128(
x, _mm_cmpeq_epi8(
s, w3));
413 unsigned short r =
static_cast<unsigned short>(~_mm_movemask_epi8(
x));
415 #ifdef _MSC_VER // Find the index of first non-whitespace 420 return p + __builtin_ffs(
r) - 1;
428 #endif // RAPIDJSON_SSE2 430 #ifdef RAPIDJSON_SIMD 433 is.
src_ =
const_cast<char*
>(SkipWhitespace_SIMD(is.
src_));
438 is.
src_ = SkipWhitespace_SIMD(is.
src_);
442 is.is_.src_ = SkipWhitespace_SIMD(is.is_.src_, is.is_.end_);
444 #endif // RAPIDJSON_SIMD 465 template <
typename SourceEncoding,
typename TargetEncoding,
typename StackAllocator = CrtAllocator>
468 typedef typename SourceEncoding::Ch
Ch;
484 template <
unsigned parseFlags,
typename InputStream,
typename Handler>
487 return IterativeParse<parseFlags>(is,
handler);
493 SkipWhitespaceAndComments<parseFlags>(is);
501 ParseValue<parseFlags>(is,
handler);
505 SkipWhitespaceAndComments<parseFlags>(is);
525 template <
typename InputStream,
typename Handler>
527 return Parse<kParseDefaultFlags>(is,
handler);
559 template<
unsigned parseFlags,
typename InputStream>
578 while (is.Peek() !=
'\0' && is.Take() !=
'\n');
588 template<
unsigned parseFlags,
typename InputStream,
typename Handler>
596 SkipWhitespaceAndComments<parseFlags>(is);
597 RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
609 ParseString<parseFlags>(is,
handler,
true);
610 RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
612 SkipWhitespaceAndComments<parseFlags>(is);
613 RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
618 SkipWhitespaceAndComments<parseFlags>(is);
619 RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
621 ParseValue<parseFlags>(is,
handler);
622 RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
624 SkipWhitespaceAndComments<parseFlags>(is);
625 RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
632 SkipWhitespaceAndComments<parseFlags>(is);
633 RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
645 if (is.Peek() ==
'}') {
656 template<
unsigned parseFlags,
typename InputStream,
typename Handler>
664 SkipWhitespaceAndComments<parseFlags>(is);
665 RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
674 ParseValue<parseFlags>(is,
handler);
675 RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
678 SkipWhitespaceAndComments<parseFlags>(is);
679 RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
682 SkipWhitespaceAndComments<parseFlags>(is);
683 RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
694 if (is.Peek() ==
']') {
704 template<
unsigned parseFlags,
typename InputStream,
typename Handler>
717 template<
unsigned parseFlags,
typename InputStream,
typename Handler>
730 template<
unsigned parseFlags,
typename InputStream,
typename Handler>
743 template<
typename InputStream>
744 RAPIDJSON_FORCEINLINE
static bool Consume(InputStream& is,
typename InputStream::Ch expect) {
754 template<
typename InputStream>
755 unsigned ParseHex4(InputStream& is,
size_t escapeOffset) {
757 for (
int i = 0; i < 4; i++) {
761 if (
c >=
'0' &&
c <=
'9')
763 else if (
c >=
'A' &&
c <=
'F')
765 else if (
c >=
'a' &&
c <=
'f')
769 RAPIDJSON_PARSE_ERROR_EARLY_RETURN(0);
776 template <
typename CharType>
783 *
stack_.template Push<Ch>() =
c;
807 template<
unsigned parseFlags,
typename InputStream,
typename Handler>
810 InputStream&
s(copy.s);
817 typename InputStream::Ch *
head =
s.PutBegin();
818 ParseStringToStream<parseFlags, SourceEncoding, SourceEncoding>(
s,
s);
819 RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
822 const typename TargetEncoding::Ch*
const str =
reinterpret_cast<typename TargetEncoding::Ch*
>(
head);
827 ParseStringToStream<parseFlags, SourceEncoding, TargetEncoding>(
s, stackStream);
828 RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
830 const typename TargetEncoding::Ch*
const str = stackStream.
Pop();
839 template<
unsigned parseFlags,
typename SEncoding,
typename TEncoding,
typename InputStream,
typename OutputStream>
842 #define Z16 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 843 static const char escape[256] = {
844 Z16,
Z16, 0, 0,
'\"', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
'/',
845 Z16,
Z16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
'\\', 0, 0, 0,
846 0, 0,
'\b', 0, 0, 0,
'\f', 0, 0, 0, 0, 0, 0, 0,
'\n', 0,
847 0, 0,
'\r', 0,
'\t', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
860 size_t escapeOffset = is.Tell();
863 if ((
sizeof(
Ch) == 1 ||
unsigned(e) < 256) &&
RAPIDJSON_LIKELY(escape[static_cast<unsigned char>(e)])) {
865 os.Put(static_cast<typename TEncoding::Ch>(escape[static_cast<unsigned char>(e)]));
870 RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
875 unsigned codepoint2 =
ParseHex4(is, escapeOffset);
876 RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
898 size_t offset = is.Tell();
907 template<
typename InputStream,
typename OutputStream>
912 #if defined(RAPIDJSON_SSE2) || defined(RAPIDJSON_SSE42) 915 const char*
p = is.
src_;
918 const char* nextAligned =
reinterpret_cast<const char*
>((
reinterpret_cast<size_t>(
p) + 15) &
static_cast<size_t>(~15));
919 while (
p != nextAligned)
928 static const char dquote[16] = {
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"' };
929 static const char bslash[16] = {
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\' };
930 static const char space[16] = { 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19 };
931 const __m128i dq = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&dquote[0]));
932 const __m128i bs = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&bslash[0]));
933 const __m128i sp = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&space[0]));
936 const __m128i
s = _mm_load_si128(reinterpret_cast<const __m128i *>(
p));
937 const __m128i t1 = _mm_cmpeq_epi8(
s, dq);
938 const __m128i t2 = _mm_cmpeq_epi8(
s, bs);
939 const __m128i t3 = _mm_cmpeq_epi8(_mm_max_epu8(
s, sp), sp);
940 const __m128i
x = _mm_or_si128(_mm_or_si128(t1, t2), t3);
941 unsigned short r =
static_cast<unsigned short>(_mm_movemask_epi8(
x));
944 #ifdef _MSC_VER // Find the index of first escaped 951 char*
q =
reinterpret_cast<char*
>(os.Push(
length));
952 for (
size_t i = 0; i <
length; i++)
958 _mm_storeu_si128(reinterpret_cast<__m128i *>(os.Push(16)),
s);
970 SkipUnescapedString(is);
978 const char* nextAligned =
reinterpret_cast<const char*
>((
reinterpret_cast<size_t>(
p) + 15) &
static_cast<size_t>(~15));
979 while (
p != nextAligned)
989 static const char dquote[16] = {
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"' };
990 static const char bslash[16] = {
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\' };
991 static const char space[16] = { 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19 };
992 const __m128i dq = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&dquote[0]));
993 const __m128i bs = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&bslash[0]));
994 const __m128i sp = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&space[0]));
996 for (;;
p += 16,
q += 16) {
997 const __m128i
s = _mm_load_si128(reinterpret_cast<const __m128i *>(
p));
998 const __m128i t1 = _mm_cmpeq_epi8(
s, dq);
999 const __m128i t2 = _mm_cmpeq_epi8(
s, bs);
1000 const __m128i t3 = _mm_cmpeq_epi8(_mm_max_epu8(
s, sp), sp);
1001 const __m128i
x = _mm_or_si128(_mm_or_si128(t1, t2), t3);
1002 unsigned short r =
static_cast<unsigned short>(_mm_movemask_epi8(
x));
1005 #ifdef _MSC_VER // Find the index of first escaped 1010 length =
static_cast<size_t>(__builtin_ffs(
r) - 1);
1012 for (
const char* pend =
p +
length;
p != pend; )
1016 _mm_storeu_si128(reinterpret_cast<__m128i *>(
q),
s);
1029 const char* nextAligned =
reinterpret_cast<const char*
>((
reinterpret_cast<size_t>(
p) + 15) &
static_cast<size_t>(~15));
1030 for (;
p != nextAligned;
p++)
1037 static const char dquote[16] = {
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"',
'\"' };
1038 static const char bslash[16] = {
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\',
'\\' };
1039 static const char space[16] = { 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19 };
1040 const __m128i dq = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&dquote[0]));
1041 const __m128i bs = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&bslash[0]));
1042 const __m128i sp = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&space[0]));
1045 const __m128i
s = _mm_load_si128(reinterpret_cast<const __m128i *>(
p));
1046 const __m128i t1 = _mm_cmpeq_epi8(
s, dq);
1047 const __m128i t2 = _mm_cmpeq_epi8(
s, bs);
1048 const __m128i t3 = _mm_cmpeq_epi8(_mm_max_epu8(
s, sp), sp);
1049 const __m128i
x = _mm_or_si128(_mm_or_si128(t1, t2), t3);
1050 unsigned short r =
static_cast<unsigned short>(_mm_movemask_epi8(
x));
1053 #ifdef _MSC_VER // Find the index of first escaped 1058 length =
static_cast<size_t>(__builtin_ffs(
r) - 1);
1069 template<
typename InputStream,
bool backup,
bool pushOnTake>
1072 template<
typename InputStream>
1075 typedef typename InputStream::Ch
Ch;
1083 RAPIDJSON_FORCEINLINE
void Push(
char) {}
1087 const char*
Pop() {
return 0; }
1095 template<
typename InputStream>
1103 stackStream.Put(static_cast<char>(Base::is.Peek()));
1104 return Base::is.Take();
1107 RAPIDJSON_FORCEINLINE
void Push(
char c) {
1111 size_t Length() {
return stackStream.Length(); }
1114 stackStream.Put(
'\0');
1115 return stackStream.Pop();
1122 template<
typename InputStream>
1129 RAPIDJSON_FORCEINLINE
Ch Take() {
return Base::TakePush(); }
1132 template<
unsigned parseFlags,
typename InputStream,
typename Handler>
1142 size_t startOffset =
s.Tell();
1144 bool useNanOrInf =
false;
1152 bool use64bit =
false;
1153 int significandDigit = 0;
1159 i =
static_cast<unsigned>(
s.TakePush() -
'0');
1170 i = i * 10 +
static_cast<unsigned>(
s.TakePush() -
'0');
1182 i = i * 10 +
static_cast<unsigned>(
s.TakePush() -
'0');
1190 d = std::numeric_limits<double>::quiet_NaN();
1193 d = (
minus ? -std::numeric_limits<double>::infinity() : std::numeric_limits<double>::infinity());
1205 bool useDouble =
false;
1211 d =
static_cast<double>(i64);
1215 i64 = i64 * 10 +
static_cast<unsigned>(
s.TakePush() -
'0');
1222 d =
static_cast<double>(i64);
1226 i64 = i64 * 10 +
static_cast<unsigned>(
s.TakePush() -
'0');
1236 d = d * 10 + (
s.TakePush() -
'0');
1242 size_t decimalPosition;
1244 decimalPosition =
s.Length();
1259 i64 = i64 * 10 +
static_cast<unsigned>(
s.TakePush() -
'0');
1266 d =
static_cast<double>(i64);
1269 d =
static_cast<double>(use64bit ? i64 : i);
1275 if (significandDigit < 17) {
1276 d = d * 10.0 + (
s.TakePush() -
'0');
1286 decimalPosition =
s.Length();
1292 d =
static_cast<double>(use64bit ? i64 : i);
1296 bool expMinus =
false;
1303 exp =
static_cast<int>(
s.Take() -
'0');
1306 exp =
exp * 10 +
static_cast<int>(
s.Take() -
'0');
1307 if (
exp >= 214748364) {
1314 int maxExp = 308 - expFrac;
1316 exp =
exp * 10 +
static_cast<int>(
s.Take() -
'0');
1335 typename InputStream::Ch*
head = is.PutBegin();
1336 const size_t length =
s.Tell() - startOffset;
1339 const typename TargetEncoding::Ch*
const str =
reinterpret_cast<typename TargetEncoding::Ch*
>(
head);
1346 while (numCharsToCopy--) {
1349 dstStream.Put(
'\0');
1350 const typename TargetEncoding::Ch*
str = dstStream.Pop();
1357 const char* decimal =
s.Pop();
1360 int p =
exp + expFrac;
1368 else if (useNanOrInf) {
1374 cont =
handler.Int64(static_cast<int64_t>(~i64 + 1));
1380 cont =
handler.Int(static_cast<int32_t>(~i + 1));
1391 template<
unsigned parseFlags,
typename InputStream,
typename Handler>
1393 switch (is.Peek()) {
1394 case 'n': ParseNull <parseFlags>(is,
handler);
break;
1395 case 't': ParseTrue <parseFlags>(is,
handler);
break;
1396 case 'f': ParseFalse <parseFlags>(is,
handler);
break;
1397 case '"': ParseString<parseFlags>(is,
handler);
break;
1398 case '{': ParseObject<parseFlags>(is,
handler);
break;
1399 case '[': ParseArray <parseFlags>(is,
handler);
break;
1401 ParseNumber<parseFlags>(is,
handler);
1458 #define N NumberToken 1459 #define N16 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N 1461 static const unsigned char tokenMap[256] = {
1464 N, N,
StringToken, N, N, N, N, N, N, N, N, N,
CommaToken, N, N, N,
1465 N, N, N, N, N, N, N, N, N, N,
ColonToken, N, N, N, N, N,
1467 N, N, N, N, N, N, N, N, N, N, N,
LeftBracketToken, N,
RightBracketToken, N, N,
1468 N, N, N, N, N, N,
FalseToken, N, N, N, N, N, N, N,
NullToken, N,
1469 N, N, N, N,
TrueToken, N, N, N, N, N, N,
LeftCurlyBracketToken, N,
RightCurlyBracketToken, N, N,
1470 N16, N16, N16, N16, N16, N16, N16, N16
1476 if (
sizeof(
Ch) == 1 || static_cast<unsigned>(
c) < 256)
1477 return static_cast<Token>(tokenMap[
static_cast<unsigned char>(
c)]);
1648 template <
unsigned parseFlags,
typename InputStream,
typename Handler>
1667 *
stack_.template Push<SizeType>(1) =
n;
1669 *
stack_.template Push<SizeType>(1) = 0;
1684 ParseString<parseFlags>(is,
handler,
true);
1697 ParseValue<parseFlags>(is,
handler);
1705 ParseValue<parseFlags>(is,
handler);
1715 *
stack_.template Top<SizeType>() = *
stack_.template Top<SizeType>() + 1;
1792 ParseValue<parseFlags>(is,
handler);
1800 template <
typename InputStream>
1821 template <
unsigned parseFlags,
typename InputStream,
typename Handler>
1827 SkipWhitespaceAndComments<parseFlags>(is);
1829 while (is.Peek() !=
'\0') {
1845 SkipWhitespaceAndComments<parseFlags>(is);
1879 #endif // RAPIDJSON_READER_H_
Parsing was terminated.
Definition: error.h:88
RAPIDJSON_FORCEINLINE Ch Take()
Definition: reader.h:1129
Default parse flags. Can be customized by defining RAPIDJSON_PARSE_DEFAULT_FLAGS.
Definition: reader.h:156
Definition: reader.h:1073
double StrtodFullPrecision(double d, int p, const char *decimals, size_t length, size_t decimalPosition, int exp)
Definition: strtod.h:224
Definition: reader.h:1424
RAPIDJSON_FORCEINLINE Ch Peek() const
Definition: reader.h:1080
Ch Peek()
Definition: stream.h:150
void ParseString(InputStream &is, Handler &handler, bool isKey=false)
Definition: reader.h:808
InputStream::Ch Ch
Definition: reader.h:1075
Definition: reader.h:1452
ParseResult Parse(InputStream &is, Handler &handler)
Parse JSON text.
Definition: reader.h:485
NumberStream(GenericReader &reader, InputStream &is)
Definition: reader.h:1099
Definition: reader.h:1420
Encoding::Ch Ch
Definition: reader.h:197
Missing a closing quotation mark in string.
Definition: error.h:81
NumberStream< InputStream, false, false > Base
Definition: reader.h:1097
internal::Stack< StackAllocator > stack_
A stack for storing decoded string temporarily during non-destructive parsing.
Definition: reader.h:1857
#define G(L)
Definition: lstate.h:205
RAPIDJSON_FORCEINLINE Token Tokenize(Ch c)
Definition: reader.h:1455
bool minus
Definition: connect_wiiupro.c:41
static const char * reader(lua_State *L, void *ud, size_t *size)
Definition: luac.c:122
Invalid value.
Definition: error.h:70
Definition: reader.h:1447
static int codepoint(lua_State *L)
Definition: lutf8lib.c:100
bool Null()
Definition: reader.h:202
void ParseNull(InputStream &is, Handler &handler)
Definition: reader.h:705
Invalid escape character in string.
Definition: error.h:80
Allow parsing NaN, Inf, Infinity, -Inf and -Infinity as doubles.
Definition: reader.h:155
bool HasParseError() const
Whether a parse error has occured in the last parsing.
Definition: reader.h:531
GLdouble GLdouble GLdouble r
Definition: glext.h:6406
A read-write string stream.
Definition: fwd.h:52
GLdouble GLdouble t
Definition: glext.h:6398
size_t Length()
Definition: reader.h:1086
#define RAPIDJSON_LIKELY(x)
Compiler branching hint for expression with high probability to be true.
Definition: rapidjson.h:455
Represents an in-memory input byte stream.
Definition: memorystream.h:40
Definition: reader.h:1430
GLenum GLsizei len
Definition: glext.h:7389
Definition: reader.h:1416
~NumberStream()
Definition: reader.h:1078
In-situ(destructive) parsing.
Definition: reader.h:147
~NumberStream()
Definition: reader.h:1100
Encoding conversion.
Definition: encodings.h:658
StackStream & operator=(const StackStream &)
#define RAPIDJSON_PARSE_ERROR_NORETURN(parseErrorCode, offset)
Macro to indicate a parse error.
Definition: reader.h:99
bool Uint(unsigned)
Definition: reader.h:205
const Ch * src_
Current read position.
Definition: stream.h:124
GLdouble s
Definition: glext.h:6390
#define cast(t, exp)
Definition: llimits.h:111
RAPIDJSON_FORCEINLINE IterativeParsingState Predict(IterativeParsingState state, Token token)
Definition: reader.h:1482
Definition: reader.h:1450
static RAPIDJSON_FORCEINLINE void ScanCopyUnescapedString(InputStream &, OutputStream &)
Definition: reader.h:908
RAPIDJSON_FORCEINLINE void ParseStringToStream(InputStream &is, OutputStream &os)
Definition: reader.h:840
Allow one-line (//) and multi-line (/**/) comments.
Definition: reader.h:152
Definition: reader.h:1418
typedef void(__stdcall *PFN_DESTRUCTION_CALLBACK)(void *pData)
void HandleError(IterativeParsingState src, InputStream &is)
Definition: reader.h:1801
#define exp(a)
Definition: math.h:32
SizeType length_
Definition: reader.h:803
After parsing a complete JSON root from stream, stop further processing the rest of stream....
Definition: reader.h:150
#define RAPIDJSON_NAMESPACE_END
provide custom rapidjson namespace (closing expression)
Definition: rapidjson.h:119
Read-only string stream.
Definition: fwd.h:47
Incorrect hex digit after \u escape in string.
Definition: error.h:78
bool success(size_t len)
Definition: peglib.h:475
const char * Pop()
Definition: reader.h:1113
const GLubyte * c
Definition: glext.h:9812
bool EndObject(SizeType)
Definition: reader.h:214
Result of parsing (wraps ParseErrorCode)
Definition: error.h:106
GLuint GLuint GLsizei count
Definition: glext.h:6292
bool String(const Ch *, SizeType, bool)
Definition: reader.h:211
size_t Tell()
Definition: reader.h:1085
static const size_t kDefaultStackCapacity
Default stack capacity in bytes for storing a single decoded string.
Definition: reader.h:1856
StackStream< char > stackStream
Definition: reader.h:1119
Allow trailing commas at the end of objects and arrays.
Definition: reader.h:154
void ParseFalse(InputStream &is, Handler &handler)
Definition: reader.h:731
internal::SelectIf< internal::IsSame< Derived, void >, BaseReaderHandler, Derived >::Type Override
Definition: reader.h:199
The document is empty.
Definition: error.h:67
StreamLocalCopy(Stream &original)
Definition: reader.h:246
Ch Take()
Definition: stream.h:151
void SetParseError(ParseErrorCode code, size_t offset)
Definition: reader.h:540
Definition: reader.h:1449
bool RawNumber(const Ch *str, SizeType len, bool copy)
enabled via kParseNumbersAsStringsFlag, string is not null-terminated (use length)
Definition: reader.h:210
double StrtodNormalPrecision(double d, int p)
Definition: strtod.h:35
bool StartObject()
Definition: reader.h:212
GenericReader< UTF8<>, UTF8<> > Reader
Reader with UTF8 encoding and default allocator.
Definition: reader.h:1862
Definition: reader.h:1421
void SkipWhitespace(InputStream &is)
Skip the JSON white spaces in a stream.
Definition: reader.h:264
Parse all numbers (ints/doubles) as strings.
Definition: reader.h:153
void Clear()
Definition: stack.h:98
Missing a comma or '}' after an object member.
Definition: error.h:74
ClearStackOnExit(GenericReader &r)
Definition: reader.h:551
Definition: reader.h:1412
Ch * Pop()
Definition: reader.h:794
The surrogate pair in string is invalid.
Definition: error.h:79
unsigned ParseHex4(InputStream &is, size_t escapeOffset)
Definition: reader.h:755
GenericReader(StackAllocator *stackAllocator=0, size_t stackCapacity=kDefaultStackCapacity)
Constructor.
Definition: reader.h:474
ParseResult IterativeParse(InputStream &is, Handler &handler)
Definition: reader.h:1822
Default implementation of Handler.
Definition: fwd.h:85
Ch * dst_
Definition: stream.h:165
bool Double(double)
Definition: reader.h:208
Miss fraction part in number.
Definition: error.h:85
bool StartArray()
Definition: reader.h:215
Number too big to be stored in double.
Definition: error.h:84
The document root must not follow by other values.
Definition: error.h:68
static uint64_t state[MAX_PADS]
Definition: xenon360_input.c:33
void ParseValue(InputStream &is, Handler &handler)
Definition: reader.h:1392
Definition: reader.h:1446
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:402
GLenum src
Definition: glext.h:6980
Definition: reader.h:1425
GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint GLdouble w1
Definition: glext.h:9211
NumberStream< InputStream, true, false > Base
Definition: reader.h:1124
size_t Length()
Definition: reader.h:1111
#define RAPIDJSON_PARSE_ERROR(parseErrorCode, offset)
(Internal) macro to indicate and handle a parse error.
Definition: reader.h:118
GLint GLint GLint GLint GLint x
Definition: glext.h:6295
GLdouble GLdouble GLdouble GLdouble q
Definition: glext.h:6414
Definition: document.h:391
#define RAPIDJSON_UNLIKELY(x)
Compiler branching hint for expression with low probability to be true.
Definition: rapidjson.h:468
Definition: reader.h:1419
Definition: inftrees.h:27
SourceEncoding::Ch Ch
SourceEncoding character type.
Definition: reader.h:468
RAPIDJSON_FORCEINLINE void * Push(SizeType count)
Definition: reader.h:787
GLfloat GLfloat p
Definition: glext.h:9809
Definition: reader.h:1070
const char * Pop()
Definition: reader.h:1087
size_t Offset() const
Get the error offset, if IsError(), 0 otherwise.
Definition: error.h:116
bool Int(int)
Definition: reader.h:204
void ClearStack()
Definition: reader.h:547
void Clear()
Reset error code.
Definition: error.h:128
Stream s
Definition: reader.h:234
#define RAPIDJSON_PARSE_DEFAULT_FLAGS
Definition: reader.h:139
RAPIDJSON_FORCEINLINE void Push(char c)
Definition: reader.h:1107
size_t Length() const
Definition: reader.h:792
Missing a name for object member.
Definition: error.h:72
bool Default()
Definition: reader.h:201
size_t GetErrorOffset() const
Get the position of last parsing error in input, 0 otherwise.
Definition: reader.h:537
Parse number in full precision (but slower).
Definition: reader.h:151
bool IsError() const
Whether the result is an error.
Definition: error.h:121
void Set(ParseErrorCode code, size_t offset=0)
Update error code and offset.
Definition: error.h:130
Definition: reader.h:1411
ParseErrorCode
Error code of parsing.
Definition: error.h:64
#define RAPIDJSON_NAMESPACE_BEGIN
provide custom rapidjson namespace (opening expression)
Definition: rapidjson.h:116
~ClearStackOnExit()
Definition: reader.h:552
ParseErrorCode Code() const
Get the error code.
Definition: error.h:114
bool Key(const Ch *str, SizeType len, bool copy)
Definition: reader.h:213
ParseResult parseResult_
Definition: reader.h:1858
GenericReader & r_
Definition: reader.h:554
NumberStream(GenericReader &reader, InputStream &is)
Definition: reader.h:1126
Ch * src_
Definition: stream.h:164
bool Bool(bool)
Definition: reader.h:203
RAPIDJSON_FORCEINLINE IterativeParsingState Transit(IterativeParsingState src, Token token, IterativeParsingState dst, InputStream &is, Handler &handler)
Definition: reader.h:1649
CharType Ch
Definition: reader.h:779
Definition: reader.h:1413
Missing a comma or ']' after an array element.
Definition: error.h:76
StackStream(internal::Stack< StackAllocator > &stack)
Definition: reader.h:781
bool Uint64(uint64_t)
Definition: reader.h:207
Input byte stream wrapper with a statically bound encoding.
Definition: encodedstream.h:39
JSON_Parser_EncodingDetectedHandler handler
Definition: jsonsax_full.h:561
signed __int64 int64_t
Definition: stdint.h:135
Definition: reader.h:1441
bool Int64(int64_t)
Definition: reader.h:206
Definition: reader.h:1444
static RAPIDJSON_FORCEINLINE bool Consume(InputStream &is, typename InputStream::Ch expect)
Definition: reader.h:744
GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint GLdouble GLdouble w2
Definition: glext.h:9211
Definition: reader.h:1427
Validate encoding of JSON strings.
Definition: reader.h:148
RAPIDJSON_FORCEINLINE Ch TakePush()
Definition: reader.h:1102
void ParseNumber(InputStream &is, Handler &handler)
Definition: reader.h:1133
StreamLocalCopy(Stream &original)
Definition: reader.h:231
ClearStackOnExit & operator=(const ClearStackOnExit &)
InputStream & is
Definition: reader.h:1092
void ParseObject(InputStream &is, Handler &handler)
Definition: reader.h:589
bool EndArray(SizeType)
Definition: reader.h:216
~NumberStream()
Definition: reader.h:1127
No flags are set.
Definition: reader.h:146
Definition: reader.h:1440
internal::Stack< StackAllocator > & stack_
Definition: reader.h:802
Type
Type of JSON value.
Definition: rapidjson.h:603
GLenum GLenum dst
Definition: glext.h:6980
ParseFlag
Combination of parseFlags.
Definition: reader.h:145
ParseErrorCode GetParseErrorCode() const
Get the ParseErrorCode of last parsing.
Definition: reader.h:534
vu8 head
Definition: keyboard.c:426
void ParseArray(InputStream &is, Handler &handler)
Definition: reader.h:657
GLuint GLuint end
Definition: glext.h:6292
void SkipWhitespaceAndComments(InputStream &is)
Definition: reader.h:560
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:6742
RAPIDJSON_FORCEINLINE Ch TakePush()
Definition: reader.h:1081
#define false
Definition: ordinals.h:83
UTF-8 encoding.
Definition: encodings.h:96
Definition: reader.h:1438
RAPIDJSON_FORCEINLINE void Push(char)
Definition: reader.h:1083
Definition: reader.h:1096
Definition: reader.h:1433
#define RAPIDJSON_UINT64_C2(high32, low32)
Construct a 64-bit literal by a pair of 32-bit integer.
Definition: rapidjson.h:289
GLintptr offset
Definition: glext.h:6560
#define true
Definition: ordinals.h:82
RAPIDJSON_FORCEINLINE void Put(Ch c)
Definition: reader.h:782
Miss exponent in number.
Definition: error.h:86
RAPIDJSON_FORCEINLINE Ch Take()
Definition: reader.h:1082
Stream & s
Definition: reader.h:248
SAX-style JSON parser. Use Reader for UTF8 encoding and default allocator.
Definition: fwd.h:88
Definition: reader.h:1417
Invalid encoding in string.
Definition: error.h:82
IterativeParsingState
Definition: reader.h:1410
Unspecific syntax error.
Definition: error.h:89
void ParseTrue(InputStream &is, Handler &handler)
Definition: reader.h:718
unsigned __int64 uint64_t
Definition: stdint.h:136
GLenum GLuint GLenum GLsizei length
Definition: glext.h:6233
Stream & original_
Definition: reader.h:239
GLdouble n
Definition: glext.h:8396
Iterative(constant complexity in terms of function call stack size) parsing.
Definition: reader.h:149
Definition: reader.h:1448
const char *const str
Definition: portlistingparse.c:18
GenericReader & operator=(const GenericReader &)
RAPIDJSON_NAMESPACE_BEGIN typedef unsigned SizeType
Size type (for string lengths, array sizes, etc.)
Definition: rapidjson.h:380
Definition: reader.h:1437
Missing a colon after a name of object member.
Definition: error.h:73
size_t Tell()
Definition: stream.h:152
~StreamLocalCopy()
Definition: reader.h:232
Definition: reader.h:1443
NumberStream(GenericReader &reader, InputStream &s)
Definition: reader.h:1077
ParseResult Parse(InputStream &is, Handler &handler)
Parse JSON text (with kParseDefaultFlags)
Definition: reader.h:526
Definition: reader.h:1426