00001
00002
00003 #ifndef ascstringH
00004 #define ascstringH
00005
00006 #include "ASCStringHelpers.h"
00007 #include <stdexcept>
00008 #include <stdarg.h>
00009
00010 using std::range_error;
00011
00012
00013 class ASCString : public ASCCharTString
00014 {
00015
00016 public:
00017
00021 typedef ASCStringHelpers::charT charT;
00022
00023 #ifndef _UNICODE_BROKEN_
00024
00029 typedef ASCStringHelpers::NoncharT NoncharT;
00030
00031 #endif // _UNICODE_BROKEN_
00032
00033
00034 ASCString ( );
00035 ASCString ( const charT* pS );
00036 ASCString ( const charT* pS, size_type n );
00037 ASCString ( size_type n, charT c );
00038 ASCString ( const_iterator first, const_iterator last );
00039
00040
00041 ASCString ( const ASCCharTString& s );
00042 ASCString ( const ASCCharTString& s, size_type pos, size_type n );
00043
00044 #ifndef _UNICODE_BROKEN_
00045
00046
00047 explicit ASCString ( const ASCAdaptatorString& s );
00048 explicit ASCString ( const ASCAdaptatorString& s, size_type pos, size_type n );
00049
00050
00051 ASCString& operator=( const ASCAdaptatorString& s );
00052
00053 #endif // _UNICODE_BROKEN_
00054
00055
00056 ASCString& operator= ( const ASCCharTString& s );
00057
00058
00059 ASCString& operator= ( const charT* pS );
00060
00061
00062 int compare_ci ( const ASCCharTString& s ) const;
00063 int compare_ci ( size_type p0, size_type n0, const ASCCharTString& s );
00064 int compare_ci ( size_type p0, size_type n0, const ASCCharTString& s, size_type pos, size_type n );
00065 int compare_ci ( const charT* pS ) const;
00066 int compare_ci ( size_type p0, size_type n0, const charT* pS, size_type pos ) const;
00067
00069 static ASCString toString( int i );
00070
00071 #ifdef SIZE_T_not_identical_to_INT
00072 static ASCString toString( size_t i );
00073 #endif
00074
00076
00078 static ASCString toString( double d );
00079
00081 ASCString& replaceAll( const ASCString& old, const ASCString& newString);
00082
00084 ASCString& replaceAll_ci( const ASCString& old, const ASCString& newString);
00085
00086
00087 ASCString& toLower ();
00088 ASCString& toUpper ();
00089
00090
00091 ASCString& format ( const charT* pFormat, ... );
00092 ASCString& vaformat ( const charT* pFormat, va_list ap );
00093 void printf ();
00094
00095
00096 bool endswith( const ASCString& s ) const;
00097 };
00098
00099
00103 inline ASCString::ASCString ( )
00104 : ASCCharTString ( )
00105 {
00106 }
00107
00113 inline ASCString::ASCString ( const charT* pS )
00114 : ASCCharTString ( pS )
00115 {
00116 }
00117
00125 inline ASCString::ASCString ( const charT* pS, size_type n )
00126 : ASCCharTString ( pS, n )
00127 {
00128 }
00129
00137 inline ASCString::ASCString ( size_type n, charT c )
00138 : ASCCharTString ( n, c )
00139 {
00140 }
00141
00151 inline ASCString::ASCString ( const_iterator first, const_iterator last )
00152 : ASCCharTString ( first, last )
00153 {
00154 }
00155
00156
00162 inline ASCString::ASCString ( const ASCCharTString& s )
00163 : ASCCharTString ( s )
00164 {
00165 }
00166
00176 inline ASCString::ASCString ( const ASCCharTString& s, size_type pos, size_type n )
00177 : ASCCharTString ( s, pos, n )
00178 {
00179 }
00180
00181
00182 #ifndef _UNICODE_BROKEN_
00183
00184
00185
00195 inline ASCString::ASCString ( const ASCAdaptatorString& s )
00196 : ASCCharTString ()
00197 {
00198
00199 auto_ptr< charT > pE ( new charT [ s.length () + sizeof ( charT ) ] );
00200
00201 size_t stNumCharConverted = ASCStringHelpers::_ConvertToCharT ( pE.get (), s.c_str(), s.length() );
00202 if ( stNumCharConverted != s.length() )
00203 {
00204 throw range_error ( "ASCString::ASCString( const ASCAdaptatorString& s ) ==> unable to convert all characters from ASCAdaptatorString to ASCCharTString type." );
00205 }
00206
00207 assign ( pE.get(), stNumCharConverted );
00208 }
00209
00223 inline ASCString::ASCString ( const ASCAdaptatorString& s, size_type pos, size_type n )
00224 : ASCCharTString ()
00225 {
00226 size_t stLen = n - pos;
00227
00228
00229 auto_ptr< charT > pE ( new charT [ stLen + sizeof ( charT ) ] );
00230
00231 const NoncharT* pCE = s.c_str ();
00232 size_t stNumCharConverted = ASCStringHelpers::_ConvertToCharT ( pE.get (), &pCE[ pos ], stLen );
00233 if ( stNumCharConverted != stLen )
00234 {
00235 throw range_error ( "ASCString::ASCString( const ASCAdaptatorString& s, size_type pos, size_type n ) ==> unable to convert all characters from ASCAdaptatorString to ASCCharTString type." );
00236 }
00237
00238 assign ( pE.get(), stLen );
00239 }
00240
00241
00242
00254 inline ASCString& ASCString::operator= ( const ASCAdaptatorString& s )
00255 {
00256 ASCString str ( s );
00257 assign ( str );
00258 return *this;
00259 }
00260
00261 #endif // _UNICODE_BROKEN_
00262
00263
00264
00265
00273 inline ASCString& ASCString::operator= ( const ASCCharTString& s )
00274 {
00275 assign ( s );
00276 return *this;
00277 }
00278
00279
00280 inline ASCString& ASCString::operator= ( const charT* pS )
00281 {
00282 ASCString str ( pS );
00283 assign ( str );
00284 return *this;
00285 }
00286
00287
00288
00294 inline int ASCString::compare_ci ( const ASCCharTString& s ) const
00295 {
00296 return ASCStringHelpers::_Stricmp ( c_str (), s.c_str () );
00297 }
00298
00304 inline int ASCString::compare_ci ( size_type p0, size_type n0, const ASCCharTString& s )
00305 {
00306 ASCString l_TempString ( *this, p0, n0 );
00307 return ASCStringHelpers::_Stricmp ( l_TempString.c_str () , s.c_str () );
00308 }
00309
00315 inline int ASCString::compare_ci ( size_type p0, size_type n0,const ASCCharTString& s, size_type pos, size_type n )
00316 {
00317 ASCString l_TempStr1 ( *this, p0, n0 );
00318 ASCString l_TempStr2 ( s, pos, n );
00319 return ASCStringHelpers::_Stricmp ( l_TempStr1.c_str (), l_TempStr2.c_str () );
00320 }
00321
00325 inline int ASCString::compare_ci ( const charT* pS ) const
00326 {
00327 return ASCStringHelpers::_Stricmp ( c_str (), pS );
00328 }
00329
00335 inline int ASCString::compare_ci ( size_type p0, size_type n0, const charT* pS, size_type pos ) const
00336 {
00337 ASCString l_TempStr1 ( *this, p0, n0 );
00338 ASCString l_TempStr2 ( pS, pos );
00339 return ASCStringHelpers::_Stricmp ( l_TempStr1.c_str (), l_TempStr2.c_str () );
00340 }
00341
00342
00343 ASCString copytoLower ( const ASCString& s );
00344 ASCString copytoUpper ( const ASCString& s );
00345
00346
00347 extern const ASCString operator+ ( const char* s1, const ASCString& s2 );
00348
00349 #endif // _ASC_STRING_H_INCLUDED_