Ticket #5086: boost_tokenizer_tolerate_negative_char.patch

File boost_tokenizer_tolerate_negative_char.patch, 2.5 KB (added by Kazutoshi Satoda <k_satoda@…>, 12 years ago)

svn diff for trunk r68230

  • boost/token_functions.hpp

     
    218218    {
    219219#if !defined(BOOST_NO_CWCTYPE)
    220220      if (sizeof(char_type) == 1)
    221         return std::isspace(static_cast<int>(c)) != 0;
     221        return std::isspace(static_cast<unsigned char>(c)) != 0;
    222222      else
    223223        return std::iswspace(static_cast<std::wint_t>(c)) != 0;
    224224#else
    225       return static_cast< unsigned >(c) <= 255 && std::isspace(c) != 0;
     225      return static_cast< unsigned >(c) <= 255 &&
     226        std::isspace(static_cast<unsigned char>(c)) != 0;
    226227#endif
    227228    }
    228229
     
    230231    {
    231232#if !defined(BOOST_NO_CWCTYPE)
    232233      if (sizeof(char_type) == 1)
    233         return std::ispunct(static_cast<int>(c)) != 0;
     234        return std::ispunct(static_cast<unsigned char>(c)) != 0;
    234235      else
    235236        return std::iswpunct(static_cast<std::wint_t>(c)) != 0;
    236237#else
    237       return static_cast< unsigned >(c) <= 255 && std::ispunct(c) != 0;
     238      return static_cast< unsigned >(c) <= 255
     239        && std::ispunct(static_cast<unsigned char>(c)) != 0;
    238240#endif
    239241    }
    240242  };
  • libs/tokenizer/test/tolerate_negative_char.cpp

     
     1// (c) Copyright Kazutoshi Satoda 2010.
     2
     3// Distributed under the Boost Software License, Version 1.0. (See
     4// accompanying file LICENSE_1_0.txt or copy at
     5// http://www.boost.org/LICENSE_1_0.txt)
     6
     7// See http://www.boost.org/libs/tokenizer for documenation
     8
     9/// Test to tolerate negative chars in input
     10#include <boost/tokenizer.hpp>
     11#include <string>
     12
     13int main()
     14{
     15    char const negative_char = -123;
     16    char const* p = &negative_char;
     17    std::string token;
     18    boost::char_separator<char>()(p, &negative_char + 1, token);
     19    // This is a very specific test for MSVC which can detect invalid
     20    // arguments for std::isXXX() (isspace(), ispunct(), ...) functions,
     21    // as assertion failure.
     22}
  • libs/tokenizer/test/Jamfile.v2

     
    1212    [ run simple_example_3.cpp ]
    1313    [ run simple_example_4.cpp ]
    1414    [ run simple_example_5.cpp ]
     15    [ run tolerate_negative_char.cpp ]
    1516    ;