Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
json
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
json
Commits
a690a9f2
Unverified
Commit
a690a9f2
authored
Mar 29, 2017
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'develop' into feature/manual_lexer
parents
9578c0f7
c2e80a72
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
68 additions
and
33 deletions
+68
-33
Makefile
Makefile
+3
-0
json.hpp
src/json.hpp
+29
-11
unit-regression.cpp
test/src/unit-regression.cpp
+7
-6
unit-testsuites.cpp
test/src/unit-testsuites.cpp
+27
-14
unit-unicode.cpp
test/src/unit-unicode.cpp
+2
-2
No files found.
Makefile
View file @
a690a9f2
...
@@ -45,6 +45,7 @@ doctest:
...
@@ -45,6 +45,7 @@ doctest:
# -Wno-documentation-unknown-command: code uses user-defined commands like @complexity
# -Wno-documentation-unknown-command: code uses user-defined commands like @complexity
# -Wno-exit-time-destructors: warning in Catch code
# -Wno-exit-time-destructors: warning in Catch code
# -Wno-keyword-macro: unit-tests use "#define private public"
# -Wno-keyword-macro: unit-tests use "#define private public"
# -Wno-deprecated-declarations: the library deprecated some functions
# -Wno-weak-vtables: exception class is defined inline, but has virtual method
# -Wno-weak-vtables: exception class is defined inline, but has virtual method
# -Wno-range-loop-analysis: iterator_wrapper tests tests "for(const auto i...)"
# -Wno-range-loop-analysis: iterator_wrapper tests tests "for(const auto i...)"
pedantic_clang
:
pedantic_clang
:
...
@@ -55,6 +56,7 @@ pedantic_clang:
...
@@ -55,6 +56,7 @@ pedantic_clang:
-Wno-documentation-unknown-command
\
-Wno-documentation-unknown-command
\
-Wno-exit-time-destructors
\
-Wno-exit-time-destructors
\
-Wno-keyword-macro
\
-Wno-keyword-macro
\
-Wno-deprecated-declarations
\
-Wno-weak-vtables
\
-Wno-weak-vtables
\
-Wno-range-loop-analysis"
-Wno-range-loop-analysis"
...
@@ -62,6 +64,7 @@ pedantic_clang:
...
@@ -62,6 +64,7 @@ pedantic_clang:
pedantic_gcc
:
pedantic_gcc
:
$(MAKE)
json_unit
CXX
=
g++
CXXFLAGS
=
"
\
$(MAKE)
json_unit
CXX
=
g++
CXXFLAGS
=
"
\
-std=c++11
\
-std=c++11
\
-Wno-deprecated-declarations
\
-Werror
\
-Werror
\
-Wall -Wpedantic -Wextra
\
-Wall -Wpedantic -Wextra
\
-Walloca
\
-Walloca
\
...
...
src/json.hpp
View file @
a690a9f2
...
@@ -79,6 +79,15 @@ SOFTWARE.
...
@@ -79,6 +79,15 @@ SOFTWARE.
#pragma GCC diagnostic ignored "-Wdocumentation"
#pragma GCC diagnostic ignored "-Wdocumentation"
#endif
#endif
// allow for portable deprecation warnings
#if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__)
#define JSON_DEPRECATED __attribute__((deprecated))
#elif defined(_MSC_VER)
#define JSON_DEPRECATED __declspec(deprecated)
#else
#define JSON_DEPRECATED
#endif
// allow to disable exceptions
// allow to disable exceptions
#if (defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)) && not defined(JSON_NOEXCEPTION)
#if (defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)) && not defined(JSON_NOEXCEPTION)
#define JSON_THROW(exception) throw exception
#define JSON_THROW(exception) throw exception
...
@@ -7093,8 +7102,12 @@ class basic_json
...
@@ -7093,8 +7102,12 @@ class basic_json
/*!
/*!
@brief serialize to stream
@brief serialize to stream
@copydoc operator<<(std::ostream&, const basic_json&)
@deprecated This stream operator is deprecated and will be removed in a
future version of the library. Please use
@ref std::ostream& operator<<(std::ostream&, const basic_json&)
instead; that is, replace calls like `j >> o;` with `o << j;`.
*/
*/
JSON_DEPRECATED
friend
std
::
ostream
&
operator
>>
(
const
basic_json
&
j
,
std
::
ostream
&
o
)
friend
std
::
ostream
&
operator
>>
(
const
basic_json
&
j
,
std
::
ostream
&
o
)
{
{
return
o
<<
j
;
return
o
<<
j
;
...
@@ -7369,6 +7382,20 @@ class basic_json
...
@@ -7369,6 +7382,20 @@ class basic_json
/*!
/*!
@brief deserialize from stream
@brief deserialize from stream
@deprecated This stream operator is deprecated and will be removed in a
future version of the library. Please use
@ref std::istream& operator>>(std::istream&, basic_json&)
instead; that is, replace calls like `j << i;` with `i >> j;`.
*/
JSON_DEPRECATED
friend
std
::
istream
&
operator
<<
(
basic_json
&
j
,
std
::
istream
&
i
)
{
j
=
parser
(
i
).
parse
();
return
i
;
}
/*!
@brief deserialize from stream
Deserializes an input stream to a JSON value.
Deserializes an input stream to a JSON value.
...
@@ -7393,16 +7420,6 @@ class basic_json
...
@@ -7393,16 +7420,6 @@ class basic_json
@since version 1.0.0
@since version 1.0.0
*/
*/
friend
std
::
istream
&
operator
<<
(
basic_json
&
j
,
std
::
istream
&
i
)
{
j
=
parser
(
i
).
parse
(
false
);
return
i
;
}
/*!
@brief deserialize from stream
@copydoc operator<<(basic_json&, std::istream&)
*/
friend
std
::
istream
&
operator
>>
(
std
::
istream
&
i
,
basic_json
&
j
)
friend
std
::
istream
&
operator
>>
(
std
::
istream
&
i
,
basic_json
&
j
)
{
{
j
=
parser
(
i
).
parse
(
false
);
j
=
parser
(
i
).
parse
(
false
);
...
@@ -13259,5 +13276,6 @@ inline nlohmann::json::json_pointer operator "" _json_pointer(const char* s, std
...
@@ -13259,5 +13276,6 @@ inline nlohmann::json::json_pointer operator "" _json_pointer(const char* s, std
#undef JSON_TRY
#undef JSON_TRY
#undef JSON_LIKELY
#undef JSON_LIKELY
#undef JSON_UNLIKELY
#undef JSON_UNLIKELY
#undef JSON_DEPRECATED
#endif
#endif
test/src/unit-regression.cpp
View file @
a690a9f2
...
@@ -217,6 +217,7 @@ TEST_CASE("regression tests")
...
@@ -217,6 +217,7 @@ TEST_CASE("regression tests")
json
a
=
{
1
,
2
,
3
};
json
a
=
{
1
,
2
,
3
};
json
::
reverse_iterator
rit
=
++
a
.
rbegin
();
json
::
reverse_iterator
rit
=
++
a
.
rbegin
();
CHECK
(
*
rit
==
json
(
2
));
CHECK
(
*
rit
==
json
(
2
));
CHECK
(
rit
.
value
()
==
json
(
2
));
}
}
{
{
json
a
=
{
1
,
2
,
3
};
json
a
=
{
1
,
2
,
3
};
...
@@ -541,7 +542,7 @@ TEST_CASE("regression tests")
...
@@ -541,7 +542,7 @@ TEST_CASE("regression tests")
CAPTURE
(
filename
);
CAPTURE
(
filename
);
json
j
;
json
j
;
std
::
ifstream
f
(
filename
);
std
::
ifstream
f
(
filename
);
CHECK_NOTHROW
(
j
<<
f
);
CHECK_NOTHROW
(
f
>>
j
);
}
}
}
}
...
@@ -557,7 +558,7 @@ TEST_CASE("regression tests")
...
@@ -557,7 +558,7 @@ TEST_CASE("regression tests")
CAPTURE
(
filename
);
CAPTURE
(
filename
);
json
j
;
json
j
;
std
::
ifstream
f
(
filename
);
std
::
ifstream
f
(
filename
);
CHECK_NOTHROW
(
j
<<
f
);
CHECK_NOTHROW
(
f
>>
j
);
}
}
}
}
...
@@ -587,15 +588,15 @@ TEST_CASE("regression tests")
...
@@ -587,15 +588,15 @@ TEST_CASE("regression tests")
std
::
stringstream
ss
;
std
::
stringstream
ss
;
json
j
;
json
j
;
ss
<<
"123"
;
ss
<<
"123"
;
CHECK_NOTHROW
(
j
<<
ss
);
CHECK_NOTHROW
(
ss
>>
j
);
// see https://github.com/nlohmann/json/issues/367#issuecomment-262841893:
// see https://github.com/nlohmann/json/issues/367#issuecomment-262841893:
// ss is not at EOF; this yielded an error before the fix
// ss is not at EOF; this yielded an error before the fix
// (threw basic_string::append). No, it should just throw
// (threw basic_string::append). No, it should just throw
// a parse error because of the EOF.
// a parse error because of the EOF.
CHECK_THROWS_AS
(
j
<<
ss
,
json
::
parse_error
);
CHECK_THROWS_AS
(
ss
>>
j
,
json
::
parse_error
);
CHECK_THROWS_WITH
(
j
<<
ss
,
CHECK_THROWS_WITH
(
ss
>>
j
,
"[json.exception.parse_error.101] parse error at 1:
syntax
error - unexpected end of input"
);
"[json.exception.parse_error.101] parse error at 1:
parse
error - unexpected end of input"
);
}
}
SECTION
(
"issue #389 - Integer-overflow (OSS-Fuzz issue 267)"
)
SECTION
(
"issue #389 - Integer-overflow (OSS-Fuzz issue 267)"
)
...
...
test/src/unit-testsuites.cpp
View file @
a690a9f2
...
@@ -78,7 +78,8 @@ TEST_CASE("compliance tests from json.org")
...
@@ -78,7 +78,8 @@ TEST_CASE("compliance tests from json.org")
{
{
CAPTURE
(
filename
);
CAPTURE
(
filename
);
std
::
ifstream
f
(
filename
);
std
::
ifstream
f
(
filename
);
CHECK_THROWS_AS
(
json
::
parse
(
f
),
json
::
parse_error
);
json
j
;
CHECK_THROWS_AS
(
f
>>
j
,
json
::
parse_error
);
}
}
}
}
...
@@ -93,7 +94,8 @@ TEST_CASE("compliance tests from json.org")
...
@@ -93,7 +94,8 @@ TEST_CASE("compliance tests from json.org")
{
{
CAPTURE
(
filename
);
CAPTURE
(
filename
);
std
::
ifstream
f
(
filename
);
std
::
ifstream
f
(
filename
);
CHECK_NOTHROW
(
json
::
parse
(
f
));
json
j
;
CHECK_NOTHROW
(
f
>>
j
);
}
}
}
}
}
}
...
@@ -318,7 +320,7 @@ TEST_CASE("test suite from json-test-suite")
...
@@ -318,7 +320,7 @@ TEST_CASE("test suite from json-test-suite")
// strings in a JSON array
// strings in a JSON array
std
::
ifstream
f
(
"test/data/json_testsuite/sample.json"
);
std
::
ifstream
f
(
"test/data/json_testsuite/sample.json"
);
json
j
;
json
j
;
CHECK_NOTHROW
(
j
=
json
::
parse
(
f
)
);
CHECK_NOTHROW
(
f
>>
j
);
// the array has 3 elements
// the array has 3 elements
CHECK
(
j
.
size
()
==
3
);
CHECK
(
j
.
size
()
==
3
);
...
@@ -332,31 +334,36 @@ TEST_CASE("json.org examples")
...
@@ -332,31 +334,36 @@ TEST_CASE("json.org examples")
SECTION
(
"1.json"
)
SECTION
(
"1.json"
)
{
{
std
::
ifstream
f
(
"test/data/json.org/1.json"
);
std
::
ifstream
f
(
"test/data/json.org/1.json"
);
CHECK_NOTHROW
(
json
::
parse
(
f
));
json
j
;
CHECK_NOTHROW
(
f
>>
j
);
}
}
SECTION
(
"2.json"
)
SECTION
(
"2.json"
)
{
{
std
::
ifstream
f
(
"test/data/json.org/2.json"
);
std
::
ifstream
f
(
"test/data/json.org/2.json"
);
CHECK_NOTHROW
(
json
::
parse
(
f
));
json
j
;
CHECK_NOTHROW
(
f
>>
j
);
}
}
SECTION
(
"3.json"
)
SECTION
(
"3.json"
)
{
{
std
::
ifstream
f
(
"test/data/json.org/3.json"
);
std
::
ifstream
f
(
"test/data/json.org/3.json"
);
CHECK_NOTHROW
(
json
::
parse
(
f
));
json
j
;
CHECK_NOTHROW
(
f
>>
j
);
}
}
SECTION
(
"4.json"
)
SECTION
(
"4.json"
)
{
{
std
::
ifstream
f
(
"test/data/json.org/4.json"
);
std
::
ifstream
f
(
"test/data/json.org/4.json"
);
CHECK_NOTHROW
(
json
::
parse
(
f
));
json
j
;
CHECK_NOTHROW
(
f
>>
j
);
}
}
SECTION
(
"5.json"
)
SECTION
(
"5.json"
)
{
{
std
::
ifstream
f
(
"test/data/json.org/5.json"
);
std
::
ifstream
f
(
"test/data/json.org/5.json"
);
CHECK_NOTHROW
(
json
::
parse
(
f
));
json
j
;
CHECK_NOTHROW
(
f
>>
j
);
}
}
}
}
...
@@ -538,7 +545,8 @@ TEST_CASE("nst's JSONTestSuite")
...
@@ -538,7 +545,8 @@ TEST_CASE("nst's JSONTestSuite")
{
{
CAPTURE
(
filename
);
CAPTURE
(
filename
);
std
::
ifstream
f
(
filename
);
std
::
ifstream
f
(
filename
);
CHECK_NOTHROW
(
json
::
parse
(
f
));
json
j
;
CHECK_NOTHROW
(
f
>>
j
);
}
}
}
}
...
@@ -746,7 +754,8 @@ TEST_CASE("nst's JSONTestSuite")
...
@@ -746,7 +754,8 @@ TEST_CASE("nst's JSONTestSuite")
{
{
CAPTURE
(
filename
);
CAPTURE
(
filename
);
std
::
ifstream
f
(
filename
);
std
::
ifstream
f
(
filename
);
CHECK_THROWS_AS
(
json
::
parse
(
f
),
json
::
parse_error
);
json
j
;
CHECK_THROWS_AS
(
f
>>
j
,
json
::
parse_error
);
}
}
}
}
...
@@ -768,7 +777,8 @@ TEST_CASE("nst's JSONTestSuite")
...
@@ -768,7 +777,8 @@ TEST_CASE("nst's JSONTestSuite")
{
{
CAPTURE
(
filename
);
CAPTURE
(
filename
);
std
::
ifstream
f
(
filename
);
std
::
ifstream
f
(
filename
);
CHECK_NOTHROW
(
json
::
parse
(
f
));
json
j
;
CHECK_NOTHROW
(
f
>>
j
);
}
}
}
}
...
@@ -787,7 +797,8 @@ TEST_CASE("nst's JSONTestSuite")
...
@@ -787,7 +797,8 @@ TEST_CASE("nst's JSONTestSuite")
{
{
CAPTURE
(
filename
);
CAPTURE
(
filename
);
std
::
ifstream
f
(
filename
);
std
::
ifstream
f
(
filename
);
CHECK_THROWS_AS
(
json
::
parse
(
f
),
json
::
out_of_range
);
json
j
;
CHECK_THROWS_AS
(
f
>>
j
,
json
::
out_of_range
);
}
}
}
}
...
@@ -813,7 +824,8 @@ TEST_CASE("nst's JSONTestSuite")
...
@@ -813,7 +824,8 @@ TEST_CASE("nst's JSONTestSuite")
{
{
CAPTURE
(
filename
);
CAPTURE
(
filename
);
std
::
ifstream
f
(
filename
);
std
::
ifstream
f
(
filename
);
CHECK_THROWS_AS
(
json
::
parse
(
f
),
json
::
parse_error
);
json
j
;
CHECK_THROWS_AS
(
f
>>
j
,
json
::
parse_error
);
}
}
}
}
}
}
...
@@ -839,7 +851,8 @@ TEST_CASE("Big List of Naughty Strings")
...
@@ -839,7 +851,8 @@ TEST_CASE("Big List of Naughty Strings")
SECTION
(
"parsing blns.json"
)
SECTION
(
"parsing blns.json"
)
{
{
std
::
ifstream
f
(
"test/data/big-list-of-naughty-strings/blns.json"
);
std
::
ifstream
f
(
"test/data/big-list-of-naughty-strings/blns.json"
);
CHECK_NOTHROW
(
json
::
parse
(
f
));
json
j
;
CHECK_NOTHROW
(
f
>>
j
);
}
}
// check if parsed strings roundtrip
// check if parsed strings roundtrip
...
...
test/src/unit-unicode.cpp
View file @
a690a9f2
...
@@ -127,7 +127,7 @@ TEST_CASE("Unicode", "[hide]")
...
@@ -127,7 +127,7 @@ TEST_CASE("Unicode", "[hide]")
// strings in a JSON array
// strings in a JSON array
std
::
ifstream
f
(
"test/data/json_nlohmann_tests/all_unicode.json"
);
std
::
ifstream
f
(
"test/data/json_nlohmann_tests/all_unicode.json"
);
json
j
;
json
j
;
CHECK_NOTHROW
(
j
<<
f
);
CHECK_NOTHROW
(
f
>>
j
);
// the array has 1112064 + 1 elemnts (a terminating "null" value)
// the array has 1112064 + 1 elemnts (a terminating "null" value)
// Note: 1112064 = 0x1FFFFF code points - 2048 invalid values between
// Note: 1112064 = 0x1FFFFF code points - 2048 invalid values between
...
@@ -170,7 +170,7 @@ TEST_CASE("Unicode", "[hide]")
...
@@ -170,7 +170,7 @@ TEST_CASE("Unicode", "[hide]")
// read a file with a UTF-8 BOM
// read a file with a UTF-8 BOM
std
::
ifstream
f
(
"test/data/json_nlohmann_tests/bom.json"
);
std
::
ifstream
f
(
"test/data/json_nlohmann_tests/bom.json"
);
json
j
;
json
j
;
CHECK_NOTHROW
(
j
<<
f
);
CHECK_NOTHROW
(
f
>>
j
);
}
}
SECTION
(
"error for incomplete/wrong BOM"
)
SECTION
(
"error for incomplete/wrong BOM"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment