Ticket #5086: boost_tokenizer_tolerate_negative_char.patch
File boost_tokenizer_tolerate_negative_char.patch, 2.5 KB (added by , 12 years ago) |
---|
-
boost/token_functions.hpp
218 218 { 219 219 #if !defined(BOOST_NO_CWCTYPE) 220 220 if (sizeof(char_type) == 1) 221 return std::isspace(static_cast< int>(c)) != 0;221 return std::isspace(static_cast<unsigned char>(c)) != 0; 222 222 else 223 223 return std::iswspace(static_cast<std::wint_t>(c)) != 0; 224 224 #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; 226 227 #endif 227 228 } 228 229 … … 230 231 { 231 232 #if !defined(BOOST_NO_CWCTYPE) 232 233 if (sizeof(char_type) == 1) 233 return std::ispunct(static_cast< int>(c)) != 0;234 return std::ispunct(static_cast<unsigned char>(c)) != 0; 234 235 else 235 236 return std::iswpunct(static_cast<std::wint_t>(c)) != 0; 236 237 #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; 238 240 #endif 239 241 } 240 242 }; -
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 13 int 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
12 12 [ run simple_example_3.cpp ] 13 13 [ run simple_example_4.cpp ] 14 14 [ run simple_example_5.cpp ] 15 [ run tolerate_negative_char.cpp ] 15 16 ;