Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
json
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
json
Commits
ef40673a
Commit
ef40673a
authored
Oct 22, 2017
by
Niels Lohmann
Committed by
GitHub
Oct 22, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'develop' into develop-simplify-istream
parents
a8cc7a1b
33df3250
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
71 additions
and
30 deletions
+71
-30
doc/Doxyfile
doc/Doxyfile
+1
-1
src/json.hpp
src/json.hpp
+43
-27
test/CMakeLists.txt
test/CMakeLists.txt
+16
-0
test/src/unit-constructor1.cpp
test/src/unit-constructor1.cpp
+1
-1
test/src/unit-readme.cpp
test/src/unit-readme.cpp
+9
-0
test/src/unit-udt.cpp
test/src/unit-udt.cpp
+1
-1
No files found.
doc/Doxyfile
View file @
ef40673a
...
...
@@ -281,7 +281,7 @@ SKIP_FUNCTION_MACROS = YES
# Configuration options related to external references
#---------------------------------------------------------------------------
TAGFILES =
GENERATE_TAGFILE =
GENERATE_TAGFILE =
html/nlohmann_json.tag
ALLEXTERNALS = NO
EXTERNAL_GROUPS = YES
EXTERNAL_PAGES = YES
...
...
src/json.hpp
View file @
ef40673a
...
...
@@ -206,9 +206,9 @@ class exception : public std::exception
protected:
exception
(
int
id_
,
const
char
*
what_arg
)
:
id
(
id_
),
m
(
what_arg
)
{}
static
std
::
string
name
(
const
std
::
string
&
ename
,
int
id
)
static
std
::
string
name
(
const
std
::
string
&
ename
,
int
id
_
)
{
return
"[json.exception."
+
ename
+
"."
+
std
::
to_string
(
id
)
+
"] "
;
return
"[json.exception."
+
ename
+
"."
+
std
::
to_string
(
id
_
)
+
"] "
;
}
private:
...
...
@@ -264,18 +264,18 @@ class parse_error : public exception
public:
/*!
@brief create a parse error exception
@param[in] id
the id of the exception
@param[in] id
_
the id of the exception
@param[in] byte_ the byte index where the error occurred (or 0 if the
position cannot be determined)
@param[in] what_arg the explanatory string
@return parse_error object
*/
static
parse_error
create
(
int
id
,
std
::
size_t
byte_
,
const
std
::
string
&
what_arg
)
static
parse_error
create
(
int
id
_
,
std
::
size_t
byte_
,
const
std
::
string
&
what_arg
)
{
std
::
string
w
=
exception
::
name
(
"parse_error"
,
id
)
+
"parse error"
+
std
::
string
w
=
exception
::
name
(
"parse_error"
,
id
_
)
+
"parse error"
+
(
byte_
!=
0
?
(
" at "
+
std
::
to_string
(
byte_
))
:
""
)
+
": "
+
what_arg
;
return
parse_error
(
id
,
byte_
,
w
.
c_str
());
return
parse_error
(
id
_
,
byte_
,
w
.
c_str
());
}
/*!
...
...
@@ -334,10 +334,10 @@ caught.,invalid_iterator}
class
invalid_iterator
:
public
exception
{
public:
static
invalid_iterator
create
(
int
id
,
const
std
::
string
&
what_arg
)
static
invalid_iterator
create
(
int
id
_
,
const
std
::
string
&
what_arg
)
{
std
::
string
w
=
exception
::
name
(
"invalid_iterator"
,
id
)
+
what_arg
;
return
invalid_iterator
(
id
,
w
.
c_str
());
std
::
string
w
=
exception
::
name
(
"invalid_iterator"
,
id
_
)
+
what_arg
;
return
invalid_iterator
(
id
_
,
w
.
c_str
());
}
private:
...
...
@@ -385,10 +385,10 @@ caught.,type_error}
class
type_error
:
public
exception
{
public:
static
type_error
create
(
int
id
,
const
std
::
string
&
what_arg
)
static
type_error
create
(
int
id
_
,
const
std
::
string
&
what_arg
)
{
std
::
string
w
=
exception
::
name
(
"type_error"
,
id
)
+
what_arg
;
return
type_error
(
id
,
w
.
c_str
());
std
::
string
w
=
exception
::
name
(
"type_error"
,
id
_
)
+
what_arg
;
return
type_error
(
id
_
,
w
.
c_str
());
}
private:
...
...
@@ -428,10 +428,10 @@ caught.,out_of_range}
class
out_of_range
:
public
exception
{
public:
static
out_of_range
create
(
int
id
,
const
std
::
string
&
what_arg
)
static
out_of_range
create
(
int
id
_
,
const
std
::
string
&
what_arg
)
{
std
::
string
w
=
exception
::
name
(
"out_of_range"
,
id
)
+
what_arg
;
return
out_of_range
(
id
,
w
.
c_str
());
std
::
string
w
=
exception
::
name
(
"out_of_range"
,
id
_
)
+
what_arg
;
return
out_of_range
(
id
_
,
w
.
c_str
());
}
private:
...
...
@@ -466,10 +466,10 @@ caught.,other_error}
class
other_error
:
public
exception
{
public:
static
other_error
create
(
int
id
,
const
std
::
string
&
what_arg
)
static
other_error
create
(
int
id
_
,
const
std
::
string
&
what_arg
)
{
std
::
string
w
=
exception
::
name
(
"other_error"
,
id
)
+
what_arg
;
return
other_error
(
id
,
w
.
c_str
());
std
::
string
w
=
exception
::
name
(
"other_error"
,
id
_
)
+
what_arg
;
return
other_error
(
id
_
,
w
.
c_str
());
}
private:
...
...
@@ -3008,11 +3008,19 @@ class parser
{
case
token_type
:
:
begin_object
:
{
if
(
keep
and
(
not
callback
or
((
keep
=
callback
(
depth
++
,
parse_event_t
::
object_start
,
result
))))
)
if
(
keep
)
{
// explicitly set result to object to cope with {}
result
.
m_type
=
value_t
::
object
;
result
.
m_value
=
value_t
::
object
;
if
(
callback
)
{
keep
=
callback
(
depth
++
,
parse_event_t
::
object_start
,
result
);
}
if
(
not
callback
or
keep
)
{
// explicitly set result to object to cope with {}
result
.
m_type
=
value_t
::
object
;
result
.
m_value
=
value_t
::
object
;
}
}
// read next token
...
...
@@ -3104,11 +3112,19 @@ class parser
case
token_type
:
:
begin_array
:
{
if
(
keep
and
(
not
callback
or
((
keep
=
callback
(
depth
++
,
parse_event_t
::
array_start
,
result
))))
)
if
(
keep
)
{
// explicitly set result to object to cope with []
result
.
m_type
=
value_t
::
array
;
result
.
m_value
=
value_t
::
array
;
if
(
callback
)
{
keep
=
callback
(
depth
++
,
parse_event_t
::
array_start
,
result
);
}
if
(
not
callback
or
keep
)
{
// explicitly set result to array to cope with []
result
.
m_type
=
value_t
::
array
;
result
.
m_value
=
value_t
::
array
;
}
}
// read next token
...
...
@@ -5250,7 +5266,7 @@ class binary_reader
{
get
();
check_eof
();
return
current
;
return
static_cast
<
char
>
(
current
)
;
});
return
result
;
}
...
...
test/CMakeLists.txt
View file @
ef40673a
...
...
@@ -66,6 +66,22 @@ set_target_properties(catch_main PROPERTIES
)
target_include_directories
(
catch_main PRIVATE
"thirdparty/catch"
)
# https://stackoverflow.com/questions/2368811/how-to-set-warning-level-in-cmake
if
(
MSVC
)
# Force to always compile with W4
if
(
CMAKE_CXX_FLAGS MATCHES
"/W[0-4]"
)
string
(
REGEX REPLACE
"/W[0-4]"
"/W4"
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
"
)
else
()
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
/W4"
)
endif
()
# Disable warning C4389: '==': signed/unsigned mismatch
# Disable warning C4309: 'static_cast': truncation of constant value
# Disable warning C4566: character represented by universal-character-name '\uFF01' cannot be represented in the current code page (1252)
# Disable warning C4996: 'nlohmann::basic_json<std::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>::operator <<': was declared deprecated
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
/wd4389 /wd4309 /wd4566 /wd4996"
)
endif
()
#############################################################################
# one executable for each unit test file
#############################################################################
...
...
test/src/unit-constructor1.cpp
View file @
ef40673a
...
...
@@ -242,7 +242,7 @@ TEST_CASE("constructors")
SECTION
(
"std::pair"
)
{
std
::
pair
<
float
,
std
::
string
>
p
{
1.0
,
"string"
};
std
::
pair
<
float
,
std
::
string
>
p
{
1.0
f
,
"string"
};
json
j
(
p
);
CHECK
(
j
.
type
()
==
json
::
value_t
::
array
);
...
...
test/src/unit-readme.cpp
View file @
ef40673a
...
...
@@ -38,6 +38,11 @@ using nlohmann::json;
#include <unordered_set>
#include <iostream>
#if defined(_MSC_VER)
#pragma warning (push)
#pragma warning (disable : 4189) // local variable is initialized but not referenced
#endif
TEST_CASE
(
"README"
,
"[hide]"
)
{
{
...
...
@@ -298,3 +303,7 @@ TEST_CASE("README", "[hide]")
std
::
cout
.
rdbuf
(
old_cout_buffer
);
}
}
#if defined(_MSC_VER)
#pragma warning (pop)
#endif
test/src/unit-udt.cpp
View file @
ef40673a
...
...
@@ -201,7 +201,7 @@ void from_json(const BasicJsonType& j, country& c)
{
{
u8"中华人民共和国"
,
country
::
china
},
{
"France"
,
country
::
france
},
{
"Российская Федерация"
,
country
::
russia
}
{
u8
"Российская Федерация"
,
country
::
russia
}
};
const
auto
it
=
m
.
find
(
str
);
...
...
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