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
6ef3cb51
Commit
6ef3cb51
authored
Feb 14, 2015
by
Niels
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
some reorganization
parent
cc4a8319
Changes
3
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
665 additions
and
646 deletions
+665
-646
src/json.hpp
src/json.hpp
+571
-572
src/json.hpp.re2c
src/json.hpp.re2c
+76
-74
test/unit.cpp
test/unit.cpp
+18
-0
No files found.
src/json.hpp
View file @
6ef3cb51
This diff is collapsed.
Click to expand it.
src/json.hpp.re2c
View file @
6ef3cb51
...
...
@@ -2516,6 +2516,8 @@ class basic_json
// pointer for backtracking information
const char* m_marker = nullptr;
while (true)
{
// remember the begin of the token
m_start = m_cursor;
...
...
@@ -2526,12 +2528,12 @@ class basic_json
re2c:define:YYMARKER = m_marker;
re2c:indent:string = " ";
re2c:indent:top = 1;
re2c:labelprefix = "
json_parser_";
re2c:labelprefix = "basic_
json_parser_";
re2c:yyfill:enable = 0;
// whitespace
ws = [ \t\n\r]*
;
ws { return scan()
; }
ws = [ \t\n\r]+
;
ws { continue
; }
// structural characters
"[" { return token_type::begin_array; }
...
...
@@ -2564,7 +2566,9 @@ class basic_json
quotation_mark = [\"];
escape = [\\];
unescaped = [^\"\\\000];
escaped = escape ([\"\\/bfnrt] | [u][0-9a-fA-F]{4});
single_escaped = [\"\\/bfnrt];
unicode_escaped = [u][0-9a-fA-F]{4};
escaped = escape (single_escaped | unicode_escaped);
char = unescaped | escaped;
string = quotation_mark char* quotation_mark;
string { return token_type::value_string; }
...
...
@@ -2576,8 +2580,9 @@ class basic_json
. { return token_type::parse_error; }
*/
}
}
inline std::string get_
string_value
() const
inline std::string get_
token
() const
{
return std::string(m_start, static_cast<size_t>(m_cursor - m_start));
}
...
...
@@ -2612,15 +2617,9 @@ class basic_json
char* endptr;
const auto float_val = std::strtod(reinterpret_cast<const char*>(m_start), &endptr);
// check if strtod read beyond the end of the lexem
if (endptr != m_cursor)
{
return NAN;
}
else
{
return float_val;
}
// return float_val if the whole number was translated and NAN
// otherwise
return (endptr == m_cursor) ? float_val : NAN;
}
private:
...
...
@@ -2787,10 +2786,12 @@ class basic_json
{
auto float_val = m_lexer.get_number();
// NAN is returned if token could not be translated
// completely
if (std::isnan(float_val))
{
throw std::invalid_argument(std::string("parse error - ") +
m_lexer.get_
string_value
() + " is not a number");
m_lexer.get_
token
() + " is not a number");
}
get_token();
...
...
@@ -2812,7 +2813,7 @@ class basic_json
default:
{
std::string error_msg = "parse error - unexpected \'";
error_msg += m_lexer.get_
string_value
();
error_msg += m_lexer.get_
token
();
error_msg += "\' (";
error_msg += lexer::token_type_name(last_token) + ")";
throw std::invalid_argument(error_msg);
...
...
@@ -2832,7 +2833,7 @@ class basic_json
if (t != last_token)
{
std::string error_msg = "parse error - unexpected \'";
error_msg += m_lexer.get_
string_value
();
error_msg += m_lexer.get_
token
();
error_msg += "\' (" + lexer::token_type_name(last_token);
error_msg += "); expected " + lexer::token_type_name(t);
throw std::invalid_argument(error_msg);
...
...
@@ -2844,6 +2845,7 @@ class basic_json
std::string m_buffer;
/// the type of the last read token
typename lexer::token_type last_token = lexer::token_type::uninitialized;
/// the lexer
lexer m_lexer;
};
};
...
...
test/unit.cpp
View file @
6ef3cb51
...
...
@@ -3630,6 +3630,8 @@ TEST_CASE("capacity")
{
CHECK
(
std
::
distance
(
j
.
begin
(),
j
.
end
())
==
j
.
size
());
CHECK
(
std
::
distance
(
j_const
.
begin
(),
j_const
.
end
())
==
j_const
.
size
());
CHECK
(
std
::
distance
(
j
.
rbegin
(),
j
.
rend
())
==
j
.
size
());
CHECK
(
std
::
distance
(
j_const
.
crbegin
(),
j_const
.
crend
())
==
j_const
.
size
());
}
}
...
...
@@ -3648,6 +3650,8 @@ TEST_CASE("capacity")
{
CHECK
(
std
::
distance
(
j
.
begin
(),
j
.
end
())
==
j
.
size
());
CHECK
(
std
::
distance
(
j_const
.
begin
(),
j_const
.
end
())
==
j_const
.
size
());
CHECK
(
std
::
distance
(
j
.
rbegin
(),
j
.
rend
())
==
j
.
size
());
CHECK
(
std
::
distance
(
j_const
.
crbegin
(),
j_const
.
crend
())
==
j_const
.
size
());
}
}
...
...
@@ -3668,6 +3672,8 @@ TEST_CASE("capacity")
{
CHECK
(
std
::
distance
(
j
.
begin
(),
j
.
end
())
==
j
.
size
());
CHECK
(
std
::
distance
(
j_const
.
begin
(),
j_const
.
end
())
==
j_const
.
size
());
CHECK
(
std
::
distance
(
j
.
rbegin
(),
j
.
rend
())
==
j
.
size
());
CHECK
(
std
::
distance
(
j_const
.
crbegin
(),
j_const
.
crend
())
==
j_const
.
size
());
}
}
...
...
@@ -3686,6 +3692,8 @@ TEST_CASE("capacity")
{
CHECK
(
std
::
distance
(
j
.
begin
(),
j
.
end
())
==
j
.
size
());
CHECK
(
std
::
distance
(
j_const
.
begin
(),
j_const
.
end
())
==
j_const
.
size
());
CHECK
(
std
::
distance
(
j
.
rbegin
(),
j
.
rend
())
==
j
.
size
());
CHECK
(
std
::
distance
(
j_const
.
crbegin
(),
j_const
.
crend
())
==
j_const
.
size
());
}
}
}
...
...
@@ -3707,6 +3715,8 @@ TEST_CASE("capacity")
{
CHECK
(
std
::
distance
(
j
.
begin
(),
j
.
end
())
==
j
.
size
());
CHECK
(
std
::
distance
(
j_const
.
begin
(),
j_const
.
end
())
==
j_const
.
size
());
CHECK
(
std
::
distance
(
j
.
rbegin
(),
j
.
rend
())
==
j
.
size
());
CHECK
(
std
::
distance
(
j_const
.
crbegin
(),
j_const
.
crend
())
==
j_const
.
size
());
}
}
...
...
@@ -3725,6 +3735,8 @@ TEST_CASE("capacity")
{
CHECK
(
std
::
distance
(
j
.
begin
(),
j
.
end
())
==
j
.
size
());
CHECK
(
std
::
distance
(
j_const
.
begin
(),
j_const
.
end
())
==
j_const
.
size
());
CHECK
(
std
::
distance
(
j
.
rbegin
(),
j
.
rend
())
==
j
.
size
());
CHECK
(
std
::
distance
(
j_const
.
crbegin
(),
j_const
.
crend
())
==
j_const
.
size
());
}
}
}
...
...
@@ -3744,6 +3756,8 @@ TEST_CASE("capacity")
{
CHECK
(
std
::
distance
(
j
.
begin
(),
j
.
end
())
==
j
.
size
());
CHECK
(
std
::
distance
(
j_const
.
begin
(),
j_const
.
end
())
==
j_const
.
size
());
CHECK
(
std
::
distance
(
j
.
rbegin
(),
j
.
rend
())
==
j
.
size
());
CHECK
(
std
::
distance
(
j_const
.
crbegin
(),
j_const
.
crend
())
==
j_const
.
size
());
}
}
...
...
@@ -3762,6 +3776,8 @@ TEST_CASE("capacity")
{
CHECK
(
std
::
distance
(
j
.
begin
(),
j
.
end
())
==
j
.
size
());
CHECK
(
std
::
distance
(
j_const
.
begin
(),
j_const
.
end
())
==
j_const
.
size
());
CHECK
(
std
::
distance
(
j
.
rbegin
(),
j
.
rend
())
==
j
.
size
());
CHECK
(
std
::
distance
(
j_const
.
crbegin
(),
j_const
.
crend
())
==
j_const
.
size
());
}
}
...
...
@@ -3780,6 +3796,8 @@ TEST_CASE("capacity")
{
CHECK
(
std
::
distance
(
j
.
begin
(),
j
.
end
())
==
j
.
size
());
CHECK
(
std
::
distance
(
j_const
.
begin
(),
j_const
.
end
())
==
j_const
.
size
());
CHECK
(
std
::
distance
(
j
.
rbegin
(),
j
.
rend
())
==
j
.
size
());
CHECK
(
std
::
distance
(
j_const
.
crbegin
(),
j_const
.
crend
())
==
j_const
.
size
());
}
}
}
...
...
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