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