mirror of
https://github.com/open-source-parsers/jsoncpp.git
synced 2024-12-13 10:22:55 +01:00
Merge branch 'master' into master
This commit is contained in:
commit
cf8a11eab9
@ -62,11 +62,11 @@ project(jsoncpp
|
||||
# 2. ./include/json/version.h
|
||||
# 3. ./CMakeLists.txt
|
||||
# IMPORTANT: also update the PROJECT_SOVERSION!!
|
||||
VERSION 1.9.5 # <major>[.<minor>[.<patch>[.<tweak>]]]
|
||||
VERSION 1.9.6 # <major>[.<minor>[.<patch>[.<tweak>]]]
|
||||
LANGUAGES CXX)
|
||||
|
||||
message(STATUS "JsonCpp Version: ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")
|
||||
set(PROJECT_SOVERSION 25)
|
||||
set(PROJECT_SOVERSION 26)
|
||||
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/include/PreventInSourceBuilds.cmake)
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/include/PreventInBuildInstalls.cmake)
|
||||
|
@ -2,8 +2,8 @@
|
||||
# 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)
|
||||
get_filename_component(srcdir "${CMAKE_CURRENT_SOURCE_DIR}" REALPATH)
|
||||
get_filename_component(bindir "${CMAKE_CURRENT_BINARY_DIR}" REALPATH)
|
||||
|
||||
# disallow in-source builds
|
||||
if("${srcdir}" STREQUAL "${bindir}")
|
||||
|
@ -385,6 +385,12 @@ public:
|
||||
* \snippet src/lib_json/json_reader.cpp CharReaderBuilderStrictMode
|
||||
*/
|
||||
static void strictMode(Json::Value* settings);
|
||||
/** ECMA-404 mode.
|
||||
* \pre 'settings' != NULL (but Json::null is fine)
|
||||
* \remark Defaults:
|
||||
* \snippet src/lib_json/json_reader.cpp CharReaderBuilderECMA404Mode
|
||||
*/
|
||||
static void ecma404Mode(Json::Value* settings);
|
||||
};
|
||||
|
||||
/** Consume entire stream and use its begin/end.
|
||||
|
@ -3,8 +3,8 @@
|
||||
// recognized in your jurisdiction.
|
||||
// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
|
||||
|
||||
#ifndef JSON_H_INCLUDED
|
||||
#define JSON_H_INCLUDED
|
||||
#ifndef JSON_VALUE_H_INCLUDED
|
||||
#define JSON_VALUE_H_INCLUDED
|
||||
|
||||
#if !defined(JSON_IS_AMALGAMATION)
|
||||
#include "forwards.h"
|
||||
@ -513,6 +513,9 @@ public:
|
||||
/// and operator[]const
|
||||
/// \note As stated elsewhere, behavior is undefined if (end-begin) >= 2^30
|
||||
Value const* find(char const* begin, char const* end) const;
|
||||
/// Most general and efficient version of isMember()const, get()const,
|
||||
/// and operator[]const
|
||||
Value const* find(const String& key) const;
|
||||
/// Most general and efficient version of object-mutators.
|
||||
/// \note As stated elsewhere, behavior is undefined if (end-begin) >= 2^30
|
||||
/// \return non-zero, but JSON_ASSERT if this is neither object nor nullValue.
|
||||
|
@ -9,10 +9,10 @@
|
||||
// 3. /CMakeLists.txt
|
||||
// IMPORTANT: also update the SOVERSION!!
|
||||
|
||||
#define JSONCPP_VERSION_STRING "1.9.5"
|
||||
#define JSONCPP_VERSION_STRING "1.9.6"
|
||||
#define JSONCPP_VERSION_MAJOR 1
|
||||
#define JSONCPP_VERSION_MINOR 9
|
||||
#define JSONCPP_VERSION_PATCH 5
|
||||
#define JSONCPP_VERSION_PATCH 6
|
||||
#define JSONCPP_VERSION_QUALIFIER
|
||||
#define JSONCPP_VERSION_HEXA \
|
||||
((JSONCPP_VERSION_MAJOR << 24) | (JSONCPP_VERSION_MINOR << 16) | \
|
||||
|
@ -1,7 +1,9 @@
|
||||
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 ()
|
||||
if (NOT TARGET JsonCpp::JsonCpp)
|
||||
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 ()
|
||||
endif ()
|
||||
|
8
jsoncppConfig.cmake.meson.in
Normal file
8
jsoncppConfig.cmake.meson.in
Normal file
@ -0,0 +1,8 @@
|
||||
@PACKAGE_INIT@
|
||||
|
||||
@MESON_SHARED_TARGET@
|
||||
@MESON_STATIC_TARGET@
|
||||
|
||||
include ( "${CMAKE_CURRENT_LIST_DIR}/jsoncpp-namespaced-targets.cmake" )
|
||||
|
||||
check_required_components(JsonCpp)
|
43
meson.build
43
meson.build
@ -9,13 +9,13 @@ project(
|
||||
# 2. /include/json/version.h
|
||||
# 3. /CMakeLists.txt
|
||||
# IMPORTANT: also update the SOVERSION!!
|
||||
version : '1.9.4',
|
||||
version : '1.9.6',
|
||||
default_options : [
|
||||
'buildtype=release',
|
||||
'cpp_std=c++11',
|
||||
'warning_level=1'],
|
||||
license : 'Public Domain',
|
||||
meson_version : '>= 0.49.0')
|
||||
meson_version : '>= 0.54.0')
|
||||
|
||||
|
||||
jsoncpp_headers = files([
|
||||
@ -50,7 +50,7 @@ jsoncpp_lib = library(
|
||||
'src/lib_json/json_value.cpp',
|
||||
'src/lib_json/json_writer.cpp',
|
||||
]),
|
||||
soversion : 25,
|
||||
soversion : 26,
|
||||
install : true,
|
||||
include_directories : jsoncpp_include_directories,
|
||||
cpp_args: dll_export_flag)
|
||||
@ -62,6 +62,43 @@ import('pkgconfig').generate(
|
||||
filebase : 'jsoncpp',
|
||||
description : 'A C++ library for interacting with JSON')
|
||||
|
||||
cmakeconf = configuration_data()
|
||||
cmakeconf.set('MESON_LIB_DIR', get_option('libdir'))
|
||||
cmakeconf.set('MESON_INCLUDE_DIR', get_option('includedir'))
|
||||
|
||||
fs = import('fs')
|
||||
if get_option('default_library') == 'shared'
|
||||
shared_name = fs.name(jsoncpp_lib.full_path())
|
||||
endif
|
||||
if get_option('default_library') == 'static'
|
||||
static_name = fs.name(jsoncpp_lib.full_path())
|
||||
endif
|
||||
if get_option('default_library') == 'both'
|
||||
shared_name = fs.name(jsoncpp_lib.get_shared_lib().full_path())
|
||||
static_name = fs.name(jsoncpp_lib.get_static_lib().full_path())
|
||||
endif
|
||||
|
||||
if get_option('default_library') == 'shared' or get_option('default_library') == 'both'
|
||||
cmakeconf.set('MESON_SHARED_TARGET', '''
|
||||
add_library(jsoncpp_lib IMPORTED SHARED)
|
||||
set_target_properties(jsoncpp_lib PROPERTIES
|
||||
IMPORTED_LOCATION "''' + join_paths('${PACKAGE_PREFIX_DIR}', get_option('libdir'), shared_name) + '''"
|
||||
INTERFACE_INCLUDE_DIRECTORIES "''' + join_paths('${PACKAGE_PREFIX_DIR}', get_option('includedir')) + '")')
|
||||
endif
|
||||
if get_option('default_library') == 'static' or get_option('default_library') == 'both'
|
||||
cmakeconf.set('MESON_STATIC_TARGET', '''
|
||||
add_library(jsoncpp_static IMPORTED STATIC)
|
||||
set_target_properties(jsoncpp_static PROPERTIES
|
||||
IMPORTED_LOCATION "''' + join_paths('${PACKAGE_PREFIX_DIR}', get_option('libdir'), static_name) + '''"
|
||||
INTERFACE_INCLUDE_DIRECTORIES "''' + join_paths('${PACKAGE_PREFIX_DIR}', get_option('includedir')) + '")')
|
||||
endif
|
||||
|
||||
import('cmake').configure_package_config_file(
|
||||
name: 'jsoncpp',
|
||||
input: 'jsoncppConfig.cmake.meson.in',
|
||||
configuration: cmakeconf)
|
||||
install_data('jsoncpp-namespaced-targets.cmake', install_dir : join_paths(get_option('libdir'), 'cmake', jsoncpp_lib.name()))
|
||||
|
||||
# for libraries bundling jsoncpp
|
||||
jsoncpp_dep = declare_dependency(
|
||||
include_directories : jsoncpp_include_directories,
|
||||
|
@ -132,7 +132,6 @@ if(BUILD_SHARED_LIBS)
|
||||
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})
|
||||
@ -166,7 +165,6 @@ if(BUILD_STATIC_LIBS)
|
||||
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})
|
||||
@ -193,7 +191,6 @@ if(BUILD_OBJECT_LIBS)
|
||||
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})
|
||||
|
@ -587,8 +587,7 @@ bool Reader::decodeDouble(Token& token) {
|
||||
|
||||
bool Reader::decodeDouble(Token& token, Value& decoded) {
|
||||
double value = 0;
|
||||
String buffer(token.start_, token.end_);
|
||||
IStringStream is(buffer);
|
||||
IStringStream is(String(token.start_, token.end_));
|
||||
if (!(is >> value)) {
|
||||
if (value == std::numeric_limits<double>::max())
|
||||
value = std::numeric_limits<double>::infinity();
|
||||
@ -1622,8 +1621,7 @@ bool OurReader::decodeDouble(Token& token) {
|
||||
|
||||
bool OurReader::decodeDouble(Token& token, Value& decoded) {
|
||||
double value = 0;
|
||||
const String buffer(token.start_, token.end_);
|
||||
IStringStream is(buffer);
|
||||
IStringStream is(String(token.start_, token.end_));
|
||||
if (!(is >> value)) {
|
||||
if (value == std::numeric_limits<double>::max())
|
||||
value = std::numeric_limits<double>::infinity();
|
||||
@ -1963,6 +1961,22 @@ void CharReaderBuilder::setDefaults(Json::Value* settings) {
|
||||
(*settings)["skipBom"] = true;
|
||||
//! [CharReaderBuilderDefaults]
|
||||
}
|
||||
// static
|
||||
void CharReaderBuilder::ecma404Mode(Json::Value* settings) {
|
||||
//! [CharReaderBuilderECMA404Mode]
|
||||
(*settings)["allowComments"] = false;
|
||||
(*settings)["allowTrailingCommas"] = false;
|
||||
(*settings)["strictRoot"] = false;
|
||||
(*settings)["allowDroppedNullPlaceholders"] = false;
|
||||
(*settings)["allowNumericKeys"] = false;
|
||||
(*settings)["allowSingleQuotes"] = false;
|
||||
(*settings)["stackLimit"] = 1000;
|
||||
(*settings)["failIfExtra"] = true;
|
||||
(*settings)["rejectDupKeys"] = false;
|
||||
(*settings)["allowSpecialFloats"] = false;
|
||||
(*settings)["skipBom"] = false;
|
||||
//! [CharReaderBuilderECMA404Mode]
|
||||
}
|
||||
|
||||
std::vector<CharReader::StructuredError>
|
||||
CharReader::getStructuredErrors() const {
|
||||
@ -1981,7 +1995,7 @@ bool parseFromStream(CharReader::Factory const& fact, IStream& sin, Value* root,
|
||||
String* errs) {
|
||||
OStringStream ssin;
|
||||
ssin << sin.rdbuf();
|
||||
String doc = ssin.str();
|
||||
String doc = std::move(ssin).str();
|
||||
char const* begin = doc.data();
|
||||
char const* end = begin + doc.size();
|
||||
// Note that we do not actually need a null-terminator.
|
||||
|
@ -1092,6 +1092,9 @@ Value const* Value::find(char const* begin, char const* end) const {
|
||||
return nullptr;
|
||||
return &(*it).second;
|
||||
}
|
||||
Value const* Value::find(const String& key) const {
|
||||
return find(key.data(), key.data() + key.length());
|
||||
}
|
||||
Value* Value::demand(char const* begin, char const* end) {
|
||||
JSON_ASSERT_MESSAGE(type() == nullValue || type() == objectValue,
|
||||
"in Json::Value::demand(begin, end): requires "
|
||||
@ -1105,7 +1108,7 @@ const Value& Value::operator[](const char* key) const {
|
||||
return *found;
|
||||
}
|
||||
Value const& Value::operator[](const String& key) const {
|
||||
Value const* found = find(key.data(), key.data() + key.length());
|
||||
Value const* found = find(key);
|
||||
if (!found)
|
||||
return nullSingleton();
|
||||
return *found;
|
||||
@ -1205,7 +1208,7 @@ bool Value::removeIndex(ArrayIndex index, Value* removed) {
|
||||
return false;
|
||||
}
|
||||
if (removed)
|
||||
*removed = it->second;
|
||||
*removed = std::move(it->second);
|
||||
ArrayIndex oldSize = size();
|
||||
// shift left all items left, into the place of the "removed"
|
||||
for (ArrayIndex i = index; i < (oldSize - 1); ++i) {
|
||||
|
@ -1251,7 +1251,7 @@ String writeString(StreamWriter::Factory const& factory, Value const& root) {
|
||||
OStringStream sout;
|
||||
StreamWriterPtr const writer(factory.newStreamWriter());
|
||||
writer->write(root, &sout);
|
||||
return sout.str();
|
||||
return std::move(sout).str();
|
||||
}
|
||||
|
||||
OStream& operator<<(OStream& sout, Value const& root) {
|
||||
|
@ -220,11 +220,20 @@ JSONTEST_FIXTURE_LOCAL(ValueTest, objects) {
|
||||
JSONTEST_ASSERT(foundId != nullptr);
|
||||
JSONTEST_ASSERT_EQUAL(Json::Value(1234), *foundId);
|
||||
|
||||
const std::string stringIdKey = "id";
|
||||
const Json::Value* stringFoundId = object1_.find(stringIdKey);
|
||||
JSONTEST_ASSERT(stringFoundId != nullptr);
|
||||
JSONTEST_ASSERT_EQUAL(Json::Value(1234), *stringFoundId);
|
||||
|
||||
const char unknownIdKey[] = "unknown id";
|
||||
const Json::Value* foundUnknownId =
|
||||
object1_.find(unknownIdKey, unknownIdKey + strlen(unknownIdKey));
|
||||
JSONTEST_ASSERT_EQUAL(nullptr, foundUnknownId);
|
||||
|
||||
const std::string stringUnknownIdKey = "unknown id";
|
||||
const Json::Value* stringFoundUnknownId = object1_.find(stringUnknownIdKey);
|
||||
JSONTEST_ASSERT_EQUAL(nullptr, stringFoundUnknownId);
|
||||
|
||||
// Access through demand()
|
||||
const char yetAnotherIdKey[] = "yet another id";
|
||||
const Json::Value* foundYetAnotherId =
|
||||
|
Loading…
Reference in New Issue
Block a user