From 737816d0cd53c755f64f78c7a4cf6e32e2120b62 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Thu, 14 Sep 2017 17:31:14 +0200 Subject: [PATCH 1/7] :construction_worker: another try with Travis --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 50331a1f..4f423e2f 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -2,7 +2,7 @@ version: '{build}' os: - Visual Studio 2015 - - Previous Visual Studio 2017 + - Visual Studio 2017 environment: matrix: From 647711fad1e2dd08b14f62d6c4c4b3c563ee4863 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Thu, 14 Sep 2017 17:31:28 +0200 Subject: [PATCH 2/7] :white_check_mark: improved test coverage --- test/src/unit-json_pointer.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/src/unit-json_pointer.cpp b/test/src/unit-json_pointer.cpp index a9fbc613..ee55dc58 100644 --- a/test/src/unit-json_pointer.cpp +++ b/test/src/unit-json_pointer.cpp @@ -430,4 +430,23 @@ TEST_CASE("JSON pointers") CHECK(json::json_pointer(ptr).to_string() == ptr); } } + + SECTION("conversion") + { + SECTION("array") + { + json j; + // all numbers -> array + j["/12"_json_pointer] = 0; + CHECK(j.is_array()); + } + + SECTION("object") + { + json j; + // contains a number, but is not a number -> object + j["/a12"_json_pointer] = 0; + CHECK(j.is_object()); + } + } } From ec60ff3451c21de4a4bb8563ed611ae047bff9b5 Mon Sep 17 00:00:00 2001 From: gregmarr Date: Tue, 26 Sep 2017 08:39:38 -0700 Subject: [PATCH 3/7] Add info for the vcpkg package. --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8052f6bf..d160d38e 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,9 @@ If you are using the [Meson Build System](http://mesonbuild.com), then you can w If you are using [Conan](https://www.conan.io/) to manage your dependencies, merely add `jsonformoderncpp/x.y.z@vthiery/stable` to your `conanfile.py`'s requires, where `x.y.z` is the release version you want to use. Please file issues [here](https://github.com/vthiery/conan-jsonformoderncpp/issues) if you experience problems with the packages. -If you are using [hunter](https://github.com/ruslo/hunter/) on your project for external dependencies, then you can use the [nlohman_json package](https://github.com/ruslo/hunter/wiki/pkg.nlohmann_json). Please see the hunter project for any issues regarding the packaging. +If you are using [hunter](https://github.com/ruslo/hunter/) on your project for external dependencies, then you can use the [nlohmann_json package](https://github.com/ruslo/hunter/wiki/pkg.nlohmann_json). Please see the hunter project for any issues regarding the packaging. + +If you are using [vcpkg](https://github.com/Microsoft/vcpkg/) on your project for external dependencies, then you can use the [nlohmann-json package](https://github.com/Microsoft/vcpkg/tree/master/ports/nlohmann-json). Please see the vcpkg project for any issues regarding the packaging. :warning: [Version 3.0.0](https://github.com/nlohmann/json/wiki/Road-toward-3.0.0) is currently under development. Branch `develop` is used for the ongoing work and is probably **unstable**. Please use the `master` branch for the last stable version 2.1.1. From 1a66527dca9220878a64a9df8169427102a52902 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Sat, 30 Sep 2017 10:18:18 +0200 Subject: [PATCH 4/7] :memo: fixed documentation #745 --- doc/examples/operator_deserialize.cpp | 2 +- doc/examples/operator_deserialize.link | 2 +- src/json.hpp | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/doc/examples/operator_deserialize.cpp b/doc/examples/operator_deserialize.cpp index 06656b65..b553cf67 100644 --- a/doc/examples/operator_deserialize.cpp +++ b/doc/examples/operator_deserialize.cpp @@ -18,7 +18,7 @@ int main() // create JSON value and read the serialization from the stream json j; - j << ss; + ss >> j; // serialize JSON std::cout << std::setw(2) << j << '\n'; diff --git a/doc/examples/operator_deserialize.link b/doc/examples/operator_deserialize.link index 4544a65b..407b40e1 100644 --- a/doc/examples/operator_deserialize.link +++ b/doc/examples/operator_deserialize.link @@ -1 +1 @@ -online \ No newline at end of file +online \ No newline at end of file diff --git a/src/json.hpp b/src/json.hpp index 10af0e0d..ce2fb44e 100644 --- a/src/json.hpp +++ b/src/json.hpp @@ -12818,6 +12818,7 @@ class basic_json future version of the library. Please use @ref operator<<(std::ostream&, const basic_json&) instead; that is, replace calls like `j >> o;` with `o << j;`. + @since version 1.0.0; deprecated since version 3.0.0 */ JSON_DEPRECATED friend std::ostream& operator>>(const basic_json& j, std::ostream& o) @@ -13001,6 +13002,7 @@ class basic_json future version of the library. Please use @ref operator>>(std::istream&, basic_json&) instead; that is, replace calls like `j << i;` with `i >> j;`. + @since version 1.0.0; deprecated since version 3.0.0 */ JSON_DEPRECATED friend std::istream& operator<<(basic_json& j, std::istream& i) From 8af49d4be5a3d454c7f0db3974e8c700f48eca9d Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Sat, 30 Sep 2017 11:00:26 +0200 Subject: [PATCH 5/7] :rotating_light: removing compiler warnings #755 --- src/json.hpp | 8 ++++---- test/src/unit-cbor.cpp | 4 ++-- test/src/unit-deserialization.cpp | 22 +++++++++++----------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/json.hpp b/src/json.hpp index ce2fb44e..6a6cbb85 100644 --- a/src/json.hpp +++ b/src/json.hpp @@ -62,7 +62,7 @@ SOFTWARE. #if (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__) < 30400 #error "unsupported Clang version - see https://github.com/nlohmann/json#supported-compilers" #endif -#elif defined(__GNUC__) +#elif defined(__GNUC__) && !(defined(__ICC) || defined(__INTEL_COMPILER)) #if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) < 40900 #error "unsupported GCC version - see https://github.com/nlohmann/json#supported-compilers" #endif @@ -6320,7 +6320,7 @@ class serializer */ static constexpr std::size_t bytes_following(const uint8_t u) { - return ((0 <= u and u <= 127) ? 0 + return ((u <= 127) ? 0 : ((192 <= u and u <= 223) ? 1 : ((224 <= u and u <= 239) ? 2 : ((240 <= u and u <= 247) ? 3 : std::string::npos)))); @@ -6660,7 +6660,7 @@ class serializer return; } - const bool is_negative = x < 0; + const auto is_negative = std::signbit(x); std::size_t i = 0; // spare 1 byte for '\0' @@ -9759,7 +9759,7 @@ class basic_json , "incompatible pointer type"); // delegate the call to get_impl_ptr<>() const - return get_impl_ptr(static_cast(nullptr)); + return get_impl_ptr(static_cast(nullptr)); } /*! diff --git a/test/src/unit-cbor.cpp b/test/src/unit-cbor.cpp index 4ec03f23..02f3d482 100644 --- a/test/src/unit-cbor.cpp +++ b/test/src/unit-cbor.cpp @@ -739,13 +739,13 @@ TEST_CASE("CBOR") { SECTION("no byte follows") { - CHECK_THROWS_AS(json::from_cbor(std::vector({0xf9})), json::parse_error); + CHECK_THROWS_AS(json::from_cbor(std::vector({0xf9})), json::parse_error&); CHECK_THROWS_WITH(json::from_cbor(std::vector({0xf9})), "[json.exception.parse_error.110] parse error at 2: unexpected end of input"); } SECTION("only one byte follows") { - CHECK_THROWS_AS(json::from_cbor(std::vector({0xf9, 0x7c})), json::parse_error); + CHECK_THROWS_AS(json::from_cbor(std::vector({0xf9, 0x7c})), json::parse_error&); CHECK_THROWS_WITH(json::from_cbor(std::vector({0xf9, 0x7c})), "[json.exception.parse_error.110] parse error at 3: unexpected end of input"); } diff --git a/test/src/unit-deserialization.cpp b/test/src/unit-deserialization.cpp index 9f574807..2798f102 100644 --- a/test/src/unit-deserialization.cpp +++ b/test/src/unit-deserialization.cpp @@ -451,11 +451,11 @@ TEST_CASE("deserialization") SECTION("BOM only") { - CHECK_THROWS_AS(json::parse(bom), json::parse_error); + CHECK_THROWS_AS(json::parse(bom), json::parse_error&); CHECK_THROWS_WITH(json::parse(bom), "[json.exception.parse_error.101] parse error at 1: syntax error - unexpected end of input; expected '[', '{', or a literal"); - CHECK_THROWS_AS(json::parse(std::istringstream(bom)), json::parse_error); + CHECK_THROWS_AS(json::parse(std::istringstream(bom)), json::parse_error&); CHECK_THROWS_WITH(json::parse(std::istringstream(bom)), "[json.exception.parse_error.101] parse error at 1: syntax error - unexpected end of input; expected '[', '{', or a literal"); } @@ -468,22 +468,22 @@ TEST_CASE("deserialization") SECTION("2 byte of BOM") { - CHECK_THROWS_AS(json::parse(bom.substr(0, 2)), json::parse_error); + CHECK_THROWS_AS(json::parse(bom.substr(0, 2)), json::parse_error&); CHECK_THROWS_WITH(json::parse(bom), "[json.exception.parse_error.101] parse error at 1: syntax error - unexpected end of input; expected '[', '{', or a literal"); - CHECK_THROWS_AS(json::parse(std::istringstream(bom.substr(0, 2))), json::parse_error); + CHECK_THROWS_AS(json::parse(std::istringstream(bom.substr(0, 2))), json::parse_error&); CHECK_THROWS_WITH(json::parse(std::istringstream(bom)), "[json.exception.parse_error.101] parse error at 1: syntax error - unexpected end of input; expected '[', '{', or a literal"); } SECTION("1 byte of BOM") { - CHECK_THROWS_AS(json::parse(bom.substr(0, 1)), json::parse_error); + CHECK_THROWS_AS(json::parse(bom.substr(0, 1)), json::parse_error&); CHECK_THROWS_WITH(json::parse(bom), "[json.exception.parse_error.101] parse error at 1: syntax error - unexpected end of input; expected '[', '{', or a literal"); - CHECK_THROWS_AS(json::parse(std::istringstream(bom.substr(0, 1))), json::parse_error); + CHECK_THROWS_AS(json::parse(std::istringstream(bom.substr(0, 1))), json::parse_error&); CHECK_THROWS_WITH(json::parse(std::istringstream(bom)), "[json.exception.parse_error.101] parse error at 1: syntax error - unexpected end of input; expected '[', '{', or a literal"); } @@ -504,9 +504,9 @@ TEST_CASE("deserialization") CAPTURE(i2); std::string s = ""; - s.push_back(bom[0] + i0); - s.push_back(bom[1] + i1); - s.push_back(bom[2] + i2); + s.push_back(static_cast(bom[0] + i0)); + s.push_back(static_cast(bom[1] + i1)); + s.push_back(static_cast(bom[2] + i2)); if (i0 == 0 and i1 == 0 and i2 == 0) { @@ -517,8 +517,8 @@ TEST_CASE("deserialization") else { // any variation is an error - CHECK_THROWS_AS(json::parse(s + "null"), json::parse_error); - CHECK_THROWS_AS(json::parse(std::istringstream(s + "null")), json::parse_error); + CHECK_THROWS_AS(json::parse(s + "null"), json::parse_error&); + CHECK_THROWS_AS(json::parse(std::istringstream(s + "null")), json::parse_error&); } } } From 1df836ce401a33d0c38cf45860cdc1de983aab40 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Sun, 1 Oct 2017 15:48:29 +0200 Subject: [PATCH 6/7] :rewind: removed call to std::signbit #761 --- src/json.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/json.hpp b/src/json.hpp index 6a6cbb85..12ae3b52 100644 --- a/src/json.hpp +++ b/src/json.hpp @@ -6660,7 +6660,7 @@ class serializer return; } - const auto is_negative = std::signbit(x); + const bool is_negative = x < 0; std::size_t i = 0; // spare 1 byte for '\0' From 8be303d4fb959c15ae81617bb959900d5f2d2e91 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Mon, 2 Oct 2017 13:54:14 +0200 Subject: [PATCH 7/7] :checkered_flag: fixing a min() call for MSVC #762 --- src/json.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/json.hpp b/src/json.hpp index 12ae3b52..b781b98c 100644 --- a/src/json.hpp +++ b/src/json.hpp @@ -3580,7 +3580,7 @@ class primitive_iterator_t static constexpr difference_type end_value = begin_value + 1; /// iterator as signed integer type - difference_type m_it = std::numeric_limits::min(); + difference_type m_it = (std::numeric_limits::min)(); }; /*!