| 1 | --- /tmp/json_parser_write.hpp 2015-11-10 15:40:51.487154585 -0400
|
|---|
| 2 | +++ json_parser_write.hpp 2015-11-10 15:47:08.967154252 -0400
|
|---|
| 3 | @@ -20,6 +20,36 @@
|
|---|
| 4 | namespace boost { namespace property_tree { namespace json_parser
|
|---|
| 5 | {
|
|---|
| 6 |
|
|---|
| 7 | + /*
|
|---|
| 8 | + * Add specialized checks for the case where the character
|
|---|
| 9 | + * class is char or unsigned char. The specialized check avoids
|
|---|
| 10 | + * comparing to <= 0xFF which triggers a GCC warning about the
|
|---|
| 11 | + * fact that the check is always true.
|
|---|
| 12 | + *
|
|---|
| 13 | + * See https://svn.boost.org/trac/boost/ticket/5598
|
|---|
| 14 | + */
|
|---|
| 15 | + namespace detail {
|
|---|
| 16 | + template <class Ch>
|
|---|
| 17 | + bool check_is_ascii(const Ch c)
|
|---|
| 18 | + {
|
|---|
| 19 | + return (c == 0x20 || c == 0x21 || (c >= 0x23 && c <= 0x2E) ||
|
|---|
| 20 | + (c >= 0x30 && c <= 0x5B) || (c >= 0x5D && c <= 0xFF));
|
|---|
| 21 | + }
|
|---|
| 22 | +
|
|---|
| 23 | + template <>
|
|---|
| 24 | + bool check_is_ascii(const char c)
|
|---|
| 25 | + {
|
|---|
| 26 | + return (c == 0x20 || c == 0x21 || (c >= 0x23 && c <= 0x2E) ||
|
|---|
| 27 | + (c >= 0x30 && c <= 0x5B) || c >= 0x5D);
|
|---|
| 28 | + }
|
|---|
| 29 | +
|
|---|
| 30 | + template <>
|
|---|
| 31 | + bool check_is_ascii(const unsigned char c)
|
|---|
| 32 | + {
|
|---|
| 33 | + return (c == 0x20 || c == 0x21 || (c >= 0x23 && c <= 0x2E) ||
|
|---|
| 34 | + (c >= 0x30 && c <= 0x5B) || c >= 0x5D);
|
|---|
| 35 | + }
|
|---|
| 36 | + }
|
|---|
| 37 | // Create necessary escape sequences from illegal characters
|
|---|
| 38 | template<class Ch>
|
|---|
| 39 | std::basic_string<Ch> create_escapes(const std::basic_string<Ch> &s)
|
|---|
| 40 | @@ -30,12 +60,10 @@
|
|---|
| 41 | while (b != e)
|
|---|
| 42 | {
|
|---|
| 43 | typedef typename make_unsigned<Ch>::type UCh;
|
|---|
| 44 | - UCh c(*b);
|
|---|
| 45 | // This assumes an ASCII superset. But so does everything in PTree.
|
|---|
| 46 | // We escape everything outside ASCII, because this code can't
|
|---|
| 47 | // handle high unicode characters.
|
|---|
| 48 | - if (c == 0x20 || c == 0x21 || (c >= 0x23 && c <= 0x2E) ||
|
|---|
| 49 | - (c >= 0x30 && c <= 0x5B) || (c >= 0x5D && c <= 0xFF))
|
|---|
| 50 | + if (detail::check_is_ascii(*b))
|
|---|
| 51 | result += *b;
|
|---|
| 52 | else if (*b == Ch('\b')) result += Ch('\\'), result += Ch('b');
|
|---|
| 53 | else if (*b == Ch('\f')) result += Ch('\\'), result += Ch('f');
|
|---|