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
71597be2
Commit
71597be2
authored
Jul 11, 2017
by
Ryan Mulder
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add ensure_ascii parameter to dump. #330
parent
7dee868a
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
77 additions
and
42 deletions
+77
-42
json.hpp
src/json.hpp
+65
-40
unit-convenience.cpp
test/src/unit-convenience.cpp
+5
-2
unit-inspection.cpp
test/src/unit-inspection.cpp
+7
-0
No files found.
src/json.hpp
View file @
71597be2
This diff is collapsed.
Click to expand it.
test/src/unit-convenience.cpp
View file @
71597be2
...
@@ -50,11 +50,12 @@ TEST_CASE("convenience functions")
...
@@ -50,11 +50,12 @@ TEST_CASE("convenience functions")
SECTION
(
"string escape"
)
SECTION
(
"string escape"
)
{
{
const
auto
check_escaped
=
[](
const
char
*
original
,
const
auto
check_escaped
=
[](
const
char
*
original
,
const
char
*
escaped
)
const
char
*
escaped
,
const
bool
ensure_ascii
=
false
)
{
{
std
::
stringstream
ss
;
std
::
stringstream
ss
;
json
::
serializer
s
(
nlohmann
::
detail
::
output_adapter_factory
<
char
>::
create
(
ss
),
' '
);
json
::
serializer
s
(
nlohmann
::
detail
::
output_adapter_factory
<
char
>::
create
(
ss
),
' '
);
s
.
dump_escaped
(
original
);
s
.
dump_escaped
(
original
,
ensure_ascii
);
CHECK
(
ss
.
str
()
==
escaped
);
CHECK
(
ss
.
str
()
==
escaped
);
};
};
...
@@ -97,5 +98,7 @@ TEST_CASE("convenience functions")
...
@@ -97,5 +98,7 @@ TEST_CASE("convenience functions")
check_escaped
(
"
\x1d
"
,
"
\\
u001d"
);
check_escaped
(
"
\x1d
"
,
"
\\
u001d"
);
check_escaped
(
"
\x1e
"
,
"
\\
u001e"
);
check_escaped
(
"
\x1e
"
,
"
\\
u001e"
);
check_escaped
(
"
\x1f
"
,
"
\\
u001f"
);
check_escaped
(
"
\x1f
"
,
"
\\
u001f"
);
check_escaped
(
"
\xA9
"
,
"
\xA9
"
);
check_escaped
(
"
\xA9
"
,
"
\\
u00a9"
,
true
);
}
}
}
}
test/src/unit-inspection.cpp
View file @
71597be2
...
@@ -250,6 +250,13 @@ TEST_CASE("object inspection")
...
@@ -250,6 +250,13 @@ TEST_CASE("object inspection")
CHECK
(
json
(
"❤️"
).
dump
()
==
"
\"
❤️
\"
"
);
CHECK
(
json
(
"❤️"
).
dump
()
==
"
\"
❤️
\"
"
);
}
}
SECTION
(
"dump with ensure_ascii and non-ASCII characters"
)
{
CHECK
(
json
(
"ä"
).
dump
(
-
1
,
' '
,
true
)
==
R"("\u00c3\u00a4")"
);
CHECK
(
json
(
"Ö"
).
dump
(
-
1
,
' '
,
true
)
==
R"("\u00c3\u0096")"
);
CHECK
(
json
(
"❤️"
).
dump
(
-
1
,
' '
,
true
)
==
R"("\u00e2\u009d\u00a4\u00ef\u00b8\u008f")"
);
}
SECTION
(
"serialization of discarded element"
)
SECTION
(
"serialization of discarded element"
)
{
{
json
j_discarded
(
json
::
value_t
::
discarded
);
json
j_discarded
(
json
::
value_t
::
discarded
);
...
...
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