]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/boost/spirit/home/support/char_encoding/standard.hpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / boost / spirit / home / support / char_encoding / standard.hpp
CommitLineData
7c673cae
FG
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>
92f5a8d4 16#include <boost/assert.hpp>
7c673cae
FG
17#include <boost/cstdint.hpp>
18
19namespace 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;
92f5a8d4 27 typedef unsigned char classify_type;
7c673cae
FG
28
29 static bool
30 isascii_(int ch)
31 {
32 return 0 == (ch & ~0x7f);
33 }
34
35 static bool
36 ischar(int ch)
37 {
38 // uses all 8 bits
39 // we have to watch out for sign extensions
92f5a8d4
TL
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
50 strict_ischar(int ch)
51 {
52 // ch should be representable as an unsigned char
53 return ch >= 0 && ch <= UCHAR_MAX;
7c673cae
FG
54 }
55
56 static bool
57 isalnum(int ch)
58 {
92f5a8d4
TL
59 BOOST_ASSERT(strict_ischar(ch));
60 return std::isalnum(ch) != 0;
7c673cae
FG
61 }
62
63 static bool
64 isalpha(int ch)
65 {
92f5a8d4
TL
66 BOOST_ASSERT(strict_ischar(ch));
67 return std::isalpha(ch) != 0;
7c673cae
FG
68 }
69
70 static bool
71 isdigit(int ch)
72 {
92f5a8d4
TL
73 BOOST_ASSERT(strict_ischar(ch));
74 return std::isdigit(ch) != 0;
7c673cae
FG
75 }
76
77 static bool
78 isxdigit(int ch)
79 {
92f5a8d4
TL
80 BOOST_ASSERT(strict_ischar(ch));
81 return std::isxdigit(ch) != 0;
7c673cae
FG
82 }
83
84 static bool
85 iscntrl(int ch)
86 {
92f5a8d4
TL
87 BOOST_ASSERT(strict_ischar(ch));
88 return std::iscntrl(ch) != 0;
7c673cae
FG
89 }
90
91 static bool
92 isgraph(int ch)
93 {
92f5a8d4
TL
94 BOOST_ASSERT(strict_ischar(ch));
95 return std::isgraph(ch) != 0;
7c673cae
FG
96 }
97
98 static bool
99 islower(int ch)
100 {
92f5a8d4
TL
101 BOOST_ASSERT(strict_ischar(ch));
102 return std::islower(ch) != 0;
7c673cae
FG
103 }
104
105 static bool
106 isprint(int ch)
107 {
92f5a8d4
TL
108 BOOST_ASSERT(strict_ischar(ch));
109 return std::isprint(ch) != 0;
7c673cae
FG
110 }
111
112 static bool
113 ispunct(int ch)
114 {
92f5a8d4
TL
115 BOOST_ASSERT(strict_ischar(ch));
116 return std::ispunct(ch) != 0;
7c673cae
FG
117 }
118
119 static bool
120 isspace(int ch)
121 {
92f5a8d4
TL
122 BOOST_ASSERT(strict_ischar(ch));
123 return std::isspace(ch) != 0;
7c673cae
FG
124 }
125
126 static bool
127 isblank BOOST_PREVENT_MACRO_SUBSTITUTION (int ch)
128 {
92f5a8d4 129 BOOST_ASSERT(strict_ischar(ch));
7c673cae
FG
130 return (ch == ' ' || ch == '\t');
131 }
132
133 static bool
134 isupper(int ch)
135 {
92f5a8d4
TL
136 BOOST_ASSERT(strict_ischar(ch));
137 return std::isupper(ch) != 0;
7c673cae
FG
138 }
139
140 ///////////////////////////////////////////////////////////////////////////////
141 // Simple character conversions
142 ///////////////////////////////////////////////////////////////////////////////
143
144 static int
145 tolower(int ch)
146 {
92f5a8d4 147 BOOST_ASSERT(strict_ischar(ch));
7c673cae
FG
148 return std::tolower(ch);
149 }
150
151 static int
152 toupper(int ch)
153 {
92f5a8d4 154 BOOST_ASSERT(strict_ischar(ch));
7c673cae
FG
155 return std::toupper(ch);
156 }
157
158 static ::boost::uint32_t
159 toucs4(int ch)
160 {
92f5a8d4 161 BOOST_ASSERT(strict_ischar(ch));
7c673cae
FG
162 return ch;
163 }
164 };
165}}}
166
167#endif