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
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
| #ifndef XSTRING_INC
#define XSTRING_INC
#include "xserializable.h"
class LD_XBASE XString : virtual public XSerializable
{
public:
/*************************************************************************/
/* Construction/destruction */
/*************************************************************************/
///////////////////////////////////////////////////////////////////////////
// Default constructor, constructs an empty XString object.
///////////////////////////////////////////////////////////////////////////
XString();
///////////////////////////////////////////////////////////////////////////
// Constructs a XString object from a character pointer. If the pointer
// is 0, an empty XString object will be constructed.
///////////////////////////////////////////////////////////////////////////
XString(const char * const sz);
XString(const wchar_t * const wsz);
///////////////////////////////////////////////////////////////////////////
// Constructs a XString object from another XString object
///////////////////////////////////////////////////////////////////////////
XString(const XString &string);
///////////////////////////////////////////////////////////////////////////
// Constructs a XString object from a signed 32 bit integer
///////////////////////////////////////////////////////////////////////////
XString(long l);
///////////////////////////////////////////////////////////////////////////
// Constructs a XString object from an unsigned 32 bit integer
///////////////////////////////////////////////////////////////////////////
XString(unsigned long ul);
///////////////////////////////////////////////////////////////////////////
// Constructs a XString object from a single character
///////////////////////////////////////////////////////////////////////////
XString(char ch);
XString(wchar_t wch);
virtual ~XString();
/*************************************************************************/
/* Modification routines */
/*************************************************************************/
///////////////////////////////////////////////////////////////////////////
// Clears the contents of the member string, effectively making it empty.
// Returns a reference to the current XString object.
///////////////////////////////////////////////////////////////////////////
virtual XString &clear();
///////////////////////////////////////////////////////////////////////////
// Replaces the contents of the member string with the string.
// Returns a reference to the current XString object.
///////////////////////////////////////////////////////////////////////////
virtual XString &operator =(const char * const sz);
virtual XString &operator =(const wchar_t * const wsz);
virtual XString &operator =(const XString &xsz);
///////////////////////////////////////////////////////////////////////////
// Replaces the contents of the string with the character.
// Returns a reference to the current XString object.
///////////////////////////////////////////////////////////////////////////
virtual XString &operator =(char ch);
virtual XString &operator =(wchar_t wch);
///////////////////////////////////////////////////////////////////////////
// Replaces the contents of the member string with the string
// representation of the signed or unsigned 32 bit integer.
// Returns a reference to the current XString object.
///////////////////////////////////////////////////////////////////////////
virtual XString &operator =(long l);
virtual XString &operator =(unsigned long ul);
///////////////////////////////////////////////////////////////////////////
// Inserts a string (either from character pointer or XString object) into
// the member string at position 'pos', which is a zero-based index (so 0
// will place the string entirely string before the first character of the
// member string).
// If the indicated position is greater than the length of the member
// string, the string is inserted behind the last character of the member
// string.
// Returns a reference to the current XString object.
///////////////////////////////////////////////////////////////////////////
virtual XString &insert(const char * const sz,unsigned long pos);
virtual XString &insert(const wchar_t * const wsz,unsigned long pos);
virtual XString &insert(const XString &xsz,unsigned long pos);
///////////////////////////////////////////////////////////////////////////
// Inserts a character into the string at position 'pos'. If the position
// is greater then the length of the string, the character is appended
// to the string.
// Returns a reference to the current XString object.
///////////////////////////////////////////////////////////////////////////
virtual XString &insert(char ch,unsigned long pos);
virtual XString &insert(wchar_t wch,unsigned long pos);
///////////////////////////////////////////////////////////////////////////
// Inserts the string representation of a signed or unsigned 32 bit integer
// into the string at position 'pos'. If the position is greater then the
// length of the string, the number is appended to the string.
// Returns a reference to the current XString object.
///////////////////////////////////////////////////////////////////////////
virtual XString &insert(long l,unsigned long pos);
virtual XString &insert(unsigned long ul,unsigned long pos);
///////////////////////////////////////////////////////////////////////////
// Concatenates the string to the member string.
// Returns a reference to the current XString object.
///////////////////////////////////////////////////////////////////////////
virtual XString &concat(const char * const sz);
virtual XString &concat(const wchar_t * const wsz);
virtual XString &concat(const XString &xsz);
virtual XString &operator +=(const char * const sz);
virtual XString &operator +=(const wchar_t * const wsz);
virtual XString &operator +=(const XString &xsz);
///////////////////////////////////////////////////////////////////////////
// Concatenates a character to the string.
// Returns a reference to the current XString object.
///////////////////////////////////////////////////////////////////////////
virtual XString &concat(char ch);
virtual XString &concat(wchar_t wch);
virtual XString &operator +=(char ch);
virtual XString &operator +=(wchar_t wch);
///////////////////////////////////////////////////////////////////////////
// Concatenates the string representation of the signed or unsigned 32 bit
// integer to the string.
// Returns a reference to the current XString object.
///////////////////////////////////////////////////////////////////////////
virtual XString &concat(long l);
virtual XString &concat(unsigned long ul);
virtual XString &operator +=(long l);
virtual XString &operator +=(unsigned long ul);
///////////////////////////////////////////////////////////////////////////
// Removes 'len' characters from the string, starting at
// position 'pos' (which is a zero-based index). If 'pos' is greater then
// the length of the string, no characters are removed. If 'len' is greater
// then the number of remaining characters behind 'pos', then the remainder
// of the string is removed.
// Returns a reference to the current XString object.
///////////////////////////////////////////////////////////////////////////
virtual XString &remove(unsigned long pos,unsigned long len);
///////////////////////////////////////////////////////////////////////////
// If the string (either character pointer or XString object)
// is found within the member string, it is removed from the member string.
// Note that all occurrences of the string are removed, not just the
// first one.
// Returns a reference to the current XString object.
///////////////////////////////////////////////////////////////////////////
virtual XString &remove(const char * const sz);
virtual XString &remove(const wchar_t * const sz);
virtual XString &remove(const XString &xsz);
///////////////////////////////////////////////////////////////////////////
// If the character is found within the string, it is removed from the
// string. Note that all occurrences of the character are removed, not just
// the first one.
// Returns a reference to the current XString object.
///////////////////////////////////////////////////////////////////////////
virtual XString &remove(char ch);
virtual XString &remove(wchar_t wch);
///////////////////////////////////////////////////////////////////////////
// If the string representation of the signed or unsigned 32 bit integer
// is found within the member string, it is removed from the member string.
// Note that all occurrences of the number are removed, not just
// the first one.
// Returns a reference to the current XString object.
///////////////////////////////////////////////////////////////////////////
virtual XString &remove(long l);
virtual XString &remove(unsigned long ul);
///////////////////////////////////////////////////////////////////////////
// Replaces all occurrances of the first string within the member string
// with the second string.
// Returns a reference to the current XString object.
///////////////////////////////////////////////////////////////////////////
virtual XString &replace(const char * const szSrc,const char * const szTgt);
virtual XString &replace(const wchar_t * const wszSrc,const wchar_t * const wszTgt);
virtual XString &replace(const XString &xszSrc,const XString &xszTgt);
virtual XString &replace(const char * const sz,const XString &xsz);
virtual XString &replace(const wchar_t * const wsz,const XString &xsz);
virtual XString &replace(const XString &xsz,const char * const sz);
virtual XString &replace(const XString &xsz,const wchar_t * const wsz);
///////////////////////////////////////////////////////////////////////////
// For each character in the first character array, the string is parsed.
// If that character is found in the string, it is replaced with the
// corresponding character from the second character array.
// Returns a reference to the current XString object.
///////////////////////////////////////////////////////////////////////////
virtual XString &translate(char *szSrc,char *szTgt);
virtual XString &translate(wchar_t *wszSrc,wchar_t *wszTgt);
///////////////////////////////////////////////////////////////////////////
// Converts all characters in the string to uppercase.
// Returns a reference to the current XString object.
///////////////////////////////////////////////////////////////////////////
virtual XString &toUpper();
///////////////////////////////////////////////////////////////////////////
// Converts all characters in the string to lowercase.
// Returns a reference to the current XString object.
///////////////////////////////////////////////////////////////////////////
virtual XString &toLower();
/*************************************************************************/
/* Substring querying routines */
/*************************************************************************/
///////////////////////////////////////////////////////////////////////////
// Returns the position of the first character in the member string of
// the substring in that member string that matches the string entirely.
// If the string isn't contained in the member string, the function
// returns -1
///////////////////////////////////////////////////////////////////////////
virtual long pos(const char * const sz) const;
virtual long pos(const wchar_t * const wsz) const;
virtual long pos(const XString &xsz) const;
///////////////////////////////////////////////////////////////////////////
// Returns the position of the first character in the string that matches
// the given character.
// If the character isn't contained in the member string, the function
// returns -1
///////////////////////////////////////////////////////////////////////////
virtual long pos(char ch) const;
virtual long pos(wchar_t wch) const;
///////////////////////////////////////////////////////////////////////////
// Returns the position of the first character in the member string of
// the substring in that member string that matches the string
// representation of the signed or unsigned 32 bit integer entirely.
// If the number isn't contained in the member string, the function
// returns -1
///////////////////////////////////////////////////////////////////////////
virtual long pos(long l) const;
virtual long pos(unsigned long ul) const;
///////////////////////////////////////////////////////////////////////////
// Returns the substring from the meber string starting at position 'pos'
// and with length 'len'.
///////////////////////////////////////////////////////////////////////////
virtual XString substr(unsigned long pos,unsigned long len) const;
///////////////////////////////////////////////////////////////////////////
// Tests whether the string is found entirely in the member string.
// i.e. "BCD" is contained in "ABCDEF", but "BDE" is not
///////////////////////////////////////////////////////////////////////////
virtual bool contains(const char * const sz) const;
virtual bool contains(const wchar_t * const wsz) const;
virtual bool contains(const XString &xsz) const;
///////////////////////////////////////////////////////////////////////////
// Tests whether the character is found in the string.
///////////////////////////////////////////////////////////////////////////
virtual bool contains(char ch) const;
virtual bool contains(wchar_t wch) const;
///////////////////////////////////////////////////////////////////////////
// Tests whether the string representation of the signed or unsigned
// 32 bit integer is found in the member string.
///////////////////////////////////////////////////////////////////////////
virtual bool contains(long l) const;
virtual bool contains(unsigned long ul) const;
/*************************************************************************/
/* Conversion routines */
/*************************************************************************/
///////////////////////////////////////////////////////////////////////////
// Returns the signed or unsigned 32 bit integer value which is represented
// by the string. If conversion is not possible (the string does not
// represent a number), 0 is returned.
///////////////////////////////////////////////////////////////////////////
virtual long toLong() const;
virtual unsigned long toUlong() const;
///////////////////////////////////////////////////////////////////////////
// Casts the XString object to a character pointer.
///////////////////////////////////////////////////////////////////////////
virtual operator const char * const() const;
virtual operator const wchar_t * const() const;
/*************************************************************************/
/* Comparison routines */
/*************************************************************************/
///////////////////////////////////////////////////////////////////////////
// Returns true if the string is empty.
///////////////////////////////////////////////////////////////////////////
virtual bool isEmpty() const;
///////////////////////////////////////////////////////////////////////////
// Returns true if the string exactly matches the member string. This
// operator is case sensitive.
///////////////////////////////////////////////////////////////////////////
virtual bool operator ==(const char * const sz) const;
virtual bool operator ==(const wchar_t * const wsz) const;
virtual bool operator ==(const XString &xsz) const;
friend bool operator ==(const char * const sz,const XString &xsz);
friend bool operator ==(const wchar_t * const wsz,const XString &xsz);
///////////////////////////////////////////////////////////////////////////
// Returns true if the string does not exactly match the member string.
// This operator is case sensitive.
///////////////////////////////////////////////////////////////////////////
virtual bool operator !=(const char * const sz) const;
virtual bool operator !=(const wchar_t * const wsz) const;
virtual bool operator !=(const XString &xsz) const;
friend bool operator !=(const char * const sz,const XString &xsz);
friend bool operator !=(const wchar_t * const wsz,const XString &xsz);
///////////////////////////////////////////////////////////////////////////
// Returns true if the string is alfabatically indexed before the member
// string.
// This operator is case sensitive.
///////////////////////////////////////////////////////////////////////////
virtual bool operator >(const char * const sz) const;
virtual bool operator >(const wchar_t * const wsz) const;
virtual bool operator >(const XString &xsz) const;
friend bool operator >(const char * const sz,const XString &xsz);
friend bool operator >(const wchar_t * const wsz,const XString &xsz);
///////////////////////////////////////////////////////////////////////////
// Returns true if the string is alfabatically indexed after the member
// string.
// This operator is case sensitive.
///////////////////////////////////////////////////////////////////////////
virtual bool operator <(const char * const sz) const;
virtual bool operator <(const wchar_t * const wsz) const;
virtual bool operator <(const XString &xsz) const;
friend bool operator <(const char * const sz,const XString &xsz);
friend bool operator <(const wchar_t * const wsz,const XString &xsz);
///////////////////////////////////////////////////////////////////////////
// Returns true if the string is alfabatically indexed before or equally
// to the member string.
// This operator is case sensitive.
///////////////////////////////////////////////////////////////////////////
virtual bool operator >=(const char * const sz) const;
virtual bool operator >=(const wchar_t * const wsz) const;
virtual bool operator >=(const XString &xsz) const;
friend bool operator >=(const char * const sz,const XString &xsz);
friend bool operator >=(const wchar_t * const wsz,const XString &xsz);
///////////////////////////////////////////////////////////////////////////
// Returns true if the string is alfabatically indexed after or equally
// to the member string.
// This operator is case sensitive.
///////////////////////////////////////////////////////////////////////////
virtual bool operator <=(const char * const sz) const;
virtual bool operator <=(const wchar_t * const wsz) const;
virtual bool operator <=(const XString &xsz) const;
friend bool operator <=(const char * const sz,const XString &xsz);
friend bool operator <=(const wchar_t * const wsz,const XString &xsz);
/*************************************************************************/
/* Direct member querying */
/*************************************************************************/
///////////////////////////////////////////////////////////////////////////
// Returns the number of characters in the string.
///////////////////////////////////////////////////////////////////////////
virtual DWORD length() const;
///////////////////////////////////////////////////////////////////////////
// Returns the character at position 'pos' in the string, which is a zero
// based index. If 'pos' is greater then the length of the string, it
// returns 0.
///////////////////////////////////////////////////////////////////////////
virtual char operator[](unsigned long pos) const;
/*************************************************************************/
/* Cloning routines */
/*************************************************************************/
///////////////////////////////////////////////////////////////////////////
// Returns a copy of the string.
///////////////////////////////////////////////////////////////////////////
virtual XString clone() const;
///////////////////////////////////////////////////////////////////////////
// Clones the current XString object and adds a string to the clone.
///////////////////////////////////////////////////////////////////////////
virtual XString operator +(const char * const sz) const;
virtual XString operator +(const wchar_t * const wsz) const;
virtual XString operator +(const XString &xsz) const;
friend XString operator +(const char * const sz,const XString &xsz);
friend XString operator +(const wchar_t * const wsz,const XString &xsz);
friend XString operator +(char ch,const XString &xsz);
friend XString operator +(wchar_t wch,const XString &xsz);
friend XString operator +(long l,const XString &xsz);
friend XString operator +(unsigned long ul,const XString &xsz);
/*************************************************************************/
/* Interface requirements */
/*************************************************************************/
///////////////////////////////////////////////////////////////////////////
// Functions of the serializable interface.
// Override these if you add additional data members to your
// derived class of XString.
///////////////////////////////////////////////////////////////////////////
virtual unsigned long byteSize() const;
virtual BYTE *serialize(BYTE *pBuf) const;
virtual BYTE *deserialize(BYTE *pBuf);
protected:
char * m_sz;
mutable wchar_t * m_wsz;
unsigned long m_ulLen;
};
#endif |