aboutsummaryrefslogtreecommitdiff
path: root/src/lib_json
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2021-12-07 09:43:38 -0800
committerElliott Hughes <enh@google.com>2021-12-07 09:43:38 -0800
commit1601ea0835d235a9f5c498e637e2b559da58e17b (patch)
tree5015100cb583ba035d40917cc21d3846f42adc89 /src/lib_json
parent51fd5436a52846f49fc68197a55304025e86f25b (diff)
downloadjsoncpp-1601ea0835d235a9f5c498e637e2b559da58e17b.tar.gz
Upgrade jsoncpp to 1.9.5
Test: make Change-Id: I0be1376ee1502a2fd9db2733b503f30f2777a02a
Diffstat (limited to 'src/lib_json')
-rw-r--r--src/lib_json/CMakeLists.txt64
-rw-r--r--src/lib_json/json_reader.cpp5
-rw-r--r--src/lib_json/json_tool.h10
-rw-r--r--src/lib_json/json_value.cpp26
-rw-r--r--src/lib_json/json_writer.cpp43
5 files changed, 70 insertions, 78 deletions
diff --git a/src/lib_json/CMakeLists.txt b/src/lib_json/CMakeLists.txt
index af26476..b7596e8 100644
--- a/src/lib_json/CMakeLists.txt
+++ b/src/lib_json/CMakeLists.txt
@@ -11,20 +11,10 @@ include(CheckCXXSymbolExists)
check_include_file_cxx(clocale HAVE_CLOCALE)
check_cxx_symbol_exists(localeconv clocale HAVE_LOCALECONV)
-if(CMAKE_VERSION VERSION_LESS 3.0.0)
- # The "LANGUAGE CXX" parameter is not supported in CMake versions below 3,
- # so the C compiler and header has to be used.
- check_include_file(locale.h HAVE_LOCALE_H)
- set(CMAKE_EXTRA_INCLUDE_FILES locale.h)
- check_type_size("struct lconv" LCONV_SIZE)
- unset(CMAKE_EXTRA_INCLUDE_FILES)
- check_struct_has_member("struct lconv" decimal_point locale.h HAVE_DECIMAL_POINT)
-else()
- set(CMAKE_EXTRA_INCLUDE_FILES clocale)
- check_type_size(lconv LCONV_SIZE LANGUAGE CXX)
- unset(CMAKE_EXTRA_INCLUDE_FILES)
- check_struct_has_member(lconv decimal_point clocale HAVE_DECIMAL_POINT LANGUAGE CXX)
-endif()
+set(CMAKE_EXTRA_INCLUDE_FILES clocale)
+check_type_size(lconv LCONV_SIZE LANGUAGE CXX)
+unset(CMAKE_EXTRA_INCLUDE_FILES)
+check_struct_has_member(lconv decimal_point clocale HAVE_DECIMAL_POINT LANGUAGE CXX)
if(NOT (HAVE_CLOCALE AND HAVE_LCONV_SIZE AND HAVE_DECIMAL_POINT AND HAVE_LOCALECONV))
message(WARNING "Locale functionality is not supported")
@@ -129,7 +119,7 @@ if(BUILD_SHARED_LIBS)
OUTPUT_NAME jsoncpp
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_SOVERSION}
- POSITION_INDEPENDENT_CODE ON
+ POSITION_INDEPENDENT_CODE ${BUILD_SHARED_LIBS}
)
# Set library's runtime search path on OSX
@@ -139,13 +129,11 @@ if(BUILD_SHARED_LIBS)
target_compile_features(${SHARED_LIB} PUBLIC ${REQUIRED_FEATURES})
- if(NOT CMAKE_VERSION VERSION_LESS 2.8.11)
- target_include_directories(${SHARED_LIB} PUBLIC
- $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
- $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/${JSONCPP_INCLUDE_DIR}>
- $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include/json>
- )
- endif()
+ target_include_directories(${SHARED_LIB} PUBLIC
+ $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
+ $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/${JSONCPP_INCLUDE_DIR}>
+ $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include/json>
+ )
list(APPEND CMAKE_TARGETS ${SHARED_LIB})
endif()
@@ -156,7 +144,11 @@ if(BUILD_STATIC_LIBS)
# avoid name clashes on windows as the shared import lib is alse named jsoncpp.lib
if(NOT DEFINED STATIC_SUFFIX AND BUILD_SHARED_LIBS)
- set(STATIC_SUFFIX "_static")
+ if (MSVC)
+ set(STATIC_SUFFIX "_static")
+ else()
+ set(STATIC_SUFFIX "")
+ endif()
endif()
set_target_properties(${STATIC_LIB} PROPERTIES
@@ -171,13 +163,11 @@ if(BUILD_STATIC_LIBS)
target_compile_features(${STATIC_LIB} PUBLIC ${REQUIRED_FEATURES})
- if(NOT CMAKE_VERSION VERSION_LESS 2.8.11)
- target_include_directories(${STATIC_LIB} PUBLIC
- $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
- $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/${JSONCPP_INCLUDE_DIR}>
- $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include/json>
- )
- endif()
+ target_include_directories(${STATIC_LIB} PUBLIC
+ $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
+ $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/${JSONCPP_INCLUDE_DIR}>
+ $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include/json>
+ )
list(APPEND CMAKE_TARGETS ${STATIC_LIB})
endif()
@@ -190,7 +180,7 @@ if(BUILD_OBJECT_LIBS)
OUTPUT_NAME jsoncpp
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_SOVERSION}
- POSITION_INDEPENDENT_CODE ON
+ POSITION_INDEPENDENT_CODE ${BUILD_SHARED_LIBS}
)
# Set library's runtime search path on OSX
@@ -200,13 +190,11 @@ if(BUILD_OBJECT_LIBS)
target_compile_features(${OBJECT_LIB} PUBLIC ${REQUIRED_FEATURES})
- if(NOT CMAKE_VERSION VERSION_LESS 2.8.11)
- target_include_directories(${OBJECT_LIB} PUBLIC
- $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
- $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/${JSONCPP_INCLUDE_DIR}>
- $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include/json>
- )
- endif()
+ target_include_directories(${OBJECT_LIB} PUBLIC
+ $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
+ $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/${JSONCPP_INCLUDE_DIR}>
+ $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include/json>
+ )
list(APPEND CMAKE_TARGETS ${OBJECT_LIB})
endif()
diff --git a/src/lib_json/json_reader.cpp b/src/lib_json/json_reader.cpp
index 19922a8..a6a3f4e 100644
--- a/src/lib_json/json_reader.cpp
+++ b/src/lib_json/json_reader.cpp
@@ -104,8 +104,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);
}
@@ -1921,7 +1920,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;
}
diff --git a/src/lib_json/json_tool.h b/src/lib_json/json_tool.h
index 2d7b7d9..b952c19 100644
--- a/src/lib_json/json_tool.h
+++ b/src/lib_json/json_tool.h
@@ -116,14 +116,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
* 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) {
if (*(end - 1) != '0') {
return end;
}
// Don't delete the last zero before the decimal point.
- if (begin != (end - 1) && *(end - 2) == '.') {
- return end;
+ if (begin != (end - 1) && begin != (end - 2) && *(end - 2) == '.') {
+ if (precision) {
+ return end;
+ }
+ return end - 2;
}
}
return end;
diff --git a/src/lib_json/json_value.cpp b/src/lib_json/json_value.cpp
index 0872ff5..aa2b744 100644
--- a/src/lib_json/json_value.cpp
+++ b/src/lib_json/json_value.cpp
@@ -259,7 +259,7 @@ Value::CZString::CZString(const CZString& other) {
storage_.length_ = other.storage_.length_;
}
-Value::CZString::CZString(CZString&& other)
+Value::CZString::CZString(CZString&& other) noexcept
: cstr_(other.cstr_), index_(other.index_) {
other.cstr_ = nullptr;
}
@@ -285,7 +285,7 @@ Value::CZString& Value::CZString::operator=(const CZString& other) {
return *this;
}
-Value::CZString& Value::CZString::operator=(CZString&& other) {
+Value::CZString& Value::CZString::operator=(CZString&& other) noexcept {
cstr_ = other.cstr_;
index_ = other.index_;
other.cstr_ = nullptr;
@@ -433,7 +433,7 @@ Value::Value(const Value& other) {
dupMeta(other);
}
-Value::Value(Value&& other) {
+Value::Value(Value&& other) noexcept {
initBasic(nullValue);
swap(other);
}
@@ -448,7 +448,7 @@ Value& Value::operator=(const Value& other) {
return *this;
}
-Value& Value::operator=(Value&& other) {
+Value& Value::operator=(Value&& other) noexcept {
other.swap(*this);
return *this;
}
@@ -912,7 +912,8 @@ void Value::resize(ArrayIndex newSize) {
if (newSize == 0)
clear();
else if (newSize > oldSize)
- this->operator[](newSize - 1);
+ for (ArrayIndex i = oldSize; i < newSize; ++i)
+ (*this)[i];
else {
for (ArrayIndex index = newSize; index < oldSize; ++index) {
value_.map_->erase(index);
@@ -1373,14 +1374,15 @@ bool Value::isObject() const { return type() == objectValue; }
Value::Comments::Comments(const Comments& that)
: 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) {
ptr_ = cloneUnique(that.ptr_);
return *this;
}
-Value::Comments& Value::Comments::operator=(Comments&& that) {
+Value::Comments& Value::Comments::operator=(Comments&& that) noexcept {
ptr_ = std::move(that.ptr_);
return *this;
}
@@ -1396,13 +1398,11 @@ String Value::Comments::get(CommentPlacement slot) const {
}
void Value::Comments::set(CommentPlacement slot, String comment) {
- if (!ptr_) {
+ if (slot >= CommentPlacement::numberOfCommentPlacement)
+ return;
+ if (!ptr_)
ptr_ = std::unique_ptr<Array>(new Array());
- }
- // check comments array boundry.
- if (slot < CommentPlacement::numberOfCommentPlacement) {
- (*ptr_)[slot] = std::move(comment);
- }
+ (*ptr_)[slot] = std::move(comment);
}
void Value::setComment(String comment, CommentPlacement placement) {
diff --git a/src/lib_json/json_writer.cpp b/src/lib_json/json_writer.cpp
index 8bf02db..0dd160e 100644
--- a/src/lib_json/json_writer.cpp
+++ b/src/lib_json/json_writer.cpp
@@ -68,7 +68,7 @@
#if !defined(isnan)
// IEEE standard states that NaN values will not compare to themselves
-#define isnan(x) (x != x)
+#define isnan(x) ((x) != (x))
#endif
#if !defined(__APPLE__)
@@ -154,16 +154,18 @@ String valueToString(double value, bool useSpecialFloats,
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
// input
if (buffer.find('.') == buffer.npos && buffer.find('e') == buffer.npos) {
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;
}
} // namespace
@@ -270,7 +272,7 @@ static void appendHex(String& result, unsigned 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) {
if (value == nullptr)
return "";
@@ -348,7 +350,7 @@ static String valueToQuotedStringN(const char* value, unsigned length,
}
String valueToQuotedString(const char* value) {
- return valueToQuotedStringN(value, static_cast<unsigned int>(strlen(value)));
+ return valueToQuotedStringN(value, strlen(value));
}
// Class Writer
@@ -397,7 +399,7 @@ void FastWriter::writeValue(const Value& value) {
char const* end;
bool ok = value.getString(&str, &end);
if (ok)
- document_ += valueToQuotedStringN(str, static_cast<unsigned>(end - str));
+ document_ += valueToQuotedStringN(str, static_cast<size_t>(end - str));
break;
}
case booleanValue:
@@ -420,8 +422,7 @@ void FastWriter::writeValue(const Value& value) {
const String& name = *it;
if (it != members.begin())
document_ += ',';
- document_ += valueToQuotedStringN(name.data(),
- static_cast<unsigned>(name.length()));
+ document_ += valueToQuotedStringN(name.data(), name.length());
document_ += yamlCompatibilityEnabled_ ? ": " : ":";
writeValue(value[name]);
}
@@ -466,7 +467,7 @@ void StyledWriter::writeValue(const Value& value) {
char const* end;
bool ok = value.getString(&str, &end);
if (ok)
- pushValue(valueToQuotedStringN(str, static_cast<unsigned>(end - str)));
+ pushValue(valueToQuotedStringN(str, static_cast<size_t>(end - str)));
else
pushValue("");
break;
@@ -507,7 +508,7 @@ void StyledWriter::writeValue(const Value& value) {
}
void StyledWriter::writeArrayValue(const Value& value) {
- unsigned size = value.size();
+ size_t size = value.size();
if (size == 0)
pushValue("[]");
else {
@@ -516,7 +517,7 @@ void StyledWriter::writeArrayValue(const Value& value) {
writeWithIndent("[");
indent();
bool hasChildValue = !childValues_.empty();
- unsigned index = 0;
+ ArrayIndex index = 0;
for (;;) {
const Value& childValue = value[index];
writeCommentBeforeValue(childValue);
@@ -539,7 +540,7 @@ void StyledWriter::writeArrayValue(const Value& value) {
{
assert(childValues_.size() == size);
document_ += "[ ";
- for (unsigned index = 0; index < size; ++index) {
+ for (size_t index = 0; index < size; ++index) {
if (index > 0)
document_ += ", ";
document_ += childValues_[index];
@@ -684,7 +685,7 @@ void StyledStreamWriter::writeValue(const Value& value) {
char const* end;
bool ok = value.getString(&str, &end);
if (ok)
- pushValue(valueToQuotedStringN(str, static_cast<unsigned>(end - str)));
+ pushValue(valueToQuotedStringN(str, static_cast<size_t>(end - str)));
else
pushValue("");
break;
@@ -958,8 +959,8 @@ void BuiltStyledStreamWriter::writeValue(Value const& value) {
char const* end;
bool ok = value.getString(&str, &end);
if (ok)
- pushValue(valueToQuotedStringN(str, static_cast<unsigned>(end - str),
- emitUTF8_));
+ pushValue(
+ valueToQuotedStringN(str, static_cast<size_t>(end - str), emitUTF8_));
else
pushValue("");
break;
@@ -982,8 +983,8 @@ void BuiltStyledStreamWriter::writeValue(Value const& value) {
String const& name = *it;
Value const& childValue = value[name];
writeCommentBeforeValue(childValue);
- writeWithIndent(valueToQuotedStringN(
- name.data(), static_cast<unsigned>(name.length()), emitUTF8_));
+ writeWithIndent(
+ valueToQuotedStringN(name.data(), name.length(), emitUTF8_));
*sout_ << colonSymbol_;
writeValue(childValue);
if (++it == members.end()) {
@@ -1217,7 +1218,7 @@ bool StreamWriterBuilder::validate(Json::Value* invalid) const {
if (valid_keys.count(key))
continue;
if (invalid)
- (*invalid)[std::move(key)] = *si;
+ (*invalid)[key] = *si;
else
return false;
}