mirror of
https://github.com/open-source-parsers/jsoncpp.git
synced 2025-12-12 04:55:19 +01:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b4e88e35be | ||
|
|
a888632781 |
@@ -2,6 +2,7 @@
|
||||
Checks: 'google-readability-casting,modernize-deprecated-headers,modernize-loop-convert,modernize-use-auto,modernize-use-default-member-init,modernize-use-using,readability-else-after-return,readability-redundant-member-init,readability-redundant-string-cstr'
|
||||
WarningsAsErrors: ''
|
||||
HeaderFilterRegex: ''
|
||||
AnalyzeTemporaryDtors: false
|
||||
FormatStyle: none
|
||||
CheckOptions:
|
||||
- key: modernize-use-using.IgnoreMacros
|
||||
|
||||
4
.gitignore
vendored
4
.gitignore
vendored
@@ -55,7 +55,3 @@ compile_commands.json
|
||||
|
||||
# temps
|
||||
/version
|
||||
|
||||
# Bazel output paths
|
||||
/bazel-*
|
||||
/MODULE.bazel.lock
|
||||
|
||||
33
BUILD.bazel
33
BUILD.bazel
@@ -1,29 +1,7 @@
|
||||
licenses(["unencumbered"]) # Public Domain or MIT
|
||||
|
||||
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
|
||||
|
||||
exports_files(["LICENSE"])
|
||||
|
||||
bool_flag(
|
||||
name = "use_exception",
|
||||
build_setting_default = False,
|
||||
)
|
||||
|
||||
config_setting(
|
||||
name = "use_exception_cfg",
|
||||
flag_values = {":use_exception": "true"},
|
||||
)
|
||||
|
||||
bool_flag(
|
||||
name = "has_int64",
|
||||
build_setting_default = True,
|
||||
)
|
||||
|
||||
config_setting(
|
||||
name = "has_int64_cfg",
|
||||
flag_values = {":has_int64": "true"},
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "jsoncpp",
|
||||
srcs = [
|
||||
@@ -44,13 +22,10 @@ cc_library(
|
||||
"include/json/version.h",
|
||||
"include/json/writer.h",
|
||||
],
|
||||
defines = select({
|
||||
":use_exception_cfg": ["JSON_USE_EXCEPTION=1"],
|
||||
"//conditions:default": ["JSON_USE_EXCEPTION=0"],
|
||||
}) + select({
|
||||
":has_int64_cfg": ["JSON_HAS_INT64"],
|
||||
"//conditions:default": [],
|
||||
}),
|
||||
copts = [
|
||||
"-DJSON_USE_EXCEPTION=0",
|
||||
"-DJSON_HAS_INT64",
|
||||
],
|
||||
includes = ["include"],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [":private"],
|
||||
|
||||
@@ -55,13 +55,12 @@ endif()
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
|
||||
|
||||
project(jsoncpp
|
||||
# Note: version must be updated in four places when doing a release. This
|
||||
# Note: version must be updated in three places when doing a release. This
|
||||
# annoying process ensures that amalgamate, CMake, and meson all report the
|
||||
# correct version.
|
||||
# 1. ./meson.build
|
||||
# 2. ./include/json/version.h
|
||||
# 3. ./CMakeLists.txt
|
||||
# 4. ./MODULE.bazel
|
||||
# IMPORTANT: also update the PROJECT_SOVERSION!!
|
||||
VERSION 1.9.7 # <major>[.<minor>[.<patch>[.<tweak>]]]
|
||||
LANGUAGES CXX)
|
||||
|
||||
19
MODULE.bazel
19
MODULE.bazel
@@ -1,19 +0,0 @@
|
||||
module(
|
||||
name = "jsoncpp",
|
||||
|
||||
# Note: version must be updated in four places when doing a release. This
|
||||
# annoying process ensures that amalgamate, CMake, and meson all report the
|
||||
# correct version.
|
||||
# 1. /meson.build
|
||||
# 2. /include/json/version.h
|
||||
# 3. /CMakeLists.txt
|
||||
# 4. /MODULE.bazel
|
||||
# IMPORTANT: also update the SOVERSION!!
|
||||
version = "1.9.7",
|
||||
compatibility_level = 1,
|
||||
)
|
||||
|
||||
bazel_dep(
|
||||
name = "bazel_skylib",
|
||||
version = "1.7.1",
|
||||
)
|
||||
10
README.md
10
README.md
@@ -1,6 +1,6 @@
|
||||
# JsonCpp
|
||||
|
||||
[](https://conan.io/center/recipes/jsoncpp)
|
||||
[](https://bintray.com/theirix/conan-repo/jsoncpp%3Atheirix)
|
||||
[](https://github.com/open-source-parsers/jsoncpp/blob/master/LICENSE)
|
||||
[](http://open-source-parsers.github.io/jsoncpp-docs/doxygen/index.html)
|
||||
[](https://coveralls.io/github/open-source-parsers/jsoncpp?branch=master)
|
||||
@@ -52,14 +52,6 @@ You can download and install JsonCpp using the [vcpkg](https://github.com/Micros
|
||||
|
||||
The JsonCpp port in vcpkg is kept up to date by Microsoft team members and community contributors. If the version is out of date, please [create an issue or pull request](https://github.com/Microsoft/vcpkg) on the vcpkg repository.
|
||||
|
||||
### Conan package manager
|
||||
|
||||
You can download and install JsonCpp using the [Conan](https://conan.io/) package manager:
|
||||
|
||||
conan install -r conancenter --requires="jsoncpp/[*]" --build=missing
|
||||
|
||||
The JsonCpp package in Conan Center is kept up to date by [ConanCenterIndex](https://github.com/conan-io/conan-center-index) contributors. If the version is out of date, please create an issue or pull request on the Conan Center Index repository.
|
||||
|
||||
### Amalgamated source
|
||||
https://github.com/open-source-parsers/jsoncpp/wiki/Amalgamated-(Possibly-outdated)
|
||||
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
cc_binary(
|
||||
name = "readFromStream_ok",
|
||||
srcs = ["readFromStream/readFromStream.cpp"],
|
||||
deps = ["//:jsoncpp"],
|
||||
args = ["$(location :readFromStream/withComment.json)"],
|
||||
data = ["readFromStream/withComment.json"],
|
||||
)
|
||||
|
||||
cc_binary(
|
||||
name = "readFromStream_err",
|
||||
srcs = ["readFromStream/readFromStream.cpp"],
|
||||
deps = ["//:jsoncpp"],
|
||||
args = ["$(location :readFromStream/errorFormat.json)"],
|
||||
data = ["readFromStream/errorFormat.json"],
|
||||
)
|
||||
|
||||
cc_binary(
|
||||
name = "readFromString",
|
||||
srcs = ["readFromString/readFromString.cpp"],
|
||||
deps = ["//:jsoncpp"],
|
||||
)
|
||||
|
||||
cc_binary(
|
||||
name = "streamWrite",
|
||||
srcs = ["streamWrite/streamWrite.cpp"],
|
||||
deps = ["//:jsoncpp"],
|
||||
)
|
||||
|
||||
cc_binary(
|
||||
name = "stringWrite",
|
||||
srcs = ["stringWrite/stringWrite.cpp"],
|
||||
deps = ["//:jsoncpp"],
|
||||
)
|
||||
@@ -39,10 +39,6 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if __cplusplus >= 201703L
|
||||
#define JSONCPP_HAS_STRING_VIEW 1
|
||||
#endif
|
||||
|
||||
#include <array>
|
||||
#include <exception>
|
||||
#include <map>
|
||||
@@ -50,10 +46,6 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#ifdef JSONCPP_HAS_STRING_VIEW
|
||||
#include <string_view>
|
||||
#endif
|
||||
|
||||
// Disable warning C4251: <data member>: <type> needs to have dll-interface to
|
||||
// be used by...
|
||||
#if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
|
||||
@@ -350,9 +342,6 @@ public:
|
||||
*/
|
||||
Value(const StaticString& value);
|
||||
Value(const String& value);
|
||||
#ifdef JSONCPP_HAS_STRING_VIEW
|
||||
Value(std::string_view value);
|
||||
#endif
|
||||
Value(bool value);
|
||||
Value(std::nullptr_t ptr) = delete;
|
||||
Value(const Value& other);
|
||||
@@ -395,12 +384,6 @@ public:
|
||||
* \return false if !string. (Seg-fault if str or end are NULL.)
|
||||
*/
|
||||
bool getString(char const** begin, char const** end) const;
|
||||
#ifdef JSONCPP_HAS_STRING_VIEW
|
||||
/** Get string_view of string-value.
|
||||
* \return false if !string. (Seg-fault if str is NULL.)
|
||||
*/
|
||||
bool getString(std::string_view* str) const;
|
||||
#endif
|
||||
Int asInt() const;
|
||||
UInt asUInt() const;
|
||||
#if defined(JSON_HAS_INT64)
|
||||
@@ -487,15 +470,6 @@ public:
|
||||
bool insert(ArrayIndex index, const Value& newValue);
|
||||
bool insert(ArrayIndex index, Value&& newValue);
|
||||
|
||||
#ifdef JSONCPP_HAS_STRING_VIEW
|
||||
/// Access an object value by name, create a null member if it does not exist.
|
||||
/// \param key may contain embedded nulls.
|
||||
Value& operator[](std::string_view key);
|
||||
/// Access an object value by name, returns null if there is no member with
|
||||
/// that name.
|
||||
/// \param key may contain embedded nulls.
|
||||
const Value& operator[](std::string_view key) const;
|
||||
#else
|
||||
/// Access an object value by name, create a null member if it does not exist.
|
||||
/// \note Because of our implementation, keys are limited to 2^30 -1 chars.
|
||||
/// Exceeding that will cause an exception.
|
||||
@@ -510,7 +484,6 @@ public:
|
||||
/// that name.
|
||||
/// \param key may contain embedded nulls.
|
||||
const Value& operator[](const String& key) const;
|
||||
#endif
|
||||
/** \brief Access an object value by name, create a null member if it does not
|
||||
* exist.
|
||||
*
|
||||
@@ -524,24 +497,18 @@ public:
|
||||
* \endcode
|
||||
*/
|
||||
Value& operator[](const StaticString& key);
|
||||
#ifdef JSONCPP_HAS_STRING_VIEW
|
||||
/// Return the member named key if it exist, defaultValue otherwise.
|
||||
/// \note deep copy
|
||||
Value get(std::string_view key, const Value& defaultValue) const;
|
||||
#else
|
||||
/// Return the member named key if it exist, defaultValue otherwise.
|
||||
/// \note deep copy
|
||||
Value get(const char* key, const Value& defaultValue) const;
|
||||
/// Return the member named key if it exist, defaultValue otherwise.
|
||||
/// \note deep copy
|
||||
/// \param key may contain embedded nulls.
|
||||
Value get(const String& key, const Value& defaultValue) const;
|
||||
#endif
|
||||
/// Return the member named key if it exist, defaultValue otherwise.
|
||||
/// \note deep copy
|
||||
/// \note key may contain embedded nulls.
|
||||
Value get(const char* begin, const char* end,
|
||||
const Value& defaultValue) const;
|
||||
/// Return the member named key if it exist, defaultValue otherwise.
|
||||
/// \note deep copy
|
||||
/// \param key may contain embedded nulls.
|
||||
Value get(const String& key, const Value& defaultValue) const;
|
||||
/// Most general and efficient version of isMember()const, get()const,
|
||||
/// and operator[]const
|
||||
/// \note As stated elsewhere, behavior is undefined if (end-begin) >= 2^30
|
||||
@@ -549,29 +516,6 @@ public:
|
||||
/// Most general and efficient version of isMember()const, get()const,
|
||||
/// and operator[]const
|
||||
Value const* find(const String& key) const;
|
||||
|
||||
/// Calls find and only returns a valid pointer if the type is found
|
||||
template <typename T, bool (T::*TMemFn)() const>
|
||||
Value const* findValue(const String& key) const {
|
||||
Value const* found = find(key);
|
||||
if (!found || !(found->*TMemFn)())
|
||||
return nullptr;
|
||||
return found;
|
||||
}
|
||||
|
||||
Value const* findNull(const String& key) const;
|
||||
Value const* findBool(const String& key) const;
|
||||
Value const* findInt(const String& key) const;
|
||||
Value const* findInt64(const String& key) const;
|
||||
Value const* findUInt(const String& key) const;
|
||||
Value const* findUInt64(const String& key) const;
|
||||
Value const* findIntegral(const String& key) const;
|
||||
Value const* findDouble(const String& key) const;
|
||||
Value const* findNumeric(const String& key) const;
|
||||
Value const* findString(const String& key) const;
|
||||
Value const* findArray(const String& key) const;
|
||||
Value const* findObject(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.
|
||||
@@ -581,28 +525,20 @@ public:
|
||||
/// Do nothing if it did not exist.
|
||||
/// \pre type() is objectValue or nullValue
|
||||
/// \post type() is unchanged
|
||||
#if JSONCPP_HAS_STRING_VIEW
|
||||
void removeMember(std::string_view key);
|
||||
#else
|
||||
void removeMember(const char* key);
|
||||
/// Same as removeMember(const char*)
|
||||
/// \param key may contain embedded nulls.
|
||||
void removeMember(const String& key);
|
||||
#endif
|
||||
/// Same as removeMember(const char* begin, const char* end, Value* removed),
|
||||
/// but 'key' is null-terminated.
|
||||
bool removeMember(const char* key, Value* removed);
|
||||
/** \brief Remove the named map member.
|
||||
*
|
||||
* Update 'removed' iff removed.
|
||||
* \param key may contain embedded nulls.
|
||||
* \return true iff removed (no exceptions)
|
||||
*/
|
||||
#if JSONCPP_HAS_STRING_VIEW
|
||||
bool removeMember(std::string_view key, Value* removed);
|
||||
#else
|
||||
bool removeMember(String const& key, Value* removed);
|
||||
/// Same as removeMember(const char* begin, const char* end, Value* removed),
|
||||
/// but 'key' is null-terminated.
|
||||
bool removeMember(const char* key, Value* removed);
|
||||
#endif
|
||||
/// Same as removeMember(String const& key, Value* removed)
|
||||
bool removeMember(const char* begin, const char* end, Value* removed);
|
||||
/** \brief Remove the indexed array element.
|
||||
@@ -613,18 +549,12 @@ public:
|
||||
*/
|
||||
bool removeIndex(ArrayIndex index, Value* removed);
|
||||
|
||||
#ifdef JSONCPP_HAS_STRING_VIEW
|
||||
/// Return true if the object has a member named key.
|
||||
/// \param key may contain embedded nulls.
|
||||
bool isMember(std::string_view key) const;
|
||||
#else
|
||||
/// Return true if the object has a member named key.
|
||||
/// \note 'key' must be null-terminated.
|
||||
bool isMember(const char* key) const;
|
||||
/// Return true if the object has a member named key.
|
||||
/// \param key may contain embedded nulls.
|
||||
bool isMember(const String& key) const;
|
||||
#endif
|
||||
/// Same as isMember(String const& key)const
|
||||
bool isMember(const char* begin, const char* end) const;
|
||||
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
#ifndef JSON_VERSION_H_INCLUDED
|
||||
#define JSON_VERSION_H_INCLUDED
|
||||
|
||||
// Note: version must be updated in four places when doing a release. This
|
||||
// Note: version must be updated in three places when doing a release. This
|
||||
// annoying process ensures that amalgamate, CMake, and meson all report the
|
||||
// correct version.
|
||||
// 1. /meson.build
|
||||
// 2. /include/json/version.h
|
||||
// 3. /CMakeLists.txt
|
||||
// 4. /MODULE.bazel
|
||||
// IMPORTANT: also update the SOVERSION!!
|
||||
|
||||
#define JSONCPP_VERSION_STRING "1.9.7"
|
||||
|
||||
@@ -2,13 +2,12 @@ project(
|
||||
'jsoncpp',
|
||||
'cpp',
|
||||
|
||||
# Note: version must be updated in four places when doing a release. This
|
||||
# Note: version must be updated in three places when doing a release. This
|
||||
# annoying process ensures that amalgamate, CMake, and meson all report the
|
||||
# correct version.
|
||||
# 1. /meson.build
|
||||
# 2. /include/json/version.h
|
||||
# 3. /CMakeLists.txt
|
||||
# 4. /MODULE.bazel
|
||||
# IMPORTANT: also update the SOVERSION!!
|
||||
version : '1.9.7',
|
||||
default_options : [
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
cc_binary(
|
||||
name = "jsontestrunner",
|
||||
srcs = ["main.cpp"],
|
||||
deps = ["//:jsoncpp"],
|
||||
visibility = ["//test:__pkg__"],
|
||||
)
|
||||
@@ -16,7 +16,6 @@
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <istream>
|
||||
#include <iterator>
|
||||
#include <limits>
|
||||
#include <memory>
|
||||
#include <set>
|
||||
@@ -144,12 +143,7 @@ bool Reader::readValue() {
|
||||
// after calling readValue(). parse() executes one nodes_.push(), so > instead
|
||||
// of >=.
|
||||
if (nodes_.size() > stackLimit_g)
|
||||
#if JSON_USE_EXCEPTION
|
||||
throwRuntimeError("Exceeded stackLimit in readValue().");
|
||||
#else
|
||||
// throwRuntimeError aborts. Don't abort here.
|
||||
return false;
|
||||
#endif
|
||||
|
||||
Token token;
|
||||
readTokenSkippingComments(token);
|
||||
|
||||
@@ -17,10 +17,6 @@
|
||||
#include <sstream>
|
||||
#include <utility>
|
||||
|
||||
#ifdef JSONCPP_HAS_STRING_VIEW
|
||||
#include <string_view>
|
||||
#endif
|
||||
|
||||
// Provide implementation equivalent of std::snprintf for older _MSC compilers
|
||||
#if defined(_MSC_VER) && _MSC_VER < 1900
|
||||
#include <stdarg.h>
|
||||
@@ -424,14 +420,6 @@ Value::Value(const String& value) {
|
||||
value.data(), static_cast<unsigned>(value.length()));
|
||||
}
|
||||
|
||||
#ifdef JSONCPP_HAS_STRING_VIEW
|
||||
Value::Value(std::string_view value) {
|
||||
initBasic(stringValue, true);
|
||||
value_.string_ = duplicateAndPrefixStringValue(
|
||||
value.data(), static_cast<unsigned>(value.length()));
|
||||
}
|
||||
#endif
|
||||
|
||||
Value::Value(const StaticString& value) {
|
||||
initBasic(stringValue);
|
||||
value_.string_ = const_cast<char*>(value.c_str());
|
||||
@@ -639,21 +627,6 @@ bool Value::getString(char const** begin, char const** end) const {
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifdef JSONCPP_HAS_STRING_VIEW
|
||||
bool Value::getString(std::string_view* str) const {
|
||||
if (type() != stringValue)
|
||||
return false;
|
||||
if (value_.string_ == nullptr)
|
||||
return false;
|
||||
const char* begin;
|
||||
unsigned length;
|
||||
decodePrefixedString(this->isAllocated(), this->value_.string_, &length,
|
||||
&begin);
|
||||
*str = std::string_view(begin, length);
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
String Value::asString() const {
|
||||
switch (type()) {
|
||||
case nullValue:
|
||||
@@ -1129,61 +1102,12 @@ Value const* Value::find(char const* begin, char const* end) const {
|
||||
Value const* Value::find(const String& key) const {
|
||||
return find(key.data(), key.data() + key.length());
|
||||
}
|
||||
|
||||
Value const* Value::findNull(const String& key) const {
|
||||
return findValue<Value, &Value::isNull>(key);
|
||||
}
|
||||
Value const* Value::findBool(const String& key) const {
|
||||
return findValue<Value, &Value::isBool>(key);
|
||||
}
|
||||
Value const* Value::findInt(const String& key) const {
|
||||
return findValue<Value, &Value::isInt>(key);
|
||||
}
|
||||
Value const* Value::findInt64(const String& key) const {
|
||||
return findValue<Value, &Value::isInt64>(key);
|
||||
}
|
||||
Value const* Value::findUInt(const String& key) const {
|
||||
return findValue<Value, &Value::isUInt>(key);
|
||||
}
|
||||
Value const* Value::findUInt64(const String& key) const {
|
||||
return findValue<Value, &Value::isUInt64>(key);
|
||||
}
|
||||
Value const* Value::findIntegral(const String& key) const {
|
||||
return findValue<Value, &Value::isIntegral>(key);
|
||||
}
|
||||
Value const* Value::findDouble(const String& key) const {
|
||||
return findValue<Value, &Value::isDouble>(key);
|
||||
}
|
||||
Value const* Value::findNumeric(const String& key) const {
|
||||
return findValue<Value, &Value::isNumeric>(key);
|
||||
}
|
||||
Value const* Value::findString(const String& key) const {
|
||||
return findValue<Value, &Value::isString>(key);
|
||||
}
|
||||
Value const* Value::findArray(const String& key) const {
|
||||
return findValue<Value, &Value::isArray>(key);
|
||||
}
|
||||
Value const* Value::findObject(const String& key) const {
|
||||
return findValue<Value, &Value::isObject>(key);
|
||||
}
|
||||
|
||||
Value* Value::demand(char const* begin, char const* end) {
|
||||
JSON_ASSERT_MESSAGE(type() == nullValue || type() == objectValue,
|
||||
"in Json::Value::demand(begin, end): requires "
|
||||
"objectValue or nullValue");
|
||||
return &resolveReference(begin, end);
|
||||
}
|
||||
#ifdef JSONCPP_HAS_STRING_VIEW
|
||||
const Value& Value::operator[](std::string_view key) const {
|
||||
Value const* found = find(key.data(), key.data() + key.length());
|
||||
if (!found)
|
||||
return nullSingleton();
|
||||
return *found;
|
||||
}
|
||||
Value& Value::operator[](std::string_view key) {
|
||||
return resolveReference(key.data(), key.data() + key.length());
|
||||
}
|
||||
#else
|
||||
const Value& Value::operator[](const char* key) const {
|
||||
Value const* found = find(key, key + strlen(key));
|
||||
if (!found)
|
||||
@@ -1204,7 +1128,6 @@ Value& Value::operator[](const char* key) {
|
||||
Value& Value::operator[](const String& key) {
|
||||
return resolveReference(key.data(), key.data() + key.length());
|
||||
}
|
||||
#endif
|
||||
|
||||
Value& Value::operator[](const StaticString& key) {
|
||||
return resolveReference(key.c_str());
|
||||
@@ -1244,18 +1167,12 @@ Value Value::get(char const* begin, char const* end,
|
||||
Value const* found = find(begin, end);
|
||||
return !found ? defaultValue : *found;
|
||||
}
|
||||
#ifdef JSONCPP_HAS_STRING_VIEW
|
||||
Value Value::get(std::string_view key, const Value& defaultValue) const {
|
||||
return get(key.data(), key.data() + key.length(), defaultValue);
|
||||
}
|
||||
#else
|
||||
Value Value::get(char const* key, Value const& defaultValue) const {
|
||||
return get(key, key + strlen(key), defaultValue);
|
||||
}
|
||||
Value Value::get(String const& key, Value const& defaultValue) const {
|
||||
return get(key.data(), key.data() + key.length(), defaultValue);
|
||||
}
|
||||
#endif
|
||||
|
||||
bool Value::removeMember(const char* begin, const char* end, Value* removed) {
|
||||
if (type() != objectValue) {
|
||||
@@ -1271,31 +1188,12 @@ bool Value::removeMember(const char* begin, const char* end, Value* removed) {
|
||||
value_.map_->erase(it);
|
||||
return true;
|
||||
}
|
||||
#ifdef JSONCPP_HAS_STRING_VIEW
|
||||
bool Value::removeMember(std::string_view key, Value* removed) {
|
||||
return removeMember(key.data(), key.data() + key.length(), removed);
|
||||
}
|
||||
#else
|
||||
bool Value::removeMember(const char* key, Value* removed) {
|
||||
return removeMember(key, key + strlen(key), removed);
|
||||
}
|
||||
bool Value::removeMember(String const& key, Value* removed) {
|
||||
return removeMember(key.data(), key.data() + key.length(), removed);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef JSONCPP_HAS_STRING_VIEW
|
||||
void Value::removeMember(std::string_view key) {
|
||||
JSON_ASSERT_MESSAGE(type() == nullValue || type() == objectValue,
|
||||
"in Json::Value::removeMember(): requires objectValue");
|
||||
if (type() == nullValue)
|
||||
return;
|
||||
|
||||
CZString actualKey(key.data(), unsigned(key.length()),
|
||||
CZString::noDuplication);
|
||||
value_.map_->erase(actualKey);
|
||||
}
|
||||
#else
|
||||
void Value::removeMember(const char* key) {
|
||||
JSON_ASSERT_MESSAGE(type() == nullValue || type() == objectValue,
|
||||
"in Json::Value::removeMember(): requires objectValue");
|
||||
@@ -1306,7 +1204,6 @@ void Value::removeMember(const char* key) {
|
||||
value_.map_->erase(actualKey);
|
||||
}
|
||||
void Value::removeMember(const String& key) { removeMember(key.c_str()); }
|
||||
#endif
|
||||
|
||||
bool Value::removeIndex(ArrayIndex index, Value* removed) {
|
||||
if (type() != arrayValue) {
|
||||
@@ -1336,18 +1233,12 @@ bool Value::isMember(char const* begin, char const* end) const {
|
||||
Value const* value = find(begin, end);
|
||||
return nullptr != value;
|
||||
}
|
||||
#ifdef JSONCPP_HAS_STRING_VIEW
|
||||
bool Value::isMember(std::string_view key) const {
|
||||
return isMember(key.data(), key.data() + key.length());
|
||||
}
|
||||
#else
|
||||
bool Value::isMember(char const* key) const {
|
||||
return isMember(key, key + strlen(key));
|
||||
}
|
||||
bool Value::isMember(String const& key) const {
|
||||
return isMember(key.data(), key.data() + key.length());
|
||||
}
|
||||
#endif
|
||||
|
||||
Value::Members Value::getMemberNames() const {
|
||||
JSON_ASSERT_MESSAGE(
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
cc_test(
|
||||
name = "jsoncpp_test",
|
||||
srcs = [
|
||||
"jsontest.cpp",
|
||||
"jsontest.h",
|
||||
"main.cpp",
|
||||
"fuzz.h",
|
||||
"fuzz.cpp",
|
||||
],
|
||||
deps = ["//:jsoncpp"],
|
||||
)
|
||||
@@ -11,6 +11,10 @@
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
namespace Json {
|
||||
class Exception;
|
||||
}
|
||||
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
|
||||
Json::CharReaderBuilder builder;
|
||||
|
||||
@@ -41,14 +45,10 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
|
||||
|
||||
Json::Value root;
|
||||
const auto data_str = reinterpret_cast<const char*>(data);
|
||||
#if JSON_USE_EXCEPTION
|
||||
try {
|
||||
#endif // JSON_USE_EXCEPTION
|
||||
reader->parse(data_str, data_str + size, &root, nullptr);
|
||||
#if JSON_USE_EXCEPTION
|
||||
} catch (Json::Exception const&) {
|
||||
}
|
||||
#endif // JSON_USE_EXCEPTION
|
||||
// Whether it succeeded or not doesn't matter.
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -228,8 +228,6 @@ TestResult& checkStringEqual(TestResult& result, const Json::String& expected,
|
||||
JsonTest::ToJsonString(actual), __FILE__, \
|
||||
__LINE__, #expected " == " #actual)
|
||||
|
||||
#if JSON_USE_EXCEPTION
|
||||
|
||||
/// \brief Asserts that a given expression throws an exception
|
||||
#define JSONTEST_ASSERT_THROWS(expr) \
|
||||
do { \
|
||||
@@ -244,8 +242,6 @@ TestResult& checkStringEqual(TestResult& result, const Json::String& expected,
|
||||
"expected exception thrown: " #expr); \
|
||||
} while (0)
|
||||
|
||||
#endif // JSON_USE_EXCEPTION
|
||||
|
||||
/// \brief Begin a fixture test case.
|
||||
#define JSONTEST_FIXTURE(FixtureType, name) \
|
||||
class Test##FixtureType##name : public FixtureType { \
|
||||
|
||||
@@ -76,8 +76,6 @@ struct ValueTest : JsonTest::TestCase {
|
||||
Json::Value float_{0.00390625f};
|
||||
Json::Value array1_;
|
||||
Json::Value object1_;
|
||||
Json::Value object2_;
|
||||
Json::Value object3_;
|
||||
Json::Value emptyString_{""};
|
||||
Json::Value string1_{"a"};
|
||||
Json::Value string_{"sometext with space"};
|
||||
@@ -87,34 +85,6 @@ struct ValueTest : JsonTest::TestCase {
|
||||
ValueTest() {
|
||||
array1_.append(1234);
|
||||
object1_["id"] = 1234;
|
||||
|
||||
// object2 with matching values
|
||||
object2_["null"] = Json::nullValue;
|
||||
object2_["bool"] = true;
|
||||
object2_["int"] = Json::Int{Json::Value::maxInt};
|
||||
object2_["int64"] = Json::Int64{Json::Value::maxInt64};
|
||||
object2_["uint"] = Json::UInt{Json::Value::maxUInt};
|
||||
object2_["uint64"] = Json::UInt64{Json::Value::maxUInt64};
|
||||
object2_["integral"] = 1234;
|
||||
object2_["double"] = 1234.56789;
|
||||
object2_["numeric"] = 0.12345f;
|
||||
object2_["string"] = "string";
|
||||
object2_["array"] = Json::arrayValue;
|
||||
object2_["object"] = Json::objectValue;
|
||||
|
||||
// object3 with not matching values
|
||||
object3_["object"] = Json::nullValue;
|
||||
object3_["null"] = true;
|
||||
object3_["bool"] = Json::Int{Json::Value::maxInt};
|
||||
object3_["int"] = "not_an_int";
|
||||
object3_["int64"] = "not_an_int64";
|
||||
object3_["uint"] = "not_an_uint";
|
||||
object3_["uin64"] = "not_an_uint64";
|
||||
object3_["integral"] = 1234.56789;
|
||||
object3_["double"] = false;
|
||||
object3_["numeric"] = "string";
|
||||
object3_["string"] = Json::arrayValue;
|
||||
object3_["array"] = Json::objectValue;
|
||||
}
|
||||
|
||||
struct IsCheck {
|
||||
@@ -264,62 +234,6 @@ JSONTEST_FIXTURE_LOCAL(ValueTest, objects) {
|
||||
const Json::Value* stringFoundUnknownId = object1_.find(stringUnknownIdKey);
|
||||
JSONTEST_ASSERT_EQUAL(nullptr, stringFoundUnknownId);
|
||||
|
||||
// Access through find<Type>()
|
||||
const Json::Value* nullFound = object2_.findNull("null");
|
||||
JSONTEST_ASSERT(nullFound != nullptr);
|
||||
JSONTEST_ASSERT_EQUAL(Json::nullValue, *nullFound);
|
||||
JSONTEST_ASSERT(object3_.findNull("null") == nullptr);
|
||||
|
||||
const Json::Value* boolFound = object2_.findBool("bool");
|
||||
JSONTEST_ASSERT(boolFound != nullptr);
|
||||
JSONTEST_ASSERT_EQUAL(true, *boolFound);
|
||||
JSONTEST_ASSERT(object3_.findBool("bool") == nullptr);
|
||||
|
||||
const Json::Value* intFound = object2_.findInt("int");
|
||||
JSONTEST_ASSERT(intFound != nullptr);
|
||||
JSONTEST_ASSERT_EQUAL(Json::Int{Json::Value::maxInt}, *intFound);
|
||||
JSONTEST_ASSERT(object3_.findInt("int") == nullptr);
|
||||
|
||||
const Json::Value* int64Found = object2_.findInt64("int64");
|
||||
JSONTEST_ASSERT(int64Found != nullptr);
|
||||
JSONTEST_ASSERT_EQUAL(Json::Int64{Json::Value::maxInt64}, *int64Found);
|
||||
JSONTEST_ASSERT(object3_.findInt64("int64") == nullptr);
|
||||
|
||||
const Json::Value* uintFound = object2_.findUInt("uint");
|
||||
JSONTEST_ASSERT(uintFound != nullptr);
|
||||
JSONTEST_ASSERT_EQUAL(Json::UInt{Json::Value::maxUInt}, *uintFound);
|
||||
JSONTEST_ASSERT(object3_.findUInt("uint") == nullptr);
|
||||
|
||||
const Json::Value* uint64Found = object2_.findUInt64("uint64");
|
||||
JSONTEST_ASSERT(uint64Found != nullptr);
|
||||
JSONTEST_ASSERT_EQUAL(Json::UInt64{Json::Value::maxUInt64}, *uint64Found);
|
||||
JSONTEST_ASSERT(object3_.findUInt64("uint64") == nullptr);
|
||||
|
||||
const Json::Value* integralFound = object2_.findIntegral("integral");
|
||||
JSONTEST_ASSERT(integralFound != nullptr);
|
||||
JSONTEST_ASSERT_EQUAL(1234, *integralFound);
|
||||
JSONTEST_ASSERT(object3_.findIntegral("integral") == nullptr);
|
||||
|
||||
const Json::Value* doubleFound = object2_.findDouble("double");
|
||||
JSONTEST_ASSERT(doubleFound != nullptr);
|
||||
JSONTEST_ASSERT_EQUAL(1234.56789, *doubleFound);
|
||||
JSONTEST_ASSERT(object3_.findDouble("double") == nullptr);
|
||||
|
||||
const Json::Value* numericFound = object2_.findNumeric("numeric");
|
||||
JSONTEST_ASSERT(numericFound != nullptr);
|
||||
JSONTEST_ASSERT_EQUAL(0.12345f, *numericFound);
|
||||
JSONTEST_ASSERT(object3_.findNumeric("numeric") == nullptr);
|
||||
|
||||
const Json::Value* stringFound = object2_.findString("string");
|
||||
JSONTEST_ASSERT(stringFound != nullptr);
|
||||
JSONTEST_ASSERT_EQUAL(std::string{"string"}, *stringFound);
|
||||
JSONTEST_ASSERT(object3_.findString("string") == nullptr);
|
||||
|
||||
const Json::Value* arrayFound = object2_.findArray("array");
|
||||
JSONTEST_ASSERT(arrayFound != nullptr);
|
||||
JSONTEST_ASSERT_EQUAL(Json::arrayValue, *arrayFound);
|
||||
JSONTEST_ASSERT(object3_.findArray("array") == nullptr);
|
||||
|
||||
// Access through demand()
|
||||
const char yetAnotherIdKey[] = "yet another id";
|
||||
const Json::Value* foundYetAnotherId =
|
||||
@@ -1888,7 +1802,7 @@ JSONTEST_FIXTURE_LOCAL(ValueTest, typeChecksThrowExceptions) {
|
||||
JSONTEST_ASSERT_THROWS(objVal.asBool());
|
||||
JSONTEST_ASSERT_THROWS(arrVal.asBool());
|
||||
|
||||
#endif // JSON_USE_EXCEPTION
|
||||
#endif
|
||||
}
|
||||
|
||||
JSONTEST_FIXTURE_LOCAL(ValueTest, offsetAccessors) {
|
||||
@@ -3323,8 +3237,6 @@ JSONTEST_FIXTURE_LOCAL(CharReaderTest, parseWithDetailError) {
|
||||
}
|
||||
|
||||
JSONTEST_FIXTURE_LOCAL(CharReaderTest, parseWithStackLimit) {
|
||||
#if JSON_USE_EXCEPTION
|
||||
|
||||
Json::CharReaderBuilder b;
|
||||
Json::Value root;
|
||||
char const doc[] = R"({ "property" : "value" })";
|
||||
@@ -3344,8 +3256,6 @@ JSONTEST_FIXTURE_LOCAL(CharReaderTest, parseWithStackLimit) {
|
||||
JSONTEST_ASSERT_THROWS(
|
||||
reader->parse(doc, doc + std::strlen(doc), &root, &errs));
|
||||
}
|
||||
|
||||
#endif // JSON_USE_EXCEPTION
|
||||
}
|
||||
|
||||
JSONTEST_FIXTURE_LOCAL(CharReaderTest, testOperator) {
|
||||
@@ -3965,8 +3875,6 @@ JSONTEST_FIXTURE_LOCAL(IteratorTest, indexes) {
|
||||
}
|
||||
|
||||
JSONTEST_FIXTURE_LOCAL(IteratorTest, constness) {
|
||||
#if JSON_USE_EXCEPTION
|
||||
|
||||
Json::Value const v;
|
||||
JSONTEST_ASSERT_THROWS(
|
||||
Json::Value::iterator it(v.begin())); // Compile, but throw.
|
||||
@@ -3988,8 +3896,6 @@ JSONTEST_FIXTURE_LOCAL(IteratorTest, constness) {
|
||||
}
|
||||
Json::String expected = R"(" 9","10","11",)";
|
||||
JSONTEST_ASSERT_STRING_EQUAL(expected, out.str());
|
||||
|
||||
#endif // JSON_USE_EXCEPTION
|
||||
}
|
||||
|
||||
struct RValueTest : JsonTest::TestCase {};
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
filegroup(
|
||||
name = "expected",
|
||||
srcs = glob(["data/**", "jsonchecker/**"], exclude=["**/*.json"]),
|
||||
)
|
||||
|
||||
[py_test(
|
||||
name = "runjson_%s_test" % "_".join(f.split("/")),
|
||||
srcs = ["runjsontests.py"],
|
||||
main = "runjsontests.py",
|
||||
args = [
|
||||
"--with-json-checker",
|
||||
"$(location //src/jsontestrunner:jsontestrunner)",
|
||||
"$(location :%s)" % f,
|
||||
],
|
||||
data = [
|
||||
"//src/jsontestrunner:jsontestrunner",
|
||||
":expected",
|
||||
":%s" % f,
|
||||
],
|
||||
) for f in glob(["**/*.json"])]
|
||||
@@ -66,51 +66,38 @@ class FailError(Exception):
|
||||
def __init__(self, msg):
|
||||
super(Exception, self).__init__(msg)
|
||||
|
||||
def runAllTests(jsontest_executable_path, input_path = None,
|
||||
def runAllTests(jsontest_executable_path, input_dir = None,
|
||||
use_valgrind=False, with_json_checker=False,
|
||||
writerClass='StyledWriter'):
|
||||
if not input_path:
|
||||
input_path = os.path.join(os.getcwd(), 'data')
|
||||
if not input_dir:
|
||||
input_dir = os.path.join(os.getcwd(), 'data')
|
||||
tests = glob(os.path.join(input_dir, '*.json'))
|
||||
if with_json_checker:
|
||||
all_tests = glob(os.path.join(input_dir, '../jsonchecker', '*.json'))
|
||||
# These tests fail with strict json support, but pass with JsonCPP's
|
||||
# extra leniency features. When adding a new exclusion to this list,
|
||||
# remember to add the test's number and reasoning here:
|
||||
known = ["fail{}.json".format(n) for n in [
|
||||
4, 9, # fail because we allow trailing commas
|
||||
7, # fails because we allow commas after close
|
||||
8, # fails because we allow extra close
|
||||
10, # fails because we allow extra values after close
|
||||
13, # fails because we allow leading zeroes in numbers
|
||||
18, # fails because we allow deeply nested values
|
||||
25, # fails because we allow tab characters in strings
|
||||
27, # fails because we allow string line breaks
|
||||
]]
|
||||
test_jsonchecker = [ test for test in all_tests
|
||||
if os.path.basename(test) not in known]
|
||||
|
||||
if os.path.isdir(input_path):
|
||||
tests = [
|
||||
os.path.normpath(os.path.abspath(test))
|
||||
for test in glob(os.path.join(input_path, '*.json'))
|
||||
]
|
||||
|
||||
if with_json_checker:
|
||||
tests += [
|
||||
os.path.normpath(os.path.abspath(test))
|
||||
for test in glob(os.path.join(input_path, '../jsonchecker', '*.json'))
|
||||
]
|
||||
else:
|
||||
tests = [input_path]
|
||||
|
||||
# These tests fail with strict json support, but pass with JsonCPP's
|
||||
# extra leniency features. When adding a new exclusion to this list,
|
||||
# remember to add the test's number and reasoning here:
|
||||
known = ["fail{}.json".format(n) for n in [
|
||||
4, 9, # fail because we allow trailing commas
|
||||
7, # fails because we allow commas after close
|
||||
8, # fails because we allow extra close
|
||||
10, # fails because we allow extra values after close
|
||||
13, # fails because we allow leading zeroes in numbers
|
||||
18, # fails because we allow deeply nested values
|
||||
25, # fails because we allow tab characters in strings
|
||||
27, # fails because we allow string line breaks
|
||||
]]
|
||||
|
||||
tests = [
|
||||
test for test in tests
|
||||
if os.path.basename(test) not in known or
|
||||
os.path.basename(os.path.dirname(test)) != "jsonchecker"
|
||||
]
|
||||
test_jsonchecker = []
|
||||
|
||||
failed_tests = []
|
||||
valgrind_path = use_valgrind and VALGRIND_CMD or ''
|
||||
for input_path in tests:
|
||||
for input_path in tests + test_jsonchecker:
|
||||
expect_failure = os.path.basename(input_path).startswith('fail')
|
||||
is_json_checker_test = os.path.basename(os.path.dirname(input_path)) == "jsonchecker"
|
||||
is_json_checker_test = input_path in test_jsonchecker
|
||||
is_parse_only = is_json_checker_test or expect_failure
|
||||
is_strict_test = ('_strict_' in os.path.basename(input_path)) or is_json_checker_test
|
||||
print('TESTING:', input_path, end=' ')
|
||||
|
||||
Reference in New Issue
Block a user