From d2d5f6f91984a533107a52cdad40e34c9b86906d Mon Sep 17 00:00:00 2001 From: Sergey Kosarevsky Date: Sun, 28 Feb 2016 17:58:34 +0100 Subject: [PATCH] ParseNumber() handles kParseNumbersAsStringsFlag --- include/rapidjson/reader.h | 57 +++++++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 22 deletions(-) diff --git a/include/rapidjson/reader.h b/include/rapidjson/reader.h index 6ee1f43..5f8b1a9 100644 --- a/include/rapidjson/reader.h +++ b/include/rapidjson/reader.h @@ -1097,6 +1097,8 @@ private: NumberStream s(*this, copy.s); size_t startOffset = s.Tell(); + typename InputStream::Ch *head = is.PutBegin(); + // Parse minus bool minus = Consume(s, '-'); @@ -1268,31 +1270,42 @@ private: // Finish parsing, call event according to the type of number. bool cont = true; - size_t length = s.Length(); - const char* decimal = s.Pop(); // Pop stack no matter if it will be used or not. - if (useDouble) { - int p = exp + expFrac; - if (parseFlags & kParseFullPrecisionFlag) - d = internal::StrtodFullPrecision(d, p, decimal, length, decimalPosition, exp); - else - d = internal::StrtodNormalPrecision(d, p); + if (parseFlags & kParseNumbersAsStringsFlag) + { + s.Pop(); // Pop stack no matter if it will be used or not. + const size_t length = s.Tell() - startOffset; - cont = handler.Double(minus ? -d : d); + cont = handler.Number(head, length, (parseFlags & kParseInsituFlag) ? false : true); } - else { - if (use64bit) { - if (minus) - cont = handler.Int64(static_cast(~i64 + 1)); - else - cont = handler.Uint64(i64); - } - else { - if (minus) - cont = handler.Int(static_cast(~i + 1)); - else - cont = handler.Uint(i); - } + else + { + size_t length = s.Length(); + const char* decimal = s.Pop(); // Pop stack no matter if it will be used or not. + + if (useDouble) { + int p = exp + expFrac; + if (parseFlags & kParseFullPrecisionFlag) + d = internal::StrtodFullPrecision(d, p, decimal, length, decimalPosition, exp); + else + d = internal::StrtodNormalPrecision(d, p); + + cont = handler.Double(minus ? -d : d); + } + else { + if (use64bit) { + if (minus) + cont = handler.Int64(static_cast(~i64 + 1)); + else + cont = handler.Uint64(i64); + } + else { + if (minus) + cont = handler.Int(static_cast(~i + 1)); + else + cont = handler.Uint(i); + } + } } if (RAPIDJSON_UNLIKELY(!cont)) RAPIDJSON_PARSE_ERROR(kParseErrorTermination, startOffset);