1 |
|
---|
2 | /*
|
---|
3 | * bs_string.h:
|
---|
4 | * header file for the various string classes.
|
---|
5 | *
|
---|
6 | * This declares BSString, BSUString, and
|
---|
7 | * BSUniCodec, among other things. These give
|
---|
8 | * you not only a very efficient basic string
|
---|
9 | * class (BSString), but also full Unicode
|
---|
10 | * and codepage support and conversion between
|
---|
11 | * them.
|
---|
12 | *
|
---|
13 | * Warning: if you include this header, you'll
|
---|
14 | * get a typedef for "string" to BSString and
|
---|
15 | * for "ustring" to BSUString, which might
|
---|
16 | * conflict with other string classes that you
|
---|
17 | * might be using.
|
---|
18 | *
|
---|
19 | *@@include #include "helpers\stringh.h"
|
---|
20 | *@@include #include "helpers\xstring.h"
|
---|
21 | *@@include #include "base\bs_string.h"
|
---|
22 | */
|
---|
23 |
|
---|
24 | /*
|
---|
25 | * This file Copyright (C) 1999-2002 Ulrich Mller.
|
---|
26 | * This program is free software; you can redistribute it and/or modify
|
---|
27 | * it under the terms of the GNU General Public License as published by
|
---|
28 | * the Free Software Foundation, in version 2 as it comes in the COPYING
|
---|
29 | * file of this distribution.
|
---|
30 | * This program is distributed in the hope that it will be useful,
|
---|
31 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
32 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
33 | * GNU General Public License for more details.
|
---|
34 | */
|
---|
35 |
|
---|
36 | #ifndef WARPIN_STRING_HEADER_INCLUDED
|
---|
37 | #define WARPIN_STRING_HEADER_INCLUDED
|
---|
38 |
|
---|
39 | typedef unsigned long size_type;
|
---|
40 |
|
---|
41 | class BSString;
|
---|
42 | class BSUString;
|
---|
43 |
|
---|
44 | // extern BSMutex G_mtxStrings;
|
---|
45 |
|
---|
46 | // #define STRINGLOCK BSLock lock(G_mtxStrings)
|
---|
47 |
|
---|
48 | #define STRINGLOCK
|
---|
49 |
|
---|
50 | /*
|
---|
51 | *@@ BSUniCodec:
|
---|
52 | * Unicode conversion object (COder and
|
---|
53 | * DECoder).
|
---|
54 | *
|
---|
55 | * Create one such object to allow conversion
|
---|
56 | * from UTF-8 to codepage-specific and back.
|
---|
57 | * An instance of this is required as input
|
---|
58 | * to the conversion methods from BSString
|
---|
59 | * to BSUString and vice versa, such as:
|
---|
60 | *
|
---|
61 | * -- BSString::assignUtf8 (convert UTF-8
|
---|
62 | * to codepage-specific)
|
---|
63 | *
|
---|
64 | * -- BSString::appendUtf8 (append UTF-8
|
---|
65 | * to codepage-specific)
|
---|
66 | *
|
---|
67 | * -- BSUString::assignCP (convert
|
---|
68 | * codepage-specific to UTF-8)
|
---|
69 | *
|
---|
70 | * This thing throws BSExcptBase if the
|
---|
71 | * input codepage is not supported or if
|
---|
72 | * we run into invalid code sequences.
|
---|
73 | *
|
---|
74 | *@@added V0.9.18 (2002-03-08) [umoeller]
|
---|
75 | */
|
---|
76 |
|
---|
77 | class BSUniCodec : public BSRoot
|
---|
78 | {
|
---|
79 | private:
|
---|
80 | void *_pCodec;
|
---|
81 | unsigned short _usCodepage;
|
---|
82 | char _achDBCS[12];
|
---|
83 | BOOL _fDouble; // TRUE if double-byte codepage
|
---|
84 |
|
---|
85 | public:
|
---|
86 | DECLARE_CLASS(BSUniCodec);
|
---|
87 |
|
---|
88 | BSUniCodec(unsigned short usCodepage);
|
---|
89 | ~BSUniCodec();
|
---|
90 |
|
---|
91 | void Codepage2Uni(BSUString &ustr,
|
---|
92 | const char *pcszCP,
|
---|
93 | unsigned long ulLength);
|
---|
94 |
|
---|
95 | void Uni2Codepage(BSString &str,
|
---|
96 | const char *pcszUni,
|
---|
97 | unsigned long ulLength);
|
---|
98 |
|
---|
99 | /*
|
---|
100 | *@@ QueryCodepage:
|
---|
101 | * returns the codepage that this
|
---|
102 | * BSUniCodec was created for.
|
---|
103 | */
|
---|
104 |
|
---|
105 | inline unsigned short QueryCodepage()
|
---|
106 | {
|
---|
107 | return _usCodepage;
|
---|
108 | }
|
---|
109 | };
|
---|
110 |
|
---|
111 | /*
|
---|
112 | *@@ BSStringBuf:
|
---|
113 | * string buffer encapsulation for BSStringBase.
|
---|
114 | *
|
---|
115 | * Several BSStringBase instances can share
|
---|
116 | * the same string buffer when copied from
|
---|
117 | * one another. This is new with V0.9.18,
|
---|
118 | * while previously each BSString had its own
|
---|
119 | * buffer, which lead to a lot of redundant
|
---|
120 | * copying.
|
---|
121 | *
|
---|
122 | * Note that all methods are private in order
|
---|
123 | * not to let anyone mess with these things.
|
---|
124 | *
|
---|
125 | *@@added V0.9.18 (2002-03-08) [umoeller]
|
---|
126 | */
|
---|
127 |
|
---|
128 | class BSStringBuf : public BSRoot
|
---|
129 | {
|
---|
130 | friend class BSStringBase;
|
---|
131 | friend class BSString;
|
---|
132 | friend class BSUString;
|
---|
133 |
|
---|
134 | private:
|
---|
135 | XSTRING _str;
|
---|
136 |
|
---|
137 | size_t *_pShiftTable;
|
---|
138 | unsigned long _fRepeat;
|
---|
139 |
|
---|
140 | unsigned long _cShared; // if 0, buf is used only by one
|
---|
141 | // instance; otherwise, no. of
|
---|
142 | // BSString's that share this buf
|
---|
143 |
|
---|
144 | DECLARE_CLASS(BSStringBuf);
|
---|
145 |
|
---|
146 | /*
|
---|
147 | *@@ BSStringBuf:
|
---|
148 | * constructor to create a
|
---|
149 | * new member XSTRING from the
|
---|
150 | * given C string.
|
---|
151 | */
|
---|
152 |
|
---|
153 | BSStringBuf(const char *pcsz,
|
---|
154 | unsigned long ulLength,
|
---|
155 | unsigned long cbAllocate)
|
---|
156 | : BSRoot(tBSStringBuf)
|
---|
157 | {
|
---|
158 | xstrInit(&_str, cbAllocate);
|
---|
159 | xstrcpy(&_str, pcsz, ulLength);
|
---|
160 | _pShiftTable = NULL;
|
---|
161 | _fRepeat = 0;
|
---|
162 | _cShared = 0;
|
---|
163 | }
|
---|
164 |
|
---|
165 | /*
|
---|
166 | *@@ BSStringBuf:
|
---|
167 | * evil second constructor
|
---|
168 | * to take over an existing
|
---|
169 | * XSTRING. Used by BSString::_take_from
|
---|
170 | * only.
|
---|
171 | */
|
---|
172 |
|
---|
173 | BSStringBuf(XSTRING &str)
|
---|
174 | : BSRoot(tBSStringBuf)
|
---|
175 | {
|
---|
176 | memcpy(&_str, &str, sizeof(XSTRING));
|
---|
177 | _pShiftTable = NULL;
|
---|
178 | _fRepeat = 0;
|
---|
179 | _cShared = 0;
|
---|
180 |
|
---|
181 | // and nuke the source XSTRING so
|
---|
182 | // that the caller won't free it
|
---|
183 | memset(&str, 0, sizeof(XSTRING));
|
---|
184 | }
|
---|
185 |
|
---|
186 | /*
|
---|
187 | *@@ ~BSStringBuf:
|
---|
188 | * destructor. Frees all memory associated
|
---|
189 | * with the buffer.
|
---|
190 | */
|
---|
191 |
|
---|
192 | ~BSStringBuf()
|
---|
193 | {
|
---|
194 | ClearShiftTable();
|
---|
195 | xstrClear(&_str);
|
---|
196 | }
|
---|
197 |
|
---|
198 | /*
|
---|
199 | *@@ ClearShiftTable:
|
---|
200 | * clears the internal shift
|
---|
201 | * table when the string buffer
|
---|
202 | * has changed.
|
---|
203 | */
|
---|
204 |
|
---|
205 | inline void ClearShiftTable()
|
---|
206 | {
|
---|
207 | if (_pShiftTable)
|
---|
208 | {
|
---|
209 | free(_pShiftTable);
|
---|
210 | _pShiftTable = 0;
|
---|
211 | }
|
---|
212 | _fRepeat = FALSE;
|
---|
213 | }
|
---|
214 | };
|
---|
215 |
|
---|
216 | /*
|
---|
217 | *@@ BSStringBase:
|
---|
218 | * common superclass for BSString and
|
---|
219 | * BSUString. This implements most of
|
---|
220 | * the functionality for the two, but
|
---|
221 | * since the constructor is protected,
|
---|
222 | * this cannot be created as such.
|
---|
223 | *
|
---|
224 | * BSString and BSUString are implemented
|
---|
225 | * as subclasses of this to prevent illegal
|
---|
226 | * assignments between codepage-specific
|
---|
227 | * and UTF-8 strings already by the compiler.
|
---|
228 | *
|
---|
229 | * This has a BSStringBuf pointer as
|
---|
230 | * a member so that several strings can
|
---|
231 | * share the same memory.
|
---|
232 | *
|
---|
233 | *@@added V0.9.18 (2002-03-08) [umoeller]
|
---|
234 | */
|
---|
235 |
|
---|
236 | class BSStringBase : public BSRoot
|
---|
237 | {
|
---|
238 | public:
|
---|
239 | DECLARE_CLASS(BSStringBase);
|
---|
240 |
|
---|
241 | #ifdef __IBMCPP__
|
---|
242 | friend class BSStringBase;
|
---|
243 | #endif
|
---|
244 | // 2000-01-15: This line is extraordinary useless - class instances
|
---|
245 | // of the same type are always friends (czw)
|
---|
246 | // V0.9.1 (2000-02-01) [umoeller]: Hi Jens. Not with VAC++, apparently,
|
---|
247 | // because without this line, this wouldn't compile.
|
---|
248 |
|
---|
249 | protected:
|
---|
250 | BSStringBuf *_pBuf;
|
---|
251 |
|
---|
252 | /********************************************
|
---|
253 | *
|
---|
254 | * protected methods
|
---|
255 | *
|
---|
256 | ********************************************/
|
---|
257 |
|
---|
258 | /*
|
---|
259 | *@@ Init:
|
---|
260 | * private helper method to initialize
|
---|
261 | * the instance. Called by all constructors.
|
---|
262 | */
|
---|
263 |
|
---|
264 | void Init();
|
---|
265 |
|
---|
266 | void FreeBuf();
|
---|
267 |
|
---|
268 | void CopyFrom(const BSStringBase &s);
|
---|
269 | void CopyFrom(const BSStringBase &s,
|
---|
270 | size_type ulPos,
|
---|
271 | size_type n = npos);
|
---|
272 | void CopyFrom(const char *psz);
|
---|
273 | void CopyFrom(const char *p1, const char *p2);
|
---|
274 | void CopyFrom(char c);
|
---|
275 |
|
---|
276 | BSStringBase(BSClassID &Class);
|
---|
277 |
|
---|
278 | private:
|
---|
279 |
|
---|
280 | /*
|
---|
281 | *@@ BSStringBase:
|
---|
282 | * private default copy constructor
|
---|
283 | * to make sure this can never be
|
---|
284 | * called by the subclasses.
|
---|
285 | */
|
---|
286 |
|
---|
287 | BSStringBase(const BSStringBase &s)
|
---|
288 | : BSRoot(s._Class)
|
---|
289 | {
|
---|
290 | };
|
---|
291 |
|
---|
292 | protected:
|
---|
293 |
|
---|
294 | BSStringBase(const BSStringBase &s,
|
---|
295 | BSClassID &Class);
|
---|
296 |
|
---|
297 | virtual ~BSStringBase();
|
---|
298 |
|
---|
299 | public:
|
---|
300 |
|
---|
301 | static const size_type npos;
|
---|
302 |
|
---|
303 | /********************************************
|
---|
304 | *
|
---|
305 | * property queries
|
---|
306 | *
|
---|
307 | ********************************************/
|
---|
308 |
|
---|
309 | /*
|
---|
310 | *@@ size:
|
---|
311 | * returns the no. of characters in
|
---|
312 | * the string (excluding our internal
|
---|
313 | * null terminator) or 0 if the string
|
---|
314 | * is empty.
|
---|
315 | *
|
---|
316 | * Be warned, if the string is UTF-8
|
---|
317 | * encoded, this will not take multi-byte
|
---|
318 | * encodings into account. This returns
|
---|
319 | * the number of bytes, not the number
|
---|
320 | * of UTF characters.
|
---|
321 | */
|
---|
322 |
|
---|
323 | inline size_type size()
|
---|
324 | const
|
---|
325 | {
|
---|
326 | return ((_pBuf) ? (_pBuf->_str.ulLength) : 0);
|
---|
327 | }
|
---|
328 |
|
---|
329 | /*
|
---|
330 | *@@ length:
|
---|
331 | * STL string compatibility function,
|
---|
332 | * same as BSStringBase::size().
|
---|
333 | */
|
---|
334 |
|
---|
335 | inline size_type length()
|
---|
336 | const
|
---|
337 | {
|
---|
338 | return (size());
|
---|
339 | }
|
---|
340 |
|
---|
341 | /*
|
---|
342 | *@@ capacity:
|
---|
343 | * returns the amount of memory presently
|
---|
344 | * allocated for the string. This is at
|
---|
345 | * least what size() or length() return,
|
---|
346 | * but can be more.
|
---|
347 | *
|
---|
348 | *@@added V0.9.6 (2000-10-31) [umoeller]
|
---|
349 | */
|
---|
350 |
|
---|
351 | inline size_type capacity()
|
---|
352 | const
|
---|
353 | {
|
---|
354 | return ((_pBuf) ? (_pBuf->_str.cbAllocated) : 0);
|
---|
355 | }
|
---|
356 |
|
---|
357 | /*
|
---|
358 | *@@ operator():
|
---|
359 | * returns 1 (TRUE) if the string
|
---|
360 | * contains something, 0 (FALSE)
|
---|
361 | * otherwise.
|
---|
362 | *
|
---|
363 | * Note: as far as I know, this operator
|
---|
364 | * is NOT defined with the C++ string class.
|
---|
365 | */
|
---|
366 |
|
---|
367 | inline int operator()()
|
---|
368 | const
|
---|
369 | {
|
---|
370 | return (size() != 0);
|
---|
371 | }
|
---|
372 |
|
---|
373 | /*
|
---|
374 | *@@ empty:
|
---|
375 | * returns 1 (TRUE) if the string
|
---|
376 | * contains nothing, 0 (FALSE) otherwise.
|
---|
377 | */
|
---|
378 |
|
---|
379 | inline int empty()
|
---|
380 | const
|
---|
381 | {
|
---|
382 | return (size() == 0);
|
---|
383 | }
|
---|
384 |
|
---|
385 | /********************************************
|
---|
386 | *
|
---|
387 | * assignment, modification
|
---|
388 | *
|
---|
389 | ********************************************/
|
---|
390 |
|
---|
391 | void reserve(size_type stExtra = 0);
|
---|
392 |
|
---|
393 | void _take_from(XSTRING &str);
|
---|
394 |
|
---|
395 | size_type _printf(const char *pszFormatString, ...);
|
---|
396 |
|
---|
397 | void _itoa10(int value, char cThousands);
|
---|
398 |
|
---|
399 | BSStringBase& erase(size_type ulPos = 0, size_type n = npos);
|
---|
400 |
|
---|
401 | /********************************************
|
---|
402 | *
|
---|
403 | * comparison
|
---|
404 | *
|
---|
405 | ********************************************/
|
---|
406 |
|
---|
407 | protected:
|
---|
408 |
|
---|
409 | int compare(const BSStringBase &s) const;
|
---|
410 |
|
---|
411 | int compare(const char *psz) const;
|
---|
412 |
|
---|
413 | /********************************************
|
---|
414 | *
|
---|
415 | * find, replace
|
---|
416 | *
|
---|
417 | ********************************************/
|
---|
418 |
|
---|
419 | size_type _find_replace(BSStringBase &strFind,
|
---|
420 | const BSStringBase &strReplaceWith,
|
---|
421 | size_type *pulPos);
|
---|
422 |
|
---|
423 | size_type _find_replace(const char *pszFind,
|
---|
424 | const BSStringBase &strReplaceWith,
|
---|
425 | size_type *pulPos);
|
---|
426 |
|
---|
427 | public:
|
---|
428 |
|
---|
429 | size_type _find_replace(char cFind,
|
---|
430 | char cReplace,
|
---|
431 | size_type *pulPos);
|
---|
432 |
|
---|
433 | /********************************************
|
---|
434 | *
|
---|
435 | * misc
|
---|
436 | *
|
---|
437 | ********************************************/
|
---|
438 |
|
---|
439 | /*
|
---|
440 | *@@ swap:
|
---|
441 | * swaps the contents of this instance
|
---|
442 | * with that of another BSStringBase.
|
---|
443 | *
|
---|
444 | * This is very fast because only the
|
---|
445 | * pointers are exchanged.
|
---|
446 | *
|
---|
447 | *@@added V0.9.6 (2000-10-31) [umoeller]
|
---|
448 | */
|
---|
449 |
|
---|
450 | void swap(BSStringBase &str)
|
---|
451 | {
|
---|
452 | BSStringBuf *pBuf = str._pBuf;
|
---|
453 | str._pBuf = _pBuf;
|
---|
454 | _pBuf = pBuf;
|
---|
455 | }
|
---|
456 | };
|
---|
457 |
|
---|
458 | /*
|
---|
459 | *@@ BSString:
|
---|
460 | * string class vaguely modelled after the C++ ANSI
|
---|
461 | * string class which IBM VAC 3.08 has no support for.
|
---|
462 | *
|
---|
463 | * This implements the "BSString" class and typedefs "string"
|
---|
464 | * to "BSString". As a result, you can use either "BSString"
|
---|
465 | * or "string".
|
---|
466 | *
|
---|
467 | * <B>Introduction</B>
|
---|
468 | *
|
---|
469 | * If you're not familiar with the C++ "string" class, here's
|
---|
470 | * a short introduction.
|
---|
471 | *
|
---|
472 | * Basically, the "string" class allows you to use strings
|
---|
473 | * as a basic type, like int, char, long, and so on, without
|
---|
474 | * having to worry about memory management.
|
---|
475 | *
|
---|
476 | * Here is an example:
|
---|
477 | +
|
---|
478 | + string str = "Hello."
|
---|
479 | +
|
---|
480 | + if (str == "Hello")
|
---|
481 | + {
|
---|
482 | + string str = "We should say ";
|
---|
483 | + string str2 = str + "Hello now"
|
---|
484 | * str2 += '.';
|
---|
485 | +
|
---|
486 | + printf("%s", str2.c_str());
|
---|
487 | + }
|
---|
488 | *
|
---|
489 | * This shows some of the most convenient features of the
|
---|
490 | * string class:
|
---|
491 | *
|
---|
492 | * -- You can just create an instance of it on the stack.
|
---|
493 | * The destructor will automatically free the memory
|
---|
494 | * that has been allocated for the string -- no more
|
---|
495 | * memory leaks as with the C functions.
|
---|
496 | *
|
---|
497 | * -- You can compare strings using ==, !=, <, >. (This
|
---|
498 | * calls strcmp internally.)
|
---|
499 | *
|
---|
500 | * -- You can concatenate strings using the "+" operator.
|
---|
501 | *
|
---|
502 | * -- If you need a C-type string (e.g. for OS/2 API
|
---|
503 | * functions), use the BSString::c_str() method,
|
---|
504 | * which returns a "const char*" pointer to the string
|
---|
505 | * in the class.
|
---|
506 | *
|
---|
507 | * In addition, the string class has methods for more
|
---|
508 | * complicated things, such BSString::find and
|
---|
509 | * BSString::replace.
|
---|
510 | *
|
---|
511 | * Finally, this class is NOT thread-safe. If methods are
|
---|
512 | * operating on the same instance on several threads at
|
---|
513 | * the same time, this will DEFINITELY crash.
|
---|
514 | *
|
---|
515 | * <B>C++ ANSI "string" class compatibility</B>
|
---|
516 | *
|
---|
517 | * Unless marked otherwise, all methods and operators are
|
---|
518 | * compatible with the standard "string" class.
|
---|
519 | *
|
---|
520 | * However, we only support single-byte (8-bit) character
|
---|
521 | * sets at this point, and only a subset of the "string"
|
---|
522 | * methods and operators. But since WarpIN uses UTF-8
|
---|
523 | * for encoding things, this is not really a problem.
|
---|
524 | *
|
---|
525 | * Non-standard functions are marked with a leading
|
---|
526 | * underscore (e.g. BSString::_printf).
|
---|
527 | *
|
---|
528 | * <B>Changes</B>
|
---|
529 | *
|
---|
530 | * With V0.9.6, I have made improvements on memory management.
|
---|
531 | * Memory no longer gets reallocated with every change, but
|
---|
532 | * only if necessary.
|
---|
533 | *
|
---|
534 | * With V0.9.18, I finally implemented buffer sharing as
|
---|
535 | * with the C++ string class. This allows several BSString
|
---|
536 | * instances to share the same memory buffer. See BSStringBuf.
|
---|
537 | *
|
---|
538 | * In addition, V0.9.18 added Unicode support. See BSUString
|
---|
539 | * and BSUniCodec for more information.
|
---|
540 | *
|
---|
541 | * All the V0.9.18 changes are backward-compatible. So even
|
---|
542 | * though the implementation has changed significantly,
|
---|
543 | * all old code should still compile.
|
---|
544 | */
|
---|
545 |
|
---|
546 | class BSString : public BSStringBase
|
---|
547 | {
|
---|
548 | public:
|
---|
549 | DECLARE_CLASS(BSString);
|
---|
550 |
|
---|
551 | /*
|
---|
552 | *@@ BSString:
|
---|
553 | * default constructor to create an empty string.
|
---|
554 | */
|
---|
555 |
|
---|
556 | BSString()
|
---|
557 | : BSStringBase(tBSString)
|
---|
558 | {
|
---|
559 | }
|
---|
560 |
|
---|
561 | /*
|
---|
562 | *@@ BSString:
|
---|
563 | * default copy constructor;
|
---|
564 | * required for exception handling!
|
---|
565 | */
|
---|
566 |
|
---|
567 | BSString(const BSString &s)
|
---|
568 | : BSStringBase(s, tBSString)
|
---|
569 | {
|
---|
570 | }
|
---|
571 |
|
---|
572 | BSString(const BSString &s,
|
---|
573 | size_type ulPos,
|
---|
574 | size_type n = npos);
|
---|
575 | BSString(const char *psz);
|
---|
576 | BSString(const char *p1, const char *p2);
|
---|
577 | BSString(char c);
|
---|
578 |
|
---|
579 | BSString(BSUniCodec *pCodec,
|
---|
580 | const BSUString &ustr);
|
---|
581 |
|
---|
582 | /********************************************
|
---|
583 | *
|
---|
584 | * property queries
|
---|
585 | *
|
---|
586 | ********************************************/
|
---|
587 |
|
---|
588 | char operator[](const size_type ul) const;
|
---|
589 |
|
---|
590 | /*
|
---|
591 | *@@ c_str:
|
---|
592 | * returns the string member as a
|
---|
593 | * classic const C string. Note that
|
---|
594 | * this _never_ returns NULL. If the
|
---|
595 | * member string is empty, this
|
---|
596 | * returns a pointer to a null byte.
|
---|
597 | */
|
---|
598 |
|
---|
599 | inline const char* c_str()
|
---|
600 | const
|
---|
601 | {
|
---|
602 | return ((_pBuf && _pBuf->_str.psz) ? _pBuf->_str.psz : "");
|
---|
603 | }
|
---|
604 |
|
---|
605 | /********************************************
|
---|
606 | *
|
---|
607 | * assignment, modification
|
---|
608 | *
|
---|
609 | ********************************************/
|
---|
610 |
|
---|
611 | BSString& assign(const BSString &s);
|
---|
612 | BSString& assign(const BSString &s,
|
---|
613 | size_type ulPos,
|
---|
614 | size_type n = npos);
|
---|
615 | BSString& assign(const char *psz);
|
---|
616 | BSString& assign(const char *p1, const char *p2);
|
---|
617 | BSString& assign(char c);
|
---|
618 |
|
---|
619 | BSString& assignUtf8(BSUniCodec *pCodec,
|
---|
620 | const BSUString &ustr);
|
---|
621 |
|
---|
622 | /*
|
---|
623 | *@@ operator=:
|
---|
624 | *
|
---|
625 | */
|
---|
626 |
|
---|
627 | inline BSString& operator=(const BSString &s)
|
---|
628 | {
|
---|
629 | return (assign(s));
|
---|
630 | }
|
---|
631 |
|
---|
632 | /*
|
---|
633 | *@@ operator=:
|
---|
634 | *
|
---|
635 | */
|
---|
636 |
|
---|
637 | inline BSString& operator=(const char *psz)
|
---|
638 | {
|
---|
639 | return (assign(psz));
|
---|
640 | }
|
---|
641 |
|
---|
642 | /*
|
---|
643 | *@@ operator=:
|
---|
644 | *
|
---|
645 | */
|
---|
646 |
|
---|
647 | inline BSString& operator=(char c)
|
---|
648 | {
|
---|
649 | return (assign(c));
|
---|
650 | }
|
---|
651 |
|
---|
652 | BSString& append(const BSString &s);
|
---|
653 | BSString& append(const char *psz);
|
---|
654 | BSString& append(char c);
|
---|
655 |
|
---|
656 | BSString& appendUtf8(BSUniCodec *pCodec, const BSUString &s);
|
---|
657 |
|
---|
658 | /*
|
---|
659 | *@@ operator+=:
|
---|
660 | * shortcut to append(BSStringBase &s).
|
---|
661 | *
|
---|
662 | *@@changed V0.9.2 (2000-03-29) [umoeller]: added return *this
|
---|
663 | */
|
---|
664 |
|
---|
665 | inline BSString& operator+=(const BSString &s) // in: string to append
|
---|
666 | {
|
---|
667 | return (append(s));
|
---|
668 | }
|
---|
669 |
|
---|
670 | /*
|
---|
671 | *@@ operator+=:
|
---|
672 | * shortcut to append(const char *psz).
|
---|
673 | *
|
---|
674 | *@@changed V0.9.2 (2000-03-29) [umoeller]: added return *this
|
---|
675 | */
|
---|
676 |
|
---|
677 | inline BSString& operator+=(const char *psz) // in: string to append
|
---|
678 | {
|
---|
679 | return (append(psz));
|
---|
680 | }
|
---|
681 |
|
---|
682 | /*
|
---|
683 | *@@ operator+=:
|
---|
684 | * shortcut to append(char c).
|
---|
685 | *
|
---|
686 | *@@changed V0.9.2 (2000-03-29) [umoeller]: added return *this
|
---|
687 | */
|
---|
688 |
|
---|
689 | inline BSString& operator+=(char c) // in: character to append
|
---|
690 | {
|
---|
691 | return (append(c));
|
---|
692 | }
|
---|
693 |
|
---|
694 | /********************************************
|
---|
695 | *
|
---|
696 | * comparison
|
---|
697 | *
|
---|
698 | ********************************************/
|
---|
699 |
|
---|
700 | /*
|
---|
701 | *@@ compare:
|
---|
702 | *
|
---|
703 | */
|
---|
704 |
|
---|
705 | inline int compare(const BSString &s) const
|
---|
706 | {
|
---|
707 | return BSStringBase::compare(s);
|
---|
708 | }
|
---|
709 |
|
---|
710 | /*
|
---|
711 | *@@ compare:
|
---|
712 | *
|
---|
713 | */
|
---|
714 |
|
---|
715 | inline int compare(const char *psz) const
|
---|
716 | {
|
---|
717 | return BSStringBase::compare(psz);
|
---|
718 | }
|
---|
719 |
|
---|
720 | int compare(size_type ulPos, size_type n, const BSString &s) const;
|
---|
721 |
|
---|
722 | /********************************************
|
---|
723 | *
|
---|
724 | * find, replace
|
---|
725 | *
|
---|
726 | ********************************************/
|
---|
727 |
|
---|
728 | size_type find(const BSString &strFind, size_type ulPos = 0) const;
|
---|
729 | size_type find(const char *pszFind, size_type ulPos = 0) const;
|
---|
730 | size_type find(char c, size_type ulPos = 0) const;
|
---|
731 |
|
---|
732 | size_type rfind(char c, size_type ulPos = npos) const;
|
---|
733 |
|
---|
734 | size_type find_first_of(const char *achChars, size_type ulPos = 0) const;
|
---|
735 |
|
---|
736 | size_type find_first_not_of(char c, size_type ulPos = 0) const;
|
---|
737 | size_type find_first_not_of(const char *achChars, size_type ulPos = 0) const;
|
---|
738 |
|
---|
739 | BSString& replace(size_type ulPosThis,
|
---|
740 | size_type nThis,
|
---|
741 | const BSString &strReplace);
|
---|
742 |
|
---|
743 | /* BSString& replace(size_type ulPosThis,
|
---|
744 | size_type nThis,
|
---|
745 | const BSString &strReplace,
|
---|
746 | size_type ulPosReplace = 0,
|
---|
747 | size_type nReplace = npos);
|
---|
748 |
|
---|
749 | BSString& replace(size_type ulPosThis,
|
---|
750 | size_type nThis,
|
---|
751 | const char *pszReplace,
|
---|
752 | size_type nReplace);
|
---|
753 |
|
---|
754 | BSString& replace(size_type ulPosThis,
|
---|
755 | size_type nThis,
|
---|
756 | const char *pszReplace); */
|
---|
757 |
|
---|
758 | size_type _find_word(BSString &strFind,
|
---|
759 | size_type ulPos = 0,
|
---|
760 | const char *pcszBeginChars = "\x0d\x0a ()/\\-,.;*",
|
---|
761 | const char *pcszEndChars = "\x0d\x0a ()/\\-,.:;*&'")
|
---|
762 | const;
|
---|
763 |
|
---|
764 | size_type _find_word(const char *pszFind,
|
---|
765 | size_type ulPos = 0,
|
---|
766 | const char *pcszBeginChars = "\x0d\x0a ()/\\-,.;*",
|
---|
767 | const char *pcszEndChars = "\x0d\x0a ()/\\-,.:;*&'")
|
---|
768 | const;
|
---|
769 |
|
---|
770 | /*
|
---|
771 | *@@ _find_replace:
|
---|
772 | *
|
---|
773 | */
|
---|
774 |
|
---|
775 | inline size_type _find_replace(BSString &strFind,
|
---|
776 | const BSString &strReplaceWith,
|
---|
777 | size_type *pulPos)
|
---|
778 | {
|
---|
779 | return BSStringBase::_find_replace(strFind, strReplaceWith, pulPos);
|
---|
780 | }
|
---|
781 |
|
---|
782 | /*
|
---|
783 | *@@ _find_replace:
|
---|
784 | *
|
---|
785 | */
|
---|
786 |
|
---|
787 | inline size_type _find_replace(const char *pszFind,
|
---|
788 | const BSString &strReplaceWith,
|
---|
789 | size_type *pulPos)
|
---|
790 | {
|
---|
791 | return BSStringBase::_find_replace(pszFind, strReplaceWith, pulPos);
|
---|
792 | }
|
---|
793 |
|
---|
794 | /*
|
---|
795 | *@@ _find_replace:
|
---|
796 | *
|
---|
797 | */
|
---|
798 |
|
---|
799 | inline size_type _find_replace(char cFind,
|
---|
800 | char cReplace,
|
---|
801 | size_type *pulPos)
|
---|
802 | {
|
---|
803 | return BSStringBase::_find_replace(cFind, cReplace, pulPos);
|
---|
804 | }
|
---|
805 |
|
---|
806 | BSString substr(size_type ulPos = 0,
|
---|
807 | size_type n = npos)
|
---|
808 | const;
|
---|
809 |
|
---|
810 | int _extract_word(unsigned long ulIndex,
|
---|
811 | BSString &strTarget,
|
---|
812 | size_type ulPos = 0,
|
---|
813 | const char *pcszBeginChars = "\x0d\x0a ()/\\-,.;*",
|
---|
814 | const char *pcszEndChars = "\x0d\x0a ()/\\-,.:;*&'")
|
---|
815 | const;
|
---|
816 |
|
---|
817 | void _format();
|
---|
818 | };
|
---|
819 |
|
---|
820 | int operator==(const BSString &s1, const BSString &s2);
|
---|
821 |
|
---|
822 | int operator==(const char *psz1, const BSString &s2);
|
---|
823 |
|
---|
824 | int operator==(const BSString &s1, const char *psz2);
|
---|
825 |
|
---|
826 | int operator!=(const BSString &s1, const BSString &s2);
|
---|
827 |
|
---|
828 | int operator!=(const char *psz1, const BSString &s2);
|
---|
829 |
|
---|
830 | int operator!=(const BSString &s1, const char *psz2);
|
---|
831 |
|
---|
832 | int operator<(const BSString &s1, const BSString &s2);
|
---|
833 |
|
---|
834 | BSString operator+(const BSString &s1, const BSString &s2);
|
---|
835 |
|
---|
836 | BSString operator+(const char *psz1, const BSString &s2);
|
---|
837 |
|
---|
838 | BSString operator+(const BSString &s1, const char *psz2);
|
---|
839 |
|
---|
840 | /*
|
---|
841 | *@@ string:
|
---|
842 | * typedef for using BSStrings like the
|
---|
843 | * standard string class.
|
---|
844 | */
|
---|
845 |
|
---|
846 | typedef BSString string;
|
---|
847 |
|
---|
848 | /*
|
---|
849 | *@@ BSUString:
|
---|
850 | * unmodified BSString subclass for marking
|
---|
851 | * strings that are not plain ASCII, but UTF-8
|
---|
852 | * encoded. This is used in some declarations
|
---|
853 | * to make sure that interfaces can react
|
---|
854 | * properly.
|
---|
855 | *
|
---|
856 | * Most notably, this has restrictions on the
|
---|
857 | * assigment and conversion methods. In order
|
---|
858 | * to not accidentally assign codepage strings
|
---|
859 | * to a BSUString, regular assignments from
|
---|
860 | * const char * to BSUStrings are not allowed.
|
---|
861 | * Use BSUstring::assignUtf8 for this.
|
---|
862 | *
|
---|
863 | * In detail, the following things do not work:
|
---|
864 | *
|
---|
865 | * -- extracting substrings, because with UTF-8
|
---|
866 | * you can never be sure if an offset points
|
---|
867 | * into the middle of a multi-byte character;
|
---|
868 | *
|
---|
869 | * -- c_str() does not exist to avoid accidentally
|
---|
870 | * passing the member buffer to legacy APIs.
|
---|
871 | * Use BSUString::GetBuffer() instead.
|
---|
872 | *
|
---|
873 | * -- "=" assignments, "==" comparisons and "+"
|
---|
874 | * concatenation between BSString and BSUString.
|
---|
875 | * See BSUniCodec on how to convert BSString's
|
---|
876 | * to BSUString's and back.
|
---|
877 | *
|
---|
878 | * However, "==" between two BSUString's works.
|
---|
879 | *
|
---|
880 | *@@added V0.9.18 (2002-03-08) [umoeller]
|
---|
881 | */
|
---|
882 |
|
---|
883 | class BSUString : public BSStringBase
|
---|
884 | {
|
---|
885 | public:
|
---|
886 | DECLARE_CLASS(BSUString);
|
---|
887 |
|
---|
888 | /*
|
---|
889 | *@@ BSUString:
|
---|
890 | * default constructor to create an empty string.
|
---|
891 | */
|
---|
892 |
|
---|
893 | BSUString()
|
---|
894 | : BSStringBase(tBSUString)
|
---|
895 | {
|
---|
896 | }
|
---|
897 |
|
---|
898 | /*
|
---|
899 | *@@ BSUString:
|
---|
900 | * default copy constructor;
|
---|
901 | * required for exception handling!
|
---|
902 | */
|
---|
903 |
|
---|
904 | BSUString(const BSUString &s)
|
---|
905 | : BSStringBase(s, tBSUString)
|
---|
906 | {
|
---|
907 | }
|
---|
908 |
|
---|
909 | BSUString(BSUniCodec *pCodec,
|
---|
910 | const BSString &str);
|
---|
911 |
|
---|
912 | /********************************************
|
---|
913 | *
|
---|
914 | * property queries
|
---|
915 | *
|
---|
916 | ********************************************/
|
---|
917 |
|
---|
918 | char operator[](const size_type ul) const;
|
---|
919 |
|
---|
920 | /*
|
---|
921 | *@@ GetBuffer:
|
---|
922 | * like BSString::c_str(), but with
|
---|
923 | * a different name to make sure
|
---|
924 | * ustrings don't get passed to
|
---|
925 | * code which cannot handle that.
|
---|
926 | */
|
---|
927 |
|
---|
928 | inline const char* GetBuffer()
|
---|
929 | const
|
---|
930 | {
|
---|
931 | return ((_pBuf && _pBuf->_str.psz) ? _pBuf->_str.psz : "");
|
---|
932 | }
|
---|
933 |
|
---|
934 | /********************************************
|
---|
935 | *
|
---|
936 | * assignment, modification
|
---|
937 | *
|
---|
938 | ********************************************/
|
---|
939 |
|
---|
940 | BSUString& assign(const BSUString &s);
|
---|
941 | BSUString& assignUtf8(const char *psz);
|
---|
942 | BSUString& assignUtf8(const char *p1, const char *p2);
|
---|
943 | BSUString& assignCP(BSUniCodec *pCodec,
|
---|
944 | const BSString &str);
|
---|
945 | BSUString& assignCP(BSUniCodec *pCodec,
|
---|
946 | const char *psz);
|
---|
947 |
|
---|
948 | /*
|
---|
949 | *@@ operator=:
|
---|
950 | *
|
---|
951 | */
|
---|
952 |
|
---|
953 | inline BSUString& operator=(const BSUString &s)
|
---|
954 | {
|
---|
955 | return (assign(s));
|
---|
956 | }
|
---|
957 |
|
---|
958 | BSUString& append(const BSUString &s);
|
---|
959 | BSUString& appendUtf8(const char *psz);
|
---|
960 | BSUString& appendCP(BSUniCodec *pCodec,
|
---|
961 | const BSString &str);
|
---|
962 |
|
---|
963 | /*
|
---|
964 | *@@ operator+=:
|
---|
965 | * shortcut to append(BSUString &s).
|
---|
966 | *
|
---|
967 | */
|
---|
968 |
|
---|
969 | inline BSUString& operator+=(const BSUString &s) // in: string to append
|
---|
970 | {
|
---|
971 | return (append(s));
|
---|
972 | }
|
---|
973 |
|
---|
974 | /********************************************
|
---|
975 | *
|
---|
976 | * comparison
|
---|
977 | *
|
---|
978 | ********************************************/
|
---|
979 |
|
---|
980 | inline int compare(const BSUString &s) const
|
---|
981 | {
|
---|
982 | return BSStringBase::compare(s);
|
---|
983 | }
|
---|
984 |
|
---|
985 | inline int compareUtf8(const char *psz) const
|
---|
986 | {
|
---|
987 | return BSStringBase::compare(psz);
|
---|
988 | }
|
---|
989 |
|
---|
990 | int compareI(const BSUString &s) const;
|
---|
991 |
|
---|
992 | int compareUtf8I(const char *psz) const;
|
---|
993 |
|
---|
994 | /********************************************
|
---|
995 | *
|
---|
996 | * find, replace
|
---|
997 | *
|
---|
998 | ********************************************/
|
---|
999 |
|
---|
1000 | /*
|
---|
1001 | *@@ _find_replace:
|
---|
1002 | *
|
---|
1003 | */
|
---|
1004 |
|
---|
1005 | inline size_type _find_replace(BSUString &strFind,
|
---|
1006 | const BSUString &strReplaceWith,
|
---|
1007 | size_type *pulPos)
|
---|
1008 | {
|
---|
1009 | return BSStringBase::_find_replace(strFind, strReplaceWith, pulPos);
|
---|
1010 | }
|
---|
1011 |
|
---|
1012 | /*
|
---|
1013 | *@@ _find_replace:
|
---|
1014 | *
|
---|
1015 | */
|
---|
1016 |
|
---|
1017 | inline size_type _find_replace(const char *pszFind,
|
---|
1018 | const BSUString &strReplaceWith,
|
---|
1019 | size_type *pulPos)
|
---|
1020 | {
|
---|
1021 | return BSStringBase::_find_replace(pszFind, strReplaceWith, pulPos);
|
---|
1022 | }
|
---|
1023 |
|
---|
1024 | /*
|
---|
1025 | *@@ _find_replace:
|
---|
1026 | *
|
---|
1027 | */
|
---|
1028 |
|
---|
1029 | inline size_type _find_replace(char cFind,
|
---|
1030 | char cReplace,
|
---|
1031 | size_type *pulPos)
|
---|
1032 | {
|
---|
1033 | return BSStringBase::_find_replace(cFind, cReplace, pulPos);
|
---|
1034 | }
|
---|
1035 | };
|
---|
1036 |
|
---|
1037 | int operator==(const BSUString &s1, const BSUString &s2);
|
---|
1038 |
|
---|
1039 | int operator!=(const BSUString &s1, const BSUString &s2);
|
---|
1040 |
|
---|
1041 | BSUString operator+(const BSUString &s1, const BSUString &s2);
|
---|
1042 |
|
---|
1043 | /*
|
---|
1044 | *@@ ustring:
|
---|
1045 | *
|
---|
1046 | *@@added V0.9.18 (2002-03-08) [umoeller]
|
---|
1047 | */
|
---|
1048 |
|
---|
1049 | typedef BSUString ustring;
|
---|
1050 |
|
---|
1051 | #endif
|
---|
1052 |
|
---|