00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 #ifndef _character_h
00018 #define _character_h
00019 
00020 #include <ctype.h>
00021 #include <wctype.h>
00022 #include <spl/types.h>
00023 #include <spl/Numeric.h>
00024 #include <spl/String.h>
00025 
00026 #ifdef HAVE_LIMITS_H
00027 #include <limits.h>
00028 #endif
00029 
00036 #define CHAR_MAJIC 0x0015               //< Majic number for ASSERT's in Compare and Convert
00037 
00041 class Char : public Numeric
00042 {
00043 private:
00044         int m_val;
00045 
00046 public:
00047         Char();
00048         Char(const Char& i);
00049         Char(const int i);
00050         virtual ~Char();
00051 
00052         virtual int32 HashCode() const;
00053 
00054         virtual bool Equals(const IComparable *a) const;
00055         virtual int Compare(const IComparable *a) const;
00056         virtual bool Equals(const IComparable& a) const;
00057         virtual int Compare(const IComparable& a) const;
00058         virtual int32 MajicNumber() const;
00059 
00060         virtual int ToInt() const;
00061         virtual double ToDouble() const;
00062         virtual StringPtr ToString() const;
00063 
00064         inline operator char() { return (char)m_val; }
00065 
00066 #ifdef DEBUG
00067         virtual void ValidateMem() const;
00068         virtual void CheckMem() const;
00069 #endif
00070 
00071         inline static bool IsAscii(const int32 c) { return c < 256; }
00072         inline static bool IsControl(const int32 c) { return 0 != iswcntrl(c); }
00073         inline static bool IsDigit(const int32 c) { return 0 != iswdigit(c); }
00074         inline static bool IsLetter(const int32 c) { return 0 != iswalpha(c); }
00075         inline static bool IsLetterOrDigit(const int32 c) { return 0 != iswalnum(c); }
00076         inline static bool IsLower(const int32 c) { return 0 != iswlower(c); }
00077         inline static bool IsNumber(const int32 c) { return 0 != iswdigit(c); }
00078         inline static bool IsPunctuation(const int32 c) { return 0 != iswpunct(c); }
00079         inline static bool IsUpper(const int32 c) { return 0 != iswupper(c); }
00080         static bool IsWhiteSpace(const int32 c);
00081         inline static int32 ToUpper(const int32 c) { return towupper(c); }
00082         inline static int32 ToLower(const int32 c) { return towlower(c); }
00083 
00084         static StringPtr ToString(int32 i);
00085         static StringPtr ToString(char c);
00086 
00087         inline static int MaxValue() { return 255; }
00088         inline static int MinValue() { return 0; }
00089 };
00090 
00091 REGISTER_TYPEOF( 556, Char );
00092 
00095 #endif