diff options
Diffstat (limited to 'Utilities/cmjsoncpp/src/lib_json/json_reader.cpp')
-rw-r--r-- | Utilities/cmjsoncpp/src/lib_json/json_reader.cpp | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/Utilities/cmjsoncpp/src/lib_json/json_reader.cpp b/Utilities/cmjsoncpp/src/lib_json/json_reader.cpp index e6caf40..5cc718d 100644 --- a/Utilities/cmjsoncpp/src/lib_json/json_reader.cpp +++ b/Utilities/cmjsoncpp/src/lib_json/json_reader.cpp @@ -12,6 +12,7 @@ #endif // if !defined(JSON_IS_AMALGAMATION) #include <algorithm> #include <cassert> +#include <cmath> #include <cstring> #include <iostream> #include <istream> @@ -104,8 +105,7 @@ bool Reader::parse(std::istream& is, Value& root, bool collectComments) { // Since String is reference-counted, this at least does not // create an extra copy. - String doc; - std::getline(is, doc, static_cast<char> EOF); + String doc(std::istreambuf_iterator<char>(is), {}); return parse(doc.data(), doc.data() + doc.size(), root, collectComments); } @@ -601,9 +601,15 @@ bool Reader::decodeDouble(Token& token, Value& decoded) { double value = 0; String buffer(token.start_, token.end_); IStringStream is(buffer); - if (!(is >> value)) - return addError( + if (!(is >> value)) { + if (value == std::numeric_limits<double>::max()) + value = std::numeric_limits<double>::infinity(); + else if (value == std::numeric_limits<double>::lowest()) + value = -std::numeric_limits<double>::infinity(); + else if (!std::isinf(value)) + return addError( "'" + String(token.start_, token.end_) + "' is not a number.", token); + } decoded = value; return true; } @@ -1608,7 +1614,7 @@ bool OurReader::decodeNumber(Token& token, Value& decoded) { const auto digit(static_cast<Value::UInt>(c - '0')); if (value >= threshold) { // We've hit or exceeded the max value divided by 10 (rounded down). If - // a) we've only just touched the limit, meaing value == threshold, + // a) we've only just touched the limit, meaning value == threshold, // b) this is the last digit, or // c) it's small enough to fit in that rounding delta, we're okay. // Otherwise treat this number as a double to avoid overflow. @@ -1648,7 +1654,12 @@ bool OurReader::decodeDouble(Token& token, Value& decoded) { const String buffer(token.start_, token.end_); IStringStream is(buffer); if (!(is >> value)) { - return addError( + if (value == std::numeric_limits<double>::max()) + value = std::numeric_limits<double>::infinity(); + else if (value == std::numeric_limits<double>::lowest()) + value = -std::numeric_limits<double>::infinity(); + else if (!std::isinf(value)) + return addError( "'" + String(token.start_, token.end_) + "' is not a number.", token); } decoded = value; @@ -1922,7 +1933,7 @@ bool CharReaderBuilder::validate(Json::Value* invalid) const { if (valid_keys.count(key)) continue; if (invalid) - (*invalid)[std::move(key)] = *si; + (*invalid)[key] = *si; else return false; } |