File: ascstring.h

package info (click to toggle)
asc 2.6.1.0-9
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 81,740 kB
  • sloc: cpp: 158,704; sh: 11,544; ansic: 6,736; makefile: 604; perl: 138
file content (351 lines) | stat: -rw-r--r-- 10,935 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351


#ifndef ascstringH
#define ascstringH

#include "ASCStringHelpers.h"
#include <stdexcept>      // for range_error
#include <stdarg.h>
#include <boost/scoped_array.hpp>

using std::range_error;


class ASCString : public ASCCharTString
{

public:

    /*!
        charT is an alias to ASCStringHelpers::charT, the character type used to represent strings internally.
    */
    typedef ASCStringHelpers::charT     charT;

#ifndef _UNICODE_BROKEN_

    /*!
        NoncharT is an alias to ASCStringHelpers::NoncharT, the complementary character type used to convert strings
        not using charT types.
    */
    typedef ASCStringHelpers::NoncharT        NoncharT;

#endif // _UNICODE_BROKEN_

    // Constructors
    ASCString ( );
    ASCString ( const charT* pS );
    ASCString ( const charT* pS, size_type n );
    ASCString ( size_type n, charT c );
    ASCString ( const_iterator first, const_iterator last );

    // Constructors for ASCCharTString type
    ASCString ( const ASCCharTString& s );
    ASCString ( const ASCCharTString& s, size_type pos, size_type n );

#ifndef _UNICODE_BROKEN_

    // Constructors for ASCAdaptatorString type
    explicit ASCString ( const ASCAdaptatorString& s );
    explicit ASCString ( const ASCAdaptatorString& s, size_type pos, size_type n );

    // Copy Operators for ASCAdaptatorString type
    ASCString& operator=( const ASCAdaptatorString& s );

#endif // _UNICODE_BROKEN_

    // Copy Operators for ASCCharTString type
    ASCString& operator= ( const ASCCharTString& s );

    // Copy Operators for charT*  type
    ASCString& operator= ( const charT* pS );

    // Case-insensitive comparisons
    int compare_ci ( const ASCCharTString& s ) const;
    int compare_ci ( size_type p0, size_type n0, const ASCCharTString& s );
    int compare_ci ( size_type p0, size_type n0, const ASCCharTString& s, size_type pos, size_type n );
    int compare_ci ( const charT* pS ) const;
    int compare_ci ( size_type p0, size_type n0, const charT* pS, size_type pos ) const;

    //! converts the parameter to a String
    static ASCString toString( int i );
    static ASCString toString( unsigned int i );
    
   #ifdef SIZE_T_not_identical_to_INT
    static ASCString toString( size_t i );
   #endif 
    
    //! converts the parameter to a String with base radix
    // static ASCString toString(int i, int radix );
    //! converts the parameter to a String
    static ASCString toString( double d );

    //! replaces all occurances of old with newString
    ASCString& replaceAll( const ASCString& old, const ASCString& newString);

    //! replaces all occurances of old with newString ; case insensitive
    ASCString& replaceAll_ci( const ASCString& old, const ASCString& newString);
    
    // Case-manipulation helpers
    ASCString&  toLower    ();
    ASCString&  toUpper    ();

    // Printing and formating helpers.
    ASCString&  format     ( const charT* pFormat, ... );
    ASCString&  vaformat     ( const charT* pFormat, va_list ap );
    void        printf     ();
    
    // convenience functions
    bool endswith( const ASCString& s ) const;
};

// CONSTRUCTORS
/*!
    Construct an ASCString object.
*/
inline ASCString::ASCString ( )
: ASCCharTString ( )
{
}

/*!
    \overload ASCString::ASCString ( const charT* pS )

    \param pS a pointer to a NULL-terminated array of \a charT element types.
*/
inline ASCString::ASCString ( const charT* pS )
: ASCCharTString ( pS )
{
}

/*!
    \overload ASCString::ASCString ( const charT* pS, size_type n )

    \param pS a pointer to a NULL-terminated array of \a charT element types.

    \param n the number of elements from \a pS to use to initialise the ASCString object.
*/
inline ASCString::ASCString ( const charT* pS, size_type n )
: ASCCharTString ( pS, n )
{
}

/*!
    \overload ASCString::ASCString ( size_type n, charT c )

    \param n the repeat count of \a c.

    \param c a single \a charT element type to be repeated \a n times.
*/
inline ASCString::ASCString ( size_type n, charT c )
: ASCCharTString ( n, c )
{
}

/*!
    \overload ASCString::ASCString ( const_iterator first, const_iterator last )

    \param first a const iterator delimiting the begining of a range of \a charT element types to be used
    to construct this ASCString.

    \param last a const iterator delimiting the ending of a range of \a charT element types to be used
    to construct this ASCString.
*/
inline ASCString::ASCString ( const_iterator first, const_iterator last )
: ASCCharTString ( first, last )
{
}

// Constructors for ASCCharTString type
/*!
    \overload ASCString::ASCString ( const ASCCharTString& s )

    \param s a const reference to an ASCCharTString object to be used to construct this ASCString.
*/
inline ASCString::ASCString ( const ASCCharTString& s )
: ASCCharTString ( s )
{
}

/*!
    \overload ASCString::ASCString ( const ASCCharTString& s, size_type pos, size_type n )

    \param s a const reference to an ASCCharTString object to be used to construct this ASCString.

    \param pos the position of the first character in \a s to be used to construct this ASCString.

    \param n the count of characters used to construct this ASCString begining at position \a pos.
*/
inline ASCString::ASCString ( const ASCCharTString& s, size_type pos, size_type n )
: ASCCharTString ( s, pos, n )
{
}


#ifndef _UNICODE_BROKEN_

// Constructors for ASCAdaptatorString type

/*!
    \overload ASCString::ASCString ( const ASCAdaptatorString& s )

    \param s a const reference to an ASCAdaptatorString object to be used to construct this ASCString.

    \exception range_error
    The range_error exception is raised when not all the characters of ASCAdaptatorString can be converted
    to ASCCharTString's characters.
*/
inline ASCString::ASCString ( const ASCAdaptatorString& s )
: ASCCharTString ()
{
    // auto_ptr will release memory if an exception is raised
    boost::scoped_array< charT > pE ( new charT [ s.length () + sizeof ( charT ) ] );

    size_t stNumCharConverted = ASCStringHelpers::_ConvertToCharT ( pE.get (), s.c_str(), s.length() );
    if ( stNumCharConverted != s.length() )
    {
        throw range_error ( "ASCString::ASCString( const ASCAdaptatorString& s ) ==> unable to convert all characters from ASCAdaptatorString to ASCCharTString type." );
    }

    assign ( pE.get(), stNumCharConverted );
}

/*!
    \overload ASCString::ASCString ( const ASCAdaptatorString& s, size_type pos, size_type n )

    \param s a const reference to an ASCAdaptatorString object to be used to construct this ASCString.

    \param pos the position of the first character in \a s to be used to construct this ASCString.

    \param n the count of characters used to construct this ASCString begining at position \a pos.

    \exception range_error
    The range_error exception is raised when not all the characters of ASCAdaptatorString can be converted
    to ASCCharTString's characters.
*/
inline ASCString::ASCString ( const ASCAdaptatorString& s, size_type pos, size_type n )
: ASCCharTString ()
{
    size_t stLen = n - pos;

    // auto_ptr will release memory if an exception is raised
    boost::scoped_array< charT > pE ( new charT [ stLen + sizeof ( charT ) ] );

    const NoncharT* pCE = s.c_str ();
    size_t stNumCharConverted = ASCStringHelpers::_ConvertToCharT ( pE.get (), &pCE[ pos ], stLen );
    if ( stNumCharConverted != stLen )
    {
        throw range_error ( "ASCString::ASCString( const ASCAdaptatorString& s, size_type pos, size_type n ) ==> unable to convert all characters from ASCAdaptatorString to ASCCharTString type." );
    }

    assign ( pE.get(), stLen );
}

// Copy Operators for ASCAdaptatorString type

/*!
    \overload ASCString& ASCString::operator= ( const ASCAdaptatorString& s )

    \param s a const reference to an ASCAdaptatorString object to be assigned to this ASCString.

    \return returns a reference to this ASCString.

    \exception range_error
    The range_error exception is raised when not all the characters of ASCAdaptatorString can be converted
    to ASCCharTString's characters.
*/
inline ASCString& ASCString::operator= ( const ASCAdaptatorString& s )
{
    ASCString str ( s );
    assign ( str );
    return *this;
}

#endif // _UNICODE_BROKEN_


// Copy Operators

/*!
    Assign a new value to an ASCString object.

    \param s a const reference to an ASCCharTString object to be assigned to this ASCString.

    \return returns a reference to this ASCString.
*/
inline ASCString& ASCString::operator= ( const ASCCharTString& s )
{
    assign ( s );
    return *this;
}


inline ASCString& ASCString::operator= ( const charT* pS )
{
    ASCString str ( pS );
    assign ( str );
    return *this;
}

// COMPARE_CI

/*!
    Compare two strings, case insensitive.

    \param s a const reference to an ASCCharTString object to be used to construct this ASCString.
*/
inline int ASCString::compare_ci ( const ASCCharTString& s ) const
{
    return ASCStringHelpers::_Stricmp ( c_str (), s.c_str () );
}

/*!
    \overload int ASCString::compare_ci ( size_type p0, size_type n0, const ASCCharTString& s )

    Compare the range [ p0 , n0 ] of this ASCString with the whole ASCCharTString.
*/
inline int ASCString::compare_ci ( size_type p0, size_type n0, const ASCCharTString& s )
{
    ASCString l_TempString ( *this, p0, n0 );
    return ASCStringHelpers::_Stricmp ( l_TempString.c_str () , s.c_str () );
}

/*!
    \overload int ASCString::compare_ci ( size_type p0, size_type n0,const ASCCharTString& s, size_type pos, size_type n )

    Compare the range [ p0 , n0 ] of this ASCString with the range [ pos, n ] of ASCCharTString.
*/
inline int ASCString::compare_ci ( size_type p0, size_type n0,const ASCCharTString& s, size_type pos, size_type n )
{
    ASCString l_TempStr1 ( *this, p0, n0 );
    ASCString l_TempStr2 ( s, pos, n );
    return ASCStringHelpers::_Stricmp ( l_TempStr1.c_str (), l_TempStr2.c_str () );
}

/*!
    \overload int ASCString::compare_ci ( const charT* pS ) const
*/
inline int ASCString::compare_ci ( const charT* pS ) const
{
    return ASCStringHelpers::_Stricmp ( c_str (), pS );
}

/*!
    \overload int ASCString::compare_ci ( size_type p0, size_type n0, const charT* pS, size_type pos ) const

    Compare the range [ p0 , n0 ] of this ASCString with up to [ 0, pos ] elements of \a pS.
*/
inline int ASCString::compare_ci ( size_type p0, size_type n0, const charT* pS, size_type pos ) const
{
    ASCString l_TempStr1 ( *this, p0, n0 );
    ASCString l_TempStr2 ( pS, pos  );
    return ASCStringHelpers::_Stricmp ( l_TempStr1.c_str (), l_TempStr2.c_str () );
}

// GLOBALS
ASCString copytoLower ( const ASCString& s );
ASCString copytoUpper ( const ASCString& s );

// extern const ASCString operator+ ( const ASCString& s1, const ASCString& s2 );
extern const ASCString operator+ ( const char* s1, const ASCString& s2 );

#endif // _ASC_STRING_H_INCLUDED_