Skip to content

Commit a4ae149

Browse files
committed
Readded automatic quote escaping.
1 parent c951193 commit a4ae149

File tree

3 files changed

+18
-13
lines changed

3 files changed

+18
-13
lines changed

parse/jsd_options.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ namespace JSON
2929
InvalidPathHandlingBehaviour invalidPathHandler = InvalidPathHandlingBehaviour::THROW,
3030
bool strings_are_binary = false
3131
)
32-
: invalidPropertyHandler(invalidPropertyHandler)
33-
, invalidPathHandler(invalidPathHandler)
34-
, strings_are_binary(strings_are_binary)
32+
: invalidPropertyHandler{invalidPropertyHandler}
33+
, invalidPathHandler{invalidPathHandler}
34+
, strings_are_binary{strings_are_binary}
3535
{}
3636
};
3737

stringify/jss_options.hpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,23 @@ namespace JSON
2020
bool reverse_order;
2121
PointerHandling ptr_behaviour;
2222
bool in_object;
23-
bool strings_are_binary;
23+
bool strings_are_binary;
24+
bool escape_strings;
2425

2526
StringificationOptions (bool ignore_name = false,
2627
std::string delimiter = ",",
2728
bool reverse_order = false,
2829
PointerHandling ptr_behaviour = {},
2930
bool in_object = false,
30-
bool strings_are_binary = false)
31+
bool strings_are_binary = false,
32+
bool escape_strings = true)
3133
: ignore_name {ignore_name}
3234
, delimiter {delimiter}
3335
, reverse_order {reverse_order}
3436
, ptr_behaviour {ptr_behaviour}
3537
, in_object {in_object}
36-
, strings_are_binary {strings_are_binary}
38+
, strings_are_binary {strings_are_binary}
39+
, escape_strings {escape_strings}
3740
{}
3841
};
3942

stringify/jss_string.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,17 @@ namespace JSON
99
stream << '"';
1010
if (!options.strings_are_binary)
1111
{
12-
/*
13-
for (auto const& i : value)
12+
if (options.escape_strings)
1413
{
15-
if (i == '"' || i == '\\')
16-
stream.put('\\');
17-
stream.put(i);
14+
for (auto const& i : value)
15+
{
16+
if (i == '"' || i == '\\')
17+
stream.put('\\');
18+
stream.put(i);
19+
}
1820
}
19-
*/
20-
stream << value;
21+
else
22+
stream << value;
2123
}
2224
else
2325
{

0 commit comments

Comments
 (0)