activemq-cpp-3.8.2
Character.h
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #ifndef _DECAF_LANG_CHARACTER_H_
19 #define _DECAF_LANG_CHARACTER_H_
20 
21 #include <decaf/util/Config.h>
22 #include <decaf/lang/Number.h>
23 #include <decaf/lang/Comparable.h>
24 #include <string>
25 
26 namespace decaf{
27 namespace lang{
28 
29  class DECAF_API Character : public Number,
30  public Comparable<Character>,
31  public Comparable<char> {
32  private:
33 
34  // The primitive Char value
35  char value;
36 
37  public:
38 
40  static const int MIN_RADIX = 2;
41 
43  static const int MAX_RADIX = 36;
44 
46  static const char MIN_VALUE = (char)0x7F;
47 
49  static const char MAX_VALUE = (char)0x80;
50 
52  static const int SIZE = 8;
53 
54  public:
55 
59  Character( char value );
60 
69  virtual int compareTo( const Character& c ) const {
70  return this->value < c.value ? -1 : (this->value > c.value) ? 1 : 0;
71  }
72 
78  virtual bool operator==( const Character& c ) const {
79  return this->value == c.value;
80  }
81 
88  virtual bool operator<( const Character& c ) const {
89  return this->value < c.value;
90  }
91 
100  virtual int compareTo( const char& c ) const {
101  return this->value < c ? -1 : (this->value > c) ? 1 : 0;
102  }
103 
109  virtual bool operator==( const char& c ) const {
110  return this->value == c;
111  }
112 
119  virtual bool operator<( const char& c ) const {
120  return this->value < c;
121  }
122 
126  bool equals( const Character& c ) const {
127  return this->value == c.value;
128  }
129 
133  bool equals( const char& c ) const {
134  return this->value == c;
135  }
136 
140  std::string toString() const;
141 
146  virtual double doubleValue() const {
147  return (double)this->value;
148  }
149 
154  virtual float floatValue() const {
155  return (float)this->value;
156  }
157 
162  virtual unsigned char byteValue() const {
163  return (unsigned char)this->value;
164  }
165 
170  virtual short shortValue() const {
171  return (short)this->value;
172  }
173 
178  virtual int intValue() const {
179  return (int)this->value;
180  }
181 
186  virtual long long longValue() const {
187  return (long long)this->value;
188  }
189 
190  public: // statics
191 
197  static Character valueOf( char value ) {
198  return Character( value );
199  }
200 
205  static bool isWhitespace( char c ){
206  switch ( c )
207  {
208  case '\n':
209  case '\t':
210  case '\r':
211  case '\f':
212  case ' ':
213  return true;
214  }
215 
216  return false;
217  }
218 
223  static bool isDigit( char c ){
224  return c >= '0' && c <= '9';
225  }
226 
231  static bool isLowerCase( char c ){
232  return c >= 'a' && c <= 'z';
233  }
234 
239  static bool isUpperCase( char c ){
240  return c >= 'A' && c <= 'Z';
241  }
242 
247  static bool isLetter( char c ){
248  return isUpperCase(c) || isLowerCase(c);
249  }
250 
255  static bool isLetterOrDigit( char c ){
256  return isLetter(c) || isDigit(c);
257  }
258 
265  static bool isISOControl( char c ) {
266  return ( c >= 0 && c <= 0x1f ) ||
267  ( (unsigned char)c >= 0x7f && (unsigned char)c <= 0x9f );
268  }
269 
292  static int digit(char c, int radix);
293 
304  static char toLowerCase(char value) {
305  if ('A' <= value && value <= 'Z') {
306  return (char) (value + ('a' - 'A'));
307  }
308 
309  return value;
310  }
311 
322  static char toUpperCase(char value) {
323  if ('a' <= value && value <= 'z') {
324  return (char) (value - ('a' - 'A'));
325  }
326 
327  return value;
328  }
329 
330  };
331 
332 }}
333 
334 #endif /*_DECAF_LANG_CHARACTER_H_*/
static bool isDigit(char c)
Indicates whether or not the given character is a digit.
Definition: Character.h:223
virtual short shortValue() const
Answers the short value which the receiver represents.
Definition: Character.h:170
static bool isLetter(char c)
Indicates whether or not the given character is a letter.
Definition: Character.h:247
static bool isISOControl(char c)
Answers whether the character is an ISO control character, which is a char that lays in the range of ...
Definition: Character.h:265
virtual int compareTo(const Character &c) const
Compares this Character instance with another.
Definition: Character.h:69
static char toLowerCase(char value)
Returns the lower case equivalent for the specified character if the character is an upper case lette...
Definition: Character.h:304
static char toUpperCase(char value)
Returns the upper case equivalent for the specified character if the character is a lower case letter...
Definition: Character.h:322
bool equals(const char &c) const
Definition: Character.h:133
bool equals(const Character &c) const
Definition: Character.h:126
virtual int compareTo(const char &c) const
Compares this Character instance with a char type.
Definition: Character.h:100
static bool isLowerCase(char c)
Indicates whether or not the given character is a lower case character.
Definition: Character.h:231
virtual int intValue() const
Answers the int value which the receiver represents.
Definition: Character.h:178
virtual bool operator==(const Character &c) const
Compares equality between this object and the one passed.
Definition: Character.h:78
virtual bool operator<(const Character &c) const
Compares this object to another and returns true if this object is considered to be less than the one...
Definition: Character.h:88
virtual bool operator==(const char &c) const
Compares equality between this object and the one passed.
Definition: Character.h:109
virtual double doubleValue() const
Answers the double value which the receiver represents.
Definition: Character.h:146
The abstract class Number is the superclass of classes Byte, Double, Float, Integer, Long, and Short.
Definition: Number.h:35
static bool isUpperCase(char c)
Indicates whether or not the given character is a upper case character.
Definition: Character.h:239
static Character valueOf(char value)
Returns a Character instance representing the specified char value.
Definition: Character.h:197
static bool isWhitespace(char c)
Indicates whether or not the given character is considered whitespace.
Definition: Character.h:205
#define DECAF_API
Definition: Config.h:29
virtual float floatValue() const
Answers the float value which the receiver represents.
Definition: Character.h:154
Definition: Character.h:29
virtual long long longValue() const
Answers the long value which the receiver represents.
Definition: Character.h:186
virtual bool operator<(const char &c) const
Compares this object to another and returns true if this object is considered to be less than the one...
Definition: Character.h:119
static bool isLetterOrDigit(char c)
Indicates whether or not the given character is either a letter or a digit.
Definition: Character.h:255
This interface imposes a total ordering on the objects of each class that implements it...
Definition: Comparable.h:33
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements...
Definition: AprPool.h:25
virtual unsigned char byteValue() const
Answers the byte value which the receiver represents.
Definition: Character.h:162