diff --git a/CMakeLists.txt b/CMakeLists.txt index 2b81049..02a2dae 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -80,26 +80,28 @@ endif () ]==============================================================================================] set(fetch_packages "") -# Fetch/Find nlohmann_json -# TODO: Remove when bumping cmake >= 3.24 -if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.24) - FetchContent_Declare(nlohmann_json - GIT_REPOSITORY https://github.com/nlohmann/json - GIT_TAG ${JSON_FETCH_VERSION} - FIND_PACKAGE_ARGS - ) - list(APPEND fetch_packages nlohmann_json) -else () - # Try to get system installed version - find_package(nlohmann_json QUIET) - if (NOT nlohmann_json_FOUND) - # If failed fetch the desired version - FetchContent_Declare(nlohmann_json - GIT_REPOSITORY https://github.com/nlohmann/json - GIT_TAG ${JSON_FETCH_VERSION} - ) - list(APPEND fetch_packages nlohmann_json) - endif () +if (NOT TARGET nlohmann_json) + # Fetch/Find nlohmann_json + # TODO: Remove when bumping cmake >= 3.24 + if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.24) + FetchContent_Declare(nlohmann_json + GIT_REPOSITORY https://github.com/nlohmann/json + GIT_TAG ${JSON_FETCH_VERSION} + FIND_PACKAGE_ARGS + ) + list(APPEND fetch_packages nlohmann_json) + else () + # Try to get system installed version + find_package(nlohmann_json QUIET) + if (NOT nlohmann_json_FOUND) + # If failed fetch the desired version + FetchContent_Declare(nlohmann_json + GIT_REPOSITORY https://github.com/nlohmann/json + GIT_TAG ${JSON_FETCH_VERSION} + ) + list(APPEND fetch_packages nlohmann_json) + endif () + endif () endif () # Handle configure flags diff --git a/README.md b/README.md index e9b80ed..93751e7 100644 --- a/README.md +++ b/README.md @@ -74,7 +74,7 @@ types, depending on if the schema type is "integer" or "number". Bignum This library is based on Niels Lohmann's JSON-library and thus has a build-dependency to it. -Currently at least version **3.6.0** of NLohmann's JSON library +Currently at least version **3.8.0** of NLohmann's JSON library is required. Various methods using CMake can be used to build this project. diff --git a/src/json-patch.hpp b/src/json-patch.hpp index 80fe1df..39a579b 100644 --- a/src/json-patch.hpp +++ b/src/json-patch.hpp @@ -28,10 +28,13 @@ public: json_patch &replace(const json::json_pointer &, json value); json_patch &remove(const json::json_pointer &); + json &get_json() { return j_; } + const json &get_json() const { return j_; } + operator json() const { return j_; } private: - json j_; + json j_ = nlohmann::json::array(); static void validateJsonPatch(json const &patch); }; diff --git a/src/json-validator.cpp b/src/json-validator.cpp index 43fc588..438ced0 100644 --- a/src/json-validator.cpp +++ b/src/json-validator.cpp @@ -436,12 +436,12 @@ class logical_combination : public schema for (auto &s : subschemata_) { first_error_handler esub; - json_patch old_patch(patch); + auto oldPatchSize = patch.get_json().size(); s->validate(ptr, instance, patch, esub); if (!esub) count++; else - patch = old_patch; + patch.get_json().get_ref().resize(oldPatchSize); if (is_validate_complete(instance, ptr, e, esub, count)) return; diff --git a/src/smtp-address-validator.cpp b/src/smtp-address-validator.cpp index 14dfae7..5ddd811 100644 --- a/src/smtp-address-validator.cpp +++ b/src/smtp-address-validator.cpp @@ -669,10 +669,6 @@ static const short _address_eof_trans[] = { 1278, 1279, 1280, 1281, 1282, 1283, 0}; static const int address_start = 1; -static const int address_first_final = 196; -static const int address_error = 0; - -static const int address_en_main = 1; bool is_address(const char *p, const char *pe) {