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
59c83438
Commit
59c83438
authored
Nov 02, 2016
by
Niels
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cleanup
parent
94c16b2c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
55 additions
and
52 deletions
+55
-52
src/json.hpp
src/json.hpp
+24
-24
src/json.hpp.re2c
src/json.hpp.re2c
+16
-16
test/src/unit-deserialization.cpp
test/src/unit-deserialization.cpp
+15
-12
No files found.
src/json.hpp
View file @
59c83438
...
...
@@ -7836,7 +7836,7 @@ class basic_json
};
if
((
m_limit
-
m_cursor
)
<
5
)
{
fill_line_buffer
(
);
// LCOV_EXCL_LINE;
fill_line_buffer
(
5
);
// LCOV_EXCL_LINE
}
yych
=
*
m_cursor
;
if
(
yybm
[
0
+
yych
]
&
32
)
...
...
@@ -7966,7 +7966,7 @@ basic_json_parser_6:
++
m_cursor
;
if
(
m_limit
<=
m_cursor
)
{
fill_line_buffer
(
);
// LCOV_EXCL_LINE;
fill_line_buffer
(
1
);
// LCOV_EXCL_LINE
}
yych
=
*
m_cursor
;
if
(
yybm
[
0
+
yych
]
&
32
)
...
...
@@ -8048,7 +8048,7 @@ basic_json_parser_15:
m_marker
=
++
m_cursor
;
if
((
m_limit
-
m_cursor
)
<
3
)
{
fill_line_buffer
(
);
// LCOV_EXCL_LINE;
fill_line_buffer
(
3
);
// LCOV_EXCL_LINE
}
yych
=
*
m_cursor
;
if
(
yybm
[
0
+
yych
]
&
64
)
...
...
@@ -8133,7 +8133,7 @@ basic_json_parser_30:
++
m_cursor
;
if
(
m_limit
<=
m_cursor
)
{
fill_line_buffer
(
);
// LCOV_EXCL_LINE;
fill_line_buffer
(
1
);
// LCOV_EXCL_LINE
}
yych
=
*
m_cursor
;
basic_json_parser_31:
...
...
@@ -8214,7 +8214,7 @@ basic_json_parser_35:
++
m_cursor
;
if
(
m_limit
<=
m_cursor
)
{
fill_line_buffer
(
);
// LCOV_EXCL_LINE;
fill_line_buffer
(
1
);
// LCOV_EXCL_LINE
}
yych
=
*
m_cursor
;
if
(
yych
<=
'e'
)
...
...
@@ -8293,7 +8293,7 @@ basic_json_parser_36:
++
m_cursor
;
if
(
m_limit
<=
m_cursor
)
{
fill_line_buffer
(
);
// LCOV_EXCL_LINE;
fill_line_buffer
(
1
);
// LCOV_EXCL_LINE
}
yych
=
*
m_cursor
;
if
(
yych
<=
0x7F
)
...
...
@@ -8309,7 +8309,7 @@ basic_json_parser_37:
++
m_cursor
;
if
(
m_limit
<=
m_cursor
)
{
fill_line_buffer
(
);
// LCOV_EXCL_LINE;
fill_line_buffer
(
1
);
// LCOV_EXCL_LINE
}
yych
=
*
m_cursor
;
if
(
yych
<=
0x9F
)
...
...
@@ -8325,7 +8325,7 @@ basic_json_parser_38:
++
m_cursor
;
if
(
m_limit
<=
m_cursor
)
{
fill_line_buffer
(
);
// LCOV_EXCL_LINE;
fill_line_buffer
(
1
);
// LCOV_EXCL_LINE
}
yych
=
*
m_cursor
;
if
(
yych
<=
0x7F
)
...
...
@@ -8341,7 +8341,7 @@ basic_json_parser_39:
++
m_cursor
;
if
(
m_limit
<=
m_cursor
)
{
fill_line_buffer
(
);
// LCOV_EXCL_LINE;
fill_line_buffer
(
1
);
// LCOV_EXCL_LINE
}
yych
=
*
m_cursor
;
if
(
yych
<=
0x7F
)
...
...
@@ -8357,7 +8357,7 @@ basic_json_parser_40:
++
m_cursor
;
if
(
m_limit
<=
m_cursor
)
{
fill_line_buffer
(
);
// LCOV_EXCL_LINE;
fill_line_buffer
(
1
);
// LCOV_EXCL_LINE
}
yych
=
*
m_cursor
;
if
(
yych
<=
0x8F
)
...
...
@@ -8373,7 +8373,7 @@ basic_json_parser_41:
++
m_cursor
;
if
(
m_limit
<=
m_cursor
)
{
fill_line_buffer
(
);
// LCOV_EXCL_LINE;
fill_line_buffer
(
1
);
// LCOV_EXCL_LINE
}
yych
=
*
m_cursor
;
if
(
yych
<=
0x7F
)
...
...
@@ -8389,7 +8389,7 @@ basic_json_parser_42:
++
m_cursor
;
if
(
m_limit
<=
m_cursor
)
{
fill_line_buffer
(
);
// LCOV_EXCL_LINE;
fill_line_buffer
(
1
);
// LCOV_EXCL_LINE
}
yych
=
*
m_cursor
;
if
(
yych
<=
0x7F
)
...
...
@@ -8463,7 +8463,7 @@ basic_json_parser_48:
++
m_cursor
;
if
(
m_limit
<=
m_cursor
)
{
fill_line_buffer
(
);
// LCOV_EXCL_LINE;
fill_line_buffer
(
1
);
// LCOV_EXCL_LINE
}
yych
=
*
m_cursor
;
if
(
yych
<=
'@'
)
...
...
@@ -8499,7 +8499,7 @@ basic_json_parser_49:
m_marker
=
++
m_cursor
;
if
((
m_limit
-
m_cursor
)
<
3
)
{
fill_line_buffer
(
);
// LCOV_EXCL_LINE;
fill_line_buffer
(
3
);
// LCOV_EXCL_LINE
}
yych
=
*
m_cursor
;
if
(
yych
<=
'D'
)
...
...
@@ -8540,7 +8540,7 @@ basic_json_parser_52:
++
m_cursor
;
if
(
m_limit
<=
m_cursor
)
{
fill_line_buffer
(
);
// LCOV_EXCL_LINE;
fill_line_buffer
(
1
);
// LCOV_EXCL_LINE
}
yych
=
*
m_cursor
;
if
(
yych
<=
'/'
)
...
...
@@ -8577,7 +8577,7 @@ basic_json_parser_57:
++
m_cursor
;
if
(
m_limit
<=
m_cursor
)
{
fill_line_buffer
(
);
// LCOV_EXCL_LINE;
fill_line_buffer
(
1
);
// LCOV_EXCL_LINE
}
yych
=
*
m_cursor
;
if
(
yych
<=
'@'
)
...
...
@@ -8631,7 +8631,7 @@ basic_json_parser_63:
++
m_cursor
;
if
(
m_limit
<=
m_cursor
)
{
fill_line_buffer
(
);
// LCOV_EXCL_LINE;
fill_line_buffer
(
1
);
// LCOV_EXCL_LINE
}
yych
=
*
m_cursor
;
if
(
yych
<=
'@'
)
...
...
@@ -8672,7 +8672,7 @@ basic_json_parser_66:
++
m_cursor
;
if
(
m_limit
<=
m_cursor
)
{
fill_line_buffer
(
);
// LCOV_EXCL_LINE;
fill_line_buffer
(
1
);
// LCOV_EXCL_LINE
}
yych
=
*
m_cursor
;
if
(
yych
<=
'@'
)
...
...
@@ -8738,7 +8738,7 @@ basic_json_parser_66:
m_start
m_content
*/
void
fill_line_buffer
()
void
fill_line_buffer
(
size_t
n
=
0
)
{
// number of processed characters (p)
const
auto
offset_start
=
m_start
-
m_content
;
...
...
@@ -8761,10 +8761,10 @@ basic_json_parser_66:
}
}
// append
5 characters (size of longest keyword "false") to
//
make sure that there is sufficient space between m_cursor
// and m_limit
m_line_buffer
.
append
(
5
,
'\0
'
);
// append
n characters to make sure that there is sufficient
//
space between m_cursor and m_limit
m_line_buffer
.
append
(
1
,
'\x00'
);
m_line_buffer
.
append
(
n
-
1
,
'\x01
'
);
}
else
{
...
...
@@ -8772,7 +8772,7 @@ basic_json_parser_66:
m_line_buffer
.
erase
(
0
,
static_cast
<
size_t
>
(
offset_start
));
// read next line from input stream
std
::
string
line
;
std
::
getline
(
*
m_stream
,
line
);
std
::
getline
(
*
m_stream
,
line
,
'\n'
);
// add line with newline symbol to the line buffer
m_line_buffer
+=
line
+
"
\n
"
;
}
...
...
src/json.hpp.re2c
View file @
59c83438
...
...
@@ -7796,15 +7796,15 @@ class basic_json
assert(m_start != nullptr);
/*!re2c
re2c:define:YYCTYPE = lexer_char_t;
re2c:define:YYCURSOR = m_cursor;
re2c:define:YYLIMIT = m_limit;
re2c:define:YYMARKER = m_marker;
re2c:define:YYFILL
= "fill_line_buffer(
); // LCOV_EXCL_LINE";
re2c:
yyfill:parameter = 0
;
re2c:indent:string = " ";
re2c:indent:top = 1;
re2c:labelprefix = "basic_json_parser_";
re2c:define:YYCTYPE
= lexer_char_t;
re2c:define:YYCURSOR
= m_cursor;
re2c:define:YYLIMIT
= m_limit;
re2c:define:YYMARKER
= m_marker;
re2c:define:YYFILL
= "fill_line_buffer(@@
); // LCOV_EXCL_LINE";
re2c:
define:YYFILL:naked = 1
;
re2c:indent:string
= " ";
re2c:indent:top
= 1;
re2c:labelprefix
= "basic_json_parser_";
// ignore whitespace
ws = [ \t\n\r]+;
...
...
@@ -7849,7 +7849,7 @@ class basic_json
string { last_token_type = token_type::value_string; break; }
// end of file
"\
0
00" { last_token_type = token_type::end_of_input; break; }
"\
x
00" { last_token_type = token_type::end_of_input; break; }
// anything else is an error
* { last_token_type = token_type::parse_error; break; }
...
...
@@ -7887,7 +7887,7 @@ class basic_json
m_start
m_content
*/
void fill_line_buffer()
void fill_line_buffer(
size_t n = 0
)
{
// number of processed characters (p)
const auto offset_start = m_start - m_content;
...
...
@@ -7910,10 +7910,10 @@ class basic_json
}
}
// append
5 characters (size of longest keyword "false") to
//
make sure that there is sufficient space between m_cursor
// and m_limit
m_line_buffer.append(
5, '\0
');
// append
n characters to make sure that there is sufficient
//
space between m_cursor and m_limit
m_line_buffer.append(1, '\x00');
m_line_buffer.append(
n - 1, '\x01
');
}
else
{
...
...
@@ -7921,7 +7921,7 @@ class basic_json
m_line_buffer.erase(0, static_cast<size_t>(offset_start));
// read next line from input stream
std::string line;
std::getline(*m_stream, line);
std::getline(*m_stream, line
, '\n'
);
// add line with newline symbol to the line buffer
m_line_buffer += line + "\n";
}
...
...
test/src/unit-deserialization.cpp
View file @
59c83438
...
...
@@ -87,10 +87,11 @@ TEST_CASE("deserialization")
{
SECTION
(
"stream"
)
{
std
::
stringstream
ss
;
ss
<<
"[
\"
foo
\"
,1,2,3,false,{
\"
one
\"
:1}"
;
CHECK_THROWS_AS
(
json
::
parse
(
ss
),
std
::
invalid_argument
);
CHECK_THROWS_WITH
(
json
::
parse
(
ss
),
"parse error - unexpected end of input"
);
std
::
stringstream
ss1
,
ss2
;
ss1
<<
"[
\"
foo
\"
,1,2,3,false,{
\"
one
\"
:1}"
;
ss2
<<
"[
\"
foo
\"
,1,2,3,false,{
\"
one
\"
:1}"
;
CHECK_THROWS_AS
(
json
::
parse
(
ss1
),
std
::
invalid_argument
);
CHECK_THROWS_WITH
(
json
::
parse
(
ss2
),
"parse error - unexpected end of input; expected ']'"
);
}
SECTION
(
"string"
)
...
...
@@ -102,20 +103,22 @@ TEST_CASE("deserialization")
SECTION
(
"operator<<"
)
{
std
::
stringstream
ss
;
ss
<<
"[
\"
foo
\"
,1,2,3,false,{
\"
one
\"
:1}"
;
std
::
stringstream
ss1
,
ss2
;
ss1
<<
"[
\"
foo
\"
,1,2,3,false,{
\"
one
\"
:1}"
;
ss2
<<
"[
\"
foo
\"
,1,2,3,false,{
\"
one
\"
:1}"
;
json
j
;
CHECK_THROWS_AS
(
j
<<
ss
,
std
::
invalid_argument
);
CHECK_THROWS_WITH
(
j
<<
ss
,
"parse error - unexpected end of input
"
);
CHECK_THROWS_AS
(
j
<<
ss
1
,
std
::
invalid_argument
);
CHECK_THROWS_WITH
(
j
<<
ss
2
,
"parse error - unexpected end of input; expected ']'
"
);
}
SECTION
(
"operator>>"
)
{
std
::
stringstream
ss
;
ss
<<
"[
\"
foo
\"
,1,2,3,false,{
\"
one
\"
:1}"
;
std
::
stringstream
ss1
,
ss2
;
ss1
<<
"[
\"
foo
\"
,1,2,3,false,{
\"
one
\"
:1}"
;
ss2
<<
"[
\"
foo
\"
,1,2,3,false,{
\"
one
\"
:1}"
;
json
j
;
CHECK_THROWS_AS
(
ss
>>
j
,
std
::
invalid_argument
);
CHECK_THROWS_WITH
(
ss
>>
j
,
"parse error - unexpected end of input
"
);
CHECK_THROWS_AS
(
ss
1
>>
j
,
std
::
invalid_argument
);
CHECK_THROWS_WITH
(
ss
2
>>
j
,
"parse error - unexpected end of input; expected ']'
"
);
}
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