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 <boost/assert.hpp> 17 #include <boost/cstdint.hpp> 18 19 namespace boost { namespace spirit { namespace char_encoding 20 { 21 /////////////////////////////////////////////////////////////////////////// 22 // Test characters for specified conditions (using std functions) 23 /////////////////////////////////////////////////////////////////////////// 24 struct standard 25 { 26 typedef char char_type; 27 typedef unsigned char classify_type; 28 29 static bool isascii_boost::spirit::char_encoding::standard30 isascii_(int ch) 31 { 32 return 0 == (ch & ~0x7f); 33 } 34 35 static bool ischarboost::spirit::char_encoding::standard36 ischar(int ch) 37 { 38 // uses all 8 bits 39 // we have to watch out for sign extensions 40 return (0 == (ch & ~0xff) || ~0 == (ch | 0xff)) != 0; 41 } 42 43 // *** Note on assertions: The precondition is that the calls to 44 // these functions do not violate the required range of ch (int) 45 // which is that strict_ischar(ch) should be true. It is the 46 // responsibility of the caller to make sure this precondition is not 47 // violated. 48 49 static bool strict_ischarboost::spirit::char_encoding::standard50 strict_ischar(int ch) 51 { 52 // ch should be representable as an unsigned char 53 return ch >= 0 && ch <= UCHAR_MAX; 54 } 55 56 static bool isalnumboost::spirit::char_encoding::standard57 isalnum(int ch) 58 { 59 BOOST_ASSERT(strict_ischar(ch)); 60 return std::isalnum(ch) != 0; 61 } 62 63 static bool isalphaboost::spirit::char_encoding::standard64 isalpha(int ch) 65 { 66 BOOST_ASSERT(strict_ischar(ch)); 67 return std::isalpha(ch) != 0; 68 } 69 70 static bool isdigitboost::spirit::char_encoding::standard71 isdigit(int ch) 72 { 73 BOOST_ASSERT(strict_ischar(ch)); 74 return std::isdigit(ch) != 0; 75 } 76 77 static bool isxdigitboost::spirit::char_encoding::standard78 isxdigit(int ch) 79 { 80 BOOST_ASSERT(strict_ischar(ch)); 81 return std::isxdigit(ch) != 0; 82 } 83 84 static bool iscntrlboost::spirit::char_encoding::standard85 iscntrl(int ch) 86 { 87 BOOST_ASSERT(strict_ischar(ch)); 88 return std::iscntrl(ch) != 0; 89 } 90 91 static bool isgraphboost::spirit::char_encoding::standard92 isgraph(int ch) 93 { 94 BOOST_ASSERT(strict_ischar(ch)); 95 return std::isgraph(ch) != 0; 96 } 97 98 static bool islowerboost::spirit::char_encoding::standard99 islower(int ch) 100 { 101 BOOST_ASSERT(strict_ischar(ch)); 102 return std::islower(ch) != 0; 103 } 104 105 static bool isprintboost::spirit::char_encoding::standard106 isprint(int ch) 107 { 108 BOOST_ASSERT(strict_ischar(ch)); 109 return std::isprint(ch) != 0; 110 } 111 112 static bool ispunctboost::spirit::char_encoding::standard113 ispunct(int ch) 114 { 115 BOOST_ASSERT(strict_ischar(ch)); 116 return std::ispunct(ch) != 0; 117 } 118 119 static bool isspaceboost::spirit::char_encoding::standard120 isspace(int ch) 121 { 122 BOOST_ASSERT(strict_ischar(ch)); 123 return std::isspace(ch) != 0; 124 } 125 126 static bool BOOST_PREVENT_MACRO_SUBSTITUTIONboost::spirit::char_encoding::standard127 isblank BOOST_PREVENT_MACRO_SUBSTITUTION (int ch) 128 { 129 BOOST_ASSERT(strict_ischar(ch)); 130 return (ch == ' ' || ch == '\t'); 131 } 132 133 static bool isupperboost::spirit::char_encoding::standard134 isupper(int ch) 135 { 136 BOOST_ASSERT(strict_ischar(ch)); 137 return std::isupper(ch) != 0; 138 } 139 140 /////////////////////////////////////////////////////////////////////////////// 141 // Simple character conversions 142 /////////////////////////////////////////////////////////////////////////////// 143 144 static int tolowerboost::spirit::char_encoding::standard145 tolower(int ch) 146 { 147 BOOST_ASSERT(strict_ischar(ch)); 148 return std::tolower(ch); 149 } 150 151 static int toupperboost::spirit::char_encoding::standard152 toupper(int ch) 153 { 154 BOOST_ASSERT(strict_ischar(ch)); 155 return std::toupper(ch); 156 } 157 158 static ::boost::uint32_t toucs4boost::spirit::char_encoding::standard159 toucs4(int ch) 160 { 161 BOOST_ASSERT(strict_ischar(ch)); 162 return ch; 163 } 164 }; 165 }}} 166 167 #endif 168