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
c51b1e6f
Unverified
Commit
c51b1e6f
authored
Oct 22, 2018
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
🚧
fixed an issue with ensure_ascii #1198
parent
c7af027c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
2 deletions
+20
-2
serializer.hpp
include/nlohmann/detail/output/serializer.hpp
+6
-1
json.hpp
single_include/nlohmann/json.hpp
+6
-1
unit-unicode.cpp
test/src/unit-unicode.cpp
+8
-0
No files found.
include/nlohmann/detail/output/serializer.hpp
View file @
c51b1e6f
...
@@ -302,6 +302,7 @@ class serializer
...
@@ -302,6 +302,7 @@ class serializer
// number of bytes written at the point of the last valid byte
// number of bytes written at the point of the last valid byte
std
::
size_t
bytes_after_last_accept
=
0
;
std
::
size_t
bytes_after_last_accept
=
0
;
std
::
size_t
undumped_chars
=
0
;
for
(
std
::
size_t
i
=
0
;
i
<
s
.
size
();
++
i
)
for
(
std
::
size_t
i
=
0
;
i
<
s
.
size
();
++
i
)
{
{
...
@@ -403,6 +404,7 @@ class serializer
...
@@ -403,6 +404,7 @@ class serializer
// remember the byte position of this accept
// remember the byte position of this accept
bytes_after_last_accept
=
bytes
;
bytes_after_last_accept
=
bytes
;
undumped_chars
=
0
;
break
;
break
;
}
}
...
@@ -424,7 +426,7 @@ class serializer
...
@@ -424,7 +426,7 @@ class serializer
// would like to read it again, because the byte
// would like to read it again, because the byte
// may be OK for itself, but just not OK for the
// may be OK for itself, but just not OK for the
// previous sequence
// previous sequence
if
(
bytes_after_last_accept
!=
bytes
)
if
(
undumped_chars
>
0
)
{
{
--
i
;
--
i
;
}
}
...
@@ -454,6 +456,8 @@ class serializer
...
@@ -454,6 +456,8 @@ class serializer
bytes_after_last_accept
=
bytes
;
bytes_after_last_accept
=
bytes
;
}
}
undumped_chars
=
0
;
// continue processing the string
// continue processing the string
state
=
UTF8_ACCEPT
;
state
=
UTF8_ACCEPT
;
continue
;
continue
;
...
@@ -468,6 +472,7 @@ class serializer
...
@@ -468,6 +472,7 @@ class serializer
// code point will not be escaped - copy byte to buffer
// code point will not be escaped - copy byte to buffer
string_buffer
[
bytes
++
]
=
s
[
i
];
string_buffer
[
bytes
++
]
=
s
[
i
];
}
}
++
undumped_chars
;
break
;
break
;
}
}
}
}
...
...
single_include/nlohmann/json.hpp
View file @
c51b1e6f
...
@@ -10254,6 +10254,7 @@ class serializer
...
@@ -10254,6 +10254,7 @@ class serializer
// number of bytes written at the point of the last valid byte
// number of bytes written at the point of the last valid byte
std
::
size_t
bytes_after_last_accept
=
0
;
std
::
size_t
bytes_after_last_accept
=
0
;
std
::
size_t
undumped_chars
=
0
;
for
(
std
::
size_t
i
=
0
;
i
<
s
.
size
();
++
i
)
for
(
std
::
size_t
i
=
0
;
i
<
s
.
size
();
++
i
)
{
{
...
@@ -10355,6 +10356,7 @@ class serializer
...
@@ -10355,6 +10356,7 @@ class serializer
// remember the byte position of this accept
// remember the byte position of this accept
bytes_after_last_accept
=
bytes
;
bytes_after_last_accept
=
bytes
;
undumped_chars
=
0
;
break
;
break
;
}
}
...
@@ -10376,7 +10378,7 @@ class serializer
...
@@ -10376,7 +10378,7 @@ class serializer
// would like to read it again, because the byte
// would like to read it again, because the byte
// may be OK for itself, but just not OK for the
// may be OK for itself, but just not OK for the
// previous sequence
// previous sequence
if
(
bytes_after_last_accept
!=
bytes
)
if
(
undumped_chars
>
0
)
{
{
--
i
;
--
i
;
}
}
...
@@ -10406,6 +10408,8 @@ class serializer
...
@@ -10406,6 +10408,8 @@ class serializer
bytes_after_last_accept
=
bytes
;
bytes_after_last_accept
=
bytes
;
}
}
undumped_chars
=
0
;
// continue processing the string
// continue processing the string
state
=
UTF8_ACCEPT
;
state
=
UTF8_ACCEPT
;
continue
;
continue
;
...
@@ -10420,6 +10424,7 @@ class serializer
...
@@ -10420,6 +10424,7 @@ class serializer
// code point will not be escaped - copy byte to buffer
// code point will not be escaped - copy byte to buffer
string_buffer
[
bytes
++
]
=
s
[
i
];
string_buffer
[
bytes
++
]
=
s
[
i
];
}
}
++
undumped_chars
;
break
;
break
;
}
}
}
}
...
...
test/src/unit-unicode.cpp
View file @
c51b1e6f
...
@@ -76,8 +76,12 @@ void check_utf8dump(bool success_expected, int byte1, int byte2 = -1, int byte3
...
@@ -76,8 +76,12 @@ void check_utf8dump(bool success_expected, int byte1, int byte2 = -1, int byte3
// dumping with ignore/replace must not throw in any case
// dumping with ignore/replace must not throw in any case
auto
s_ignored
=
j
.
dump
(
-
1
,
' '
,
false
,
json
::
error_handler_t
::
ignore
);
auto
s_ignored
=
j
.
dump
(
-
1
,
' '
,
false
,
json
::
error_handler_t
::
ignore
);
auto
s_ignored2
=
j2
.
dump
(
-
1
,
' '
,
false
,
json
::
error_handler_t
::
ignore
);
auto
s_ignored2
=
j2
.
dump
(
-
1
,
' '
,
false
,
json
::
error_handler_t
::
ignore
);
auto
s_ignored_ascii
=
j
.
dump
(
-
1
,
' '
,
true
,
json
::
error_handler_t
::
ignore
);
auto
s_ignored2_ascii
=
j2
.
dump
(
-
1
,
' '
,
true
,
json
::
error_handler_t
::
ignore
);
auto
s_replaced
=
j
.
dump
(
-
1
,
' '
,
false
,
json
::
error_handler_t
::
replace
);
auto
s_replaced
=
j
.
dump
(
-
1
,
' '
,
false
,
json
::
error_handler_t
::
replace
);
auto
s_replaced2
=
j2
.
dump
(
-
1
,
' '
,
false
,
json
::
error_handler_t
::
replace
);
auto
s_replaced2
=
j2
.
dump
(
-
1
,
' '
,
false
,
json
::
error_handler_t
::
replace
);
auto
s_replaced_ascii
=
j
.
dump
(
-
1
,
' '
,
true
,
json
::
error_handler_t
::
replace
);
auto
s_replaced2_ascii
=
j2
.
dump
(
-
1
,
' '
,
true
,
json
::
error_handler_t
::
replace
);
if
(
success_expected
)
if
(
success_expected
)
{
{
...
@@ -102,8 +106,12 @@ void check_utf8dump(bool success_expected, int byte1, int byte2 = -1, int byte3
...
@@ -102,8 +106,12 @@ void check_utf8dump(bool success_expected, int byte1, int byte2 = -1, int byte3
// check that prefix and suffix are preserved
// check that prefix and suffix are preserved
CHECK
(
s_ignored2
.
substr
(
1
,
3
)
==
"abc"
);
CHECK
(
s_ignored2
.
substr
(
1
,
3
)
==
"abc"
);
CHECK
(
s_ignored2
.
substr
(
s_ignored2
.
size
()
-
4
,
3
)
==
"xyz"
);
CHECK
(
s_ignored2
.
substr
(
s_ignored2
.
size
()
-
4
,
3
)
==
"xyz"
);
CHECK
(
s_ignored2_ascii
.
substr
(
1
,
3
)
==
"abc"
);
CHECK
(
s_ignored2_ascii
.
substr
(
s_ignored2_ascii
.
size
()
-
4
,
3
)
==
"xyz"
);
CHECK
(
s_replaced2
.
substr
(
1
,
3
)
==
"abc"
);
CHECK
(
s_replaced2
.
substr
(
1
,
3
)
==
"abc"
);
CHECK
(
s_replaced2
.
substr
(
s_replaced2
.
size
()
-
4
,
3
)
==
"xyz"
);
CHECK
(
s_replaced2
.
substr
(
s_replaced2
.
size
()
-
4
,
3
)
==
"xyz"
);
CHECK
(
s_replaced2_ascii
.
substr
(
1
,
3
)
==
"abc"
);
CHECK
(
s_replaced2_ascii
.
substr
(
s_replaced2_ascii
.
size
()
-
4
,
3
)
==
"xyz"
);
}
}
void
check_utf8string
(
bool
success_expected
,
int
byte1
,
int
byte2
,
int
byte3
,
int
byte4
);
void
check_utf8string
(
bool
success_expected
,
int
byte1
,
int
byte2
,
int
byte3
,
int
byte4
);
...
...
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