Advanced Strategic Command
ascstring.h
Go to the documentation of this file.
1 
2 
3 #ifndef ascstringH
4 #define ascstringH
5 
6 #include "ASCStringHelpers.h"
7 #include <stdexcept> // for range_error
8 #include <stdarg.h>
9 #include <boost/scoped_array.hpp>
10 
11 using std::range_error;
12 
13 
14 class ASCString : public ASCCharTString
15 {
16 
17 public:
18 
23 
24 #ifndef _UNICODE_BROKEN_
25 
31 
32 #endif // _UNICODE_BROKEN_
33 
34  // Constructors
35  ASCString ( );
36  ASCString ( const charT* pS );
37  ASCString ( const charT* pS, size_type n );
38  ASCString ( size_type n, charT c );
39  ASCString ( const_iterator first, const_iterator last );
40 
41  // Constructors for ASCCharTString type
42  ASCString ( const ASCCharTString& s );
43  ASCString ( const ASCCharTString& s, size_type pos, size_type n );
44 
45 #ifndef _UNICODE_BROKEN_
46 
47  // Constructors for ASCAdaptatorString type
48  explicit ASCString ( const ASCAdaptatorString& s );
49  explicit ASCString ( const ASCAdaptatorString& s, size_type pos, size_type n );
50 
51  // Copy Operators for ASCAdaptatorString type
53 
54 #endif // _UNICODE_BROKEN_
55 
56  // Copy Operators for ASCCharTString type
57  ASCString& operator= ( const ASCCharTString& s );
58 
59  // Copy Operators for charT* type
60  ASCString& operator= ( const charT* pS );
61 
62  // Case-insensitive comparisons
63  int compare_ci ( const ASCCharTString& s ) const;
64  int compare_ci ( size_type p0, size_type n0, const ASCCharTString& s );
65  int compare_ci ( size_type p0, size_type n0, const ASCCharTString& s, size_type pos, size_type n );
66  int compare_ci ( const charT* pS ) const;
67  int compare_ci ( size_type p0, size_type n0, const charT* pS, size_type pos ) const;
68 
70  static ASCString toString( int i );
71  static ASCString toString( unsigned int i );
72 
73  #ifdef SIZE_T_not_identical_to_INT
74  static ASCString toString( size_t i );
75  #endif
76 
78  // static ASCString toString(int i, int radix );
80  static ASCString toString( double d );
81 
83  ASCString& replaceAll( const ASCString& old, const ASCString& newString);
84 
86  ASCString& replaceAll_ci( const ASCString& old, const ASCString& newString);
87 
88  // Case-manipulation helpers
89  ASCString& toLower ();
90  ASCString& toUpper ();
91 
92  // Printing and formating helpers.
93  ASCString& format ( const charT* pFormat, ... );
94  ASCString& vaformat ( const charT* pFormat, va_list ap );
95  void printf ();
96 
97  // convenience functions
98  bool endswith( const ASCString& s ) const;
99 };
100 
101 // CONSTRUCTORS
106 : ASCCharTString ( )
107 {
108 }
109 
115 inline ASCString::ASCString ( const charT* pS )
116 : ASCCharTString ( pS )
117 {
118 }
119 
127 inline ASCString::ASCString ( const charT* pS, size_type n )
128 : ASCCharTString ( pS, n )
129 {
130 }
131 
139 inline ASCString::ASCString ( size_type n, charT c )
140 : ASCCharTString ( n, c )
141 {
142 }
143 
153 inline ASCString::ASCString ( const_iterator first, const_iterator last )
154 : ASCCharTString ( first, last )
155 {
156 }
157 
158 // Constructors for ASCCharTString type
165 : ASCCharTString ( s )
166 {
167 }
168 
178 inline ASCString::ASCString ( const ASCCharTString& s, size_type pos, size_type n )
179 : ASCCharTString ( s, pos, n )
180 {
181 }
182 
183 
184 #ifndef _UNICODE_BROKEN_
185 
186 // Constructors for ASCAdaptatorString type
187 
198 : ASCCharTString ()
199 {
200  // auto_ptr will release memory if an exception is raised
201  boost::scoped_array< charT > pE ( new charT [ s.length () + sizeof ( charT ) ] );
202 
203  size_t stNumCharConverted = ASCStringHelpers::_ConvertToCharT ( pE.get (), s.c_str(), s.length() );
204  if ( stNumCharConverted != s.length() )
205  {
206  throw range_error ( "ASCString::ASCString( const ASCAdaptatorString& s ) ==> unable to convert all characters from ASCAdaptatorString to ASCCharTString type." );
207  }
208 
209  assign ( pE.get(), stNumCharConverted );
210 }
211 
225 inline ASCString::ASCString ( const ASCAdaptatorString& s, size_type pos, size_type n )
226 : ASCCharTString ()
227 {
228  size_t stLen = n - pos;
229 
230  // auto_ptr will release memory if an exception is raised
231  boost::scoped_array< charT > pE ( new charT [ stLen + sizeof ( charT ) ] );
232 
233  const NoncharT* pCE = s.c_str ();
234  size_t stNumCharConverted = ASCStringHelpers::_ConvertToCharT ( pE.get (), &pCE[ pos ], stLen );
235  if ( stNumCharConverted != stLen )
236  {
237  throw range_error ( "ASCString::ASCString( const ASCAdaptatorString& s, size_type pos, size_type n ) ==> unable to convert all characters from ASCAdaptatorString to ASCCharTString type." );
238  }
239 
240  assign ( pE.get(), stLen );
241 }
242 
243 // Copy Operators for ASCAdaptatorString type
244 
257 {
258  ASCString str ( s );
259  assign ( str );
260  return *this;
261 }
262 
263 #endif // _UNICODE_BROKEN_
264 
265 
266 // Copy Operators
267 
276 {
277  assign ( s );
278  return *this;
279 }
280 
281 
283 {
284  ASCString str ( pS );
285  assign ( str );
286  return *this;
287 }
288 
289 // COMPARE_CI
290 
296 inline int ASCString::compare_ci ( const ASCCharTString& s ) const
297 {
298  return ASCStringHelpers::_Stricmp ( c_str (), s.c_str () );
299 }
300 
306 inline int ASCString::compare_ci ( size_type p0, size_type n0, const ASCCharTString& s )
307 {
308  ASCString l_TempString ( *this, p0, n0 );
309  return ASCStringHelpers::_Stricmp ( l_TempString.c_str () , s.c_str () );
310 }
311 
317 inline int ASCString::compare_ci ( size_type p0, size_type n0,const ASCCharTString& s, size_type pos, size_type n )
318 {
319  ASCString l_TempStr1 ( *this, p0, n0 );
320  ASCString l_TempStr2 ( s, pos, n );
321  return ASCStringHelpers::_Stricmp ( l_TempStr1.c_str (), l_TempStr2.c_str () );
322 }
323 
327 inline int ASCString::compare_ci ( const charT* pS ) const
328 {
329  return ASCStringHelpers::_Stricmp ( c_str (), pS );
330 }
331 
337 inline int ASCString::compare_ci ( size_type p0, size_type n0, const charT* pS, size_type pos ) const
338 {
339  ASCString l_TempStr1 ( *this, p0, n0 );
340  ASCString l_TempStr2 ( pS, pos );
341  return ASCStringHelpers::_Stricmp ( l_TempStr1.c_str (), l_TempStr2.c_str () );
342 }
343 
344 // GLOBALS
345 ASCString copytoLower ( const ASCString& s );
346 ASCString copytoUpper ( const ASCString& s );
347 
348 // extern const ASCString operator+ ( const ASCString& s1, const ASCString& s2 );
349 extern const ASCString operator+ ( const char* s1, const ASCString& s2 );
350 
351 #endif // _ASC_STRING_H_INCLUDED_
ASCString & toLower()
Definition: ascstring.cpp:36
ASCStringHelpers::charT charT
Definition: ascstring.h:22
ASCString & toUpper()
Definition: ascstring.cpp:55
ASCString & vaformat(const charT *pFormat, va_list ap)
Definition: ascstring.cpp:91
static int _Stricmp(const charT *pS1, const charT *pS2)
static size_t _ConvertToCharT(charT *pDest, const NoncharT *pSrc, size_t count)
const ASCString operator+(const char *s1, const ASCString &s2)
Definition: ascstring.cpp:232
ASCString & format(const charT *pFormat,...)
Definition: ascstring.cpp:78
The ASCString class provides an abstract way to manipulate strings.
Definition: ascstring.h:14
ASCCharTString represents the STL parent's string class of ASCString.
ASCString copytoLower(const ASCString &String)
Definition: ascstring.cpp:167
ASCString & operator=(const ASCAdaptatorString &s)
Definition: ascstring.h:256
static ASCString toString(int i)
converts the parameter to a String
Definition: ascstring.cpp:193
ASCAdaptatorString represents the complementary class to ASCCharTString.
ASCStringHelpers::NoncharT NoncharT
Definition: ascstring.h:30
ASCString copytoUpper(const ASCString &String)
Definition: ascstring.cpp:185
ASCCharTString::value_type charT
void printf()
Definition: ascstring.cpp:137
bool endswith(const ASCString &s) const
Checks if the last characters of string are equal to s.
Definition: ascstring.cpp:146
ASCString & replaceAll(const ASCString &old, const ASCString &newString)
replaces all occurances of old with newString
Definition: ascstring.cpp:239
ASCAdaptatorString::value_type NoncharT
int compare_ci(const ASCCharTString &s) const
Definition: ascstring.h:296
ASCString & replaceAll_ci(const ASCString &old, const ASCString &newString)
replaces all occurances of old with newString ; case insensitive
Definition: ascstring.cpp:248