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
ff72f388
Unverified
Commit
ff72f388
authored
Apr 06, 2017
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
🔨
fixed another warning
Do not store eof() in a char buffer…
parent
b992acc2
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
14 deletions
+25
-14
json.hpp
src/json.hpp
+25
-14
No files found.
src/json.hpp
View file @
ff72f388
...
@@ -8485,8 +8485,7 @@ class basic_json
...
@@ -8485,8 +8485,7 @@ class basic_json
{
{
public
:
public
:
cached_input_stream_adapter
(
std
::
istream
&
i
,
const
size_t
buffer_size
)
cached_input_stream_adapter
(
std
::
istream
&
i
,
const
size_t
buffer_size
)
:
is
(
i
),
start_position
(
is
.
tellg
()),
:
is
(
i
),
start_position
(
is
.
tellg
()),
buffer
(
buffer_size
,
'\0'
)
buffer
(
buffer_size
,
std
::
char_traits
<
char
>::
eof
())
{
{
// immediately abort if stream is erroneous
// immediately abort if stream is erroneous
if
(
JSON_UNLIKELY
(
i
.
fail
()))
if
(
JSON_UNLIKELY
(
i
.
fail
()))
...
@@ -8494,12 +8493,13 @@ class basic_json
...
@@ -8494,12 +8493,13 @@ class basic_json
JSON_THROW
(
parse_error
::
create
(
111
,
0
,
"bad input stream"
));
JSON_THROW
(
parse_error
::
create
(
111
,
0
,
"bad input stream"
));
}
}
// initial fill
; unfilled buffer characters remain EOF
// initial fill
is
.
read
(
buffer
.
data
(),
static_cast
<
std
::
streamsize
>
(
buffer
.
size
()));
is
.
read
(
buffer
.
data
(),
static_cast
<
std
::
streamsize
>
(
buffer
.
size
()));
// store number of bytes in the buffer
fill_size
=
static_cast
<
size_t
>
(
is
.
gcount
());
// skip byte-order mark
// skip byte-order mark
assert
(
buffer
.
size
()
>=
3
);
if
(
fill_size
>=
3
and
buffer
[
0
]
==
'\xEF'
and
buffer
[
1
]
==
'\xBB'
and
buffer
[
2
]
==
'\xBF'
)
if
(
buffer
[
0
]
==
'\xEF'
and
buffer
[
1
]
==
'\xBB'
and
buffer
[
2
]
==
'\xBF'
)
{
{
buffer_pos
+=
3
;
buffer_pos
+=
3
;
processed_chars
+=
3
;
processed_chars
+=
3
;
...
@@ -8516,22 +8516,28 @@ class basic_json
...
@@ -8516,22 +8516,28 @@ class basic_json
int
get_character
()
override
int
get_character
()
override
{
{
// check if refilling is necessary
// check if refilling is necessary
and possible
if
(
JSON_UNLIKELY
(
buffer_pos
==
buffer
.
size
())
)
if
(
buffer_pos
==
fill_size
and
not
eof
)
{
{
// refill
// refill
is
.
read
(
reinterpret_cast
<
char
*>
(
buffer
.
data
()),
static_cast
<
std
::
streamsize
>
(
buffer
.
size
()));
is
.
read
(
buffer
.
data
(),
static_cast
<
std
::
streamsize
>
(
buffer
.
size
()));
// set unfilled characters to EOF
// store number of bytes in the buffer
std
::
fill_n
(
buffer
.
begin
()
+
static_cast
<
int
>
(
is
.
gcount
()),
fill_size
=
static_cast
<
size_t
>
(
is
.
gcount
());
buffer
.
size
()
-
static_cast
<
size_t
>
(
is
.
gcount
()),
std
::
char_traits
<
char
>::
eof
());
// remember that filling did not yield new input
if
(
fill_size
==
0
)
{
eof
=
true
;
}
// the buffer is ready
// the buffer is ready
buffer_pos
=
0
;
buffer_pos
=
0
;
}
}
++
processed_chars
;
++
processed_chars
;
const
int
res
=
buffer
[
buffer_pos
++
];
return
eof
return
(
res
==
std
::
char_traits
<
char
>::
eof
())
?
res
:
res
&
0xFF
;
?
std
::
char_traits
<
char
>::
eof
()
:
buffer
[
buffer_pos
++
]
&
0xFF
;
}
}
std
::
string
read
(
size_t
offset
,
size_t
length
)
override
std
::
string
read
(
size_t
offset
,
size_t
length
)
override
...
@@ -8568,6 +8574,11 @@ class basic_json
...
@@ -8568,6 +8574,11 @@ class basic_json
/// chars processed in the current buffer
/// chars processed in the current buffer
size_t
buffer_pos
=
0
;
size_t
buffer_pos
=
0
;
/// whether stream reached eof
bool
eof
=
false
;
/// how many chars have been copied to the buffer by last (re)fill
size_t
fill_size
=
0
;
/// position of the stream when we started
/// position of the stream when we started
const
std
::
streampos
start_position
;
const
std
::
streampos
start_position
;
...
...
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