Ticket #5598: json_parser_write.hpp.2.diff

File json_parser_write.hpp.2.diff, 2.0 KB (added by Matthieu Vachon <matthieu.o.vachon@…>, 9 years ago)

Updated patch for 1.53.0

  • boost/property_tree/detail/json_parser_write.hpp

     
    1919
    2020namespace boost { namespace property_tree { namespace json_parser
    2121{
     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    } 
    2252
    2353    // Create necessary escape sequences from illegal characters
    2454    template<class Ch>
     
    3262            // This assumes an ASCII superset. But so does everything in PTree.
    3363            // We escape everything outside ASCII, because this code can't
    3464            // 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))               
    3766                result += *b;
    3867            else if (*b == Ch('\b')) result += Ch('\\'), result += Ch('b');
    3968            else if (*b == Ch('\f')) result += Ch('\\'), result += Ch('f');