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
12efeadc
Commit
12efeadc
authored
Oct 03, 2017
by
Perry Kundert
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Further simplify istream handling; use native unget
parent
f585fe4e
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
6 deletions
+16
-6
src/json.hpp
src/json.hpp
+16
-6
No files found.
src/json.hpp
View file @
12efeadc
...
...
@@ -1398,6 +1398,7 @@ constexpr T static_const<T>::value;
struct
input_adapter_protocol
{
virtual
int
get_character
()
=
0
;
virtual
void
unget_character
()
=
0
;
virtual
~
input_adapter_protocol
()
=
default
;
};
...
...
@@ -1448,6 +1449,10 @@ class input_stream_adapter : public input_adapter_protocol
return
c
==
std
::
char_traits
<
char
>::
eof
()
?
c
:
(
c
&
0xFF
);
}
void
unget_character
()
override
{
is
.
unget
();
}
private:
/// the associated input stream
...
...
@@ -1482,6 +1487,14 @@ class input_buffer_adapter : public input_adapter_protocol
return
std
::
char_traits
<
char
>::
eof
();
}
void
unget_character
()
noexcept
override
{
if
(
JSON_LIKELY
(
cursor
>
0
))
{
--
cursor
;
}
}
private:
/// pointer to the current character
const
char
*
cursor
;
...
...
@@ -2647,8 +2660,8 @@ scan_number_done:
int
get
()
{
++
chars_read
;
int
c
=
next_unget
?
(
next_unget
=
false
,
current
)
:
(
current
=
ia
->
get_character
()
);
int
c
=
current
=
ia
->
get_character
(
);
token_string
+=
static_cast
<
char
>
(
c
);
return
c
;
}
...
...
@@ -2657,7 +2670,7 @@ scan_number_done:
void
unget
()
{
--
chars_read
;
next_unget
=
true
;
if
(
token_string
.
size
()
>
0
)
token_string
.
resize
(
token_string
.
size
()
-
1
);
}
...
...
@@ -2825,9 +2838,6 @@ scan_number_done:
/// the current character
int
current
=
std
::
char_traits
<
char
>::
eof
();
/// whether get() should return the last character again
bool
next_unget
=
false
;
/// the number of characters read
std
::
size_t
chars_read
=
0
;
/// the start position of the current token
...
...
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