]> git.saurik.com Git - wxWidgets.git/blob - include/wx/string.h
some OS/2 updates
[wxWidgets.git] / include / wx / string.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: string.h
3 // Purpose: wxString and wxArrayString classes
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 29/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows license
10 ///////////////////////////////////////////////////////////////////////////////
11
12 /*
13 Efficient string class [more or less] compatible with MFC CString,
14 wxWindows version 1 wxString and std::string and some handy functions
15 missing from string.h.
16 */
17
18 #ifndef _WX_WXSTRINGH__
19 #define _WX_WXSTRINGH__
20
21 #ifdef __GNUG__
22 #pragma interface "string.h"
23 #endif
24
25 // ----------------------------------------------------------------------------
26 // conditinal compilation
27 // ----------------------------------------------------------------------------
28
29 // compile the std::string compatibility functions if defined
30 #define wxSTD_STRING_COMPATIBILITY
31
32 // ----------------------------------------------------------------------------
33 // headers
34 // ----------------------------------------------------------------------------
35
36 #include "wx/defs.h" // everybody should include this
37
38 #if defined(__WXMAC__) || defined(__VISAGECPP__)
39 #include <ctype.h>
40 #endif
41
42 #ifdef __EMX__
43 #include <std.h>
44 #endif
45
46 #if defined(__VISAGECPP__) && __IBMCPP__ >= 400
47 // problem in VACPP V4 with including stdlib.h multiple times
48 // strconv includes it anyway
49 # include <stdio.h>
50 # include <string.h>
51 # include <stdarg.h>
52 # include <limits.h>
53 #else
54 # include <string.h>
55 # include <stdio.h>
56 # include <stdarg.h>
57 # include <limits.h>
58 # include <stdlib.h>
59 #endif
60
61 #ifdef HAVE_STRINGS_H
62 #include <strings.h> // for strcasecmp()
63 #endif // HAVE_STRINGS_H
64
65 #include "wx/wxchar.h" // for wxChar
66 #include "wx/buffer.h" // for wxCharBuffer
67 #include "wx/strconv.h" // for wxConvertXXX() macros and wxMBConv classes
68
69 // ---------------------------------------------------------------------------
70 // macros
71 // ---------------------------------------------------------------------------
72
73 // casts [unfortunately!] needed to call some broken functions which require
74 // "char *" instead of "const char *"
75 #define WXSTRINGCAST (wxChar *)(const wxChar *)
76 #define wxCSTRINGCAST (wxChar *)(const wxChar *)
77 #define wxMBSTRINGCAST (char *)(const char *)
78 #define wxWCSTRINGCAST (wchar_t *)(const wchar_t *)
79
80 // implementation only
81 #define wxASSERT_VALID_INDEX(i) \
82 wxASSERT_MSG( (size_t)(i) <= Len(), _T("invalid index in wxString") )
83
84 // ----------------------------------------------------------------------------
85 // constants
86 // ----------------------------------------------------------------------------
87
88 #if defined(__VISAGECPP__) && __IBMCPP__ >= 400
89 // must define this static for VA or else you get multiply defined symbols everywhere
90 extern const unsigned int wxSTRING_MAXLEN;
91
92 #else
93 // maximum possible length for a string means "take all string" everywhere
94 // (as sizeof(StringData) is unknown here, we substract 100)
95 const unsigned int wxSTRING_MAXLEN = UINT_MAX - 100;
96
97 #endif
98
99 // ----------------------------------------------------------------------------
100 // global data
101 // ----------------------------------------------------------------------------
102
103 // global pointer to empty string
104 WXDLLEXPORT_DATA(extern const wxChar*) wxEmptyString;
105
106 // ---------------------------------------------------------------------------
107 // global functions complementing standard C string library replacements for
108 // strlen() and portable strcasecmp()
109 //---------------------------------------------------------------------------
110
111 // Use wxXXX() functions from wxchar.h instead! These functions are for
112 // backwards compatibility only.
113
114 // checks whether the passed in pointer is NULL and if the string is empty
115 inline bool IsEmpty(const char *p) { return (!p || !*p); }
116
117 // safe version of strlen() (returns 0 if passed NULL pointer)
118 inline size_t Strlen(const char *psz)
119 { return psz ? strlen(psz) : 0; }
120
121 // portable strcasecmp/_stricmp
122 inline int Stricmp(const char *psz1, const char *psz2)
123 {
124 #if defined(__VISUALC__) || ( defined(__MWERKS__) && defined(__INTEL__) )
125 return _stricmp(psz1, psz2);
126 #elif defined(__SC__)
127 return _stricmp(psz1, psz2);
128 #elif defined(__SALFORDC__)
129 return stricmp(psz1, psz2);
130 #elif defined(__BORLANDC__)
131 return stricmp(psz1, psz2);
132 #elif defined(__WATCOMC__)
133 return stricmp(psz1, psz2);
134 #elif defined(__DJGPP__)
135 return stricmp(psz1, psz2);
136 #elif defined(__EMX__)
137 return stricmp(psz1, psz2);
138 #elif defined(__WXPM__)
139 return stricmp(psz1, psz2);
140 #elif defined(__UNIX__) || defined(__GNUWIN32__)
141 return strcasecmp(psz1, psz2);
142 #elif defined(__MWERKS__) && !defined(__INTEL__)
143 register char c1, c2;
144 do {
145 c1 = tolower(*psz1++);
146 c2 = tolower(*psz2++);
147 } while ( c1 && (c1 == c2) );
148
149 return c1 - c2;
150 #else
151 // almost all compilers/libraries provide this function (unfortunately under
152 // different names), that's why we don't implement our own which will surely
153 // be more efficient than this code (uncomment to use):
154 /*
155 register char c1, c2;
156 do {
157 c1 = tolower(*psz1++);
158 c2 = tolower(*psz2++);
159 } while ( c1 && (c1 == c2) );
160
161 return c1 - c2;
162 */
163
164 #error "Please define string case-insensitive compare for your OS/compiler"
165 #endif // OS/compiler
166 }
167
168 // return an empty wxString
169 class WXDLLEXPORT wxString; // not yet defined
170 inline const wxString& wxGetEmptyString() { return *(wxString *)&wxEmptyString; }
171
172 // ---------------------------------------------------------------------------
173 // string data prepended with some housekeeping info (used by wxString class),
174 // is never used directly (but had to be put here to allow inlining)
175 // ---------------------------------------------------------------------------
176
177 struct WXDLLEXPORT wxStringData
178 {
179 int nRefs; // reference count
180 size_t nDataLength, // actual string length
181 nAllocLength; // allocated memory size
182
183 // mimics declaration 'wxChar data[nAllocLength]'
184 wxChar* data() const { return (wxChar*)(this + 1); }
185
186 // empty string has a special ref count so it's never deleted
187 bool IsEmpty() const { return (nRefs == -1); }
188 bool IsShared() const { return (nRefs > 1); }
189
190 // lock/unlock
191 void Lock() { if ( !IsEmpty() ) nRefs++; }
192
193 // VC++ will refuse to inline this function but profiling shows that it
194 // is wrong
195 #if defined(__VISUALC__) && (__VISUALC__ >= 1200)
196 __forceinline
197 #endif
198 void Unlock() { if ( !IsEmpty() && --nRefs == 0) free(this); }
199
200 // if we had taken control over string memory (GetWriteBuf), it's
201 // intentionally put in invalid state
202 void Validate(bool b) { nRefs = (b ? 1 : 0); }
203 bool IsValid() const { return (nRefs != 0); }
204 };
205
206 // ---------------------------------------------------------------------------
207 // This is (yet another one) String class for C++ programmers. It doesn't use
208 // any of "advanced" C++ features (i.e. templates, exceptions, namespaces...)
209 // thus you should be able to compile it with practicaly any C++ compiler.
210 // This class uses copy-on-write technique, i.e. identical strings share the
211 // same memory as long as neither of them is changed.
212 //
213 // This class aims to be as compatible as possible with the new standard
214 // std::string class, but adds some additional functions and should be at
215 // least as efficient than the standard implementation.
216 //
217 // Performance note: it's more efficient to write functions which take "const
218 // String&" arguments than "const char *" if you assign the argument to
219 // another string.
220 //
221 // It was compiled and tested under Win32, Linux (libc 5 & 6), Solaris 5.5.
222 //
223 // To do:
224 // - ressource support (string tables in ressources)
225 // - more wide character (UNICODE) support
226 // - regular expressions support
227 // ---------------------------------------------------------------------------
228
229 class WXDLLEXPORT wxString
230 {
231 friend class WXDLLEXPORT wxArrayString;
232
233 // NB: special care was taken in arranging the member functions in such order
234 // that all inline functions can be effectively inlined, verify that all
235 // performace critical functions are still inlined if you change order!
236 private:
237 // points to data preceded by wxStringData structure with ref count info
238 wxChar *m_pchData;
239
240 // accessor to string data
241 wxStringData* GetStringData() const { return (wxStringData*)m_pchData - 1; }
242
243 // string (re)initialization functions
244 // initializes the string to the empty value (must be called only from
245 // ctors, use Reinit() otherwise)
246 void Init() { m_pchData = (wxChar *)wxEmptyString; }
247 // initializaes the string with (a part of) C-string
248 void InitWith(const wxChar *psz, size_t nPos = 0, size_t nLen = wxSTRING_MAXLEN);
249 // as Init, but also frees old data
250 void Reinit() { GetStringData()->Unlock(); Init(); }
251
252 // memory allocation
253 // allocates memory for string of length nLen
254 bool AllocBuffer(size_t nLen);
255 // copies data to another string
256 bool AllocCopy(wxString&, int, int) const;
257 // effectively copies data to string
258 bool AssignCopy(size_t, const wxChar *);
259
260 // append a (sub)string
261 bool ConcatSelf(int nLen, const wxChar *src);
262
263 // functions called before writing to the string: they copy it if there
264 // are other references to our data (should be the only owner when writing)
265 bool CopyBeforeWrite();
266 bool AllocBeforeWrite(size_t);
267
268 // if we hadn't made these operators private, it would be possible to
269 // compile "wxString s; s = 17;" without any warnings as 17 is implicitly
270 // converted to char in C and we do have operator=(char)
271 //
272 // NB: we don't need other versions (short/long and unsigned) as attempt
273 // to assign another numeric type to wxString will now result in
274 // ambiguity between operator=(char) and operator=(int)
275 wxString& operator=(int);
276
277 // these methods are not implemented - there is _no_ conversion from int to
278 // string, you're doing something wrong if the compiler wants to call it!
279 //
280 // try `s << i' or `s.Printf("%d", i)' instead
281 wxString(int);
282
283 public:
284 // constructors and destructor
285 // ctor for an empty string
286 wxString() : m_pchData(NULL) { Init(); }
287 // copy ctor
288 wxString(const wxString& stringSrc) : m_pchData(NULL)
289 {
290 wxASSERT_MSG( stringSrc.GetStringData()->IsValid(),
291 _T("did you forget to call UngetWriteBuf()?") );
292
293 if ( stringSrc.IsEmpty() ) {
294 // nothing to do for an empty string
295 Init();
296 }
297 else {
298 m_pchData = stringSrc.m_pchData; // share same data
299 GetStringData()->Lock(); // => one more copy
300 }
301 }
302 // string containing nRepeat copies of ch
303 wxString(wxChar ch, size_t nRepeat = 1);
304 // ctor takes first nLength characters from C string
305 // (default value of wxSTRING_MAXLEN means take all the string)
306 wxString(const wxChar *psz, size_t nLength = wxSTRING_MAXLEN)
307 : m_pchData(NULL)
308 { InitWith(psz, 0, nLength); }
309 wxString(const wxChar *psz, wxMBConv& WXUNUSED(conv), size_t nLength = wxSTRING_MAXLEN)
310 : m_pchData(NULL)
311 { InitWith(psz, 0, nLength); }
312
313 #if wxUSE_UNICODE
314 // from multibyte string
315 // (NB: nLength is right now number of Unicode characters, not
316 // characters in psz! So try not to use it yet!)
317 wxString(const char *psz, wxMBConv& conv = wxConvLibc, size_t nLength = wxSTRING_MAXLEN);
318 // from wxWCharBuffer (i.e. return from wxGetString)
319 wxString(const wxWCharBuffer& psz)
320 { InitWith(psz, 0, wxSTRING_MAXLEN); }
321 #else // ANSI
322 // from C string (for compilers using unsigned char)
323 wxString(const unsigned char* psz, size_t nLength = wxSTRING_MAXLEN)
324 : m_pchData(NULL)
325 { InitWith((const char*)psz, 0, nLength); }
326
327 #if wxUSE_WCHAR_T
328 // from wide (Unicode) string
329 wxString(const wchar_t *pwz, wxMBConv& conv = wxConvLibc, size_t nLength = wxSTRING_MAXLEN);
330 #endif // !wxUSE_WCHAR_T
331
332 // from wxCharBuffer
333 wxString(const wxCharBuffer& psz)
334 : m_pchData(NULL)
335 { InitWith(psz, 0, wxSTRING_MAXLEN); }
336 #endif // Unicode/ANSI
337
338 // dtor is not virtual, this class must not be inherited from!
339 ~wxString() { GetStringData()->Unlock(); }
340
341 // generic attributes & operations
342 // as standard strlen()
343 size_t Len() const { return GetStringData()->nDataLength; }
344 // string contains any characters?
345 bool IsEmpty() const { return Len() == 0; }
346 // empty string is "FALSE", so !str will return TRUE
347 bool operator!() const { return IsEmpty(); }
348 // truncate the string to given length
349 wxString& Truncate(size_t uiLen);
350 // empty string contents
351 void Empty()
352 {
353 Truncate(0);
354
355 wxASSERT_MSG( IsEmpty(), _T("string not empty after call to Empty()?") );
356 }
357 // empty the string and free memory
358 void Clear()
359 {
360 if ( !GetStringData()->IsEmpty() )
361 Reinit();
362
363 wxASSERT_MSG( !GetStringData()->nDataLength &&
364 !GetStringData()->nAllocLength,
365 _T("string should be empty after Clear()") );
366 }
367
368 // contents test
369 // Is an ascii value
370 bool IsAscii() const;
371 // Is a number
372 bool IsNumber() const;
373 // Is a word
374 bool IsWord() const;
375
376 // data access (all indexes are 0 based)
377 // read access
378 wxChar GetChar(size_t n) const
379 { wxASSERT_VALID_INDEX( n ); return m_pchData[n]; }
380 // read/write access
381 wxChar& GetWritableChar(size_t n)
382 { wxASSERT_VALID_INDEX( n ); CopyBeforeWrite(); return m_pchData[n]; }
383 // write access
384 void SetChar(size_t n, wxChar ch)
385 { wxASSERT_VALID_INDEX( n ); CopyBeforeWrite(); m_pchData[n] = ch; }
386
387 // get last character
388 wxChar Last() const
389 {
390 wxASSERT_MSG( !IsEmpty(), _T("wxString: index out of bounds") );
391
392 return m_pchData[Len() - 1];
393 }
394
395 // get writable last character
396 wxChar& Last()
397 {
398 wxASSERT_MSG( !IsEmpty(), _T("wxString: index out of bounds") );
399 CopyBeforeWrite();
400 return m_pchData[Len()-1];
401 }
402
403 /*
404 So why do we have all these overloaded operator[]s? A bit of history:
405 initially there was only one of them, taking size_t. Then people
406 started complaining because they wanted to use ints as indices (I
407 wonder why) and compilers were giving warnings about it, so we had to
408 add the operator[](int). Then it became apparent that you couldn't
409 write str[0] any longer because there was ambiguity between two
410 overloads and so you now had to write str[0u] (or, of course, use the
411 explicit casts to either int or size_t but nobody did this).
412
413 Finally, someone decided to compile wxWin on an Alpha machine and got
414 a surprize: str[0u] didn't compile there because it is of type
415 unsigned int and size_t is unsigned _long_ on Alpha and so there was
416 ambiguity between converting uint to int or ulong. To fix this one we
417 now add operator[](uint) for the machines where size_t is not already
418 the same as unsigned int - hopefully this fixes the problem (for some
419 time)
420
421 The only real fix is, of course, to remove all versions but the one
422 taking size_t...
423 */
424
425 // operator version of GetChar
426 wxChar operator[](size_t n) const
427 { wxASSERT_VALID_INDEX( n ); return m_pchData[n]; }
428
429 // operator version of GetChar
430 wxChar operator[](int n) const
431 { wxASSERT_VALID_INDEX( n ); return m_pchData[n]; }
432
433 // operator version of GetWriteableChar
434 wxChar& operator[](size_t n)
435 { wxASSERT_VALID_INDEX( n ); CopyBeforeWrite(); return m_pchData[n]; }
436
437 #ifndef wxSIZE_T_IS_UINT
438 // operator version of GetChar
439 wxChar operator[](unsigned int n) const
440 { wxASSERT_VALID_INDEX( n ); return m_pchData[n]; }
441
442 // operator version of GetWriteableChar
443 wxChar& operator[](unsigned int n)
444 { wxASSERT_VALID_INDEX( n ); CopyBeforeWrite(); return m_pchData[n]; }
445 #endif // size_t != unsigned int
446
447 // implicit conversion to C string
448 operator const wxChar*() const { return m_pchData; }
449 // explicit conversion to C string (use this with printf()!)
450 const wxChar* c_str() const { return m_pchData; }
451 // identical to c_str()
452 const wxChar* wx_str() const { return m_pchData; }
453 // identical to c_str()
454 const wxChar* GetData() const { return m_pchData; }
455
456 // conversion to plain ascii: this is usefull for
457 // converting numbers or strings which are certain
458 // not to contain special chars (typically system
459 // functions, X atoms, environment variables etc.)
460 #if wxUSE_UNICODE
461 static wxString FromAscii( char *ascii );
462 const wxCharBuffer ToAscii() const;
463 #else
464 static wxString FromAscii( char *ascii ) { return wxString( ascii ); }
465 const char *ToAscii() const { return m_pchData; }
466 #endif
467
468 // conversions with (possible) format convertions: have to return a
469 // buffer with temporary data
470 //
471 // the functions defined (in either Unicode or ANSI) mode are mb_str() to
472 // return an ANSI (multibyte) string, wc_str() to return a wide string and
473 // fn_str() to return a string which should be used with the OS APIs
474 // accepting the file names. The return value is always the same, but the
475 // type differs because a function may either return pointer to the buffer
476 // directly or have to use intermediate buffer for translation.
477 #if wxUSE_UNICODE
478 const wxCharBuffer mb_str(wxMBConv& conv = wxConvLibc) const
479 { return conv.cWC2MB(m_pchData); }
480
481 const wxWX2MBbuf mbc_str() const { return mb_str(*wxConvCurrent); }
482
483 const wxChar* wc_str() const { return m_pchData; }
484
485 // for compatibility with !wxUSE_UNICODE version
486 const wxChar* wc_str(wxMBConv& WXUNUSED(conv)) const { return m_pchData; }
487
488 #if wxMBFILES
489 const wxCharBuffer fn_str() const { return mb_str(wxConvFile); }
490 #else // !wxMBFILES
491 const wxChar* fn_str() const { return m_pchData; }
492 #endif // wxMBFILES/!wxMBFILES
493 #else // ANSI
494 const wxChar* mb_str() const { return m_pchData; }
495
496 // for compatibility with wxUSE_UNICODE version
497 const wxChar* mb_str(wxMBConv& WXUNUSED(conv)) const { return m_pchData; }
498
499 const wxWX2MBbuf mbc_str() const { return mb_str(); }
500
501 #if wxUSE_WCHAR_T
502 const wxWCharBuffer wc_str(wxMBConv& conv) const
503 { return conv.cMB2WC(m_pchData); }
504 #endif // wxUSE_WCHAR_T
505
506 const wxChar* fn_str() const { return m_pchData; }
507 #endif // Unicode/ANSI
508
509 // overloaded assignment
510 // from another wxString
511 wxString& operator=(const wxString& stringSrc);
512 // from a character
513 wxString& operator=(wxChar ch);
514 // from a C string
515 wxString& operator=(const wxChar *psz);
516 #if wxUSE_UNICODE
517 // from wxWCharBuffer
518 wxString& operator=(const wxWCharBuffer& psz)
519 { (void) operator=((const wchar_t *)psz); return *this; }
520 #else // ANSI
521 // from another kind of C string
522 wxString& operator=(const unsigned char* psz);
523 #if wxUSE_WCHAR_T
524 // from a wide string
525 wxString& operator=(const wchar_t *pwz);
526 #endif
527 // from wxCharBuffer
528 wxString& operator=(const wxCharBuffer& psz)
529 { (void) operator=((const char *)psz); return *this; }
530 #endif // Unicode/ANSI
531
532 // string concatenation
533 // in place concatenation
534 /*
535 Concatenate and return the result. Note that the left to right
536 associativity of << allows to write things like "str << str1 << str2
537 << ..." (unlike with +=)
538 */
539 // string += string
540 wxString& operator<<(const wxString& s)
541 {
542 wxASSERT_MSG( s.GetStringData()->IsValid(),
543 _T("did you forget to call UngetWriteBuf()?") );
544
545 ConcatSelf(s.Len(), s);
546 return *this;
547 }
548 // string += C string
549 wxString& operator<<(const wxChar *psz)
550 { ConcatSelf(wxStrlen(psz), psz); return *this; }
551 // string += char
552 wxString& operator<<(wxChar ch) { ConcatSelf(1, &ch); return *this; }
553
554 // string += string
555 void operator+=(const wxString& s) { (void)operator<<(s); }
556 // string += C string
557 void operator+=(const wxChar *psz) { (void)operator<<(psz); }
558 // string += char
559 void operator+=(wxChar ch) { (void)operator<<(ch); }
560
561 // string += buffer (i.e. from wxGetString)
562 #if wxUSE_UNICODE
563 wxString& operator<<(const wxWCharBuffer& s)
564 { (void)operator<<((const wchar_t *)s); return *this; }
565 void operator+=(const wxWCharBuffer& s)
566 { (void)operator<<((const wchar_t *)s); }
567 #else // !wxUSE_UNICODE
568 wxString& operator<<(const wxCharBuffer& s)
569 { (void)operator<<((const char *)s); return *this; }
570 void operator+=(const wxCharBuffer& s)
571 { (void)operator<<((const char *)s); }
572 #endif // wxUSE_UNICODE/!wxUSE_UNICODE
573
574 // string += C string
575 wxString& Append(const wxString& s)
576 {
577 // test for IsEmpty() to share the string if possible
578 if ( IsEmpty() )
579 *this = s;
580 else
581 ConcatSelf(s.Length(), s.c_str());
582 return *this;
583 }
584 wxString& Append(const wxChar* psz)
585 { ConcatSelf(wxStrlen(psz), psz); return *this; }
586 // append count copies of given character
587 wxString& Append(wxChar ch, size_t count = 1u)
588 { wxString str(ch, count); return *this << str; }
589 wxString& Append(const wxChar* psz, size_t nLen)
590 { ConcatSelf(nLen, psz); return *this; }
591
592 // prepend a string, return the string itself
593 wxString& Prepend(const wxString& str)
594 { *this = str + *this; return *this; }
595
596 // non-destructive concatenation
597 //
598 friend wxString WXDLLEXPORT operator+(const wxString& string1, const wxString& string2);
599 //
600 friend wxString WXDLLEXPORT operator+(const wxString& string, wxChar ch);
601 //
602 friend wxString WXDLLEXPORT operator+(wxChar ch, const wxString& string);
603 //
604 friend wxString WXDLLEXPORT operator+(const wxString& string, const wxChar *psz);
605 //
606 friend wxString WXDLLEXPORT operator+(const wxChar *psz, const wxString& string);
607
608 // stream-like functions
609 // insert an int into string
610 wxString& operator<<(int i)
611 { return (*this) << Format(_T("%d"), i); }
612 // insert an unsigned int into string
613 wxString& operator<<(unsigned int ui)
614 { return (*this) << Format(_T("%u"), ui); }
615 // insert a long into string
616 wxString& operator<<(long l)
617 { return (*this) << Format(_T("%ld"), l); }
618 // insert an unsigned long into string
619 wxString& operator<<(unsigned long ul)
620 { return (*this) << Format(_T("%lu"), ul); }
621 // insert a float into string
622 wxString& operator<<(float f)
623 { return (*this) << Format(_T("%f"), f); }
624 // insert a double into string
625 wxString& operator<<(double d)
626 { return (*this) << Format(_T("%g"), d); }
627
628 // string comparison
629 // case-sensitive comparison (returns a value < 0, = 0 or > 0)
630 int Cmp(const wxChar *psz) const { return wxStrcmp(c_str(), psz); }
631 // same as Cmp() but not case-sensitive
632 int CmpNoCase(const wxChar *psz) const { return wxStricmp(c_str(), psz); }
633 // test for the string equality, either considering case or not
634 // (if compareWithCase then the case matters)
635 bool IsSameAs(const wxChar *psz, bool compareWithCase = TRUE) const
636 { return (compareWithCase ? Cmp(psz) : CmpNoCase(psz)) == 0; }
637 // comparison with a signle character: returns TRUE if equal
638 bool IsSameAs(wxChar c, bool compareWithCase = TRUE) const
639 {
640 return (Len() == 1) && (compareWithCase ? GetChar(0u) == c
641 : wxToupper(GetChar(0u)) == wxToupper(c));
642 }
643
644 // simple sub-string extraction
645 // return substring starting at nFirst of length nCount (or till the end
646 // if nCount = default value)
647 wxString Mid(size_t nFirst, size_t nCount = wxSTRING_MAXLEN) const;
648
649 // operator version of Mid()
650 wxString operator()(size_t start, size_t len) const
651 { return Mid(start, len); }
652
653 // check that the string starts with prefix and return the rest of the
654 // string in the provided pointer if it is not NULL, otherwise return
655 // FALSE
656 bool StartsWith(const wxChar *prefix, wxString *rest = NULL) const;
657
658 // get first nCount characters
659 wxString Left(size_t nCount) const;
660 // get last nCount characters
661 wxString Right(size_t nCount) const;
662 // get all characters before the first occurance of ch
663 // (returns the whole string if ch not found)
664 wxString BeforeFirst(wxChar ch) const;
665 // get all characters before the last occurence of ch
666 // (returns empty string if ch not found)
667 wxString BeforeLast(wxChar ch) const;
668 // get all characters after the first occurence of ch
669 // (returns empty string if ch not found)
670 wxString AfterFirst(wxChar ch) const;
671 // get all characters after the last occurence of ch
672 // (returns the whole string if ch not found)
673 wxString AfterLast(wxChar ch) const;
674
675 // for compatibility only, use more explicitly named functions above
676 wxString Before(wxChar ch) const { return BeforeLast(ch); }
677 wxString After(wxChar ch) const { return AfterFirst(ch); }
678
679 // case conversion
680 // convert to upper case in place, return the string itself
681 wxString& MakeUpper();
682 // convert to upper case, return the copy of the string
683 // Here's something to remember: BC++ doesn't like returns in inlines.
684 wxString Upper() const ;
685 // convert to lower case in place, return the string itself
686 wxString& MakeLower();
687 // convert to lower case, return the copy of the string
688 wxString Lower() const ;
689
690 // trimming/padding whitespace (either side) and truncating
691 // remove spaces from left or from right (default) side
692 wxString& Trim(bool bFromRight = TRUE);
693 // add nCount copies chPad in the beginning or at the end (default)
694 wxString& Pad(size_t nCount, wxChar chPad = wxT(' '), bool bFromRight = TRUE);
695
696 // searching and replacing
697 // searching (return starting index, or -1 if not found)
698 int Find(wxChar ch, bool bFromEnd = FALSE) const; // like strchr/strrchr
699 // searching (return starting index, or -1 if not found)
700 int Find(const wxChar *pszSub) const; // like strstr
701 // replace first (or all of bReplaceAll) occurences of substring with
702 // another string, returns the number of replacements made
703 size_t Replace(const wxChar *szOld,
704 const wxChar *szNew,
705 bool bReplaceAll = TRUE);
706
707 // check if the string contents matches a mask containing '*' and '?'
708 bool Matches(const wxChar *szMask) const;
709
710 // conversion to numbers: all functions return TRUE only if the whole
711 // string is a number and put the value of this number into the pointer
712 // provided, the base is the numeric base in which the conversion should be
713 // done and must be comprised between 2 and 36 or be 0 in which case the
714 // standard C rules apply (leading '0' => octal, "0x" => hex)
715 // convert to a signed integer
716 bool ToLong(long *val, int base = 10) const;
717 // convert to an unsigned integer
718 bool ToULong(unsigned long *val, int base = 10) const;
719 // convert to a double
720 bool ToDouble(double *val) const;
721
722 // formated input/output
723 // as sprintf(), returns the number of characters written or < 0 on error
724 // (take 'this' into account in attribute parameter count)
725 int Printf(const wxChar *pszFormat, ...) ATTRIBUTE_PRINTF_2;
726 // as vprintf(), returns the number of characters written or < 0 on error
727 int PrintfV(const wxChar* pszFormat, va_list argptr);
728
729 // returns the string containing the result of Printf() to it
730 static wxString Format(const wxChar *pszFormat, ...) ATTRIBUTE_PRINTF_1;
731 // the same as above, but takes a va_list
732 static wxString FormatV(const wxChar *pszFormat, va_list argptr);
733
734 // raw access to string memory
735 // ensure that string has space for at least nLen characters
736 // only works if the data of this string is not shared
737 bool Alloc(size_t nLen);
738 // minimize the string's memory
739 // only works if the data of this string is not shared
740 bool Shrink();
741 // get writable buffer of at least nLen bytes. Unget() *must* be called
742 // a.s.a.p. to put string back in a reasonable state!
743 wxChar *GetWriteBuf(size_t nLen);
744 // call this immediately after GetWriteBuf() has been used
745 void UngetWriteBuf();
746 void UngetWriteBuf(size_t nLen);
747
748 // wxWindows version 1 compatibility functions
749
750 // use Mid()
751 wxString SubString(size_t from, size_t to) const
752 { return Mid(from, (to - from + 1)); }
753 // values for second parameter of CompareTo function
754 enum caseCompare {exact, ignoreCase};
755 // values for first parameter of Strip function
756 enum stripType {leading = 0x1, trailing = 0x2, both = 0x3};
757
758 // use Printf()
759 // (take 'this' into account in attribute parameter count)
760 int sprintf(const wxChar *pszFormat, ...) ATTRIBUTE_PRINTF_2;
761
762 // use Cmp()
763 inline int CompareTo(const wxChar* psz, caseCompare cmp = exact) const
764 { return cmp == exact ? Cmp(psz) : CmpNoCase(psz); }
765
766 // use Len
767 size_t Length() const { return Len(); }
768 // Count the number of characters
769 int Freq(wxChar ch) const;
770 // use MakeLower
771 void LowerCase() { MakeLower(); }
772 // use MakeUpper
773 void UpperCase() { MakeUpper(); }
774 // use Trim except that it doesn't change this string
775 wxString Strip(stripType w = trailing) const;
776
777 // use Find (more general variants not yet supported)
778 size_t Index(const wxChar* psz) const { return Find(psz); }
779 size_t Index(wxChar ch) const { return Find(ch); }
780 // use Truncate
781 wxString& Remove(size_t pos) { return Truncate(pos); }
782 wxString& RemoveLast(size_t n = 1) { return Truncate(Len() - n); }
783
784 wxString& Remove(size_t nStart, size_t nLen) { return erase( nStart, nLen ); }
785
786 // use Find()
787 int First( const wxChar ch ) const { return Find(ch); }
788 int First( const wxChar* psz ) const { return Find(psz); }
789 int First( const wxString &str ) const { return Find(str); }
790 int Last( const wxChar ch ) const { return Find(ch, TRUE); }
791 bool Contains(const wxString& str) const { return Find(str) != -1; }
792
793 // use IsEmpty()
794 bool IsNull() const { return IsEmpty(); }
795
796 #ifdef wxSTD_STRING_COMPATIBILITY
797 // std::string compatibility functions
798
799 // standard types
800 typedef wxChar value_type;
801 typedef const value_type *const_iterator;
802
803 // an 'invalid' value for string index
804 static const size_t npos;
805
806 // constructors
807 // take nLen chars starting at nPos
808 wxString(const wxString& str, size_t nPos, size_t nLen)
809 : m_pchData(NULL)
810 {
811 wxASSERT_MSG( str.GetStringData()->IsValid(),
812 _T("did you forget to call UngetWriteBuf()?") );
813
814 InitWith(str.c_str(), nPos, nLen == npos ? 0 : nLen);
815 }
816 // take all characters from pStart to pEnd
817 wxString(const void *pStart, const void *pEnd);
818
819 // lib.string.capacity
820 // return the length of the string
821 size_t size() const { return Len(); }
822 // return the length of the string
823 size_t length() const { return Len(); }
824 // return the maximum size of the string
825 size_t max_size() const { return wxSTRING_MAXLEN; }
826 // resize the string, filling the space with c if c != 0
827 void resize(size_t nSize, wxChar ch = wxT('\0'));
828 // delete the contents of the string
829 void clear() { Empty(); }
830 // returns true if the string is empty
831 bool empty() const { return IsEmpty(); }
832 // inform string about planned change in size
833 void reserve(size_t size) { Alloc(size); }
834
835 // lib.string.access
836 // return the character at position n
837 wxChar at(size_t n) const { return GetChar(n); }
838 // returns the writable character at position n
839 wxChar& at(size_t n) { return GetWritableChar(n); }
840
841 // first valid index position
842 const_iterator begin() const { return wx_str(); }
843 // position one after the last valid one
844 const_iterator end() const { return wx_str() + length(); }
845
846 // lib.string.modifiers
847 // append a string
848 wxString& append(const wxString& str)
849 { *this += str; return *this; }
850 // append elements str[pos], ..., str[pos+n]
851 wxString& append(const wxString& str, size_t pos, size_t n)
852 { ConcatSelf(n, str.c_str() + pos); return *this; }
853 // append first n (or all if n == npos) characters of sz
854 wxString& append(const wxChar *sz, size_t n = npos)
855 { ConcatSelf(n == npos ? wxStrlen(sz) : n, sz); return *this; }
856
857 // append n copies of ch
858 wxString& append(size_t n, wxChar ch) { return Pad(n, ch); }
859
860 // same as `this_string = str'
861 wxString& assign(const wxString& str)
862 { return *this = str; }
863 // same as ` = str[pos..pos + n]
864 wxString& assign(const wxString& str, size_t pos, size_t n)
865 { Empty(); return Append(str.c_str() + pos, n); }
866 // same as `= first n (or all if n == npos) characters of sz'
867 wxString& assign(const wxChar *sz, size_t n = npos)
868 { Empty(); return Append(sz, n == npos ? wxStrlen(sz) : n); }
869 // same as `= n copies of ch'
870 wxString& assign(size_t n, wxChar ch)
871 { Empty(); return Append(ch, n); }
872
873 // insert another string
874 wxString& insert(size_t nPos, const wxString& str);
875 // insert n chars of str starting at nStart (in str)
876 wxString& insert(size_t nPos, const wxString& str, size_t nStart, size_t n)
877 { return insert(nPos, wxString((const wxChar *)str + nStart, n)); }
878
879 // insert first n (or all if n == npos) characters of sz
880 wxString& insert(size_t nPos, const wxChar *sz, size_t n = npos)
881 { return insert(nPos, wxString(sz, n)); }
882 // insert n copies of ch
883 wxString& insert(size_t nPos, size_t n, wxChar ch)
884 { return insert(nPos, wxString(ch, n)); }
885
886 // delete characters from nStart to nStart + nLen
887 wxString& erase(size_t nStart = 0, size_t nLen = npos);
888
889 // replaces the substring of length nLen starting at nStart
890 wxString& replace(size_t nStart, size_t nLen, const wxChar* sz);
891 // replaces the substring with nCount copies of ch
892 wxString& replace(size_t nStart, size_t nLen, size_t nCount, wxChar ch);
893 // replaces a substring with another substring
894 wxString& replace(size_t nStart, size_t nLen,
895 const wxString& str, size_t nStart2, size_t nLen2);
896 // replaces the substring with first nCount chars of sz
897 wxString& replace(size_t nStart, size_t nLen,
898 const wxChar* sz, size_t nCount);
899
900 // swap two strings
901 void swap(wxString& str);
902
903 // All find() functions take the nStart argument which specifies the
904 // position to start the search on, the default value is 0. All functions
905 // return npos if there were no match.
906
907 // find a substring
908 size_t find(const wxString& str, size_t nStart = 0) const;
909
910 // VC++ 1.5 can't cope with this syntax.
911 #if !defined(__VISUALC__) || defined(__WIN32__)
912 // find first n characters of sz
913 size_t find(const wxChar* sz, size_t nStart = 0, size_t n = npos) const;
914 #endif // VC++ 1.5
915
916 // Gives a duplicate symbol (presumably a case-insensitivity problem)
917 #if !defined(__BORLANDC__)
918 // find the first occurence of character ch after nStart
919 size_t find(wxChar ch, size_t nStart = 0) const;
920 #endif
921 // rfind() family is exactly like find() but works right to left
922
923 // as find, but from the end
924 size_t rfind(const wxString& str, size_t nStart = npos) const;
925
926 // VC++ 1.5 can't cope with this syntax.
927 #if !defined(__VISUALC__) || defined(__WIN32__)
928 // as find, but from the end
929 size_t rfind(const wxChar* sz, size_t nStart = npos,
930 size_t n = npos) const;
931 // as find, but from the end
932 size_t rfind(wxChar ch, size_t nStart = npos) const;
933 #endif // VC++ 1.5
934
935 // find first/last occurence of any character in the set
936
937 // as strpbrk() but starts at nStart, returns npos if not found
938 size_t find_first_of(const wxString& str, size_t nStart = 0) const
939 { return find_first_of(str.c_str(), nStart); }
940 // same as above
941 size_t find_first_of(const wxChar* sz, size_t nStart = 0) const;
942 // same as find(char, size_t)
943 size_t find_first_of(wxChar c, size_t nStart = 0) const
944 { return find(c, nStart); }
945 // find the last (starting from nStart) char from str in this string
946 size_t find_last_of (const wxString& str, size_t nStart = npos) const
947 { return find_last_of(str.c_str(), nStart); }
948 // same as above
949 size_t find_last_of (const wxChar* sz, size_t nStart = npos) const;
950 // same as above
951 size_t find_last_of(wxChar c, size_t nStart = npos) const
952 { return rfind(c, nStart); }
953
954 // find first/last occurence of any character not in the set
955
956 // as strspn() (starting from nStart), returns npos on failure
957 size_t find_first_not_of(const wxString& str, size_t nStart = 0) const
958 { return find_first_not_of(str.c_str(), nStart); }
959 // same as above
960 size_t find_first_not_of(const wxChar* sz, size_t nStart = 0) const;
961 // same as above
962 size_t find_first_not_of(wxChar ch, size_t nStart = 0) const;
963 // as strcspn()
964 size_t find_last_not_of(const wxString& str, size_t nStart = npos) const
965 { return find_first_not_of(str.c_str(), nStart); }
966 // same as above
967 size_t find_last_not_of(const wxChar* sz, size_t nStart = npos) const;
968 // same as above
969 size_t find_last_not_of(wxChar ch, size_t nStart = npos) const;
970
971 // All compare functions return -1, 0 or 1 if the [sub]string is less,
972 // equal or greater than the compare() argument.
973
974 // just like strcmp()
975 int compare(const wxString& str) const { return Cmp(str); }
976 // comparison with a substring
977 int compare(size_t nStart, size_t nLen, const wxString& str) const
978 { return Mid(nStart, nLen).Cmp(str); }
979 // comparison of 2 substrings
980 int compare(size_t nStart, size_t nLen,
981 const wxString& str, size_t nStart2, size_t nLen2) const
982 { return Mid(nStart, nLen).Cmp(str.Mid(nStart2, nLen2)); }
983 // just like strcmp()
984 int compare(const wxChar* sz) const { return Cmp(sz); }
985 // substring comparison with first nCount characters of sz
986 int compare(size_t nStart, size_t nLen,
987 const wxChar* sz, size_t nCount = npos) const
988 { return Mid(nStart, nLen).Cmp(wxString(sz, nCount)); }
989
990 // substring extraction
991 wxString substr(size_t nStart = 0, size_t nLen = npos) const
992 { return Mid(nStart, nLen); }
993 #endif // wxSTD_STRING_COMPATIBILITY
994 };
995
996 // ----------------------------------------------------------------------------
997 // The string array uses it's knowledge of internal structure of the wxString
998 // class to optimize string storage. Normally, we would store pointers to
999 // string, but as wxString is, in fact, itself a pointer (sizeof(wxString) is
1000 // sizeof(char *)) we store these pointers instead. The cast to "wxString *" is
1001 // really all we need to turn such pointer into a string!
1002 //
1003 // Of course, it can be called a dirty hack, but we use twice less memory and
1004 // this approach is also more speed efficient, so it's probably worth it.
1005 //
1006 // Usage notes: when a string is added/inserted, a new copy of it is created,
1007 // so the original string may be safely deleted. When a string is retrieved
1008 // from the array (operator[] or Item() method), a reference is returned.
1009 // ----------------------------------------------------------------------------
1010
1011 class WXDLLEXPORT wxArrayString
1012 {
1013 public:
1014 // type of function used by wxArrayString::Sort()
1015 typedef int (*CompareFunction)(const wxString& first,
1016 const wxString& second);
1017
1018 // constructors and destructor
1019 // default ctor
1020 wxArrayString()
1021 : m_nSize(0), m_nCount(0), m_pItems(NULL), m_autoSort(FALSE)
1022 { Init(FALSE); }
1023 // if autoSort is TRUE, the array is always sorted (in alphabetical order)
1024 //
1025 // NB: the reason for using int and not bool is that like this we can avoid
1026 // using this ctor for implicit conversions from "const char *" (which
1027 // we'd like to be implicitly converted to wxString instead!)
1028 //
1029 // of course, using explicit would be even better - if all compilers
1030 // supported it...
1031 wxArrayString(int autoSort)
1032 : m_nSize(0), m_nCount(0), m_pItems(NULL), m_autoSort(FALSE)
1033 { Init(autoSort != 0); }
1034 // copy ctor
1035 wxArrayString(const wxArrayString& array);
1036 // assignment operator
1037 wxArrayString& operator=(const wxArrayString& src);
1038 // not virtual, this class should not be derived from
1039 ~wxArrayString();
1040
1041 // memory management
1042 // empties the list, but doesn't release memory
1043 void Empty();
1044 // empties the list and releases memory
1045 void Clear();
1046 // preallocates memory for given number of items
1047 void Alloc(size_t nCount);
1048 // minimzes the memory usage (by freeing all extra memory)
1049 void Shrink();
1050
1051 // simple accessors
1052 // number of elements in the array
1053 size_t GetCount() const { return m_nCount; }
1054 // is it empty?
1055 bool IsEmpty() const { return m_nCount == 0; }
1056 // number of elements in the array (GetCount is preferred API)
1057 size_t Count() const { return m_nCount; }
1058
1059 // items access (range checking is done in debug version)
1060 // get item at position uiIndex
1061 wxString& Item(size_t nIndex) const
1062 {
1063 wxASSERT_MSG( nIndex < m_nCount,
1064 _T("wxArrayString: index out of bounds") );
1065
1066 return *(wxString *)&(m_pItems[nIndex]);
1067 }
1068
1069 // same as Item()
1070 wxString& operator[](size_t nIndex) const { return Item(nIndex); }
1071 // get last item
1072 wxString& Last() const
1073 {
1074 wxASSERT_MSG( !IsEmpty(),
1075 _T("wxArrayString: index out of bounds") );
1076 return Item(Count() - 1);
1077 }
1078
1079 // return a wxString[], useful for the controls which
1080 // take one in their ctor. You must delete[] it yourself
1081 // once you are done with it. Will return NULL if the
1082 // ArrayString was empty.
1083 wxString* GetStringArray() const;
1084
1085 // item management
1086 // Search the element in the array, starting from the beginning if
1087 // bFromEnd is FALSE or from end otherwise. If bCase, comparison is case
1088 // sensitive (default). Returns index of the first item matched or
1089 // wxNOT_FOUND
1090 int Index (const wxChar *sz, bool bCase = TRUE, bool bFromEnd = FALSE) const;
1091 // add new element at the end (if the array is not sorted), return its
1092 // index
1093 size_t Add(const wxString& str, size_t nInsert = 1);
1094 // add new element at given position
1095 void Insert(const wxString& str, size_t uiIndex, size_t nInsert = 1);
1096 // expand the array to have count elements
1097 void SetCount(size_t count);
1098 // remove first item matching this value
1099 void Remove(const wxChar *sz);
1100 // remove item by index
1101 void Remove(size_t nIndex, size_t nRemove = 1);
1102 void RemoveAt(size_t nIndex, size_t nRemove = 1) { Remove(nIndex, nRemove); }
1103
1104 // sorting
1105 // sort array elements in alphabetical order (or reversed alphabetical
1106 // order if reverseOrder parameter is TRUE)
1107 void Sort(bool reverseOrder = FALSE);
1108 // sort array elements using specified comparaison function
1109 void Sort(CompareFunction compareFunction);
1110
1111 // comparison
1112 // compare two arrays case sensitively
1113 bool operator==(const wxArrayString& a) const;
1114 // compare two arrays case sensitively
1115 bool operator!=(const wxArrayString& a) const { return !(*this == a); }
1116
1117 protected:
1118 void Init(bool autoSort); // common part of all ctors
1119 void Copy(const wxArrayString& src); // copies the contents of another array
1120
1121 private:
1122 void Grow(size_t nIncrement = 0); // makes array bigger if needed
1123 void Free(); // free all the strings stored
1124
1125 void DoSort(); // common part of all Sort() variants
1126
1127 size_t m_nSize, // current size of the array
1128 m_nCount; // current number of elements
1129
1130 wxChar **m_pItems; // pointer to data
1131
1132 bool m_autoSort; // if TRUE, keep the array always sorted
1133 };
1134
1135 class WXDLLEXPORT wxSortedArrayString : public wxArrayString
1136 {
1137 public:
1138 wxSortedArrayString() : wxArrayString(TRUE)
1139 { }
1140 wxSortedArrayString(const wxArrayString& array) : wxArrayString(TRUE)
1141 { Copy(array); }
1142 };
1143
1144 // ----------------------------------------------------------------------------
1145 // wxStringBuffer: a tiny class allowing to get a writable pointer into string
1146 // ----------------------------------------------------------------------------
1147
1148 class WXDLLEXPORT wxStringBuffer
1149 {
1150 DECLARE_NO_COPY_CLASS(wxStringBuffer)
1151
1152 public:
1153 wxStringBuffer(wxString& str, size_t lenWanted = 1024)
1154 : m_str(str), m_buf(NULL)
1155 { m_buf = m_str.GetWriteBuf(lenWanted); }
1156
1157 ~wxStringBuffer() { m_str.UngetWriteBuf(); }
1158
1159 operator wxChar*() const { return m_buf; }
1160
1161 private:
1162 wxString& m_str;
1163 wxChar *m_buf;
1164 };
1165
1166 // ---------------------------------------------------------------------------
1167 // wxString comparison functions: operator versions are always case sensitive
1168 // ---------------------------------------------------------------------------
1169
1170 inline bool operator==(const wxString& s1, const wxString& s2)
1171 { return (s1.Len() == s2.Len()) && (s1.Cmp(s2) == 0); }
1172 inline bool operator==(const wxString& s1, const wxChar * s2)
1173 { return s1.Cmp(s2) == 0; }
1174 inline bool operator==(const wxChar * s1, const wxString& s2)
1175 { return s2.Cmp(s1) == 0; }
1176 inline bool operator!=(const wxString& s1, const wxString& s2)
1177 { return (s1.Len() != s2.Len()) || (s1.Cmp(s2) != 0); }
1178 inline bool operator!=(const wxString& s1, const wxChar * s2)
1179 { return s1.Cmp(s2) != 0; }
1180 inline bool operator!=(const wxChar * s1, const wxString& s2)
1181 { return s2.Cmp(s1) != 0; }
1182 inline bool operator< (const wxString& s1, const wxString& s2)
1183 { return s1.Cmp(s2) < 0; }
1184 inline bool operator< (const wxString& s1, const wxChar * s2)
1185 { return s1.Cmp(s2) < 0; }
1186 inline bool operator< (const wxChar * s1, const wxString& s2)
1187 { return s2.Cmp(s1) > 0; }
1188 inline bool operator> (const wxString& s1, const wxString& s2)
1189 { return s1.Cmp(s2) > 0; }
1190 inline bool operator> (const wxString& s1, const wxChar * s2)
1191 { return s1.Cmp(s2) > 0; }
1192 inline bool operator> (const wxChar * s1, const wxString& s2)
1193 { return s2.Cmp(s1) < 0; }
1194 inline bool operator<=(const wxString& s1, const wxString& s2)
1195 { return s1.Cmp(s2) <= 0; }
1196 inline bool operator<=(const wxString& s1, const wxChar * s2)
1197 { return s1.Cmp(s2) <= 0; }
1198 inline bool operator<=(const wxChar * s1, const wxString& s2)
1199 { return s2.Cmp(s1) >= 0; }
1200 inline bool operator>=(const wxString& s1, const wxString& s2)
1201 { return s1.Cmp(s2) >= 0; }
1202 inline bool operator>=(const wxString& s1, const wxChar * s2)
1203 { return s1.Cmp(s2) >= 0; }
1204 inline bool operator>=(const wxChar * s1, const wxString& s2)
1205 { return s2.Cmp(s1) <= 0; }
1206
1207 // comparison with char
1208 inline bool operator==(wxChar c, const wxString& s) { return s.IsSameAs(c); }
1209 inline bool operator==(const wxString& s, wxChar c) { return s.IsSameAs(c); }
1210 inline bool operator!=(wxChar c, const wxString& s) { return !s.IsSameAs(c); }
1211 inline bool operator!=(const wxString& s, wxChar c) { return !s.IsSameAs(c); }
1212
1213 #if wxUSE_UNICODE
1214 inline bool operator==(const wxString& s1, const wxWCharBuffer& s2)
1215 { return (s1.Cmp((const wchar_t *)s2) == 0); }
1216 inline bool operator==(const wxWCharBuffer& s1, const wxString& s2)
1217 { return (s2.Cmp((const wchar_t *)s1) == 0); }
1218 inline bool operator!=(const wxString& s1, const wxWCharBuffer& s2)
1219 { return (s1.Cmp((const wchar_t *)s2) != 0); }
1220 inline bool operator!=(const wxWCharBuffer& s1, const wxString& s2)
1221 { return (s2.Cmp((const wchar_t *)s1) != 0); }
1222 #else // !wxUSE_UNICODE
1223 inline bool operator==(const wxString& s1, const wxCharBuffer& s2)
1224 { return (s1.Cmp((const char *)s2) == 0); }
1225 inline bool operator==(const wxCharBuffer& s1, const wxString& s2)
1226 { return (s2.Cmp((const char *)s1) == 0); }
1227 inline bool operator!=(const wxString& s1, const wxCharBuffer& s2)
1228 { return (s1.Cmp((const char *)s2) != 0); }
1229 inline bool operator!=(const wxCharBuffer& s1, const wxString& s2)
1230 { return (s2.Cmp((const char *)s1) != 0); }
1231 #endif // wxUSE_UNICODE/!wxUSE_UNICODE
1232
1233 wxString WXDLLEXPORT operator+(const wxString& string1, const wxString& string2);
1234 wxString WXDLLEXPORT operator+(const wxString& string, wxChar ch);
1235 wxString WXDLLEXPORT operator+(wxChar ch, const wxString& string);
1236 wxString WXDLLEXPORT operator+(const wxString& string, const wxChar *psz);
1237 wxString WXDLLEXPORT operator+(const wxChar *psz, const wxString& string);
1238 #if wxUSE_UNICODE
1239 inline wxString operator+(const wxString& string, const wxWCharBuffer& buf)
1240 { return string + (const wchar_t *)buf; }
1241 inline wxString operator+(const wxWCharBuffer& buf, const wxString& string)
1242 { return (const wchar_t *)buf + string; }
1243 #else // !wxUSE_UNICODE
1244 inline wxString operator+(const wxString& string, const wxCharBuffer& buf)
1245 { return string + (const char *)buf; }
1246 inline wxString operator+(const wxCharBuffer& buf, const wxString& string)
1247 { return (const char *)buf + string; }
1248 #endif // wxUSE_UNICODE/!wxUSE_UNICODE
1249
1250 // ---------------------------------------------------------------------------
1251 // Implementation only from here until the end of file
1252 // ---------------------------------------------------------------------------
1253
1254 // don't pollute the library user's name space
1255 #undef wxASSERT_VALID_INDEX
1256
1257 #if defined(wxSTD_STRING_COMPATIBILITY) && wxUSE_STD_IOSTREAM
1258
1259 #include "wx/ioswrap.h"
1260
1261 WXDLLEXPORT wxSTD istream& operator>>(wxSTD istream&, wxString&);
1262 WXDLLEXPORT wxSTD ostream& operator<<(wxSTD ostream&, const wxString&);
1263
1264 #endif // wxSTD_STRING_COMPATIBILITY
1265
1266 #endif // _WX_WXSTRINGH__