]> git.saurik.com Git - wxWidgets.git/blob - include/wx/string.h
use UTF8-encoded char* strings in UTF8 build instead of wchar_t* if the current local...
[wxWidgets.git] / include / wx / string.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/string.h
3 // Purpose: wxString class
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 29/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 /*
13 Efficient string class [more or less] compatible with MFC CString,
14 wxWidgets version 1 wxString and std::string and some handy functions
15 missing from string.h.
16 */
17
18 #ifndef _WX_WXSTRING_H__
19 #define _WX_WXSTRING_H__
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/wxcrt.h" // for wxChar, wxStrlen() etc.
55 #include "wx/strvararg.h"
56 #include "wx/buffer.h" // for wxCharBuffer
57 #include "wx/strconv.h" // for wxConvertXXX() macros and wxMBConv classes
58 #include "wx/stringimpl.h"
59 #include "wx/stringops.h"
60 #include "wx/unichar.h"
61
62 class WXDLLIMPEXP_BASE wxString;
63
64 // unless this symbol is predefined to disable the compatibility functions, do
65 // use them
66 #ifndef WXWIN_COMPATIBILITY_STRING_PTR_AS_ITER
67 #define WXWIN_COMPATIBILITY_STRING_PTR_AS_ITER 1
68 #endif
69
70 // ---------------------------------------------------------------------------
71 // macros
72 // ---------------------------------------------------------------------------
73
74 // casts [unfortunately!] needed to call some broken functions which require
75 // "char *" instead of "const char *"
76 #define WXSTRINGCAST (wxChar *)(const wxChar *)
77 #define wxCSTRINGCAST (wxChar *)(const wxChar *)
78 #define wxMBSTRINGCAST (char *)(const char *)
79 #define wxWCSTRINGCAST (wchar_t *)(const wchar_t *)
80
81 // ----------------------------------------------------------------------------
82 // constants
83 // ----------------------------------------------------------------------------
84
85 #if WXWIN_COMPATIBILITY_2_6
86
87 // deprecated in favour of wxString::npos, don't use in new code
88 //
89 // maximum possible length for a string means "take all string" everywhere
90 #define wxSTRING_MAXLEN wxString::npos
91
92 #endif // WXWIN_COMPATIBILITY_2_6
93
94 // ---------------------------------------------------------------------------
95 // global functions complementing standard C string library replacements for
96 // strlen() and portable strcasecmp()
97 //---------------------------------------------------------------------------
98
99 #if WXWIN_COMPATIBILITY_2_8
100 // Use wxXXX() functions from wxcrt.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
104 wxDEPRECATED( inline bool IsEmpty(const char *p) );
105 inline bool IsEmpty(const char *p) { return (!p || !*p); }
106
107 // safe version of strlen() (returns 0 if passed NULL pointer)
108 wxDEPRECATED( inline size_t Strlen(const char *psz) );
109 inline size_t Strlen(const char *psz)
110 { return psz ? strlen(psz) : 0; }
111
112 // portable strcasecmp/_stricmp
113 wxDEPRECATED( inline int Stricmp(const char *psz1, const char *psz2) );
114 inline int Stricmp(const char *psz1, const char *psz2)
115 {
116 #if defined(__VISUALC__) && defined(__WXWINCE__)
117 register char c1, c2;
118 do {
119 c1 = tolower(*psz1++);
120 c2 = tolower(*psz2++);
121 } while ( c1 && (c1 == c2) );
122
123 return c1 - c2;
124 #elif defined(__VISUALC__) || ( defined(__MWERKS__) && defined(__INTEL__) )
125 return _stricmp(psz1, psz2);
126 #elif defined(__SC__)
127 return _stricmp(psz1, psz2);
128 #elif defined(__SALFORDC__)
129 return stricmp(psz1, psz2);
130 #elif defined(__BORLANDC__)
131 return stricmp(psz1, psz2);
132 #elif defined(__WATCOMC__)
133 return stricmp(psz1, psz2);
134 #elif defined(__DJGPP__)
135 return stricmp(psz1, psz2);
136 #elif defined(__EMX__)
137 return stricmp(psz1, psz2);
138 #elif defined(__WXPM__)
139 return stricmp(psz1, psz2);
140 #elif defined(__WXPALMOS__) || \
141 defined(HAVE_STRCASECMP_IN_STRING_H) || \
142 defined(HAVE_STRCASECMP_IN_STRINGS_H) || \
143 defined(__GNUWIN32__)
144 return strcasecmp(psz1, psz2);
145 #elif defined(__MWERKS__) && !defined(__INTEL__)
146 register char c1, c2;
147 do {
148 c1 = tolower(*psz1++);
149 c2 = tolower(*psz2++);
150 } while ( c1 && (c1 == c2) );
151
152 return c1 - c2;
153 #else
154 // almost all compilers/libraries provide this function (unfortunately under
155 // different names), that's why we don't implement our own which will surely
156 // be more efficient than this code (uncomment to use):
157 /*
158 register char c1, c2;
159 do {
160 c1 = tolower(*psz1++);
161 c2 = tolower(*psz2++);
162 } while ( c1 && (c1 == c2) );
163
164 return c1 - c2;
165 */
166
167 #error "Please define string case-insensitive compare for your OS/compiler"
168 #endif // OS/compiler
169 }
170
171 #endif // WXWIN_COMPATIBILITY_2_8
172
173 // ----------------------------------------------------------------------------
174 // wxCStrData
175 // ----------------------------------------------------------------------------
176
177 // Lightweight object returned by wxString::c_str() and implicitly convertible
178 // to either const char* or const wchar_t*.
179 class WXDLLIMPEXP_BASE wxCStrData
180 {
181 private:
182 // Ctors; for internal use by wxString and wxCStrData only
183 wxCStrData(const wxString *str, size_t offset = 0, bool owned = false)
184 : m_str(str), m_offset(offset), m_owned(owned) {}
185
186 public:
187 // Ctor constructs the object from char literal; they are needed to make
188 // operator?: compile and they intentionally take char*, not const char*
189 wxCStrData(char *buf);
190 wxCStrData(wchar_t *buf);
191
192 inline ~wxCStrData();
193
194 // methods defined inline below must be declared inline or mingw32 3.4.5
195 // warns about "<symbol> defined locally after being referenced with
196 // dllimport linkage"
197 #if wxUSE_UNICODE_WCHAR
198 inline
199 #endif
200 const wchar_t* AsWChar() const;
201 operator const wchar_t*() const { return AsWChar(); }
202
203 #if !wxUSE_UNICODE
204 inline
205 #endif
206 const char* AsChar() const;
207 const unsigned char* AsUnsignedChar() const
208 { return (const unsigned char *) AsChar(); }
209 operator const char*() const { return AsChar(); }
210 operator const unsigned char*() const { return AsUnsignedChar(); }
211
212 operator const void*() const { return AsChar(); }
213
214 inline const wxCharBuffer AsCharBuf() const;
215 inline const wxWCharBuffer AsWCharBuf() const;
216
217 inline wxString AsString() const;
218
219 // returns the value as C string in internal representation (equivalent
220 // to AsString().wx_str(), but more efficient)
221 const wxStringCharType *AsInternal() const;
222
223 // allow expressions like "c_str()[0]":
224 inline wxUniChar operator[](size_t n) const;
225 wxUniChar operator[](int n) const { return operator[](size_t(n)); }
226 wxUniChar operator[](long n) const { return operator[](size_t(n)); }
227 #ifndef wxSIZE_T_IS_UINT
228 wxUniChar operator[](unsigned int n) const { return operator[](size_t(n)); }
229 #endif // size_t != unsigned int
230
231 // these operators are needed to emulate the pointer semantics of c_str():
232 // expressions like "wxChar *p = str.c_str() + 1;" should continue to work
233 // (we need both versions to resolve ambiguities):
234 wxCStrData operator+(int n) const
235 { return wxCStrData(m_str, m_offset + n, m_owned); }
236 wxCStrData operator+(long n) const
237 { return wxCStrData(m_str, m_offset + n, m_owned); }
238 wxCStrData operator+(size_t n) const
239 { return wxCStrData(m_str, m_offset + n, m_owned); }
240
241 // and these for "str.c_str() + n - 2":
242 wxCStrData operator-(int n) const
243 {
244 wxASSERT_MSG( n <= (int)m_offset,
245 _T("attempt to construct address before the beginning of the string") );
246 return wxCStrData(m_str, m_offset - n, m_owned);
247 }
248 wxCStrData operator-(long n) const
249 {
250 wxASSERT_MSG( n <= (int)m_offset,
251 _T("attempt to construct address before the beginning of the string") );
252 return wxCStrData(m_str, m_offset - n, m_owned);
253 }
254 wxCStrData operator-(size_t n) const
255 {
256 wxASSERT_MSG( n <= m_offset,
257 _T("attempt to construct address before the beginning of the string") );
258 return wxCStrData(m_str, m_offset - n, m_owned);
259 }
260
261 // this operator is needed to make expressions like "*c_str()" or
262 // "*(c_str() + 2)" work
263 inline wxUniChar operator*() const;
264
265 private:
266 const wxString *m_str;
267 size_t m_offset;
268 bool m_owned;
269
270 friend class WXDLLIMPEXP_BASE wxString;
271 };
272
273 // ----------------------------------------------------------------------------
274 // wxStringPrintfMixin
275 // ---------------------------------------------------------------------------
276
277 // NB: VC6 has a bug that causes linker errors if you have template methods
278 // in a class using __declspec(dllimport). The solution is to split such
279 // class into two classes, one that contains the template methods and does
280 // *not* use WXDLLIMPEXP_BASE and another class that contains the rest
281 // (with DLL linkage).
282 //
283 // We only do this for VC6 here, because the code is less efficient
284 // (Printf() has to use dynamic_cast<>) and because OpenWatcom compiler
285 // cannot compile this code.
286
287 #if defined(__VISUALC__) && __VISUALC__ < 1300
288 #define wxNEEDS_WXSTRING_PRINTF_MIXIN
289 #endif
290
291 #ifdef wxNEEDS_WXSTRING_PRINTF_MIXIN
292 // this class contains implementation of wxString's vararg methods, it's
293 // exported from wxBase DLL
294 class WXDLLIMPEXP_BASE wxStringPrintfMixinBase
295 {
296 protected:
297 wxStringPrintfMixinBase() {}
298
299 int DoPrintf(const wxString& format, ...);
300 static wxString DoFormat(const wxString& format, ...);
301 };
302
303 // this class contains template wrappers for wxString's vararg methods, it's
304 // intentionally *not* exported from the DLL in order to fix the VC6 bug
305 // described above
306 class wxStringPrintfMixin : public wxStringPrintfMixinBase
307 {
308 private:
309 // to further complicate things, we can't return wxString from
310 // wxStringPrintfMixin::Format() because wxString is not yet declared at
311 // this point; the solution is to use this fake type trait template - this
312 // way the compiler won't know the return type until Format() is used
313 // (this doesn't compile with Watcom, but VC6 compiles it just fine):
314 template<typename T> struct StringReturnType
315 {
316 typedef wxString type;
317 };
318
319 public:
320 // these are duplicated wxString methods, they're also declared below
321 // if !wxNEEDS_WXSTRING_PRINTF_MIXIN:
322
323 // static wxString Format(const wString& format, ...) ATTRIBUTE_PRINTF_1;
324 WX_DEFINE_VARARG_FUNC2_SANS_N0(static typename StringReturnType<T1>::type,
325 Format, 1, (const wxString&),
326 DoFormat, DoFormat)
327 // We have to implement the version without template arguments manually
328 // because of the StringReturnType<> hack, although WX_DEFINE_VARARG_FUNC
329 // normally does it itself. It has to be a template so that we can use
330 // the hack, even though there's no real template parameter:
331 struct FormatDummyArg {} ;
332
333 template<typename T>
334 inline static typename StringReturnType<T>::type
335 Format(const wxString& fmt, FormatDummyArg dummy = FormatDummyArg())
336 {
337 return DoFormat(fmt);
338 }
339
340 // int Printf(const wxString& format, ...);
341 WX_DEFINE_VARARG_FUNC(int, Printf, 1, (const wxString&), DoPrintf)
342 // int sprintf(const wxString& format, ...) ATTRIBUTE_PRINTF_2;
343 WX_DEFINE_VARARG_FUNC(int, sprintf, 1, (const wxString&), DoPrintf)
344
345 protected:
346 wxStringPrintfMixin() : wxStringPrintfMixinBase() {}
347 };
348 #endif // wxNEEDS_WXSTRING_PRINTF_MIXIN
349
350
351 // ----------------------------------------------------------------------------
352 // wxString: string class trying to be compatible with std::string, MFC
353 // CString and wxWindows 1.x wxString all at once
354 // ---------------------------------------------------------------------------
355
356 #ifdef wxNEEDS_WXSTRING_PRINTF_MIXIN
357 // "non dll-interface class 'wxStringPrintfMixin' used as base interface
358 // for dll-interface class 'wxString'" -- this is OK in our case
359 #pragma warning (disable:4275)
360 #endif
361
362 class WXDLLIMPEXP_BASE wxString
363 #ifdef wxNEEDS_WXSTRING_PRINTF_MIXIN
364 : public wxStringPrintfMixin
365 #endif
366 {
367 // NB: special care was taken in arranging the member functions in such order
368 // that all inline functions can be effectively inlined, verify that all
369 // performance critical functions are still inlined if you change order!
370 public:
371 // an 'invalid' value for string index, moved to this place due to a CW bug
372 static const size_t npos;
373
374 private:
375 // if we hadn't made these operators private, it would be possible to
376 // compile "wxString s; s = 17;" without any warnings as 17 is implicitly
377 // converted to char in C and we do have operator=(char)
378 //
379 // NB: we don't need other versions (short/long and unsigned) as attempt
380 // to assign another numeric type to wxString will now result in
381 // ambiguity between operator=(char) and operator=(int)
382 wxString& operator=(int);
383
384 // these methods are not implemented - there is _no_ conversion from int to
385 // string, you're doing something wrong if the compiler wants to call it!
386 //
387 // try `s << i' or `s.Printf("%d", i)' instead
388 wxString(int);
389
390
391 // buffer for holding temporary substring when using any of the methods
392 // that take (char*,size_t) or (wchar_t*,size_t) arguments:
393 template<typename T>
394 struct SubstrBufFromType
395 {
396 T data;
397 size_t len;
398
399 SubstrBufFromType(const T& data_, size_t len_)
400 : data(data_), len(len_) {}
401 };
402
403 #if wxUSE_UNICODE_UTF8
404 // even char* -> char* needs conversion, from locale charset to UTF-8
405 typedef SubstrBufFromType<wxCharBuffer> SubstrBufFromWC;
406 typedef SubstrBufFromType<wxCharBuffer> SubstrBufFromMB;
407 #elif wxUSE_UNICODE_WCHAR
408 typedef SubstrBufFromType<const wchar_t*> SubstrBufFromWC;
409 typedef SubstrBufFromType<wxWCharBuffer> SubstrBufFromMB;
410 #else
411 typedef SubstrBufFromType<const char*> SubstrBufFromMB;
412 typedef SubstrBufFromType<wxCharBuffer> SubstrBufFromWC;
413 #endif
414
415
416 // Functions implementing primitive operations on string data; wxString
417 // methods and iterators are implemented in terms of it. The differences
418 // between UTF-8 and wchar_t* representations of the string are mostly
419 // contained here.
420
421 #if wxUSE_UNICODE_UTF8
422 static SubstrBufFromMB ConvertStr(const char *psz, size_t nLength,
423 const wxMBConv& conv);
424 static SubstrBufFromWC ConvertStr(const wchar_t *pwz, size_t nLength,
425 const wxMBConv& conv);
426 #elif wxUSE_UNICODE_WCHAR
427 static SubstrBufFromMB ConvertStr(const char *psz, size_t nLength,
428 const wxMBConv& conv);
429 #else
430 static SubstrBufFromWC ConvertStr(const wchar_t *pwz, size_t nLength,
431 const wxMBConv& conv);
432 #endif
433
434 #if !wxUSE_UNICODE_UTF8 // wxUSE_UNICODE_WCHAR or !wxUSE_UNICODE
435 // returns C string encoded as the implementation expects:
436 #if wxUSE_UNICODE
437 static const wchar_t* ImplStr(const wchar_t* str)
438 { return str ? str : wxT(""); }
439 static const SubstrBufFromWC ImplStr(const wchar_t* str, size_t n)
440 { return SubstrBufFromWC(str, (str && n == npos) ? wxWcslen(str) : n); }
441 static wxWCharBuffer ImplStr(const char* str,
442 const wxMBConv& conv = wxConvLibc)
443 { return ConvertStr(str, npos, conv).data; }
444 static SubstrBufFromMB ImplStr(const char* str, size_t n,
445 const wxMBConv& conv = wxConvLibc)
446 { return ConvertStr(str, n, conv); }
447 #else
448 static const char* ImplStr(const char* str,
449 const wxMBConv& WXUNUSED(conv) = wxConvLibc)
450 { return str ? str : ""; }
451 static const SubstrBufFromMB ImplStr(const char* str, size_t n,
452 const wxMBConv& WXUNUSED(conv) = wxConvLibc)
453 { return SubstrBufFromMB(str, (str && n == npos) ? wxStrlen(str) : n); }
454 static wxCharBuffer ImplStr(const wchar_t* str)
455 { return ConvertStr(str, npos, wxConvLibc).data; }
456 static SubstrBufFromWC ImplStr(const wchar_t* str, size_t n)
457 { return ConvertStr(str, n, wxConvLibc); }
458 #endif
459
460 // translates position index in wxString to/from index in underlying
461 // wxStringImpl:
462 static size_t PosToImpl(size_t pos) { return pos; }
463 static void PosLenToImpl(size_t pos, size_t len,
464 size_t *implPos, size_t *implLen)
465 { *implPos = pos; *implLen = len; }
466 static size_t LenToImpl(size_t len) { return len; }
467 static size_t PosFromImpl(size_t pos) { return pos; }
468
469 #else // wxUSE_UNICODE_UTF8
470
471 // FIXME-UTF8: return as-is without copying under UTF8 locale, return
472 // converted string under other locales - needs wxCharBuffer
473 // changes
474 static wxCharBuffer ImplStr(const char* str,
475 const wxMBConv& conv = wxConvLibc)
476 { return ConvertStr(str, npos, conv).data; }
477 static SubstrBufFromMB ImplStr(const char* str, size_t n,
478 const wxMBConv& conv = wxConvLibc)
479 { return ConvertStr(str, n, conv); }
480
481 static wxCharBuffer ImplStr(const wchar_t* str)
482 { return ConvertStr(str, npos, wxConvUTF8).data; }
483 static SubstrBufFromWC ImplStr(const wchar_t* str, size_t n)
484 { return ConvertStr(str, n, wxConvUTF8); }
485
486 size_t PosToImpl(size_t pos) const
487 {
488 if ( pos == 0 || pos == npos )
489 return pos;
490 else
491 return (begin() + pos).impl() - m_impl.begin();
492 }
493
494 void PosLenToImpl(size_t pos, size_t len, size_t *implPos, size_t *implLen) const;
495
496 size_t LenToImpl(size_t len) const
497 {
498 size_t pos, len2;
499 PosLenToImpl(0, len, &pos, &len2);
500 return len2;
501 }
502
503 size_t PosFromImpl(size_t pos) const
504 {
505 if ( pos == 0 || pos == npos )
506 return pos;
507 else
508 return const_iterator(m_impl.begin() + pos) - begin();
509 }
510 #endif // !wxUSE_UNICODE_UTF8/wxUSE_UNICODE_UTF8
511
512 public:
513 // standard types
514 typedef wxUniChar value_type;
515 typedef wxUniChar char_type;
516 typedef wxUniCharRef reference;
517 typedef wxChar* pointer;
518 typedef const wxChar* const_pointer;
519
520 typedef size_t size_type;
521 typedef wxUniChar const_reference;
522
523 #if wxUSE_STL
524 #if wxUSE_UNICODE_UTF8
525 // random access is not O(1), as required by Random Access Iterator
526 #define WX_STR_ITERATOR_TAG std::bidirectional_iterator_tag
527 #else
528 #define WX_STR_ITERATOR_TAG std::random_access_iterator_tag
529 #endif
530 #else
531 #define WX_STR_ITERATOR_TAG void /* dummy type */
532 #endif
533
534 #define WX_STR_ITERATOR_IMPL(iterator_name, pointer_type, \
535 reference_type, reference_ctor) \
536 private: \
537 typedef wxStringImpl::iterator_name underlying_iterator; \
538 public: \
539 typedef WX_STR_ITERATOR_TAG iterator_category; \
540 typedef wxUniChar value_type; \
541 typedef int difference_type; \
542 typedef reference_type reference; \
543 typedef pointer_type pointer; \
544 \
545 reference operator*() const { return reference_ctor; } \
546 reference operator[](size_t n) const { return *(*this + n); } \
547 \
548 iterator_name& operator++() \
549 { wxStringOperations::IncIter(m_cur); return *this; } \
550 iterator_name& operator--() \
551 { wxStringOperations::DecIter(m_cur); return *this; } \
552 iterator_name operator++(int) \
553 { \
554 iterator_name tmp = *this; \
555 wxStringOperations::IncIter(m_cur); \
556 return tmp; \
557 } \
558 iterator_name operator--(int) \
559 { \
560 iterator_name tmp = *this; \
561 wxStringOperations::DecIter(m_cur); \
562 return tmp; \
563 } \
564 \
565 iterator_name& operator+=(int n) \
566 { \
567 m_cur = wxStringOperations::AddToIter(m_cur, n); \
568 return *this; \
569 } \
570 iterator_name& operator+=(size_t n) \
571 { \
572 m_cur = wxStringOperations::AddToIter(m_cur, (int)n); \
573 return *this; \
574 } \
575 iterator_name& operator-=(int n) \
576 { \
577 m_cur = wxStringOperations::AddToIter(m_cur, -n); \
578 return *this; \
579 } \
580 iterator_name& operator-=(size_t n) \
581 { \
582 m_cur = wxStringOperations::AddToIter(m_cur, -(int)n); \
583 return *this; \
584 } \
585 \
586 difference_type operator-(const iterator_name& i) const \
587 { return wxStringOperations::DiffIters(m_cur, i.m_cur); } \
588 \
589 bool operator==(const iterator_name& i) const \
590 { return m_cur == i.m_cur; } \
591 bool operator!=(const iterator_name& i) const \
592 { return m_cur != i.m_cur; } \
593 \
594 bool operator<(const iterator_name& i) const \
595 { return m_cur < i.m_cur; } \
596 bool operator>(const iterator_name& i) const \
597 { return m_cur > i.m_cur; } \
598 bool operator<=(const iterator_name& i) const \
599 { return m_cur <= i.m_cur; } \
600 bool operator>=(const iterator_name& i) const \
601 { return m_cur >= i.m_cur; } \
602 \
603 private: \
604 /* for internal wxString use only: */ \
605 underlying_iterator impl() const { return m_cur; } \
606 \
607 friend class WXDLLIMPEXP_BASE wxString; \
608 friend class WXDLLIMPEXP_BASE wxCStrData; \
609 \
610 private: \
611 underlying_iterator m_cur
612
613 class const_iterator;
614
615 #if wxUSE_UNICODE_UTF8
616 class iterator
617 {
618 // NB: In UTF-8 build, (non-const) iterator needs to keep reference
619 // to the underlying wxStringImpl, because UTF-8 is variable-length
620 // encoding and changing the value pointer to by an iterator using
621 // its operator* requires calling wxStringImpl::replace() if the old
622 // and new values differ in their encoding's length.
623
624 WX_STR_ITERATOR_IMPL(iterator, wxChar*, wxUniCharRef,
625 wxUniCharRef::CreateForString(m_str, m_cur));
626
627 public:
628 iterator(const iterator& i) : m_cur(i.m_cur), m_str(i.m_str) {}
629
630 iterator operator+(int n) const
631 { return iterator(m_str, wxStringOperations::AddToIter(m_cur, n)); }
632 iterator operator+(size_t n) const
633 { return iterator(m_str, wxStringOperations::AddToIter(m_cur, (int)n)); }
634 iterator operator-(int n) const
635 { return iterator(m_str, wxStringOperations::AddToIter(m_cur, -n)); }
636 iterator operator-(size_t n) const
637 { return iterator(m_str, wxStringOperations::AddToIter(m_cur, -(int)n)); }
638
639 private:
640 iterator(wxString *str, underlying_iterator ptr)
641 : m_cur(ptr), m_str(str->m_impl) {}
642 iterator(wxStringImpl& str, underlying_iterator ptr)
643 : m_cur(ptr), m_str(str) {}
644
645 wxStringImpl& m_str;
646
647 friend class const_iterator;
648 };
649
650 size_t IterToImplPos(wxString::iterator i) const
651 { return wxStringImpl::const_iterator(i.impl()) - m_impl.begin(); }
652
653 #else // !wxUSE_UNICODE_UTF8
654
655 class iterator
656 {
657 WX_STR_ITERATOR_IMPL(iterator, wxChar*, wxUniCharRef,
658 wxUniCharRef::CreateForString(m_cur));
659
660 public:
661 iterator(const iterator& i) : m_cur(i.m_cur) {}
662
663 iterator operator+(int n) const
664 { return iterator(wxStringOperations::AddToIter(m_cur, n)); }
665 iterator operator+(size_t n) const
666 { return iterator(wxStringOperations::AddToIter(m_cur, (int)n)); }
667 iterator operator-(int n) const
668 { return iterator(wxStringOperations::AddToIter(m_cur, -n)); }
669 iterator operator-(size_t n) const
670 { return iterator(wxStringOperations::AddToIter(m_cur, -(int)n)); }
671
672 private:
673 // for internal wxString use only:
674 iterator(underlying_iterator ptr) : m_cur(ptr) {}
675 iterator(wxString *WXUNUSED(str), underlying_iterator ptr) : m_cur(ptr) {}
676
677 friend class const_iterator;
678 };
679 #endif // wxUSE_UNICODE_UTF8/!wxUSE_UNICODE_UTF8
680
681 class const_iterator
682 {
683 // NB: reference_type is intentionally value, not reference, the character
684 // may be encoded differently in wxString data:
685 WX_STR_ITERATOR_IMPL(const_iterator, const wxChar*, wxUniChar,
686 wxStringOperations::DecodeChar(m_cur));
687
688 public:
689 const_iterator(const const_iterator& i) : m_cur(i.m_cur) {}
690 const_iterator(const iterator& i) : m_cur(i.m_cur) {}
691
692 const_iterator operator+(int n) const
693 { return const_iterator(wxStringOperations::AddToIter(m_cur, n)); }
694 const_iterator operator+(size_t n) const
695 { return const_iterator(wxStringOperations::AddToIter(m_cur, (int)n)); }
696 const_iterator operator-(int n) const
697 { return const_iterator(wxStringOperations::AddToIter(m_cur, -n)); }
698 const_iterator operator-(size_t n) const
699 { return const_iterator(wxStringOperations::AddToIter(m_cur, -(int)n)); }
700
701 private:
702 // for internal wxString use only:
703 const_iterator(underlying_iterator ptr) : m_cur(ptr) {}
704 };
705
706 #undef WX_STR_ITERATOR_TAG
707 #undef WX_STR_ITERATOR_IMPL
708
709 friend class iterator;
710 friend class const_iterator;
711
712 template <typename T>
713 class reverse_iterator_impl
714 {
715 public:
716 typedef T iterator_type;
717
718 typedef typename T::iterator_category iterator_category;
719 typedef typename T::value_type value_type;
720 typedef typename T::difference_type difference_type;
721 typedef typename T::reference reference;
722 typedef typename T::pointer *pointer;
723
724 reverse_iterator_impl(iterator_type i) : m_cur(i) {}
725 reverse_iterator_impl(const reverse_iterator_impl& ri)
726 : m_cur(ri.m_cur) {}
727
728 iterator_type base() const { return m_cur; }
729
730 reference operator*() const { return *(m_cur-1); }
731 reference operator[](size_t n) const { return *(*this + n); }
732
733 reverse_iterator_impl& operator++()
734 { --m_cur; return *this; }
735 reverse_iterator_impl operator++(int)
736 { reverse_iterator_impl tmp = *this; --m_cur; return tmp; }
737 reverse_iterator_impl& operator--()
738 { ++m_cur; return *this; }
739 reverse_iterator_impl operator--(int)
740 { reverse_iterator_impl tmp = *this; ++m_cur; return tmp; }
741
742 // NB: explicit <T> in the functions below is to keep BCC 5.5 happy
743 reverse_iterator_impl operator+(int n) const
744 { return reverse_iterator_impl<T>(m_cur - n); }
745 reverse_iterator_impl operator+(size_t n) const
746 { return reverse_iterator_impl<T>(m_cur - n); }
747 reverse_iterator_impl operator-(int n) const
748 { return reverse_iterator_impl<T>(m_cur + n); }
749 reverse_iterator_impl operator-(size_t n) const
750 { return reverse_iterator_impl<T>(m_cur + n); }
751 reverse_iterator_impl operator+=(int n)
752 { m_cur -= n; return *this; }
753 reverse_iterator_impl operator+=(size_t n)
754 { m_cur -= n; return *this; }
755 reverse_iterator_impl operator-=(int n)
756 { m_cur += n; return *this; }
757 reverse_iterator_impl operator-=(size_t n)
758 { m_cur += n; return *this; }
759
760 unsigned operator-(const reverse_iterator_impl& i) const
761 { return i.m_cur - m_cur; }
762
763 bool operator==(const reverse_iterator_impl& ri) const
764 { return m_cur == ri.m_cur; }
765 bool operator!=(const reverse_iterator_impl& ri) const
766 { return !(*this == ri); }
767
768 bool operator<(const reverse_iterator_impl& i) const
769 { return m_cur > i.m_cur; }
770 bool operator>(const reverse_iterator_impl& i) const
771 { return m_cur < i.m_cur; }
772 bool operator<=(const reverse_iterator_impl& i) const
773 { return m_cur >= i.m_cur; }
774 bool operator>=(const reverse_iterator_impl& i) const
775 { return m_cur <= i.m_cur; }
776
777 private:
778 iterator_type m_cur;
779 };
780
781 typedef reverse_iterator_impl<iterator> reverse_iterator;
782 typedef reverse_iterator_impl<const_iterator> const_reverse_iterator;
783
784 private:
785 // used to transform an expression built using c_str() (and hence of type
786 // wxCStrData) to an iterator into the string
787 static const_iterator CreateConstIterator(const wxCStrData& data)
788 {
789 return const_iterator(data.m_str->begin() + data.m_offset);
790 }
791
792 // in UTF-8 STL build, creation from std::string requires conversion under
793 // non-UTF8 locales, so we can't have and use wxString(wxStringImpl) ctor;
794 // instead we define dummy type that lets us have wxString ctor for creation
795 // from wxStringImpl that couldn't be used by user code (in all other builds,
796 // "standard" ctors can be used):
797 #if wxUSE_UNICODE_UTF8 && wxUSE_STL_BASED_WXSTRING
798 struct CtorFromStringImplTag {};
799
800 wxString(CtorFromStringImplTag* WXUNUSED(dummy), const wxStringImpl& src)
801 : m_impl(src) {}
802
803 static wxString FromImpl(const wxStringImpl& src)
804 { return wxString((CtorFromStringImplTag*)NULL, src); }
805 #else
806 #if !wxUSE_STL_BASED_WXSTRING
807 wxString(const wxStringImpl& src) : m_impl(src) { }
808 // else: already defined as wxString(wxStdString) below
809 #endif
810 static wxString FromImpl(const wxStringImpl& src) { return wxString(src); }
811 #endif
812
813 public:
814 // constructors and destructor
815 // ctor for an empty string
816 wxString() {}
817
818 // copy ctor
819 wxString(const wxString& stringSrc) : m_impl(stringSrc.m_impl) { }
820
821 // string containing nRepeat copies of ch
822 wxString(wxUniChar ch, size_t nRepeat = 1)
823 { assign(nRepeat, ch); }
824 wxString(size_t nRepeat, wxUniChar ch)
825 { assign(nRepeat, ch); }
826 wxString(wxUniCharRef ch, size_t nRepeat = 1)
827 { assign(nRepeat, ch); }
828 wxString(size_t nRepeat, wxUniCharRef ch)
829 { assign(nRepeat, ch); }
830 wxString(char ch, size_t nRepeat = 1)
831 { assign(nRepeat, ch); }
832 wxString(size_t nRepeat, char ch)
833 { assign(nRepeat, ch); }
834 wxString(wchar_t ch, size_t nRepeat = 1)
835 { assign(nRepeat, ch); }
836 wxString(size_t nRepeat, wchar_t ch)
837 { assign(nRepeat, ch); }
838
839 // ctors from char* strings:
840 wxString(const char *psz)
841 : m_impl(ImplStr(psz)) {}
842 wxString(const char *psz, const wxMBConv& conv)
843 : m_impl(ImplStr(psz, conv)) {}
844 wxString(const char *psz, size_t nLength)
845 { assign(psz, nLength); }
846 wxString(const char *psz, const wxMBConv& conv, size_t nLength)
847 {
848 SubstrBufFromMB str(ImplStr(psz, nLength, conv));
849 m_impl.assign(str.data, str.len);
850 }
851
852 // and unsigned char*:
853 wxString(const unsigned char *psz)
854 : m_impl(ImplStr((const char*)psz)) {}
855 wxString(const unsigned char *psz, const wxMBConv& conv)
856 : m_impl(ImplStr((const char*)psz, conv)) {}
857 wxString(const unsigned char *psz, size_t nLength)
858 { assign((const char*)psz, nLength); }
859 wxString(const unsigned char *psz, const wxMBConv& conv, size_t nLength)
860 {
861 SubstrBufFromMB str(ImplStr((const char*)psz, nLength, conv));
862 m_impl.assign(str.data, str.len);
863 }
864
865 // ctors from wchar_t* strings:
866 wxString(const wchar_t *pwz)
867 : m_impl(ImplStr(pwz)) {}
868 wxString(const wchar_t *pwz, const wxMBConv& WXUNUSED(conv))
869 : m_impl(ImplStr(pwz)) {}
870 wxString(const wchar_t *pwz, size_t nLength)
871 { assign(pwz, nLength); }
872 wxString(const wchar_t *pwz, const wxMBConv& WXUNUSED(conv), size_t nLength)
873 { assign(pwz, nLength); }
874
875 wxString(const wxCharBuffer& buf)
876 { assign(buf.data()); } // FIXME-UTF8: fix for embedded NUL and buffer length
877 wxString(const wxWCharBuffer& buf)
878 { assign(buf.data()); } // FIXME-UTF8: fix for embedded NUL and buffer length
879
880 wxString(const wxCStrData& cstr)
881 : m_impl(cstr.AsString().m_impl) { }
882
883 // as we provide both ctors with this signature for both char and unsigned
884 // char string, we need to provide one for wxCStrData to resolve ambiguity
885 wxString(const wxCStrData& cstr, size_t nLength)
886 : m_impl(cstr.AsString().Mid(0, nLength).m_impl) {}
887
888 // and because wxString is convertible to wxCStrData and const wxChar *
889 // we also need to provide this one
890 wxString(const wxString& str, size_t nLength)
891 : m_impl(str.Mid(0, nLength).m_impl) {}
892
893 // even if we're not built with wxUSE_STL == 1 it is very convenient to allow
894 // implicit conversions from std::string to wxString and vice verse as this
895 // allows to use the same strings in non-GUI and GUI code, however we don't
896 // want to unconditionally add this ctor as it would make wx lib dependent on
897 // libstdc++ on some Linux versions which is bad, so instead we ask the
898 // client code to define this wxUSE_STD_STRING symbol if they need it
899 #if wxUSE_STD_STRING
900 #if wxUSE_UNICODE_WCHAR
901 wxString(const wxStdWideString& str) : m_impl(str) {}
902 #else // UTF-8 or ANSI
903 wxString(const wxStdWideString& str)
904 { assign(str.c_str(), str.length()); }
905 #endif
906
907 #if !wxUSE_UNICODE // ANSI build
908 // FIXME-UTF8: do this in UTF8 build #if wxUSE_UTF8_LOCALE_ONLY, too
909 wxString(const std::string& str) : m_impl(str) {}
910 #else // Unicode
911 wxString(const std::string& str)
912 { assign(str.c_str(), str.length()); }
913 #endif
914
915 #if wxUSE_UNICODE_WCHAR && wxUSE_STL_BASED_WXSTRING
916 // wxStringImpl is std::string in the encoding we want
917 operator const wxStdWideString&() const { return m_impl; }
918 #else
919 // wxStringImpl is either not std::string or needs conversion
920 operator wxStdWideString() const
921 // FIXME-UTF8: broken for embedded NULs
922 { return wxStdWideString(wc_str()); }
923 #endif
924
925 #if !wxUSE_UNICODE && wxUSE_STL_BASED_WXSTRING
926 // FIXME-UTF8: do this in UTF8 build #if wxUSE_UTF8_LOCALE_ONLY, too
927 // wxStringImpl is std::string in the encoding we want
928 operator const std::string&() const { return m_impl; }
929 #else
930 // wxStringImpl is either not std::string or needs conversion
931 operator std::string() const
932 // FIXME-UTF8: broken for embedded NULs
933 { return std::string(mb_str()); }
934 #endif
935
936 #endif // wxUSE_STD_STRING
937
938 // first valid index position
939 const_iterator begin() const { return const_iterator(m_impl.begin()); }
940 iterator begin() { return iterator(this, m_impl.begin()); }
941 // position one after the last valid one
942 const_iterator end() const { return const_iterator(m_impl.end()); }
943 iterator end() { return iterator(this, m_impl.end()); }
944
945 // first element of the reversed string
946 const_reverse_iterator rbegin() const
947 { return const_reverse_iterator(end()); }
948 reverse_iterator rbegin()
949 { return reverse_iterator(end()); }
950 // one beyond the end of the reversed string
951 const_reverse_iterator rend() const
952 { return const_reverse_iterator(begin()); }
953 reverse_iterator rend()
954 { return reverse_iterator(begin()); }
955
956 // std::string methods:
957 #if wxUSE_UNICODE_UTF8
958 size_t length() const { return end() - begin(); } // FIXME-UTF8: optimize!
959 #else
960 size_t length() const { return m_impl.length(); }
961 #endif
962
963 size_type size() const { return length(); }
964 size_type max_size() const { return npos; }
965
966 bool empty() const { return m_impl.empty(); }
967
968 size_type capacity() const { return m_impl.capacity(); } // FIXME-UTF8
969 void reserve(size_t sz) { m_impl.reserve(sz); } // FIXME-UTF8
970
971 void resize(size_t nSize, wxUniChar ch = wxT('\0'))
972 {
973 #if wxUSE_UNICODE_UTF8
974 if ( !ch.IsAscii() )
975 {
976 size_t len = length();
977 if ( nSize == len)
978 return;
979 else if ( nSize < len )
980 erase(nSize);
981 else
982 append(nSize - len, ch);
983 }
984 else
985 #endif
986 m_impl.resize(nSize, (wxStringCharType)ch);
987 }
988
989 wxString substr(size_t nStart = 0, size_t nLen = npos) const
990 {
991 size_t pos, len;
992 PosLenToImpl(nStart, nLen, &pos, &len);
993 return FromImpl(m_impl.substr(pos, len));
994 }
995
996 // generic attributes & operations
997 // as standard strlen()
998 size_t Len() const { return length(); }
999 // string contains any characters?
1000 bool IsEmpty() const { return empty(); }
1001 // empty string is "false", so !str will return true
1002 bool operator!() const { return empty(); }
1003 // truncate the string to given length
1004 wxString& Truncate(size_t uiLen);
1005 // empty string contents
1006 void Empty()
1007 {
1008 Truncate(0);
1009
1010 wxASSERT_MSG( empty(), _T("string not empty after call to Empty()?") );
1011 }
1012 // empty the string and free memory
1013 void Clear()
1014 {
1015 wxString tmp(wxEmptyString);
1016 swap(tmp);
1017 }
1018
1019 // contents test
1020 // Is an ascii value
1021 bool IsAscii() const;
1022 // Is a number
1023 bool IsNumber() const;
1024 // Is a word
1025 bool IsWord() const;
1026
1027 // data access (all indexes are 0 based)
1028 // read access
1029 wxUniChar at(size_t n) const
1030 { return *(begin() + n); } // FIXME-UTF8: optimize?
1031 wxUniChar GetChar(size_t n) const
1032 { return at(n); }
1033 // read/write access
1034 wxUniCharRef at(size_t n)
1035 { return *(begin() + n); } // FIXME-UTF8: optimize?
1036 wxUniCharRef GetWritableChar(size_t n)
1037 { return at(n); }
1038 // write access
1039 void SetChar(size_t n, wxUniChar ch)
1040 { at(n) = ch; }
1041
1042 // get last character
1043 wxUniChar Last() const
1044 {
1045 wxASSERT_MSG( !empty(), _T("wxString: index out of bounds") );
1046
1047 return at(length() - 1);
1048 }
1049
1050 // get writable last character
1051 wxUniCharRef Last()
1052 {
1053 wxASSERT_MSG( !empty(), _T("wxString: index out of bounds") );
1054 return at(length() - 1);
1055 }
1056
1057 /*
1058 Note that we we must define all of the overloads below to avoid
1059 ambiguity when using str[0].
1060 */
1061 wxUniChar operator[](int n) const
1062 { return at(n); }
1063 wxUniChar operator[](long n) const
1064 { return at(n); }
1065 wxUniChar operator[](size_t n) const
1066 { return at(n); }
1067 #ifndef wxSIZE_T_IS_UINT
1068 wxUniChar operator[](unsigned int n) const
1069 { return at(n); }
1070 #endif // size_t != unsigned int
1071
1072 // operator versions of GetWriteableChar()
1073 wxUniCharRef operator[](int n)
1074 { return at(n); }
1075 wxUniCharRef operator[](long n)
1076 { return at(n); }
1077 wxUniCharRef operator[](size_t n)
1078 { return at(n); }
1079 #ifndef wxSIZE_T_IS_UINT
1080 wxUniCharRef operator[](unsigned int n)
1081 { return at(n); }
1082 #endif // size_t != unsigned int
1083
1084 // explicit conversion to C string (use this with printf()!)
1085 wxCStrData c_str() const { return wxCStrData(this); }
1086 wxCStrData data() const { return c_str(); }
1087
1088 // implicit conversion to C string
1089 operator wxCStrData() const { return c_str(); }
1090 operator const char*() const { return c_str(); }
1091 operator const wchar_t*() const { return c_str(); }
1092
1093 // implicit conversion to untyped pointer for compatibility with previous
1094 // wxWidgets versions: this is the same as conversion to const char * so it
1095 // may fail!
1096 operator const void*() const { return c_str(); }
1097
1098 // identical to c_str(), for MFC compatibility
1099 const wxCStrData GetData() const { return c_str(); }
1100
1101 // explicit conversion to C string in internal representation (char*,
1102 // wchar_t*, UTF-8-encoded char*, depending on the build):
1103 const wxStringCharType *wx_str() const { return m_impl.c_str(); }
1104
1105 // conversion to *non-const* multibyte or widestring buffer; modifying
1106 // returned buffer won't affect the string, these methods are only useful
1107 // for passing values to const-incorrect functions
1108 wxWritableCharBuffer char_str(const wxMBConv& conv = wxConvLibc) const
1109 { return mb_str(conv); }
1110 wxWritableWCharBuffer wchar_str() const { return wc_str(); }
1111
1112 // conversion to/from plain (i.e. 7 bit) ASCII: this is useful for
1113 // converting numbers or strings which are certain not to contain special
1114 // chars (typically system functions, X atoms, environment variables etc.)
1115 //
1116 // the behaviour of these functions with the strings containing anything
1117 // else than 7 bit ASCII characters is undefined, use at your own risk.
1118 #if wxUSE_UNICODE
1119 static wxString FromAscii(const char *ascii); // string
1120 static wxString FromAscii(const char ascii); // char
1121 const wxCharBuffer ToAscii() const;
1122 #else // ANSI
1123 static wxString FromAscii(const char *ascii) { return wxString( ascii ); }
1124 static wxString FromAscii(const char ascii) { return wxString( ascii ); }
1125 const char *ToAscii() const { return c_str(); }
1126 #endif // Unicode/!Unicode
1127
1128 // conversions with (possible) format conversions: have to return a
1129 // buffer with temporary data
1130 //
1131 // the functions defined (in either Unicode or ANSI) mode are mb_str() to
1132 // return an ANSI (multibyte) string, wc_str() to return a wide string and
1133 // fn_str() to return a string which should be used with the OS APIs
1134 // accepting the file names. The return value is always the same, but the
1135 // type differs because a function may either return pointer to the buffer
1136 // directly or have to use intermediate buffer for translation.
1137 #if wxUSE_UNICODE
1138 const wxCharBuffer mb_str(const wxMBConv& conv = wxConvLibc) const;
1139
1140 const wxWX2MBbuf mbc_str() const { return mb_str(*wxConvCurrent); }
1141
1142 #if wxUSE_UNICODE_WCHAR
1143 const wxChar* wc_str() const { return wx_str(); }
1144 #elif wxUSE_UNICODE_UTF8
1145 const wxWCharBuffer wc_str() const;
1146 #endif
1147 // for compatibility with !wxUSE_UNICODE version
1148 const wxWX2WCbuf wc_str(const wxMBConv& WXUNUSED(conv)) const
1149 { return wc_str(); }
1150
1151 #if wxMBFILES
1152 const wxCharBuffer fn_str() const { return mb_str(wxConvFile); }
1153 #else // !wxMBFILES
1154 const wxWX2WCbuf fn_str() const { return wc_str(); }
1155 #endif // wxMBFILES/!wxMBFILES
1156
1157 #else // ANSI
1158 const wxChar* mb_str() const { return wx_str(); }
1159
1160 // for compatibility with wxUSE_UNICODE version
1161 const wxChar* mb_str(const wxMBConv& WXUNUSED(conv)) const { return wx_str(); }
1162
1163 const wxWX2MBbuf mbc_str() const { return mb_str(); }
1164
1165 #if wxUSE_WCHAR_T
1166 const wxWCharBuffer wc_str(const wxMBConv& conv = wxConvLibc) const;
1167 #endif // wxUSE_WCHAR_T
1168 #ifdef __WXOSX__
1169 const wxCharBuffer fn_str() const { return wxConvFile.cWC2WX( wc_str( wxConvLocal ) ); }
1170 #else
1171 const wxChar* fn_str() const { return c_str(); }
1172 #endif
1173 #endif // Unicode/ANSI
1174
1175 // overloaded assignment
1176 // from another wxString
1177 wxString& operator=(const wxString& stringSrc)
1178 { m_impl = stringSrc.m_impl; return *this; }
1179 wxString& operator=(const wxCStrData& cstr)
1180 { return *this = cstr.AsString(); }
1181 // from a character
1182 wxString& operator=(wxUniChar ch)
1183 { m_impl = wxStringOperations::EncodeChar(ch); return *this; }
1184 wxString& operator=(wxUniCharRef ch)
1185 { return operator=((wxUniChar)ch); }
1186 wxString& operator=(char ch)
1187 { return operator=(wxUniChar(ch)); }
1188 wxString& operator=(unsigned char ch)
1189 { return operator=(wxUniChar(ch)); }
1190 wxString& operator=(wchar_t ch)
1191 { return operator=(wxUniChar(ch)); }
1192 // from a C string - STL probably will crash on NULL,
1193 // so we need to compensate in that case
1194 #if wxUSE_STL_BASED_WXSTRING
1195 wxString& operator=(const char *psz)
1196 { if (psz) m_impl = ImplStr(psz); else Clear(); return *this; }
1197 wxString& operator=(const wchar_t *pwz)
1198 { if (pwz) m_impl = ImplStr(pwz); else Clear(); return *this; }
1199 #else
1200 wxString& operator=(const char *psz)
1201 { m_impl = ImplStr(psz); return *this; }
1202 wxString& operator=(const wchar_t *pwz)
1203 { m_impl = ImplStr(pwz); return *this; }
1204 #endif
1205 wxString& operator=(const unsigned char *psz)
1206 { return operator=((const char*)psz); }
1207
1208 // from wxWCharBuffer
1209 wxString& operator=(const wxWCharBuffer& s)
1210 { return operator=(s.data()); } // FIXME-UTF8: fix for embedded NULs
1211 // from wxCharBuffer
1212 wxString& operator=(const wxCharBuffer& s)
1213 { return operator=(s.data()); } // FIXME-UTF8: fix for embedded NULs
1214
1215 // string concatenation
1216 // in place concatenation
1217 /*
1218 Concatenate and return the result. Note that the left to right
1219 associativity of << allows to write things like "str << str1 << str2
1220 << ..." (unlike with +=)
1221 */
1222 // string += string
1223 wxString& operator<<(const wxString& s)
1224 {
1225 #if WXWIN_COMPATIBILITY_2_8 && !wxUSE_STL_BASED_WXSTRING && !wxUSE_UNICODE_UTF8
1226 wxASSERT_MSG( s.IsValid(),
1227 _T("did you forget to call UngetWriteBuf()?") );
1228 #endif
1229
1230 append(s);
1231 return *this;
1232 }
1233 // string += C string
1234 wxString& operator<<(const char *psz)
1235 { append(psz); return *this; }
1236 wxString& operator<<(const wchar_t *pwz)
1237 { append(pwz); return *this; }
1238 wxString& operator<<(const wxCStrData& psz)
1239 { append(psz.AsString()); return *this; }
1240 // string += char
1241 wxString& operator<<(wxUniChar ch) { append(1, ch); return *this; }
1242 wxString& operator<<(wxUniCharRef ch) { append(1, ch); return *this; }
1243 wxString& operator<<(char ch) { append(1, ch); return *this; }
1244 wxString& operator<<(unsigned char ch) { append(1, ch); return *this; }
1245 wxString& operator<<(wchar_t ch) { append(1, ch); return *this; }
1246
1247 // string += buffer (i.e. from wxGetString)
1248 wxString& operator<<(const wxWCharBuffer& s)
1249 { return operator<<((const wchar_t *)s); }
1250 wxString& operator+=(const wxWCharBuffer& s)
1251 { return operator<<((const wchar_t *)s); }
1252
1253 wxString& operator<<(const wxCharBuffer& s)
1254 { return operator<<((const char *)s); }
1255 wxString& operator+=(const wxCharBuffer& s)
1256 { return operator<<((const char *)s); }
1257
1258 // string += C string
1259 wxString& Append(const wxString& s)
1260 {
1261 // test for empty() to share the string if possible
1262 if ( empty() )
1263 *this = s;
1264 else
1265 append(s);
1266 return *this;
1267 }
1268 wxString& Append(const wxCStrData& psz)
1269 { append(psz); return *this; }
1270 wxString& Append(const char* psz)
1271 { append(psz); return *this; }
1272 wxString& Append(const wchar_t* pwz)
1273 { append(pwz); return *this; }
1274 // append count copies of given character
1275 wxString& Append(wxUniChar ch, size_t count = 1u)
1276 { append(count, ch); return *this; }
1277 wxString& Append(wxUniCharRef ch, size_t count = 1u)
1278 { append(count, ch); return *this; }
1279 wxString& Append(char ch, size_t count = 1u)
1280 { append(count, ch); return *this; }
1281 wxString& Append(unsigned char ch, size_t count = 1u)
1282 { append(count, ch); return *this; }
1283 wxString& Append(wchar_t ch, size_t count = 1u)
1284 { append(count, ch); return *this; }
1285 wxString& Append(const char* psz, size_t nLen)
1286 { append(psz, nLen); return *this; }
1287 wxString& Append(const wchar_t* pwz, size_t nLen)
1288 { append(pwz, nLen); return *this; }
1289
1290 // prepend a string, return the string itself
1291 wxString& Prepend(const wxString& str)
1292 { *this = str + *this; return *this; }
1293
1294 // non-destructive concatenation
1295 // two strings
1296 friend wxString WXDLLIMPEXP_BASE operator+(const wxString& string1,
1297 const wxString& string2);
1298 // string with a single char
1299 friend wxString WXDLLIMPEXP_BASE operator+(const wxString& string, wxUniChar ch);
1300 // char with a string
1301 friend wxString WXDLLIMPEXP_BASE operator+(wxUniChar ch, const wxString& string);
1302 // string with C string
1303 friend wxString WXDLLIMPEXP_BASE operator+(const wxString& string,
1304 const char *psz);
1305 friend wxString WXDLLIMPEXP_BASE operator+(const wxString& string,
1306 const wchar_t *pwz);
1307 // C string with string
1308 friend wxString WXDLLIMPEXP_BASE operator+(const char *psz,
1309 const wxString& string);
1310 friend wxString WXDLLIMPEXP_BASE operator+(const wchar_t *pwz,
1311 const wxString& string);
1312
1313 // stream-like functions
1314 // insert an int into string
1315 wxString& operator<<(int i)
1316 { return (*this) << Format(_T("%d"), i); }
1317 // insert an unsigned int into string
1318 wxString& operator<<(unsigned int ui)
1319 { return (*this) << Format(_T("%u"), ui); }
1320 // insert a long into string
1321 wxString& operator<<(long l)
1322 { return (*this) << Format(_T("%ld"), l); }
1323 // insert an unsigned long into string
1324 wxString& operator<<(unsigned long ul)
1325 { return (*this) << Format(_T("%lu"), ul); }
1326 #if defined wxLongLong_t && !defined wxLongLongIsLong
1327 // insert a long long if they exist and aren't longs
1328 wxString& operator<<(wxLongLong_t ll)
1329 {
1330 const wxChar *fmt = _T("%") wxLongLongFmtSpec _T("d");
1331 return (*this) << Format(fmt, ll);
1332 }
1333 // insert an unsigned long long
1334 wxString& operator<<(wxULongLong_t ull)
1335 {
1336 const wxChar *fmt = _T("%") wxLongLongFmtSpec _T("u");
1337 return (*this) << Format(fmt , ull);
1338 }
1339 #endif
1340 // insert a float into string
1341 wxString& operator<<(float f)
1342 { return (*this) << Format(_T("%f"), f); }
1343 // insert a double into string
1344 wxString& operator<<(double d)
1345 { return (*this) << Format(_T("%g"), d); }
1346
1347 // string comparison
1348 // case-sensitive comparison (returns a value < 0, = 0 or > 0)
1349 int Cmp(const char *psz) const
1350 { return compare(psz); }
1351 int Cmp(const wchar_t *pwz) const
1352 { return compare(pwz); }
1353 int Cmp(const wxString& s) const
1354 { return compare(s); }
1355 // same as Cmp() but not case-sensitive
1356 int CmpNoCase(const wxString& s) const;
1357 int CmpNoCase(const char *psz) const
1358 { return CmpNoCase(wxString(psz)); }
1359 int CmpNoCase(const wchar_t *pwz) const
1360 { return CmpNoCase(wxString(pwz)); }
1361 // test for the string equality, either considering case or not
1362 // (if compareWithCase then the case matters)
1363 bool IsSameAs(const wxString& str, bool compareWithCase = true) const
1364 { return (compareWithCase ? Cmp(str) : CmpNoCase(str)) == 0; }
1365 bool IsSameAs(const char *str, bool compareWithCase = true) const
1366 { return (compareWithCase ? Cmp(str) : CmpNoCase(str)) == 0; }
1367 bool IsSameAs(const wchar_t *str, bool compareWithCase = true) const
1368 { return (compareWithCase ? Cmp(str) : CmpNoCase(str)) == 0; }
1369 // comparison with a single character: returns true if equal
1370 bool IsSameAs(wxUniChar c, bool compareWithCase = true) const
1371 {
1372 return (length() == 1) && (compareWithCase ? GetChar(0u) == c
1373 : wxToupper(GetChar(0u)) == wxToupper(c));
1374 }
1375 // FIXME-UTF8: remove these overloads
1376 bool IsSameAs(wxUniCharRef c, bool compareWithCase = true) const
1377 { return IsSameAs(wxUniChar(c), compareWithCase); }
1378 bool IsSameAs(char c, bool compareWithCase = true) const
1379 { return IsSameAs(wxUniChar(c), compareWithCase); }
1380 bool IsSameAs(unsigned char c, bool compareWithCase = true) const
1381 { return IsSameAs(wxUniChar(c), compareWithCase); }
1382 bool IsSameAs(wchar_t c, bool compareWithCase = true) const
1383 { return IsSameAs(wxUniChar(c), compareWithCase); }
1384 bool IsSameAs(int c, bool compareWithCase = true) const
1385 { return IsSameAs(wxUniChar(c), compareWithCase); }
1386
1387 // simple sub-string extraction
1388 // return substring starting at nFirst of length nCount (or till the end
1389 // if nCount = default value)
1390 wxString Mid(size_t nFirst, size_t nCount = npos) const;
1391
1392 // operator version of Mid()
1393 wxString operator()(size_t start, size_t len) const
1394 { return Mid(start, len); }
1395
1396 // check if the string starts with the given prefix and return the rest
1397 // of the string in the provided pointer if it is not NULL; otherwise
1398 // return false
1399 bool StartsWith(const wxChar *prefix, wxString *rest = NULL) const;
1400 // check if the string ends with the given suffix and return the
1401 // beginning of the string before the suffix in the provided pointer if
1402 // it is not NULL; otherwise return false
1403 bool EndsWith(const wxChar *suffix, wxString *rest = NULL) const;
1404
1405 // get first nCount characters
1406 wxString Left(size_t nCount) const;
1407 // get last nCount characters
1408 wxString Right(size_t nCount) const;
1409 // get all characters before the first occurance of ch
1410 // (returns the whole string if ch not found)
1411 wxString BeforeFirst(wxUniChar ch) const;
1412 // get all characters before the last occurence of ch
1413 // (returns empty string if ch not found)
1414 wxString BeforeLast(wxUniChar ch) const;
1415 // get all characters after the first occurence of ch
1416 // (returns empty string if ch not found)
1417 wxString AfterFirst(wxUniChar ch) const;
1418 // get all characters after the last occurence of ch
1419 // (returns the whole string if ch not found)
1420 wxString AfterLast(wxUniChar ch) const;
1421
1422 // for compatibility only, use more explicitly named functions above
1423 wxString Before(wxUniChar ch) const { return BeforeLast(ch); }
1424 wxString After(wxUniChar ch) const { return AfterFirst(ch); }
1425
1426 // case conversion
1427 // convert to upper case in place, return the string itself
1428 wxString& MakeUpper();
1429 // convert to upper case, return the copy of the string
1430 // Here's something to remember: BC++ doesn't like returns in inlines.
1431 wxString Upper() const ;
1432 // convert to lower case in place, return the string itself
1433 wxString& MakeLower();
1434 // convert to lower case, return the copy of the string
1435 wxString Lower() const ;
1436
1437 // trimming/padding whitespace (either side) and truncating
1438 // remove spaces from left or from right (default) side
1439 wxString& Trim(bool bFromRight = true);
1440 // add nCount copies chPad in the beginning or at the end (default)
1441 wxString& Pad(size_t nCount, wxUniChar chPad = wxT(' '), bool bFromRight = true);
1442
1443 // searching and replacing
1444 // searching (return starting index, or -1 if not found)
1445 int Find(wxUniChar ch, bool bFromEnd = false) const; // like strchr/strrchr
1446 int Find(wxUniCharRef ch, bool bFromEnd = false) const
1447 { return Find(wxUniChar(ch), bFromEnd); }
1448 int Find(char ch, bool bFromEnd = false) const
1449 { return Find(wxUniChar(ch), bFromEnd); }
1450 int Find(unsigned char ch, bool bFromEnd = false) const
1451 { return Find(wxUniChar(ch), bFromEnd); }
1452 int Find(wchar_t ch, bool bFromEnd = false) const
1453 { return Find(wxUniChar(ch), bFromEnd); }
1454 // searching (return starting index, or -1 if not found)
1455 // FIXME-UTF8: keep wxString overload only
1456 int Find(const wxString& sub) const // like strstr
1457 {
1458 size_type idx = find(sub);
1459 return (idx == npos) ? wxNOT_FOUND : (int)idx;
1460 }
1461 int Find(const char *sub) const // like strstr
1462 {
1463 size_type idx = find(sub);
1464 return (idx == npos) ? wxNOT_FOUND : (int)idx;
1465 }
1466 int Find(const wchar_t *sub) const // like strstr
1467 {
1468 size_type idx = find(sub);
1469 return (idx == npos) ? wxNOT_FOUND : (int)idx;
1470 }
1471
1472 // replace first (or all of bReplaceAll) occurences of substring with
1473 // another string, returns the number of replacements made
1474 size_t Replace(const wxString& strOld,
1475 const wxString& strNew,
1476 bool bReplaceAll = true);
1477
1478 // check if the string contents matches a mask containing '*' and '?'
1479 bool Matches(const wxString& mask) const;
1480
1481 // conversion to numbers: all functions return true only if the whole
1482 // string is a number and put the value of this number into the pointer
1483 // provided, the base is the numeric base in which the conversion should be
1484 // done and must be comprised between 2 and 36 or be 0 in which case the
1485 // standard C rules apply (leading '0' => octal, "0x" => hex)
1486 // convert to a signed integer
1487 bool ToLong(long *val, int base = 10) const;
1488 // convert to an unsigned integer
1489 bool ToULong(unsigned long *val, int base = 10) const;
1490 // convert to wxLongLong
1491 #if defined(wxLongLong_t)
1492 bool ToLongLong(wxLongLong_t *val, int base = 10) const;
1493 // convert to wxULongLong
1494 bool ToULongLong(wxULongLong_t *val, int base = 10) const;
1495 #endif // wxLongLong_t
1496 // convert to a double
1497 bool ToDouble(double *val) const;
1498
1499
1500 #ifndef wxNEEDS_WXSTRING_PRINTF_MIXIN
1501 // formatted input/output
1502 // as sprintf(), returns the number of characters written or < 0 on error
1503 // (take 'this' into account in attribute parameter count)
1504 // int Printf(const wxString& format, ...);
1505 WX_DEFINE_VARARG_FUNC(int, Printf, 1, (const wxString&), DoPrintf)
1506 #ifdef __WATCOMC__
1507 WX_DEFINE_VARARG_FUNC(int, Printf, 1, (const char*), DoPrintf)
1508 WX_DEFINE_VARARG_FUNC(int, Printf, 1, (const wchar_t*), DoPrintf)
1509 WX_DEFINE_VARARG_FUNC(int, Printf, 1, (const wxCStrData&), DoPrintf)
1510 #endif
1511 #endif // !wxNEEDS_WXSTRING_PRINTF_MIXIN
1512 // as vprintf(), returns the number of characters written or < 0 on error
1513 int PrintfV(const wxString& format, va_list argptr);
1514
1515 #ifndef wxNEEDS_WXSTRING_PRINTF_MIXIN
1516 // returns the string containing the result of Printf() to it
1517 // static wxString Format(const wxString& format, ...) ATTRIBUTE_PRINTF_1;
1518 WX_DEFINE_VARARG_FUNC(static wxString, Format, 1, (const wxString&), DoFormat)
1519 #ifdef __WATCOMC__
1520 // workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351
1521 WX_DEFINE_VARARG_FUNC(static wxString, Format, 1, (const char*), DoFormat)
1522 WX_DEFINE_VARARG_FUNC(static wxString, Format, 1, (const wchar_t*), DoFormat)
1523 WX_DEFINE_VARARG_FUNC(static wxString, Format, 1, (const wxCStrData&), DoFormat)
1524 #endif
1525 #endif
1526 // the same as above, but takes a va_list
1527 static wxString FormatV(const wxString& format, va_list argptr);
1528
1529 // raw access to string memory
1530 // ensure that string has space for at least nLen characters
1531 // only works if the data of this string is not shared
1532 bool Alloc(size_t nLen) { reserve(nLen); /*return capacity() >= nLen;*/ return true; }
1533 // minimize the string's memory
1534 // only works if the data of this string is not shared
1535 bool Shrink();
1536 #if WXWIN_COMPATIBILITY_2_8 && !wxUSE_STL_BASED_WXSTRING && !wxUSE_UNICODE_UTF8
1537 // These are deprecated, use wxStringBuffer or wxStringBufferLength instead
1538 //
1539 // get writable buffer of at least nLen bytes. Unget() *must* be called
1540 // a.s.a.p. to put string back in a reasonable state!
1541 wxDEPRECATED( wxStringCharType *GetWriteBuf(size_t nLen) );
1542 // call this immediately after GetWriteBuf() has been used
1543 wxDEPRECATED( void UngetWriteBuf() );
1544 wxDEPRECATED( void UngetWriteBuf(size_t nLen) );
1545 #endif // WXWIN_COMPATIBILITY_2_8 && !wxUSE_STL_BASED_WXSTRING && wxUSE_UNICODE_UTF8
1546
1547 // wxWidgets version 1 compatibility functions
1548
1549 // use Mid()
1550 wxString SubString(size_t from, size_t to) const
1551 { return Mid(from, (to - from + 1)); }
1552 // values for second parameter of CompareTo function
1553 enum caseCompare {exact, ignoreCase};
1554 // values for first parameter of Strip function
1555 enum stripType {leading = 0x1, trailing = 0x2, both = 0x3};
1556
1557 #ifndef wxNEEDS_WXSTRING_PRINTF_MIXIN
1558 // use Printf()
1559 // (take 'this' into account in attribute parameter count)
1560 // int sprintf(const wxString& format, ...) ATTRIBUTE_PRINTF_2;
1561 WX_DEFINE_VARARG_FUNC(int, sprintf, 1, (const wxString&), DoPrintf)
1562 #ifdef __WATCOMC__
1563 // workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351
1564 WX_DEFINE_VARARG_FUNC(int, sprintf, 1, (const char*), DoPrintf)
1565 WX_DEFINE_VARARG_FUNC(int, sprintf, 1, (const wchar_t*), DoPrintf)
1566 WX_DEFINE_VARARG_FUNC(int, sprintf, 1, (const wxCStrData&), DoPrintf)
1567 #endif
1568 #endif // wxNEEDS_WXSTRING_PRINTF_MIXIN
1569
1570 // use Cmp()
1571 inline int CompareTo(const wxChar* psz, caseCompare cmp = exact) const
1572 { return cmp == exact ? Cmp(psz) : CmpNoCase(psz); }
1573
1574 // use length()
1575 size_t Length() const { return length(); }
1576 // Count the number of characters
1577 int Freq(wxUniChar ch) const;
1578 // use MakeLower
1579 void LowerCase() { MakeLower(); }
1580 // use MakeUpper
1581 void UpperCase() { MakeUpper(); }
1582 // use Trim except that it doesn't change this string
1583 wxString Strip(stripType w = trailing) const;
1584
1585 // use Find (more general variants not yet supported)
1586 size_t Index(const wxChar* psz) const { return Find(psz); }
1587 size_t Index(wxUniChar ch) const { return Find(ch); }
1588 // use Truncate
1589 wxString& Remove(size_t pos) { return Truncate(pos); }
1590 wxString& RemoveLast(size_t n = 1) { return Truncate(length() - n); }
1591
1592 wxString& Remove(size_t nStart, size_t nLen)
1593 { return (wxString&)erase( nStart, nLen ); }
1594
1595 // use Find()
1596 int First( wxUniChar ch ) const { return Find(ch); }
1597 int First( wxUniCharRef ch ) const { return Find(ch); }
1598 int First( char ch ) const { return Find(ch); }
1599 int First( unsigned char ch ) const { return Find(ch); }
1600 int First( wchar_t ch ) const { return Find(ch); }
1601 int First( const wxChar* psz ) const { return Find(psz); }
1602 int First( const wxString& str ) const { return Find(str); }
1603 int Last( wxUniChar ch ) const { return Find(ch, true); }
1604 bool Contains(const wxString& str) const { return Find(str) != wxNOT_FOUND; }
1605
1606 // use empty()
1607 bool IsNull() const { return empty(); }
1608
1609 // std::string compatibility functions
1610
1611 // take nLen chars starting at nPos
1612 wxString(const wxString& str, size_t nPos, size_t nLen)
1613 : m_impl(str.m_impl, nPos, nLen) { }
1614 // take all characters from first to last
1615 wxString(const_iterator first, const_iterator last)
1616 : m_impl(first.impl(), last.impl()) { }
1617 #if WXWIN_COMPATIBILITY_STRING_PTR_AS_ITER
1618 // the 2 overloads below are for compatibility with the existing code using
1619 // pointers instead of iterators
1620 wxString(const char *first, const char *last)
1621 {
1622 SubstrBufFromMB str(ImplStr(first, last - first));
1623 m_impl.assign(str.data, str.len);
1624 }
1625 wxString(const wchar_t *first, const wchar_t *last)
1626 {
1627 SubstrBufFromWC str(ImplStr(first, last - first));
1628 m_impl.assign(str.data, str.len);
1629 }
1630 // and this one is needed to compile code adding offsets to c_str() result
1631 wxString(const wxCStrData& first, const wxCStrData& last)
1632 : m_impl(CreateConstIterator(first).impl(),
1633 CreateConstIterator(last).impl())
1634 {
1635 wxASSERT_MSG( first.m_str == last.m_str,
1636 _T("pointers must be into the same string") );
1637 }
1638 #endif // WXWIN_COMPATIBILITY_STRING_PTR_AS_ITER
1639
1640 // lib.string.modifiers
1641 // append elements str[pos], ..., str[pos+n]
1642 wxString& append(const wxString& str, size_t pos, size_t n)
1643 {
1644 size_t from, len;
1645 str.PosLenToImpl(pos, n, &from, &len);
1646 m_impl.append(str.m_impl, from, len);
1647 return *this;
1648 }
1649 // append a string
1650 wxString& append(const wxString& str)
1651 { m_impl.append(str.m_impl); return *this; }
1652 wxString& append(const wxCStrData& str)
1653 { m_impl.append(str.AsString().m_impl); return *this; }
1654 // append first n (or all if n == npos) characters of sz
1655 wxString& append(const char *sz)
1656 { m_impl.append(ImplStr(sz)); return *this; }
1657 wxString& append(const wchar_t *sz)
1658 { m_impl.append(ImplStr(sz)); return *this; }
1659 wxString& append(const char *sz, size_t n)
1660 {
1661 SubstrBufFromMB str(ImplStr(sz, n));
1662 m_impl.append(str.data, str.len);
1663 return *this;
1664 }
1665 wxString& append(const wchar_t *sz, size_t n)
1666 {
1667 SubstrBufFromWC str(ImplStr(sz, n));
1668 m_impl.append(str.data, str.len);
1669 return *this;
1670 }
1671 // append n copies of ch
1672 wxString& append(size_t n, wxUniChar ch)
1673 {
1674 #if wxUSE_UNICODE_UTF8
1675 if ( !ch.IsAscii() )
1676 m_impl.append(wxStringOperations::EncodeNChars(n, ch));
1677 else
1678 #endif
1679 m_impl.append(n, (wxStringCharType)ch);
1680 return *this;
1681 }
1682 // append from first to last
1683 wxString& append(const_iterator first, const_iterator last)
1684 { m_impl.append(first.impl(), last.impl()); return *this; }
1685 #if WXWIN_COMPATIBILITY_STRING_PTR_AS_ITER
1686 wxString& append(const char *first, const char *last)
1687 { return append(first, last - first); }
1688 wxString& append(const wchar_t *first, const wchar_t *last)
1689 { return append(first, last - first); }
1690 wxString& append(const wxCStrData& first, const wxCStrData& last)
1691 { return append(CreateConstIterator(first), CreateConstIterator(last)); }
1692 #endif // WXWIN_COMPATIBILITY_STRING_PTR_AS_ITER
1693
1694 // same as `this_string = str'
1695 wxString& assign(const wxString& str)
1696 { m_impl = str.m_impl; return *this; }
1697 wxString& assign(const wxString& str, size_t len)
1698 {
1699 m_impl.assign(str.m_impl, 0, str.LenToImpl(len));
1700 return *this;
1701 }
1702 // same as ` = str[pos..pos + n]
1703 wxString& assign(const wxString& str, size_t pos, size_t n)
1704 {
1705 size_t from, len;
1706 str.PosLenToImpl(pos, n, &from, &len);
1707 m_impl.assign(str.m_impl, from, len);
1708 return *this;
1709 }
1710 // same as `= first n (or all if n == npos) characters of sz'
1711 wxString& assign(const char *sz)
1712 { m_impl.assign(ImplStr(sz)); return *this; }
1713 wxString& assign(const wchar_t *sz)
1714 { m_impl.assign(ImplStr(sz)); return *this; }
1715 wxString& assign(const char *sz, size_t n)
1716 {
1717 SubstrBufFromMB str(ImplStr(sz, n));
1718 m_impl.assign(str.data, str.len);
1719 return *this;
1720 }
1721 wxString& assign(const wchar_t *sz, size_t n)
1722 {
1723 SubstrBufFromWC str(ImplStr(sz, n));
1724 m_impl.assign(str.data, str.len);
1725 return *this;
1726 }
1727 // same as `= n copies of ch'
1728 wxString& assign(size_t n, wxUniChar ch)
1729 {
1730 #if wxUSE_UNICODE_UTF8
1731 if ( !ch.IsAscii() )
1732 m_impl.assign(wxStringOperations::EncodeNChars(n, ch));
1733 else
1734 #endif
1735 m_impl.assign(n, (wxStringCharType)ch);
1736 return *this;
1737 }
1738
1739 wxString& assign(size_t n, wxUniCharRef ch)
1740 { return assign(n, wxUniChar(ch)); }
1741 wxString& assign(size_t n, char ch)
1742 { return assign(n, wxUniChar(ch)); }
1743 wxString& assign(size_t n, unsigned char ch)
1744 { return assign(n, wxUniChar(ch)); }
1745 wxString& assign(size_t n, wchar_t ch)
1746 { return assign(n, wxUniChar(ch)); }
1747
1748 // assign from first to last
1749 wxString& assign(const_iterator first, const_iterator last)
1750 { m_impl.assign(first.impl(), last.impl()); return *this; }
1751 #if WXWIN_COMPATIBILITY_STRING_PTR_AS_ITER
1752 wxString& assign(const char *first, const char *last)
1753 { return assign(first, last - first); }
1754 wxString& assign(const wchar_t *first, const wchar_t *last)
1755 { return assign(first, last - first); }
1756 wxString& assign(const wxCStrData& first, const wxCStrData& last)
1757 { return assign(CreateConstIterator(first), CreateConstIterator(last)); }
1758 #endif // WXWIN_COMPATIBILITY_STRING_PTR_AS_ITER
1759
1760 // string comparison
1761 int compare(const wxString& str) const;
1762 // comparison with a substring
1763 int compare(size_t nStart, size_t nLen, const wxString& str) const;
1764 // comparison of 2 substrings
1765 int compare(size_t nStart, size_t nLen,
1766 const wxString& str, size_t nStart2, size_t nLen2) const;
1767 // just like strcmp()
1768 int compare(const char* sz) const;
1769 int compare(const wchar_t* sz) const;
1770 // substring comparison with first nCount characters of sz
1771 int compare(size_t nStart, size_t nLen,
1772 const char* sz, size_t nCount = npos) const;
1773 int compare(size_t nStart, size_t nLen,
1774 const wchar_t* sz, size_t nCount = npos) const;
1775
1776 // insert another string
1777 wxString& insert(size_t nPos, const wxString& str)
1778 { insert(begin() + nPos, str.begin(), str.end()); return *this; }
1779 // insert n chars of str starting at nStart (in str)
1780 wxString& insert(size_t nPos, const wxString& str, size_t nStart, size_t n)
1781 {
1782 size_t from, len;
1783 str.PosLenToImpl(nStart, n, &from, &len);
1784 m_impl.insert(PosToImpl(nPos), str.m_impl, from, len);
1785 return *this;
1786 }
1787 // insert first n (or all if n == npos) characters of sz
1788 wxString& insert(size_t nPos, const char *sz)
1789 { m_impl.insert(PosToImpl(nPos), ImplStr(sz)); return *this; }
1790 wxString& insert(size_t nPos, const wchar_t *sz)
1791 { m_impl.insert(PosToImpl(nPos), ImplStr(sz)); return *this; }
1792 wxString& insert(size_t nPos, const char *sz, size_t n)
1793 {
1794 SubstrBufFromMB str(ImplStr(sz, n));
1795 m_impl.insert(PosToImpl(nPos), str.data, str.len);
1796 return *this;
1797 }
1798 wxString& insert(size_t nPos, const wchar_t *sz, size_t n)
1799 {
1800 SubstrBufFromWC str(ImplStr(sz, n));
1801 m_impl.insert(PosToImpl(nPos), str.data, str.len);
1802 return *this;
1803 }
1804 // insert n copies of ch
1805 wxString& insert(size_t nPos, size_t n, wxUniChar ch)
1806 {
1807 #if wxUSE_UNICODE_UTF8
1808 if ( !ch.IsAscii() )
1809 m_impl.insert(PosToImpl(nPos), wxStringOperations::EncodeNChars(n, ch));
1810 else
1811 #endif
1812 m_impl.insert(PosToImpl(nPos), n, (wxStringCharType)ch);
1813 return *this;
1814 }
1815 iterator insert(iterator it, wxUniChar ch)
1816 {
1817 #if wxUSE_UNICODE_UTF8
1818 if ( !ch.IsAscii() )
1819 {
1820 size_t pos = IterToImplPos(it);
1821 m_impl.insert(pos, wxStringOperations::EncodeChar(ch));
1822 return iterator(this, m_impl.begin() + pos);
1823 }
1824 else
1825 #endif
1826 return iterator(this, m_impl.insert(it.impl(), (wxStringCharType)ch));
1827 }
1828 void insert(iterator it, const_iterator first, const_iterator last)
1829 { m_impl.insert(it.impl(), first.impl(), last.impl()); }
1830 #if WXWIN_COMPATIBILITY_STRING_PTR_AS_ITER
1831 void insert(iterator it, const char *first, const char *last)
1832 { insert(it - begin(), first, last - first); }
1833 void insert(iterator it, const wchar_t *first, const wchar_t *last)
1834 { insert(it - begin(), first, last - first); }
1835 void insert(iterator it, const wxCStrData& first, const wxCStrData& last)
1836 { insert(it, CreateConstIterator(first), CreateConstIterator(last)); }
1837 #endif // WXWIN_COMPATIBILITY_STRING_PTR_AS_ITER
1838
1839 void insert(iterator it, size_type n, wxUniChar ch)
1840 {
1841 #if wxUSE_UNICODE_UTF8
1842 if ( !ch.IsAscii() )
1843 m_impl.insert(IterToImplPos(it), wxStringOperations::EncodeNChars(n, ch));
1844 else
1845 #endif
1846 m_impl.insert(it.impl(), n, (wxStringCharType)ch);
1847 }
1848
1849 // delete characters from nStart to nStart + nLen
1850 wxString& erase(size_type pos = 0, size_type n = npos)
1851 {
1852 size_t from, len;
1853 PosLenToImpl(pos, n, &from, &len);
1854 m_impl.erase(from, len);
1855 return *this;
1856 }
1857 // delete characters from first up to last
1858 iterator erase(iterator first, iterator last)
1859 { return iterator(this, m_impl.erase(first.impl(), last.impl())); }
1860 iterator erase(iterator first)
1861 { return iterator(this, m_impl.erase(first.impl())); }
1862
1863 #ifdef wxSTRING_BASE_HASNT_CLEAR
1864 void clear() { erase(); }
1865 #else
1866 void clear() { m_impl.clear(); }
1867 #endif
1868
1869 // replaces the substring of length nLen starting at nStart
1870 wxString& replace(size_t nStart, size_t nLen, const char* sz)
1871 {
1872 size_t from, len;
1873 PosLenToImpl(nStart, nLen, &from, &len);
1874 m_impl.replace(from, len, ImplStr(sz));
1875 return *this;
1876 }
1877 wxString& replace(size_t nStart, size_t nLen, const wchar_t* sz)
1878 {
1879 size_t from, len;
1880 PosLenToImpl(nStart, nLen, &from, &len);
1881 m_impl.replace(from, len, ImplStr(sz));
1882 return *this;
1883 }
1884 // replaces the substring of length nLen starting at nStart
1885 wxString& replace(size_t nStart, size_t nLen, const wxString& str)
1886 {
1887 size_t from, len;
1888 PosLenToImpl(nStart, nLen, &from, &len);
1889 m_impl.replace(from, len, str.m_impl);
1890 return *this;
1891 }
1892 // replaces the substring with nCount copies of ch
1893 wxString& replace(size_t nStart, size_t nLen, size_t nCount, wxUniChar ch)
1894 {
1895 size_t from, len;
1896 PosLenToImpl(nStart, nLen, &from, &len);
1897 #if wxUSE_UNICODE_UTF8
1898 if ( !ch.IsAscii() )
1899 m_impl.replace(from, len, wxStringOperations::EncodeNChars(nCount, ch));
1900 else
1901 #endif
1902 m_impl.replace(from, len, nCount, (wxStringCharType)ch);
1903 return *this;
1904 }
1905 // replaces a substring with another substring
1906 wxString& replace(size_t nStart, size_t nLen,
1907 const wxString& str, size_t nStart2, size_t nLen2)
1908 {
1909 size_t from, len;
1910 PosLenToImpl(nStart, nLen, &from, &len);
1911
1912 size_t from2, len2;
1913 str.PosLenToImpl(nStart2, nLen2, &from2, &len2);
1914
1915 m_impl.replace(from, len, str.m_impl, from2, len2);
1916 return *this;
1917 }
1918 // replaces the substring with first nCount chars of sz
1919 wxString& replace(size_t nStart, size_t nLen,
1920 const char* sz, size_t nCount)
1921 {
1922 size_t from, len;
1923 PosLenToImpl(nStart, nLen, &from, &len);
1924
1925 SubstrBufFromMB str(ImplStr(sz, nCount));
1926
1927 m_impl.replace(from, len, str.data, str.len);
1928 return *this;
1929 }
1930 wxString& replace(size_t nStart, size_t nLen,
1931 const wchar_t* sz, size_t nCount)
1932 {
1933 size_t from, len;
1934 PosLenToImpl(nStart, nLen, &from, &len);
1935
1936 SubstrBufFromWC str(ImplStr(sz, nCount));
1937
1938 m_impl.replace(from, len, str.data, str.len);
1939 return *this;
1940 }
1941 wxString& replace(size_t nStart, size_t nLen,
1942 const wxString& s, size_t nCount)
1943 {
1944 size_t from, len;
1945 PosLenToImpl(nStart, nLen, &from, &len);
1946 m_impl.replace(from, len, s.m_impl.c_str(), s.LenToImpl(nCount));
1947 return *this;
1948 }
1949
1950 wxString& replace(iterator first, iterator last, const char* s)
1951 { m_impl.replace(first.impl(), last.impl(), ImplStr(s)); return *this; }
1952 wxString& replace(iterator first, iterator last, const wchar_t* s)
1953 { m_impl.replace(first.impl(), last.impl(), ImplStr(s)); return *this; }
1954 wxString& replace(iterator first, iterator last, const char* s, size_type n)
1955 {
1956 SubstrBufFromMB str(ImplStr(s, n));
1957 m_impl.replace(first.impl(), last.impl(), str.data, str.len);
1958 return *this;
1959 }
1960 wxString& replace(iterator first, iterator last, const wchar_t* s, size_type n)
1961 {
1962 SubstrBufFromWC str(ImplStr(s, n));
1963 m_impl.replace(first.impl(), last.impl(), str.data, str.len);
1964 return *this;
1965 }
1966 wxString& replace(iterator first, iterator last, const wxString& s)
1967 { m_impl.replace(first.impl(), last.impl(), s.m_impl); return *this; }
1968 wxString& replace(iterator first, iterator last, size_type n, wxUniChar ch)
1969 {
1970 #if wxUSE_UNICODE_UTF8
1971 if ( !ch.IsAscii() )
1972 m_impl.replace(first.impl(), last.impl(),
1973 wxStringOperations::EncodeNChars(n, ch));
1974 else
1975 #endif
1976 m_impl.replace(first.impl(), last.impl(), n, (wxStringCharType)ch);
1977 return *this;
1978 }
1979 wxString& replace(iterator first, iterator last,
1980 const_iterator first1, const_iterator last1)
1981 {
1982 m_impl.replace(first.impl(), last.impl(), first1.impl(), last1.impl());
1983 return *this;
1984 }
1985 wxString& replace(iterator first, iterator last,
1986 const char *first1, const char *last1)
1987 { replace(first, last, first1, last1 - first1); return *this; }
1988 wxString& replace(iterator first, iterator last,
1989 const wchar_t *first1, const wchar_t *last1)
1990 { replace(first, last, first1, last1 - first1); return *this; }
1991
1992 // swap two strings
1993 void swap(wxString& str)
1994 { m_impl.swap(str.m_impl); }
1995
1996 // find a substring
1997 size_t find(const wxString& str, size_t nStart = 0) const
1998 { return PosFromImpl(m_impl.find(str.m_impl, PosToImpl(nStart))); }
1999
2000 // find first n characters of sz
2001 size_t find(const char* sz, size_t nStart = 0, size_t n = npos) const
2002 {
2003 SubstrBufFromMB str(ImplStr(sz, n));
2004 return PosFromImpl(m_impl.find(str.data, PosToImpl(nStart), str.len));
2005 }
2006 size_t find(const wchar_t* sz, size_t nStart = 0, size_t n = npos) const
2007 {
2008 SubstrBufFromWC str(ImplStr(sz, n));
2009 return PosFromImpl(m_impl.find(str.data, PosToImpl(nStart), str.len));
2010 }
2011
2012 // find the first occurence of character ch after nStart
2013 size_t find(wxUniChar ch, size_t nStart = 0) const
2014 {
2015 return PosFromImpl(m_impl.find(wxStringOperations::EncodeChar(ch),
2016 PosToImpl(nStart)));
2017 }
2018 size_t find(wxUniCharRef ch, size_t nStart = 0) const
2019 { return find(wxUniChar(ch), nStart); }
2020 size_t find(char ch, size_t nStart = 0) const
2021 { return find(wxUniChar(ch), nStart); }
2022 size_t find(unsigned char ch, size_t nStart = 0) const
2023 { return find(wxUniChar(ch), nStart); }
2024 size_t find(wchar_t ch, size_t nStart = 0) const
2025 { return find(wxUniChar(ch), nStart); }
2026
2027 // rfind() family is exactly like find() but works right to left
2028
2029 // as find, but from the end
2030 size_t rfind(const wxString& str, size_t nStart = npos) const
2031 { return PosFromImpl(m_impl.rfind(str.m_impl, PosToImpl(nStart))); }
2032
2033 // as find, but from the end
2034 size_t rfind(const char* sz, size_t nStart = npos, size_t n = npos) const
2035 {
2036 SubstrBufFromMB str(ImplStr(sz, n));
2037 return PosFromImpl(m_impl.rfind(str.data, PosToImpl(nStart), str.len));
2038 }
2039 size_t rfind(const wchar_t* sz, size_t nStart = npos, size_t n = npos) const
2040 {
2041 SubstrBufFromWC str(ImplStr(sz, n));
2042 return PosFromImpl(m_impl.rfind(str.data, PosToImpl(nStart), str.len));
2043 }
2044 // as find, but from the end
2045 size_t rfind(wxUniChar ch, size_t nStart = npos) const
2046 {
2047 return PosFromImpl(m_impl.rfind(wxStringOperations::EncodeChar(ch),
2048 PosToImpl(nStart)));
2049 }
2050 size_t rfind(wxUniCharRef ch, size_t nStart = npos) const
2051 { return rfind(wxUniChar(ch), nStart); }
2052 size_t rfind(char ch, size_t nStart = npos) const
2053 { return rfind(wxUniChar(ch), nStart); }
2054 size_t rfind(unsigned char ch, size_t nStart = npos) const
2055 { return rfind(wxUniChar(ch), nStart); }
2056 size_t rfind(wchar_t ch, size_t nStart = npos) const
2057 { return rfind(wxUniChar(ch), nStart); }
2058
2059 // find first/last occurence of any character (not) in the set:
2060 #if wxUSE_STL_BASED_WXSTRING && !wxUSE_UNICODE_UTF8
2061 // FIXME-UTF8: this is not entirely correct, because it doesn't work if
2062 // sizeof(wchar_t)==2 and surrogates are present in the string;
2063 // should we care? Probably not.
2064 size_t find_first_of(const wxString& str, size_t nStart = 0) const
2065 { return m_impl.find_first_of(str.m_impl, nStart); }
2066 size_t find_first_of(const char* sz, size_t nStart = 0) const
2067 { return m_impl.find_first_of(ImplStr(sz), nStart); }
2068 size_t find_first_of(const wchar_t* sz, size_t nStart = 0) const
2069 { return m_impl.find_first_of(ImplStr(sz), nStart); }
2070 size_t find_first_of(const char* sz, size_t nStart, size_t n) const
2071 { return m_impl.find_first_of(ImplStr(sz), nStart, n); }
2072 size_t find_first_of(const wchar_t* sz, size_t nStart, size_t n) const
2073 { return m_impl.find_first_of(ImplStr(sz), nStart, n); }
2074 size_t find_first_of(wxUniChar c, size_t nStart = 0) const
2075 { return m_impl.find_first_of((wxChar)c, nStart); }
2076
2077 size_t find_last_of(const wxString& str, size_t nStart = npos) const
2078 { return m_impl.find_last_of(str.m_impl, nStart); }
2079 size_t find_last_of(const char* sz, size_t nStart = npos) const
2080 { return m_impl.find_last_of(ImplStr(sz), nStart); }
2081 size_t find_last_of(const wchar_t* sz, size_t nStart = npos) const
2082 { return m_impl.find_last_of(ImplStr(sz), nStart); }
2083 size_t find_last_of(const char* sz, size_t nStart, size_t n) const
2084 { return m_impl.find_last_of(ImplStr(sz), nStart, n); }
2085 size_t find_last_of(const wchar_t* sz, size_t nStart, size_t n) const
2086 { return m_impl.find_last_of(ImplStr(sz), nStart, n); }
2087 size_t find_last_of(wxUniChar c, size_t nStart = npos) const
2088 { return m_impl.find_last_of((wxChar)c, nStart); }
2089
2090 size_t find_first_not_of(const wxString& str, size_t nStart = 0) const
2091 { return m_impl.find_first_not_of(str.m_impl, nStart); }
2092 size_t find_first_not_of(const char* sz, size_t nStart = 0) const
2093 { return m_impl.find_first_not_of(ImplStr(sz), nStart); }
2094 size_t find_first_not_of(const wchar_t* sz, size_t nStart = 0) const
2095 { return m_impl.find_first_not_of(ImplStr(sz), nStart); }
2096 size_t find_first_not_of(const char* sz, size_t nStart, size_t n) const
2097 { return m_impl.find_first_not_of(ImplStr(sz), nStart, n); }
2098 size_t find_first_not_of(const wchar_t* sz, size_t nStart, size_t n) const
2099 { return m_impl.find_first_not_of(ImplStr(sz), nStart, n); }
2100 size_t find_first_not_of(wxUniChar c, size_t nStart = 0) const
2101 { return m_impl.find_first_not_of((wxChar)c, nStart); }
2102
2103 size_t find_last_not_of(const wxString& str, size_t nStart = npos) const
2104 { return m_impl.find_last_not_of(str.m_impl, nStart); }
2105 size_t find_last_not_of(const char* sz, size_t nStart = npos) const
2106 { return m_impl.find_last_not_of(ImplStr(sz), nStart); }
2107 size_t find_last_not_of(const wchar_t* sz, size_t nStart = npos) const
2108 { return m_impl.find_last_not_of(ImplStr(sz), nStart); }
2109 size_t find_last_not_of(const char* sz, size_t nStart, size_t n) const
2110 { return m_impl.find_last_not_of(ImplStr(sz), nStart, n); }
2111 size_t find_last_not_of(const wchar_t* sz, size_t nStart, size_t n) const
2112 { return m_impl.find_last_not_of(ImplStr(sz), nStart, n); }
2113 size_t find_last_not_of(wxUniChar c, size_t nStart = npos) const
2114 { return m_impl.find_last_not_of((wxChar)c, nStart); }
2115 #else
2116 // we can't use std::string implementation in UTF-8 build, because the
2117 // character sets would be interpreted wrongly:
2118
2119 // as strpbrk() but starts at nStart, returns npos if not found
2120 size_t find_first_of(const wxString& str, size_t nStart = 0) const
2121 #if wxUSE_UNICODE // FIXME-UTF8: temporary
2122 { return find_first_of(str.mb_str().data(), nStart); }
2123 #else
2124 { return find_first_of((const wxChar*)str.c_str(), nStart); }
2125 #endif
2126 // same as above
2127 size_t find_first_of(const char* sz, size_t nStart = 0) const;
2128 size_t find_first_of(const wchar_t* sz, size_t nStart = 0) const;
2129 size_t find_first_of(const char* sz, size_t nStart, size_t n) const;
2130 size_t find_first_of(const wchar_t* sz, size_t nStart, size_t n) const;
2131 // same as find(char, size_t)
2132 size_t find_first_of(wxUniChar c, size_t nStart = 0) const
2133 { return find(c, nStart); }
2134 // find the last (starting from nStart) char from str in this string
2135 size_t find_last_of (const wxString& str, size_t nStart = npos) const
2136 #if wxUSE_UNICODE // FIXME-UTF8: temporary
2137 { return find_last_of(str.mb_str().data(), nStart); }
2138 #else
2139 { return find_last_of((const wxChar*)str.c_str(), nStart); }
2140 #endif
2141 // same as above
2142 size_t find_last_of (const char* sz, size_t nStart = npos) const;
2143 size_t find_last_of (const wchar_t* sz, size_t nStart = npos) const;
2144 size_t find_last_of(const char* sz, size_t nStart, size_t n) const;
2145 size_t find_last_of(const wchar_t* sz, size_t nStart, size_t n) const;
2146 // same as above
2147 size_t find_last_of(wxUniChar c, size_t nStart = npos) const
2148 { return rfind(c, nStart); }
2149
2150 // find first/last occurence of any character not in the set
2151
2152 // as strspn() (starting from nStart), returns npos on failure
2153 size_t find_first_not_of(const wxString& str, size_t nStart = 0) const
2154 #if wxUSE_UNICODE // FIXME-UTF8: temporary
2155 { return find_first_not_of(str.mb_str().data(), nStart); }
2156 #else
2157 { return find_first_not_of((const wxChar*)str.c_str(), nStart); }
2158 #endif
2159 // same as above
2160 size_t find_first_not_of(const char* sz, size_t nStart = 0) const;
2161 size_t find_first_not_of(const wchar_t* sz, size_t nStart = 0) const;
2162 size_t find_first_not_of(const char* sz, size_t nStart, size_t n) const;
2163 size_t find_first_not_of(const wchar_t* sz, size_t nStart, size_t n) const;
2164 // same as above
2165 size_t find_first_not_of(wxUniChar ch, size_t nStart = 0) const;
2166 // as strcspn()
2167 size_t find_last_not_of(const wxString& str, size_t nStart = npos) const
2168 #if wxUSE_UNICODE // FIXME-UTF8: temporary
2169 { return find_last_not_of(str.mb_str().data(), nStart); }
2170 #else
2171 { return find_last_not_of((const wxChar*)str.c_str(), nStart); }
2172 #endif
2173 // same as above
2174 size_t find_last_not_of(const char* sz, size_t nStart = npos) const;
2175 size_t find_last_not_of(const wchar_t* sz, size_t nStart = npos) const;
2176 size_t find_last_not_of(const char* sz, size_t nStart, size_t n) const;
2177 size_t find_last_not_of(const wchar_t* sz, size_t nStart, size_t n) const;
2178 // same as above
2179 size_t find_last_not_of(wxUniChar ch, size_t nStart = npos) const;
2180 #endif // wxUSE_STL_BASED_WXSTRING && !wxUSE_UNICODE_UTF8 or not
2181
2182 // provide char/wchar_t/wxUniCharRef overloads for char-finding functions
2183 // above to resolve ambiguities:
2184 size_t find_first_of(wxUniCharRef ch, size_t nStart = 0) const
2185 { return find_first_of(wxUniChar(ch), nStart); }
2186 size_t find_first_of(char ch, size_t nStart = 0) const
2187 { return find_first_of(wxUniChar(ch), nStart); }
2188 size_t find_first_of(unsigned char ch, size_t nStart = 0) const
2189 { return find_first_of(wxUniChar(ch), nStart); }
2190 size_t find_first_of(wchar_t ch, size_t nStart = 0) const
2191 { return find_first_of(wxUniChar(ch), nStart); }
2192 size_t find_last_of(wxUniCharRef ch, size_t nStart = npos) const
2193 { return find_last_of(wxUniChar(ch), nStart); }
2194 size_t find_last_of(char ch, size_t nStart = npos) const
2195 { return find_last_of(wxUniChar(ch), nStart); }
2196 size_t find_last_of(unsigned char ch, size_t nStart = npos) const
2197 { return find_last_of(wxUniChar(ch), nStart); }
2198 size_t find_last_of(wchar_t ch, size_t nStart = npos) const
2199 { return find_last_of(wxUniChar(ch), nStart); }
2200 size_t find_first_not_of(wxUniCharRef ch, size_t nStart = 0) const
2201 { return find_first_not_of(wxUniChar(ch), nStart); }
2202 size_t find_first_not_of(char ch, size_t nStart = 0) const
2203 { return find_first_not_of(wxUniChar(ch), nStart); }
2204 size_t find_first_not_of(unsigned char ch, size_t nStart = 0) const
2205 { return find_first_not_of(wxUniChar(ch), nStart); }
2206 size_t find_first_not_of(wchar_t ch, size_t nStart = 0) const
2207 { return find_first_not_of(wxUniChar(ch), nStart); }
2208 size_t find_last_not_of(wxUniCharRef ch, size_t nStart = npos) const
2209 { return find_last_not_of(wxUniChar(ch), nStart); }
2210 size_t find_last_not_of(char ch, size_t nStart = npos) const
2211 { return find_last_not_of(wxUniChar(ch), nStart); }
2212 size_t find_last_not_of(unsigned char ch, size_t nStart = npos) const
2213 { return find_last_not_of(wxUniChar(ch), nStart); }
2214 size_t find_last_not_of(wchar_t ch, size_t nStart = npos) const
2215 { return find_last_not_of(wxUniChar(ch), nStart); }
2216
2217 // string += string
2218 wxString& operator+=(const wxString& s)
2219 { m_impl += s.m_impl; return *this; }
2220 // string += C string
2221 wxString& operator+=(const char *psz)
2222 { m_impl += ImplStr(psz); return *this; }
2223 wxString& operator+=(const wchar_t *pwz)
2224 { m_impl += ImplStr(pwz); return *this; }
2225 wxString& operator+=(const wxCStrData& s)
2226 { m_impl += s.AsString().m_impl; return *this; }
2227 // string += char
2228 wxString& operator+=(wxUniChar ch)
2229 { m_impl += wxStringOperations::EncodeChar(ch); return *this; }
2230 wxString& operator+=(wxUniCharRef ch) { return *this += wxUniChar(ch); }
2231 wxString& operator+=(int ch) { return *this += wxUniChar(ch); }
2232 wxString& operator+=(char ch) { return *this += wxUniChar(ch); }
2233 wxString& operator+=(unsigned char ch) { return *this += wxUniChar(ch); }
2234 wxString& operator+=(wchar_t ch) { return *this += wxUniChar(ch); }
2235
2236 private:
2237 #if !wxUSE_STL_BASED_WXSTRING
2238 // helpers for wxStringBuffer and wxStringBufferLength
2239 wxStringCharType *DoGetWriteBuf(size_t nLen)
2240 { return m_impl.DoGetWriteBuf(nLen); }
2241 void DoUngetWriteBuf()
2242 { m_impl.DoUngetWriteBuf(); }
2243 void DoUngetWriteBuf(size_t nLen)
2244 { m_impl.DoUngetWriteBuf(nLen); }
2245 #endif // !wxUSE_STL_BASED_WXSTRING
2246
2247 #ifndef wxNEEDS_WXSTRING_PRINTF_MIXIN
2248 int DoPrintf(const wxString& format, ...);
2249 static wxString DoFormat(const wxString& format, ...);
2250 #endif
2251
2252 #if !wxUSE_STL_BASED_WXSTRING
2253 // check string's data validity
2254 bool IsValid() const { return m_impl.GetStringData()->IsValid(); }
2255 #endif
2256
2257 private:
2258 wxStringImpl m_impl;
2259
2260 // buffers for compatibility conversion from (char*)c_str() and
2261 // (wchar_t*)c_str():
2262 // FIXME-UTF8: bechmark various approaches to keeping compatibility buffers
2263 template<typename T>
2264 struct ConvertedBuffer
2265 {
2266 ConvertedBuffer() : m_buf(NULL) {}
2267 ~ConvertedBuffer()
2268 { free(m_buf); }
2269
2270 operator T*() const { return m_buf; }
2271
2272 ConvertedBuffer& operator=(T *str)
2273 {
2274 free(m_buf);
2275 m_buf = str;
2276 return *this;
2277 }
2278
2279 T *m_buf;
2280 };
2281 #if wxUSE_UNICODE
2282 ConvertedBuffer<char> m_convertedToChar;
2283 #endif
2284 #if !wxUSE_UNICODE_WCHAR
2285 ConvertedBuffer<wchar_t> m_convertedToWChar;
2286 #endif
2287
2288 friend class WXDLLIMPEXP_BASE wxCStrData;
2289 friend class wxImplStringBuffer;
2290 friend class wxImplStringBufferLength;
2291 };
2292
2293 #ifdef wxNEEDS_WXSTRING_PRINTF_MIXIN
2294 #pragma warning (default:4275)
2295 #endif
2296
2297 // string iterator operators that satisfy STL Random Access Iterator
2298 // requirements:
2299 inline wxString::iterator operator+(int n, wxString::iterator i)
2300 { return i + n; }
2301 inline wxString::iterator operator+(size_t n, wxString::iterator i)
2302 { return i + n; }
2303 inline wxString::const_iterator operator+(int n, wxString::const_iterator i)
2304 { return i + n; }
2305 inline wxString::const_iterator operator+(size_t n, wxString::const_iterator i)
2306 { return i + n; }
2307 inline wxString::reverse_iterator operator+(int n, wxString::reverse_iterator i)
2308 { return i + n; }
2309 inline wxString::reverse_iterator operator+(size_t n, wxString::reverse_iterator i)
2310 { return i + n; }
2311 inline wxString::const_reverse_iterator operator+(int n, wxString::const_reverse_iterator i)
2312 { return i + n; }
2313 inline wxString::const_reverse_iterator operator+(size_t n, wxString::const_reverse_iterator i)
2314 { return i + n; }
2315
2316 // notice that even though for many compilers the friend declarations above are
2317 // enough, from the point of view of C++ standard we must have the declarations
2318 // here as friend ones are not injected in the enclosing namespace and without
2319 // them the code fails to compile with conforming compilers such as xlC or g++4
2320 wxString WXDLLIMPEXP_BASE operator+(const wxString& string1, const wxString& string2);
2321 wxString WXDLLIMPEXP_BASE operator+(const wxString& string, const char *psz);
2322 wxString WXDLLIMPEXP_BASE operator+(const wxString& string, const wchar_t *pwz);
2323 wxString WXDLLIMPEXP_BASE operator+(const char *psz, const wxString& string);
2324 wxString WXDLLIMPEXP_BASE operator+(const wchar_t *pwz, const wxString& string);
2325
2326 wxString WXDLLIMPEXP_BASE operator+(const wxString& string, wxUniChar ch);
2327 wxString WXDLLIMPEXP_BASE operator+(wxUniChar ch, const wxString& string);
2328
2329 inline wxString operator+(const wxString& string, wxUniCharRef ch)
2330 { return string + (wxUniChar)ch; }
2331 inline wxString operator+(const wxString& string, char ch)
2332 { return string + wxUniChar(ch); }
2333 inline wxString operator+(const wxString& string, wchar_t ch)
2334 { return string + wxUniChar(ch); }
2335 inline wxString operator+(wxUniCharRef ch, const wxString& string)
2336 { return (wxUniChar)ch + string; }
2337 inline wxString operator+(char ch, const wxString& string)
2338 { return wxUniChar(ch) + string; }
2339 inline wxString operator+(wchar_t ch, const wxString& string)
2340 { return wxUniChar(ch) + string; }
2341
2342
2343 #if wxUSE_STL_BASED_WXSTRING
2344 // return an empty wxString (not very useful with wxUSE_STL == 1)
2345 inline const wxString wxGetEmptyString() { return wxString(); }
2346 #else // !wxUSE_STL_BASED_WXSTRING
2347 // return an empty wxString (more efficient than wxString() here)
2348 inline const wxString& wxGetEmptyString()
2349 {
2350 return *(wxString *)&wxEmptyString;
2351 }
2352 #endif // wxUSE_STL_BASED_WXSTRING/!wxUSE_STL_BASED_WXSTRING
2353
2354 // ----------------------------------------------------------------------------
2355 // wxStringBuffer: a tiny class allowing to get a writable pointer into string
2356 // ----------------------------------------------------------------------------
2357
2358 #if !wxUSE_STL_BASED_WXSTRING
2359 // string buffer for direct access to string data in their native
2360 // representation:
2361 class wxImplStringBuffer
2362 {
2363 public:
2364 typedef wxStringCharType CharType;
2365
2366 wxImplStringBuffer(wxString& str, size_t lenWanted = 1024)
2367 : m_str(str), m_buf(NULL)
2368 { m_buf = m_str.DoGetWriteBuf(lenWanted); }
2369
2370 ~wxImplStringBuffer() { m_str.DoUngetWriteBuf(); }
2371
2372 operator wxStringCharType*() const { return m_buf; }
2373
2374 private:
2375 wxString& m_str;
2376 wxStringCharType *m_buf;
2377
2378 DECLARE_NO_COPY_CLASS(wxImplStringBuffer)
2379 };
2380
2381 class wxImplStringBufferLength
2382 {
2383 public:
2384 typedef wxStringCharType CharType;
2385
2386 wxImplStringBufferLength(wxString& str, size_t lenWanted = 1024)
2387 : m_str(str), m_buf(NULL), m_len(0), m_lenSet(false)
2388 {
2389 m_buf = m_str.DoGetWriteBuf(lenWanted);
2390 wxASSERT(m_buf != NULL);
2391 }
2392
2393 ~wxImplStringBufferLength()
2394 {
2395 wxASSERT(m_lenSet);
2396 m_str.DoUngetWriteBuf(m_len);
2397 }
2398
2399 operator wxStringCharType*() const { return m_buf; }
2400 void SetLength(size_t length) { m_len = length; m_lenSet = true; }
2401
2402 private:
2403 wxString& m_str;
2404 wxStringCharType *m_buf;
2405 size_t m_len;
2406 bool m_lenSet;
2407
2408 DECLARE_NO_COPY_CLASS(wxImplStringBufferLength)
2409 };
2410
2411 #endif // !wxUSE_STL_BASED_WXSTRING
2412
2413 template<typename T>
2414 class wxStringTypeBufferBase
2415 {
2416 public:
2417 typedef T CharType;
2418
2419 wxStringTypeBufferBase(wxString& str, size_t lenWanted = 1024)
2420 : m_str(str), m_buf(lenWanted)
2421 { }
2422
2423
2424 operator CharType*() { return m_buf.data(); }
2425
2426 protected:
2427 wxString& m_str;
2428 wxCharTypeBuffer<CharType> m_buf;
2429 };
2430
2431 template<typename T>
2432 class wxStringTypeBufferLengthBase
2433 {
2434 public:
2435 typedef T CharType;
2436
2437 wxStringTypeBufferLengthBase(wxString& str, size_t lenWanted = 1024)
2438 : m_str(str), m_buf(lenWanted), m_len(0), m_lenSet(false)
2439 { }
2440
2441 ~wxStringTypeBufferLengthBase()
2442 {
2443 wxASSERT(m_lenSet);
2444 m_str.assign(m_buf.data(), m_len);
2445 }
2446
2447 operator CharType*() { return m_buf.data(); }
2448 void SetLength(size_t length) { m_len = length; m_lenSet = true; }
2449
2450 protected:
2451 wxString& m_str;
2452 wxCharTypeBuffer<CharType> m_buf;
2453 size_t m_len;
2454 bool m_lenSet;
2455 };
2456
2457 template<typename T>
2458 class wxStringTypeBuffer : public wxStringTypeBufferBase<T>
2459 {
2460 public:
2461 wxStringTypeBuffer(wxString& str, size_t lenWanted = 1024)
2462 : wxStringTypeBufferBase<T>(str, lenWanted) {}
2463 ~wxStringTypeBuffer()
2464 {
2465 this->m_str.assign(this->m_buf.data());
2466 }
2467
2468 DECLARE_NO_COPY_CLASS(wxStringTypeBuffer)
2469 };
2470
2471 template<typename T>
2472 class wxStringTypeBufferLength : public wxStringTypeBufferLengthBase<T>
2473 {
2474 public:
2475 wxStringTypeBufferLength(wxString& str, size_t lenWanted = 1024)
2476 : wxStringTypeBufferLengthBase<T>(str, lenWanted) {}
2477
2478 ~wxStringTypeBufferLength()
2479 {
2480 wxASSERT(this->m_lenSet);
2481 this->m_str.assign(this->m_buf.data(), this->m_len);
2482 }
2483
2484 DECLARE_NO_COPY_CLASS(wxStringTypeBufferLength)
2485 };
2486
2487 #if wxUSE_STL_BASED_WXSTRING
2488 class wxImplStringBuffer : public wxStringTypeBufferBase<wxStringCharType>
2489 {
2490 public:
2491 wxImplStringBuffer(wxString& str, size_t lenWanted = 1024)
2492 : wxStringTypeBufferBase<wxStringCharType>(str, lenWanted) {}
2493 ~wxImplStringBuffer()
2494 { m_str.m_impl.assign(m_buf.data()); }
2495
2496 DECLARE_NO_COPY_CLASS(wxImplStringBuffer)
2497 };
2498
2499 class wxImplStringBufferLength : public wxStringTypeBufferLengthBase<wxStringCharType>
2500 {
2501 public:
2502 wxImplStringBufferLength(wxString& str, size_t lenWanted = 1024)
2503 : wxStringTypeBufferLengthBase<wxStringCharType>(str, lenWanted) {}
2504
2505 ~wxImplStringBufferLength()
2506 {
2507 wxASSERT(m_lenSet);
2508 m_str.m_impl.assign(m_buf.data(), m_len);
2509 }
2510
2511 DECLARE_NO_COPY_CLASS(wxImplStringBufferLength)
2512 };
2513 #endif // wxUSE_STL_BASED_WXSTRING
2514
2515
2516 #if wxUSE_STL_BASED_WXSTRING || wxUSE_UNICODE_UTF8
2517 typedef wxStringTypeBuffer<wxChar> wxStringBuffer;
2518 typedef wxStringTypeBufferLength<wxChar> wxStringBufferLength;
2519 #else // if !wxUSE_STL_BASED_WXSTRING && !wxUSE_UNICODE_UTF8
2520 typedef wxImplStringBuffer wxStringBuffer;
2521 typedef wxImplStringBufferLength wxStringBufferLength;
2522 #endif // !wxUSE_STL_BASED_WXSTRING && !wxUSE_UNICODE_UTF8
2523
2524 // ---------------------------------------------------------------------------
2525 // wxString comparison functions: operator versions are always case sensitive
2526 // ---------------------------------------------------------------------------
2527
2528 #define wxCMP_WXCHAR_STRING(p, s, op) 0 op s.Cmp(p)
2529
2530 wxDEFINE_ALL_COMPARISONS(const wxChar *, const wxString&, wxCMP_WXCHAR_STRING)
2531
2532 #undef wxCMP_WXCHAR_STRING
2533
2534 // note that there is an optimization in operator==() and !=(): we (quickly)
2535 // checks the strings length first, before comparing their data
2536 inline bool operator==(const wxString& s1, const wxString& s2)
2537 { return (s1.Len() == s2.Len()) && (s1.Cmp(s2) == 0); }
2538 inline bool operator!=(const wxString& s1, const wxString& s2)
2539 { return (s1.Len() != s2.Len()) || (s1.Cmp(s2) != 0); }
2540 inline bool operator< (const wxString& s1, const wxString& s2)
2541 { return s1.Cmp(s2) < 0; }
2542 inline bool operator> (const wxString& s1, const wxString& s2)
2543 { return s1.Cmp(s2) > 0; }
2544 inline bool operator<=(const wxString& s1, const wxString& s2)
2545 { return s1.Cmp(s2) <= 0; }
2546 inline bool operator>=(const wxString& s1, const wxString& s2)
2547 { return s1.Cmp(s2) >= 0; }
2548
2549 #if wxUSE_UNICODE
2550 inline bool operator==(const wxString& s1, const wxWCharBuffer& s2)
2551 { return (s1.Cmp((const wchar_t *)s2) == 0); }
2552 inline bool operator==(const wxWCharBuffer& s1, const wxString& s2)
2553 { return (s2.Cmp((const wchar_t *)s1) == 0); }
2554 inline bool operator!=(const wxString& s1, const wxWCharBuffer& s2)
2555 { return (s1.Cmp((const wchar_t *)s2) != 0); }
2556 inline bool operator!=(const wxWCharBuffer& s1, const wxString& s2)
2557 { return (s2.Cmp((const wchar_t *)s1) != 0); }
2558 #else // !wxUSE_UNICODE
2559 inline bool operator==(const wxString& s1, const wxCharBuffer& s2)
2560 { return (s1.Cmp((const char *)s2) == 0); }
2561 inline bool operator==(const wxCharBuffer& s1, const wxString& s2)
2562 { return (s2.Cmp((const char *)s1) == 0); }
2563 inline bool operator!=(const wxString& s1, const wxCharBuffer& s2)
2564 { return (s1.Cmp((const char *)s2) != 0); }
2565 inline bool operator!=(const wxCharBuffer& s1, const wxString& s2)
2566 { return (s2.Cmp((const char *)s1) != 0); }
2567 #endif // wxUSE_UNICODE/!wxUSE_UNICODE
2568
2569 #if wxUSE_UNICODE
2570 inline wxString operator+(const wxString& string, const wxWCharBuffer& buf)
2571 { return string + (const wchar_t *)buf; }
2572 inline wxString operator+(const wxWCharBuffer& buf, const wxString& string)
2573 { return (const wchar_t *)buf + string; }
2574 #else // !wxUSE_UNICODE
2575 inline wxString operator+(const wxString& string, const wxCharBuffer& buf)
2576 { return string + (const char *)buf; }
2577 inline wxString operator+(const wxCharBuffer& buf, const wxString& string)
2578 { return (const char *)buf + string; }
2579 #endif // wxUSE_UNICODE/!wxUSE_UNICODE
2580
2581 // comparison with char
2582 inline bool operator==(const wxUniChar& c, const wxString& s) { return s.IsSameAs(c); }
2583 inline bool operator==(const wxUniCharRef& c, const wxString& s) { return s.IsSameAs(c); }
2584 inline bool operator==(char c, const wxString& s) { return s.IsSameAs(c); }
2585 inline bool operator==(wchar_t c, const wxString& s) { return s.IsSameAs(c); }
2586 inline bool operator==(int c, const wxString& s) { return s.IsSameAs(c); }
2587 inline bool operator==(const wxString& s, const wxUniChar& c) { return s.IsSameAs(c); }
2588 inline bool operator==(const wxString& s, const wxUniCharRef& c) { return s.IsSameAs(c); }
2589 inline bool operator==(const wxString& s, char c) { return s.IsSameAs(c); }
2590 inline bool operator==(const wxString& s, wchar_t c) { return s.IsSameAs(c); }
2591 inline bool operator!=(const wxUniChar& c, const wxString& s) { return !s.IsSameAs(c); }
2592 inline bool operator!=(const wxUniCharRef& c, const wxString& s) { return !s.IsSameAs(c); }
2593 inline bool operator!=(char c, const wxString& s) { return !s.IsSameAs(c); }
2594 inline bool operator!=(wchar_t c, const wxString& s) { return !s.IsSameAs(c); }
2595 inline bool operator!=(int c, const wxString& s) { return !s.IsSameAs(c); }
2596 inline bool operator!=(const wxString& s, const wxUniChar& c) { return !s.IsSameAs(c); }
2597 inline bool operator!=(const wxString& s, const wxUniCharRef& c) { return !s.IsSameAs(c); }
2598 inline bool operator!=(const wxString& s, char c) { return !s.IsSameAs(c); }
2599 inline bool operator!=(const wxString& s, wchar_t c) { return !s.IsSameAs(c); }
2600
2601 // comparison with C string in Unicode build
2602 #if wxUSE_UNICODE
2603
2604 #define wxCMP_CHAR_STRING(p, s, op) wxString(p) op s
2605
2606 wxDEFINE_ALL_COMPARISONS(const char *, const wxString&, wxCMP_CHAR_STRING)
2607
2608 #undef wxCMP_CHAR_STRING
2609
2610 #endif // wxUSE_UNICODE
2611
2612 // we also need to provide the operators for comparison with wxCStrData to
2613 // resolve ambiguity between operator(const wxChar *,const wxString &) and
2614 // operator(const wxChar *, const wxChar *) for "p == s.c_str()"
2615 //
2616 // notice that these are (shallow) pointer comparisons, not (deep) string ones
2617 #define wxCMP_CHAR_CSTRDATA(p, s, op) p op s.AsChar()
2618 #define wxCMP_WCHAR_CSTRDATA(p, s, op) p op s.AsWChar()
2619
2620 wxDEFINE_ALL_COMPARISONS(const wchar_t *, const wxCStrData&, wxCMP_WCHAR_CSTRDATA)
2621 wxDEFINE_ALL_COMPARISONS(const char *, const wxCStrData&, wxCMP_CHAR_CSTRDATA)
2622
2623 #undef wxCMP_CHAR_CSTRDATA
2624 #undef wxCMP_WCHAR_CSTRDATA
2625
2626 // ---------------------------------------------------------------------------
2627 // Implementation only from here until the end of file
2628 // ---------------------------------------------------------------------------
2629
2630 #if wxUSE_STD_IOSTREAM
2631
2632 #include "wx/iosfwrap.h"
2633
2634 WXDLLIMPEXP_BASE wxSTD ostream& operator<<(wxSTD ostream&, const wxString&);
2635 WXDLLIMPEXP_BASE wxSTD ostream& operator<<(wxSTD ostream&, const wxCStrData&);
2636 WXDLLIMPEXP_BASE wxSTD ostream& operator<<(wxSTD ostream&, const wxCharBuffer&);
2637 #ifndef __BORLANDC__
2638 WXDLLIMPEXP_BASE wxSTD ostream& operator<<(wxSTD ostream&, const wxWCharBuffer&);
2639 #endif
2640
2641 #endif // wxSTD_STRING_COMPATIBILITY
2642
2643 // ---------------------------------------------------------------------------
2644 // wxCStrData implementation
2645 // ---------------------------------------------------------------------------
2646
2647 inline wxCStrData::wxCStrData(char *buf)
2648 : m_str(new wxString(buf)), m_offset(0), m_owned(true) {}
2649 inline wxCStrData::wxCStrData(wchar_t *buf)
2650 : m_str(new wxString(buf)), m_offset(0), m_owned(true) {}
2651
2652 inline wxCStrData::~wxCStrData()
2653 {
2654 if ( m_owned )
2655 delete m_str;
2656 }
2657
2658 // simple cases for AsChar() and AsWChar(), the complicated ones are
2659 // in string.cpp
2660 #if wxUSE_UNICODE_WCHAR
2661 inline const wchar_t* wxCStrData::AsWChar() const
2662 {
2663 return m_str->wx_str() + m_offset;
2664 }
2665 #endif // wxUSE_UNICODE_WCHAR
2666
2667 #if !wxUSE_UNICODE
2668 inline const char* wxCStrData::AsChar() const
2669 {
2670 return m_str->wx_str() + m_offset;
2671 }
2672 #endif // !wxUSE_UNICODE
2673
2674 inline const wxCharBuffer wxCStrData::AsCharBuf() const
2675 {
2676 #if !wxUSE_UNICODE
2677 return wxCharBuffer::CreateNonOwned(AsChar());
2678 #else
2679 return AsString().mb_str();
2680 #endif
2681 }
2682
2683 inline const wxWCharBuffer wxCStrData::AsWCharBuf() const
2684 {
2685 #if wxUSE_UNICODE_WCHAR
2686 return wxWCharBuffer::CreateNonOwned(AsWChar());
2687 #else
2688 return AsString().wc_str();
2689 #endif
2690 }
2691
2692 inline wxString wxCStrData::AsString() const
2693 {
2694 if ( m_offset == 0 )
2695 return *m_str;
2696 else
2697 return m_str->Mid(m_offset);
2698 }
2699
2700 inline const wxStringCharType *wxCStrData::AsInternal() const
2701 {
2702 return wxStringOperations::AddToIter(m_str->wx_str(), m_offset);
2703 }
2704
2705 inline wxUniChar wxCStrData::operator*() const
2706 {
2707 if ( m_str->empty() )
2708 return wxUniChar(_T('\0'));
2709 else
2710 return (*m_str)[m_offset];
2711 }
2712
2713 inline wxUniChar wxCStrData::operator[](size_t n) const
2714 {
2715 // NB: we intentionally use operator[] and not at() here because the former
2716 // works for the terminating NUL while the latter does not
2717 return (*m_str)[m_offset + n];
2718 }
2719
2720 // ----------------------------------------------------------------------------
2721 // more wxCStrData operators
2722 // ----------------------------------------------------------------------------
2723
2724 // we need to define those to allow "size_t pos = p - s.c_str()" where p is
2725 // some pointer into the string
2726 inline size_t operator-(const char *p, const wxCStrData& cs)
2727 {
2728 return p - cs.AsChar();
2729 }
2730
2731 inline size_t operator-(const wchar_t *p, const wxCStrData& cs)
2732 {
2733 return p - cs.AsWChar();
2734 }
2735
2736 // ----------------------------------------------------------------------------
2737 // implementation of wx[W]CharBuffer inline methods using wxCStrData
2738 // ----------------------------------------------------------------------------
2739
2740 // FIXME-UTF8: move this to buffer.h
2741 inline wxCharBuffer::wxCharBuffer(const wxCStrData& cstr)
2742 : wxCharTypeBufferBase(cstr.AsCharBuf())
2743 {
2744 }
2745
2746 inline wxWCharBuffer::wxWCharBuffer(const wxCStrData& cstr)
2747 : wxCharTypeBufferBase(cstr.AsWCharBuf())
2748 {
2749 }
2750
2751 #endif // _WX_WXSTRING_H_