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