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