aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2021-12-08 02:12:30 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2021-12-08 02:12:30 +0000
commit22d33955e4c2525e659f729c9f02afe09183b107 (patch)
tree5015100cb583ba035d40917cc21d3846f42adc89 /src
parent7d7d096b3577b5bbadfc1704baab022e17aa111f (diff)
parente898ee304bccb30ce7553b4f45979b78932da5fc (diff)
downloadjsoncpp-android13-mainline-adservices-release.tar.gz
Merge "Upgrade jsoncpp to 1.9.5" am: d537ece935 am: 90de0e3376 am: 807b6eed29 am: e898ee304bt_frc_odp_330442040t_frc_odp_330442000t_frc_con_330443020t_frc_cbr_330443000t_frc_ase_330444010t_frc_art_330443060t_frc_adb_330444000frc_340821000frc_340819280frc_340819220frc_340819190frc_340819030frc_340819020frc_340819010frc_340818170frc_340818110android-vts-14.0_r4android-vts-14.0_r3android-vts-14.0_r2android-vts-14.0_r1android-u-beta-1-gplandroid-security-14.0.0_r9android-security-14.0.0_r8android-security-14.0.0_r7android-security-14.0.0_r6android-security-14.0.0_r5android-security-14.0.0_r4android-security-14.0.0_r3android-security-14.0.0_r2android-security-14.0.0_r1android-platform-14.0.0_r8android-platform-14.0.0_r7android-platform-14.0.0_r6android-platform-14.0.0_r5android-platform-14.0.0_r4android-platform-14.0.0_r3android-platform-14.0.0_r2android-platform-14.0.0_r1android-cts-14.0_r4android-cts-14.0_r3android-cts-14.0_r2android-cts-14.0_r1android-14.0.0_r9android-14.0.0_r8android-14.0.0_r7android-14.0.0_r6android-14.0.0_r5android-14.0.0_r45android-14.0.0_r44android-14.0.0_r43android-14.0.0_r42android-14.0.0_r41android-14.0.0_r40android-14.0.0_r4android-14.0.0_r39android-14.0.0_r38android-14.0.0_r3android-14.0.0_r28android-14.0.0_r27android-14.0.0_r26android-14.0.0_r25android-14.0.0_r24android-14.0.0_r23android-14.0.0_r22android-14.0.0_r21android-14.0.0_r20android-14.0.0_r2android-14.0.0_r19android-14.0.0_r18android-14.0.0_r17android-14.0.0_r16android-14.0.0_r15android-14.0.0_r14android-14.0.0_r13android-14.0.0_r12android-14.0.0_r11android-14.0.0_r10android-14.0.0_r1android-13.0.0_r83android-13.0.0_r82android-13.0.0_r81android-13.0.0_r80android-13.0.0_r79android-13.0.0_r78android-13.0.0_r77android-13.0.0_r76android-13.0.0_r75android-13.0.0_r74android-13.0.0_r73android-13.0.0_r72android-13.0.0_r71android-13.0.0_r70android-13.0.0_r69android-13.0.0_r68android-13.0.0_r67android-13.0.0_r66android-13.0.0_r65android-13.0.0_r64android-13.0.0_r63android-13.0.0_r62android-13.0.0_r61android-13.0.0_r60android-13.0.0_r59android-13.0.0_r58android-13.0.0_r57android-13.0.0_r56android-13.0.0_r55android-13.0.0_r54android-13.0.0_r53android-13.0.0_r52android-13.0.0_r51android-13.0.0_r50android-13.0.0_r49android-13.0.0_r48android-13.0.0_r47android-13.0.0_r46android-13.0.0_r45android-13.0.0_r44android-13.0.0_r43android-13.0.0_r42android-13.0.0_r41android-13.0.0_r40android-13.0.0_r39android-13.0.0_r38android-13.0.0_r37android-13.0.0_r36android-13.0.0_r35android-13.0.0_r34android-13.0.0_r33android-13.0.0_r32android-13.0.0_r30android-13.0.0_r29android-13.0.0_r28android-13.0.0_r27android-13.0.0_r24android-13.0.0_r23android-13.0.0_r22android-13.0.0_r21android-13.0.0_r20android-13.0.0_r19android-13.0.0_r18android-13.0.0_r17android-13.0.0_r16aml_uwb_341710010aml_uwb_341513070aml_uwb_341511050aml_uwb_341310300aml_uwb_341310030aml_uwb_341111010aml_uwb_341011000aml_uwb_331910010aml_uwb_331820070aml_uwb_331613010aml_uwb_331611010aml_uwb_331410010aml_uwb_331310030aml_uwb_331115000aml_uwb_331015040aml_uwb_330810010aml_tz5_341510070aml_tz5_341510050aml_tz5_341510010aml_tz4_332714070aml_tz4_332714050aml_tz4_332714010aml_tz4_331910000aml_tz4_331314030aml_tz4_331314020aml_tz4_331314010aml_tz4_331012050aml_tz4_331012040aml_tz4_331012000aml_rkp_341510000aml_rkp_341311000aml_rkp_341114000aml_rkp_341015010aml_rkp_341012000aml_odp_341717000aml_odp_341610000aml_hef_341717050aml_hef_341613000aml_hef_341512030aml_hef_341415040aml_hef_341311010aml_hef_341114030aml_go_wif_330911000aml_go_uwb_330912000aml_go_tz4_330912000aml_go_tet_330914010aml_go_swc_330913000aml_go_sta_330911000aml_go_sdk_330810000aml_go_sch_330911000aml_go_res_330912000aml_go_per_330912000aml_go_odp_330913000aml_go_odp_330912000aml_go_neu_330912000aml_go_net_330913000aml_go_mpr_330912000aml_go_ase_330913000aml_go_ads_330915100aml_go_ads_330915000aml_go_ads_330913000aml_go_adb_330913000aml_cfg_341510000aml_ase_341510000aml_ase_341410000aml_ase_341310010aml_ase_341113000aml_ase_340913000aml_ase_331311020aml_ase_331112000aml_ase_331011020aml_ads_341720000aml_ads_341615050aml_ads_341517040aml_ads_341413000aml_ads_341316030aml_ads_341131050aml_ads_341027030aml_ads_340915050aml_ads_331920180aml_ads_331814200aml_ads_331710270aml_ads_331611190aml_ads_331511020aml_ads_331418080aml_ads_331131000main-16k-with-phonesmain-16kandroid14-tests-releaseandroid14-security-releaseandroid14-s2-releaseandroid14-s1-releaseandroid14-releaseandroid14-qpr1-s2-releaseandroid14-qpr1-releaseandroid14-platform-releaseandroid14-mainline-uwb-releaseandroid14-mainline-healthfitness-releaseandroid14-mainline-appsearch-releaseandroid14-mainline-adservices-releaseandroid14-gsiandroid14-devandroid14-d2-s5-releaseandroid14-d2-s4-releaseandroid14-d2-s3-releaseandroid14-d2-s2-releaseandroid14-d2-s1-releaseandroid14-d2-releaseandroid14-d1-s7-releaseandroid14-d1-s6-releaseandroid14-d1-s5-releaseandroid14-d1-s4-releaseandroid14-d1-s3-releaseandroid14-d1-s2-releaseandroid14-d1-s1-releaseandroid14-d1-releaseandroid13-qpr3-s9-releaseandroid13-qpr3-s8-releaseandroid13-qpr3-s7-releaseandroid13-qpr3-s6-releaseandroid13-qpr3-s5-releaseandroid13-qpr3-s4-releaseandroid13-qpr3-s3-releaseandroid13-qpr3-s2-releaseandroid13-qpr3-s14-releaseandroid13-qpr3-s13-releaseandroid13-qpr3-s12-releaseandroid13-qpr3-s11-releaseandroid13-qpr3-s10-releaseandroid13-qpr3-s1-releaseandroid13-qpr3-releaseandroid13-qpr3-c-s8-releaseandroid13-qpr3-c-s7-releaseandroid13-qpr3-c-s6-releaseandroid13-qpr3-c-s5-releaseandroid13-qpr3-c-s4-releaseandroid13-qpr3-c-s3-releaseandroid13-qpr3-c-s2-releaseandroid13-qpr3-c-s12-releaseandroid13-qpr3-c-s11-releaseandroid13-qpr3-c-s10-releaseandroid13-qpr3-c-s1-releaseandroid13-qpr2-s9-releaseandroid13-qpr2-s8-releaseandroid13-qpr2-s7-releaseandroid13-qpr2-s6-releaseandroid13-qpr2-s5-releaseandroid13-qpr2-s3-releaseandroid13-qpr2-s2-releaseandroid13-qpr2-s12-releaseandroid13-qpr2-s11-releaseandroid13-qpr2-s10-releaseandroid13-qpr2-s1-releaseandroid13-qpr2-releaseandroid13-qpr2-b-s1-releaseandroid13-qpr1-s8-releaseandroid13-qpr1-s7-releaseandroid13-qpr1-s6-releaseandroid13-qpr1-s5-releaseandroid13-qpr1-s4-releaseandroid13-qpr1-s3-releaseandroid13-qpr1-s2-releaseandroid13-qpr1-s1-releaseandroid13-qpr1-releaseandroid13-mainline-uwb-releaseandroid13-mainline-tzdata4-releaseandroid13-mainline-go-wifi-releaseandroid13-mainline-go-uwb-releaseandroid13-mainline-go-tzdata4-releaseandroid13-mainline-go-tethering-releaseandroid13-mainline-go-sdkext-releaseandroid13-mainline-go-scheduling-releaseandroid13-mainline-go-resolv-releaseandroid13-mainline-go-permission-releaseandroid13-mainline-go-os-statsd-releaseandroid13-mainline-go-odp-releaseandroid13-mainline-go-neuralnetworks-releaseandroid13-mainline-go-networking-releaseandroid13-mainline-go-mediaprovider-releaseandroid13-mainline-go-media-swcodec-releaseandroid13-mainline-go-appsearch-releaseandroid13-mainline-go-adservices-releaseandroid13-mainline-go-adbd-releaseandroid13-mainline-appsearch-releaseandroid13-mainline-adservices-releaseandroid13-frc-odp-releaseandroid13-frc-conscrypt-releaseandroid13-frc-cellbroadcast-releaseandroid13-frc-art-releaseandroid13-frc-adbd-releaseandroid13-devandroid13-d4-s2-releaseandroid13-d4-s1-releaseandroid13-d4-releaseandroid13-d3-s1-releaseandroid13-d2-releaseaml_tz5_341510010aml_tz4_332714010
Original change: https://android-review.googlesource.com/c/platform/external/jsoncpp/+/1913907 Change-Id: I427d411cdae47a90cbf6d89a8f86a1e28298b913
Diffstat (limited to 'src')
-rw-r--r--src/jsontestrunner/main.cpp1
-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
-rw-r--r--src/test_lib_json/main.cpp50
7 files changed, 121 insertions, 78 deletions
diff --git a/src/jsontestrunner/main.cpp b/src/jsontestrunner/main.cpp
index 3452c59..df717ff 100644
--- a/src/jsontestrunner/main.cpp
+++ b/src/jsontestrunner/main.cpp
@@ -335,6 +335,7 @@ int main(int argc, const char* argv[]) {
std::cerr << "Unhandled exception:" << std::endl << e.what() << std::endl;
return 1;
}
+ return 0;
}
#if defined(__GNUC__)
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;
}
diff --git a/src/test_lib_json/main.cpp b/src/test_lib_json/main.cpp
index 991c247..d0f5364 100644
--- a/src/test_lib_json/main.cpp
+++ b/src/test_lib_json/main.cpp
@@ -12,6 +12,7 @@
#include "fuzz.h"
#include "jsontest.h"
+#include <algorithm>
#include <cmath>
#include <cstring>
#include <functional>
@@ -24,6 +25,7 @@
#include <memory>
#include <sstream>
#include <string>
+#include <vector>
using CharReaderPtr = std::unique_ptr<Json::CharReader>;
@@ -347,6 +349,17 @@ JSONTEST_FIXTURE_LOCAL(ValueTest, resizeArray) {
JSONTEST_ASSERT_EQUAL(array.size(), 0);
}
}
+
+JSONTEST_FIXTURE_LOCAL(ValueTest, resizePopulatesAllMissingElements) {
+ Json::ArrayIndex n = 10;
+ Json::Value v;
+ v.resize(n);
+ JSONTEST_ASSERT_EQUAL(n, v.size());
+ JSONTEST_ASSERT_EQUAL(n, std::distance(v.begin(), v.end()));
+ for (const Json::Value& e : v)
+ JSONTEST_ASSERT_EQUAL(e, Json::Value{});
+}
+
JSONTEST_FIXTURE_LOCAL(ValueTest, getArrayValue) {
Json::Value array;
for (Json::ArrayIndex i = 0; i < 5; i++)
@@ -2005,6 +2018,34 @@ JSONTEST_FIXTURE_LOCAL(ValueTest, precision) {
result = Json::writeString(b, v);
JSONTEST_ASSERT_STRING_EQUAL(expected, result);
+ b.settings_["precision"] = 0;
+ b.settings_["precisionType"] = "decimal";
+ v = 123.56345694873740545068;
+ expected = "124";
+ result = Json::writeString(b, v);
+ JSONTEST_ASSERT_STRING_EQUAL(expected, result);
+
+ b.settings_["precision"] = 1;
+ b.settings_["precisionType"] = "decimal";
+ v = 1230.001;
+ expected = "1230.0";
+ result = Json::writeString(b, v);
+ JSONTEST_ASSERT_STRING_EQUAL(expected, result);
+
+ b.settings_["precision"] = 0;
+ b.settings_["precisionType"] = "decimal";
+ v = 1230.001;
+ expected = "1230";
+ result = Json::writeString(b, v);
+ JSONTEST_ASSERT_STRING_EQUAL(expected, result);
+
+ b.settings_["precision"] = 0;
+ b.settings_["precisionType"] = "decimal";
+ v = 1231.5;
+ expected = "1232";
+ result = Json::writeString(b, v);
+ JSONTEST_ASSERT_STRING_EQUAL(expected, result);
+
b.settings_["precision"] = 10;
b.settings_["precisionType"] = "decimal";
v = 0.23300000;
@@ -3916,6 +3957,15 @@ JSONTEST_FIXTURE_LOCAL(MemberTemplateIs, BehavesSameAsNamedIs) {
}
}
+class VersionTest : public JsonTest::TestCase {};
+
+JSONTEST_FIXTURE_LOCAL(VersionTest, VersionNumbersMatch) {
+ std::ostringstream vstr;
+ vstr << JSONCPP_VERSION_MAJOR << '.' << JSONCPP_VERSION_MINOR << '.'
+ << JSONCPP_VERSION_PATCH;
+ JSONTEST_ASSERT_EQUAL(vstr.str(), std::string(JSONCPP_VERSION_STRING));
+}
+
#if defined(__GNUC__)
#pragma GCC diagnostic pop
#endif