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