Ticket #5598: json_parser_write.hpp.2.diff
File json_parser_write.hpp.2.diff, 2.0 KB (added by , 9 years ago) |
---|
-
boost/property_tree/detail/json_parser_write.hpp
19 19 20 20 namespace boost { namespace property_tree { namespace json_parser 21 21 { 22 /* 23 * Add specialized checks for the case where the character 24 * class is char or unsigned char. The specialized check avoids 25 * comparing to <= 0xFF which triggers a GCC warning about the 26 * fact that the check is always true. 27 * 28 * See https://svn.boost.org/trac/boost/ticket/5598 29 */ 30 namespace detail { 31 template <class Ch> 32 bool check_is_ascii(const Ch c) 33 { 34 return (c == 0x20 || c == 0x21 || (c >= 0x23 && c <= 0x2E) || 35 (c >= 0x30 && c <= 0x5B) || (c >= 0x5D && c <= 0xFF)); 36 } 37 38 template <> 39 bool check_is_ascii(const char c) 40 { 41 return (c == 0x20 || c == 0x21 || (c >= 0x23 && c <= 0x2E) || 42 (c >= 0x30 && c <= 0x5B) || c >= 0x5D); 43 } 44 45 template <> 46 bool check_is_ascii(const unsigned char c) 47 { 48 return (c == 0x20 || c == 0x21 || (c >= 0x23 && c <= 0x2E) || 49 (c >= 0x30 && c <= 0x5B) || c >= 0x5D); 50 } 51 } 22 52 23 53 // Create necessary escape sequences from illegal characters 24 54 template<class Ch> … … 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');