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