Update jsoncpp from 1.9.3 to 1.9.5 (#14122)

This commit is contained in:
Rose
2022-10-05 12:35:27 -04:00
committed by GitHub
parent 54dc2c4432
commit 00cdacc96b
5 changed files with 108 additions and 98 deletions

View File

@@ -2,8 +2,8 @@
[Amalgamated](https://github.com/open-source-parsers/jsoncpp/wiki/Amalgamated) [Amalgamated](https://github.com/open-source-parsers/jsoncpp/wiki/Amalgamated)
from source commit from source commit
[6aba23f](https://github.com/open-source-parsers/jsoncpp/commit/6aba23f4a8628d599a9ef7fa4811c4ff6e4070e2), [5defb4e](https://github.com/open-source-parsers/jsoncpp/commit/5defb4ed1a4293b8e2bf641e16b156fb9de498cc),
release 1.9.3. release 1.9.5.
> Generating amalgamated source and header JsonCpp is provided with a script to > Generating amalgamated source and header JsonCpp is provided with a script to
> generate a single header and a single source file to ease inclusion into an > generate a single header and a single source file to ease inclusion into an

View File

@@ -6,7 +6,7 @@
"type": "git", "type": "git",
"git": { "git": {
"repositoryUrl": "https://github.com/open-source-parsers/jsoncpp", "repositoryUrl": "https://github.com/open-source-parsers/jsoncpp",
"commitHash": "6aba23f4a8628d599a9ef7fa4811c4ff6e4070e2" "commitHash": "5defb4ed1a4293b8e2bf641e16b156fb9de498cc"
} }
} }
} }

View File

@@ -7,28 +7,28 @@
// ////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////
/* /*
The JsonCpp library's source code, including accompanying documentation, The JsonCpp library's source code, including accompanying documentation,
tests and demonstration applications, are licensed under the following tests and demonstration applications, are licensed under the following
conditions... conditions...
Baptiste Lepilleur and The JsonCpp Authors explicitly disclaim copyright in all Baptiste Lepilleur and The JsonCpp Authors explicitly disclaim copyright in all
jurisdictions which recognize such a disclaimer. In such jurisdictions, jurisdictions which recognize such a disclaimer. In such jurisdictions,
this software is released into the Public Domain. this software is released into the Public Domain.
In jurisdictions which do not recognize Public Domain property (e.g. Germany as of In jurisdictions which do not recognize Public Domain property (e.g. Germany as of
2010), this software is Copyright (c) 2007-2010 by Baptiste Lepilleur and 2010), this software is Copyright (c) 2007-2010 by Baptiste Lepilleur and
The JsonCpp Authors, and is released under the terms of the MIT License (see below). The JsonCpp Authors, and is released under the terms of the MIT License (see below).
In jurisdictions which recognize Public Domain property, the user of this In jurisdictions which recognize Public Domain property, the user of this
software may choose to accept it either as 1) Public Domain, 2) under the software may choose to accept it either as 1) Public Domain, 2) under the
conditions of the MIT License (see below), or 3) under the terms of dual conditions of the MIT License (see below), or 3) under the terms of dual
Public Domain/MIT License conditions described here, as they choose. Public Domain/MIT License conditions described here, as they choose.
The MIT License is about as close to Public Domain as a license can get, and is The MIT License is about as close to Public Domain as a license can get, and is
described in clear, concise terms at: described in clear, concise terms at:
http://en.wikipedia.org/wiki/MIT_License http://en.wikipedia.org/wiki/MIT_License
The full text of the MIT License follows: The full text of the MIT License follows:
======================================================================== ========================================================================
@@ -94,10 +94,10 @@ license you like.
// 3. /CMakeLists.txt // 3. /CMakeLists.txt
// IMPORTANT: also update the SOVERSION!! // IMPORTANT: also update the SOVERSION!!
#define JSONCPP_VERSION_STRING "1.9.3" #define JSONCPP_VERSION_STRING "1.9.5"
#define JSONCPP_VERSION_MAJOR 1 #define JSONCPP_VERSION_MAJOR 1
#define JSONCPP_VERSION_MINOR 9 #define JSONCPP_VERSION_MINOR 9
#define JSONCPP_VERSION_PATCH 3 #define JSONCPP_VERSION_PATCH 5
#define JSONCPP_VERSION_QUALIFIER #define JSONCPP_VERSION_QUALIFIER
#define JSONCPP_VERSION_HEXA \ #define JSONCPP_VERSION_HEXA \
((JSONCPP_VERSION_MAJOR << 24) | (JSONCPP_VERSION_MINOR << 16) | \ ((JSONCPP_VERSION_MAJOR << 24) | (JSONCPP_VERSION_MINOR << 16) | \
@@ -162,11 +162,10 @@ public:
* Release memory which was allocated for N items at pointer P. * Release memory which was allocated for N items at pointer P.
* *
* The memory block is filled with zeroes before being released. * The memory block is filled with zeroes before being released.
* The pointer argument is tagged as "volatile" to prevent the
* compiler optimizing out this critical step.
*/ */
void deallocate(volatile pointer p, size_type n) { void deallocate(pointer p, size_type n) {
std::memset(p, 0, n * sizeof(T)); // memset_s is used because memset may be optimized away by the compiler
memset_s(p, n * sizeof(T), 0, n * sizeof(T));
// free using "global operator delete" // free using "global operator delete"
::operator delete(p); ::operator delete(p);
} }

View File

@@ -6,28 +6,28 @@
// ////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////
/* /*
The JsonCpp library's source code, including accompanying documentation, The JsonCpp library's source code, including accompanying documentation,
tests and demonstration applications, are licensed under the following tests and demonstration applications, are licensed under the following
conditions... conditions...
Baptiste Lepilleur and The JsonCpp Authors explicitly disclaim copyright in all Baptiste Lepilleur and The JsonCpp Authors explicitly disclaim copyright in all
jurisdictions which recognize such a disclaimer. In such jurisdictions, jurisdictions which recognize such a disclaimer. In such jurisdictions,
this software is released into the Public Domain. this software is released into the Public Domain.
In jurisdictions which do not recognize Public Domain property (e.g. Germany as of In jurisdictions which do not recognize Public Domain property (e.g. Germany as of
2010), this software is Copyright (c) 2007-2010 by Baptiste Lepilleur and 2010), this software is Copyright (c) 2007-2010 by Baptiste Lepilleur and
The JsonCpp Authors, and is released under the terms of the MIT License (see below). The JsonCpp Authors, and is released under the terms of the MIT License (see below).
In jurisdictions which recognize Public Domain property, the user of this In jurisdictions which recognize Public Domain property, the user of this
software may choose to accept it either as 1) Public Domain, 2) under the software may choose to accept it either as 1) Public Domain, 2) under the
conditions of the MIT License (see below), or 3) under the terms of dual conditions of the MIT License (see below), or 3) under the terms of dual
Public Domain/MIT License conditions described here, as they choose. Public Domain/MIT License conditions described here, as they choose.
The MIT License is about as close to Public Domain as a license can get, and is The MIT License is about as close to Public Domain as a license can get, and is
described in clear, concise terms at: described in clear, concise terms at:
http://en.wikipedia.org/wiki/MIT_License http://en.wikipedia.org/wiki/MIT_License
The full text of the MIT License follows: The full text of the MIT License follows:
======================================================================== ========================================================================
@@ -93,10 +93,10 @@ license you like.
// 3. /CMakeLists.txt // 3. /CMakeLists.txt
// IMPORTANT: also update the SOVERSION!! // IMPORTANT: also update the SOVERSION!!
#define JSONCPP_VERSION_STRING "1.9.3" #define JSONCPP_VERSION_STRING "1.9.5"
#define JSONCPP_VERSION_MAJOR 1 #define JSONCPP_VERSION_MAJOR 1
#define JSONCPP_VERSION_MINOR 9 #define JSONCPP_VERSION_MINOR 9
#define JSONCPP_VERSION_PATCH 3 #define JSONCPP_VERSION_PATCH 5
#define JSONCPP_VERSION_QUALIFIER #define JSONCPP_VERSION_QUALIFIER
#define JSONCPP_VERSION_HEXA \ #define JSONCPP_VERSION_HEXA \
((JSONCPP_VERSION_MAJOR << 24) | (JSONCPP_VERSION_MINOR << 16) | \ ((JSONCPP_VERSION_MAJOR << 24) | (JSONCPP_VERSION_MINOR << 16) | \
@@ -161,11 +161,10 @@ public:
* Release memory which was allocated for N items at pointer P. * Release memory which was allocated for N items at pointer P.
* *
* The memory block is filled with zeroes before being released. * The memory block is filled with zeroes before being released.
* The pointer argument is tagged as "volatile" to prevent the
* compiler optimizing out this critical step.
*/ */
void deallocate(volatile pointer p, size_type n) { void deallocate(pointer p, size_type n) {
std::memset(p, 0, n * sizeof(T)); // memset_s is used because memset may be optimized away by the compiler
memset_s(p, n * sizeof(T), 0, n * sizeof(T));
// free using "global operator delete" // free using "global operator delete"
::operator delete(p); ::operator delete(p);
} }
@@ -575,7 +574,7 @@ public:
// be used by... // be used by...
#if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING) #if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
#pragma warning(push) #pragma warning(push)
#pragma warning(disable : 4251) #pragma warning(disable : 4251 4275)
#endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING) #endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
#pragma pack(push, 8) #pragma pack(push, 8)
@@ -788,10 +787,10 @@ private:
CZString(ArrayIndex index); CZString(ArrayIndex index);
CZString(char const* str, unsigned length, DuplicationPolicy allocate); CZString(char const* str, unsigned length, DuplicationPolicy allocate);
CZString(CZString const& other); CZString(CZString const& other);
CZString(CZString&& other); CZString(CZString&& other) noexcept;
~CZString(); ~CZString();
CZString& operator=(const CZString& other); CZString& operator=(const CZString& other);
CZString& operator=(CZString&& other); CZString& operator=(CZString&& other) noexcept;
bool operator<(CZString const& other) const; bool operator<(CZString const& other) const;
bool operator==(CZString const& other) const; bool operator==(CZString const& other) const;
@@ -867,14 +866,15 @@ public:
Value(const StaticString& value); Value(const StaticString& value);
Value(const String& value); Value(const String& value);
Value(bool value); Value(bool value);
Value(std::nullptr_t ptr) = delete;
Value(const Value& other); Value(const Value& other);
Value(Value&& other); Value(Value&& other) noexcept;
~Value(); ~Value();
/// \note Overwrite existing comments. To preserve comments, use /// \note Overwrite existing comments. To preserve comments, use
/// #swapPayload(). /// #swapPayload().
Value& operator=(const Value& other); Value& operator=(const Value& other);
Value& operator=(Value&& other); Value& operator=(Value&& other) noexcept;
/// Swap everything. /// Swap everything.
void swap(Value& other); void swap(Value& other);
@@ -1159,9 +1159,9 @@ private:
public: public:
Comments() = default; Comments() = default;
Comments(const Comments& that); Comments(const Comments& that);
Comments(Comments&& that); Comments(Comments&& that) noexcept;
Comments& operator=(const Comments& that); Comments& operator=(const Comments& that);
Comments& operator=(Comments&& that); Comments& operator=(Comments&& that) noexcept;
bool has(CommentPlacement slot) const; bool has(CommentPlacement slot) const;
String get(CommentPlacement slot) const; String get(CommentPlacement slot) const;
void set(CommentPlacement slot, String comment); void set(CommentPlacement slot, String comment);
@@ -1442,8 +1442,8 @@ public:
* because the returned references/pointers can be used * because the returned references/pointers can be used
* to change state of the base class. * to change state of the base class.
*/ */
reference operator*() { return deref(); } reference operator*() const { return const_cast<reference>(deref()); }
pointer operator->() { return &deref(); } pointer operator->() const { return const_cast<pointer>(&deref()); }
}; };
inline void swap(Value& a, Value& b) { a.swap(b); } inline void swap(Value& a, Value& b) { a.swap(b); }
@@ -1506,8 +1506,7 @@ namespace Json {
* \deprecated Use CharReader and CharReaderBuilder. * \deprecated Use CharReader and CharReaderBuilder.
*/ */
class JSONCPP_DEPRECATED( class JSON_API Reader {
"Use CharReader and CharReaderBuilder instead.") JSON_API Reader {
public: public:
using Char = char; using Char = char;
using Location = const Char*; using Location = const Char*;
@@ -1524,13 +1523,13 @@ public:
}; };
/** \brief Constructs a Reader allowing all features for parsing. /** \brief Constructs a Reader allowing all features for parsing.
* \deprecated Use CharReader and CharReaderBuilder.
*/ */
JSONCPP_DEPRECATED("Use CharReader and CharReaderBuilder instead")
Reader(); Reader();
/** \brief Constructs a Reader allowing the specified feature set for parsing. /** \brief Constructs a Reader allowing the specified feature set for parsing.
* \deprecated Use CharReader and CharReaderBuilder.
*/ */
JSONCPP_DEPRECATED("Use CharReader and CharReaderBuilder instead")
Reader(const Features& features); Reader(const Features& features);
/** \brief Read a Value from a <a HREF="http://www.json.org">JSON</a> /** \brief Read a Value from a <a HREF="http://www.json.org">JSON</a>
@@ -1797,6 +1796,9 @@ public:
* - `"allowSpecialFloats": false or true` * - `"allowSpecialFloats": false or true`
* - If true, special float values (NaNs and infinities) are allowed and * - If true, special float values (NaNs and infinities) are allowed and
* their values are lossfree restorable. * their values are lossfree restorable.
* - `"skipBom": false or true`
* - If true, if the input starts with the Unicode byte order mark (BOM),
* it is skipped.
* *
* You can examine 'settings_` yourself to see the defaults. You can also * You can examine 'settings_` yourself to see the defaults. You can also
* write and read them just like any JSON Value. * write and read them just like any JSON Value.
@@ -2000,6 +2002,8 @@ public:
* - Number of precision digits for formatting of real values. * - Number of precision digits for formatting of real values.
* - "precisionType": "significant"(default) or "decimal" * - "precisionType": "significant"(default) or "decimal"
* - Type of precision for formatting of real values. * - Type of precision for formatting of real values.
* - "emitUTF8": false or true
* - If true, outputs raw UTF8 strings instead of escaping them.
* You can examine 'settings_` yourself * You can examine 'settings_` yourself
* to see the defaults. You can also write and read them just like any * to see the defaults. You can also write and read them just like any
@@ -2035,7 +2039,7 @@ public:
/** \brief Abstract class for writers. /** \brief Abstract class for writers.
* \deprecated Use StreamWriter. (And really, this is an implementation detail.) * \deprecated Use StreamWriter. (And really, this is an implementation detail.)
*/ */
class JSONCPP_DEPRECATED("Use StreamWriter instead") JSON_API Writer { class JSON_API Writer {
public: public:
virtual ~Writer(); virtual ~Writer();
@@ -2055,7 +2059,7 @@ public:
#pragma warning(push) #pragma warning(push)
#pragma warning(disable : 4996) // Deriving from deprecated class #pragma warning(disable : 4996) // Deriving from deprecated class
#endif #endif
class JSONCPP_DEPRECATED("Use StreamWriterBuilder instead") JSON_API FastWriter class JSON_API FastWriter
: public Writer { : public Writer {
public: public:
FastWriter(); FastWriter();
@@ -2115,7 +2119,7 @@ private:
#pragma warning(push) #pragma warning(push)
#pragma warning(disable : 4996) // Deriving from deprecated class #pragma warning(disable : 4996) // Deriving from deprecated class
#endif #endif
class JSONCPP_DEPRECATED("Use StreamWriterBuilder instead") JSON_API class JSON_API
StyledWriter : public Writer { StyledWriter : public Writer {
public: public:
StyledWriter(); StyledWriter();
@@ -2184,7 +2188,7 @@ private:
#pragma warning(push) #pragma warning(push)
#pragma warning(disable : 4996) // Deriving from deprecated class #pragma warning(disable : 4996) // Deriving from deprecated class
#endif #endif
class JSONCPP_DEPRECATED("Use StreamWriterBuilder instead") JSON_API class JSON_API
StyledStreamWriter { StyledStreamWriter {
public: public:
/** /**

View File

@@ -6,28 +6,28 @@
// ////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////
/* /*
The JsonCpp library's source code, including accompanying documentation, The JsonCpp library's source code, including accompanying documentation,
tests and demonstration applications, are licensed under the following tests and demonstration applications, are licensed under the following
conditions... conditions...
Baptiste Lepilleur and The JsonCpp Authors explicitly disclaim copyright in all Baptiste Lepilleur and The JsonCpp Authors explicitly disclaim copyright in all
jurisdictions which recognize such a disclaimer. In such jurisdictions, jurisdictions which recognize such a disclaimer. In such jurisdictions,
this software is released into the Public Domain. this software is released into the Public Domain.
In jurisdictions which do not recognize Public Domain property (e.g. Germany as of In jurisdictions which do not recognize Public Domain property (e.g. Germany as of
2010), this software is Copyright (c) 2007-2010 by Baptiste Lepilleur and 2010), this software is Copyright (c) 2007-2010 by Baptiste Lepilleur and
The JsonCpp Authors, and is released under the terms of the MIT License (see below). The JsonCpp Authors, and is released under the terms of the MIT License (see below).
In jurisdictions which recognize Public Domain property, the user of this In jurisdictions which recognize Public Domain property, the user of this
software may choose to accept it either as 1) Public Domain, 2) under the software may choose to accept it either as 1) Public Domain, 2) under the
conditions of the MIT License (see below), or 3) under the terms of dual conditions of the MIT License (see below), or 3) under the terms of dual
Public Domain/MIT License conditions described here, as they choose. Public Domain/MIT License conditions described here, as they choose.
The MIT License is about as close to Public Domain as a license can get, and is The MIT License is about as close to Public Domain as a license can get, and is
described in clear, concise terms at: described in clear, concise terms at:
http://en.wikipedia.org/wiki/MIT_License http://en.wikipedia.org/wiki/MIT_License
The full text of the MIT License follows: The full text of the MIT License follows:
======================================================================== ========================================================================
@@ -202,14 +202,18 @@ template <typename Iter> void fixNumericLocaleInput(Iter begin, Iter end) {
* Return iterator that would be the new end of the range [begin,end), if we * Return iterator that would be the new end of the range [begin,end), if we
* were to delete zeros in the end of string, but not the last zero before '.'. * were to delete zeros in the end of string, but not the last zero before '.'.
*/ */
template <typename Iter> Iter fixZerosInTheEnd(Iter begin, Iter end) { template <typename Iter>
Iter fixZerosInTheEnd(Iter begin, Iter end, unsigned int precision) {
for (; begin != end; --end) { for (; begin != end; --end) {
if (*(end - 1) != '0') { if (*(end - 1) != '0') {
return end; return end;
} }
// Don't delete the last zero before the decimal point. // Don't delete the last zero before the decimal point.
if (begin != (end - 1) && *(end - 2) == '.') { if (begin != (end - 1) && begin != (end - 2) && *(end - 2) == '.') {
return end; if (precision) {
return end;
}
return end - 2;
} }
} }
return end; return end;
@@ -338,8 +342,7 @@ bool Reader::parse(std::istream& is, Value& root, bool collectComments) {
// Since String is reference-counted, this at least does not // Since String is reference-counted, this at least does not
// create an extra copy. // create an extra copy.
String doc; String doc(std::istreambuf_iterator<char>(is), {});
std::getline(is, doc, static_cast<char> EOF);
return parse(doc.data(), doc.data() + doc.size(), root, collectComments); return parse(doc.data(), doc.data() + doc.size(), root, collectComments);
} }
@@ -1409,8 +1412,11 @@ bool OurReader::readToken(Token& token) {
if (features_.allowSingleQuotes_) { if (features_.allowSingleQuotes_) {
token.type_ = tokenString; token.type_ = tokenString;
ok = readStringSingleQuote(); ok = readStringSingleQuote();
break; } else {
} // else fall through // If we don't allow single quotes, this is a failure case.
ok = false;
}
break;
case '/': case '/':
token.type_ = tokenComment; token.type_ = tokenComment;
ok = readComment(); ok = readComment();
@@ -2152,7 +2158,7 @@ bool CharReaderBuilder::validate(Json::Value* invalid) const {
if (valid_keys.count(key)) if (valid_keys.count(key))
continue; continue;
if (invalid) if (invalid)
(*invalid)[std::move(key)] = *si; (*invalid)[key] = *si;
else else
return false; return false;
} }
@@ -2667,7 +2673,7 @@ Value::CZString::CZString(const CZString& other) {
storage_.length_ = other.storage_.length_; storage_.length_ = other.storage_.length_;
} }
Value::CZString::CZString(CZString&& other) Value::CZString::CZString(CZString&& other) noexcept
: cstr_(other.cstr_), index_(other.index_) { : cstr_(other.cstr_), index_(other.index_) {
other.cstr_ = nullptr; other.cstr_ = nullptr;
} }
@@ -2693,7 +2699,7 @@ Value::CZString& Value::CZString::operator=(const CZString& other) {
return *this; return *this;
} }
Value::CZString& Value::CZString::operator=(CZString&& other) { Value::CZString& Value::CZString::operator=(CZString&& other) noexcept {
cstr_ = other.cstr_; cstr_ = other.cstr_;
index_ = other.index_; index_ = other.index_;
other.cstr_ = nullptr; other.cstr_ = nullptr;
@@ -2841,7 +2847,7 @@ Value::Value(const Value& other) {
dupMeta(other); dupMeta(other);
} }
Value::Value(Value&& other) { Value::Value(Value&& other) noexcept {
initBasic(nullValue); initBasic(nullValue);
swap(other); swap(other);
} }
@@ -2856,7 +2862,7 @@ Value& Value::operator=(const Value& other) {
return *this; return *this;
} }
Value& Value::operator=(Value&& other) { Value& Value::operator=(Value&& other) noexcept {
other.swap(*this); other.swap(*this);
return *this; return *this;
} }
@@ -3320,7 +3326,8 @@ void Value::resize(ArrayIndex newSize) {
if (newSize == 0) if (newSize == 0)
clear(); clear();
else if (newSize > oldSize) else if (newSize > oldSize)
this->operator[](newSize - 1); for (ArrayIndex i = oldSize; i < newSize; ++i)
(*this)[i];
else { else {
for (ArrayIndex index = newSize; index < oldSize; ++index) { for (ArrayIndex index = newSize; index < oldSize; ++index) {
value_.map_->erase(index); value_.map_->erase(index);
@@ -3781,14 +3788,15 @@ bool Value::isObject() const { return type() == objectValue; }
Value::Comments::Comments(const Comments& that) Value::Comments::Comments(const Comments& that)
: ptr_{cloneUnique(that.ptr_)} {} : ptr_{cloneUnique(that.ptr_)} {}
Value::Comments::Comments(Comments&& that) : ptr_{std::move(that.ptr_)} {} Value::Comments::Comments(Comments&& that) noexcept
: ptr_{std::move(that.ptr_)} {}
Value::Comments& Value::Comments::operator=(const Comments& that) { Value::Comments& Value::Comments::operator=(const Comments& that) {
ptr_ = cloneUnique(that.ptr_); ptr_ = cloneUnique(that.ptr_);
return *this; return *this;
} }
Value::Comments& Value::Comments::operator=(Comments&& that) { Value::Comments& Value::Comments::operator=(Comments&& that) noexcept {
ptr_ = std::move(that.ptr_); ptr_ = std::move(that.ptr_);
return *this; return *this;
} }
@@ -3804,13 +3812,11 @@ String Value::Comments::get(CommentPlacement slot) const {
} }
void Value::Comments::set(CommentPlacement slot, String comment) { void Value::Comments::set(CommentPlacement slot, String comment) {
if (!ptr_) { if (slot >= CommentPlacement::numberOfCommentPlacement)
return;
if (!ptr_)
ptr_ = std::unique_ptr<Array>(new Array()); ptr_ = std::unique_ptr<Array>(new Array());
} (*ptr_)[slot] = std::move(comment);
// check comments array boundry.
if (slot < CommentPlacement::numberOfCommentPlacement) {
(*ptr_)[slot] = std::move(comment);
}
} }
void Value::setComment(String comment, CommentPlacement placement) { void Value::setComment(String comment, CommentPlacement placement) {
@@ -4124,7 +4130,7 @@ Value& Path::make(Value& root) const {
#if !defined(isnan) #if !defined(isnan)
// IEEE standard states that NaN values will not compare to themselves // IEEE standard states that NaN values will not compare to themselves
#define isnan(x) (x != x) #define isnan(x) ((x) != (x))
#endif #endif
#if !defined(__APPLE__) #if !defined(__APPLE__)
@@ -4210,16 +4216,18 @@ String valueToString(double value, bool useSpecialFloats,
buffer.erase(fixNumericLocale(buffer.begin(), buffer.end()), buffer.end()); buffer.erase(fixNumericLocale(buffer.begin(), buffer.end()), buffer.end());
// strip the zero padding from the right
if (precisionType == PrecisionType::decimalPlaces) {
buffer.erase(fixZerosInTheEnd(buffer.begin(), buffer.end()), buffer.end());
}
// try to ensure we preserve the fact that this was given to us as a double on // try to ensure we preserve the fact that this was given to us as a double on
// input // input
if (buffer.find('.') == buffer.npos && buffer.find('e') == buffer.npos) { if (buffer.find('.') == buffer.npos && buffer.find('e') == buffer.npos) {
buffer += ".0"; buffer += ".0";
} }
// strip the zero padding from the right
if (precisionType == PrecisionType::decimalPlaces) {
buffer.erase(fixZerosInTheEnd(buffer.begin(), buffer.end(), precision),
buffer.end());
}
return buffer; return buffer;
} }
} // namespace } // namespace
@@ -4231,11 +4239,11 @@ String valueToString(double value, unsigned int precision,
String valueToString(bool value) { return value ? "true" : "false"; } String valueToString(bool value) { return value ? "true" : "false"; }
static bool isAnyCharRequiredQuoting(char const* s, size_t n) { static bool doesAnyCharRequireEscaping(char const* s, size_t n) {
assert(s || !n); assert(s || !n);
return std::any_of(s, s + n, [](unsigned char c) { return std::any_of(s, s + n, [](unsigned char c) {
return c == '\\' || c == '"' || !std::isprint(c); return c == '\\' || c == '"' || c < 0x20 || c > 0x7F;
}); });
} }
@@ -4326,12 +4334,12 @@ static void appendHex(String& result, unsigned ch) {
result.append("\\u").append(toHex16Bit(ch)); result.append("\\u").append(toHex16Bit(ch));
} }
static String valueToQuotedStringN(const char* value, unsigned length, static String valueToQuotedStringN(const char* value, size_t length,
bool emitUTF8 = false) { bool emitUTF8 = false) {
if (value == nullptr) if (value == nullptr)
return ""; return "";
if (!isAnyCharRequiredQuoting(value, length)) if (!doesAnyCharRequireEscaping(value, length))
return String("\"") + value + "\""; return String("\"") + value + "\"";
// We have to walk value and escape any special characters. // We have to walk value and escape any special characters.
// Appending to String is not efficient, but this should be rare. // Appending to String is not efficient, but this should be rare.
@@ -4404,7 +4412,7 @@ static String valueToQuotedStringN(const char* value, unsigned length,
} }
String valueToQuotedString(const char* value) { String valueToQuotedString(const char* value) {
return valueToQuotedStringN(value, static_cast<unsigned int>(strlen(value))); return valueToQuotedStringN(value, strlen(value));
} }
// Class Writer // Class Writer
@@ -4453,7 +4461,7 @@ void FastWriter::writeValue(const Value& value) {
char const* end; char const* end;
bool ok = value.getString(&str, &end); bool ok = value.getString(&str, &end);
if (ok) if (ok)
document_ += valueToQuotedStringN(str, static_cast<unsigned>(end - str)); document_ += valueToQuotedStringN(str, static_cast<size_t>(end - str));
break; break;
} }
case booleanValue: case booleanValue:
@@ -4476,8 +4484,7 @@ void FastWriter::writeValue(const Value& value) {
const String& name = *it; const String& name = *it;
if (it != members.begin()) if (it != members.begin())
document_ += ','; document_ += ',';
document_ += valueToQuotedStringN(name.data(), document_ += valueToQuotedStringN(name.data(), name.length());
static_cast<unsigned>(name.length()));
document_ += yamlCompatibilityEnabled_ ? ": " : ":"; document_ += yamlCompatibilityEnabled_ ? ": " : ":";
writeValue(value[name]); writeValue(value[name]);
} }
@@ -4522,7 +4529,7 @@ void StyledWriter::writeValue(const Value& value) {
char const* end; char const* end;
bool ok = value.getString(&str, &end); bool ok = value.getString(&str, &end);
if (ok) if (ok)
pushValue(valueToQuotedStringN(str, static_cast<unsigned>(end - str))); pushValue(valueToQuotedStringN(str, static_cast<size_t>(end - str)));
else else
pushValue(""); pushValue("");
break; break;
@@ -4563,7 +4570,7 @@ void StyledWriter::writeValue(const Value& value) {
} }
void StyledWriter::writeArrayValue(const Value& value) { void StyledWriter::writeArrayValue(const Value& value) {
unsigned size = value.size(); size_t size = value.size();
if (size == 0) if (size == 0)
pushValue("[]"); pushValue("[]");
else { else {
@@ -4572,7 +4579,7 @@ void StyledWriter::writeArrayValue(const Value& value) {
writeWithIndent("["); writeWithIndent("[");
indent(); indent();
bool hasChildValue = !childValues_.empty(); bool hasChildValue = !childValues_.empty();
unsigned index = 0; ArrayIndex index = 0;
for (;;) { for (;;) {
const Value& childValue = value[index]; const Value& childValue = value[index];
writeCommentBeforeValue(childValue); writeCommentBeforeValue(childValue);
@@ -4595,7 +4602,7 @@ void StyledWriter::writeArrayValue(const Value& value) {
{ {
assert(childValues_.size() == size); assert(childValues_.size() == size);
document_ += "[ "; document_ += "[ ";
for (unsigned index = 0; index < size; ++index) { for (size_t index = 0; index < size; ++index) {
if (index > 0) if (index > 0)
document_ += ", "; document_ += ", ";
document_ += childValues_[index]; document_ += childValues_[index];
@@ -4740,7 +4747,7 @@ void StyledStreamWriter::writeValue(const Value& value) {
char const* end; char const* end;
bool ok = value.getString(&str, &end); bool ok = value.getString(&str, &end);
if (ok) if (ok)
pushValue(valueToQuotedStringN(str, static_cast<unsigned>(end - str))); pushValue(valueToQuotedStringN(str, static_cast<size_t>(end - str)));
else else
pushValue(""); pushValue("");
break; break;
@@ -5014,8 +5021,8 @@ void BuiltStyledStreamWriter::writeValue(Value const& value) {
char const* end; char const* end;
bool ok = value.getString(&str, &end); bool ok = value.getString(&str, &end);
if (ok) if (ok)
pushValue(valueToQuotedStringN(str, static_cast<unsigned>(end - str), pushValue(
emitUTF8_)); valueToQuotedStringN(str, static_cast<size_t>(end - str), emitUTF8_));
else else
pushValue(""); pushValue("");
break; break;
@@ -5038,8 +5045,8 @@ void BuiltStyledStreamWriter::writeValue(Value const& value) {
String const& name = *it; String const& name = *it;
Value const& childValue = value[name]; Value const& childValue = value[name];
writeCommentBeforeValue(childValue); writeCommentBeforeValue(childValue);
writeWithIndent(valueToQuotedStringN( writeWithIndent(
name.data(), static_cast<unsigned>(name.length()), emitUTF8_)); valueToQuotedStringN(name.data(), name.length(), emitUTF8_));
*sout_ << colonSymbol_; *sout_ << colonSymbol_;
writeValue(childValue); writeValue(childValue);
if (++it == members.end()) { if (++it == members.end()) {
@@ -5273,7 +5280,7 @@ bool StreamWriterBuilder::validate(Json::Value* invalid) const {
if (valid_keys.count(key)) if (valid_keys.count(key))
continue; continue;
if (invalid) if (invalid)
(*invalid)[std::move(key)] = *si; (*invalid)[key] = *si;
else else
return false; return false;
} }