Ticket #5598: json_parser_write.hpp.diff
File json_parser_write.hpp.diff, 2.0 KB (added by , 10 years ago) |
---|
-
boost/property_tree/detail/json_parser_write.hpp
old new 20 20 namespace boost { namespace property_tree { namespace json_parser 21 21 { 22 22 23 /* 24 * Add specialized checks for the case where the character 25 * class is char or unsigned char. The specialized check avoids 26 * comparing to <= 0xFF which triggers a GCC warning about the 27 * fact that the check is always true. 28 * 29 * See https://svn.boost.org/trac/boost/ticket/5598 30 */ 31 namespace detail { 32 template <class Ch> 33 bool check_is_ascii(const Ch c) 34 { 35 return (c == 0x20 || c == 0x21 || (c >= 0x23 && c <= 0x2E) || 36 (c >= 0x30 && c <= 0x5B) || (c >= 0x5D && c <= 0xFF)); 37 } 38 39 template <> 40 bool check_is_ascii(const char c) 41 { 42 return (c == 0x20 || c == 0x21 || (c >= 0x23 && c <= 0x2E) || 43 (c >= 0x30 && c <= 0x5B) || c >= 0x5D); 44 } 45 46 template <> 47 bool check_is_ascii(const unsigned char c) 48 { 49 return (c == 0x20 || c == 0x21 || (c >= 0x23 && c <= 0x2E) || 50 (c >= 0x30 && c <= 0x5B) || c >= 0x5D); 51 } 52 } 23 53 // Create necessary escape sequences from illegal characters 24 54 template<class Ch> 25 55 std::basic_string<Ch> create_escapes(const std::basic_string<Ch> &s) … … 32 62 // This assumes an ASCII superset. But so does everything in PTree. 33 63 // We escape everything outside ASCII, because this code can't 34 64 // handle high unicode characters. 35 if (*b == 0x20 || *b == 0x21 || (*b >= 0x23 && *b <= 0x2E) || 36 (*b >= 0x30 && *b <= 0x5B) || (*b >= 0x5D && *b <= 0xFF)) 65 if (detail::check_is_ascii(*b)) 37 66 result += *b; 38 67 else if (*b == Ch('\b')) result += Ch('\\'), result += Ch('b'); 39 68 else if (*b == Ch('\f')) result += Ch('\\'), result += Ch('f');