aboutsummaryrefslogtreecommitdiff
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
parent51fd5436a52846f49fc68197a55304025e86f25b (diff)
downloadjsoncpp-1601ea0835d235a9f5c498e637e2b559da58e17b.tar.gz
Upgrade jsoncpp to 1.9.5
Test: make Change-Id: I0be1376ee1502a2fd9db2733b503f30f2777a02a
-rw-r--r--.clang-tidy2
-rw-r--r--.gitignore5
-rw-r--r--.travis.yml6
-rwxr-xr-x.travis_scripts/meson_builder.sh2
-rwxr-xr-x.travis_scripts/run-clang-format.py2
-rwxr-xr-x.travis_scripts/run-clang-format.sh2
-rw-r--r--.travis_scripts/travis.before_install.osx.sh1
-rw-r--r--.travis_scripts/travis.install.linux.sh11
-rw-r--r--BUILD.bazel37
-rw-r--r--CMakeLists.txt35
-rw-r--r--CONTRIBUTING.md7
-rw-r--r--LICENSE14
-rw-r--r--METADATA14
-rw-r--r--appveyor.yml11
-rw-r--r--dev.makefile4
-rw-r--r--devtools/antglob.py2
-rw-r--r--devtools/fixeol.py4
-rw-r--r--devtools/licenseupdater.py4
-rw-r--r--doxybuild.py4
-rw-r--r--example/README.md4
-rw-r--r--example/readFromString/readFromString.cpp1
-rw-r--r--example/streamWrite/streamWrite.cpp1
-rw-r--r--get_version.pl5
-rw-r--r--include/PreventInBuildInstalls.cmake9
-rw-r--r--include/PreventInSourceBuilds.cmake45
-rw-r--r--include/json/allocator.h7
-rw-r--r--include/json/reader.h10
-rw-r--r--include/json/value.h18
-rw-r--r--include/json/version.h4
-rw-r--r--include/json/writer.h10
-rw-r--r--jsoncpp-namespaced-targets.cmake7
-rw-r--r--jsoncppConfig.cmake.in11
-rw-r--r--meson.build2
-rw-r--r--pkg-config/jsoncpp.pc.in2
-rwxr-xr-xreformat.sh1
-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
-rw-r--r--test/data/legacy_test_array_06.json2
-rw-r--r--test/data/legacy_test_complex_01.json22
-rw-r--r--test/data/legacy_test_object_03.json2
-rw-r--r--test/data/legacy_test_object_04.json2
-rw-r--r--test/data/legacy_test_preserve_comment_01.expected2
-rw-r--r--test/data/legacy_test_preserve_comment_01.json2
-rw-r--r--test/pyjsontestrunner.py8
49 files changed, 368 insertions, 175 deletions
diff --git a/.clang-tidy b/.clang-tidy
index be3d06a..99e914d 100644
--- a/.clang-tidy
+++ b/.clang-tidy
@@ -4,7 +4,7 @@ WarningsAsErrors: ''
HeaderFilterRegex: ''
AnalyzeTemporaryDtors: false
FormatStyle: none
-CheckOptions:
+CheckOptions:
- key: modernize-use-using.IgnoreMacros
value: '0'
...
diff --git a/.gitignore b/.gitignore
index 68f40b0..9682782 100644
--- a/.gitignore
+++ b/.gitignore
@@ -10,6 +10,7 @@
/libs/
/doc/doxyfile
/dist/
+/.cache/
# MSVC project files:
*.sln
@@ -30,6 +31,7 @@
CMakeFiles/
/pkg-config/jsoncpp.pc
jsoncpp_lib_static.dir/
+compile_commands.json
# In case someone runs cmake in the root-dir:
/CMakeCache.txt
@@ -50,3 +52,6 @@ jsoncpp_lib_static.dir/
# DS_Store
.DS_Store
+
+# temps
+/version
diff --git a/.travis.yml b/.travis.yml
index 0554dc9..23acd4e 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,5 +1,5 @@
# Build matrix / environment variables are explained on:
-# http://about.travis-ci.org/docs/user/build-configuration/
+# http://about.travis-ci.com/docs/user/build-configuration/
# This file can be validated on: http://www.yamllint.com/
# Or using the Ruby based travel command line tool:
# gem install travis --no-rdoc --no-ri
@@ -22,8 +22,6 @@ addons:
- clang-8
- valgrind
matrix:
- allow_failures:
- - os: osx
include:
- name: Mac clang meson static release testing
os: osx
@@ -44,6 +42,8 @@ matrix:
CC="clang"
LIB_TYPE=static
BUILD_TYPE=release
+ PYTHONUSERBASE="$(pwd)/LOCAL"
+ PATH="$PYTHONUSERBASE/bin:$PATH"
# before_install and install steps only needed for linux meson builds
before_install:
- source ./.travis_scripts/travis.before_install.${TRAVIS_OS_NAME}.sh
diff --git a/.travis_scripts/meson_builder.sh b/.travis_scripts/meson_builder.sh
index 1fdd8f6..bc74732 100755
--- a/.travis_scripts/meson_builder.sh
+++ b/.travis_scripts/meson_builder.sh
@@ -64,7 +64,7 @@ ninja --version
_COMPILER_NAME=`basename ${CXX}`
_BUILD_DIR_NAME="build-${BUILD_TYPE}_${LIB_TYPE}_${_COMPILER_NAME}"
-./.travis_scripts/run-clang-format.sh
+#./.travis_scripts/run-clang-format.sh
meson --fatal-meson-warnings --werror --buildtype ${BUILD_TYPE} --default-library ${LIB_TYPE} . "${_BUILD_DIR_NAME}"
ninja -v -j 2 -C "${_BUILD_DIR_NAME}"
diff --git a/.travis_scripts/run-clang-format.py b/.travis_scripts/run-clang-format.py
index 68179aa..605b5aa 100755
--- a/.travis_scripts/run-clang-format.py
+++ b/.travis_scripts/run-clang-format.py
@@ -353,4 +353,4 @@ def main():
if __name__ == '__main__':
- sys.exit(main()) \ No newline at end of file
+ sys.exit(main())
diff --git a/.travis_scripts/run-clang-format.sh b/.travis_scripts/run-clang-format.sh
index 9197284..ded76aa 100755
--- a/.travis_scripts/run-clang-format.sh
+++ b/.travis_scripts/run-clang-format.sh
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
-python $DIR/run-clang-format.py -r $DIR/../src/**/ $DIR/../include/**/ \ No newline at end of file
+python $DIR/run-clang-format.py -r $DIR/../src/**/ $DIR/../include/**/
diff --git a/.travis_scripts/travis.before_install.osx.sh b/.travis_scripts/travis.before_install.osx.sh
index 5d83c0c..e69de29 100644
--- a/.travis_scripts/travis.before_install.osx.sh
+++ b/.travis_scripts/travis.before_install.osx.sh
@@ -1 +0,0 @@
-# NOTHING TO DO HERE
diff --git a/.travis_scripts/travis.install.linux.sh b/.travis_scripts/travis.install.linux.sh
index 7c5846f..6495fef 100644
--- a/.travis_scripts/travis.install.linux.sh
+++ b/.travis_scripts/travis.install.linux.sh
@@ -1,10 +1,5 @@
set -vex
-wget https://github.com/ninja-build/ninja/releases/download/v1.9.0/ninja-linux.zip
-unzip -q ninja-linux.zip -d build
-
-pip3 install meson
-echo ${PATH}
-ls /usr/local
-ls /usr/local/bin
-export PATH="${PWD}"/build:/usr/local/bin:/usr/bin:${PATH}
+pip3 install --user meson ninja
+which meson
+which ninja
diff --git a/BUILD.bazel b/BUILD.bazel
new file mode 100644
index 0000000..6d7ac3d
--- /dev/null
+++ b/BUILD.bazel
@@ -0,0 +1,37 @@
+licenses(["unencumbered"]) # Public Domain or MIT
+
+exports_files(["LICENSE"])
+
+cc_library(
+ name = "jsoncpp",
+ srcs = [
+ "src/lib_json/json_reader.cpp",
+ "src/lib_json/json_tool.h",
+ "src/lib_json/json_value.cpp",
+ "src/lib_json/json_writer.cpp",
+ ],
+ hdrs = [
+ "include/json/allocator.h",
+ "include/json/assertions.h",
+ "include/json/config.h",
+ "include/json/json_features.h",
+ "include/json/forwards.h",
+ "include/json/json.h",
+ "include/json/reader.h",
+ "include/json/value.h",
+ "include/json/version.h",
+ "include/json/writer.h",
+ ],
+ copts = [
+ "-DJSON_USE_EXCEPTION=0",
+ "-DJSON_HAS_INT64",
+ ],
+ includes = ["include"],
+ visibility = ["//visibility:public"],
+ deps = [":private"],
+)
+
+cc_library(
+ name = "private",
+ textual_hdrs = ["src/lib_json/json_valueiterator.inl"],
+)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 51b74fc..2841277 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -22,6 +22,9 @@ else()
set(JSONCPP_CMAKE_POLICY_VERSION "${JSONCPP_NEWEST_VALIDATED_POLICIES_VERSION}")
endif()
cmake_policy(VERSION ${JSONCPP_CMAKE_POLICY_VERSION})
+if(POLICY CMP0091)
+ cmake_policy(SET CMP0091 NEW)
+endif()
#
# Now enumerate specific policies newer than JSONCPP_NEWEST_VALIDATED_POLICIES_VERSION
# that may need to be individually set to NEW/OLD
@@ -69,11 +72,14 @@ project(jsoncpp
# 2. ./include/json/version.h
# 3. ./CMakeLists.txt
# IMPORTANT: also update the PROJECT_SOVERSION!!
- VERSION 1.9.4 # <major>[.<minor>[.<patch>[.<tweak>]]]
+ VERSION 1.9.5 # <major>[.<minor>[.<patch>[.<tweak>]]]
LANGUAGES CXX)
message(STATUS "JsonCpp Version: ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")
-set(PROJECT_SOVERSION 24)
+set(PROJECT_SOVERSION 25)
+
+include(${CMAKE_CURRENT_SOURCE_DIR}/include/PreventInSourceBuilds.cmake)
+include(${CMAKE_CURRENT_SOURCE_DIR}/include/PreventInBuildInstalls.cmake)
option(JSONCPP_WITH_TESTS "Compile and (for jsoncpp_check) run JsonCpp test executables" ON)
option(JSONCPP_WITH_POST_BUILD_UNITTEST "Automatically run unit-tests as a post build step" ON)
@@ -82,6 +88,7 @@ option(JSONCPP_WITH_STRICT_ISO "Issue all the warnings demanded by strict ISO C
option(JSONCPP_WITH_PKGCONFIG_SUPPORT "Generate and install .pc files" ON)
option(JSONCPP_WITH_CMAKE_PACKAGE "Generate and install cmake package files" ON)
option(JSONCPP_WITH_EXAMPLE "Compile JsonCpp example" OFF)
+option(JSONCPP_STATIC_WINDOWS_RUNTIME "Use static (MT/MTd) Windows runtime" OFF)
option(BUILD_SHARED_LIBS "Build jsoncpp_lib as a shared library." ON)
option(BUILD_STATIC_LIBS "Build jsoncpp_lib as a static library." ON)
option(BUILD_OBJECT_LIBS "Build jsoncpp_lib as a object library." ON)
@@ -120,11 +127,18 @@ if(MSVC)
# Only enabled in debug because some old versions of VS STL generate
# unreachable code warning when compiled in release configuration.
add_compile_options($<$<CONFIG:Debug>:/W4>)
+ if (JSONCPP_STATIC_WINDOWS_RUNTIME)
+ set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
+ endif()
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# using regular Clang or AppleClang
- add_compile_options(-Wall -Wconversion -Wshadow -Werror=conversion -Werror=sign-compare)
+ add_compile_options(-Wall -Wconversion -Wshadow)
+
+ if(JSONCPP_WITH_WARNING_AS_ERROR)
+ add_compile_options(-Werror=conversion -Werror=sign-compare)
+ endif()
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
# using GCC
add_compile_options(-Wall -Wconversion -Wshadow -Wextra)
@@ -138,9 +152,11 @@ elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
endif()
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
# using Intel compiler
- add_compile_options(-Wall -Wconversion -Wshadow -Wextra -Werror=conversion)
+ add_compile_options(-Wall -Wconversion -Wshadow -Wextra)
- if(JSONCPP_WITH_STRICT_ISO AND NOT JSONCPP_WITH_WARNING_AS_ERROR)
+ if(JSONCPP_WITH_WARNING_AS_ERROR)
+ add_compile_options(-Werror=conversion)
+ elseif(JSONCPP_WITH_STRICT_ISO)
add_compile_options(-Wpedantic)
endif()
endif()
@@ -167,11 +183,16 @@ if(JSONCPP_WITH_CMAKE_PACKAGE)
include(CMakePackageConfigHelpers)
install(EXPORT jsoncpp
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/jsoncpp
- FILE jsoncppConfig.cmake)
+ FILE jsoncpp-targets.cmake)
+ configure_package_config_file(jsoncppConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/jsoncppConfig.cmake
+ INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/jsoncpp)
+
write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/jsoncppConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion)
- install(FILES ${CMAKE_CURRENT_BINARY_DIR}/jsoncppConfigVersion.cmake
+ install(FILES
+ ${CMAKE_CURRENT_BINARY_DIR}/jsoncppConfigVersion.cmake ${CMAKE_CURRENT_BINARY_DIR}/jsoncppConfig.cmake
+ ${CMAKE_CURRENT_SOURCE_DIR}/jsoncpp-namespaced-targets.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/jsoncpp)
endif()
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 9c9fc6a..8d992be 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -19,7 +19,7 @@ If you wish to install to a directory other than /usr/local, set an environment
DESTDIR=/path/to/install/dir
Then,
-
+```sh
cd jsoncpp/
BUILD_TYPE=debug
#BUILD_TYPE=release
@@ -35,6 +35,7 @@ Then,
#meson test --no-rebuild --print-errorlogs
sudo ninja install
+```
## Building and testing with other build systems
See https://github.com/open-source-parsers/jsoncpp/wiki/Building
@@ -143,7 +144,9 @@ bool Reader::decodeNumber(Token& token) {
```
Before submitting your code, ensure that you meet the versioning requirements above, follow the style guide of the file you are modifying (or the above rules for new files), and run clang format. Meson exposes clang format with the following command:
-
```
ninja -v -C build-${LIB_TYPE}/ clang-format
```
+
+For convenience, you can also run the `reformat.sh` script located in the root directory.
+
diff --git a/LICENSE b/LICENSE
index 89280a6..c41a1d1 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,25 +1,25 @@
-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
conditions...
-Baptiste Lepilleur and The JsonCpp Authors explicitly disclaim copyright in all
-jurisdictions which recognize such a disclaimer. In such jurisdictions,
+Baptiste Lepilleur and The JsonCpp Authors explicitly disclaim copyright in all
+jurisdictions which recognize such a disclaimer. In such jurisdictions,
this software is released into the Public Domain.
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
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
-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
+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
+conditions of the MIT License (see below), or 3) under the terms of dual
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
described in clear, concise terms at:
http://en.wikipedia.org/wiki/MIT_License
-
+
The full text of the MIT License follows:
========================================================================
diff --git a/METADATA b/METADATA
index 8b98e5f..a1c5da4 100644
--- a/METADATA
+++ b/METADATA
@@ -3,16 +3,16 @@ description: "JsonCpp is a C++ library that allows manipulating JSON values, inc
third_party {
url {
type: ARCHIVE
- value: "https://github.com/open-source-parsers/jsoncpp/archive/1.9.4.tar.gz"
+ value: "https://github.com/open-source-parsers/jsoncpp/archive/1.9.5.tar.gz"
}
- version: "1.9.4"
+ version: "1.9.5"
license_type: NOTICE
- last_upgrade_date {
- year: 2021
- month: 2
- day: 24
- }
security {
tag: "NVD-CPE2.3:cpe:/a:jsoncpp_project:jsoncpp:1.9.4"
}
+ last_upgrade_date {
+ year: 2021
+ month: 12
+ day: 7
+ }
}
diff --git a/appveyor.yml b/appveyor.yml
index 0b9c8fe..cccce42 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -1,6 +1,7 @@
clone_folder: c:\projects\jsoncpp
environment:
+
matrix:
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
CMAKE_GENERATOR: Visual Studio 14 2015
@@ -13,11 +14,15 @@ environment:
build_script:
- cmake --version
- - cd c:\projects\jsoncpp
- - cmake -G "%CMAKE_GENERATOR%" -DCMAKE_INSTALL_PREFIX:PATH=%CD:\=/%/install -DBUILD_SHARED_LIBS:BOOL=ON .
+ # The build script starts in root.
+ - set JSONCPP_FOLDER=%cd%
+ - set JSONCPP_BUILD_FOLDER=%JSONCPP_FOLDER%\build\release
+ - mkdir -p %JSONCPP_BUILD_FOLDER%
+ - cd %JSONCPP_BUILD_FOLDER%
+ - cmake -G "%CMAKE_GENERATOR%" -DCMAKE_INSTALL_PREFIX:PATH=%CD:\=/%/install -DBUILD_SHARED_LIBS:BOOL=ON %JSONCPP_FOLDER%
# Use ctest to make a dashboard build:
# - ctest -D Experimental(Start|Update|Configure|Build|Test|Coverage|MemCheck|Submit)
- # NOTE: Testing on window is not yet finished:
+ # NOTE: Testing on windows is not yet finished:
# - ctest -C Release -D ExperimentalStart -D ExperimentalConfigure -D ExperimentalBuild -D ExperimentalTest -D ExperimentalSubmit
- ctest -C Release -D ExperimentalStart -D ExperimentalConfigure -D ExperimentalBuild -D ExperimentalSubmit
# Final step is to verify that installation succeeds
diff --git a/dev.makefile b/dev.makefile
index 1a4be6a..545ff27 100644
--- a/dev.makefile
+++ b/dev.makefile
@@ -1,9 +1,11 @@
# This is only for jsoncpp developers/contributors.
# We use this to sign releases, generate documentation, etc.
-VER?=$(shell cat version.txt)
+VER?=$(shell cat version)
default:
@echo "VER=${VER}"
+update-version:
+ perl get_version.pl meson.build >| version
sign: jsoncpp-${VER}.tar.gz
gpg --armor --detach-sign $<
gpg --verify $<.asc
diff --git a/devtools/antglob.py b/devtools/antglob.py
index 9843765..bd2d7ae 100644
--- a/devtools/antglob.py
+++ b/devtools/antglob.py
@@ -146,7 +146,7 @@ def glob(dir_path,
entry_type = is_file and FILE_LINK or DIR_LINK
else:
entry_type = is_file and FILE or DIR
-## print '=> type: %d' % entry_type,
+## print '=> type: %d' % entry_type,
if (entry_type & entry_type_filter) != 0:
## print ' => KEEP'
yield os.path.join(dir_path, entry)
diff --git a/devtools/fixeol.py b/devtools/fixeol.py
index 45252a0..11e1ce2 100644
--- a/devtools/fixeol.py
+++ b/devtools/fixeol.py
@@ -32,8 +32,8 @@ def fix_source_eol(path, is_dry_run = True, verbose = True, eol = '\n'):
if verbose:
print(is_dry_run and ' NEED FIX' or ' FIXED')
return True
-##
-##
+##
+##
##
##def _do_fix(is_dry_run = True):
## from waftools import antglob
diff --git a/devtools/licenseupdater.py b/devtools/licenseupdater.py
index 36bdb5c..d9b662e 100644
--- a/devtools/licenseupdater.py
+++ b/devtools/licenseupdater.py
@@ -20,7 +20,7 @@ def update_license(path, dry_run, show_diff):
dry_run: if True, just print the path of the file that would be updated,
but don't change it.
show_diff: if True, print the path of the file that would be modified,
- as well as the change made to the file.
+ as well as the change made to the file.
"""
with open(path, 'rt') as fin:
original_text = fin.read().replace('\r\n','\n')
@@ -51,7 +51,7 @@ def update_license_in_source_directories(source_dirs, dry_run, show_diff):
dry_run: if True, just print the path of the file that would be updated,
but don't change it.
show_diff: if True, print the path of the file that would be modified,
- as well as the change made to the file.
+ as well as the change made to the file.
"""
from devtools import antglob
prune_dirs = antglob.prune_dirs + 'scons-local* ./build* ./libs ./dist'
diff --git a/doxybuild.py b/doxybuild.py
index 862c1f4..254ab71 100644
--- a/doxybuild.py
+++ b/doxybuild.py
@@ -46,7 +46,7 @@ def do_subst_in_file(targetfile, sourcefile, dict):
with open(sourcefile, 'r') as f:
contents = f.read()
for (k,v) in list(dict.items()):
- v = v.replace('\\','\\\\')
+ v = v.replace('\\','\\\\')
contents = re.sub(k, v, contents)
with open(targetfile, 'w') as f:
f.write(contents)
@@ -158,7 +158,7 @@ def main():
Generates doxygen documentation in build/doxygen.
Optionally makes a tarball of the documentation to dist/.
- Must be started in the project top directory.
+ Must be started in the project top directory.
"""
from optparse import OptionParser
parser = OptionParser(usage=usage)
diff --git a/example/README.md b/example/README.md
index b1ae4c8..92b925c 100644
--- a/example/README.md
+++ b/example/README.md
@@ -1,8 +1,8 @@
-***NOTE***
+***NOTE***
If you get linker errors about undefined references to symbols that involve types in the `std::__cxx11` namespace or the tag
`[abi:cxx11]` then it probably indicates that you are trying to link together object files that were compiled with different
-values for the _GLIBCXX_USE_CXX11_ABI marco. This commonly happens when linking to a third-party library that was compiled with
+values for the _GLIBCXX_USE_CXX11_ABI marco. This commonly happens when linking to a third-party library that was compiled with
an older version of GCC. If the third-party library cannot be rebuilt with the new ABI, then you need to recompile your code with
the old ABI,just like:
**g++ stringWrite.cpp -ljsoncpp -std=c++11 -D_GLIBCXX_USE_CXX11_ABI=0 -o stringWrite**
diff --git a/example/readFromString/readFromString.cpp b/example/readFromString/readFromString.cpp
index c27bbd5..0b29a4e 100644
--- a/example/readFromString/readFromString.cpp
+++ b/example/readFromString/readFromString.cpp
@@ -1,5 +1,6 @@
#include "json/json.h"
#include <iostream>
+#include <memory>
/**
* \brief Parse a raw string into Value object using the CharReaderBuilder
* class, or the legacy Reader class.
diff --git a/example/streamWrite/streamWrite.cpp b/example/streamWrite/streamWrite.cpp
index 6f7f797..a72f5a5 100644
--- a/example/streamWrite/streamWrite.cpp
+++ b/example/streamWrite/streamWrite.cpp
@@ -1,5 +1,6 @@
#include "json/json.h"
#include <iostream>
+#include <memory>
/** \brief Write the Value object to a stream.
* Example Usage:
* $g++ streamWrite.cpp -ljsoncpp -std=c++11 -o streamWrite
diff --git a/get_version.pl b/get_version.pl
new file mode 100644
index 0000000..19b6a54
--- /dev/null
+++ b/get_version.pl
@@ -0,0 +1,5 @@
+while (<>) {
+ if (/version : '(.+)',/) {
+ print "$1";
+ }
+}
diff --git a/include/PreventInBuildInstalls.cmake b/include/PreventInBuildInstalls.cmake
new file mode 100644
index 0000000..accfea6
--- /dev/null
+++ b/include/PreventInBuildInstalls.cmake
@@ -0,0 +1,9 @@
+string(TOLOWER "${CMAKE_INSTALL_PREFIX}" _PREFIX)
+string(TOLOWER "${ITK_BINARY_DIR}" _BUILD)
+if("${_PREFIX}" STREQUAL "${_BUILD}")
+ message(FATAL_ERROR
+ "The current CMAKE_INSTALL_PREFIX points at the build tree:\n"
+ " ${CMAKE_INSTALL_PREFIX}\n"
+ "This is not supported."
+ )
+endif()
diff --git a/include/PreventInSourceBuilds.cmake b/include/PreventInSourceBuilds.cmake
new file mode 100644
index 0000000..7ddda54
--- /dev/null
+++ b/include/PreventInSourceBuilds.cmake
@@ -0,0 +1,45 @@
+#
+# This function will prevent in-source builds
+function(AssureOutOfSourceBuilds)
+ # make sure the user doesn't play dirty with symlinks
+ get_filename_component(srcdir "${CMAKE_SOURCE_DIR}" REALPATH)
+ get_filename_component(bindir "${CMAKE_BINARY_DIR}" REALPATH)
+
+ # disallow in-source builds
+ if("${srcdir}" STREQUAL "${bindir}")
+ message("######################################################")
+ message("# jsoncpp should not be configured & built in the jsoncpp source directory")
+ message("# You must run cmake in a build directory.")
+ message("# For example:")
+ message("# mkdir jsoncpp-Sandbox ; cd jsoncpp-sandbox")
+ message("# git clone https://github.com/open-source-parsers/jsoncpp.git # or download & unpack the source tarball")
+ message("# mkdir jsoncpp-build")
+ message("# this will create the following directory structure")
+ message("#")
+ message("# jsoncpp-Sandbox")
+ message("# +--jsoncpp")
+ message("# +--jsoncpp-build")
+ message("#")
+ message("# Then you can proceed to configure and build")
+ message("# by using the following commands")
+ message("#")
+ message("# cd jsoncpp-build")
+ message("# cmake ../jsoncpp # or ccmake, or cmake-gui ")
+ message("# make")
+ message("#")
+ message("# NOTE: Given that you already tried to make an in-source build")
+ message("# CMake have already created several files & directories")
+ message("# in your source tree. run 'git status' to find them and")
+ message("# remove them by doing:")
+ message("#")
+ message("# cd jsoncpp-Sandbox/jsoncpp")
+ message("# git clean -n -d")
+ message("# git clean -f -d")
+ message("# git checkout --")
+ message("#")
+ message("######################################################")
+ message(FATAL_ERROR "Quitting configuration")
+ endif()
+endfunction()
+
+AssureOutOfSourceBuilds()
diff --git a/include/json/allocator.h b/include/json/allocator.h
index 0f5c224..95ef8a5 100644
--- a/include/json/allocator.h
+++ b/include/json/allocator.h
@@ -35,11 +35,10 @@ public:
* Release memory which was allocated for N items at pointer P.
*
* 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) {
- std::memset(p, 0, n * sizeof(T));
+ void deallocate(pointer p, size_type n) {
+ // 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"
::operator delete(p);
}
diff --git a/include/json/reader.h b/include/json/reader.h
index 9175466..be0d767 100644
--- a/include/json/reader.h
+++ b/include/json/reader.h
@@ -33,8 +33,7 @@ namespace Json {
* \deprecated Use CharReader and CharReaderBuilder.
*/
-class JSONCPP_DEPRECATED(
- "Use CharReader and CharReaderBuilder instead.") JSON_API Reader {
+class JSON_API Reader {
public:
using Char = char;
using Location = const Char*;
@@ -51,13 +50,13 @@ public:
};
/** \brief Constructs a Reader allowing all features for parsing.
+ * \deprecated Use CharReader and CharReaderBuilder.
*/
- JSONCPP_DEPRECATED("Use CharReader and CharReaderBuilder instead")
Reader();
/** \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);
/** \brief Read a Value from a <a HREF="http://www.json.org">JSON</a>
@@ -324,6 +323,9 @@ public:
* - `"allowSpecialFloats": false or true`
* - If true, special float values (NaNs and infinities) are allowed and
* 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
* write and read them just like any JSON Value.
diff --git a/include/json/value.h b/include/json/value.h
index df1eba6..0edeb05 100644
--- a/include/json/value.h
+++ b/include/json/value.h
@@ -50,7 +50,7 @@
// be used by...
#if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
#pragma warning(push)
-#pragma warning(disable : 4251)
+#pragma warning(disable : 4251 4275)
#endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
#pragma pack(push, 8)
@@ -263,10 +263,10 @@ private:
CZString(ArrayIndex index);
CZString(char const* str, unsigned length, DuplicationPolicy allocate);
CZString(CZString const& other);
- CZString(CZString&& other);
+ CZString(CZString&& other) noexcept;
~CZString();
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;
@@ -344,13 +344,13 @@ public:
Value(bool value);
Value(std::nullptr_t ptr) = delete;
Value(const Value& other);
- Value(Value&& other);
+ Value(Value&& other) noexcept;
~Value();
/// \note Overwrite existing comments. To preserve comments, use
/// #swapPayload().
Value& operator=(const Value& other);
- Value& operator=(Value&& other);
+ Value& operator=(Value&& other) noexcept;
/// Swap everything.
void swap(Value& other);
@@ -635,9 +635,9 @@ private:
public:
Comments() = default;
Comments(const Comments& that);
- Comments(Comments&& that);
+ Comments(Comments&& that) noexcept;
Comments& operator=(const Comments& that);
- Comments& operator=(Comments&& that);
+ Comments& operator=(Comments&& that) noexcept;
bool has(CommentPlacement slot) const;
String get(CommentPlacement slot) const;
void set(CommentPlacement slot, String comment);
@@ -918,8 +918,8 @@ public:
* because the returned references/pointers can be used
* to change state of the base class.
*/
- reference operator*() { return deref(); }
- pointer operator->() { return &deref(); }
+ reference operator*() const { return const_cast<reference>(deref()); }
+ pointer operator->() const { return const_cast<pointer>(&deref()); }
};
inline void swap(Value& a, Value& b) { a.swap(b); }
diff --git a/include/json/version.h b/include/json/version.h
index 5b9783d..e931d03 100644
--- a/include/json/version.h
+++ b/include/json/version.h
@@ -9,10 +9,10 @@
// 3. /CMakeLists.txt
// IMPORTANT: also update the SOVERSION!!
-#define JSONCPP_VERSION_STRING "1.9.4"
+#define JSONCPP_VERSION_STRING "1.9.5"
#define JSONCPP_VERSION_MAJOR 1
#define JSONCPP_VERSION_MINOR 9
-#define JSONCPP_VERSION_PATCH 3
+#define JSONCPP_VERSION_PATCH 5
#define JSONCPP_VERSION_QUALIFIER
#define JSONCPP_VERSION_HEXA \
((JSONCPP_VERSION_MAJOR << 24) | (JSONCPP_VERSION_MINOR << 16) | \
diff --git a/include/json/writer.h b/include/json/writer.h
index fb0852a..88a3b12 100644
--- a/include/json/writer.h
+++ b/include/json/writer.h
@@ -110,6 +110,8 @@ public:
* - Number of precision digits for formatting of real values.
* - "precisionType": "significant"(default) or "decimal"
* - 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
* to see the defaults. You can also write and read them just like any
@@ -145,7 +147,7 @@ public:
/** \brief Abstract class for writers.
* \deprecated Use StreamWriter. (And really, this is an implementation detail.)
*/
-class JSONCPP_DEPRECATED("Use StreamWriter instead") JSON_API Writer {
+class JSON_API Writer {
public:
virtual ~Writer();
@@ -165,7 +167,7 @@ public:
#pragma warning(push)
#pragma warning(disable : 4996) // Deriving from deprecated class
#endif
-class JSONCPP_DEPRECATED("Use StreamWriterBuilder instead") JSON_API FastWriter
+class JSON_API FastWriter
: public Writer {
public:
FastWriter();
@@ -225,7 +227,7 @@ private:
#pragma warning(push)
#pragma warning(disable : 4996) // Deriving from deprecated class
#endif
-class JSONCPP_DEPRECATED("Use StreamWriterBuilder instead") JSON_API
+class JSON_API
StyledWriter : public Writer {
public:
StyledWriter();
@@ -294,7 +296,7 @@ private:
#pragma warning(push)
#pragma warning(disable : 4996) // Deriving from deprecated class
#endif
-class JSONCPP_DEPRECATED("Use StreamWriterBuilder instead") JSON_API
+class JSON_API
StyledStreamWriter {
public:
/**
diff --git a/jsoncpp-namespaced-targets.cmake b/jsoncpp-namespaced-targets.cmake
new file mode 100644
index 0000000..ac1504e
--- /dev/null
+++ b/jsoncpp-namespaced-targets.cmake
@@ -0,0 +1,7 @@
+if (TARGET jsoncpp_static)
+ add_library(JsonCpp::JsonCpp INTERFACE IMPORTED)
+ set_target_properties(JsonCpp::JsonCpp PROPERTIES INTERFACE_LINK_LIBRARIES "jsoncpp_static")
+elseif (TARGET jsoncpp_lib)
+ add_library(JsonCpp::JsonCpp INTERFACE IMPORTED)
+ set_target_properties(JsonCpp::JsonCpp PROPERTIES INTERFACE_LINK_LIBRARIES "jsoncpp_lib")
+endif () \ No newline at end of file
diff --git a/jsoncppConfig.cmake.in b/jsoncppConfig.cmake.in
new file mode 100644
index 0000000..76570bc
--- /dev/null
+++ b/jsoncppConfig.cmake.in
@@ -0,0 +1,11 @@
+cmake_policy(PUSH)
+cmake_policy(VERSION 3.0)
+
+@PACKAGE_INIT@
+
+include ( "${CMAKE_CURRENT_LIST_DIR}/jsoncpp-targets.cmake" )
+include ( "${CMAKE_CURRENT_LIST_DIR}/jsoncpp-namespaced-targets.cmake" )
+
+check_required_components(JsonCpp)
+
+cmake_policy(POP)
diff --git a/meson.build b/meson.build
index 08e0f29..f68db30 100644
--- a/meson.build
+++ b/meson.build
@@ -50,7 +50,7 @@ jsoncpp_lib = library(
'src/lib_json/json_value.cpp',
'src/lib_json/json_writer.cpp',
]),
- soversion : 24,
+ soversion : 25,
install : true,
include_directories : jsoncpp_include_directories,
cpp_args: dll_export_flag)
diff --git a/pkg-config/jsoncpp.pc.in b/pkg-config/jsoncpp.pc.in
index 632a377..2a22210 100644
--- a/pkg-config/jsoncpp.pc.in
+++ b/pkg-config/jsoncpp.pc.in
@@ -5,7 +5,7 @@ includedir=@includedir_for_pc_file@
Name: jsoncpp
Description: A C++ library for interacting with JSON
-Version: @JSONCPP_VERSION@
+Version: @PROJECT_VERSION@
URL: https://github.com/open-source-parsers/jsoncpp
Libs: -L${libdir} -ljsoncpp
Cflags: -I${includedir}
diff --git a/reformat.sh b/reformat.sh
new file mode 100755
index 0000000..cdc03b1
--- /dev/null
+++ b/reformat.sh
@@ -0,0 +1 @@
+find src -name '*.cpp' -or -name '*.h' | xargs clang-format -i
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
diff --git a/test/data/legacy_test_array_06.json b/test/data/legacy_test_array_06.json
index 7f6c516..1fda03b 100644
--- a/test/data/legacy_test_array_06.json
+++ b/test/data/legacy_test_array_06.json
@@ -1,4 +1,4 @@
-[ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
+[ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
"ccccccccccccccccccccccc",
"dddddddddddddddddddddddddddddddddddddddddddddddddddd" ] \ No newline at end of file
diff --git a/test/data/legacy_test_complex_01.json b/test/data/legacy_test_complex_01.json
index cc0f30f..2c4a869 100644
--- a/test/data/legacy_test_complex_01.json
+++ b/test/data/legacy_test_complex_01.json
@@ -1,17 +1,17 @@
-{
+{
"count" : 1234,
"name" : { "aka" : "T.E.S.T.", "id" : 123987 },
- "attribute" : [
- "random",
- "short",
- "bold",
- 12,
- { "height" : 7, "width" : 64 }
+ "attribute" : [
+ "random",
+ "short",
+ "bold",
+ 12,
+ { "height" : 7, "width" : 64 }
],
- "test": { "1" :
- { "2" :
- { "3" : { "coord" : [ 1,2] }
- }
+ "test": { "1" :
+ { "2" :
+ { "3" : { "coord" : [ 1,2] }
+ }
}
}
}
diff --git a/test/data/legacy_test_object_03.json b/test/data/legacy_test_object_03.json
index 4fcd4d8..90dba2a 100644
--- a/test/data/legacy_test_object_03.json
+++ b/test/data/legacy_test_object_03.json
@@ -1,4 +1,4 @@
-{
+{
"count" : 1234,
"name" : "test",
"attribute" : "random"
diff --git a/test/data/legacy_test_object_04.json b/test/data/legacy_test_object_04.json
index 450762d..9e43ff8 100644
--- a/test/data/legacy_test_object_04.json
+++ b/test/data/legacy_test_object_04.json
@@ -1,3 +1,3 @@
-{
+{
"" : 1234
}
diff --git a/test/data/legacy_test_preserve_comment_01.expected b/test/data/legacy_test_preserve_comment_01.expected
index 2797aa7..d6c11b4 100644
--- a/test/data/legacy_test_preserve_comment_01.expected
+++ b/test/data/legacy_test_preserve_comment_01.expected
@@ -6,6 +6,6 @@
/* Comment before 'second'
*/
.second=2
-/* A comment at
+/* A comment at
the end of the file.
*/
diff --git a/test/data/legacy_test_preserve_comment_01.json b/test/data/legacy_test_preserve_comment_01.json
index fabd55d..21b5ea7 100644
--- a/test/data/legacy_test_preserve_comment_01.json
+++ b/test/data/legacy_test_preserve_comment_01.json
@@ -9,6 +9,6 @@
"second" : 2
}
-/* A comment at
+/* A comment at
the end of the file.
*/
diff --git a/test/pyjsontestrunner.py b/test/pyjsontestrunner.py
index bd749b5..8acdbd2 100644
--- a/test/pyjsontestrunner.py
+++ b/test/pyjsontestrunner.py
@@ -15,7 +15,7 @@ import types
if len(sys.argv) != 2:
print("Usage: %s input-json-file", sys.argv[0])
sys.exit(3)
-
+
input_path = sys.argv[1]
base_path = os.path.splitext(input_path)[0]
actual_path = base_path + '.actual'
@@ -23,7 +23,7 @@ rewrite_path = base_path + '.rewrite'
rewrite_actual_path = base_path + '.actual-rewrite'
def valueTreeToString(fout, value, path = '.'):
- ty = type(value)
+ ty = type(value)
if ty is types.DictType:
fout.write('%s={}\n' % path)
suffix = path[-1] != '.' and '.' or ''
@@ -49,7 +49,7 @@ def valueTreeToString(fout, value, path = '.'):
fout.write('%s=null\n' % path)
else:
assert False and "Unexpected value type"
-
+
def parseAndSaveValueTree(input, actual_path):
root = json.loads(input)
fout = file(actual_path, 'wt')
@@ -62,7 +62,7 @@ def rewriteValueTree(value, rewrite_path):
#rewrite = rewrite[1:-1] # Somehow the string is quoted ! jsonpy bug ?
file(rewrite_path, 'wt').write(rewrite + '\n')
return rewrite
-
+
input = file(input_path, 'rt').read()
root = parseAndSaveValueTree(input, actual_path)
rewrite = rewriteValueTree(json.write(root), rewrite_path)