1 /*============================================================================= 2 Copyright (c) 2001-2011 Hartmut Kaiser 3 Copyright (c) 2001-2011 Joel de Guzman 4 5 Distributed under the Boost Software License, Version 1.0. (See accompanying 6 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 =============================================================================*/ 8 #if !defined(BOOST_SPIRIT_STANDARD_APRIL_26_2006_1106PM) 9 #define BOOST_SPIRIT_STANDARD_APRIL_26_2006_1106PM 10 11 #if defined(_MSC_VER) 12 #pragma once 13 #endif 14 15 #include <cctype> 16 #include <climits> 17 #include <boost/assert.hpp> 18 #include <boost/cstdint.hpp> 19 20 namespace boost { namespace spirit { namespace char_encoding 21 { 22 /////////////////////////////////////////////////////////////////////////// 23 // Test characters for specified conditions (using std functions) 24 /////////////////////////////////////////////////////////////////////////// 25 struct standard 26 { 27 typedef char char_type; 28 typedef unsigned char classify_type; 29 30 static bool isascii_boost::spirit::char_encoding::standard31 isascii_(int ch) 32 { 33 return 0 == (ch & ~0x7f); 34 } 35 36 static bool ischarboost::spirit::char_encoding::standard37 ischar(int ch) 38 { 39 // uses all 8 bits 40 // we have to watch out for sign extensions 41 return (0 == (ch & ~0xff) || ~0 == (ch | 0xff)) != 0; 42 } 43 44 // *** Note on assertions: The precondition is that the calls to 45 // these functions do not violate the required range of ch (int) 46 // which is that strict_ischar(ch) should be true. It is the 47 // responsibility of the caller to make sure this precondition is not 48 // violated. 49 50 static bool strict_ischarboost::spirit::char_encoding::standard51 strict_ischar(int ch) 52 { 53 // ch should be representable as an unsigned char 54 return ch >= 0 && ch <= UCHAR_MAX; 55 } 56 57 static bool isalnumboost::spirit::char_encoding::standard58 isalnum(int ch) 59 { 60 BOOST_ASSERT(strict_ischar(ch)); 61 return std::isalnum(ch) != 0; 62 } 63 64 static bool isalphaboost::spirit::char_encoding::standard65 isalpha(int ch) 66 { 67 BOOST_ASSERT(strict_ischar(ch)); 68 return std::isalpha(ch) != 0; 69 } 70 71 static bool isdigitboost::spirit::char_encoding::standard72 isdigit(int ch) 73 { 74 BOOST_ASSERT(strict_ischar(ch)); 75 return std::isdigit(ch) != 0; 76 } 77 78 static bool isxdigitboost::spirit::char_encoding::standard79 isxdigit(int ch) 80 { 81 BOOST_ASSERT(strict_ischar(ch)); 82 return std::isxdigit(ch) != 0; 83 } 84 85 static bool iscntrlboost::spirit::char_encoding::standard86 iscntrl(int ch) 87 { 88 BOOST_ASSERT(strict_ischar(ch)); 89 return std::iscntrl(ch) != 0; 90 } 91 92 static bool isgraphboost::spirit::char_encoding::standard93 isgraph(int ch) 94 { 95 BOOST_ASSERT(strict_ischar(ch)); 96 return std::isgraph(ch) != 0; 97 } 98 99 static bool islowerboost::spirit::char_encoding::standard100 islower(int ch) 101 { 102 BOOST_ASSERT(strict_ischar(ch)); 103 return std::islower(ch) != 0; 104 } 105 106 static bool isprintboost::spirit::char_encoding::standard107 isprint(int ch) 108 { 109 BOOST_ASSERT(strict_ischar(ch)); 110 return std::isprint(ch) != 0; 111 } 112 113 static bool ispunctboost::spirit::char_encoding::standard114 ispunct(int ch) 115 { 116 BOOST_ASSERT(strict_ischar(ch)); 117 return std::ispunct(ch) != 0; 118 } 119 120 static bool isspaceboost::spirit::char_encoding::standard121 isspace(int ch) 122 { 123 BOOST_ASSERT(strict_ischar(ch)); 124 return std::isspace(ch) != 0; 125 } 126 127 static bool BOOST_PREVENT_MACRO_SUBSTITUTIONboost::spirit::char_encoding::standard128 isblank BOOST_PREVENT_MACRO_SUBSTITUTION (int ch) 129 { 130 BOOST_ASSERT(strict_ischar(ch)); 131 return (ch == ' ' || ch == '\t'); 132 } 133 134 static bool isupperboost::spirit::char_encoding::standard135 isupper(int ch) 136 { 137 BOOST_ASSERT(strict_ischar(ch)); 138 return std::isupper(ch) != 0; 139 } 140 141 /////////////////////////////////////////////////////////////////////////////// 142 // Simple character conversions 143 /////////////////////////////////////////////////////////////////////////////// 144 145 static int tolowerboost::spirit::char_encoding::standard146 tolower(int ch) 147 { 148 BOOST_ASSERT(strict_ischar(ch)); 149 return std::tolower(ch); 150 } 151 152 static int toupperboost::spirit::char_encoding::standard153 toupper(int ch) 154 { 155 BOOST_ASSERT(strict_ischar(ch)); 156 return std::toupper(ch); 157 } 158 159 static ::boost::uint32_t toucs4boost::spirit::char_encoding::standard160 toucs4(int ch) 161 { 162 BOOST_ASSERT(strict_ischar(ch)); 163 return ch; 164 } 165 }; 166 }}} 167 168 #endif 169