1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/string.h
3 // Purpose: wxString and wxArrayString classes
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 29/01/98
7 // RCS-ID: $Id: string.h 61872 2009-09-09 22:37:05Z VZ $
8 // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 /*
13 Efficient string class [more or less] compatible with MFC CString,
14 wxWidgets 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 // ----------------------------------------------------------------------------
22 // headers
23 // ----------------------------------------------------------------------------
24
25 #include "wx/defs.h" // everybody should include this
26
27 #if defined(__WXMAC__) || defined(__VISAGECPP__)
28 #include <ctype.h>
29 #endif
30
31 #if defined(__VISAGECPP__) && __IBMCPP__ >= 400
32 // problem in VACPP V4 with including stdlib.h multiple times
33 // strconv includes it anyway
34 # include <stdio.h>
35 # include <string.h>
36 # include <stdarg.h>
37 # include <limits.h>
38 #else
39 # include <string.h>
40 # include <stdio.h>
41 # include <stdarg.h>
42 # include <limits.h>
43 # include <stdlib.h>
44 #endif
45
46 #ifdef HAVE_STRCASECMP_IN_STRINGS_H
47 #include <strings.h> // for strcasecmp()
48 #endif // HAVE_STRCASECMP_IN_STRINGS_H
49
50 #ifdef __WXPALMOS__
51 #include <StringMgr.h>
52 #endif
53
54 #include "wx/wxchar.h" // for wxChar
55 #include "wx/buffer.h" // for wxCharBuffer
56 #include "wx/strconv.h" // for wxConvertXXX() macros and wxMBConv classes
57
58 class WXDLLIMPEXP_FWD_BASE wxString;
59
60 // ---------------------------------------------------------------------------
61 // macros
62 // ---------------------------------------------------------------------------
63
64 // casts [unfortunately!] needed to call some broken functions which require
65 // "char *" instead of "const char *"
66 #define WXSTRINGCAST (wxChar *)(const wxChar *)
67 #define wxCSTRINGCAST (wxChar *)(const wxChar *)
68 #define wxMBSTRINGCAST (char *)(const char *)
69 #define wxWCSTRINGCAST (wchar_t *)(const wchar_t *)
70
71 // implementation only
72 #define wxASSERT_VALID_INDEX(i) \
73 wxASSERT_MSG( (size_t)(i) <= length(), wxT("invalid index in wxString") )
74
75 // ----------------------------------------------------------------------------
76 // constants
77 // ----------------------------------------------------------------------------
78
79 #if WXWIN_COMPATIBILITY_2_6
80
81 // deprecated in favour of wxString::npos, don't use in new code
82 //
83 // maximum possible length for a string means "take all string" everywhere
84 #define wxSTRING_MAXLEN wxStringBase::npos
85
86 #endif // WXWIN_COMPATIBILITY_2_6
87
88 // ----------------------------------------------------------------------------
89 // global data
90 // ----------------------------------------------------------------------------
91
92 // global pointer to empty string
93 extern WXDLLIMPEXP_DATA_BASE(const wxChar*) wxEmptyString;
94
95 // ---------------------------------------------------------------------------
96 // global functions complementing standard C string library replacements for
97 // strlen() and portable strcasecmp()
98 //---------------------------------------------------------------------------
99
100 // Use wxXXX() functions from wxchar.h instead! These functions are for
101 // backwards compatibility only.
102
103 // checks whether the passed in pointer is NULL and if the string is empty
IsEmpty(const char * p)104 inline bool IsEmpty(const char *p) { return (!p || !*p); }
105
106 // safe version of strlen() (returns 0 if passed NULL pointer)
Strlen(const char * psz)107 inline size_t Strlen(const char *psz)
108 { return psz ? strlen(psz) : 0; }
109
110 // portable strcasecmp/_stricmp
Stricmp(const char * psz1,const char * psz2)111 inline int Stricmp(const char *psz1, const char *psz2)
112 {
113 #if defined(__VISUALC__) && defined(__WXWINCE__)
114 register char c1, c2;
115 do {
116 c1 = tolower(*psz1++);
117 c2 = tolower(*psz2++);
118 } while ( c1 && (c1 == c2) );
119
120 return c1 - c2;
121 #elif defined(__VISUALC__) || ( defined(__MWERKS__) && defined(__INTEL__) )
122 return _stricmp(psz1, psz2);
123 #elif defined(__SC__)
124 return _stricmp(psz1, psz2);
125 #elif defined(__SALFORDC__)
126 return stricmp(psz1, psz2);
127 #elif defined(__BORLANDC__)
128 return stricmp(psz1, psz2);
129 #elif defined(__WATCOMC__)
130 return stricmp(psz1, psz2);
131 #elif defined(__DJGPP__)
132 return stricmp(psz1, psz2);
133 #elif defined(__EMX__)
134 return stricmp(psz1, psz2);
135 #elif defined(__WXPM__)
136 return stricmp(psz1, psz2);
137 #elif defined(__WXPALMOS__) || \
138 defined(HAVE_STRCASECMP_IN_STRING_H) || \
139 defined(HAVE_STRCASECMP_IN_STRINGS_H) || \
140 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 // ----------------------------------------------------------------------------
169 // deal with STL/non-STL/non-STL-but-wxUSE_STD_STRING
170 // ----------------------------------------------------------------------------
171
172 // in both cases we need to define wxStdString
173 #if wxUSE_STL || wxUSE_STD_STRING
174
175 #include "wx/beforestd.h"
176 #include <string>
177 #include "wx/afterstd.h"
178
179 #if wxUSE_UNICODE
180 #ifdef HAVE_STD_WSTRING
181 typedef std::wstring wxStdString;
182 #else
183 typedef std::basic_string<wxChar> wxStdString;
184 #endif
185 #else
186 typedef std::string wxStdString;
187 #endif
188
189 #endif // need <string>
190
191 #if wxUSE_STL
192
193 // we don't need an extra ctor from std::string when copy ctor already does
194 // the work
195 #undef wxUSE_STD_STRING
196 #define wxUSE_STD_STRING 0
197
198 #if (defined(__GNUG__) && (__GNUG__ < 3)) || \
199 (defined(_MSC_VER) && (_MSC_VER <= 1200))
200 #define wxSTRING_BASE_HASNT_CLEAR
201 #endif
202
203 typedef wxStdString wxStringBase;
204 #else // if !wxUSE_STL
205
206 #if !defined(HAVE_STD_STRING_COMPARE) && \
207 (!defined(__WX_SETUP_H__) || wxUSE_STL == 0)
208 #define HAVE_STD_STRING_COMPARE
209 #endif
210
211 // ---------------------------------------------------------------------------
212 // string data prepended with some housekeeping info (used by wxString class),
213 // is never used directly (but had to be put here to allow inlining)
214 // ---------------------------------------------------------------------------
215
216 struct WXDLLIMPEXP_BASE wxStringData
217 {
218 int nRefs; // reference count
219 size_t nDataLength, // actual string length
220 nAllocLength; // allocated memory size
221
222 // mimics declaration 'wxChar data[nAllocLength]'
datawxStringData223 wxChar* data() const { return (wxChar*)(this + 1); }
224
225 // empty string has a special ref count so it's never deleted
IsEmptywxStringData226 bool IsEmpty() const { return (nRefs == -1); }
IsSharedwxStringData227 bool IsShared() const { return (nRefs > 1); }
228
229 // lock/unlock
LockwxStringData230 void Lock() { if ( !IsEmpty() ) nRefs++; }
231
232 // VC++ will refuse to inline Unlock but profiling shows that it is wrong
233 #if defined(__VISUALC__) && (__VISUALC__ >= 1200)
234 __forceinline
235 #endif
236 // VC++ free must take place in same DLL as allocation when using non dll
237 // run-time library (e.g. Multithreaded instead of Multithreaded DLL)
238 #if defined(__VISUALC__) && defined(_MT) && !defined(_DLL)
UnlockwxStringData239 void Unlock() { if ( !IsEmpty() && --nRefs == 0) Free(); }
240 // we must not inline deallocation since allocation is not inlined
241 void Free();
242 #else
243 void Unlock() { if ( !IsEmpty() && --nRefs == 0) free(this); }
244 #endif
245
246 // if we had taken control over string memory (GetWriteBuf), it's
247 // intentionally put in invalid state
ValidatewxStringData248 void Validate(bool b) { nRefs = (b ? 1 : 0); }
IsValidwxStringData249 bool IsValid() const { return (nRefs != 0); }
250 };
251
252 class WXDLLIMPEXP_BASE wxStringBase
253 {
254 #if !wxUSE_STL
255 friend class WXDLLIMPEXP_FWD_BASE wxArrayString;
256 #endif
257 public :
258 // an 'invalid' value for string index, moved to this place due to a CW bug
259 static const size_t npos;
260 protected:
261 // points to data preceded by wxStringData structure with ref count info
262 wxChar *m_pchData;
263
264 // accessor to string data
GetStringData()265 wxStringData* GetStringData() const { return (wxStringData*)m_pchData - 1; }
266
267 // string (re)initialization functions
268 // initializes the string to the empty value (must be called only from
269 // ctors, use Reinit() otherwise)
Init()270 void Init() { m_pchData = (wxChar *)wxEmptyString; }
271 // initializes the string with (a part of) C-string
272 void InitWith(const wxChar *psz, size_t nPos = 0, size_t nLen = npos);
273 // as Init, but also frees old data
Reinit()274 void Reinit() { GetStringData()->Unlock(); Init(); }
275
276 // memory allocation
277 // allocates memory for string of length nLen
278 bool AllocBuffer(size_t nLen);
279 // copies data to another string
280 bool AllocCopy(wxString&, int, int) const;
281 // effectively copies data to string
282 bool AssignCopy(size_t, const wxChar *);
283
284 // append a (sub)string
285 bool ConcatSelf(size_t nLen, const wxChar *src, size_t nMaxLen);
ConcatSelf(size_t nLen,const wxChar * src)286 bool ConcatSelf(size_t nLen, const wxChar *src)
287 { return ConcatSelf(nLen, src, nLen); }
288
289 // functions called before writing to the string: they copy it if there
290 // are other references to our data (should be the only owner when writing)
291 bool CopyBeforeWrite();
292 bool AllocBeforeWrite(size_t);
293
294 // compatibility with wxString
295 bool Alloc(size_t nLen);
296 public:
297 // standard types
298 typedef wxChar value_type;
299 typedef wxChar char_type;
300 typedef size_t size_type;
301 typedef value_type& reference;
302 typedef const value_type& const_reference;
303 typedef value_type* pointer;
304 typedef const value_type* const_pointer;
305 typedef value_type *iterator;
306 typedef const value_type *const_iterator;
307
308 #define wxSTRING_REVERSE_ITERATOR(name, const_or_not) \
309 class name \
310 { \
311 public: \
312 typedef wxChar value_type; \
313 typedef const_or_not value_type& reference; \
314 typedef const_or_not value_type *pointer; \
315 typedef const_or_not value_type *iterator_type; \
316 \
317 name(iterator_type i) : m_cur(i) { } \
318 name(const name& ri) : m_cur(ri.m_cur) { } \
319 \
320 iterator_type base() const { return m_cur; } \
321 \
322 reference operator*() const { return *(m_cur - 1); } \
323 \
324 name& operator++() { --m_cur; return *this; } \
325 name operator++(int) { name tmp = *this; --m_cur; return tmp; } \
326 name& operator--() { ++m_cur; return *this; } \
327 name operator--(int) { name tmp = *this; ++m_cur; return tmp; } \
328 \
329 bool operator==(name ri) const { return m_cur == ri.m_cur; } \
330 bool operator!=(name ri) const { return !(*this == ri); } \
331 \
332 private: \
333 iterator_type m_cur; \
334 }
335
336 wxSTRING_REVERSE_ITERATOR(const_reverse_iterator, const);
337
338 #define wxSTRING_CONST
339 wxSTRING_REVERSE_ITERATOR(reverse_iterator, wxSTRING_CONST);
340 #undef wxSTRING_CONST
341
342 #undef wxSTRING_REVERSE_ITERATOR
343
344
345 // constructors and destructor
346 // ctor for an empty string
wxStringBase()347 wxStringBase() { Init(); }
348 // copy ctor
wxStringBase(const wxStringBase & stringSrc)349 wxStringBase(const wxStringBase& stringSrc)
350 {
351 wxASSERT_MSG( stringSrc.GetStringData()->IsValid(),
352 wxT("did you forget to call UngetWriteBuf()?") );
353
354 if ( stringSrc.empty() ) {
355 // nothing to do for an empty string
356 Init();
357 }
358 else {
359 m_pchData = stringSrc.m_pchData; // share same data
360 GetStringData()->Lock(); // => one more copy
361 }
362 }
363 // string containing nRepeat copies of ch
364 wxStringBase(size_type nRepeat, wxChar ch);
365 // ctor takes first nLength characters from C string
366 // (default value of npos means take all the string)
wxStringBase(const wxChar * psz)367 wxStringBase(const wxChar *psz)
368 { InitWith(psz, 0, npos); }
wxStringBase(const wxChar * psz,size_t nLength)369 wxStringBase(const wxChar *psz, size_t nLength)
370 { InitWith(psz, 0, nLength); }
371 wxStringBase(const wxChar *psz,
372 const wxMBConv& WXUNUSED(conv),
373 size_t nLength = npos)
374 { InitWith(psz, 0, nLength); }
375 // take nLen chars starting at nPos
wxStringBase(const wxStringBase & str,size_t nPos,size_t nLen)376 wxStringBase(const wxStringBase& str, size_t nPos, size_t nLen)
377 {
378 wxASSERT_MSG( str.GetStringData()->IsValid(),
379 wxT("did you forget to call UngetWriteBuf()?") );
380 Init();
381 size_t strLen = str.length() - nPos; nLen = strLen < nLen ? strLen : nLen;
382 InitWith(str.c_str(), nPos, nLen);
383 }
384 // take all characters from pStart to pEnd
385 wxStringBase(const void *pStart, const void *pEnd);
386
387 // dtor is not virtual, this class must not be inherited from!
~wxStringBase()388 ~wxStringBase()
389 {
390 #if defined(__VISUALC__) && (__VISUALC__ >= 1200)
391 //RN - according to the above VC++ does indeed inline this,
392 //even though it spits out two warnings
393 #pragma warning (disable:4714)
394 #endif
395
396 GetStringData()->Unlock();
397 }
398
399 #if defined(__VISUALC__) && (__VISUALC__ >= 1200)
400 //re-enable inlining warning
401 #pragma warning (default:4714)
402 #endif
403 // overloaded assignment
404 // from another wxString
405 wxStringBase& operator=(const wxStringBase& stringSrc);
406 // from a character
407 wxStringBase& operator=(wxChar ch);
408 // from a C string
409 wxStringBase& operator=(const wxChar *psz);
410
411 // return the length of the string
length()412 size_type length() const { return GetStringData()->nDataLength; }
413 // return the length of the string
size()414 size_type size() const { return length(); }
415 // return the maximum size of the string
max_size()416 size_type max_size() const { return npos; }
417 // resize the string, filling the space with c if c != 0
418 void resize(size_t nSize, wxChar ch = wxT('\0'));
419 // delete the contents of the string
clear()420 void clear() { erase(0, npos); }
421 // returns true if the string is empty
empty()422 bool empty() const { return length() == 0; }
423 // inform string about planned change in size
reserve(size_t sz)424 void reserve(size_t sz) { Alloc(sz); }
capacity()425 size_type capacity() const { return GetStringData()->nAllocLength; }
426
427 // lib.string.access
428 // return the character at position n
at(size_type n)429 value_type at(size_type n) const
430 { wxASSERT_VALID_INDEX( n ); return m_pchData[n]; }
431 // returns the writable character at position n
at(size_type n)432 reference at(size_type n)
433 { wxASSERT_VALID_INDEX( n ); CopyBeforeWrite(); return m_pchData[n]; }
434
435 // lib.string.modifiers
436 // append elements str[pos], ..., str[pos+n]
append(const wxStringBase & str,size_t pos,size_t n)437 wxStringBase& append(const wxStringBase& str, size_t pos, size_t n)
438 {
439 wxASSERT(pos <= str.length());
440 ConcatSelf(n, str.c_str() + pos, str.length() - pos);
441 return *this;
442 }
443 // append a string
append(const wxStringBase & str)444 wxStringBase& append(const wxStringBase& str)
445 { ConcatSelf(str.length(), str.c_str()); return *this; }
446 // append first n (or all if n == npos) characters of sz
append(const wxChar * sz)447 wxStringBase& append(const wxChar *sz)
448 { ConcatSelf(wxStrlen(sz), sz); return *this; }
append(const wxChar * sz,size_t n)449 wxStringBase& append(const wxChar *sz, size_t n)
450 { ConcatSelf(n, sz); return *this; }
451 // append n copies of ch
452 wxStringBase& append(size_t n, wxChar ch);
453 // append from first to last
append(const_iterator first,const_iterator last)454 wxStringBase& append(const_iterator first, const_iterator last)
455 { ConcatSelf(last - first, first); return *this; }
456
457 // same as `this_string = str'
assign(const wxStringBase & str)458 wxStringBase& assign(const wxStringBase& str)
459 { return *this = str; }
460 // same as ` = str[pos..pos + n]
assign(const wxStringBase & str,size_t pos,size_t n)461 wxStringBase& assign(const wxStringBase& str, size_t pos, size_t n)
462 { clear(); return append(str, pos, n); }
463 // same as `= first n (or all if n == npos) characters of sz'
assign(const wxChar * sz)464 wxStringBase& assign(const wxChar *sz)
465 { clear(); return append(sz, wxStrlen(sz)); }
assign(const wxChar * sz,size_t n)466 wxStringBase& assign(const wxChar *sz, size_t n)
467 { clear(); return append(sz, n); }
468 // same as `= n copies of ch'
assign(size_t n,wxChar ch)469 wxStringBase& assign(size_t n, wxChar ch)
470 { clear(); return append(n, ch); }
471 // assign from first to last
assign(const_iterator first,const_iterator last)472 wxStringBase& assign(const_iterator first, const_iterator last)
473 { clear(); return append(first, last); }
474
475 // first valid index position
begin()476 const_iterator begin() const { return m_pchData; }
477 iterator begin();
478 // position one after the last valid one
end()479 const_iterator end() const { return m_pchData + length(); }
480 iterator end();
481
482 // first element of the reversed string
rbegin()483 const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); }
rbegin()484 reverse_iterator rbegin() { return reverse_iterator(end()); }
485 // one beyond the end of the reversed string
rend()486 const_reverse_iterator rend() const { return const_reverse_iterator(begin()); }
rend()487 reverse_iterator rend() { return reverse_iterator(begin()); }
488
489 // insert another string
insert(size_t nPos,const wxStringBase & str)490 wxStringBase& insert(size_t nPos, const wxStringBase& str)
491 {
492 wxASSERT( str.GetStringData()->IsValid() );
493 return insert(nPos, str.c_str(), str.length());
494 }
495 // insert n chars of str starting at nStart (in str)
insert(size_t nPos,const wxStringBase & str,size_t nStart,size_t n)496 wxStringBase& insert(size_t nPos, const wxStringBase& str, size_t nStart, size_t n)
497 {
498 wxASSERT( str.GetStringData()->IsValid() );
499 wxASSERT( nStart < str.length() );
500 size_t strLen = str.length() - nStart;
501 n = strLen < n ? strLen : n;
502 return insert(nPos, str.c_str() + nStart, n);
503 }
504 // insert first n (or all if n == npos) characters of sz
505 wxStringBase& insert(size_t nPos, const wxChar *sz, size_t n = npos);
506 // insert n copies of ch
insert(size_t nPos,size_t n,wxChar ch)507 wxStringBase& insert(size_t nPos, size_t n, wxChar ch)
508 { return insert(nPos, wxStringBase(n, ch)); }
insert(iterator it,wxChar ch)509 iterator insert(iterator it, wxChar ch)
510 { size_t idx = it - begin(); insert(idx, 1, ch); return begin() + idx; }
insert(iterator it,const_iterator first,const_iterator last)511 void insert(iterator it, const_iterator first, const_iterator last)
512 { insert(it - begin(), first, last - first); }
insert(iterator it,size_type n,wxChar ch)513 void insert(iterator it, size_type n, wxChar ch)
514 { insert(it - begin(), n, ch); }
515
516 // delete characters from nStart to nStart + nLen
517 wxStringBase& erase(size_type pos = 0, size_type n = npos);
erase(iterator first,iterator last)518 iterator erase(iterator first, iterator last)
519 {
520 size_t idx = first - begin();
521 erase(idx, last - first);
522 return begin() + idx;
523 }
524 iterator erase(iterator first);
525
526 // explicit conversion to C string (use this with printf()!)
c_str()527 const wxChar* c_str() const { return m_pchData; }
data()528 const wxChar* data() const { return m_pchData; }
529
530 // replaces the substring of length nLen starting at nStart
531 wxStringBase& replace(size_t nStart, size_t nLen, const wxChar* sz);
532 // replaces the substring of length nLen starting at nStart
replace(size_t nStart,size_t nLen,const wxStringBase & str)533 wxStringBase& replace(size_t nStart, size_t nLen, const wxStringBase& str)
534 { return replace(nStart, nLen, str.c_str()); }
535 // replaces the substring with nCount copies of ch
536 wxStringBase& replace(size_t nStart, size_t nLen, size_t nCount, wxChar ch);
537 // replaces a substring with another substring
538 wxStringBase& replace(size_t nStart, size_t nLen,
539 const wxStringBase& str, size_t nStart2, size_t nLen2);
540 // replaces the substring with first nCount chars of sz
541 wxStringBase& replace(size_t nStart, size_t nLen,
542 const wxChar* sz, size_t nCount);
replace(iterator first,iterator last,const_pointer s)543 wxStringBase& replace(iterator first, iterator last, const_pointer s)
544 { return replace(first - begin(), last - first, s); }
replace(iterator first,iterator last,const_pointer s,size_type n)545 wxStringBase& replace(iterator first, iterator last, const_pointer s,
546 size_type n)
547 { return replace(first - begin(), last - first, s, n); }
replace(iterator first,iterator last,const wxStringBase & s)548 wxStringBase& replace(iterator first, iterator last, const wxStringBase& s)
549 { return replace(first - begin(), last - first, s); }
replace(iterator first,iterator last,size_type n,wxChar c)550 wxStringBase& replace(iterator first, iterator last, size_type n, wxChar c)
551 { return replace(first - begin(), last - first, n, c); }
replace(iterator first,iterator last,const_iterator first1,const_iterator last1)552 wxStringBase& replace(iterator first, iterator last,
553 const_iterator first1, const_iterator last1)
554 { return replace(first - begin(), last - first, first1, last1 - first1); }
555
556 // swap two strings
557 void swap(wxStringBase& str);
558
559 // All find() functions take the nStart argument which specifies the
560 // position to start the search on, the default value is 0. All functions
561 // return npos if there were no match.
562
563 // find a substring
564 size_t find(const wxStringBase& str, size_t nStart = 0) const;
565
566 // find first n characters of sz
567 size_t find(const wxChar* sz, size_t nStart = 0, size_t n = npos) const;
568
569 // find the first occurence of character ch after nStart
570 size_t find(wxChar ch, size_t nStart = 0) const;
571
572 // rfind() family is exactly like find() but works right to left
573
574 // as find, but from the end
575 size_t rfind(const wxStringBase& str, size_t nStart = npos) const;
576
577 // as find, but from the end
578 size_t rfind(const wxChar* sz, size_t nStart = npos,
579 size_t n = npos) const;
580 // as find, but from the end
581 size_t rfind(wxChar ch, size_t nStart = npos) const;
582
583 // find first/last occurence of any character in the set
584
585 // as strpbrk() but starts at nStart, returns npos if not found
586 size_t find_first_of(const wxStringBase& str, size_t nStart = 0) const
587 { return find_first_of(str.c_str(), nStart); }
588 // same as above
589 size_t find_first_of(const wxChar* sz, size_t nStart = 0) const;
590 size_t find_first_of(const wxChar* sz, size_t nStart, size_t n) const;
591 // same as find(char, size_t)
592 size_t find_first_of(wxChar c, size_t nStart = 0) const
593 { return find(c, nStart); }
594 // find the last (starting from nStart) char from str in this string
595 size_t find_last_of (const wxStringBase& str, size_t nStart = npos) const
596 { return find_last_of(str.c_str(), nStart); }
597 // same as above
598 size_t find_last_of (const wxChar* sz, size_t nStart = npos) const;
599 size_t find_last_of(const wxChar* sz, size_t nStart, size_t n) const;
600 // same as above
601 size_t find_last_of(wxChar c, size_t nStart = npos) const
602 { return rfind(c, nStart); }
603
604 // find first/last occurence of any character not in the set
605
606 // as strspn() (starting from nStart), returns npos on failure
607 size_t find_first_not_of(const wxStringBase& str, size_t nStart = 0) const
608 { return find_first_not_of(str.c_str(), nStart); }
609 // same as above
610 size_t find_first_not_of(const wxChar* sz, size_t nStart = 0) const;
611 size_t find_first_not_of(const wxChar* sz, size_t nStart, size_t n) const;
612 // same as above
613 size_t find_first_not_of(wxChar ch, size_t nStart = 0) const;
614 // as strcspn()
615 size_t find_last_not_of(const wxStringBase& str, size_t nStart = npos) const
616 { return find_last_not_of(str.c_str(), nStart); }
617 // same as above
618 size_t find_last_not_of(const wxChar* sz, size_t nStart = npos) const;
619 size_t find_last_not_of(const wxChar* sz, size_t nStart, size_t n) const;
620 // same as above
621 size_t find_last_not_of(wxChar ch, size_t nStart = npos) const;
622
623 // All compare functions return -1, 0 or 1 if the [sub]string is less,
624 // equal or greater than the compare() argument.
625
626 // comparison with another string
627 int compare(const wxStringBase& str) const;
628 // comparison with a substring
629 int compare(size_t nStart, size_t nLen, const wxStringBase& str) const;
630 // comparison of 2 substrings
631 int compare(size_t nStart, size_t nLen,
632 const wxStringBase& str, size_t nStart2, size_t nLen2) const;
633 // comparison with a c string
634 int compare(const wxChar* sz) const;
635 // substring comparison with first nCount characters of sz
636 int compare(size_t nStart, size_t nLen,
637 const wxChar* sz, size_t nCount = npos) const;
638
639 size_type copy(wxChar* s, size_type n, size_type pos = 0);
640
641 // substring extraction
642 wxStringBase substr(size_t nStart = 0, size_t nLen = npos) const;
643
644 // string += string
645 wxStringBase& operator+=(const wxStringBase& s) { return append(s); }
646 // string += C string
647 wxStringBase& operator+=(const wxChar *psz) { return append(psz); }
648 // string += char
649 wxStringBase& operator+=(wxChar ch) { return append(1, ch); }
650 };
651
652 #endif // !wxUSE_STL
653
654 // ----------------------------------------------------------------------------
655 // wxString: string class trying to be compatible with std::string, MFC
656 // CString and wxWindows 1.x wxString all at once
657 // ---------------------------------------------------------------------------
658
659 class WXDLLIMPEXP_BASE wxString : public wxStringBase
660 {
661 #if !wxUSE_STL
662 friend class WXDLLIMPEXP_FWD_BASE wxArrayString;
663 #endif
664
665 // NB: special care was taken in arranging the member functions in such order
666 // that all inline functions can be effectively inlined, verify that all
667 // performance critical functions are still inlined if you change order!
668 private:
669 // if we hadn't made these operators private, it would be possible to
670 // compile "wxString s; s = 17;" without any warnings as 17 is implicitly
671 // converted to char in C and we do have operator=(char)
672 //
673 // NB: we don't need other versions (short/long and unsigned) as attempt
674 // to assign another numeric type to wxString will now result in
675 // ambiguity between operator=(char) and operator=(int)
676 wxString& operator=(int);
677
678 // these methods are not implemented - there is _no_ conversion from int to
679 // string, you're doing something wrong if the compiler wants to call it!
680 //
681 // try `s << i' or `s.Printf("%d", i)' instead
682 wxString(int);
683
684 public:
685 // constructors and destructor
686 // ctor for an empty string
wxString()687 wxString() : wxStringBase() { }
688 // copy ctor
wxString(const wxStringBase & stringSrc)689 wxString(const wxStringBase& stringSrc) : wxStringBase(stringSrc) { }
wxString(const wxString & stringSrc)690 wxString(const wxString& stringSrc) : wxStringBase(stringSrc) { }
691 // string containing nRepeat copies of ch
692 wxString(wxChar ch, size_t nRepeat = 1)
wxStringBase(nRepeat,ch)693 : wxStringBase(nRepeat, ch) { }
wxString(size_t nRepeat,wxChar ch)694 wxString(size_t nRepeat, wxChar ch)
695 : wxStringBase(nRepeat, ch) { }
696 // ctor takes first nLength characters from C string
697 // (default value of npos means take all the string)
wxString(const wxChar * psz)698 wxString(const wxChar *psz)
699 : wxStringBase(psz ? psz : wxT("")) { }
wxString(const wxChar * psz,size_t nLength)700 wxString(const wxChar *psz, size_t nLength)
701 : wxStringBase(psz, nLength) { }
702 wxString(const wxChar *psz,
703 const wxMBConv& WXUNUSED(conv),
704 size_t nLength = npos)
705 : wxStringBase(psz, nLength == npos ? wxStrlen(psz) : nLength) { }
706
707 // even if we're not built with wxUSE_STL == 1 it is very convenient to allow
708 // implicit conversions from std::string to wxString as this allows to use
709 // the same strings in non-GUI and GUI code, however we don't want to
710 // unconditionally add this ctor as it would make wx lib dependent on
711 // libstdc++ on some Linux versions which is bad, so instead we ask the
712 // client code to define this wxUSE_STD_STRING symbol if they need it
713 #if wxUSE_STD_STRING
wxString(const wxStdString & s)714 wxString(const wxStdString& s)
715 : wxStringBase(s.c_str()) { }
716 #endif // wxUSE_STD_STRING
717
718 #if wxUSE_UNICODE
719 // from multibyte string
720 wxString(const char *psz, const wxMBConv& conv, size_t nLength = npos);
721 // from wxWCharBuffer (i.e. return from wxGetString)
wxString(const wxWCharBuffer & psz)722 wxString(const wxWCharBuffer& psz) : wxStringBase(psz.data()) { }
723 #else // ANSI
724 // from C string (for compilers using unsigned char)
wxString(const unsigned char * psz)725 wxString(const unsigned char* psz)
726 : wxStringBase((const char*)psz) { }
727 // from part of C string (for compilers using unsigned char)
wxString(const unsigned char * psz,size_t nLength)728 wxString(const unsigned char* psz, size_t nLength)
729 : wxStringBase((const char*)psz, nLength) { }
730
731 #if wxUSE_WCHAR_T
732 // from wide (Unicode) string
733 wxString(const wchar_t *pwz,
734 const wxMBConv& conv = wxConvLibc,
735 size_t nLength = npos);
736 #endif // !wxUSE_WCHAR_T
737
738 // from wxCharBuffer
wxString(const wxCharBuffer & psz)739 wxString(const wxCharBuffer& psz)
740 : wxStringBase(psz) { }
741 #endif // Unicode/ANSI
742
743 // generic attributes & operations
744 // as standard strlen()
Len()745 size_t Len() const { return length(); }
746 // string contains any characters?
IsEmpty()747 bool IsEmpty() const { return empty(); }
748 // empty string is "false", so !str will return true
749 bool operator!() const { return empty(); }
750 // truncate the string to given length
751 wxString& Truncate(size_t uiLen);
752 // empty string contents
Empty()753 void Empty()
754 {
755 Truncate(0);
756
757 wxASSERT_MSG( empty(), wxT("string not empty after call to Empty()?") );
758 }
759 // empty the string and free memory
Clear()760 void Clear()
761 {
762 wxString tmp(wxEmptyString);
763 swap(tmp);
764 }
765
766 // contents test
767 // Is an ascii value
768 bool IsAscii() const;
769 // Is a number
770 bool IsNumber() const;
771 // Is a word
772 bool IsWord() const;
773
774 // data access (all indexes are 0 based)
775 // read access
GetChar(size_t n)776 wxChar GetChar(size_t n) const
777 { return at(n); }
778 // read/write access
GetWritableChar(size_t n)779 wxChar& GetWritableChar(size_t n)
780 { return at(n); }
781 // write access
SetChar(size_t n,wxChar ch)782 void SetChar(size_t n, wxChar ch)
783 { at(n) = ch; }
784
785 // get last character
Last()786 wxChar Last() const
787 {
788 wxASSERT_MSG( !empty(), wxT("wxString: index out of bounds") );
789
790 return at(length() - 1);
791 }
792
793 // get writable last character
Last()794 wxChar& Last()
795 {
796 wxASSERT_MSG( !empty(), wxT("wxString: index out of bounds") );
797 return at(length() - 1);
798 }
799
800 /*
801 Note that we we must define all of the overloads below to avoid
802 ambiguity when using str[0]. Also note that for a conforming compiler we
803 don't need const version of operatorp[] at all as indexed access to
804 const string is provided by implicit conversion to "const wxChar *"
805 below and defining them would only result in ambiguities, but some other
806 compilers refuse to compile "str[0]" without them.
807 */
808
809 #if defined(__BORLANDC__) || defined(__WATCOMC__) || defined(__MWERKS__)
810 wxChar operator[](int n) const
811 { return wxStringBase::at(n); }
812 wxChar operator[](size_type n) const
813 { return wxStringBase::at(n); }
814 #ifndef wxSIZE_T_IS_UINT
815 wxChar operator[](unsigned int n) const
816 { return wxStringBase::at(n); }
817 #endif // size_t != unsigned int
818 #endif // broken compiler
819
820
821 // operator versions of GetWriteableChar()
822 wxChar& operator[](int n)
823 { return wxStringBase::at(n); }
824 wxChar& operator[](size_type n)
825 { return wxStringBase::at(n); }
826 #ifndef wxSIZE_T_IS_UINT
827 wxChar& operator[](unsigned int n)
828 { return wxStringBase::at(n); }
829 #endif // size_t != unsigned int
830
831 // implicit conversion to C string
832 operator const wxChar*() const { return c_str(); }
833
834 // identical to c_str(), for wxWin 1.6x compatibility
wx_str()835 const wxChar* wx_str() const { return c_str(); }
836 // identical to c_str(), for MFC compatibility
GetData()837 const wxChar* GetData() const { return c_str(); }
838
839 #if wxABI_VERSION >= 20804
840 // conversion to *non-const* multibyte or widestring buffer; modifying
841 // returned buffer won't affect the string, these methods are only useful
842 // for passing values to const-incorrect functions
843 wxWritableCharBuffer char_str(const wxMBConv& conv = wxConvLibc) const
844 { return mb_str(conv); }
845 #if wxUSE_WCHAR_T
wchar_str()846 wxWritableWCharBuffer wchar_str() const { return wc_str(wxConvLibc); }
847 #endif
848 #endif // wxABI_VERSION >= 20804
849
850 // conversion to/from plain (i.e. 7 bit) ASCII: this is useful for
851 // converting numbers or strings which are certain not to contain special
852 // chars (typically system functions, X atoms, environment variables etc.)
853 //
854 // the behaviour of these functions with the strings containing anything
855 // else than 7 bit ASCII characters is undefined, use at your own risk.
856 #if wxUSE_UNICODE
857 static wxString FromAscii(const char *ascii); // string
858 static wxString FromAscii(const char ascii); // char
859 const wxCharBuffer ToAscii() const;
860 #else // ANSI
FromAscii(const char * ascii)861 static wxString FromAscii(const char *ascii) { return wxString( ascii ); }
FromAscii(const char ascii)862 static wxString FromAscii(const char ascii) { return wxString( ascii ); }
ToAscii()863 const char *ToAscii() const { return c_str(); }
864 #endif // Unicode/!Unicode
865
866 #if wxABI_VERSION >= 20804
867 // conversion to/from UTF-8:
868 #if wxUSE_UNICODE
FromUTF8(const char * utf8)869 static wxString FromUTF8(const char *utf8)
870 { return wxString(utf8, wxConvUTF8); }
FromUTF8(const char * utf8,size_t len)871 static wxString FromUTF8(const char *utf8, size_t len)
872 { return wxString(utf8, wxConvUTF8, len); }
utf8_str()873 const wxCharBuffer utf8_str() const { return mb_str(wxConvUTF8); }
ToUTF8()874 const wxCharBuffer ToUTF8() const { return utf8_str(); }
875 #elif wxUSE_WCHAR_T // ANSI
FromUTF8(const char * utf8)876 static wxString FromUTF8(const char *utf8)
877 { return wxString(wxConvUTF8.cMB2WC(utf8)); }
FromUTF8(const char * utf8,size_t len)878 static wxString FromUTF8(const char *utf8, size_t len)
879 {
880 size_t wlen;
881 wxWCharBuffer buf(wxConvUTF8.cMB2WC(utf8, len == npos ? wxNO_LEN : len, &wlen));
882 return wxString(buf.data(), wxConvLibc, wlen);
883 }
utf8_str()884 const wxCharBuffer utf8_str() const
885 { return wxConvUTF8.cWC2MB(wc_str(wxConvLibc)); }
ToUTF8()886 const wxCharBuffer ToUTF8() const { return utf8_str(); }
887 #endif // Unicode/ANSI
888 #endif // wxABI_VERSION >= 20804
889
890 #if wxABI_VERSION >= 20804
891 // functions for storing binary data in wxString:
892 #if wxUSE_UNICODE
From8BitData(const char * data,size_t len)893 static wxString From8BitData(const char *data, size_t len)
894 { return wxString(data, wxConvISO8859_1, len); }
895 // version for NUL-terminated data:
From8BitData(const char * data)896 static wxString From8BitData(const char *data)
897 { return wxString(data, wxConvISO8859_1); }
To8BitData()898 const wxCharBuffer To8BitData() const { return mb_str(wxConvISO8859_1); }
899 #else // ANSI
From8BitData(const char * data,size_t len)900 static wxString From8BitData(const char *data, size_t len)
901 { return wxString(data, len); }
902 // version for NUL-terminated data:
From8BitData(const char * data)903 static wxString From8BitData(const char *data)
904 { return wxString(data); }
To8BitData()905 const char *To8BitData() const { return c_str(); }
906 #endif // Unicode/ANSI
907 #endif // wxABI_VERSION >= 20804
908
909 // conversions with (possible) format conversions: have to return a
910 // buffer with temporary data
911 //
912 // the functions defined (in either Unicode or ANSI) mode are mb_str() to
913 // return an ANSI (multibyte) string, wc_str() to return a wide string and
914 // fn_str() to return a string which should be used with the OS APIs
915 // accepting the file names. The return value is always the same, but the
916 // type differs because a function may either return pointer to the buffer
917 // directly or have to use intermediate buffer for translation.
918 #if wxUSE_UNICODE
919 const wxCharBuffer mb_str(const wxMBConv& conv = wxConvLibc) const;
920
mbc_str()921 const wxWX2MBbuf mbc_str() const { return mb_str(*wxConvCurrent); }
922
wc_str()923 const wxChar* wc_str() const { return c_str(); }
924
925 // for compatibility with !wxUSE_UNICODE version
wc_str(const wxMBConv & WXUNUSED (conv))926 const wxChar* wc_str(const wxMBConv& WXUNUSED(conv)) const { return c_str(); }
927
928 #if wxMBFILES
fn_str()929 const wxCharBuffer fn_str() const { return mb_str(wxConvFile); }
930 #else // !wxMBFILES
fn_str()931 const wxChar* fn_str() const { return c_str(); }
932 #endif // wxMBFILES/!wxMBFILES
933 #else // ANSI
mb_str()934 const wxChar* mb_str() const { return c_str(); }
935
936 // for compatibility with wxUSE_UNICODE version
mb_str(const wxMBConv & WXUNUSED (conv))937 const wxChar* mb_str(const wxMBConv& WXUNUSED(conv)) const { return c_str(); }
938
mbc_str()939 const wxWX2MBbuf mbc_str() const { return mb_str(); }
940
941 #if wxUSE_WCHAR_T
942 const wxWCharBuffer wc_str(const wxMBConv& conv) const;
943 #endif // wxUSE_WCHAR_T
944 #ifdef __WXOSX__
fn_str()945 const wxCharBuffer fn_str() const { return wxConvFile.cWC2WX( wc_str( wxConvLocal ) ); }
946 #else
fn_str()947 const wxChar* fn_str() const { return c_str(); }
948 #endif
949 #endif // Unicode/ANSI
950
951 // overloaded assignment
952 // from another wxString
953 wxString& operator=(const wxStringBase& stringSrc)
954 { return (wxString&)wxStringBase::operator=(stringSrc); }
955 // from a character
956 wxString& operator=(wxChar ch)
957 { return (wxString&)wxStringBase::operator=(ch); }
958 // from a C string - STL probably will crash on NULL,
959 // so we need to compensate in that case
960 #if wxUSE_STL
961 wxString& operator=(const wxChar *psz)
962 { if(psz) wxStringBase::operator=(psz); else Clear(); return *this; }
963 #else
964 wxString& operator=(const wxChar *psz)
965 { return (wxString&)wxStringBase::operator=(psz); }
966 #endif
967
968 #if wxUSE_UNICODE
969 // from wxWCharBuffer
970 wxString& operator=(const wxWCharBuffer& psz)
971 { (void) operator=((const wchar_t *)psz); return *this; }
972 #else // ANSI
973 // from another kind of C string
974 wxString& operator=(const unsigned char* psz);
975 #if wxUSE_WCHAR_T
976 // from a wide string
977 wxString& operator=(const wchar_t *pwz);
978 #endif
979 // from wxCharBuffer
980 wxString& operator=(const wxCharBuffer& psz)
981 { (void) operator=((const char *)psz); return *this; }
982 #endif // Unicode/ANSI
983
984 // string concatenation
985 // in place concatenation
986 /*
987 Concatenate and return the result. Note that the left to right
988 associativity of << allows to write things like "str << str1 << str2
989 << ..." (unlike with +=)
990 */
991 // string += string
992 wxString& operator<<(const wxString& s)
993 {
994 #if !wxUSE_STL
995 wxASSERT_MSG( s.GetStringData()->IsValid(),
996 wxT("did you forget to call UngetWriteBuf()?") );
997 #endif
998
999 append(s);
1000 return *this;
1001 }
1002 // string += C string
1003 wxString& operator<<(const wxChar *psz)
1004 { append(psz); return *this; }
1005 // string += char
1006 wxString& operator<<(wxChar ch) { append(1, ch); return *this; }
1007
1008 // string += buffer (i.e. from wxGetString)
1009 #if wxUSE_UNICODE
1010 wxString& operator<<(const wxWCharBuffer& s)
1011 { (void)operator<<((const wchar_t *)s); return *this; }
1012 void operator+=(const wxWCharBuffer& s)
1013 { (void)operator<<((const wchar_t *)s); }
1014 #else // !wxUSE_UNICODE
1015 wxString& operator<<(const wxCharBuffer& s)
1016 { (void)operator<<((const char *)s); return *this; }
1017 void operator+=(const wxCharBuffer& s)
1018 { (void)operator<<((const char *)s); }
1019 #endif // wxUSE_UNICODE/!wxUSE_UNICODE
1020
1021 // string += C string
Append(const wxString & s)1022 wxString& Append(const wxString& s)
1023 {
1024 // test for empty() to share the string if possible
1025 if ( empty() )
1026 *this = s;
1027 else
1028 append(s);
1029 return *this;
1030 }
Append(const wxChar * psz)1031 wxString& Append(const wxChar* psz)
1032 { append(psz); return *this; }
1033 // append count copies of given character
1034 wxString& Append(wxChar ch, size_t count = 1u)
1035 { append(count, ch); return *this; }
Append(const wxChar * psz,size_t nLen)1036 wxString& Append(const wxChar* psz, size_t nLen)
1037 { append(psz, nLen); return *this; }
1038
1039 // prepend a string, return the string itself
Prepend(const wxString & str)1040 wxString& Prepend(const wxString& str)
1041 { *this = str + *this; return *this; }
1042
1043 // non-destructive concatenation
1044 // two strings
1045 friend wxString WXDLLIMPEXP_BASE operator+(const wxString& string1,
1046 const wxString& string2);
1047 // string with a single char
1048 friend wxString WXDLLIMPEXP_BASE operator+(const wxString& string, wxChar ch);
1049 // char with a string
1050 friend wxString WXDLLIMPEXP_BASE operator+(wxChar ch, const wxString& string);
1051 // string with C string
1052 friend wxString WXDLLIMPEXP_BASE operator+(const wxString& string,
1053 const wxChar *psz);
1054 // C string with string
1055 friend wxString WXDLLIMPEXP_BASE operator+(const wxChar *psz,
1056 const wxString& string);
1057
1058 // stream-like functions
1059 // insert an int into string
1060 wxString& operator<<(int i)
1061 { return (*this) << Format(wxT("%d"), i); }
1062 // insert an unsigned int into string
1063 wxString& operator<<(unsigned int ui)
1064 { return (*this) << Format(wxT("%u"), ui); }
1065 // insert a long into string
1066 wxString& operator<<(long l)
1067 { return (*this) << Format(wxT("%ld"), l); }
1068 // insert an unsigned long into string
1069 wxString& operator<<(unsigned long ul)
1070 { return (*this) << Format(wxT("%lu"), ul); }
1071 #if defined wxLongLong_t && !defined wxLongLongIsLong
1072 // insert a long long if they exist and aren't longs
1073 wxString& operator<<(wxLongLong_t ll)
1074 {
1075 const wxChar *fmt = wxT("%") wxLongLongFmtSpec wxT("d");
1076 return (*this) << Format(fmt, ll);
1077 }
1078 // insert an unsigned long long
1079 wxString& operator<<(wxULongLong_t ull)
1080 {
1081 const wxChar *fmt = wxT("%") wxLongLongFmtSpec wxT("u");
1082 return (*this) << Format(fmt , ull);
1083 }
1084 #endif
1085 // insert a float into string
1086 wxString& operator<<(float f)
1087 { return (*this) << Format(wxT("%f"), f); }
1088 // insert a double into string
1089 wxString& operator<<(double d)
1090 { return (*this) << Format(wxT("%g"), d); }
1091
1092 // string comparison
1093 // case-sensitive comparison (returns a value < 0, = 0 or > 0)
1094 int Cmp(const wxChar *psz) const;
1095 int Cmp(const wxString& s) const;
1096 // same as Cmp() but not case-sensitive
1097 int CmpNoCase(const wxChar *psz) const;
1098 int CmpNoCase(const wxString& s) const;
1099 // test for the string equality, either considering case or not
1100 // (if compareWithCase then the case matters)
1101 bool IsSameAs(const wxChar *psz, bool compareWithCase = true) const
1102 { return (compareWithCase ? Cmp(psz) : CmpNoCase(psz)) == 0; }
1103 // comparison with a single character: returns true if equal
1104 bool IsSameAs(wxChar c, bool compareWithCase = true) const
1105 {
1106 return (length() == 1) && (compareWithCase ? GetChar(0u) == c
1107 : wxToupper(GetChar(0u)) == wxToupper(c));
1108 }
1109
1110 // simple sub-string extraction
1111 // return substring starting at nFirst of length nCount (or till the end
1112 // if nCount = default value)
1113 wxString Mid(size_t nFirst, size_t nCount = npos) const;
1114
1115 // operator version of Mid()
operator()1116 wxString operator()(size_t start, size_t len) const
1117 { return Mid(start, len); }
1118
1119 // check if the string starts with the given prefix and return the rest
1120 // of the string in the provided pointer if it is not NULL; otherwise
1121 // return false
1122 bool StartsWith(const wxChar *prefix, wxString *rest = NULL) const;
1123 // check if the string ends with the given suffix and return the
1124 // beginning of the string before the suffix in the provided pointer if
1125 // it is not NULL; otherwise return false
1126 bool EndsWith(const wxChar *suffix, wxString *rest = NULL) const;
1127
1128 // get first nCount characters
1129 wxString Left(size_t nCount) const;
1130 // get last nCount characters
1131 wxString Right(size_t nCount) const;
1132 // get all characters before the first occurance of ch
1133 // (returns the whole string if ch not found)
1134 wxString BeforeFirst(wxChar ch) const;
1135 // get all characters before the last occurence of ch
1136 // (returns empty string if ch not found)
1137 wxString BeforeLast(wxChar ch) const;
1138 // get all characters after the first occurence of ch
1139 // (returns empty string if ch not found)
1140 wxString AfterFirst(wxChar ch) const;
1141 // get all characters after the last occurence of ch
1142 // (returns the whole string if ch not found)
1143 wxString AfterLast(wxChar ch) const;
1144
1145 // for compatibility only, use more explicitly named functions above
Before(wxChar ch)1146 wxString Before(wxChar ch) const { return BeforeLast(ch); }
After(wxChar ch)1147 wxString After(wxChar ch) const { return AfterFirst(ch); }
1148
1149 // case conversion
1150 // convert to upper case in place, return the string itself
1151 wxString& MakeUpper();
1152 // convert to upper case, return the copy of the string
1153 // Here's something to remember: BC++ doesn't like returns in inlines.
1154 wxString Upper() const ;
1155 // convert to lower case in place, return the string itself
1156 wxString& MakeLower();
1157 // convert to lower case, return the copy of the string
1158 wxString Lower() const ;
1159
1160 // trimming/padding whitespace (either side) and truncating
1161 // remove spaces from left or from right (default) side
1162 wxString& Trim(bool bFromRight = true);
1163 // add nCount copies chPad in the beginning or at the end (default)
1164 wxString& Pad(size_t nCount, wxChar chPad = wxT(' '), bool bFromRight = true);
1165
1166 // searching and replacing
1167 // searching (return starting index, or -1 if not found)
1168 int Find(wxChar ch, bool bFromEnd = false) const; // like strchr/strrchr
1169 // searching (return starting index, or -1 if not found)
1170 int Find(const wxChar *pszSub) const; // like strstr
1171 // replace first (or all of bReplaceAll) occurences of substring with
1172 // another string, returns the number of replacements made
1173 size_t Replace(const wxChar *szOld,
1174 const wxChar *szNew,
1175 bool bReplaceAll = true);
1176
1177 // check if the string contents matches a mask containing '*' and '?'
1178 bool Matches(const wxChar *szMask) const;
1179
1180 // conversion to numbers: all functions return true only if the whole
1181 // string is a number and put the value of this number into the pointer
1182 // provided, the base is the numeric base in which the conversion should be
1183 // done and must be comprised between 2 and 36 or be 0 in which case the
1184 // standard C rules apply (leading '0' => octal, "0x" => hex)
1185 // convert to a signed integer
1186 bool ToLong(long *val, int base = 10) const;
1187 // convert to an unsigned integer
1188 bool ToULong(unsigned long *val, int base = 10) const;
1189 // convert to wxLongLong
1190 #if defined(wxLongLong_t)
1191 bool ToLongLong(wxLongLong_t *val, int base = 10) const;
1192 // convert to wxULongLong
1193 bool ToULongLong(wxULongLong_t *val, int base = 10) const;
1194 #endif // wxLongLong_t
1195 // convert to a double
1196 bool ToDouble(double *val) const;
1197
1198
1199
1200 // formatted input/output
1201 // as sprintf(), returns the number of characters written or < 0 on error
1202 // (take 'this' into account in attribute parameter count)
1203 int Printf(const wxChar *pszFormat, ...) ATTRIBUTE_PRINTF_2;
1204 // as vprintf(), returns the number of characters written or < 0 on error
1205 int PrintfV(const wxChar* pszFormat, va_list argptr);
1206
1207 // returns the string containing the result of Printf() to it
1208 static wxString Format(const wxChar *pszFormat, ...) ATTRIBUTE_PRINTF_1;
1209 // the same as above, but takes a va_list
1210 static wxString FormatV(const wxChar *pszFormat, va_list argptr);
1211
1212 // raw access to string memory
1213 // ensure that string has space for at least nLen characters
1214 // only works if the data of this string is not shared
Alloc(size_t nLen)1215 bool Alloc(size_t nLen) { reserve(nLen); /*return capacity() >= nLen;*/ return true; }
1216 // minimize the string's memory
1217 // only works if the data of this string is not shared
1218 bool Shrink();
1219 #if !wxUSE_STL
1220 // get writable buffer of at least nLen bytes. Unget() *must* be called
1221 // a.s.a.p. to put string back in a reasonable state!
1222 wxChar *GetWriteBuf(size_t nLen);
1223 // call this immediately after GetWriteBuf() has been used
1224 void UngetWriteBuf();
1225 void UngetWriteBuf(size_t nLen);
1226 #endif
1227
1228 // wxWidgets version 1 compatibility functions
1229
1230 // use Mid()
SubString(size_t from,size_t to)1231 wxString SubString(size_t from, size_t to) const
1232 { return Mid(from, (to - from + 1)); }
1233 // values for second parameter of CompareTo function
1234 enum caseCompare {exact, ignoreCase};
1235 // values for first parameter of Strip function
1236 enum stripType {leading = 0x1, trailing = 0x2, both = 0x3};
1237
1238 // use Printf()
1239 // (take 'this' into account in attribute parameter count)
1240 int sprintf(const wxChar *pszFormat, ...) ATTRIBUTE_PRINTF_2;
1241
1242 // use Cmp()
1243 inline int CompareTo(const wxChar* psz, caseCompare cmp = exact) const
1244 { return cmp == exact ? Cmp(psz) : CmpNoCase(psz); }
1245
1246 // use Len
Length()1247 size_t Length() const { return length(); }
1248 // Count the number of characters
1249 int Freq(wxChar ch) const;
1250 // use MakeLower
LowerCase()1251 void LowerCase() { MakeLower(); }
1252 // use MakeUpper
UpperCase()1253 void UpperCase() { MakeUpper(); }
1254 // use Trim except that it doesn't change this string
1255 wxString Strip(stripType w = trailing) const;
1256
1257 // use Find (more general variants not yet supported)
Index(const wxChar * psz)1258 size_t Index(const wxChar* psz) const { return Find(psz); }
Index(wxChar ch)1259 size_t Index(wxChar ch) const { return Find(ch); }
1260 // use Truncate
Remove(size_t pos)1261 wxString& Remove(size_t pos) { return Truncate(pos); }
1262 wxString& RemoveLast(size_t n = 1) { return Truncate(length() - n); }
1263
Remove(size_t nStart,size_t nLen)1264 wxString& Remove(size_t nStart, size_t nLen)
1265 { return (wxString&)erase( nStart, nLen ); }
1266
1267 // use Find()
First(const wxChar ch)1268 int First( const wxChar ch ) const { return Find(ch); }
First(const wxChar * psz)1269 int First( const wxChar* psz ) const { return Find(psz); }
First(const wxString & str)1270 int First( const wxString &str ) const { return Find(str); }
Last(const wxChar ch)1271 int Last( const wxChar ch ) const { return Find(ch, true); }
Contains(const wxString & str)1272 bool Contains(const wxString& str) const { return Find(str) != wxNOT_FOUND; }
1273
1274 // use empty()
IsNull()1275 bool IsNull() const { return empty(); }
1276
1277 // std::string compatibility functions
1278
1279 // take nLen chars starting at nPos
wxString(const wxString & str,size_t nPos,size_t nLen)1280 wxString(const wxString& str, size_t nPos, size_t nLen)
1281 : wxStringBase(str, nPos, nLen) { }
1282 // take all characters from pStart to pEnd
wxString(const void * pStart,const void * pEnd)1283 wxString(const void *pStart, const void *pEnd)
1284 : wxStringBase((const wxChar*)pStart, (const wxChar*)pEnd) { }
1285 #if wxUSE_STL
wxString(const_iterator first,const_iterator last)1286 wxString(const_iterator first, const_iterator last)
1287 : wxStringBase(first, last) { }
1288 #endif
1289
1290 // lib.string.modifiers
1291 // append elements str[pos], ..., str[pos+n]
append(const wxString & str,size_t pos,size_t n)1292 wxString& append(const wxString& str, size_t pos, size_t n)
1293 { return (wxString&)wxStringBase::append(str, pos, n); }
1294 // append a string
append(const wxString & str)1295 wxString& append(const wxString& str)
1296 { return (wxString&)wxStringBase::append(str); }
1297 // append first n (or all if n == npos) characters of sz
append(const wxChar * sz)1298 wxString& append(const wxChar *sz)
1299 { return (wxString&)wxStringBase::append(sz); }
append(const wxChar * sz,size_t n)1300 wxString& append(const wxChar *sz, size_t n)
1301 { return (wxString&)wxStringBase::append(sz, n); }
1302 // append n copies of ch
append(size_t n,wxChar ch)1303 wxString& append(size_t n, wxChar ch)
1304 { return (wxString&)wxStringBase::append(n, ch); }
1305 // append from first to last
append(const_iterator first,const_iterator last)1306 wxString& append(const_iterator first, const_iterator last)
1307 { return (wxString&)wxStringBase::append(first, last); }
1308
1309 // same as `this_string = str'
assign(const wxString & str)1310 wxString& assign(const wxString& str)
1311 { return (wxString&)wxStringBase::assign(str); }
1312 // same as ` = str[pos..pos + n]
assign(const wxString & str,size_t pos,size_t n)1313 wxString& assign(const wxString& str, size_t pos, size_t n)
1314 { return (wxString&)wxStringBase::assign(str, pos, n); }
1315 // same as `= first n (or all if n == npos) characters of sz'
assign(const wxChar * sz)1316 wxString& assign(const wxChar *sz)
1317 { return (wxString&)wxStringBase::assign(sz); }
assign(const wxChar * sz,size_t n)1318 wxString& assign(const wxChar *sz, size_t n)
1319 { return (wxString&)wxStringBase::assign(sz, n); }
1320 // same as `= n copies of ch'
assign(size_t n,wxChar ch)1321 wxString& assign(size_t n, wxChar ch)
1322 { return (wxString&)wxStringBase::assign(n, ch); }
1323 // assign from first to last
assign(const_iterator first,const_iterator last)1324 wxString& assign(const_iterator first, const_iterator last)
1325 { return (wxString&)wxStringBase::assign(first, last); }
1326
1327 // string comparison
1328 #if !defined(HAVE_STD_STRING_COMPARE)
1329 int compare(const wxStringBase& str) const;
1330 // comparison with a substring
1331 int compare(size_t nStart, size_t nLen, const wxStringBase& str) const;
1332 // comparison of 2 substrings
1333 int compare(size_t nStart, size_t nLen,
1334 const wxStringBase& str, size_t nStart2, size_t nLen2) const;
1335 // just like strcmp()
1336 int compare(const wxChar* sz) const;
1337 // substring comparison with first nCount characters of sz
1338 int compare(size_t nStart, size_t nLen,
1339 const wxChar* sz, size_t nCount = npos) const;
1340 #endif // !defined HAVE_STD_STRING_COMPARE
1341
1342 // insert another string
insert(size_t nPos,const wxString & str)1343 wxString& insert(size_t nPos, const wxString& str)
1344 { return (wxString&)wxStringBase::insert(nPos, str); }
1345 // insert n chars of str starting at nStart (in str)
insert(size_t nPos,const wxString & str,size_t nStart,size_t n)1346 wxString& insert(size_t nPos, const wxString& str, size_t nStart, size_t n)
1347 { return (wxString&)wxStringBase::insert(nPos, str, nStart, n); }
1348 // insert first n (or all if n == npos) characters of sz
insert(size_t nPos,const wxChar * sz)1349 wxString& insert(size_t nPos, const wxChar *sz)
1350 { return (wxString&)wxStringBase::insert(nPos, sz); }
insert(size_t nPos,const wxChar * sz,size_t n)1351 wxString& insert(size_t nPos, const wxChar *sz, size_t n)
1352 { return (wxString&)wxStringBase::insert(nPos, sz, n); }
1353 // insert n copies of ch
insert(size_t nPos,size_t n,wxChar ch)1354 wxString& insert(size_t nPos, size_t n, wxChar ch)
1355 { return (wxString&)wxStringBase::insert(nPos, n, ch); }
insert(iterator it,wxChar ch)1356 iterator insert(iterator it, wxChar ch)
1357 { return wxStringBase::insert(it, ch); }
insert(iterator it,const_iterator first,const_iterator last)1358 void insert(iterator it, const_iterator first, const_iterator last)
1359 { wxStringBase::insert(it, first, last); }
insert(iterator it,size_type n,wxChar ch)1360 void insert(iterator it, size_type n, wxChar ch)
1361 { wxStringBase::insert(it, n, ch); }
1362
1363 // delete characters from nStart to nStart + nLen
1364 wxString& erase(size_type pos = 0, size_type n = npos)
1365 { return (wxString&)wxStringBase::erase(pos, n); }
erase(iterator first,iterator last)1366 iterator erase(iterator first, iterator last)
1367 { return wxStringBase::erase(first, last); }
erase(iterator first)1368 iterator erase(iterator first)
1369 { return wxStringBase::erase(first); }
1370
1371 #ifdef wxSTRING_BASE_HASNT_CLEAR
clear()1372 void clear() { erase(); }
1373 #endif
1374
1375 // replaces the substring of length nLen starting at nStart
replace(size_t nStart,size_t nLen,const wxChar * sz)1376 wxString& replace(size_t nStart, size_t nLen, const wxChar* sz)
1377 { return (wxString&)wxStringBase::replace(nStart, nLen, sz); }
1378 // replaces the substring of length nLen starting at nStart
replace(size_t nStart,size_t nLen,const wxString & str)1379 wxString& replace(size_t nStart, size_t nLen, const wxString& str)
1380 { return (wxString&)wxStringBase::replace(nStart, nLen, str); }
1381 // replaces the substring with nCount copies of ch
replace(size_t nStart,size_t nLen,size_t nCount,wxChar ch)1382 wxString& replace(size_t nStart, size_t nLen, size_t nCount, wxChar ch)
1383 { return (wxString&)wxStringBase::replace(nStart, nLen, nCount, ch); }
1384 // replaces a substring with another substring
replace(size_t nStart,size_t nLen,const wxString & str,size_t nStart2,size_t nLen2)1385 wxString& replace(size_t nStart, size_t nLen,
1386 const wxString& str, size_t nStart2, size_t nLen2)
1387 { return (wxString&)wxStringBase::replace(nStart, nLen, str,
1388 nStart2, nLen2); }
1389 // replaces the substring with first nCount chars of sz
replace(size_t nStart,size_t nLen,const wxChar * sz,size_t nCount)1390 wxString& replace(size_t nStart, size_t nLen,
1391 const wxChar* sz, size_t nCount)
1392 { return (wxString&)wxStringBase::replace(nStart, nLen, sz, nCount); }
replace(iterator first,iterator last,const_pointer s)1393 wxString& replace(iterator first, iterator last, const_pointer s)
1394 { return (wxString&)wxStringBase::replace(first, last, s); }
replace(iterator first,iterator last,const_pointer s,size_type n)1395 wxString& replace(iterator first, iterator last, const_pointer s,
1396 size_type n)
1397 { return (wxString&)wxStringBase::replace(first, last, s, n); }
replace(iterator first,iterator last,const wxString & s)1398 wxString& replace(iterator first, iterator last, const wxString& s)
1399 { return (wxString&)wxStringBase::replace(first, last, s); }
replace(iterator first,iterator last,size_type n,wxChar c)1400 wxString& replace(iterator first, iterator last, size_type n, wxChar c)
1401 { return (wxString&)wxStringBase::replace(first, last, n, c); }
replace(iterator first,iterator last,const_iterator first1,const_iterator last1)1402 wxString& replace(iterator first, iterator last,
1403 const_iterator first1, const_iterator last1)
1404 { return (wxString&)wxStringBase::replace(first, last, first1, last1); }
1405
1406 // string += string
1407 wxString& operator+=(const wxString& s)
1408 { return (wxString&)wxStringBase::operator+=(s); }
1409 // string += C string
1410 wxString& operator+=(const wxChar *psz)
1411 { return (wxString&)wxStringBase::operator+=(psz); }
1412 // string += char
1413 wxString& operator+=(wxChar ch)
1414 { return (wxString&)wxStringBase::operator+=(ch); }
1415 };
1416
1417 // notice that even though for many compilers the friend declarations above are
1418 // enough, from the point of view of C++ standard we must have the declarations
1419 // here as friend ones are not injected in the enclosing namespace and without
1420 // them the code fails to compile with conforming compilers such as xlC or g++4
1421 wxString WXDLLIMPEXP_BASE operator+(const wxString& string1, const wxString& string2);
1422 wxString WXDLLIMPEXP_BASE operator+(const wxString& string, wxChar ch);
1423 wxString WXDLLIMPEXP_BASE operator+(wxChar ch, const wxString& string);
1424 wxString WXDLLIMPEXP_BASE operator+(const wxString& string, const wxChar *psz);
1425 wxString WXDLLIMPEXP_BASE operator+(const wxChar *psz, const wxString& string);
1426
1427
1428 // define wxArrayString, for compatibility
1429 #if WXWIN_COMPATIBILITY_2_4 && !wxUSE_STL
1430 #include "wx/arrstr.h"
1431 #endif
1432
1433 #if wxUSE_STL
1434 // return an empty wxString (not very useful with wxUSE_STL == 1)
wxGetEmptyString()1435 inline const wxString wxGetEmptyString() { return wxString(); }
1436 #else // !wxUSE_STL
1437 // return an empty wxString (more efficient than wxString() here)
wxGetEmptyString()1438 inline const wxString& wxGetEmptyString()
1439 {
1440 return *(wxString *)&wxEmptyString;
1441 }
1442 #endif // wxUSE_STL/!wxUSE_STL
1443
1444 // ----------------------------------------------------------------------------
1445 // wxStringBuffer: a tiny class allowing to get a writable pointer into string
1446 // ----------------------------------------------------------------------------
1447
1448 #if wxUSE_STL
1449
1450 class WXDLLIMPEXP_BASE wxStringBuffer
1451 {
1452 public:
1453 wxStringBuffer(wxString& str, size_t lenWanted = 1024)
m_str(str)1454 : m_str(str), m_buf(lenWanted)
1455 { }
1456
~wxStringBuffer()1457 ~wxStringBuffer() { m_str.assign(m_buf.data(), wxStrlen(m_buf.data())); }
1458
1459 operator wxChar*() { return m_buf.data(); }
1460
1461 private:
1462 wxString& m_str;
1463 #if wxUSE_UNICODE
1464 wxWCharBuffer m_buf;
1465 #else
1466 wxCharBuffer m_buf;
1467 #endif
1468
1469 DECLARE_NO_COPY_CLASS(wxStringBuffer)
1470 };
1471
1472 class WXDLLIMPEXP_BASE wxStringBufferLength
1473 {
1474 public:
1475 wxStringBufferLength(wxString& str, size_t lenWanted = 1024)
m_str(str)1476 : m_str(str), m_buf(lenWanted), m_len(0), m_lenSet(false)
1477 { }
1478
~wxStringBufferLength()1479 ~wxStringBufferLength()
1480 {
1481 wxASSERT(m_lenSet);
1482 m_str.assign(m_buf.data(), m_len);
1483 }
1484
1485 operator wxChar*() { return m_buf.data(); }
SetLength(size_t length)1486 void SetLength(size_t length) { m_len = length; m_lenSet = true; }
1487
1488 private:
1489 wxString& m_str;
1490 #if wxUSE_UNICODE
1491 wxWCharBuffer m_buf;
1492 #else
1493 wxCharBuffer m_buf;
1494 #endif
1495 size_t m_len;
1496 bool m_lenSet;
1497
1498 DECLARE_NO_COPY_CLASS(wxStringBufferLength)
1499 };
1500
1501 #else // if !wxUSE_STL
1502
1503 class WXDLLIMPEXP_BASE wxStringBuffer
1504 {
1505 public:
1506 wxStringBuffer(wxString& str, size_t lenWanted = 1024)
m_str(str)1507 : m_str(str), m_buf(NULL)
1508 { m_buf = m_str.GetWriteBuf(lenWanted); }
1509
~wxStringBuffer()1510 ~wxStringBuffer() { m_str.UngetWriteBuf(); }
1511
1512 operator wxChar*() const { return m_buf; }
1513
1514 private:
1515 wxString& m_str;
1516 wxChar *m_buf;
1517
1518 DECLARE_NO_COPY_CLASS(wxStringBuffer)
1519 };
1520
1521 class WXDLLIMPEXP_BASE wxStringBufferLength
1522 {
1523 public:
1524 wxStringBufferLength(wxString& str, size_t lenWanted = 1024)
m_str(str)1525 : m_str(str), m_buf(NULL), m_len(0), m_lenSet(false)
1526 {
1527 m_buf = m_str.GetWriteBuf(lenWanted);
1528 wxASSERT(m_buf != NULL);
1529 }
1530
~wxStringBufferLength()1531 ~wxStringBufferLength()
1532 {
1533 wxASSERT(m_lenSet);
1534 m_str.UngetWriteBuf(m_len);
1535 }
1536
1537 operator wxChar*() const { return m_buf; }
SetLength(size_t length)1538 void SetLength(size_t length) { m_len = length; m_lenSet = true; }
1539
1540 private:
1541 wxString& m_str;
1542 wxChar *m_buf;
1543 size_t m_len;
1544 bool m_lenSet;
1545
1546 DECLARE_NO_COPY_CLASS(wxStringBufferLength)
1547 };
1548
1549 #endif // !wxUSE_STL
1550
1551 // ---------------------------------------------------------------------------
1552 // wxString comparison functions: operator versions are always case sensitive
1553 // ---------------------------------------------------------------------------
1554
1555 // note that when wxUSE_STL == 1 the comparison operators taking std::string
1556 // are used and defining them also for wxString would only result in
1557 // compilation ambiguities when comparing std::string and wxString
1558 #if !wxUSE_STL
1559
1560 inline bool operator==(const wxString& s1, const wxString& s2)
1561 { return (s1.Len() == s2.Len()) && (s1.Cmp(s2) == 0); }
1562 inline bool operator==(const wxString& s1, const wxChar * s2)
1563 { return s1.Cmp(s2) == 0; }
1564 inline bool operator==(const wxChar * s1, const wxString& s2)
1565 { return s2.Cmp(s1) == 0; }
1566 inline bool operator!=(const wxString& s1, const wxString& s2)
1567 { return (s1.Len() != s2.Len()) || (s1.Cmp(s2) != 0); }
1568 inline bool operator!=(const wxString& s1, const wxChar * s2)
1569 { return s1.Cmp(s2) != 0; }
1570 inline bool operator!=(const wxChar * s1, const wxString& s2)
1571 { return s2.Cmp(s1) != 0; }
1572 inline bool operator< (const wxString& s1, const wxString& s2)
1573 { return s1.Cmp(s2) < 0; }
1574 inline bool operator< (const wxString& s1, const wxChar * s2)
1575 { return s1.Cmp(s2) < 0; }
1576 inline bool operator< (const wxChar * s1, const wxString& s2)
1577 { return s2.Cmp(s1) > 0; }
1578 inline bool operator> (const wxString& s1, const wxString& s2)
1579 { return s1.Cmp(s2) > 0; }
1580 inline bool operator> (const wxString& s1, const wxChar * s2)
1581 { return s1.Cmp(s2) > 0; }
1582 inline bool operator> (const wxChar * s1, const wxString& s2)
1583 { return s2.Cmp(s1) < 0; }
1584 inline bool operator<=(const wxString& s1, const wxString& s2)
1585 { return s1.Cmp(s2) <= 0; }
1586 inline bool operator<=(const wxString& s1, const wxChar * s2)
1587 { return s1.Cmp(s2) <= 0; }
1588 inline bool operator<=(const wxChar * s1, const wxString& s2)
1589 { return s2.Cmp(s1) >= 0; }
1590 inline bool operator>=(const wxString& s1, const wxString& s2)
1591 { return s1.Cmp(s2) >= 0; }
1592 inline bool operator>=(const wxString& s1, const wxChar * s2)
1593 { return s1.Cmp(s2) >= 0; }
1594 inline bool operator>=(const wxChar * s1, const wxString& s2)
1595 { return s2.Cmp(s1) <= 0; }
1596
1597 #if wxUSE_UNICODE
1598 inline bool operator==(const wxString& s1, const wxWCharBuffer& s2)
1599 { return (s1.Cmp((const wchar_t *)s2) == 0); }
1600 inline bool operator==(const wxWCharBuffer& s1, const wxString& s2)
1601 { return (s2.Cmp((const wchar_t *)s1) == 0); }
1602 inline bool operator!=(const wxString& s1, const wxWCharBuffer& s2)
1603 { return (s1.Cmp((const wchar_t *)s2) != 0); }
1604 inline bool operator!=(const wxWCharBuffer& s1, const wxString& s2)
1605 { return (s2.Cmp((const wchar_t *)s1) != 0); }
1606 #else // !wxUSE_UNICODE
1607 inline bool operator==(const wxString& s1, const wxCharBuffer& s2)
1608 { return (s1.Cmp((const char *)s2) == 0); }
1609 inline bool operator==(const wxCharBuffer& s1, const wxString& s2)
1610 { return (s2.Cmp((const char *)s1) == 0); }
1611 inline bool operator!=(const wxString& s1, const wxCharBuffer& s2)
1612 { return (s1.Cmp((const char *)s2) != 0); }
1613 inline bool operator!=(const wxCharBuffer& s1, const wxString& s2)
1614 { return (s2.Cmp((const char *)s1) != 0); }
1615 #endif // wxUSE_UNICODE/!wxUSE_UNICODE
1616
1617 #if wxUSE_UNICODE
1618 inline wxString operator+(const wxString& string, const wxWCharBuffer& buf)
1619 { return string + (const wchar_t *)buf; }
1620 inline wxString operator+(const wxWCharBuffer& buf, const wxString& string)
1621 { return (const wchar_t *)buf + string; }
1622 #else // !wxUSE_UNICODE
1623 inline wxString operator+(const wxString& string, const wxCharBuffer& buf)
1624 { return string + (const char *)buf; }
1625 inline wxString operator+(const wxCharBuffer& buf, const wxString& string)
1626 { return (const char *)buf + string; }
1627 #endif // wxUSE_UNICODE/!wxUSE_UNICODE
1628
1629 #endif // !wxUSE_STL
1630
1631 // comparison with char (those are not defined by std::[w]string and so should
1632 // be always available)
1633 inline bool operator==(wxChar c, const wxString& s) { return s.IsSameAs(c); }
1634 inline bool operator==(const wxString& s, wxChar c) { return s.IsSameAs(c); }
1635 inline bool operator!=(wxChar c, const wxString& s) { return !s.IsSameAs(c); }
1636 inline bool operator!=(const wxString& s, wxChar c) { return !s.IsSameAs(c); }
1637
1638 // ---------------------------------------------------------------------------
1639 // Implementation only from here until the end of file
1640 // ---------------------------------------------------------------------------
1641
1642 // don't pollute the library user's name space
1643 #undef wxASSERT_VALID_INDEX
1644
1645 #if wxUSE_STD_IOSTREAM
1646
1647 #include "wx/iosfwrap.h"
1648
1649 WXDLLIMPEXP_BASE wxSTD ostream& operator<<(wxSTD ostream&, const wxString&);
1650
1651 #endif // wxSTD_STRING_COMPATIBILITY
1652
1653 #endif // _WX_WXSTRINGH__
1654