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
c7af027c
Unverified
Commit
c7af027c
authored
6 years ago
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
respect ensure_ascii parameter #1198
parent
e5dce641
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
47 additions
and
21 deletions
+47
-21
include/nlohmann/detail/output/serializer.hpp
include/nlohmann/detail/output/serializer.hpp
+23
-7
single_include/nlohmann/json.hpp
single_include/nlohmann/json.hpp
+23
-7
test/src/unit-unicode.cpp
test/src/unit-unicode.cpp
+1
-7
No files found.
include/nlohmann/detail/output/serializer.hpp
View file @
c7af027c
...
@@ -436,12 +436,21 @@ class serializer
...
@@ -436,12 +436,21 @@ class serializer
if
(
error_handler
==
error_handler_t
::
replace
)
if
(
error_handler
==
error_handler_t
::
replace
)
{
{
// add a replacement character
// add a replacement character
string_buffer
[
bytes
++
]
=
'\\'
;
if
(
ensure_ascii
)
string_buffer
[
bytes
++
]
=
'u'
;
{
string_buffer
[
bytes
++
]
=
'f'
;
string_buffer
[
bytes
++
]
=
'\\'
;
string_buffer
[
bytes
++
]
=
'f'
;
string_buffer
[
bytes
++
]
=
'u'
;
string_buffer
[
bytes
++
]
=
'f'
;
string_buffer
[
bytes
++
]
=
'f'
;
string_buffer
[
bytes
++
]
=
'd'
;
string_buffer
[
bytes
++
]
=
'f'
;
string_buffer
[
bytes
++
]
=
'f'
;
string_buffer
[
bytes
++
]
=
'd'
;
}
else
{
string_buffer
[
bytes
++
]
=
'\xEF'
;
string_buffer
[
bytes
++
]
=
'\xBF'
;
string_buffer
[
bytes
++
]
=
'\xBD'
;
}
bytes_after_last_accept
=
bytes
;
bytes_after_last_accept
=
bytes
;
}
}
...
@@ -497,7 +506,14 @@ class serializer
...
@@ -497,7 +506,14 @@ class serializer
// write all accepted bytes
// write all accepted bytes
o
->
write_characters
(
string_buffer
.
data
(),
bytes_after_last_accept
);
o
->
write_characters
(
string_buffer
.
data
(),
bytes_after_last_accept
);
// add a replacement character
// add a replacement character
o
->
write_characters
(
"
\\
ufffd"
,
6
);
if
(
ensure_ascii
)
{
o
->
write_characters
(
"
\\
ufffd"
,
6
);
}
else
{
o
->
write_characters
(
"
\xEF\xBF\xBD
"
,
3
);
}
break
;
break
;
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
single_include/nlohmann/json.hpp
View file @
c7af027c
...
@@ -10388,12 +10388,21 @@ class serializer
...
@@ -10388,12 +10388,21 @@ class serializer
if
(
error_handler
==
error_handler_t
::
replace
)
if
(
error_handler
==
error_handler_t
::
replace
)
{
{
// add a replacement character
// add a replacement character
string_buffer
[
bytes
++
]
=
'\\'
;
if
(
ensure_ascii
)
string_buffer
[
bytes
++
]
=
'u'
;
{
string_buffer
[
bytes
++
]
=
'f'
;
string_buffer
[
bytes
++
]
=
'\\'
;
string_buffer
[
bytes
++
]
=
'f'
;
string_buffer
[
bytes
++
]
=
'u'
;
string_buffer
[
bytes
++
]
=
'f'
;
string_buffer
[
bytes
++
]
=
'f'
;
string_buffer
[
bytes
++
]
=
'd'
;
string_buffer
[
bytes
++
]
=
'f'
;
string_buffer
[
bytes
++
]
=
'f'
;
string_buffer
[
bytes
++
]
=
'd'
;
}
else
{
string_buffer
[
bytes
++
]
=
'\xEF'
;
string_buffer
[
bytes
++
]
=
'\xBF'
;
string_buffer
[
bytes
++
]
=
'\xBD'
;
}
bytes_after_last_accept
=
bytes
;
bytes_after_last_accept
=
bytes
;
}
}
...
@@ -10449,7 +10458,14 @@ class serializer
...
@@ -10449,7 +10458,14 @@ class serializer
// write all accepted bytes
// write all accepted bytes
o
->
write_characters
(
string_buffer
.
data
(),
bytes_after_last_accept
);
o
->
write_characters
(
string_buffer
.
data
(),
bytes_after_last_accept
);
// add a replacement character
// add a replacement character
o
->
write_characters
(
"
\\
ufffd"
,
6
);
if
(
ensure_ascii
)
{
o
->
write_characters
(
"
\\
ufffd"
,
6
);
}
else
{
o
->
write_characters
(
"
\xEF\xBF\xBD
"
,
3
);
}
break
;
break
;
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
test/src/unit-unicode.cpp
View file @
c7af027c
...
@@ -86,10 +86,6 @@ void check_utf8dump(bool success_expected, int byte1, int byte2 = -1, int byte3
...
@@ -86,10 +86,6 @@ void check_utf8dump(bool success_expected, int byte1, int byte2 = -1, int byte3
// all dumps should agree on the string
// all dumps should agree on the string
CHECK
(
s_strict
==
s_ignored
);
CHECK
(
s_strict
==
s_ignored
);
CHECK
(
s_strict
==
s_replaced
);
CHECK
(
s_strict
==
s_replaced
);
// check that ignore/replace string does not contain a replacement character
CHECK
(
s_ignored
.
find
(
"
\\
ufffd"
)
==
std
::
string
::
npos
);
CHECK
(
s_replaced
.
find
(
"
\\
ufffd"
)
==
std
::
string
::
npos
);
}
}
else
else
{
{
...
@@ -98,10 +94,8 @@ void check_utf8dump(bool success_expected, int byte1, int byte2 = -1, int byte3
...
@@ -98,10 +94,8 @@ void check_utf8dump(bool success_expected, int byte1, int byte2 = -1, int byte3
// ignore and replace must create different dumps
// ignore and replace must create different dumps
CHECK
(
s_ignored
!=
s_replaced
);
CHECK
(
s_ignored
!=
s_replaced
);
// check that ignore string does not contain a replacement character
CHECK
(
s_ignored
.
find
(
"
\\
ufffd"
)
==
std
::
string
::
npos
);
// check that replace string contains a replacement character
// check that replace string contains a replacement character
CHECK
(
s_replaced
.
find
(
"
\
\
ufffd
"
)
!=
std
::
string
::
npos
);
CHECK
(
s_replaced
.
find
(
"
\
xEF\xBF\xBD
"
)
!=
std
::
string
::
npos
);
}
}
...
...
This diff is collapsed.
Click to expand it.
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