00001
00002
00003
00004
00005 #ifndef __FXS_STRING_H_
00006 #define __FXS_STRING_H_
00007
00008 #include <tchar.h>
00009 #include <stdio.h>
00010
00011 struct fsString
00012 {
00013 LPTSTR pszString;
00014
00015 fsString ()
00016 {
00017 pszString = NULL;
00018 }
00019
00020 ~fsString ()
00021 {
00022 if (pszString)
00023 delete [] pszString;
00024 }
00025
00026 fsString (const fsString& str)
00027 {
00028 pszString = NULL;
00029 *this = str.pszString;
00030 }
00031
00032 fsString (LPCTSTR str)
00033 {
00034 pszString = NULL;
00035 *this = str;
00036 }
00037
00038 LPCTSTR operator = (LPCTSTR pszStr)
00039 {
00040 if (pszString)
00041 {
00042 delete [] pszString;
00043 pszString = NULL;
00044 }
00045
00046 if (pszStr)
00047 {
00048 pszString = new TCHAR [_tcslen (pszStr) + 1];
00049 if (pszString)
00050 _tcscpy ( pszString, pszStr );
00051 }
00052
00053 return pszString;
00054 }
00055
00056 fsString& operator = (const fsString& str)
00057 {
00058 *this = str.pszString;
00059 return *this;
00060 }
00061
00062 LPCTSTR operator += (LPCTSTR pszStr)
00063 {
00064 if (pszStr == NULL)
00065 return pszString;
00066
00067 if ( pszString )
00068 {
00069 LPTSTR pszOld = pszString;
00070
00071 pszString = new TCHAR [ _tcslen (pszString) + _tcslen (pszStr) + 1 ];
00072 _tcscpy ( pszString, pszOld );
00073 _tcscat ( pszString, pszStr );
00074
00075 delete [] pszOld;
00076 }
00077 else
00078 {
00079 *this = pszStr;
00080 }
00081
00082 return pszString;
00083 }
00084
00085 LPCTSTR operator += (char c)
00086 {
00087 char sz [2];
00088 sz [0] = c; sz [1] = 0;
00089 return *this += sz;
00090 }
00091
00092 fsString operator + (LPCTSTR psz) const
00093 {
00094 fsString str = *this;
00095 str += psz;
00096 return str;
00097 }
00098
00099 BOOL operator == (const fsString& str) const
00100 {
00101 return str == pszString;
00102 }
00103
00104 BOOL operator != (const fsString& str) const
00105 {
00106 return str != pszString;
00107 }
00108
00109 BOOL operator == (LPCTSTR pszStr) const
00110 {
00111 if (pszString == NULL || pszStr == NULL)
00112 return pszStr == pszString;
00113
00114 return _tcscmp ( pszString, pszStr ) == 0;
00115 }
00116
00117 void clear ()
00118 {
00119 if (pszString)
00120 {
00121 delete [] pszString;
00122 pszString = NULL;
00123 }
00124 }
00125
00126 void ncpy (LPCSTR pszStr, int nch)
00127 {
00128 alloc (nch);
00129 strncpy (pszString, pszStr, nch);
00130 }
00131
00132 void alloc (int nch)
00133 {
00134 clear ();
00135 pszString = new char [nch+1];
00136 pszString [nch] = 0;
00137 }
00138
00139 BOOL operator != (LPCSTR pszStr) const
00140 {
00141 return !(*this == pszStr);
00142 }
00143
00144 operator LPTSTR () const
00145 {
00146 return pszString;
00147 }
00148
00149 int Length ()
00150 {
00151 if (pszString)
00152 return _tcslen (pszString);
00153 else
00154 return 0;
00155 }
00156
00157 BOOL IsEmpty ()
00158 {
00159 return pszString == NULL || *pszString == 0;
00160 }
00161
00162 int GetLength () {return Length ();}
00163
00164 void Replace (LPCSTR , LPCSTR ) {}
00165
00166 void Format (LPCSTR pszFormat ...)
00167 {
00168 LPSTR psz = new char [100000];
00169 va_list ap;
00170 va_start (ap, pszFormat);
00171 vsprintf (psz, pszFormat, ap);
00172 va_end (ap);
00173 *this = psz;
00174 delete [] psz;
00175 }
00176 };
00177
00178 #endif