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
38c2e20c
Unverified
Commit
38c2e20c
authored
Mar 05, 2017
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added user-defined exceptions 404-405
parent
30331fa2
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
35 additions
and
28 deletions
+35
-28
src/json.hpp
src/json.hpp
+7
-7
src/json.hpp.re2c
src/json.hpp.re2c
+7
-7
test/src/unit-json_patch.cpp
test/src/unit-json_patch.cpp
+3
-2
test/src/unit-json_pointer.cpp
test/src/unit-json_pointer.cpp
+18
-12
No files found.
src/json.hpp
View file @
38c2e20c
...
...
@@ -11974,7 +11974,7 @@ basic_json_parser_74:
{
if
(
is_root
())
{
JSON_THROW
(
std
::
domain_error
(
"JSON pointer has no parent"
));
JSON_THROW
(
out_of_range
(
405
,
"JSON pointer has no parent"
));
}
auto
last
=
reference_tokens
.
back
();
...
...
@@ -11992,7 +11992,7 @@ basic_json_parser_74:
{
if
(
is_root
())
{
JSON_THROW
(
std
::
domain_error
(
"JSON pointer has no parent"
));
JSON_THROW
(
out_of_range
(
405
,
"JSON pointer has no parent"
));
}
json_pointer
result
=
*
this
;
...
...
@@ -12083,7 +12083,7 @@ basic_json_parser_74:
@complexity Linear in the length of the JSON pointer.
@throw
std::out_of_range
if the JSON pointer can not be resolved
@throw
out_of_range.404
if the JSON pointer can not be resolved
@throw parse_error.106 if an array index begins with '0'
@throw std::invalid_argument if an array index was not a number
*/
...
...
@@ -12153,7 +12153,7 @@ basic_json_parser_74:
default:
{
JSON_THROW
(
std
::
out_of_range
(
"unresolved reference token '"
+
reference_token
+
"'"
));
JSON_THROW
(
out_of_range
(
404
,
"unresolved reference token '"
+
reference_token
+
"'"
));
}
}
}
...
...
@@ -12204,7 +12204,7 @@ basic_json_parser_74:
default:
{
JSON_THROW
(
std
::
out_of_range
(
"unresolved reference token '"
+
reference_token
+
"'"
));
JSON_THROW
(
out_of_range
(
404
,
"unresolved reference token '"
+
reference_token
+
"'"
));
}
}
}
...
...
@@ -12263,7 +12263,7 @@ basic_json_parser_74:
default:
{
JSON_THROW
(
std
::
out_of_range
(
"unresolved reference token '"
+
reference_token
+
"'"
));
JSON_THROW
(
out_of_range
(
404
,
"unresolved reference token '"
+
reference_token
+
"'"
));
}
}
}
...
...
@@ -12314,7 +12314,7 @@ basic_json_parser_74:
default:
{
JSON_THROW
(
std
::
out_of_range
(
"unresolved reference token '"
+
reference_token
+
"'"
));
JSON_THROW
(
out_of_range
(
404
,
"unresolved reference token '"
+
reference_token
+
"'"
));
}
}
}
...
...
src/json.hpp.re2c
View file @
38c2e20c
...
...
@@ -11007,7 +11007,7 @@ class basic_json
{
if (is_root())
{
JSON_THROW(
std::domain_error(
"JSON pointer has no parent"));
JSON_THROW(
out_of_range(405,
"JSON pointer has no parent"));
}
auto last = reference_tokens.back();
...
...
@@ -11025,7 +11025,7 @@ class basic_json
{
if (is_root())
{
JSON_THROW(
std::domain_error(
"JSON pointer has no parent"));
JSON_THROW(
out_of_range(405,
"JSON pointer has no parent"));
}
json_pointer result = *this;
...
...
@@ -11116,7 +11116,7 @@ class basic_json
@complexity Linear in the length of the JSON pointer.
@throw
std::out_of_range
if the JSON pointer can not be resolved
@throw
out_of_range.404
if the JSON pointer can not be resolved
@throw parse_error.106 if an array index begins with '0'
@throw std::invalid_argument if an array index was not a number
*/
...
...
@@ -11186,7 +11186,7 @@ class basic_json
default:
{
JSON_THROW(
std::out_of_range(
"unresolved reference token '" + reference_token + "'"));
JSON_THROW(
out_of_range(404,
"unresolved reference token '" + reference_token + "'"));
}
}
}
...
...
@@ -11237,7 +11237,7 @@ class basic_json
default:
{
JSON_THROW(
std::out_of_range(
"unresolved reference token '" + reference_token + "'"));
JSON_THROW(
out_of_range(404,
"unresolved reference token '" + reference_token + "'"));
}
}
}
...
...
@@ -11296,7 +11296,7 @@ class basic_json
default:
{
JSON_THROW(
std::out_of_range(
"unresolved reference token '" + reference_token + "'"));
JSON_THROW(
out_of_range(404,
"unresolved reference token '" + reference_token + "'"));
}
}
}
...
...
@@ -11347,7 +11347,7 @@ class basic_json
default:
{
JSON_THROW(
std::out_of_range(
"unresolved reference token '" + reference_token + "'"));
JSON_THROW(
out_of_range(404,
"unresolved reference token '" + reference_token + "'"));
}
}
}
...
...
test/src/unit-json_patch.cpp
View file @
38c2e20c
...
...
@@ -791,8 +791,9 @@ TEST_CASE("JSON patch")
{
json
j
=
"string"
;
json
patch
=
{{{
"op"
,
"remove"
},
{
"path"
,
""
}}};
CHECK_THROWS_AS
(
j
.
patch
(
patch
),
std
::
domain_error
);
CHECK_THROWS_WITH
(
j
.
patch
(
patch
),
"JSON pointer has no parent"
);
CHECK_THROWS_AS
(
j
.
patch
(
patch
),
json
::
out_of_range
);
CHECK_THROWS_WITH
(
j
.
patch
(
patch
),
"[json.exception.out_of_range.405] JSON pointer has no parent"
);
}
}
...
...
test/src/unit-json_pointer.cpp
View file @
38c2e20c
...
...
@@ -49,10 +49,12 @@ TEST_CASE("JSON pointers")
"[json.exception.parse_error.108] parse error: escape character '~' must be followed with '0' or '1'"
);
json
::
json_pointer
p
;
CHECK_THROWS_AS
(
p
.
top
(),
std
::
domain_error
);
CHECK_THROWS_WITH
(
p
.
top
(),
"JSON pointer has no parent"
);
CHECK_THROWS_AS
(
p
.
pop_back
(),
std
::
domain_error
);
CHECK_THROWS_WITH
(
p
.
pop_back
(),
"JSON pointer has no parent"
);
CHECK_THROWS_AS
(
p
.
top
(),
json
::
out_of_range
);
CHECK_THROWS_WITH
(
p
.
top
(),
"[json.exception.out_of_range.405] JSON pointer has no parent"
);
CHECK_THROWS_AS
(
p
.
pop_back
(),
json
::
out_of_range
);
CHECK_THROWS_WITH
(
p
.
pop_back
(),
"[json.exception.out_of_range.405] JSON pointer has no parent"
);
}
SECTION
(
"examples from RFC 6901"
)
...
...
@@ -124,10 +126,12 @@ TEST_CASE("JSON pointers")
// unresolved access
json
j_primitive
=
1
;
CHECK_THROWS_AS
(
j_primitive
[
"/foo"
_json_pointer
],
std
::
out_of_range
);
CHECK_THROWS_WITH
(
j_primitive
[
"/foo"
_json_pointer
],
"unresolved reference token 'foo'"
);
CHECK_THROWS_AS
(
j_primitive
.
at
(
"/foo"
_json_pointer
),
std
::
out_of_range
);
CHECK_THROWS_WITH
(
j_primitive
.
at
(
"/foo"
_json_pointer
),
"unresolved reference token 'foo'"
);
CHECK_THROWS_AS
(
j_primitive
[
"/foo"
_json_pointer
],
json
::
out_of_range
);
CHECK_THROWS_WITH
(
j_primitive
[
"/foo"
_json_pointer
],
"[json.exception.out_of_range.404] unresolved reference token 'foo'"
);
CHECK_THROWS_AS
(
j_primitive
.
at
(
"/foo"
_json_pointer
),
json
::
out_of_range
);
CHECK_THROWS_WITH
(
j_primitive
.
at
(
"/foo"
_json_pointer
),
"[json.exception.out_of_range.404] unresolved reference token 'foo'"
);
}
SECTION
(
"const access"
)
...
...
@@ -191,10 +195,12 @@ TEST_CASE("JSON pointers")
// unresolved access
const
json
j_primitive
=
1
;
CHECK_THROWS_AS
(
j_primitive
[
"/foo"
_json_pointer
],
std
::
out_of_range
);
CHECK_THROWS_WITH
(
j_primitive
[
"/foo"
_json_pointer
],
"unresolved reference token 'foo'"
);
CHECK_THROWS_AS
(
j_primitive
.
at
(
"/foo"
_json_pointer
),
std
::
out_of_range
);
CHECK_THROWS_WITH
(
j_primitive
.
at
(
"/foo"
_json_pointer
),
"unresolved reference token 'foo'"
);
CHECK_THROWS_AS
(
j_primitive
[
"/foo"
_json_pointer
],
json
::
out_of_range
);
CHECK_THROWS_WITH
(
j_primitive
[
"/foo"
_json_pointer
],
"[json.exception.out_of_range.404] unresolved reference token 'foo'"
);
CHECK_THROWS_AS
(
j_primitive
.
at
(
"/foo"
_json_pointer
),
json
::
out_of_range
);
CHECK_THROWS_WITH
(
j_primitive
.
at
(
"/foo"
_json_pointer
),
"[json.exception.out_of_range.404] unresolved reference token 'foo'"
);
}
SECTION
(
"user-defined string literal"
)
...
...
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