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
0433e71f
Commit
0433e71f
authored
Feb 10, 2015
by
Niels
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rename member variables; add whitespace tests
parent
f9797f8e
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
100 additions
and
100 deletions
+100
-100
src/json.hpp
src/json.hpp
+74
-74
src/json.hpp.re2c
src/json.hpp.re2c
+24
-24
test/unit.cpp
test/unit.cpp
+2
-2
No files found.
src/json.hpp
View file @
0433e71f
This diff is collapsed.
Click to expand it.
src/json.hpp.re2c
View file @
0433e71f
...
@@ -2414,9 +2414,9 @@ class basic_json
...
@@ -2414,9 +2414,9 @@ class basic_json
inline parser(const std::string& s) : buffer(s)
inline parser(const std::string& s) : buffer(s)
{
{
// set buffer for RE2C
// set buffer for RE2C
buffer_re2c
= reinterpret_cast<const lexer_char_t*>(buffer.c_str());
m_cursor
= reinterpret_cast<const lexer_char_t*>(buffer.c_str());
// set a pointer past the end of the buffer
// set a pointer past the end of the buffer
buffer_re2c_limit = buffer_re2c
+ buffer.size();
m_limit = m_cursor
+ buffer.size();
// read first token
// read first token
get_token();
get_token();
}
}
...
@@ -2432,9 +2432,9 @@ class basic_json
...
@@ -2432,9 +2432,9 @@ class basic_json
}
}
// set buffer for RE2C
// set buffer for RE2C
buffer_re2c
= reinterpret_cast<const lexer_char_t*>(buffer.c_str());
m_cursor
= reinterpret_cast<const lexer_char_t*>(buffer.c_str());
// set a pointer past the end of the buffer
// set a pointer past the end of the buffer
buffer_re2c_limit = buffer_re2c
+ buffer.size();
m_limit = m_cursor
+ buffer.size();
// read first token
// read first token
get_token();
get_token();
}
}
...
@@ -2538,10 +2538,10 @@ class basic_json
...
@@ -2538,10 +2538,10 @@ class basic_json
case (token_type::value_number):
case (token_type::value_number):
{
{
// The pointer
current_re2c
points to the beginning of the
// The pointer
m_begin
points to the beginning of the
// parsed number. We pass this pointer to std::strtod which
// parsed number. We pass this pointer to std::strtod which
// sets endptr to the first character past the converted
// sets endptr to the first character past the converted
// number. If this pointer is not the same as
buffer_re2c
,
// number. If this pointer is not the same as
m_cursor
,
// then either more or less characters have been used
// then either more or less characters have been used
// during the comparison. This can happen for inputs like
// during the comparison. This can happen for inputs like
// "01" which will be treated like number 0 followed by
// "01" which will be treated like number 0 followed by
...
@@ -2549,13 +2549,13 @@ class basic_json
...
@@ -2549,13 +2549,13 @@ class basic_json
// conversion
// conversion
char* endptr;
char* endptr;
const auto float_val = std::strtod(reinterpret_cast<const char*>(
current_re2c
), &endptr);
const auto float_val = std::strtod(reinterpret_cast<const char*>(
m_begin
), &endptr);
// check if strtod read beyond the end of the lexem
// check if strtod read beyond the end of the lexem
if (reinterpret_cast<const lexer_char_t*>(endptr) !=
buffer_re2c
)
if (reinterpret_cast<const lexer_char_t*>(endptr) !=
m_cursor
)
{
{
throw std::invalid_argument(std::string("parse error - ") +
throw std::invalid_argument(std::string("parse error - ") +
reinterpret_cast<const char*>(
current_re2c
) + " is not a number");
reinterpret_cast<const char*>(
m_begin
) + " is not a number");
}
}
// check if conversion loses precision
// check if conversion loses precision
...
@@ -2575,7 +2575,7 @@ class basic_json
...
@@ -2575,7 +2575,7 @@ class basic_json
default:
default:
{
{
std::string error_msg = "parse error - unexpected \'";
std::string error_msg = "parse error - unexpected \'";
error_msg += static_cast<char>(
current_re2c
[0]);
error_msg += static_cast<char>(
m_begin
[0]);
error_msg += "\' (";
error_msg += "\' (";
error_msg += token_type_name(last_token) + ")";
error_msg += token_type_name(last_token) + ")";
throw std::invalid_argument(error_msg);
throw std::invalid_argument(error_msg);
...
@@ -2599,24 +2599,24 @@ class basic_json
...
@@ -2599,24 +2599,24 @@ class basic_json
inline token_type get_token()
inline token_type get_token()
{
{
// needed by RE2C
// needed by RE2C
const lexer_char_t* marker;
const lexer_char_t* marker
= nullptr
;
// set up RE2C
// set up RE2C
/*!re2c
/*!re2c
re2c:labelprefix = "json_parser_";
re2c:labelprefix = "json_parser_";
re2c:yyfill:enable = 0;
re2c:yyfill:enable = 0;
re2c:define:YYCURSOR =
buffer_re2c
;
re2c:define:YYCURSOR =
m_cursor
;
re2c:define:YYCTYPE = lexer_char_t;
re2c:define:YYCTYPE = lexer_char_t;
re2c:define:YYMARKER = marker;
re2c:define:YYMARKER = marker;
re2c:indent:string = " ";
re2c:indent:string = " ";
re2c:define:YYLIMIT =
buffer_re2c
_limit;
re2c:define:YYLIMIT =
m
_limit;
*/
*/
lexer_start:
lexer_start:
// set current to the begin of the buffer
// set current to the begin of the buffer
current_re2c = buffer_re2c
;
m_begin = m_cursor
;
if (
current_re2c == buffer_re2c
_limit)
if (
m_begin == m
_limit)
{
{
return last_token = token_type::end_of_input;
return last_token = token_type::end_of_input;
}
}
...
@@ -2707,7 +2707,7 @@ lexer_start:
...
@@ -2707,7 +2707,7 @@ lexer_start:
if (t != last_token)
if (t != last_token)
{
{
std::string error_msg = "parse error - unexpected \'";
std::string error_msg = "parse error - unexpected \'";
error_msg += static_cast<char>(
current_re2c
[0]);
error_msg += static_cast<char>(
m_begin
[0]);
error_msg += "\' (" + token_type_name(last_token);
error_msg += "\' (" + token_type_name(last_token);
error_msg += "); expected " + token_type_name(t);
error_msg += "); expected " + token_type_name(t);
throw std::invalid_argument(error_msg);
throw std::invalid_argument(error_msg);
...
@@ -2715,9 +2715,9 @@ lexer_start:
...
@@ -2715,9 +2715,9 @@ lexer_start:
}
}
/*!
/*!
The pointer
current_re2c
points to the opening quote of the string, and
The pointer
m_begin
points to the opening quote of the string, and
buffer_re2c
past the closing quote of the string. We create a std::string from
m_cursor
past the closing quote of the string. We create a std::string from
the character after the opening quotes (
current_re2c
+1) until the character
the character after the opening quotes (
m_begin
+1) until the character
before the closing quotes (hence subtracting 2 characters from the pointer
before the closing quotes (hence subtracting 2 characters from the pointer
difference of the two pointers).
difference of the two pointers).
...
@@ -2728,8 +2728,8 @@ lexer_start:
...
@@ -2728,8 +2728,8 @@ lexer_start:
inline std::string get_string() const
inline std::string get_string() const
{
{
return std::string(
return std::string(
reinterpret_cast<const char*>(
current_re2c
+ 1),
reinterpret_cast<const char*>(
m_begin
+ 1),
static_cast<std::size_t>(
buffer_re2c - current_re2c
- 2)
static_cast<std::size_t>(
m_cursor - m_begin
- 2)
);
);
}
}
...
@@ -2737,11 +2737,11 @@ lexer_start:
...
@@ -2737,11 +2737,11 @@ lexer_start:
/// the buffer
/// the buffer
std::string buffer;
std::string buffer;
/// a pointer to the next character to read from the buffer
/// a pointer to the next character to read from the buffer
const lexer_char_t*
buffer_re2c
= nullptr;
const lexer_char_t*
m_cursor
= nullptr;
/// a pointer past the last character of the buffer
/// a pointer past the last character of the buffer
const lexer_char_t*
buffer_re2c
_limit = nullptr;
const lexer_char_t*
m
_limit = nullptr;
/// a pointer to the beginning of the current token
/// a pointer to the beginning of the current token
const lexer_char_t*
current_re2c
= nullptr;
const lexer_char_t*
m_begin
= nullptr;
/// the type of the last read token
/// the type of the last read token
token_type last_token = token_type::uninitialized;
token_type last_token = token_type::uninitialized;
};
};
...
...
test/unit.cpp
View file @
0433e71f
...
@@ -4008,7 +4008,7 @@ TEST_CASE("parser class")
...
@@ -4008,7 +4008,7 @@ TEST_CASE("parser class")
CHECK
(
json
::
parser
(
"8"
).
last_token
==
json
::
parser
::
token_type
::
value_number
);
CHECK
(
json
::
parser
(
"8"
).
last_token
==
json
::
parser
::
token_type
::
value_number
);
CHECK
(
json
::
parser
(
"9"
).
last_token
==
json
::
parser
::
token_type
::
value_number
);
CHECK
(
json
::
parser
(
"9"
).
last_token
==
json
::
parser
::
token_type
::
value_number
);
}
}
/*
SECTION
(
"whitespace"
)
SECTION
(
"whitespace"
)
{
{
CHECK
(
json
::
parser
(
" 0"
).
last_token
==
json
::
parser
::
token_type
::
value_number
);
CHECK
(
json
::
parser
(
" 0"
).
last_token
==
json
::
parser
::
token_type
::
value_number
);
...
@@ -4017,7 +4017,7 @@ TEST_CASE("parser class")
...
@@ -4017,7 +4017,7 @@ TEST_CASE("parser class")
CHECK
(
json
::
parser
(
"
\r
0"
).
last_token
==
json
::
parser
::
token_type
::
value_number
);
CHECK
(
json
::
parser
(
"
\r
0"
).
last_token
==
json
::
parser
::
token_type
::
value_number
);
CHECK
(
json
::
parser
(
"
\t\n\r\n\t
0"
).
last_token
==
json
::
parser
::
token_type
::
value_number
);
CHECK
(
json
::
parser
(
"
\t\n\r\n\t
0"
).
last_token
==
json
::
parser
::
token_type
::
value_number
);
}
}
*/
/*
/*
SECTION("parse errors on first character")
SECTION("parse errors on first character")
{
{
...
...
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