| 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 |
| 31 | isascii_(int ch) |
| 32 | { |
| 33 | return 0 == (ch & ~0x7f); |
| 34 | } |
| 35 | |
| 36 | static bool |
| 37 | 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 |
| 51 | 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 |
| 58 | isalnum(int ch) |
| 59 | { |
| 60 | BOOST_ASSERT(strict_ischar(ch)); |
| 61 | return std::isalnum(ch) != 0; |
| 62 | } |
| 63 | |
| 64 | static bool |
| 65 | isalpha(int ch) |
| 66 | { |
| 67 | BOOST_ASSERT(strict_ischar(ch)); |
| 68 | return std::isalpha(ch) != 0; |
| 69 | } |
| 70 | |
| 71 | static bool |
| 72 | isdigit(int ch) |
| 73 | { |
| 74 | BOOST_ASSERT(strict_ischar(ch)); |
| 75 | return std::isdigit(ch) != 0; |
| 76 | } |
| 77 | |
| 78 | static bool |
| 79 | isxdigit(int ch) |
| 80 | { |
| 81 | BOOST_ASSERT(strict_ischar(ch)); |
| 82 | return std::isxdigit(ch) != 0; |
| 83 | } |
| 84 | |
| 85 | static bool |
| 86 | iscntrl(int ch) |
| 87 | { |
| 88 | BOOST_ASSERT(strict_ischar(ch)); |
| 89 | return std::iscntrl(ch) != 0; |
| 90 | } |
| 91 | |
| 92 | static bool |
| 93 | isgraph(int ch) |
| 94 | { |
| 95 | BOOST_ASSERT(strict_ischar(ch)); |
| 96 | return std::isgraph(ch) != 0; |
| 97 | } |
| 98 | |
| 99 | static bool |
| 100 | islower(int ch) |
| 101 | { |
| 102 | BOOST_ASSERT(strict_ischar(ch)); |
| 103 | return std::islower(ch) != 0; |
| 104 | } |
| 105 | |
| 106 | static bool |
| 107 | isprint(int ch) |
| 108 | { |
| 109 | BOOST_ASSERT(strict_ischar(ch)); |
| 110 | return std::isprint(ch) != 0; |
| 111 | } |
| 112 | |
| 113 | static bool |
| 114 | ispunct(int ch) |
| 115 | { |
| 116 | BOOST_ASSERT(strict_ischar(ch)); |
| 117 | return std::ispunct(ch) != 0; |
| 118 | } |
| 119 | |
| 120 | static bool |
| 121 | isspace(int ch) |
| 122 | { |
| 123 | BOOST_ASSERT(strict_ischar(ch)); |
| 124 | return std::isspace(ch) != 0; |
| 125 | } |
| 126 | |
| 127 | static bool |
| 128 | isblank BOOST_PREVENT_MACRO_SUBSTITUTION (int ch) |
| 129 | { |
| 130 | BOOST_ASSERT(strict_ischar(ch)); |
| 131 | return (ch == ' ' || ch == '\t'); |
| 132 | } |
| 133 | |
| 134 | static bool |
| 135 | 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 |
| 146 | tolower(int ch) |
| 147 | { |
| 148 | BOOST_ASSERT(strict_ischar(ch)); |
| 149 | return std::tolower(c: ch); |
| 150 | } |
| 151 | |
| 152 | static int |
| 153 | toupper(int ch) |
| 154 | { |
| 155 | BOOST_ASSERT(strict_ischar(ch)); |
| 156 | return std::toupper(c: ch); |
| 157 | } |
| 158 | |
| 159 | static ::boost::uint32_t |
| 160 | toucs4(int ch) |
| 161 | { |
| 162 | BOOST_ASSERT(strict_ischar(ch)); |
| 163 | return ch; |
| 164 | } |
| 165 | }; |
| 166 | }}} |
| 167 | |
| 168 | #endif |
| 169 | |