libcommonc++  0.7
Char.h++
Go to the documentation of this file.
1 /* ---------------------------------------------------------------------------
2  commonc++ - A C++ Common Class Library
3  Copyright (C) 2005-2014 Mark A Lindner
4 
5  This file is part of commonc++.
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Library General Public
9  License as published by the Free Software Foundation; either
10  version 2 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Library General Public License for more details.
16 
17  You should have received a copy of the GNU Library General Public
18  License along with this library; if not, write to the Free
19  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  ---------------------------------------------------------------------------
21 */
22 
23 #ifndef __ccxx_Char_hxx
24 #define __ccxx_Char_hxx
25 
26 #include <commonc++/Common.h++>
27 
28 namespace ccxx {
29 
34 {
35  public:
36 
38  Char();
39 
41  explicit Char(char c);
42 
44  explicit Char(char16_t c);
45 
49  Char(int c);
50 
52  ~Char();
53 
55  Char& operator=(char c);
56 
58  Char& operator=(char16_t c);
59 
61  Char& operator=(int c);
62 
64  bool isNul() const;
65 
67  bool isControl() const;
68 
70  bool isPrintable() const;
71 
73  bool isGraphical() const;
74 
76  bool isPunctuation() const;
77 
79  bool isLetter() const;
80 
82  bool isDigit() const;
83 
85  bool isHexDigit() const;
86 
88  bool isAlphabetic() const;
89 
91  bool isAlphaNumeric() const;
92 
94  bool isSign() const;
95 
97  bool isWhitespace() const;
98 
100  bool isLowerCase() const;
101 
103  bool isUpperCase() const;
104 
106  Char toLowerCase() const;
107 
109  Char toUpperCase() const;
110 
112  bool isASCII() const;
113 
115  bool isLowASCII() const;
116 
118  bool isHighASCII() const;
119 
121  bool isLowSurrogate() const;
122 
124  bool isHighSurrogate() const;
125 
128  { return(_char); }
129 
134  char toASCII() const;
135 
137  bool operator==(const Char& other) const
138  { return(_char == other._char); }
139 
141  bool operator==(char16_t other) const
142  { return(_char == other); }
143 
145  bool operator!=(const Char& other) const
146  { return(_char != other._char); }
147 
148  bool operator<(const Char& other) const
149  { return(_char < other._char); }
150 
151  bool operator>(const Char& other) const
152  { return(_char > other._char); }
153 
154  bool operator<=(const Char& other) const
155  { return(_char <= other._char); }
156 
157  bool operator>=(const Char& other) const
158  { return(_char >= other._char); }
159 
161  inline bool operator!() const
162  { return(isNul()); }
163 
165  inline Char& operator++()
166  {
167  ++_char;
168  return(*this);
169  }
170 
172  inline Char operator++(int)
173  { return(Char(_char++)); }
174 
176  inline Char& operator--()
177  {
178  --_char;
179  return(*this);
180  }
181 
183  inline Char operator--(int)
184  { return(Char(_char--)); }
185 
187  static const Char nul;
188 
190  static const Char BELL;
191 
193  static const Char BACKSPACE;
194 
196  static const Char TAB;
197 
199  static const Char NEWLINE;
200 
202  static const Char VERTICAL_TAB;
203 
205  static const Char FORM_FEED;
206 
208  static const Char RETURN;
209 
211  static const Char ESCAPE;
212 
214  static const Char SPACE;
215 
217  static const Char DELETE;
218 
220  static bool isNul(char16_t c);
221 
223  static bool isControl(char16_t c);
224 
226  static bool isPrintable(char16_t c);
227 
229  static bool isGraphical(char16_t c);
230 
232  static bool isPunctuation(char16_t c);
233 
235  static bool isLetter(char16_t c);
236 
238  static bool isDigit(char16_t c);
239 
241  static bool isHexDigit(char16_t c);
242 
244  static bool isAlphabetic(char16_t c);
245 
247  static bool isAlphaNumeric(char16_t c);
248 
250  static bool isSign(char16_t c);
251 
253  static bool isWhitespace(char16_t c);
254 
256  static bool isLowerCase(char16_t c);
257 
259  static bool isUpperCase(char16_t c);
260 
262  static char16_t toLowerCase(char16_t c);
263 
265  static char16_t toUpperCase(char16_t c);
266 
268  static bool isASCII(char16_t c);
269 
271  static bool isLowASCII(char16_t c);
272 
274  static bool isHighASCII(char16_t c);
275 
277  static bool isLowSurrogate(char16_t c);
278 
280  static bool isHighSurrogate(char16_t c);
281 
286  static char toASCII(char16_t c);
287 
288  private:
289 
290  char16_t _char;
291 };
292 
293 inline bool operator==(char c1, const Char& c2)
294 { return(static_cast<char16_t>(c1) == c2.toChar16()); }
295 
296 inline bool operator!=(char c1, const Char& c2)
297 { return(static_cast<char16_t>(c1) != c2.toChar16()); }
298 
299 inline bool operator<(char c1, const Char& c2)
300 { return(static_cast<char16_t>(c1) < c2.toChar16()); }
301 
302 inline bool operator<=(char c1, const Char& c2)
303 { return(static_cast<char16_t>(c1) <= c2.toChar16()); }
304 
305 inline bool operator>(char c1, const Char& c2)
306 { return(static_cast<char16_t>(c1) > c2.toChar16()); }
307 
308 inline bool operator>=(char c1, const Char& c2)
309 { return(static_cast<char16_t>(c1) >= c2.toChar16()); }
310 
311 inline bool operator==(char16_t c1, const Char& c2)
312 { return(c1 == c2.toChar16()); }
313 
314 inline bool operator!=(char16_t c1, const Char& c2)
315 { return(c1 != c2.toChar16()); }
316 
317 inline bool operator<(char16_t c1, const Char& c2)
318 { return(c1 < c2.toChar16()); }
319 
320 inline bool operator<=(char16_t c1, const Char& c2)
321 { return(c1 <= c2.toChar16()); }
322 
323 inline bool operator>(char16_t c1, const Char& c2)
324 { return(c1 > c2.toChar16()); }
325 
326 inline bool operator>=(char16_t c1, const Char& c2)
327 { return(c1 >= c2.toChar16()); }
328 
329 } // namespace ccxx
330 
331 #endif // __ccxx_Char_hxx
static const Char SPACE
The space character.
Definition: Char.h++:214
bool operator==(char16_t other) const
Equality operator.
Definition: Char.h++:141
static const Char BELL
The bell character.
Definition: Char.h++:190
Char operator++(int)
Increment operator (postfix).
Definition: Char.h++:172
bool operator<=(const Blob &b1, const Blob &b2)
Definition: Blob.h++:356
bool operator==(const Blob &b1, const Blob &b2)
Definition: Blob.h++:344
static const Char RETURN
The carriage return character.
Definition: Char.h++:208
Char & operator--()
Decrement operator (prefix).
Definition: Char.h++:176
static const Char nul
The NUL character.
Definition: Char.h++:187
Char operator--(int)
Decrement operator (postfix).
Definition: Char.h++:183
bool operator!() const
Equivalent to isNul().
Definition: Char.h++:161
static const Char BACKSPACE
The backspace character.
Definition: Char.h++:193
static const Char TAB
The tab character.
Definition: Char.h++:196
char16_t toChar16() const
Returns the char16_t for this character.
Definition: Char.h++:127
static const Char ESCAPE
The escape character.
Definition: Char.h++:211
bool operator<(const Char &other) const
Definition: Char.h++:148
static const Char NEWLINE
The newline character.
Definition: Char.h++:199
#define COMMONCPP_API
Definition: Common.h++:126
bool operator>=(const Char &other) const
Definition: Char.h++:157
bool operator!=(const Blob &b1, const Blob &b2)
Definition: Blob.h++:347
A class representing a UTF-16 character.
Definition: Char.h++:33
static const Char VERTICAL_TAB
The vertical tab character.
Definition: Char.h++:202
static const Char DELETE
The delete character.
Definition: Char.h++:217
bool operator<(const Blob &b1, const Blob &b2)
Definition: Blob.h++:350
static const Char FORM_FEED
The form feed character.
Definition: Char.h++:205
bool operator<=(const Char &other) const
Definition: Char.h++:154
uint16_t char16_t
A UTF-16 character.
Definition: Common.h++:201
bool operator!=(const Char &other) const
Inequality operator.
Definition: Char.h++:145
bool operator==(const Char &other) const
Equality operator.
Definition: Char.h++:137
Char & operator++()
Increment operator (prefix).
Definition: Char.h++:165
bool operator>=(const Blob &b1, const Blob &b2)
Definition: Blob.h++:359
bool operator>(const Char &other) const
Definition: Char.h++:151
Definition: AllocationMap.c++:25
bool operator>(const Blob &b1, const Blob &b2)
Definition: Blob.h++:353