diff options
| author | Brad King <brad.king@kitware.com> | 2022-01-12 22:05:54 (GMT) |
|---|---|---|
| committer | Brad King <brad.king@kitware.com> | 2022-01-12 22:05:54 (GMT) |
| commit | 33fae4cd7a344889404ce61fe1d40a443ad58def (patch) | |
| tree | 0b35ff2e6a978007be841227a731f08fccfe2ad2 /Utilities/cmjsoncpp/src/lib_json/json_reader.cpp | |
| parent | eb031dfe9fdb498592d368e900ed3e1ee2181703 (diff) | |
| parent | 7a72ab3388c5f439070167fbcefd1cbdd776be9f (diff) | |
| download | CMake-33fae4cd7a344889404ce61fe1d40a443ad58def.zip CMake-33fae4cd7a344889404ce61fe1d40a443ad58def.tar.gz CMake-33fae4cd7a344889404ce61fe1d40a443ad58def.tar.bz2 | |
Merge branch 'upstream-jsoncpp' into update-jsoncpp
* upstream-jsoncpp:
jsoncpp 2022-01-12 (42e892d9)
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; } |
