Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
json
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
json
Commits
1b43a45b
Commit
1b43a45b
authored
Oct 05, 2017
by
Perry Kundert
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement correct handling of std::streambuf int_type, eof()
o Make no assumptions about eof(), other than that it is somewhere outside of the valid range of char_type.
parent
184dab60
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
11 deletions
+14
-11
json.hpp
src/json.hpp
+14
-11
No files found.
src/json.hpp
View file @
1b43a45b
...
@@ -1397,7 +1397,7 @@ constexpr T static_const<T>::value;
...
@@ -1397,7 +1397,7 @@ constexpr T static_const<T>::value;
/// abstract input adapter interface
/// abstract input adapter interface
struct
input_adapter_protocol
struct
input_adapter_protocol
{
{
virtual
int
get_character
()
=
0
;
// returns characters in range [0,255], or eof()
(a -'ve value)
virtual
int
get_character
()
=
0
;
// returns characters in range [0,255], or eof()
virtual
void
unget_character
()
=
0
;
// restore the last non-eof() character to input
virtual
void
unget_character
()
=
0
;
// restore the last non-eof() character to input
virtual
~
input_adapter_protocol
()
=
default
;
virtual
~
input_adapter_protocol
()
=
default
;
};
};
...
@@ -1447,10 +1447,13 @@ class input_stream_adapter : public input_adapter_protocol
...
@@ -1447,10 +1447,13 @@ class input_stream_adapter : public input_adapter_protocol
}
}
}
}
// delete because of pointer members
input_stream_adapter
(
const
input_stream_adapter
&
)
=
delete
;
input_stream_adapter
&
operator
=
(
input_stream_adapter
&
)
=
delete
;
int
get_character
()
override
int
get_character
()
override
{
{
int
c
=
sb
->
sbumpc
();
// Avoided for performance: int c = is.get();
return
reinterpret_cast
<
int
>
(
sb
->
sbumpc
()
);
return
c
<
0
?
c
:
(
c
&
0xFF
);
// faster than == std::char_traits<char>::eof()
}
}
void
unget_character
()
override
void
unget_character
()
override
...
@@ -1486,10 +1489,10 @@ class input_buffer_adapter : public input_adapter_protocol
...
@@ -1486,10 +1489,10 @@ class input_buffer_adapter : public input_adapter_protocol
{
{
if
(
JSON_LIKELY
(
cursor
<
limit
))
if
(
JSON_LIKELY
(
cursor
<
limit
))
{
{
return
*
(
cursor
++
)
&
0xFF
;
return
reinterpret_cast
<
int
>
(
std
::
char_traits
<
char
>::
to_int_type
(
*
(
cursor
++
)))
;
}
}
return
std
::
char_traits
<
char
>::
eof
(
);
return
reinterpret_cast
<
int
>
(
std
::
char_traits
<
char
>::
eof
()
);
}
}
void
unget_character
()
noexcept
override
void
unget_character
()
noexcept
override
...
@@ -2668,9 +2671,9 @@ scan_number_done:
...
@@ -2668,9 +2671,9 @@ scan_number_done:
{
{
++
chars_read
;
++
chars_read
;
current
=
ia
->
get_character
();
current
=
ia
->
get_character
();
if
(
JSON_LIKELY
(
current
>=
0
))
// faster than:
!= std::char_traits<char>::eof()))
if
(
JSON_LIKELY
(
current
!=
std
::
char_traits
<
char
>::
eof
()))
{
{
token_string
.
push_back
(
st
atic_cast
<
char
>
(
current
));
token_string
.
push_back
(
st
d
::
char_traits
<
char
>::
to_char_type
(
current
));
}
}
return
current
;
return
current
;
}
}
...
@@ -2679,7 +2682,7 @@ scan_number_done:
...
@@ -2679,7 +2682,7 @@ scan_number_done:
void
unget
()
void
unget
()
{
{
--
chars_read
;
--
chars_read
;
if
(
JSON_LIKELY
(
current
>=
0
))
// faster than:
!= std::char_traits<char>::eof()))
if
(
JSON_LIKELY
(
current
!=
std
::
char_traits
<
char
>::
eof
()))
{
{
ia
->
unget_character
();
ia
->
unget_character
();
assert
(
token_string
.
size
()
!=
0
);
assert
(
token_string
.
size
()
!=
0
);
...
@@ -2690,7 +2693,7 @@ scan_number_done:
...
@@ -2690,7 +2693,7 @@ scan_number_done:
/// add a character to yytext
/// add a character to yytext
void
add
(
int
c
)
void
add
(
int
c
)
{
{
yytext
.
push_back
(
st
atic_cast
<
char
>
(
c
));
yytext
.
push_back
(
st
d
::
char_traits
<
char
>::
to_char_type
(
c
));
}
}
public
:
public
:
...
@@ -5460,14 +5463,14 @@ class binary_reader
...
@@ -5460,14 +5463,14 @@ class binary_reader
{
{
if
(
expect_eof
)
if
(
expect_eof
)
{
{
if
(
JSON_UNLIKELY
(
current
>=
0
))
// faster than:
!= std::char_traits<char>::eof()))
if
(
JSON_UNLIKELY
(
current
!=
std
::
char_traits
<
char
>::
eof
()))
{
{
JSON_THROW
(
parse_error
::
create
(
110
,
chars_read
,
"expected end of input"
));
JSON_THROW
(
parse_error
::
create
(
110
,
chars_read
,
"expected end of input"
));
}
}
}
}
else
else
{
{
if
(
JSON_UNLIKELY
(
current
<
0
))
// faster than:
== std::char_traits<char>::eof()))
if
(
JSON_UNLIKELY
(
current
==
std
::
char_traits
<
char
>::
eof
()))
{
{
JSON_THROW
(
parse_error
::
create
(
110
,
chars_read
,
"unexpected end of input"
));
JSON_THROW
(
parse_error
::
create
(
110
,
chars_read
,
"unexpected end of input"
));
}
}
...
...
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