1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxString class
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
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.
18 #ifndef _WX_WXSTRING_H__
19 #define _WX_WXSTRING_H__
21 // ----------------------------------------------------------------------------
23 // ----------------------------------------------------------------------------
25 #include "wx/defs.h" // everybody should include this
27 #if defined(__WXMAC__) || defined(__VISAGECPP__)
31 #if defined(__VISAGECPP__) && __IBMCPP__ >= 400
32 // problem in VACPP V4 with including stdlib.h multiple times
33 // strconv includes it anyway
46 #ifdef HAVE_STRCASECMP_IN_STRINGS_H
47 #include <strings.h> // for strcasecmp()
48 #endif // HAVE_STRCASECMP_IN_STRINGS_H
51 #include <StringMgr.h>
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"
62 class WXDLLIMPEXP_BASE wxString
;
64 // unless this symbol is predefined to disable the compatibility functions, do
66 #ifndef WXWIN_COMPATIBILITY_STRING_PTR_AS_ITER
67 #define WXWIN_COMPATIBILITY_STRING_PTR_AS_ITER 1
70 // ---------------------------------------------------------------------------
72 // ---------------------------------------------------------------------------
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 *)
81 // ----------------------------------------------------------------------------
83 // ----------------------------------------------------------------------------
85 #if WXWIN_COMPATIBILITY_2_6
87 // deprecated in favour of wxString::npos, don't use in new code
89 // maximum possible length for a string means "take all string" everywhere
90 #define wxSTRING_MAXLEN wxString::npos
92 #endif // WXWIN_COMPATIBILITY_2_6
94 // ---------------------------------------------------------------------------
95 // global functions complementing standard C string library replacements for
96 // strlen() and portable strcasecmp()
97 //---------------------------------------------------------------------------
99 #if WXWIN_COMPATIBILITY_2_8
100 // Use wxXXX() functions from wxcrt.h instead! These functions are for
101 // backwards compatibility only.
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
); }
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; }
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
)
116 #if defined(__VISUALC__) && defined(__WXWINCE__)
117 register char c1
, c2
;
119 c1
= tolower(*psz1
++);
120 c2
= tolower(*psz2
++);
121 } while ( c1
&& (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
;
148 c1
= tolower(*psz1
++);
149 c2
= tolower(*psz2
++);
150 } while ( c1
&& (c1
== c2
) );
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):
158 register char c1, c2;
160 c1 = tolower(*psz1++);
161 c2 = tolower(*psz2++);
162 } while ( c1 && (c1 == c2) );
167 #error "Please define string case-insensitive compare for your OS/compiler"
168 #endif // OS/compiler
171 #endif // WXWIN_COMPATIBILITY_2_8
173 // ----------------------------------------------------------------------------
175 // ----------------------------------------------------------------------------
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
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
) {}
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 inline wxCStrData(char *buf
);
190 inline wxCStrData(wchar_t *buf
);
191 inline wxCStrData(const wxCStrData
& data
);
193 inline ~wxCStrData();
195 // methods defined inline below must be declared inline or mingw32 3.4.5
196 // warns about "<symbol> defined locally after being referenced with
197 // dllimport linkage"
198 #if wxUSE_UNICODE_WCHAR
201 const wchar_t* AsWChar() const;
202 operator const wchar_t*() const { return AsWChar(); }
204 #if !wxUSE_UNICODE || wxUSE_UTF8_LOCALE_ONLY
207 const char* AsChar() const;
208 const unsigned char* AsUnsignedChar() const
209 { return (const unsigned char *) AsChar(); }
210 operator const char*() const { return AsChar(); }
211 operator const unsigned char*() const { return AsUnsignedChar(); }
213 operator const void*() const { return AsChar(); }
215 inline const wxCharBuffer
AsCharBuf() const;
216 inline const wxWCharBuffer
AsWCharBuf() const;
218 inline wxString
AsString() const;
220 // returns the value as C string in internal representation (equivalent
221 // to AsString().wx_str(), but more efficient)
222 const wxStringCharType
*AsInternal() const;
224 // allow expressions like "c_str()[0]":
225 inline wxUniChar
operator[](size_t n
) const;
226 wxUniChar
operator[](int n
) const { return operator[](size_t(n
)); }
227 wxUniChar
operator[](long n
) const { return operator[](size_t(n
)); }
228 #ifndef wxSIZE_T_IS_UINT
229 wxUniChar
operator[](unsigned int n
) const { return operator[](size_t(n
)); }
230 #endif // size_t != unsigned int
232 // these operators are needed to emulate the pointer semantics of c_str():
233 // expressions like "wxChar *p = str.c_str() + 1;" should continue to work
234 // (we need both versions to resolve ambiguities):
235 wxCStrData
operator+(int n
) const
236 { return wxCStrData(m_str
, m_offset
+ n
, m_owned
); }
237 wxCStrData
operator+(long n
) const
238 { return wxCStrData(m_str
, m_offset
+ n
, m_owned
); }
239 wxCStrData
operator+(size_t n
) const
240 { return wxCStrData(m_str
, m_offset
+ n
, m_owned
); }
242 // and these for "str.c_str() + n - 2":
243 wxCStrData
operator-(int n
) const
245 wxASSERT_MSG( n
<= (int)m_offset
,
246 _T("attempt to construct address before the beginning of the string") );
247 return wxCStrData(m_str
, m_offset
- n
, m_owned
);
249 wxCStrData
operator-(long n
) const
251 wxASSERT_MSG( n
<= (int)m_offset
,
252 _T("attempt to construct address before the beginning of the string") );
253 return wxCStrData(m_str
, m_offset
- n
, m_owned
);
255 wxCStrData
operator-(size_t n
) const
257 wxASSERT_MSG( n
<= m_offset
,
258 _T("attempt to construct address before the beginning of the string") );
259 return wxCStrData(m_str
, m_offset
- n
, m_owned
);
262 // this operator is needed to make expressions like "*c_str()" or
263 // "*(c_str() + 2)" work
264 inline wxUniChar
operator*() const;
267 const wxString
*m_str
;
271 friend class WXDLLIMPEXP_BASE wxString
;
274 // ----------------------------------------------------------------------------
275 // wxStringPrintfMixin
276 // ---------------------------------------------------------------------------
278 // NB: VC6 has a bug that causes linker errors if you have template methods
279 // in a class using __declspec(dllimport). The solution is to split such
280 // class into two classes, one that contains the template methods and does
281 // *not* use WXDLLIMPEXP_BASE and another class that contains the rest
282 // (with DLL linkage).
284 // We only do this for VC6 here, because the code is less efficient
285 // (Printf() has to use dynamic_cast<>) and because OpenWatcom compiler
286 // cannot compile this code.
288 #if defined(__VISUALC__) && __VISUALC__ < 1300
289 #define wxNEEDS_WXSTRING_PRINTF_MIXIN
292 #ifdef wxNEEDS_WXSTRING_PRINTF_MIXIN
293 // this class contains implementation of wxString's vararg methods, it's
294 // exported from wxBase DLL
295 class WXDLLIMPEXP_BASE wxStringPrintfMixinBase
298 wxStringPrintfMixinBase() {}
300 #if !wxUSE_UTF8_LOCALE_ONLY
301 int DoPrintfWchar(const wxChar
*format
, ...);
302 static wxString
DoFormatWchar(const wxChar
*format
, ...);
304 #if wxUSE_UNICODE_UTF8
305 int DoPrintfUtf8(const char *format
, ...);
306 static wxString
DoFormatUtf8(const char *format
, ...);
310 // this class contains template wrappers for wxString's vararg methods, it's
311 // intentionally *not* exported from the DLL in order to fix the VC6 bug
313 class wxStringPrintfMixin
: public wxStringPrintfMixinBase
316 // to further complicate things, we can't return wxString from
317 // wxStringPrintfMixin::Format() because wxString is not yet declared at
318 // this point; the solution is to use this fake type trait template - this
319 // way the compiler won't know the return type until Format() is used
320 // (this doesn't compile with Watcom, but VC6 compiles it just fine):
321 template<typename T
> struct StringReturnType
323 typedef wxString type
;
327 // these are duplicated wxString methods, they're also declared below
328 // if !wxNEEDS_WXSTRING_PRINTF_MIXIN:
330 // static wxString Format(const wString& format, ...) ATTRIBUTE_PRINTF_1;
331 WX_DEFINE_VARARG_FUNC_SANS_N0(static typename StringReturnType
<T1
>::type
,
332 Format
, 1, (const wxFormatString
&),
333 DoFormatWchar
, DoFormatUtf8
)
334 // We have to implement the version without template arguments manually
335 // because of the StringReturnType<> hack, although WX_DEFINE_VARARG_FUNC
336 // normally does it itself. It has to be a template so that we can use
337 // the hack, even though there's no real template parameter:
338 struct FormatDummyArg
{} ;
341 inline static typename StringReturnType
<T
>::type
342 Format(const wxFormatString
& fmt
, FormatDummyArg dummy
= FormatDummyArg())
344 return DoFormatWchar(fmt
);
347 // int Printf(const wxString& format, ...);
348 WX_DEFINE_VARARG_FUNC(int, Printf
, 1, (const wxFormatString
&),
349 DoPrintfWchar
, DoPrintfUtf8
)
350 // int sprintf(const wxString& format, ...) ATTRIBUTE_PRINTF_2;
351 WX_DEFINE_VARARG_FUNC(int, sprintf
, 1, (const wxFormatString
&),
352 DoPrintfWchar
, DoPrintfUtf8
)
355 wxStringPrintfMixin() : wxStringPrintfMixinBase() {}
357 #endif // wxNEEDS_WXSTRING_PRINTF_MIXIN
360 // ----------------------------------------------------------------------------
361 // wxString: string class trying to be compatible with std::string, MFC
362 // CString and wxWindows 1.x wxString all at once
363 // ---------------------------------------------------------------------------
365 #ifdef wxNEEDS_WXSTRING_PRINTF_MIXIN
366 // "non dll-interface class 'wxStringPrintfMixin' used as base interface
367 // for dll-interface class 'wxString'" -- this is OK in our case
368 #pragma warning (disable:4275)
371 class WXDLLIMPEXP_BASE wxString
372 #ifdef wxNEEDS_WXSTRING_PRINTF_MIXIN
373 : public wxStringPrintfMixin
376 // NB: special care was taken in arranging the member functions in such order
377 // that all inline functions can be effectively inlined, verify that all
378 // performance critical functions are still inlined if you change order!
380 // an 'invalid' value for string index, moved to this place due to a CW bug
381 static const size_t npos
;
384 // if we hadn't made these operators private, it would be possible to
385 // compile "wxString s; s = 17;" without any warnings as 17 is implicitly
386 // converted to char in C and we do have operator=(char)
388 // NB: we don't need other versions (short/long and unsigned) as attempt
389 // to assign another numeric type to wxString will now result in
390 // ambiguity between operator=(char) and operator=(int)
391 wxString
& operator=(int);
393 // these methods are not implemented - there is _no_ conversion from int to
394 // string, you're doing something wrong if the compiler wants to call it!
396 // try `s << i' or `s.Printf("%d", i)' instead
400 // buffer for holding temporary substring when using any of the methods
401 // that take (char*,size_t) or (wchar_t*,size_t) arguments:
403 struct SubstrBufFromType
408 SubstrBufFromType(const T
& data_
, size_t len_
)
409 : data(data_
), len(len_
) {}
412 #if wxUSE_UNICODE_UTF8
413 // even char* -> char* needs conversion, from locale charset to UTF-8
414 typedef SubstrBufFromType
<wxCharBuffer
> SubstrBufFromWC
;
415 typedef SubstrBufFromType
<wxCharBuffer
> SubstrBufFromMB
;
416 #elif wxUSE_UNICODE_WCHAR
417 typedef SubstrBufFromType
<const wchar_t*> SubstrBufFromWC
;
418 typedef SubstrBufFromType
<wxWCharBuffer
> SubstrBufFromMB
;
420 typedef SubstrBufFromType
<const char*> SubstrBufFromMB
;
421 typedef SubstrBufFromType
<wxCharBuffer
> SubstrBufFromWC
;
425 // Functions implementing primitive operations on string data; wxString
426 // methods and iterators are implemented in terms of it. The differences
427 // between UTF-8 and wchar_t* representations of the string are mostly
430 #if wxUSE_UNICODE_UTF8
431 static SubstrBufFromMB
ConvertStr(const char *psz
, size_t nLength
,
432 const wxMBConv
& conv
);
433 static SubstrBufFromWC
ConvertStr(const wchar_t *pwz
, size_t nLength
,
434 const wxMBConv
& conv
);
435 #elif wxUSE_UNICODE_WCHAR
436 static SubstrBufFromMB
ConvertStr(const char *psz
, size_t nLength
,
437 const wxMBConv
& conv
);
439 static SubstrBufFromWC
ConvertStr(const wchar_t *pwz
, size_t nLength
,
440 const wxMBConv
& conv
);
443 #if !wxUSE_UNICODE_UTF8 // wxUSE_UNICODE_WCHAR or !wxUSE_UNICODE
444 // returns C string encoded as the implementation expects:
446 static const wchar_t* ImplStr(const wchar_t* str
)
447 { return str
? str
: wxT(""); }
448 static const SubstrBufFromWC
ImplStr(const wchar_t* str
, size_t n
)
449 { return SubstrBufFromWC(str
, (str
&& n
== npos
) ? wxWcslen(str
) : n
); }
450 static wxWCharBuffer
ImplStr(const char* str
,
451 const wxMBConv
& conv
= wxConvLibc
)
452 { return ConvertStr(str
, npos
, conv
).data
; }
453 static SubstrBufFromMB
ImplStr(const char* str
, size_t n
,
454 const wxMBConv
& conv
= wxConvLibc
)
455 { return ConvertStr(str
, n
, conv
); }
457 static const char* ImplStr(const char* str
,
458 const wxMBConv
& WXUNUSED(conv
) = wxConvLibc
)
459 { return str
? str
: ""; }
460 static const SubstrBufFromMB
ImplStr(const char* str
, size_t n
,
461 const wxMBConv
& WXUNUSED(conv
) = wxConvLibc
)
462 { return SubstrBufFromMB(str
, (str
&& n
== npos
) ? wxStrlen(str
) : n
); }
463 static wxCharBuffer
ImplStr(const wchar_t* str
)
464 { return ConvertStr(str
, npos
, wxConvLibc
).data
; }
465 static SubstrBufFromWC
ImplStr(const wchar_t* str
, size_t n
)
466 { return ConvertStr(str
, n
, wxConvLibc
); }
469 // translates position index in wxString to/from index in underlying
471 static size_t PosToImpl(size_t pos
) { return pos
; }
472 static void PosLenToImpl(size_t pos
, size_t len
,
473 size_t *implPos
, size_t *implLen
)
474 { *implPos
= pos
; *implLen
= len
; }
475 static size_t LenToImpl(size_t len
) { return len
; }
476 static size_t PosFromImpl(size_t pos
) { return pos
; }
478 #else // wxUSE_UNICODE_UTF8
480 static wxCharBuffer
ImplStr(const char* str
,
481 const wxMBConv
& conv
= wxConvLibc
)
482 { return ConvertStr(str
, npos
, conv
).data
; }
483 static SubstrBufFromMB
ImplStr(const char* str
, size_t n
,
484 const wxMBConv
& conv
= wxConvLibc
)
485 { return ConvertStr(str
, n
, conv
); }
487 static wxCharBuffer
ImplStr(const wchar_t* str
)
488 { return ConvertStr(str
, npos
, wxConvUTF8
).data
; }
489 static SubstrBufFromWC
ImplStr(const wchar_t* str
, size_t n
)
490 { return ConvertStr(str
, n
, wxConvUTF8
); }
492 size_t PosToImpl(size_t pos
) const
494 if ( pos
== 0 || pos
== npos
)
497 return (begin() + pos
).impl() - m_impl
.begin();
500 void PosLenToImpl(size_t pos
, size_t len
, size_t *implPos
, size_t *implLen
) const;
502 size_t LenToImpl(size_t len
) const
505 PosLenToImpl(0, len
, &pos
, &len2
);
509 size_t PosFromImpl(size_t pos
) const
511 if ( pos
== 0 || pos
== npos
)
514 return const_iterator(m_impl
.begin() + pos
) - begin();
516 #endif // !wxUSE_UNICODE_UTF8/wxUSE_UNICODE_UTF8
520 typedef wxUniChar value_type
;
521 typedef wxUniChar char_type
;
522 typedef wxUniCharRef reference
;
523 typedef wxChar
* pointer
;
524 typedef const wxChar
* const_pointer
;
526 typedef size_t size_type
;
527 typedef wxUniChar const_reference
;
530 #if wxUSE_UNICODE_UTF8
531 // random access is not O(1), as required by Random Access Iterator
532 #define WX_STR_ITERATOR_TAG std::bidirectional_iterator_tag
534 #define WX_STR_ITERATOR_TAG std::random_access_iterator_tag
537 #define WX_STR_ITERATOR_TAG void /* dummy type */
540 #define WX_STR_ITERATOR_IMPL(iterator_name, pointer_type, \
541 reference_type, reference_ctor) \
543 typedef wxStringImpl::iterator_name underlying_iterator; \
545 typedef WX_STR_ITERATOR_TAG iterator_category; \
546 typedef wxUniChar value_type; \
547 typedef int difference_type; \
548 typedef reference_type reference; \
549 typedef pointer_type pointer; \
551 reference operator*() const { return reference_ctor; } \
552 reference operator[](size_t n) const { return *(*this + n); } \
554 iterator_name& operator++() \
555 { wxStringOperations::IncIter(m_cur); return *this; } \
556 iterator_name& operator--() \
557 { wxStringOperations::DecIter(m_cur); return *this; } \
558 iterator_name operator++(int) \
560 iterator_name tmp = *this; \
561 wxStringOperations::IncIter(m_cur); \
564 iterator_name operator--(int) \
566 iterator_name tmp = *this; \
567 wxStringOperations::DecIter(m_cur); \
571 iterator_name& operator+=(int n) \
573 m_cur = wxStringOperations::AddToIter(m_cur, n); \
576 iterator_name& operator+=(size_t n) \
578 m_cur = wxStringOperations::AddToIter(m_cur, (int)n); \
581 iterator_name& operator-=(int n) \
583 m_cur = wxStringOperations::AddToIter(m_cur, -n); \
586 iterator_name& operator-=(size_t n) \
588 m_cur = wxStringOperations::AddToIter(m_cur, -(int)n); \
592 difference_type operator-(const iterator_name& i) const \
593 { return wxStringOperations::DiffIters(m_cur, i.m_cur); } \
595 bool operator==(const iterator_name& i) const \
596 { return m_cur == i.m_cur; } \
597 bool operator!=(const iterator_name& i) const \
598 { return m_cur != i.m_cur; } \
600 bool operator<(const iterator_name& i) const \
601 { return m_cur < i.m_cur; } \
602 bool operator>(const iterator_name& i) const \
603 { return m_cur > i.m_cur; } \
604 bool operator<=(const iterator_name& i) const \
605 { return m_cur <= i.m_cur; } \
606 bool operator>=(const iterator_name& i) const \
607 { return m_cur >= i.m_cur; } \
610 /* for internal wxString use only: */ \
611 underlying_iterator impl() const { return m_cur; } \
613 friend class WXDLLIMPEXP_BASE wxString; \
614 friend class WXDLLIMPEXP_BASE wxCStrData; \
617 underlying_iterator m_cur
619 class const_iterator
;
621 #if wxUSE_UNICODE_UTF8
624 // NB: In UTF-8 build, (non-const) iterator needs to keep reference
625 // to the underlying wxStringImpl, because UTF-8 is variable-length
626 // encoding and changing the value pointer to by an iterator using
627 // its operator* requires calling wxStringImpl::replace() if the old
628 // and new values differ in their encoding's length.
630 WX_STR_ITERATOR_IMPL(iterator
, wxChar
*, wxUniCharRef
,
631 wxUniCharRef::CreateForString(m_str
, m_cur
));
634 iterator(const iterator
& i
) : m_cur(i
.m_cur
), m_str(i
.m_str
) {}
636 iterator
operator+(int n
) const
637 { return iterator(m_str
, wxStringOperations::AddToIter(m_cur
, n
)); }
638 iterator
operator+(size_t n
) const
639 { return iterator(m_str
, wxStringOperations::AddToIter(m_cur
, (int)n
)); }
640 iterator
operator-(int n
) const
641 { return iterator(m_str
, wxStringOperations::AddToIter(m_cur
, -n
)); }
642 iterator
operator-(size_t n
) const
643 { return iterator(m_str
, wxStringOperations::AddToIter(m_cur
, -(int)n
)); }
646 iterator(wxString
*str
, underlying_iterator ptr
)
647 : m_cur(ptr
), m_str(str
->m_impl
) {}
648 iterator(wxStringImpl
& str
, underlying_iterator ptr
)
649 : m_cur(ptr
), m_str(str
) {}
653 friend class const_iterator
;
656 size_t IterToImplPos(wxString::iterator i
) const
657 { return wxStringImpl::const_iterator(i
.impl()) - m_impl
.begin(); }
659 #else // !wxUSE_UNICODE_UTF8
663 WX_STR_ITERATOR_IMPL(iterator
, wxChar
*, wxUniCharRef
,
664 wxUniCharRef::CreateForString(m_cur
));
667 iterator(const iterator
& i
) : m_cur(i
.m_cur
) {}
669 iterator
operator+(int n
) const
670 { return iterator(wxStringOperations::AddToIter(m_cur
, n
)); }
671 iterator
operator+(size_t n
) const
672 { return iterator(wxStringOperations::AddToIter(m_cur
, (int)n
)); }
673 iterator
operator-(int n
) const
674 { return iterator(wxStringOperations::AddToIter(m_cur
, -n
)); }
675 iterator
operator-(size_t n
) const
676 { return iterator(wxStringOperations::AddToIter(m_cur
, -(int)n
)); }
679 // for internal wxString use only:
680 iterator(underlying_iterator ptr
) : m_cur(ptr
) {}
681 iterator(wxString
*WXUNUSED(str
), underlying_iterator ptr
) : m_cur(ptr
) {}
683 friend class const_iterator
;
685 #endif // wxUSE_UNICODE_UTF8/!wxUSE_UNICODE_UTF8
689 // NB: reference_type is intentionally value, not reference, the character
690 // may be encoded differently in wxString data:
691 WX_STR_ITERATOR_IMPL(const_iterator
, const wxChar
*, wxUniChar
,
692 wxStringOperations::DecodeChar(m_cur
));
695 const_iterator(const const_iterator
& i
) : m_cur(i
.m_cur
) {}
696 const_iterator(const iterator
& i
) : m_cur(i
.m_cur
) {}
698 const_iterator
operator+(int n
) const
699 { return const_iterator(wxStringOperations::AddToIter(m_cur
, n
)); }
700 const_iterator
operator+(size_t n
) const
701 { return const_iterator(wxStringOperations::AddToIter(m_cur
, (int)n
)); }
702 const_iterator
operator-(int n
) const
703 { return const_iterator(wxStringOperations::AddToIter(m_cur
, -n
)); }
704 const_iterator
operator-(size_t n
) const
705 { return const_iterator(wxStringOperations::AddToIter(m_cur
, -(int)n
)); }
708 // for internal wxString use only:
709 const_iterator(underlying_iterator ptr
) : m_cur(ptr
) {}
712 #undef WX_STR_ITERATOR_TAG
713 #undef WX_STR_ITERATOR_IMPL
715 friend class iterator
;
716 friend class const_iterator
;
718 template <typename T
>
719 class reverse_iterator_impl
722 typedef T iterator_type
;
724 typedef typename
T::iterator_category iterator_category
;
725 typedef typename
T::value_type value_type
;
726 typedef typename
T::difference_type difference_type
;
727 typedef typename
T::reference reference
;
728 typedef typename
T::pointer
*pointer
;
730 reverse_iterator_impl(iterator_type i
) : m_cur(i
) {}
731 reverse_iterator_impl(const reverse_iterator_impl
& ri
)
734 iterator_type
base() const { return m_cur
; }
736 reference
operator*() const { return *(m_cur
-1); }
737 reference
operator[](size_t n
) const { return *(*this + n
); }
739 reverse_iterator_impl
& operator++()
740 { --m_cur
; return *this; }
741 reverse_iterator_impl
operator++(int)
742 { reverse_iterator_impl tmp
= *this; --m_cur
; return tmp
; }
743 reverse_iterator_impl
& operator--()
744 { ++m_cur
; return *this; }
745 reverse_iterator_impl
operator--(int)
746 { reverse_iterator_impl tmp
= *this; ++m_cur
; return tmp
; }
748 // NB: explicit <T> in the functions below is to keep BCC 5.5 happy
749 reverse_iterator_impl
operator+(int n
) const
750 { return reverse_iterator_impl
<T
>(m_cur
- n
); }
751 reverse_iterator_impl
operator+(size_t n
) const
752 { return reverse_iterator_impl
<T
>(m_cur
- n
); }
753 reverse_iterator_impl
operator-(int n
) const
754 { return reverse_iterator_impl
<T
>(m_cur
+ n
); }
755 reverse_iterator_impl
operator-(size_t n
) const
756 { return reverse_iterator_impl
<T
>(m_cur
+ n
); }
757 reverse_iterator_impl
operator+=(int n
)
758 { m_cur
-= n
; return *this; }
759 reverse_iterator_impl
operator+=(size_t n
)
760 { m_cur
-= n
; return *this; }
761 reverse_iterator_impl
operator-=(int n
)
762 { m_cur
+= n
; return *this; }
763 reverse_iterator_impl
operator-=(size_t n
)
764 { m_cur
+= n
; return *this; }
766 unsigned operator-(const reverse_iterator_impl
& i
) const
767 { return i
.m_cur
- m_cur
; }
769 bool operator==(const reverse_iterator_impl
& ri
) const
770 { return m_cur
== ri
.m_cur
; }
771 bool operator!=(const reverse_iterator_impl
& ri
) const
772 { return !(*this == ri
); }
774 bool operator<(const reverse_iterator_impl
& i
) const
775 { return m_cur
> i
.m_cur
; }
776 bool operator>(const reverse_iterator_impl
& i
) const
777 { return m_cur
< i
.m_cur
; }
778 bool operator<=(const reverse_iterator_impl
& i
) const
779 { return m_cur
>= i
.m_cur
; }
780 bool operator>=(const reverse_iterator_impl
& i
) const
781 { return m_cur
<= i
.m_cur
; }
787 typedef reverse_iterator_impl
<iterator
> reverse_iterator
;
788 typedef reverse_iterator_impl
<const_iterator
> const_reverse_iterator
;
791 // used to transform an expression built using c_str() (and hence of type
792 // wxCStrData) to an iterator into the string
793 static const_iterator
CreateConstIterator(const wxCStrData
& data
)
795 return const_iterator(data
.m_str
->begin() + data
.m_offset
);
798 // in UTF-8 STL build, creation from std::string requires conversion under
799 // non-UTF8 locales, so we can't have and use wxString(wxStringImpl) ctor;
800 // instead we define dummy type that lets us have wxString ctor for creation
801 // from wxStringImpl that couldn't be used by user code (in all other builds,
802 // "standard" ctors can be used):
803 #if wxUSE_UNICODE_UTF8 && wxUSE_STL_BASED_WXSTRING
804 struct CtorFromStringImplTag
{};
806 wxString(CtorFromStringImplTag
* WXUNUSED(dummy
), const wxStringImpl
& src
)
809 static wxString
FromImpl(const wxStringImpl
& src
)
810 { return wxString((CtorFromStringImplTag
*)NULL
, src
); }
812 #if !wxUSE_STL_BASED_WXSTRING
813 wxString(const wxStringImpl
& src
) : m_impl(src
) { }
814 // else: already defined as wxString(wxStdString) below
816 static wxString
FromImpl(const wxStringImpl
& src
) { return wxString(src
); }
820 // constructors and destructor
821 // ctor for an empty string
825 wxString(const wxString
& stringSrc
) : m_impl(stringSrc
.m_impl
) { }
827 // string containing nRepeat copies of ch
828 wxString(wxUniChar ch
, size_t nRepeat
= 1)
829 { assign(nRepeat
, ch
); }
830 wxString(size_t nRepeat
, wxUniChar ch
)
831 { assign(nRepeat
, ch
); }
832 wxString(wxUniCharRef ch
, size_t nRepeat
= 1)
833 { assign(nRepeat
, ch
); }
834 wxString(size_t nRepeat
, wxUniCharRef ch
)
835 { assign(nRepeat
, ch
); }
836 wxString(char ch
, size_t nRepeat
= 1)
837 { assign(nRepeat
, ch
); }
838 wxString(size_t nRepeat
, char ch
)
839 { assign(nRepeat
, ch
); }
840 wxString(wchar_t ch
, size_t nRepeat
= 1)
841 { assign(nRepeat
, ch
); }
842 wxString(size_t nRepeat
, wchar_t ch
)
843 { assign(nRepeat
, ch
); }
845 // ctors from char* strings:
846 wxString(const char *psz
)
847 : m_impl(ImplStr(psz
)) {}
848 wxString(const char *psz
, const wxMBConv
& conv
)
849 : m_impl(ImplStr(psz
, conv
)) {}
850 wxString(const char *psz
, size_t nLength
)
851 { assign(psz
, nLength
); }
852 wxString(const char *psz
, const wxMBConv
& conv
, size_t nLength
)
854 SubstrBufFromMB
str(ImplStr(psz
, nLength
, conv
));
855 m_impl
.assign(str
.data
, str
.len
);
858 // and unsigned char*:
859 wxString(const unsigned char *psz
)
860 : m_impl(ImplStr((const char*)psz
)) {}
861 wxString(const unsigned char *psz
, const wxMBConv
& conv
)
862 : m_impl(ImplStr((const char*)psz
, conv
)) {}
863 wxString(const unsigned char *psz
, size_t nLength
)
864 { assign((const char*)psz
, nLength
); }
865 wxString(const unsigned char *psz
, const wxMBConv
& conv
, size_t nLength
)
867 SubstrBufFromMB
str(ImplStr((const char*)psz
, nLength
, conv
));
868 m_impl
.assign(str
.data
, str
.len
);
871 // ctors from wchar_t* strings:
872 wxString(const wchar_t *pwz
)
873 : m_impl(ImplStr(pwz
)) {}
874 wxString(const wchar_t *pwz
, const wxMBConv
& WXUNUSED(conv
))
875 : m_impl(ImplStr(pwz
)) {}
876 wxString(const wchar_t *pwz
, size_t nLength
)
877 { assign(pwz
, nLength
); }
878 wxString(const wchar_t *pwz
, const wxMBConv
& WXUNUSED(conv
), size_t nLength
)
879 { assign(pwz
, nLength
); }
881 wxString(const wxCharBuffer
& buf
)
882 { assign(buf
.data()); } // FIXME-UTF8: fix for embedded NUL and buffer length
883 wxString(const wxWCharBuffer
& buf
)
884 { assign(buf
.data()); } // FIXME-UTF8: fix for embedded NUL and buffer length
886 wxString(const wxCStrData
& cstr
)
887 : m_impl(cstr
.AsString().m_impl
) { }
889 // as we provide both ctors with this signature for both char and unsigned
890 // char string, we need to provide one for wxCStrData to resolve ambiguity
891 wxString(const wxCStrData
& cstr
, size_t nLength
)
892 : m_impl(cstr
.AsString().Mid(0, nLength
).m_impl
) {}
894 // and because wxString is convertible to wxCStrData and const wxChar *
895 // we also need to provide this one
896 wxString(const wxString
& str
, size_t nLength
)
897 : m_impl(str
.Mid(0, nLength
).m_impl
) {}
899 // even if we're not built with wxUSE_STL == 1 it is very convenient to allow
900 // implicit conversions from std::string to wxString and vice verse as this
901 // allows to use the same strings in non-GUI and GUI code, however we don't
902 // want to unconditionally add this ctor as it would make wx lib dependent on
903 // libstdc++ on some Linux versions which is bad, so instead we ask the
904 // client code to define this wxUSE_STD_STRING symbol if they need it
906 #if wxUSE_UNICODE_WCHAR
907 wxString(const wxStdWideString
& str
) : m_impl(str
) {}
908 #else // UTF-8 or ANSI
909 wxString(const wxStdWideString
& str
)
910 { assign(str
.c_str(), str
.length()); }
913 #if !wxUSE_UNICODE // ANSI build
914 // FIXME-UTF8: do this in UTF8 build #if wxUSE_UTF8_LOCALE_ONLY, too
915 wxString(const std::string
& str
) : m_impl(str
) {}
917 wxString(const std::string
& str
)
918 { assign(str
.c_str(), str
.length()); }
921 #if wxUSE_UNICODE_WCHAR && wxUSE_STL_BASED_WXSTRING
922 // wxStringImpl is std::string in the encoding we want
923 operator const wxStdWideString
&() const { return m_impl
; }
925 // wxStringImpl is either not std::string or needs conversion
926 operator wxStdWideString() const
927 // FIXME-UTF8: broken for embedded NULs
928 { return wxStdWideString(wc_str()); }
931 #if (!wxUSE_UNICODE || wxUSE_UTF8_LOCALE_ONLY) && wxUSE_STL_BASED_WXSTRING
932 // wxStringImpl is std::string in the encoding we want
933 operator const std::string
&() const { return m_impl
; }
935 // wxStringImpl is either not std::string or needs conversion
936 operator std::string() const
937 // FIXME-UTF8: broken for embedded NULs
938 { return std::string(mb_str()); }
942 // first valid index position
943 const_iterator
begin() const { return const_iterator(m_impl
.begin()); }
944 iterator
begin() { return iterator(this, m_impl
.begin()); }
945 // position one after the last valid one
946 const_iterator
end() const { return const_iterator(m_impl
.end()); }
947 iterator
end() { return iterator(this, m_impl
.end()); }
949 // first element of the reversed string
950 const_reverse_iterator
rbegin() const
951 { return const_reverse_iterator(end()); }
952 reverse_iterator
rbegin()
953 { return reverse_iterator(end()); }
954 // one beyond the end of the reversed string
955 const_reverse_iterator
rend() const
956 { return const_reverse_iterator(begin()); }
957 reverse_iterator
rend()
958 { return reverse_iterator(begin()); }
960 // std::string methods:
961 #if wxUSE_UNICODE_UTF8
962 size_t length() const { return end() - begin(); } // FIXME-UTF8: optimize!
964 size_t length() const { return m_impl
.length(); }
967 size_type
size() const { return length(); }
968 size_type
max_size() const { return npos
; }
970 bool empty() const { return m_impl
.empty(); }
972 size_type
capacity() const { return m_impl
.capacity(); } // FIXME-UTF8
973 void reserve(size_t sz
) { m_impl
.reserve(sz
); } // FIXME-UTF8
975 void resize(size_t nSize
, wxUniChar ch
= wxT('\0'))
977 #if wxUSE_UNICODE_UTF8
980 size_t len
= length();
983 else if ( nSize
< len
)
986 append(nSize
- len
, ch
);
990 m_impl
.resize(nSize
, (wxStringCharType
)ch
);
993 wxString
substr(size_t nStart
= 0, size_t nLen
= npos
) const
996 PosLenToImpl(nStart
, nLen
, &pos
, &len
);
997 return FromImpl(m_impl
.substr(pos
, len
));
1000 // generic attributes & operations
1001 // as standard strlen()
1002 size_t Len() const { return length(); }
1003 // string contains any characters?
1004 bool IsEmpty() const { return empty(); }
1005 // empty string is "false", so !str will return true
1006 bool operator!() const { return empty(); }
1007 // truncate the string to given length
1008 wxString
& Truncate(size_t uiLen
);
1009 // empty string contents
1014 wxASSERT_MSG( empty(), _T("string not empty after call to Empty()?") );
1016 // empty the string and free memory
1019 wxString
tmp(wxEmptyString
);
1024 // Is an ascii value
1025 bool IsAscii() const;
1027 bool IsNumber() const;
1029 bool IsWord() const;
1031 // data access (all indexes are 0 based)
1033 wxUniChar
at(size_t n
) const
1034 { return *(begin() + n
); } // FIXME-UTF8: optimize?
1035 wxUniChar
GetChar(size_t n
) const
1037 // read/write access
1038 wxUniCharRef
at(size_t n
)
1039 { return *(begin() + n
); } // FIXME-UTF8: optimize?
1040 wxUniCharRef
GetWritableChar(size_t n
)
1043 void SetChar(size_t n
, wxUniChar ch
)
1046 // get last character
1047 wxUniChar
Last() const
1049 wxASSERT_MSG( !empty(), _T("wxString: index out of bounds") );
1051 return at(length() - 1);
1054 // get writable last character
1057 wxASSERT_MSG( !empty(), _T("wxString: index out of bounds") );
1058 return at(length() - 1);
1062 Note that we we must define all of the overloads below to avoid
1063 ambiguity when using str[0].
1065 wxUniChar
operator[](int n
) const
1067 wxUniChar
operator[](long n
) const
1069 wxUniChar
operator[](size_t n
) const
1071 #ifndef wxSIZE_T_IS_UINT
1072 wxUniChar
operator[](unsigned int n
) const
1074 #endif // size_t != unsigned int
1076 // operator versions of GetWriteableChar()
1077 wxUniCharRef
operator[](int n
)
1079 wxUniCharRef
operator[](long n
)
1081 wxUniCharRef
operator[](size_t n
)
1083 #ifndef wxSIZE_T_IS_UINT
1084 wxUniCharRef
operator[](unsigned int n
)
1086 #endif // size_t != unsigned int
1088 // explicit conversion to C string (use this with printf()!)
1089 wxCStrData
c_str() const { return wxCStrData(this); }
1090 wxCStrData
data() const { return c_str(); }
1092 // implicit conversion to C string
1093 operator wxCStrData() const { return c_str(); }
1094 operator const char*() const { return c_str(); }
1095 operator const wchar_t*() const { return c_str(); }
1097 // implicit conversion to untyped pointer for compatibility with previous
1098 // wxWidgets versions: this is the same as conversion to const char * so it
1100 operator const void*() const { return c_str(); }
1102 // identical to c_str(), for MFC compatibility
1103 const wxCStrData
GetData() const { return c_str(); }
1105 // explicit conversion to C string in internal representation (char*,
1106 // wchar_t*, UTF-8-encoded char*, depending on the build):
1107 const wxStringCharType
*wx_str() const { return m_impl
.c_str(); }
1109 // conversion to *non-const* multibyte or widestring buffer; modifying
1110 // returned buffer won't affect the string, these methods are only useful
1111 // for passing values to const-incorrect functions
1112 wxWritableCharBuffer
char_str(const wxMBConv
& conv
= wxConvLibc
) const
1113 { return mb_str(conv
); }
1114 wxWritableWCharBuffer
wchar_str() const { return wc_str(); }
1116 // conversion to/from plain (i.e. 7 bit) ASCII: this is useful for
1117 // converting numbers or strings which are certain not to contain special
1118 // chars (typically system functions, X atoms, environment variables etc.)
1120 // the behaviour of these functions with the strings containing anything
1121 // else than 7 bit ASCII characters is undefined, use at your own risk.
1123 static wxString
FromAscii(const char *ascii
); // string
1124 static wxString
FromAscii(const char ascii
); // char
1125 const wxCharBuffer
ToAscii() const;
1127 static wxString
FromAscii(const char *ascii
) { return wxString( ascii
); }
1128 static wxString
FromAscii(const char ascii
) { return wxString( ascii
); }
1129 const char *ToAscii() const { return c_str(); }
1130 #endif // Unicode/!Unicode
1132 // conversion to/from UTF-8:
1133 #if wxUSE_UNICODE_UTF8
1134 static wxString
FromUTF8(const char *utf8
)
1136 wxASSERT( wxStringOperations::IsValidUtf8String(utf8
) );
1137 return FromImpl(wxStringImpl(utf8
));
1139 static wxString
FromUTF8(const char *utf8
, size_t len
)
1141 wxASSERT( wxStringOperations::IsValidUtf8String(utf8
, len
) );
1142 return FromImpl(wxStringImpl(utf8
, len
));
1144 const char* utf8_str() const { return wx_str(); }
1145 const char* ToUTF8() const { return wx_str(); }
1146 #elif wxUSE_UNICODE_WCHAR
1147 static wxString
FromUTF8(const char *utf8
)
1148 { return wxString(utf8
, wxConvUTF8
); }
1149 static wxString
FromUTF8(const char *utf8
, size_t len
)
1150 { return wxString(utf8
, wxConvUTF8
, len
); }
1151 const wxCharBuffer
utf8_str() const { return mb_str(wxConvUTF8
); }
1152 const wxCharBuffer
ToUTF8() const { return utf8_str(); }
1154 static wxString
FromUTF8(const char *utf8
)
1155 { return wxString(wxConvUTF8
.cMB2WC(utf8
)); }
1156 static wxString
FromUTF8(const char *utf8
, size_t len
)
1159 wxWCharBuffer
buf(wxConvUTF8
.cMB2WC(utf8
, len
== npos
? wxNO_LEN
: len
, &wlen
));
1160 return wxString(buf
.data(), wlen
);
1162 const wxCharBuffer
utf8_str() const { return wxConvUTF8
.cWC2MB(wc_str()); }
1163 const wxCharBuffer
ToUTF8() const { return utf8_str(); }
1166 // functions for storing binary data in wxString:
1168 static wxString
From8BitData(const char *data
, size_t len
)
1169 { return wxString(data
, wxConvISO8859_1
, len
); }
1170 // version for NUL-terminated data:
1171 static wxString
From8BitData(const char *data
)
1172 { return wxString(data
, wxConvISO8859_1
); }
1173 const wxCharBuffer
To8BitData() const { return mb_str(wxConvISO8859_1
); }
1175 static wxString
From8BitData(const char *data
, size_t len
)
1176 { return wxString(data
, len
); }
1177 // version for NUL-terminated data:
1178 static wxString
From8BitData(const char *data
)
1179 { return wxString(data
); }
1180 const char *To8BitData() const { return c_str(); }
1181 #endif // Unicode/ANSI
1183 // conversions with (possible) format conversions: have to return a
1184 // buffer with temporary data
1186 // the functions defined (in either Unicode or ANSI) mode are mb_str() to
1187 // return an ANSI (multibyte) string, wc_str() to return a wide string and
1188 // fn_str() to return a string which should be used with the OS APIs
1189 // accepting the file names. The return value is always the same, but the
1190 // type differs because a function may either return pointer to the buffer
1191 // directly or have to use intermediate buffer for translation.
1194 #if wxUSE_UTF8_LOCALE_ONLY
1195 const char* mb_str() const { return wx_str(); }
1196 const wxCharBuffer
mb_str(const wxMBConv
& conv
) const;
1198 const wxCharBuffer
mb_str(const wxMBConv
& conv
= wxConvLibc
) const;
1201 const wxWX2MBbuf
mbc_str() const { return mb_str(*wxConvCurrent
); }
1203 #if wxUSE_UNICODE_WCHAR
1204 const wxChar
* wc_str() const { return wx_str(); }
1205 #elif wxUSE_UNICODE_UTF8
1206 const wxWCharBuffer
wc_str() const;
1208 // for compatibility with !wxUSE_UNICODE version
1209 const wxWX2WCbuf
wc_str(const wxMBConv
& WXUNUSED(conv
)) const
1210 { return wc_str(); }
1213 const wxCharBuffer
fn_str() const { return mb_str(wxConvFile
); }
1215 const wxWX2WCbuf
fn_str() const { return wc_str(); }
1216 #endif // wxMBFILES/!wxMBFILES
1219 const wxChar
* mb_str() const { return wx_str(); }
1221 // for compatibility with wxUSE_UNICODE version
1222 const wxChar
* mb_str(const wxMBConv
& WXUNUSED(conv
)) const { return wx_str(); }
1224 const wxWX2MBbuf
mbc_str() const { return mb_str(); }
1227 const wxWCharBuffer
wc_str(const wxMBConv
& conv
= wxConvLibc
) const;
1228 #endif // wxUSE_WCHAR_T
1230 const wxCharBuffer
fn_str() const { return wxConvFile
.cWC2WX( wc_str( wxConvLocal
) ); }
1232 const wxChar
* fn_str() const { return c_str(); }
1234 #endif // Unicode/ANSI
1236 // overloaded assignment
1237 // from another wxString
1238 wxString
& operator=(const wxString
& stringSrc
)
1239 { m_impl
= stringSrc
.m_impl
; return *this; }
1240 wxString
& operator=(const wxCStrData
& cstr
)
1241 { return *this = cstr
.AsString(); }
1243 wxString
& operator=(wxUniChar ch
)
1244 { m_impl
= wxStringOperations::EncodeChar(ch
); return *this; }
1245 wxString
& operator=(wxUniCharRef ch
)
1246 { return operator=((wxUniChar
)ch
); }
1247 wxString
& operator=(char ch
)
1248 { return operator=(wxUniChar(ch
)); }
1249 wxString
& operator=(unsigned char ch
)
1250 { return operator=(wxUniChar(ch
)); }
1251 wxString
& operator=(wchar_t ch
)
1252 { return operator=(wxUniChar(ch
)); }
1253 // from a C string - STL probably will crash on NULL,
1254 // so we need to compensate in that case
1255 #if wxUSE_STL_BASED_WXSTRING
1256 wxString
& operator=(const char *psz
)
1257 { if (psz
) m_impl
= ImplStr(psz
); else Clear(); return *this; }
1258 wxString
& operator=(const wchar_t *pwz
)
1259 { if (pwz
) m_impl
= ImplStr(pwz
); else Clear(); return *this; }
1261 wxString
& operator=(const char *psz
)
1262 { m_impl
= ImplStr(psz
); return *this; }
1263 wxString
& operator=(const wchar_t *pwz
)
1264 { m_impl
= ImplStr(pwz
); return *this; }
1266 wxString
& operator=(const unsigned char *psz
)
1267 { return operator=((const char*)psz
); }
1269 // from wxWCharBuffer
1270 wxString
& operator=(const wxWCharBuffer
& s
)
1271 { return operator=(s
.data()); } // FIXME-UTF8: fix for embedded NULs
1272 // from wxCharBuffer
1273 wxString
& operator=(const wxCharBuffer
& s
)
1274 { return operator=(s
.data()); } // FIXME-UTF8: fix for embedded NULs
1276 // string concatenation
1277 // in place concatenation
1279 Concatenate and return the result. Note that the left to right
1280 associativity of << allows to write things like "str << str1 << str2
1281 << ..." (unlike with +=)
1284 wxString
& operator<<(const wxString
& s
)
1286 #if WXWIN_COMPATIBILITY_2_8 && !wxUSE_STL_BASED_WXSTRING && !wxUSE_UNICODE_UTF8
1287 wxASSERT_MSG( s
.IsValid(),
1288 _T("did you forget to call UngetWriteBuf()?") );
1294 // string += C string
1295 wxString
& operator<<(const char *psz
)
1296 { append(psz
); return *this; }
1297 wxString
& operator<<(const wchar_t *pwz
)
1298 { append(pwz
); return *this; }
1299 wxString
& operator<<(const wxCStrData
& psz
)
1300 { append(psz
.AsString()); return *this; }
1302 wxString
& operator<<(wxUniChar ch
) { append(1, ch
); return *this; }
1303 wxString
& operator<<(wxUniCharRef ch
) { append(1, ch
); return *this; }
1304 wxString
& operator<<(char ch
) { append(1, ch
); return *this; }
1305 wxString
& operator<<(unsigned char ch
) { append(1, ch
); return *this; }
1306 wxString
& operator<<(wchar_t ch
) { append(1, ch
); return *this; }
1308 // string += buffer (i.e. from wxGetString)
1309 wxString
& operator<<(const wxWCharBuffer
& s
)
1310 { return operator<<((const wchar_t *)s
); }
1311 wxString
& operator<<(const wxCharBuffer
& s
)
1312 { return operator<<((const char *)s
); }
1314 // string += C string
1315 wxString
& Append(const wxString
& s
)
1317 // test for empty() to share the string if possible
1324 wxString
& Append(const char* psz
)
1325 { append(psz
); return *this; }
1326 wxString
& Append(const wchar_t* pwz
)
1327 { append(pwz
); return *this; }
1328 wxString
& Append(const wxCStrData
& psz
)
1329 { append(psz
); return *this; }
1330 wxString
& Append(const wxCharBuffer
& psz
)
1331 { append(psz
); return *this; }
1332 wxString
& Append(const wxWCharBuffer
& psz
)
1333 { append(psz
); return *this; }
1334 // append count copies of given character
1335 wxString
& Append(wxUniChar ch
, size_t count
= 1u)
1336 { append(count
, ch
); return *this; }
1337 wxString
& Append(wxUniCharRef ch
, size_t count
= 1u)
1338 { append(count
, ch
); return *this; }
1339 wxString
& Append(char ch
, size_t count
= 1u)
1340 { append(count
, ch
); return *this; }
1341 wxString
& Append(unsigned char ch
, size_t count
= 1u)
1342 { append(count
, ch
); return *this; }
1343 wxString
& Append(wchar_t ch
, size_t count
= 1u)
1344 { append(count
, ch
); return *this; }
1345 wxString
& Append(const char* psz
, size_t nLen
)
1346 { append(psz
, nLen
); return *this; }
1347 wxString
& Append(const wchar_t* pwz
, size_t nLen
)
1348 { append(pwz
, nLen
); return *this; }
1350 // prepend a string, return the string itself
1351 wxString
& Prepend(const wxString
& str
)
1352 { *this = str
+ *this; return *this; }
1354 // non-destructive concatenation
1356 friend wxString WXDLLIMPEXP_BASE
operator+(const wxString
& string1
,
1357 const wxString
& string2
);
1358 // string with a single char
1359 friend wxString WXDLLIMPEXP_BASE
operator+(const wxString
& string
, wxUniChar ch
);
1360 // char with a string
1361 friend wxString WXDLLIMPEXP_BASE
operator+(wxUniChar ch
, const wxString
& string
);
1362 // string with C string
1363 friend wxString WXDLLIMPEXP_BASE
operator+(const wxString
& string
,
1365 friend wxString WXDLLIMPEXP_BASE
operator+(const wxString
& string
,
1366 const wchar_t *pwz
);
1367 // C string with string
1368 friend wxString WXDLLIMPEXP_BASE
operator+(const char *psz
,
1369 const wxString
& string
);
1370 friend wxString WXDLLIMPEXP_BASE
operator+(const wchar_t *pwz
,
1371 const wxString
& string
);
1373 // stream-like functions
1374 // insert an int into string
1375 wxString
& operator<<(int i
)
1376 { return (*this) << Format(_T("%d"), i
); }
1377 // insert an unsigned int into string
1378 wxString
& operator<<(unsigned int ui
)
1379 { return (*this) << Format(_T("%u"), ui
); }
1380 // insert a long into string
1381 wxString
& operator<<(long l
)
1382 { return (*this) << Format(_T("%ld"), l
); }
1383 // insert an unsigned long into string
1384 wxString
& operator<<(unsigned long ul
)
1385 { return (*this) << Format(_T("%lu"), ul
); }
1386 #if defined wxLongLong_t && !defined wxLongLongIsLong
1387 // insert a long long if they exist and aren't longs
1388 wxString
& operator<<(wxLongLong_t ll
)
1390 const wxChar
*fmt
= _T("%") wxLongLongFmtSpec
_T("d");
1391 return (*this) << Format(fmt
, ll
);
1393 // insert an unsigned long long
1394 wxString
& operator<<(wxULongLong_t ull
)
1396 const wxChar
*fmt
= _T("%") wxLongLongFmtSpec
_T("u");
1397 return (*this) << Format(fmt
, ull
);
1400 // insert a float into string
1401 wxString
& operator<<(float f
)
1402 { return (*this) << Format(_T("%f"), f
); }
1403 // insert a double into string
1404 wxString
& operator<<(double d
)
1405 { return (*this) << Format(_T("%g"), d
); }
1407 // string comparison
1408 // case-sensitive comparison (returns a value < 0, = 0 or > 0)
1409 int Cmp(const char *psz
) const
1410 { return compare(psz
); }
1411 int Cmp(const wchar_t *pwz
) const
1412 { return compare(pwz
); }
1413 int Cmp(const wxString
& s
) const
1414 { return compare(s
); }
1415 int Cmp(const wxCStrData
& s
) const
1416 { return compare(s
); }
1417 int Cmp(const wxCharBuffer
& s
) const
1418 { return compare(s
); }
1419 int Cmp(const wxWCharBuffer
& s
) const
1420 { return compare(s
); }
1421 // same as Cmp() but not case-sensitive
1422 int CmpNoCase(const wxString
& s
) const;
1423 // test for the string equality, either considering case or not
1424 // (if compareWithCase then the case matters)
1425 bool IsSameAs(const wxString
& str
, bool compareWithCase
= true) const
1426 { return (compareWithCase
? Cmp(str
) : CmpNoCase(str
)) == 0; }
1427 bool IsSameAs(const char *str
, bool compareWithCase
= true) const
1428 { return (compareWithCase
? Cmp(str
) : CmpNoCase(str
)) == 0; }
1429 bool IsSameAs(const wchar_t *str
, bool compareWithCase
= true) const
1430 { return (compareWithCase
? Cmp(str
) : CmpNoCase(str
)) == 0; }
1431 bool IsSameAs(const wxCStrData
& str
, bool compareWithCase
= true) const
1432 { return IsSameAs(str
.AsString(), compareWithCase
); }
1433 bool IsSameAs(const wxCharBuffer
& str
, bool compareWithCase
= true) const
1434 { return IsSameAs(str
.data(), compareWithCase
); }
1435 bool IsSameAs(const wxWCharBuffer
& str
, bool compareWithCase
= true) const
1436 { return IsSameAs(str
.data(), compareWithCase
); }
1437 // comparison with a single character: returns true if equal
1438 bool IsSameAs(wxUniChar c
, bool compareWithCase
= true) const
1440 return (length() == 1) && (compareWithCase
? GetChar(0u) == c
1441 : wxToupper(GetChar(0u)) == wxToupper(c
));
1443 // FIXME-UTF8: remove these overloads
1444 bool IsSameAs(wxUniCharRef c
, bool compareWithCase
= true) const
1445 { return IsSameAs(wxUniChar(c
), compareWithCase
); }
1446 bool IsSameAs(char c
, bool compareWithCase
= true) const
1447 { return IsSameAs(wxUniChar(c
), compareWithCase
); }
1448 bool IsSameAs(unsigned char c
, bool compareWithCase
= true) const
1449 { return IsSameAs(wxUniChar(c
), compareWithCase
); }
1450 bool IsSameAs(wchar_t c
, bool compareWithCase
= true) const
1451 { return IsSameAs(wxUniChar(c
), compareWithCase
); }
1452 bool IsSameAs(int c
, bool compareWithCase
= true) const
1453 { return IsSameAs(wxUniChar(c
), compareWithCase
); }
1455 // simple sub-string extraction
1456 // return substring starting at nFirst of length nCount (or till the end
1457 // if nCount = default value)
1458 wxString
Mid(size_t nFirst
, size_t nCount
= npos
) const;
1460 // operator version of Mid()
1461 wxString
operator()(size_t start
, size_t len
) const
1462 { return Mid(start
, len
); }
1464 // check if the string starts with the given prefix and return the rest
1465 // of the string in the provided pointer if it is not NULL; otherwise
1467 bool StartsWith(const wxChar
*prefix
, wxString
*rest
= NULL
) const;
1468 // check if the string ends with the given suffix and return the
1469 // beginning of the string before the suffix in the provided pointer if
1470 // it is not NULL; otherwise return false
1471 bool EndsWith(const wxChar
*suffix
, wxString
*rest
= NULL
) const;
1473 // get first nCount characters
1474 wxString
Left(size_t nCount
) const;
1475 // get last nCount characters
1476 wxString
Right(size_t nCount
) const;
1477 // get all characters before the first occurance of ch
1478 // (returns the whole string if ch not found)
1479 wxString
BeforeFirst(wxUniChar ch
) const;
1480 // get all characters before the last occurence of ch
1481 // (returns empty string if ch not found)
1482 wxString
BeforeLast(wxUniChar ch
) const;
1483 // get all characters after the first occurence of ch
1484 // (returns empty string if ch not found)
1485 wxString
AfterFirst(wxUniChar ch
) const;
1486 // get all characters after the last occurence of ch
1487 // (returns the whole string if ch not found)
1488 wxString
AfterLast(wxUniChar ch
) const;
1490 // for compatibility only, use more explicitly named functions above
1491 wxString
Before(wxUniChar ch
) const { return BeforeLast(ch
); }
1492 wxString
After(wxUniChar ch
) const { return AfterFirst(ch
); }
1495 // convert to upper case in place, return the string itself
1496 wxString
& MakeUpper();
1497 // convert to upper case, return the copy of the string
1498 // Here's something to remember: BC++ doesn't like returns in inlines.
1499 wxString
Upper() const ;
1500 // convert to lower case in place, return the string itself
1501 wxString
& MakeLower();
1502 // convert to lower case, return the copy of the string
1503 wxString
Lower() const ;
1505 // trimming/padding whitespace (either side) and truncating
1506 // remove spaces from left or from right (default) side
1507 wxString
& Trim(bool bFromRight
= true);
1508 // add nCount copies chPad in the beginning or at the end (default)
1509 wxString
& Pad(size_t nCount
, wxUniChar chPad
= wxT(' '), bool bFromRight
= true);
1511 // searching and replacing
1512 // searching (return starting index, or -1 if not found)
1513 int Find(wxUniChar ch
, bool bFromEnd
= false) const; // like strchr/strrchr
1514 int Find(wxUniCharRef ch
, bool bFromEnd
= false) const
1515 { return Find(wxUniChar(ch
), bFromEnd
); }
1516 int Find(char ch
, bool bFromEnd
= false) const
1517 { return Find(wxUniChar(ch
), bFromEnd
); }
1518 int Find(unsigned char ch
, bool bFromEnd
= false) const
1519 { return Find(wxUniChar(ch
), bFromEnd
); }
1520 int Find(wchar_t ch
, bool bFromEnd
= false) const
1521 { return Find(wxUniChar(ch
), bFromEnd
); }
1522 // searching (return starting index, or -1 if not found)
1523 int Find(const wxString
& sub
) const // like strstr
1525 size_type idx
= find(sub
);
1526 return (idx
== npos
) ? wxNOT_FOUND
: (int)idx
;
1528 int Find(const char *sub
) const // like strstr
1530 size_type idx
= find(sub
);
1531 return (idx
== npos
) ? wxNOT_FOUND
: (int)idx
;
1533 int Find(const wchar_t *sub
) const // like strstr
1535 size_type idx
= find(sub
);
1536 return (idx
== npos
) ? wxNOT_FOUND
: (int)idx
;
1539 int Find(const wxCStrData
& sub
) const
1540 { return Find(sub
.AsString()); }
1541 int Find(const wxCharBuffer
& sub
) const
1542 { return Find(sub
.data()); }
1543 int Find(const wxWCharBuffer
& sub
) const
1544 { return Find(sub
.data()); }
1546 // replace first (or all of bReplaceAll) occurences of substring with
1547 // another string, returns the number of replacements made
1548 size_t Replace(const wxString
& strOld
,
1549 const wxString
& strNew
,
1550 bool bReplaceAll
= true);
1552 // check if the string contents matches a mask containing '*' and '?'
1553 bool Matches(const wxString
& mask
) const;
1555 // conversion to numbers: all functions return true only if the whole
1556 // string is a number and put the value of this number into the pointer
1557 // provided, the base is the numeric base in which the conversion should be
1558 // done and must be comprised between 2 and 36 or be 0 in which case the
1559 // standard C rules apply (leading '0' => octal, "0x" => hex)
1560 // convert to a signed integer
1561 bool ToLong(long *val
, int base
= 10) const;
1562 // convert to an unsigned integer
1563 bool ToULong(unsigned long *val
, int base
= 10) const;
1564 // convert to wxLongLong
1565 #if defined(wxLongLong_t)
1566 bool ToLongLong(wxLongLong_t
*val
, int base
= 10) const;
1567 // convert to wxULongLong
1568 bool ToULongLong(wxULongLong_t
*val
, int base
= 10) const;
1569 #endif // wxLongLong_t
1570 // convert to a double
1571 bool ToDouble(double *val
) const;
1574 #ifndef wxNEEDS_WXSTRING_PRINTF_MIXIN
1575 // formatted input/output
1576 // as sprintf(), returns the number of characters written or < 0 on error
1577 // (take 'this' into account in attribute parameter count)
1578 // int Printf(const wxString& format, ...);
1579 WX_DEFINE_VARARG_FUNC(int, Printf
, 1, (const wxFormatString
&),
1580 DoPrintfWchar
, DoPrintfUtf8
)
1582 WX_DEFINE_VARARG_FUNC(int, Printf
, 1, (const char*),
1583 DoPrintfWchar
, DoPrintfUtf8
)
1584 WX_DEFINE_VARARG_FUNC(int, Printf
, 1, (const wchar_t*),
1585 DoPrintfWchar
, DoPrintfUtf8
)
1586 WX_DEFINE_VARARG_FUNC(int, Printf
, 1, (const wxCStrData
&),
1587 DoPrintfWchar
, DoPrintfUtf8
)
1589 #endif // !wxNEEDS_WXSTRING_PRINTF_MIXIN
1590 // as vprintf(), returns the number of characters written or < 0 on error
1591 int PrintfV(const wxString
& format
, va_list argptr
);
1593 #ifndef wxNEEDS_WXSTRING_PRINTF_MIXIN
1594 // returns the string containing the result of Printf() to it
1595 // static wxString Format(const wxString& format, ...) ATTRIBUTE_PRINTF_1;
1596 WX_DEFINE_VARARG_FUNC(static wxString
, Format
, 1, (const wxFormatString
&),
1597 DoFormatWchar
, DoFormatUtf8
)
1599 // workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351
1600 WX_DEFINE_VARARG_FUNC(static wxString
, Format
, 1, (const char*),
1601 DoFormatWchar
, DoFormatUtf8
)
1602 WX_DEFINE_VARARG_FUNC(static wxString
, Format
, 1, (const wchar_t*),
1603 DoFormatWchar
, DoFormatUtf8
)
1604 WX_DEFINE_VARARG_FUNC(static wxString
, Format
, 1, (const wxCStrData
&),
1605 DoFormatWchar
, DoFormatUtf8
)
1608 // the same as above, but takes a va_list
1609 static wxString
FormatV(const wxString
& format
, va_list argptr
);
1611 // raw access to string memory
1612 // ensure that string has space for at least nLen characters
1613 // only works if the data of this string is not shared
1614 bool Alloc(size_t nLen
) { reserve(nLen
); /*return capacity() >= nLen;*/ return true; }
1615 // minimize the string's memory
1616 // only works if the data of this string is not shared
1618 #if WXWIN_COMPATIBILITY_2_8 && !wxUSE_STL_BASED_WXSTRING && !wxUSE_UNICODE_UTF8
1619 // These are deprecated, use wxStringBuffer or wxStringBufferLength instead
1621 // get writable buffer of at least nLen bytes. Unget() *must* be called
1622 // a.s.a.p. to put string back in a reasonable state!
1623 wxDEPRECATED( wxStringCharType
*GetWriteBuf(size_t nLen
) );
1624 // call this immediately after GetWriteBuf() has been used
1625 wxDEPRECATED( void UngetWriteBuf() );
1626 wxDEPRECATED( void UngetWriteBuf(size_t nLen
) );
1627 #endif // WXWIN_COMPATIBILITY_2_8 && !wxUSE_STL_BASED_WXSTRING && wxUSE_UNICODE_UTF8
1629 // wxWidgets version 1 compatibility functions
1632 wxString
SubString(size_t from
, size_t to
) const
1633 { return Mid(from
, (to
- from
+ 1)); }
1634 // values for second parameter of CompareTo function
1635 enum caseCompare
{exact
, ignoreCase
};
1636 // values for first parameter of Strip function
1637 enum stripType
{leading
= 0x1, trailing
= 0x2, both
= 0x3};
1639 #ifndef wxNEEDS_WXSTRING_PRINTF_MIXIN
1641 // (take 'this' into account in attribute parameter count)
1642 // int sprintf(const wxString& format, ...) ATTRIBUTE_PRINTF_2;
1643 WX_DEFINE_VARARG_FUNC(int, sprintf
, 1, (const wxFormatString
&),
1644 DoPrintfWchar
, DoPrintfUtf8
)
1646 // workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351
1647 WX_DEFINE_VARARG_FUNC(int, sprintf
, 1, (const char*),
1648 DoPrintfWchar
, DoPrintfUtf8
)
1649 WX_DEFINE_VARARG_FUNC(int, sprintf
, 1, (const wchar_t*),
1650 DoPrintfWchar
, DoPrintfUtf8
)
1651 WX_DEFINE_VARARG_FUNC(int, sprintf
, 1, (const wxCStrData
&),
1652 DoPrintfWchar
, DoPrintfUtf8
)
1654 #endif // wxNEEDS_WXSTRING_PRINTF_MIXIN
1657 inline int CompareTo(const wxChar
* psz
, caseCompare cmp
= exact
) const
1658 { return cmp
== exact
? Cmp(psz
) : CmpNoCase(psz
); }
1661 size_t Length() const { return length(); }
1662 // Count the number of characters
1663 int Freq(wxUniChar ch
) const;
1665 void LowerCase() { MakeLower(); }
1667 void UpperCase() { MakeUpper(); }
1668 // use Trim except that it doesn't change this string
1669 wxString
Strip(stripType w
= trailing
) const;
1671 // use Find (more general variants not yet supported)
1672 size_t Index(const wxChar
* psz
) const { return Find(psz
); }
1673 size_t Index(wxUniChar ch
) const { return Find(ch
); }
1675 wxString
& Remove(size_t pos
) { return Truncate(pos
); }
1676 wxString
& RemoveLast(size_t n
= 1) { return Truncate(length() - n
); }
1678 wxString
& Remove(size_t nStart
, size_t nLen
)
1679 { return (wxString
&)erase( nStart
, nLen
); }
1682 int First( wxUniChar ch
) const { return Find(ch
); }
1683 int First( wxUniCharRef ch
) const { return Find(ch
); }
1684 int First( char ch
) const { return Find(ch
); }
1685 int First( unsigned char ch
) const { return Find(ch
); }
1686 int First( wchar_t ch
) const { return Find(ch
); }
1687 int First( const wxString
& str
) const { return Find(str
); }
1688 int Last( wxUniChar ch
) const { return Find(ch
, true); }
1689 bool Contains(const wxString
& str
) const { return Find(str
) != wxNOT_FOUND
; }
1692 bool IsNull() const { return empty(); }
1694 // std::string compatibility functions
1696 // take nLen chars starting at nPos
1697 wxString(const wxString
& str
, size_t nPos
, size_t nLen
)
1698 : m_impl(str
.m_impl
, nPos
, nLen
) { }
1699 // take all characters from first to last
1700 wxString(const_iterator first
, const_iterator last
)
1701 : m_impl(first
.impl(), last
.impl()) { }
1702 #if WXWIN_COMPATIBILITY_STRING_PTR_AS_ITER
1703 // the 2 overloads below are for compatibility with the existing code using
1704 // pointers instead of iterators
1705 wxString(const char *first
, const char *last
)
1707 SubstrBufFromMB
str(ImplStr(first
, last
- first
));
1708 m_impl
.assign(str
.data
, str
.len
);
1710 wxString(const wchar_t *first
, const wchar_t *last
)
1712 SubstrBufFromWC
str(ImplStr(first
, last
- first
));
1713 m_impl
.assign(str
.data
, str
.len
);
1715 // and this one is needed to compile code adding offsets to c_str() result
1716 wxString(const wxCStrData
& first
, const wxCStrData
& last
)
1717 : m_impl(CreateConstIterator(first
).impl(),
1718 CreateConstIterator(last
).impl())
1720 wxASSERT_MSG( first
.m_str
== last
.m_str
,
1721 _T("pointers must be into the same string") );
1723 #endif // WXWIN_COMPATIBILITY_STRING_PTR_AS_ITER
1725 // lib.string.modifiers
1726 // append elements str[pos], ..., str[pos+n]
1727 wxString
& append(const wxString
& str
, size_t pos
, size_t n
)
1730 str
.PosLenToImpl(pos
, n
, &from
, &len
);
1731 m_impl
.append(str
.m_impl
, from
, len
);
1735 wxString
& append(const wxString
& str
)
1736 { m_impl
.append(str
.m_impl
); return *this; }
1737 // append first n (or all if n == npos) characters of sz
1738 wxString
& append(const char *sz
)
1739 { m_impl
.append(ImplStr(sz
)); return *this; }
1740 wxString
& append(const wchar_t *sz
)
1741 { m_impl
.append(ImplStr(sz
)); return *this; }
1742 wxString
& append(const char *sz
, size_t n
)
1744 SubstrBufFromMB
str(ImplStr(sz
, n
));
1745 m_impl
.append(str
.data
, str
.len
);
1748 wxString
& append(const wchar_t *sz
, size_t n
)
1750 SubstrBufFromWC
str(ImplStr(sz
, n
));
1751 m_impl
.append(str
.data
, str
.len
);
1755 wxString
& append(const wxCStrData
& str
)
1756 { return append(str
.AsString()); }
1757 wxString
& append(const wxCharBuffer
& str
)
1758 { return append(str
.data()); }
1759 wxString
& append(const wxWCharBuffer
& str
)
1760 { return append(str
.data()); }
1762 // append n copies of ch
1763 wxString
& append(size_t n
, wxUniChar ch
)
1765 #if wxUSE_UNICODE_UTF8
1766 if ( !ch
.IsAscii() )
1767 m_impl
.append(wxStringOperations::EncodeNChars(n
, ch
));
1770 m_impl
.append(n
, (wxStringCharType
)ch
);
1773 // append from first to last
1774 wxString
& append(const_iterator first
, const_iterator last
)
1775 { m_impl
.append(first
.impl(), last
.impl()); return *this; }
1776 #if WXWIN_COMPATIBILITY_STRING_PTR_AS_ITER
1777 wxString
& append(const char *first
, const char *last
)
1778 { return append(first
, last
- first
); }
1779 wxString
& append(const wchar_t *first
, const wchar_t *last
)
1780 { return append(first
, last
- first
); }
1781 wxString
& append(const wxCStrData
& first
, const wxCStrData
& last
)
1782 { return append(CreateConstIterator(first
), CreateConstIterator(last
)); }
1783 #endif // WXWIN_COMPATIBILITY_STRING_PTR_AS_ITER
1785 // same as `this_string = str'
1786 wxString
& assign(const wxString
& str
)
1787 { m_impl
= str
.m_impl
; return *this; }
1788 wxString
& assign(const wxString
& str
, size_t len
)
1790 m_impl
.assign(str
.m_impl
, 0, str
.LenToImpl(len
));
1793 // same as ` = str[pos..pos + n]
1794 wxString
& assign(const wxString
& str
, size_t pos
, size_t n
)
1797 str
.PosLenToImpl(pos
, n
, &from
, &len
);
1798 m_impl
.assign(str
.m_impl
, from
, len
);
1801 // same as `= first n (or all if n == npos) characters of sz'
1802 wxString
& assign(const char *sz
)
1803 { m_impl
.assign(ImplStr(sz
)); return *this; }
1804 wxString
& assign(const wchar_t *sz
)
1805 { m_impl
.assign(ImplStr(sz
)); return *this; }
1806 wxString
& assign(const char *sz
, size_t n
)
1808 SubstrBufFromMB
str(ImplStr(sz
, n
));
1809 m_impl
.assign(str
.data
, str
.len
);
1812 wxString
& assign(const wchar_t *sz
, size_t n
)
1814 SubstrBufFromWC
str(ImplStr(sz
, n
));
1815 m_impl
.assign(str
.data
, str
.len
);
1819 wxString
& assign(const wxCStrData
& str
)
1820 { return assign(str
.AsString()); }
1821 wxString
& assign(const wxCharBuffer
& str
)
1822 { return assign(str
.data()); }
1823 wxString
& assign(const wxWCharBuffer
& str
)
1824 { return assign(str
.data()); }
1825 wxString
& assign(const wxCStrData
& str
, size_t len
)
1826 { return assign(str
.AsString(), len
); }
1827 wxString
& assign(const wxCharBuffer
& str
, size_t len
)
1828 { return assign(str
.data(), len
); }
1829 wxString
& assign(const wxWCharBuffer
& str
, size_t len
)
1830 { return assign(str
.data(), len
); }
1832 // same as `= n copies of ch'
1833 wxString
& assign(size_t n
, wxUniChar ch
)
1835 #if wxUSE_UNICODE_UTF8
1836 if ( !ch
.IsAscii() )
1837 m_impl
.assign(wxStringOperations::EncodeNChars(n
, ch
));
1840 m_impl
.assign(n
, (wxStringCharType
)ch
);
1844 wxString
& assign(size_t n
, wxUniCharRef ch
)
1845 { return assign(n
, wxUniChar(ch
)); }
1846 wxString
& assign(size_t n
, char ch
)
1847 { return assign(n
, wxUniChar(ch
)); }
1848 wxString
& assign(size_t n
, unsigned char ch
)
1849 { return assign(n
, wxUniChar(ch
)); }
1850 wxString
& assign(size_t n
, wchar_t ch
)
1851 { return assign(n
, wxUniChar(ch
)); }
1853 // assign from first to last
1854 wxString
& assign(const_iterator first
, const_iterator last
)
1855 { m_impl
.assign(first
.impl(), last
.impl()); return *this; }
1856 #if WXWIN_COMPATIBILITY_STRING_PTR_AS_ITER
1857 wxString
& assign(const char *first
, const char *last
)
1858 { return assign(first
, last
- first
); }
1859 wxString
& assign(const wchar_t *first
, const wchar_t *last
)
1860 { return assign(first
, last
- first
); }
1861 wxString
& assign(const wxCStrData
& first
, const wxCStrData
& last
)
1862 { return assign(CreateConstIterator(first
), CreateConstIterator(last
)); }
1863 #endif // WXWIN_COMPATIBILITY_STRING_PTR_AS_ITER
1865 // string comparison
1866 int compare(const wxString
& str
) const;
1867 int compare(const char* sz
) const;
1868 int compare(const wchar_t* sz
) const;
1869 int compare(const wxCStrData
& str
) const
1870 { return compare(str
.AsString()); }
1871 int compare(const wxCharBuffer
& str
) const
1872 { return compare(str
.data()); }
1873 int compare(const wxWCharBuffer
& str
) const
1874 { return compare(str
.data()); }
1875 // comparison with a substring
1876 int compare(size_t nStart
, size_t nLen
, const wxString
& str
) const;
1877 // comparison of 2 substrings
1878 int compare(size_t nStart
, size_t nLen
,
1879 const wxString
& str
, size_t nStart2
, size_t nLen2
) const;
1880 // substring comparison with first nCount characters of sz
1881 int compare(size_t nStart
, size_t nLen
,
1882 const char* sz
, size_t nCount
= npos
) const;
1883 int compare(size_t nStart
, size_t nLen
,
1884 const wchar_t* sz
, size_t nCount
= npos
) const;
1886 // insert another string
1887 wxString
& insert(size_t nPos
, const wxString
& str
)
1888 { insert(begin() + nPos
, str
.begin(), str
.end()); return *this; }
1889 // insert n chars of str starting at nStart (in str)
1890 wxString
& insert(size_t nPos
, const wxString
& str
, size_t nStart
, size_t n
)
1893 str
.PosLenToImpl(nStart
, n
, &from
, &len
);
1894 m_impl
.insert(PosToImpl(nPos
), str
.m_impl
, from
, len
);
1897 // insert first n (or all if n == npos) characters of sz
1898 wxString
& insert(size_t nPos
, const char *sz
)
1899 { m_impl
.insert(PosToImpl(nPos
), ImplStr(sz
)); return *this; }
1900 wxString
& insert(size_t nPos
, const wchar_t *sz
)
1901 { m_impl
.insert(PosToImpl(nPos
), ImplStr(sz
)); return *this; }
1902 wxString
& insert(size_t nPos
, const char *sz
, size_t n
)
1904 SubstrBufFromMB
str(ImplStr(sz
, n
));
1905 m_impl
.insert(PosToImpl(nPos
), str
.data
, str
.len
);
1908 wxString
& insert(size_t nPos
, const wchar_t *sz
, size_t n
)
1910 SubstrBufFromWC
str(ImplStr(sz
, n
));
1911 m_impl
.insert(PosToImpl(nPos
), str
.data
, str
.len
);
1914 // insert n copies of ch
1915 wxString
& insert(size_t nPos
, size_t n
, wxUniChar ch
)
1917 #if wxUSE_UNICODE_UTF8
1918 if ( !ch
.IsAscii() )
1919 m_impl
.insert(PosToImpl(nPos
), wxStringOperations::EncodeNChars(n
, ch
));
1922 m_impl
.insert(PosToImpl(nPos
), n
, (wxStringCharType
)ch
);
1925 iterator
insert(iterator it
, wxUniChar ch
)
1927 #if wxUSE_UNICODE_UTF8
1928 if ( !ch
.IsAscii() )
1930 size_t pos
= IterToImplPos(it
);
1931 m_impl
.insert(pos
, wxStringOperations::EncodeChar(ch
));
1932 return iterator(this, m_impl
.begin() + pos
);
1936 return iterator(this, m_impl
.insert(it
.impl(), (wxStringCharType
)ch
));
1938 void insert(iterator it
, const_iterator first
, const_iterator last
)
1939 { m_impl
.insert(it
.impl(), first
.impl(), last
.impl()); }
1940 #if WXWIN_COMPATIBILITY_STRING_PTR_AS_ITER
1941 void insert(iterator it
, const char *first
, const char *last
)
1942 { insert(it
- begin(), first
, last
- first
); }
1943 void insert(iterator it
, const wchar_t *first
, const wchar_t *last
)
1944 { insert(it
- begin(), first
, last
- first
); }
1945 void insert(iterator it
, const wxCStrData
& first
, const wxCStrData
& last
)
1946 { insert(it
, CreateConstIterator(first
), CreateConstIterator(last
)); }
1947 #endif // WXWIN_COMPATIBILITY_STRING_PTR_AS_ITER
1949 void insert(iterator it
, size_type n
, wxUniChar ch
)
1951 #if wxUSE_UNICODE_UTF8
1952 if ( !ch
.IsAscii() )
1953 m_impl
.insert(IterToImplPos(it
), wxStringOperations::EncodeNChars(n
, ch
));
1956 m_impl
.insert(it
.impl(), n
, (wxStringCharType
)ch
);
1959 // delete characters from nStart to nStart + nLen
1960 wxString
& erase(size_type pos
= 0, size_type n
= npos
)
1963 PosLenToImpl(pos
, n
, &from
, &len
);
1964 m_impl
.erase(from
, len
);
1967 // delete characters from first up to last
1968 iterator
erase(iterator first
, iterator last
)
1969 { return iterator(this, m_impl
.erase(first
.impl(), last
.impl())); }
1970 iterator
erase(iterator first
)
1971 { return iterator(this, m_impl
.erase(first
.impl())); }
1973 #ifdef wxSTRING_BASE_HASNT_CLEAR
1974 void clear() { erase(); }
1976 void clear() { m_impl
.clear(); }
1979 // replaces the substring of length nLen starting at nStart
1980 wxString
& replace(size_t nStart
, size_t nLen
, const char* sz
)
1983 PosLenToImpl(nStart
, nLen
, &from
, &len
);
1984 m_impl
.replace(from
, len
, ImplStr(sz
));
1987 wxString
& replace(size_t nStart
, size_t nLen
, const wchar_t* sz
)
1990 PosLenToImpl(nStart
, nLen
, &from
, &len
);
1991 m_impl
.replace(from
, len
, ImplStr(sz
));
1994 // replaces the substring of length nLen starting at nStart
1995 wxString
& replace(size_t nStart
, size_t nLen
, const wxString
& str
)
1998 PosLenToImpl(nStart
, nLen
, &from
, &len
);
1999 m_impl
.replace(from
, len
, str
.m_impl
);
2002 // replaces the substring with nCount copies of ch
2003 wxString
& replace(size_t nStart
, size_t nLen
, size_t nCount
, wxUniChar ch
)
2006 PosLenToImpl(nStart
, nLen
, &from
, &len
);
2007 #if wxUSE_UNICODE_UTF8
2008 if ( !ch
.IsAscii() )
2009 m_impl
.replace(from
, len
, wxStringOperations::EncodeNChars(nCount
, ch
));
2012 m_impl
.replace(from
, len
, nCount
, (wxStringCharType
)ch
);
2015 // replaces a substring with another substring
2016 wxString
& replace(size_t nStart
, size_t nLen
,
2017 const wxString
& str
, size_t nStart2
, size_t nLen2
)
2020 PosLenToImpl(nStart
, nLen
, &from
, &len
);
2023 str
.PosLenToImpl(nStart2
, nLen2
, &from2
, &len2
);
2025 m_impl
.replace(from
, len
, str
.m_impl
, from2
, len2
);
2028 // replaces the substring with first nCount chars of sz
2029 wxString
& replace(size_t nStart
, size_t nLen
,
2030 const char* sz
, size_t nCount
)
2033 PosLenToImpl(nStart
, nLen
, &from
, &len
);
2035 SubstrBufFromMB
str(ImplStr(sz
, nCount
));
2037 m_impl
.replace(from
, len
, str
.data
, str
.len
);
2040 wxString
& replace(size_t nStart
, size_t nLen
,
2041 const wchar_t* sz
, size_t nCount
)
2044 PosLenToImpl(nStart
, nLen
, &from
, &len
);
2046 SubstrBufFromWC
str(ImplStr(sz
, nCount
));
2048 m_impl
.replace(from
, len
, str
.data
, str
.len
);
2051 wxString
& replace(size_t nStart
, size_t nLen
,
2052 const wxString
& s
, size_t nCount
)
2055 PosLenToImpl(nStart
, nLen
, &from
, &len
);
2056 m_impl
.replace(from
, len
, s
.m_impl
.c_str(), s
.LenToImpl(nCount
));
2060 wxString
& replace(iterator first
, iterator last
, const char* s
)
2061 { m_impl
.replace(first
.impl(), last
.impl(), ImplStr(s
)); return *this; }
2062 wxString
& replace(iterator first
, iterator last
, const wchar_t* s
)
2063 { m_impl
.replace(first
.impl(), last
.impl(), ImplStr(s
)); return *this; }
2064 wxString
& replace(iterator first
, iterator last
, const char* s
, size_type n
)
2066 SubstrBufFromMB
str(ImplStr(s
, n
));
2067 m_impl
.replace(first
.impl(), last
.impl(), str
.data
, str
.len
);
2070 wxString
& replace(iterator first
, iterator last
, const wchar_t* s
, size_type n
)
2072 SubstrBufFromWC
str(ImplStr(s
, n
));
2073 m_impl
.replace(first
.impl(), last
.impl(), str
.data
, str
.len
);
2076 wxString
& replace(iterator first
, iterator last
, const wxString
& s
)
2077 { m_impl
.replace(first
.impl(), last
.impl(), s
.m_impl
); return *this; }
2078 wxString
& replace(iterator first
, iterator last
, size_type n
, wxUniChar ch
)
2080 #if wxUSE_UNICODE_UTF8
2081 if ( !ch
.IsAscii() )
2082 m_impl
.replace(first
.impl(), last
.impl(),
2083 wxStringOperations::EncodeNChars(n
, ch
));
2086 m_impl
.replace(first
.impl(), last
.impl(), n
, (wxStringCharType
)ch
);
2089 wxString
& replace(iterator first
, iterator last
,
2090 const_iterator first1
, const_iterator last1
)
2092 m_impl
.replace(first
.impl(), last
.impl(), first1
.impl(), last1
.impl());
2095 wxString
& replace(iterator first
, iterator last
,
2096 const char *first1
, const char *last1
)
2097 { replace(first
, last
, first1
, last1
- first1
); return *this; }
2098 wxString
& replace(iterator first
, iterator last
,
2099 const wchar_t *first1
, const wchar_t *last1
)
2100 { replace(first
, last
, first1
, last1
- first1
); return *this; }
2103 void swap(wxString
& str
)
2104 { m_impl
.swap(str
.m_impl
); }
2107 size_t find(const wxString
& str
, size_t nStart
= 0) const
2108 { return PosFromImpl(m_impl
.find(str
.m_impl
, PosToImpl(nStart
))); }
2110 // find first n characters of sz
2111 size_t find(const char* sz
, size_t nStart
= 0, size_t n
= npos
) const
2113 SubstrBufFromMB
str(ImplStr(sz
, n
));
2114 return PosFromImpl(m_impl
.find(str
.data
, PosToImpl(nStart
), str
.len
));
2116 size_t find(const wchar_t* sz
, size_t nStart
= 0, size_t n
= npos
) const
2118 SubstrBufFromWC
str(ImplStr(sz
, n
));
2119 return PosFromImpl(m_impl
.find(str
.data
, PosToImpl(nStart
), str
.len
));
2121 size_t find(const wxCharBuffer
& s
, size_t nStart
= 0, size_t n
= npos
) const
2122 { return find(s
.data(), nStart
, n
); }
2123 size_t find(const wxWCharBuffer
& s
, size_t nStart
= 0, size_t n
= npos
) const
2124 { return find(s
.data(), nStart
, n
); }
2125 size_t find(const wxCStrData
& s
, size_t nStart
= 0, size_t n
= npos
) const
2126 { return find(s
.AsWChar(), nStart
, n
); }
2128 // find the first occurence of character ch after nStart
2129 size_t find(wxUniChar ch
, size_t nStart
= 0) const
2131 return PosFromImpl(m_impl
.find(wxStringOperations::EncodeChar(ch
),
2132 PosToImpl(nStart
)));
2134 size_t find(wxUniCharRef ch
, size_t nStart
= 0) const
2135 { return find(wxUniChar(ch
), nStart
); }
2136 size_t find(char ch
, size_t nStart
= 0) const
2137 { return find(wxUniChar(ch
), nStart
); }
2138 size_t find(unsigned char ch
, size_t nStart
= 0) const
2139 { return find(wxUniChar(ch
), nStart
); }
2140 size_t find(wchar_t ch
, size_t nStart
= 0) const
2141 { return find(wxUniChar(ch
), nStart
); }
2143 // rfind() family is exactly like find() but works right to left
2145 // as find, but from the end
2146 size_t rfind(const wxString
& str
, size_t nStart
= npos
) const
2147 { return PosFromImpl(m_impl
.rfind(str
.m_impl
, PosToImpl(nStart
))); }
2149 // as find, but from the end
2150 size_t rfind(const char* sz
, size_t nStart
= npos
, size_t n
= npos
) const
2152 SubstrBufFromMB
str(ImplStr(sz
, n
));
2153 return PosFromImpl(m_impl
.rfind(str
.data
, PosToImpl(nStart
), str
.len
));
2155 size_t rfind(const wchar_t* sz
, size_t nStart
= npos
, size_t n
= npos
) const
2157 SubstrBufFromWC
str(ImplStr(sz
, n
));
2158 return PosFromImpl(m_impl
.rfind(str
.data
, PosToImpl(nStart
), str
.len
));
2160 size_t rfind(const wxCharBuffer
& s
, size_t nStart
= npos
, size_t n
= npos
) const
2161 { return rfind(s
.data(), nStart
, n
); }
2162 size_t rfind(const wxWCharBuffer
& s
, size_t nStart
= npos
, size_t n
= npos
) const
2163 { return rfind(s
.data(), nStart
, n
); }
2164 size_t rfind(const wxCStrData
& s
, size_t nStart
= npos
, size_t n
= npos
) const
2165 { return rfind(s
.AsWChar(), nStart
, n
); }
2166 // as find, but from the end
2167 size_t rfind(wxUniChar ch
, size_t nStart
= npos
) const
2169 return PosFromImpl(m_impl
.rfind(wxStringOperations::EncodeChar(ch
),
2170 PosToImpl(nStart
)));
2172 size_t rfind(wxUniCharRef ch
, size_t nStart
= npos
) const
2173 { return rfind(wxUniChar(ch
), nStart
); }
2174 size_t rfind(char ch
, size_t nStart
= npos
) const
2175 { return rfind(wxUniChar(ch
), nStart
); }
2176 size_t rfind(unsigned char ch
, size_t nStart
= npos
) const
2177 { return rfind(wxUniChar(ch
), nStart
); }
2178 size_t rfind(wchar_t ch
, size_t nStart
= npos
) const
2179 { return rfind(wxUniChar(ch
), nStart
); }
2181 // find first/last occurence of any character (not) in the set:
2182 #if wxUSE_STL_BASED_WXSTRING && !wxUSE_UNICODE_UTF8
2183 // FIXME-UTF8: this is not entirely correct, because it doesn't work if
2184 // sizeof(wchar_t)==2 and surrogates are present in the string;
2185 // should we care? Probably not.
2186 size_t find_first_of(const wxString
& str
, size_t nStart
= 0) const
2187 { return m_impl
.find_first_of(str
.m_impl
, nStart
); }
2188 size_t find_first_of(const char* sz
, size_t nStart
= 0) const
2189 { return m_impl
.find_first_of(ImplStr(sz
), nStart
); }
2190 size_t find_first_of(const wchar_t* sz
, size_t nStart
= 0) const
2191 { return m_impl
.find_first_of(ImplStr(sz
), nStart
); }
2192 size_t find_first_of(const char* sz
, size_t nStart
, size_t n
) const
2193 { return m_impl
.find_first_of(ImplStr(sz
), nStart
, n
); }
2194 size_t find_first_of(const wchar_t* sz
, size_t nStart
, size_t n
) const
2195 { return m_impl
.find_first_of(ImplStr(sz
), nStart
, n
); }
2196 size_t find_first_of(wxUniChar c
, size_t nStart
= 0) const
2197 { return m_impl
.find_first_of((wxChar
)c
, nStart
); }
2199 size_t find_last_of(const wxString
& str
, size_t nStart
= npos
) const
2200 { return m_impl
.find_last_of(str
.m_impl
, nStart
); }
2201 size_t find_last_of(const char* sz
, size_t nStart
= npos
) const
2202 { return m_impl
.find_last_of(ImplStr(sz
), nStart
); }
2203 size_t find_last_of(const wchar_t* sz
, size_t nStart
= npos
) const
2204 { return m_impl
.find_last_of(ImplStr(sz
), nStart
); }
2205 size_t find_last_of(const char* sz
, size_t nStart
, size_t n
) const
2206 { return m_impl
.find_last_of(ImplStr(sz
), nStart
, n
); }
2207 size_t find_last_of(const wchar_t* sz
, size_t nStart
, size_t n
) const
2208 { return m_impl
.find_last_of(ImplStr(sz
), nStart
, n
); }
2209 size_t find_last_of(wxUniChar c
, size_t nStart
= npos
) const
2210 { return m_impl
.find_last_of((wxChar
)c
, nStart
); }
2212 size_t find_first_not_of(const wxString
& str
, size_t nStart
= 0) const
2213 { return m_impl
.find_first_not_of(str
.m_impl
, nStart
); }
2214 size_t find_first_not_of(const char* sz
, size_t nStart
= 0) const
2215 { return m_impl
.find_first_not_of(ImplStr(sz
), nStart
); }
2216 size_t find_first_not_of(const wchar_t* sz
, size_t nStart
= 0) const
2217 { return m_impl
.find_first_not_of(ImplStr(sz
), nStart
); }
2218 size_t find_first_not_of(const char* sz
, size_t nStart
, size_t n
) const
2219 { return m_impl
.find_first_not_of(ImplStr(sz
), nStart
, n
); }
2220 size_t find_first_not_of(const wchar_t* sz
, size_t nStart
, size_t n
) const
2221 { return m_impl
.find_first_not_of(ImplStr(sz
), nStart
, n
); }
2222 size_t find_first_not_of(wxUniChar c
, size_t nStart
= 0) const
2223 { return m_impl
.find_first_not_of((wxChar
)c
, nStart
); }
2225 size_t find_last_not_of(const wxString
& str
, size_t nStart
= npos
) const
2226 { return m_impl
.find_last_not_of(str
.m_impl
, nStart
); }
2227 size_t find_last_not_of(const char* sz
, size_t nStart
= npos
) const
2228 { return m_impl
.find_last_not_of(ImplStr(sz
), nStart
); }
2229 size_t find_last_not_of(const wchar_t* sz
, size_t nStart
= npos
) const
2230 { return m_impl
.find_last_not_of(ImplStr(sz
), nStart
); }
2231 size_t find_last_not_of(const char* sz
, size_t nStart
, size_t n
) const
2232 { return m_impl
.find_last_not_of(ImplStr(sz
), nStart
, n
); }
2233 size_t find_last_not_of(const wchar_t* sz
, size_t nStart
, size_t n
) const
2234 { return m_impl
.find_last_not_of(ImplStr(sz
), nStart
, n
); }
2235 size_t find_last_not_of(wxUniChar c
, size_t nStart
= npos
) const
2236 { return m_impl
.find_last_not_of((wxChar
)c
, nStart
); }
2238 // we can't use std::string implementation in UTF-8 build, because the
2239 // character sets would be interpreted wrongly:
2241 // as strpbrk() but starts at nStart, returns npos if not found
2242 size_t find_first_of(const wxString
& str
, size_t nStart
= 0) const
2243 #if wxUSE_UNICODE // FIXME-UTF8: temporary
2244 { return find_first_of(str
.wc_str(), nStart
); }
2246 { return find_first_of(str
.mb_str(), nStart
); }
2249 size_t find_first_of(const char* sz
, size_t nStart
= 0) const;
2250 size_t find_first_of(const wchar_t* sz
, size_t nStart
= 0) const;
2251 size_t find_first_of(const char* sz
, size_t nStart
, size_t n
) const;
2252 size_t find_first_of(const wchar_t* sz
, size_t nStart
, size_t n
) const;
2253 // same as find(char, size_t)
2254 size_t find_first_of(wxUniChar c
, size_t nStart
= 0) const
2255 { return find(c
, nStart
); }
2256 // find the last (starting from nStart) char from str in this string
2257 size_t find_last_of (const wxString
& str
, size_t nStart
= npos
) const
2258 #if wxUSE_UNICODE // FIXME-UTF8: temporary
2259 { return find_last_of(str
.wc_str(), nStart
); }
2261 { return find_last_of(str
.mb_str(), nStart
); }
2264 size_t find_last_of (const char* sz
, size_t nStart
= npos
) const;
2265 size_t find_last_of (const wchar_t* sz
, size_t nStart
= npos
) const;
2266 size_t find_last_of(const char* sz
, size_t nStart
, size_t n
) const;
2267 size_t find_last_of(const wchar_t* sz
, size_t nStart
, size_t n
) const;
2269 size_t find_last_of(wxUniChar c
, size_t nStart
= npos
) const
2270 { return rfind(c
, nStart
); }
2272 // find first/last occurence of any character not in the set
2274 // as strspn() (starting from nStart), returns npos on failure
2275 size_t find_first_not_of(const wxString
& str
, size_t nStart
= 0) const
2276 #if wxUSE_UNICODE // FIXME-UTF8: temporary
2277 { return find_first_not_of(str
.wc_str(), nStart
); }
2279 { return find_first_not_of(str
.mb_str(), nStart
); }
2282 size_t find_first_not_of(const char* sz
, size_t nStart
= 0) const;
2283 size_t find_first_not_of(const wchar_t* sz
, size_t nStart
= 0) const;
2284 size_t find_first_not_of(const char* sz
, size_t nStart
, size_t n
) const;
2285 size_t find_first_not_of(const wchar_t* sz
, size_t nStart
, size_t n
) const;
2287 size_t find_first_not_of(wxUniChar ch
, size_t nStart
= 0) const;
2289 size_t find_last_not_of(const wxString
& str
, size_t nStart
= npos
) const
2290 #if wxUSE_UNICODE // FIXME-UTF8: temporary
2291 { return find_last_not_of(str
.wc_str(), nStart
); }
2293 { return find_last_not_of(str
.mb_str(), nStart
); }
2296 size_t find_last_not_of(const char* sz
, size_t nStart
= npos
) const;
2297 size_t find_last_not_of(const wchar_t* sz
, size_t nStart
= npos
) const;
2298 size_t find_last_not_of(const char* sz
, size_t nStart
, size_t n
) const;
2299 size_t find_last_not_of(const wchar_t* sz
, size_t nStart
, size_t n
) const;
2301 size_t find_last_not_of(wxUniChar ch
, size_t nStart
= npos
) const;
2302 #endif // wxUSE_STL_BASED_WXSTRING && !wxUSE_UNICODE_UTF8 or not
2304 // provide char/wchar_t/wxUniCharRef overloads for char-finding functions
2305 // above to resolve ambiguities:
2306 size_t find_first_of(wxUniCharRef ch
, size_t nStart
= 0) const
2307 { return find_first_of(wxUniChar(ch
), nStart
); }
2308 size_t find_first_of(char ch
, size_t nStart
= 0) const
2309 { return find_first_of(wxUniChar(ch
), nStart
); }
2310 size_t find_first_of(unsigned char ch
, size_t nStart
= 0) const
2311 { return find_first_of(wxUniChar(ch
), nStart
); }
2312 size_t find_first_of(wchar_t ch
, size_t nStart
= 0) const
2313 { return find_first_of(wxUniChar(ch
), nStart
); }
2314 size_t find_last_of(wxUniCharRef ch
, size_t nStart
= npos
) const
2315 { return find_last_of(wxUniChar(ch
), nStart
); }
2316 size_t find_last_of(char ch
, size_t nStart
= npos
) const
2317 { return find_last_of(wxUniChar(ch
), nStart
); }
2318 size_t find_last_of(unsigned char ch
, size_t nStart
= npos
) const
2319 { return find_last_of(wxUniChar(ch
), nStart
); }
2320 size_t find_last_of(wchar_t ch
, size_t nStart
= npos
) const
2321 { return find_last_of(wxUniChar(ch
), nStart
); }
2322 size_t find_first_not_of(wxUniCharRef ch
, size_t nStart
= 0) const
2323 { return find_first_not_of(wxUniChar(ch
), nStart
); }
2324 size_t find_first_not_of(char ch
, size_t nStart
= 0) const
2325 { return find_first_not_of(wxUniChar(ch
), nStart
); }
2326 size_t find_first_not_of(unsigned char ch
, size_t nStart
= 0) const
2327 { return find_first_not_of(wxUniChar(ch
), nStart
); }
2328 size_t find_first_not_of(wchar_t ch
, size_t nStart
= 0) const
2329 { return find_first_not_of(wxUniChar(ch
), nStart
); }
2330 size_t find_last_not_of(wxUniCharRef ch
, size_t nStart
= npos
) const
2331 { return find_last_not_of(wxUniChar(ch
), nStart
); }
2332 size_t find_last_not_of(char ch
, size_t nStart
= npos
) const
2333 { return find_last_not_of(wxUniChar(ch
), nStart
); }
2334 size_t find_last_not_of(unsigned char ch
, size_t nStart
= npos
) const
2335 { return find_last_not_of(wxUniChar(ch
), nStart
); }
2336 size_t find_last_not_of(wchar_t ch
, size_t nStart
= npos
) const
2337 { return find_last_not_of(wxUniChar(ch
), nStart
); }
2339 // and additional overloads for the versions taking strings:
2340 size_t find_first_of(const wxCStrData
& sz
, size_t nStart
= 0) const
2341 { return find_first_of(sz
.AsString(), nStart
); }
2342 size_t find_first_of(const wxCharBuffer
& sz
, size_t nStart
= 0) const
2343 { return find_first_of(sz
.data(), nStart
); }
2344 size_t find_first_of(const wxWCharBuffer
& sz
, size_t nStart
= 0) const
2345 { return find_first_of(sz
.data(), nStart
); }
2346 size_t find_first_of(const wxCStrData
& sz
, size_t nStart
, size_t n
) const
2347 { return find_first_of(sz
.AsWChar(), nStart
, n
); }
2348 size_t find_first_of(const wxCharBuffer
& sz
, size_t nStart
, size_t n
) const
2349 { return find_first_of(sz
.data(), nStart
, n
); }
2350 size_t find_first_of(const wxWCharBuffer
& sz
, size_t nStart
, size_t n
) const
2351 { return find_first_of(sz
.data(), nStart
, n
); }
2353 size_t find_last_of(const wxCStrData
& sz
, size_t nStart
= 0) const
2354 { return find_last_of(sz
.AsString(), nStart
); }
2355 size_t find_last_of(const wxCharBuffer
& sz
, size_t nStart
= 0) const
2356 { return find_last_of(sz
.data(), nStart
); }
2357 size_t find_last_of(const wxWCharBuffer
& sz
, size_t nStart
= 0) const
2358 { return find_last_of(sz
.data(), nStart
); }
2359 size_t find_last_of(const wxCStrData
& sz
, size_t nStart
, size_t n
) const
2360 { return find_last_of(sz
.AsWChar(), nStart
, n
); }
2361 size_t find_last_of(const wxCharBuffer
& sz
, size_t nStart
, size_t n
) const
2362 { return find_last_of(sz
.data(), nStart
, n
); }
2363 size_t find_last_of(const wxWCharBuffer
& sz
, size_t nStart
, size_t n
) const
2364 { return find_last_of(sz
.data(), nStart
, n
); }
2366 size_t find_first_not_of(const wxCStrData
& sz
, size_t nStart
= 0) const
2367 { return find_first_not_of(sz
.AsString(), nStart
); }
2368 size_t find_first_not_of(const wxCharBuffer
& sz
, size_t nStart
= 0) const
2369 { return find_first_not_of(sz
.data(), nStart
); }
2370 size_t find_first_not_of(const wxWCharBuffer
& sz
, size_t nStart
= 0) const
2371 { return find_first_not_of(sz
.data(), nStart
); }
2372 size_t find_first_not_of(const wxCStrData
& sz
, size_t nStart
, size_t n
) const
2373 { return find_first_not_of(sz
.AsWChar(), nStart
, n
); }
2374 size_t find_first_not_of(const wxCharBuffer
& sz
, size_t nStart
, size_t n
) const
2375 { return find_first_not_of(sz
.data(), nStart
, n
); }
2376 size_t find_first_not_of(const wxWCharBuffer
& sz
, size_t nStart
, size_t n
) const
2377 { return find_first_not_of(sz
.data(), nStart
, n
); }
2379 size_t find_last_not_of(const wxCStrData
& sz
, size_t nStart
= 0) const
2380 { return find_last_not_of(sz
.AsString(), nStart
); }
2381 size_t find_last_not_of(const wxCharBuffer
& sz
, size_t nStart
= 0) const
2382 { return find_last_not_of(sz
.data(), nStart
); }
2383 size_t find_last_not_of(const wxWCharBuffer
& sz
, size_t nStart
= 0) const
2384 { return find_last_not_of(sz
.data(), nStart
); }
2385 size_t find_last_not_of(const wxCStrData
& sz
, size_t nStart
, size_t n
) const
2386 { return find_last_not_of(sz
.AsWChar(), nStart
, n
); }
2387 size_t find_last_not_of(const wxCharBuffer
& sz
, size_t nStart
, size_t n
) const
2388 { return find_last_not_of(sz
.data(), nStart
, n
); }
2389 size_t find_last_not_of(const wxWCharBuffer
& sz
, size_t nStart
, size_t n
) const
2390 { return find_last_not_of(sz
.data(), nStart
, n
); }
2393 wxString
& operator+=(const wxString
& s
)
2394 { m_impl
+= s
.m_impl
; return *this; }
2395 // string += C string
2396 wxString
& operator+=(const char *psz
)
2397 { m_impl
+= ImplStr(psz
); return *this; }
2398 wxString
& operator+=(const wchar_t *pwz
)
2399 { m_impl
+= ImplStr(pwz
); return *this; }
2400 wxString
& operator+=(const wxCStrData
& s
)
2401 { m_impl
+= s
.AsString().m_impl
; return *this; }
2402 wxString
& operator+=(const wxCharBuffer
& s
)
2403 { return operator+=(s
.data()); }
2404 wxString
& operator+=(const wxWCharBuffer
& s
)
2405 { return operator+=(s
.data()); }
2407 wxString
& operator+=(wxUniChar ch
)
2408 { m_impl
+= wxStringOperations::EncodeChar(ch
); return *this; }
2409 wxString
& operator+=(wxUniCharRef ch
) { return *this += wxUniChar(ch
); }
2410 wxString
& operator+=(int ch
) { return *this += wxUniChar(ch
); }
2411 wxString
& operator+=(char ch
) { return *this += wxUniChar(ch
); }
2412 wxString
& operator+=(unsigned char ch
) { return *this += wxUniChar(ch
); }
2413 wxString
& operator+=(wchar_t ch
) { return *this += wxUniChar(ch
); }
2416 #if !wxUSE_STL_BASED_WXSTRING
2417 // helpers for wxStringBuffer and wxStringBufferLength
2418 wxStringCharType
*DoGetWriteBuf(size_t nLen
)
2419 { return m_impl
.DoGetWriteBuf(nLen
); }
2420 void DoUngetWriteBuf()
2421 { m_impl
.DoUngetWriteBuf(); }
2422 void DoUngetWriteBuf(size_t nLen
)
2423 { m_impl
.DoUngetWriteBuf(nLen
); }
2424 #endif // !wxUSE_STL_BASED_WXSTRING
2426 #ifndef wxNEEDS_WXSTRING_PRINTF_MIXIN
2427 #if !wxUSE_UTF8_LOCALE_ONLY
2428 int DoPrintfWchar(const wxChar
*format
, ...);
2429 static wxString
DoFormatWchar(const wxChar
*format
, ...);
2431 #if wxUSE_UNICODE_UTF8
2432 int DoPrintfUtf8(const char *format
, ...);
2433 static wxString
DoFormatUtf8(const char *format
, ...);
2437 #if !wxUSE_STL_BASED_WXSTRING
2438 // check string's data validity
2439 bool IsValid() const { return m_impl
.GetStringData()->IsValid(); }
2443 wxStringImpl m_impl
;
2445 // buffers for compatibility conversion from (char*)c_str() and
2446 // (wchar_t*)c_str():
2447 // FIXME-UTF8: bechmark various approaches to keeping compatibility buffers
2448 template<typename T
>
2449 struct ConvertedBuffer
2451 ConvertedBuffer() : m_buf(NULL
) {}
2455 operator T
*() const { return m_buf
; }
2457 ConvertedBuffer
& operator=(T
*str
)
2466 #if wxUSE_UNICODE && !wxUSE_UTF8_LOCALE_ONLY
2467 ConvertedBuffer
<char> m_convertedToChar
;
2469 #if !wxUSE_UNICODE_WCHAR
2470 ConvertedBuffer
<wchar_t> m_convertedToWChar
;
2473 friend class WXDLLIMPEXP_BASE wxCStrData
;
2474 friend class wxImplStringBuffer
;
2475 friend class wxImplStringBufferLength
;
2478 #ifdef wxNEEDS_WXSTRING_PRINTF_MIXIN
2479 #pragma warning (default:4275)
2482 // string iterator operators that satisfy STL Random Access Iterator
2484 inline wxString::iterator
operator+(int n
, wxString::iterator i
)
2486 inline wxString::iterator
operator+(size_t n
, wxString::iterator i
)
2488 inline wxString::const_iterator
operator+(int n
, wxString::const_iterator i
)
2490 inline wxString::const_iterator
operator+(size_t n
, wxString::const_iterator i
)
2492 inline wxString::reverse_iterator
operator+(int n
, wxString::reverse_iterator i
)
2494 inline wxString::reverse_iterator
operator+(size_t n
, wxString::reverse_iterator i
)
2496 inline wxString::const_reverse_iterator
operator+(int n
, wxString::const_reverse_iterator i
)
2498 inline wxString::const_reverse_iterator
operator+(size_t n
, wxString::const_reverse_iterator i
)
2501 // notice that even though for many compilers the friend declarations above are
2502 // enough, from the point of view of C++ standard we must have the declarations
2503 // here as friend ones are not injected in the enclosing namespace and without
2504 // them the code fails to compile with conforming compilers such as xlC or g++4
2505 wxString WXDLLIMPEXP_BASE
operator+(const wxString
& string1
, const wxString
& string2
);
2506 wxString WXDLLIMPEXP_BASE
operator+(const wxString
& string
, const char *psz
);
2507 wxString WXDLLIMPEXP_BASE
operator+(const wxString
& string
, const wchar_t *pwz
);
2508 wxString WXDLLIMPEXP_BASE
operator+(const char *psz
, const wxString
& string
);
2509 wxString WXDLLIMPEXP_BASE
operator+(const wchar_t *pwz
, const wxString
& string
);
2511 wxString WXDLLIMPEXP_BASE
operator+(const wxString
& string
, wxUniChar ch
);
2512 wxString WXDLLIMPEXP_BASE
operator+(wxUniChar ch
, const wxString
& string
);
2514 inline wxString
operator+(const wxString
& string
, wxUniCharRef ch
)
2515 { return string
+ (wxUniChar
)ch
; }
2516 inline wxString
operator+(const wxString
& string
, char ch
)
2517 { return string
+ wxUniChar(ch
); }
2518 inline wxString
operator+(const wxString
& string
, wchar_t ch
)
2519 { return string
+ wxUniChar(ch
); }
2520 inline wxString
operator+(wxUniCharRef ch
, const wxString
& string
)
2521 { return (wxUniChar
)ch
+ string
; }
2522 inline wxString
operator+(char ch
, const wxString
& string
)
2523 { return wxUniChar(ch
) + string
; }
2524 inline wxString
operator+(wchar_t ch
, const wxString
& string
)
2525 { return wxUniChar(ch
) + string
; }
2528 #if wxUSE_STL_BASED_WXSTRING
2529 // return an empty wxString (not very useful with wxUSE_STL == 1)
2530 inline const wxString
wxGetEmptyString() { return wxString(); }
2531 #else // !wxUSE_STL_BASED_WXSTRING
2532 // return an empty wxString (more efficient than wxString() here)
2533 inline const wxString
& wxGetEmptyString()
2535 return *(wxString
*)&wxEmptyString
;
2537 #endif // wxUSE_STL_BASED_WXSTRING/!wxUSE_STL_BASED_WXSTRING
2539 // ----------------------------------------------------------------------------
2540 // wxStringBuffer: a tiny class allowing to get a writable pointer into string
2541 // ----------------------------------------------------------------------------
2543 #if !wxUSE_STL_BASED_WXSTRING
2544 // string buffer for direct access to string data in their native
2546 class wxImplStringBuffer
2549 typedef wxStringCharType CharType
;
2551 wxImplStringBuffer(wxString
& str
, size_t lenWanted
= 1024)
2552 : m_str(str
), m_buf(NULL
)
2553 { m_buf
= m_str
.DoGetWriteBuf(lenWanted
); }
2555 ~wxImplStringBuffer() { m_str
.DoUngetWriteBuf(); }
2557 operator wxStringCharType
*() const { return m_buf
; }
2561 wxStringCharType
*m_buf
;
2563 DECLARE_NO_COPY_CLASS(wxImplStringBuffer
)
2566 class wxImplStringBufferLength
2569 typedef wxStringCharType CharType
;
2571 wxImplStringBufferLength(wxString
& str
, size_t lenWanted
= 1024)
2572 : m_str(str
), m_buf(NULL
), m_len(0), m_lenSet(false)
2574 m_buf
= m_str
.DoGetWriteBuf(lenWanted
);
2575 wxASSERT(m_buf
!= NULL
);
2578 ~wxImplStringBufferLength()
2581 m_str
.DoUngetWriteBuf(m_len
);
2584 operator wxStringCharType
*() const { return m_buf
; }
2585 void SetLength(size_t length
) { m_len
= length
; m_lenSet
= true; }
2589 wxStringCharType
*m_buf
;
2593 DECLARE_NO_COPY_CLASS(wxImplStringBufferLength
)
2596 #endif // !wxUSE_STL_BASED_WXSTRING
2598 template<typename T
>
2599 class wxStringTypeBufferBase
2604 wxStringTypeBufferBase(wxString
& str
, size_t lenWanted
= 1024)
2605 : m_str(str
), m_buf(lenWanted
)
2609 operator CharType
*() { return m_buf
.data(); }
2613 wxCharTypeBuffer
<CharType
> m_buf
;
2616 template<typename T
>
2617 class wxStringTypeBufferLengthBase
2622 wxStringTypeBufferLengthBase(wxString
& str
, size_t lenWanted
= 1024)
2623 : m_str(str
), m_buf(lenWanted
), m_len(0), m_lenSet(false)
2626 ~wxStringTypeBufferLengthBase()
2629 m_str
.assign(m_buf
.data(), m_len
);
2632 operator CharType
*() { return m_buf
.data(); }
2633 void SetLength(size_t length
) { m_len
= length
; m_lenSet
= true; }
2637 wxCharTypeBuffer
<CharType
> m_buf
;
2642 template<typename T
>
2643 class wxStringTypeBuffer
: public wxStringTypeBufferBase
<T
>
2646 wxStringTypeBuffer(wxString
& str
, size_t lenWanted
= 1024)
2647 : wxStringTypeBufferBase
<T
>(str
, lenWanted
) {}
2648 ~wxStringTypeBuffer()
2650 this->m_str
.assign(this->m_buf
.data());
2653 DECLARE_NO_COPY_CLASS(wxStringTypeBuffer
)
2656 template<typename T
>
2657 class wxStringTypeBufferLength
: public wxStringTypeBufferLengthBase
<T
>
2660 wxStringTypeBufferLength(wxString
& str
, size_t lenWanted
= 1024)
2661 : wxStringTypeBufferLengthBase
<T
>(str
, lenWanted
) {}
2663 ~wxStringTypeBufferLength()
2665 wxASSERT(this->m_lenSet
);
2666 this->m_str
.assign(this->m_buf
.data(), this->m_len
);
2669 DECLARE_NO_COPY_CLASS(wxStringTypeBufferLength
)
2672 #if wxUSE_STL_BASED_WXSTRING
2673 class wxImplStringBuffer
: public wxStringTypeBufferBase
<wxStringCharType
>
2676 wxImplStringBuffer(wxString
& str
, size_t lenWanted
= 1024)
2677 : wxStringTypeBufferBase
<wxStringCharType
>(str
, lenWanted
) {}
2678 ~wxImplStringBuffer()
2679 { m_str
.m_impl
.assign(m_buf
.data()); }
2681 DECLARE_NO_COPY_CLASS(wxImplStringBuffer
)
2684 class wxImplStringBufferLength
: public wxStringTypeBufferLengthBase
<wxStringCharType
>
2687 wxImplStringBufferLength(wxString
& str
, size_t lenWanted
= 1024)
2688 : wxStringTypeBufferLengthBase
<wxStringCharType
>(str
, lenWanted
) {}
2690 ~wxImplStringBufferLength()
2693 m_str
.m_impl
.assign(m_buf
.data(), m_len
);
2696 DECLARE_NO_COPY_CLASS(wxImplStringBufferLength
)
2698 #endif // wxUSE_STL_BASED_WXSTRING
2701 #if wxUSE_STL_BASED_WXSTRING || wxUSE_UNICODE_UTF8
2702 typedef wxStringTypeBuffer
<wxChar
> wxStringBuffer
;
2703 typedef wxStringTypeBufferLength
<wxChar
> wxStringBufferLength
;
2704 #else // if !wxUSE_STL_BASED_WXSTRING && !wxUSE_UNICODE_UTF8
2705 typedef wxImplStringBuffer wxStringBuffer
;
2706 typedef wxImplStringBufferLength wxStringBufferLength
;
2707 #endif // !wxUSE_STL_BASED_WXSTRING && !wxUSE_UNICODE_UTF8
2709 // ---------------------------------------------------------------------------
2710 // wxString comparison functions: operator versions are always case sensitive
2711 // ---------------------------------------------------------------------------
2713 #define wxCMP_WXCHAR_STRING(p, s, op) 0 op s.Cmp(p)
2715 wxDEFINE_ALL_COMPARISONS(const wxChar
*, const wxString
&, wxCMP_WXCHAR_STRING
)
2717 #undef wxCMP_WXCHAR_STRING
2719 // note that there is an optimization in operator==() and !=(): we (quickly)
2720 // checks the strings length first, before comparing their data
2721 inline bool operator==(const wxString
& s1
, const wxString
& s2
)
2722 { return (s1
.Len() == s2
.Len()) && (s1
.Cmp(s2
) == 0); }
2723 inline bool operator!=(const wxString
& s1
, const wxString
& s2
)
2724 { return (s1
.Len() != s2
.Len()) || (s1
.Cmp(s2
) != 0); }
2725 inline bool operator< (const wxString
& s1
, const wxString
& s2
)
2726 { return s1
.Cmp(s2
) < 0; }
2727 inline bool operator> (const wxString
& s1
, const wxString
& s2
)
2728 { return s1
.Cmp(s2
) > 0; }
2729 inline bool operator<=(const wxString
& s1
, const wxString
& s2
)
2730 { return s1
.Cmp(s2
) <= 0; }
2731 inline bool operator>=(const wxString
& s1
, const wxString
& s2
)
2732 { return s1
.Cmp(s2
) >= 0; }
2735 inline bool operator==(const wxString
& s1
, const wxWCharBuffer
& s2
)
2736 { return (s1
.Cmp((const wchar_t *)s2
) == 0); }
2737 inline bool operator==(const wxWCharBuffer
& s1
, const wxString
& s2
)
2738 { return (s2
.Cmp((const wchar_t *)s1
) == 0); }
2739 inline bool operator!=(const wxString
& s1
, const wxWCharBuffer
& s2
)
2740 { return (s1
.Cmp((const wchar_t *)s2
) != 0); }
2741 inline bool operator!=(const wxWCharBuffer
& s1
, const wxString
& s2
)
2742 { return (s2
.Cmp((const wchar_t *)s1
) != 0); }
2743 #else // !wxUSE_UNICODE
2744 inline bool operator==(const wxString
& s1
, const wxCharBuffer
& s2
)
2745 { return (s1
.Cmp((const char *)s2
) == 0); }
2746 inline bool operator==(const wxCharBuffer
& s1
, const wxString
& s2
)
2747 { return (s2
.Cmp((const char *)s1
) == 0); }
2748 inline bool operator!=(const wxString
& s1
, const wxCharBuffer
& s2
)
2749 { return (s1
.Cmp((const char *)s2
) != 0); }
2750 inline bool operator!=(const wxCharBuffer
& s1
, const wxString
& s2
)
2751 { return (s2
.Cmp((const char *)s1
) != 0); }
2752 #endif // wxUSE_UNICODE/!wxUSE_UNICODE
2755 inline wxString
operator+(const wxString
& string
, const wxWCharBuffer
& buf
)
2756 { return string
+ (const wchar_t *)buf
; }
2757 inline wxString
operator+(const wxWCharBuffer
& buf
, const wxString
& string
)
2758 { return (const wchar_t *)buf
+ string
; }
2759 #else // !wxUSE_UNICODE
2760 inline wxString
operator+(const wxString
& string
, const wxCharBuffer
& buf
)
2761 { return string
+ (const char *)buf
; }
2762 inline wxString
operator+(const wxCharBuffer
& buf
, const wxString
& string
)
2763 { return (const char *)buf
+ string
; }
2764 #endif // wxUSE_UNICODE/!wxUSE_UNICODE
2766 // comparison with char
2767 inline bool operator==(const wxUniChar
& c
, const wxString
& s
) { return s
.IsSameAs(c
); }
2768 inline bool operator==(const wxUniCharRef
& c
, const wxString
& s
) { return s
.IsSameAs(c
); }
2769 inline bool operator==(char c
, const wxString
& s
) { return s
.IsSameAs(c
); }
2770 inline bool operator==(wchar_t c
, const wxString
& s
) { return s
.IsSameAs(c
); }
2771 inline bool operator==(int c
, const wxString
& s
) { return s
.IsSameAs(c
); }
2772 inline bool operator==(const wxString
& s
, const wxUniChar
& c
) { return s
.IsSameAs(c
); }
2773 inline bool operator==(const wxString
& s
, const wxUniCharRef
& c
) { return s
.IsSameAs(c
); }
2774 inline bool operator==(const wxString
& s
, char c
) { return s
.IsSameAs(c
); }
2775 inline bool operator==(const wxString
& s
, wchar_t c
) { return s
.IsSameAs(c
); }
2776 inline bool operator!=(const wxUniChar
& c
, const wxString
& s
) { return !s
.IsSameAs(c
); }
2777 inline bool operator!=(const wxUniCharRef
& c
, const wxString
& s
) { return !s
.IsSameAs(c
); }
2778 inline bool operator!=(char c
, const wxString
& s
) { return !s
.IsSameAs(c
); }
2779 inline bool operator!=(wchar_t c
, const wxString
& s
) { return !s
.IsSameAs(c
); }
2780 inline bool operator!=(int c
, const wxString
& s
) { return !s
.IsSameAs(c
); }
2781 inline bool operator!=(const wxString
& s
, const wxUniChar
& c
) { return !s
.IsSameAs(c
); }
2782 inline bool operator!=(const wxString
& s
, const wxUniCharRef
& c
) { return !s
.IsSameAs(c
); }
2783 inline bool operator!=(const wxString
& s
, char c
) { return !s
.IsSameAs(c
); }
2784 inline bool operator!=(const wxString
& s
, wchar_t c
) { return !s
.IsSameAs(c
); }
2786 // comparison with C string in Unicode build
2789 #define wxCMP_CHAR_STRING(p, s, op) wxString(p) op s
2791 wxDEFINE_ALL_COMPARISONS(const char *, const wxString
&, wxCMP_CHAR_STRING
)
2793 #undef wxCMP_CHAR_STRING
2795 #endif // wxUSE_UNICODE
2797 // we also need to provide the operators for comparison with wxCStrData to
2798 // resolve ambiguity between operator(const wxChar *,const wxString &) and
2799 // operator(const wxChar *, const wxChar *) for "p == s.c_str()"
2801 // notice that these are (shallow) pointer comparisons, not (deep) string ones
2802 #define wxCMP_CHAR_CSTRDATA(p, s, op) p op s.AsChar()
2803 #define wxCMP_WCHAR_CSTRDATA(p, s, op) p op s.AsWChar()
2805 wxDEFINE_ALL_COMPARISONS(const wchar_t *, const wxCStrData
&, wxCMP_WCHAR_CSTRDATA
)
2806 wxDEFINE_ALL_COMPARISONS(const char *, const wxCStrData
&, wxCMP_CHAR_CSTRDATA
)
2808 #undef wxCMP_CHAR_CSTRDATA
2809 #undef wxCMP_WCHAR_CSTRDATA
2811 // ---------------------------------------------------------------------------
2812 // Implementation only from here until the end of file
2813 // ---------------------------------------------------------------------------
2815 #if wxUSE_STD_IOSTREAM
2817 #include "wx/iosfwrap.h"
2819 WXDLLIMPEXP_BASE wxSTD ostream
& operator<<(wxSTD ostream
&, const wxString
&);
2820 WXDLLIMPEXP_BASE wxSTD ostream
& operator<<(wxSTD ostream
&, const wxCStrData
&);
2821 WXDLLIMPEXP_BASE wxSTD ostream
& operator<<(wxSTD ostream
&, const wxCharBuffer
&);
2822 #ifndef __BORLANDC__
2823 WXDLLIMPEXP_BASE wxSTD ostream
& operator<<(wxSTD ostream
&, const wxWCharBuffer
&);
2826 #endif // wxSTD_STRING_COMPATIBILITY
2828 // ---------------------------------------------------------------------------
2829 // wxCStrData implementation
2830 // ---------------------------------------------------------------------------
2832 inline wxCStrData::wxCStrData(char *buf
)
2833 : m_str(new wxString(buf
)), m_offset(0), m_owned(true) {}
2834 inline wxCStrData::wxCStrData(wchar_t *buf
)
2835 : m_str(new wxString(buf
)), m_offset(0), m_owned(true) {}
2837 inline wxCStrData::wxCStrData(const wxCStrData
& data
)
2838 : m_str(data
.m_owned
? new wxString(*data
.m_str
) : data
.m_str
),
2839 m_offset(data
.m_offset
),
2840 m_owned(data
.m_owned
)
2844 inline wxCStrData::~wxCStrData()
2850 // simple cases for AsChar() and AsWChar(), the complicated ones are
2852 #if wxUSE_UNICODE_WCHAR
2853 inline const wchar_t* wxCStrData::AsWChar() const
2855 return m_str
->wx_str() + m_offset
;
2857 #endif // wxUSE_UNICODE_WCHAR
2859 #if !wxUSE_UNICODE || wxUSE_UTF8_LOCALE_ONLY
2860 inline const char* wxCStrData::AsChar() const
2862 return wxStringOperations::AddToIter(m_str
->wx_str(), m_offset
);
2864 #endif // !wxUSE_UNICODE
2866 inline const wxCharBuffer
wxCStrData::AsCharBuf() const
2869 return wxCharBuffer::CreateNonOwned(AsChar());
2871 return AsString().mb_str();
2875 inline const wxWCharBuffer
wxCStrData::AsWCharBuf() const
2877 #if wxUSE_UNICODE_WCHAR
2878 return wxWCharBuffer::CreateNonOwned(AsWChar());
2880 return AsString().wc_str();
2884 inline wxString
wxCStrData::AsString() const
2886 if ( m_offset
== 0 )
2889 return m_str
->Mid(m_offset
);
2892 inline const wxStringCharType
*wxCStrData::AsInternal() const
2894 return wxStringOperations::AddToIter(m_str
->wx_str(), m_offset
);
2897 inline wxUniChar
wxCStrData::operator*() const
2899 if ( m_str
->empty() )
2900 return wxUniChar(_T('\0'));
2902 return (*m_str
)[m_offset
];
2905 inline wxUniChar
wxCStrData::operator[](size_t n
) const
2907 // NB: we intentionally use operator[] and not at() here because the former
2908 // works for the terminating NUL while the latter does not
2909 return (*m_str
)[m_offset
+ n
];
2912 // ----------------------------------------------------------------------------
2913 // more wxCStrData operators
2914 // ----------------------------------------------------------------------------
2916 // we need to define those to allow "size_t pos = p - s.c_str()" where p is
2917 // some pointer into the string
2918 inline size_t operator-(const char *p
, const wxCStrData
& cs
)
2920 return p
- cs
.AsChar();
2923 inline size_t operator-(const wchar_t *p
, const wxCStrData
& cs
)
2925 return p
- cs
.AsWChar();
2928 // ----------------------------------------------------------------------------
2929 // implementation of wx[W]CharBuffer inline methods using wxCStrData
2930 // ----------------------------------------------------------------------------
2932 // FIXME-UTF8: move this to buffer.h
2933 inline wxCharBuffer::wxCharBuffer(const wxCStrData
& cstr
)
2934 : wxCharTypeBufferBase(cstr
.AsCharBuf())
2938 inline wxWCharBuffer::wxWCharBuffer(const wxCStrData
& cstr
)
2939 : wxCharTypeBufferBase(cstr
.AsWCharBuf())
2943 #if WXWIN_COMPATIBILITY_2_8
2944 // lot of code out there doesn't explicitly include wx/wxchar.h, but uses
2945 // CRT wrappers that are now declared in wx/wxcrt.h and wx/wxcrtvararg.h,
2946 // so let's include this header now that wxString is defined and it's safe
2948 #include "wx/wxchar.h"
2951 #endif // _WX_WXSTRING_H_