00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef _DECAF_LANG_CHARACTER_H_
00019 #define _DECAF_LANG_CHARACTER_H_
00020
00021 #include <decaf/util/Config.h>
00022 #include <decaf/lang/Number.h>
00023 #include <decaf/lang/Comparable.h>
00024 #include <string>
00025
00026 namespace decaf{
00027 namespace lang{
00028
00029 class DECAF_API Character : public Number,
00030 public Comparable<Character>,
00031 public Comparable<char> {
00032 private:
00033
00034
00035 char value;
00036
00037 public:
00038
00040 static const int MIN_RADIX = 2;
00041
00043 static const int MAX_RADIX = 36;
00044
00046 static const char MIN_VALUE = (char)0x7F;
00047
00049 static const char MAX_VALUE = (char)0x80;
00050
00052 static const int SIZE = 8;
00053
00054 public:
00055
00059 Character( char value );
00060
00069 virtual int compareTo( const Character& c ) const {
00070 return this->value < c.value ? -1 : (this->value > c.value) ? 1 : 0;
00071 }
00072
00078 virtual bool operator==( const Character& c ) const {
00079 return this->value == c.value;
00080 }
00081
00088 virtual bool operator<( const Character& c ) const {
00089 return this->value < c.value;
00090 }
00091
00100 virtual int compareTo( const char& c ) const {
00101 return this->value < c ? -1 : (this->value > c) ? 1 : 0;
00102 }
00103
00109 virtual bool operator==( const char& c ) const {
00110 return this->value == c;
00111 }
00112
00119 virtual bool operator<( const char& c ) const {
00120 return this->value < c;
00121 }
00122
00126 bool equals( const Character& c ) const {
00127 return this->value == c.value;
00128 }
00129
00133 bool equals( const char& c ) const {
00134 return this->value == c;
00135 }
00136
00140 std::string toString() const;
00141
00146 virtual double doubleValue() const {
00147 return (double)this->value;
00148 }
00149
00154 virtual float floatValue() const {
00155 return (float)this->value;
00156 }
00157
00162 virtual unsigned char byteValue() const {
00163 return (unsigned char)this->value;
00164 }
00165
00170 virtual short shortValue() const {
00171 return (short)this->value;
00172 }
00173
00178 virtual int intValue() const {
00179 return (int)this->value;
00180 }
00181
00186 virtual long long longValue() const {
00187 return (long long)this->value;
00188 }
00189
00190 public:
00191
00197 static Character valueOf( char value ) {
00198 return Character( value );
00199 }
00200
00205 static bool isWhitespace( char c ){
00206 switch ( c )
00207 {
00208 case '\n':
00209 case '\t':
00210 case '\r':
00211 case '\f':
00212 case ' ':
00213 return true;
00214 }
00215
00216 return false;
00217 }
00218
00223 static bool isDigit( char c ){
00224 return c >= '0' && c <= '9';
00225 }
00226
00231 static bool isLowerCase( char c ){
00232 return c >= 'a' && c <= 'z';
00233 }
00234
00239 static bool isUpperCase( char c ){
00240 return c >= 'A' && c <= 'Z';
00241 }
00242
00247 static bool isLetter( char c ){
00248 return isUpperCase(c) || isLowerCase(c);
00249 }
00250
00255 static bool isLetterOrDigit( char c ){
00256 return isLetter(c) || isDigit(c);
00257 }
00258
00265 static bool isISOControl( char c ) {
00266 return ( c >= 0 && c <= 0x1f ) ||
00267 ( (unsigned char)c >= 0x7f && (unsigned char)c <= 0x9f );
00268 }
00269
00292 static int digit(char c, int radix);
00293
00304 static char toLowerCase(char value) {
00305 if ('A' <= value && value <= 'Z') {
00306 return (char) (value + ('a' - 'A'));
00307 }
00308
00309 return value;
00310 }
00311
00322 static char toUpperCase(char value) {
00323 if ('a' <= value && value <= 'z') {
00324 return (char) (value - ('a' - 'A'));
00325 }
00326
00327 return value;
00328 }
00329
00330 };
00331
00332 }}
00333
00334 #endif