home *** CD-ROM | disk | FTP | other *** search
/ Game.EXE 2002 April / Game.EXE_04_2002.iso / Alawar / String.h < prev    next >
Encoding:
C/C++ Source or Header  |  2002-02-25  |  2.2 KB  |  119 lines

  1. #ifndef STRING_H
  2. #define STRING_H
  3.  
  4. #include <string>
  5.  
  6. class String
  7. {
  8.     std::string data;
  9. public:
  10.     String()
  11.     {}
  12.     explicit String(char c)
  13.         :    data( 1, c )
  14.     {}
  15.     String(const char * str)
  16.         :    data( str )
  17.     {}
  18.     String(const String & str)
  19.         :    data( str )
  20.     {}
  21.     const String & operator=(const char * str)
  22.     {
  23.         data = str;
  24.         return *this;
  25.     }
  26.     const String & operator=(const String & str)
  27.     {
  28.         data = str.data;
  29.         return *this;
  30.     }
  31.     operator const char *()const
  32.     {
  33.         return data.c_str();
  34.     }
  35.  
  36.     unsigned size()const
  37.     {
  38.         return data.size();
  39.     }
  40.     char operator[]( unsigned pos )const
  41.     {
  42.         if( pos >= data.size() ) // Åα«óÑα¬á «Γ¡¿¼áÑΓ óαѼ∩, ¡« ñѽáÑΓ ¬½áßß ¡áñѪ¡δ¼
  43.             return 0;
  44.         return data[ pos ];
  45.     }
  46.     bool empty()const
  47.     {
  48.         return data.size() == 0;
  49.     }
  50.     const String & operator+=(char c)
  51.     {
  52.         data += c;
  53.         return *this;
  54.     }
  55.     const String & operator+=(const char * str)
  56.     {
  57.         data += str;
  58.         return *this;
  59.     }
  60.     const String & operator+=(const String & str)
  61.     {
  62.         data += str;
  63.         return *this;
  64.     }
  65.     int compare(const char * str)const
  66.     {
  67.         return data.compare( str );
  68.     }
  69.     int compare(const String & str)const
  70.     {
  71.         return data.compare( str );
  72.     }
  73.  
  74.     static String convert( int number );
  75.     static String convert( unsigned number );
  76.     static String convert( float number );
  77.     static String convert( double number );
  78. };
  79.  
  80. inline bool operator==(const String & a, const String & b)
  81. {
  82.     return a.compare( b ) == 0;
  83. }
  84. inline bool operator==(const char * a, const String & b)
  85. {
  86.     return b.compare( a ) == 0;
  87. }
  88. inline bool operator==(const String & a, const char * b)
  89. {
  90.     return a.compare( b ) == 0;
  91. }
  92.  
  93. inline bool operator!=(const String & a, const String & b)
  94. {
  95.     return !operator==( a, b );
  96. }
  97. inline bool operator!=(const char * a, const String & b)
  98. {
  99.     return !operator==( a, b );
  100. }
  101. inline bool operator!=(const String & a, const char * b)
  102. {
  103.     return !operator==( a, b );
  104. }
  105.  
  106. inline String operator+(const String & a, const String & b)
  107. {
  108.     return String(a) += b;
  109. }
  110. inline String operator+(const String & a, const char * b)
  111. {
  112.     return String(a) += b;
  113. }
  114. inline String operator+(const String & a, char b)
  115. {
  116.     return String(a) += b;
  117. }
  118.  
  119. #endif //STRING_H