#include <tstring.h>
Public Member Functions | |
TString (const char *=NULL) | |
TString (const TString &) | |
~TString (void) | |
operator const char * (void) const | |
int | Length (void) const |
int | IndexOf (const char) const |
int | IndexOf (const char *) const |
int | LastIndexOf (const char) const |
int | LastIndexOf (const char *) const |
const TString | Substring (int) const |
const TString | Substring (int, int) const |
bool | BeginsWith (const char *) const |
void | Format (const char *,...) |
const TString & | operator= (const char *) |
const TString & | operator= (const TString &) |
const TString & | operator+= (const char *) |
const TString & | operator+= (const TString &) |
Private Attributes | |
char * | actual_string |
Friends | |
const TString | operator+ (const TString &, const TString &) |
bool | operator== (const TString &, const TString &) |
bool | operator!= (const TString &, const TString &) |
Definition at line 26 of file tstring.h.
TString::TString | ( | const char * | cstr = NULL |
) |
Definition at line 24 of file tstring.cpp.
00025 { 00026 // Initialization 00027 actual_string = NULL; 00028 00029 // Assignment 00030 *this = cstr; 00031 }
TString::TString | ( | const TString & | tstr | ) |
Definition at line 33 of file tstring.cpp.
00034 { 00035 // Initialization 00036 actual_string = NULL; 00037 00038 // Assignment 00039 *this = (const char *)tstr; 00040 }
TString::~TString | ( | void | ) |
Definition at line 42 of file tstring.cpp.
00043 { 00044 if( actual_string ) 00045 delete[] actual_string; 00046 }
bool TString::BeginsWith | ( | const char * | prefix | ) | const |
Definition at line 132 of file tstring.cpp.
00133 { 00134 if( prefix == NULL ) 00135 return false; 00136 return (strncmp( actual_string, prefix, strlen(prefix) ) == 0); 00137 }
void TString::Format | ( | const char * | format, | |
... | ||||
) |
Definition at line 139 of file tstring.cpp.
int TString::IndexOf | ( | const char * | cstr | ) | const |
Definition at line 69 of file tstring.cpp.
00070 { 00071 register int i, 00072 j; 00073 00074 if( cstr ) 00075 { 00076 const register int N = Length( ), 00077 M = strlen( cstr ); 00078 00079 for( i = 0, j = 0; i < N && j < M; i++, j++ ) 00080 { 00081 while( actual_string[ i ] != cstr[ j ] ) 00082 { 00083 i -= j-1; 00084 j = 0; 00085 } 00086 } 00087 if( j == M ) 00088 return i-M; 00089 } 00090 00091 return -1; 00092 }
int TString::IndexOf | ( | const char | ch | ) | const |
Definition at line 55 of file tstring.cpp.
00056 { 00057 register int i; 00058 const register int N = Length( ); 00059 00060 for( i = 0; i < N; i++ ) 00061 { 00062 if( actual_string[ i ] == ch ) 00063 return i; 00064 } 00065 00066 return -1; 00067 }
int TString::LastIndexOf | ( | const char * | ) | const |
int TString::LastIndexOf | ( | const char | ch | ) | const |
Definition at line 94 of file tstring.cpp.
00095 { 00096 register int i; 00097 00098 for( i = Length( )-1; i >= 0; i-- ) 00099 { 00100 if( actual_string[ i ] == ch ) 00101 return i; 00102 } 00103 return -1; 00104 }
int TString::Length | ( | void | ) | const |
Definition at line 48 of file tstring.cpp.
00049 { 00050 if( actual_string ) 00051 return strlen( actual_string ); 00052 return 0; 00053 }
TString::operator const char * | ( | void | ) | const [inline] |
Definition at line 38 of file tstring.h.
00038 { return actual_string; };
Definition at line 195 of file tstring.cpp.
const TString & TString::operator+= | ( | const char * | cstr | ) |
Definition at line 174 of file tstring.cpp.
00175 { 00176 char * temp_string; 00177 00178 if( cstr ) 00179 { 00180 temp_string = new char[ Length( ) + strlen( cstr ) + 1 ]; 00181 00182 if( actual_string ) 00183 { 00184 strcpy( temp_string, actual_string ); 00185 delete[] actual_string; 00186 } 00187 00188 strcat( temp_string, cstr ); 00189 actual_string = temp_string; 00190 } 00191 00192 return *this; 00193 }
Definition at line 169 of file tstring.cpp.
const TString & TString::operator= | ( | const char * | cstr | ) |
Definition at line 152 of file tstring.cpp.
00153 { 00154 if( actual_string ) 00155 { 00156 delete actual_string; 00157 actual_string = NULL; 00158 } 00159 00160 if( cstr ) 00161 { 00162 actual_string = new char[ strlen( cstr ) + 1 ]; 00163 strcpy( actual_string, cstr ); 00164 } 00165 00166 return *this; 00167 }
const TString TString::Substring | ( | int | begin, | |
int | end | |||
) | const |
Definition at line 116 of file tstring.cpp.
00117 { 00118 TString tstr; 00119 char * temp_string; 00120 00121 if( begin < Length( ) && end > begin && end < Length( ) ) 00122 { 00123 temp_string = new char[ end - begin + 2 ]; 00124 strncpy( temp_string, actual_string + begin, end-begin+1 ); 00125 tstr = temp_string; 00126 delete[] temp_string; 00127 } 00128 00129 return tstr; 00130 }
const TString TString::Substring | ( | int | begin | ) | const |
Definition at line 106 of file tstring.cpp.
00107 { 00108 TString tstr; 00109 00110 if( begin < Length( ) ) 00111 tstr = actual_string + begin; 00112 00113 return tstr; 00114 }
Definition at line 216 of file tstring.cpp.
Definition at line 200 of file tstring.cpp.
00201 { 00202 TString temp_tstr( tstr1 ); 00203 00204 temp_tstr += tstr2; 00205 00206 return temp_tstr; 00207 }
Definition at line 209 of file tstring.cpp.
char* TString::actual_string [private] |