Merge branch 'develop' into feature/issue698

This commit is contained in:
Niels Lohmann 2017-10-02 17:47:53 +02:00
commit f89f8b2d0b
No known key found for this signature in database
GPG key ID: 7F3CEA63AE251B69
8 changed files with 44 additions and 21 deletions

View file

@ -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.

View file

@ -2,7 +2,7 @@ version: '{build}'
os:
- Visual Studio 2015
- Previous Visual Studio 2017
- Visual Studio 2017
environment:
matrix:

View file

@ -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';

View file

@ -1 +1 @@
<a target="_blank" href="https://wandbox.org/permlink/doaPmtdJ277jNm9C"><b>online</b></a>
<a target="_blank" href="https://wandbox.org/permlink/atomVJKVgMTIh1iT"><b>online</b></a>

View file

@ -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
@ -3576,7 +3576,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<std::ptrdiff_t>::min();
difference_type m_it = (std::numeric_limits<std::ptrdiff_t>::min)();
};
/*!
@ -6316,7 +6316,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))));
@ -9755,7 +9755,7 @@ class basic_json
, "incompatible pointer type");
// delegate the call to get_impl_ptr<>() const
return get_impl_ptr(static_cast<const PointerType>(nullptr));
return get_impl_ptr(static_cast<PointerType>(nullptr));
}
/*!
@ -12814,6 +12814,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)
@ -12997,6 +12998,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)

View file

@ -739,13 +739,13 @@ TEST_CASE("CBOR")
{
SECTION("no byte follows")
{
CHECK_THROWS_AS(json::from_cbor(std::vector<uint8_t>({0xf9})), json::parse_error);
CHECK_THROWS_AS(json::from_cbor(std::vector<uint8_t>({0xf9})), json::parse_error&);
CHECK_THROWS_WITH(json::from_cbor(std::vector<uint8_t>({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<uint8_t>({0xf9, 0x7c})), json::parse_error);
CHECK_THROWS_AS(json::from_cbor(std::vector<uint8_t>({0xf9, 0x7c})), json::parse_error&);
CHECK_THROWS_WITH(json::from_cbor(std::vector<uint8_t>({0xf9, 0x7c})),
"[json.exception.parse_error.110] parse error at 3: unexpected end of input");
}

View file

@ -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<char>(bom[0] + i0));
s.push_back(static_cast<char>(bom[1] + i1));
s.push_back(static_cast<char>(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&);
}
}
}

View file

@ -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());
}
}
}