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(); }
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 wxString
&),
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 wxString
& fmt
, FormatDummyArg dummy
= FormatDummyArg())
344 return DoFormat(fmt
);
347 // int Printf(const wxString& format, ...);
348 WX_DEFINE_VARARG_FUNC(int, Printf
, 1, (const wxString
&),
349 DoPrintfWchar
, DoPrintfUtf8
)
350 // int sprintf(const wxString& format, ...) ATTRIBUTE_PRINTF_2;
351 WX_DEFINE_VARARG_FUNC(int, sprintf
, 1, (const wxString
&),
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 // FIXME-UTF8: return as-is without copying under UTF8 locale, return
481 // converted string under other locales - needs wxCharBuffer
483 static wxCharBuffer
ImplStr(const char* str
,
484 const wxMBConv
& conv
= wxConvLibc
)
485 { return ConvertStr(str
, npos
, conv
).data
; }
486 static SubstrBufFromMB
ImplStr(const char* str
, size_t n
,
487 const wxMBConv
& conv
= wxConvLibc
)
488 { return ConvertStr(str
, n
, conv
); }
490 static wxCharBuffer
ImplStr(const wchar_t* str
)
491 { return ConvertStr(str
, npos
, wxConvUTF8
).data
; }
492 static SubstrBufFromWC
ImplStr(const wchar_t* str
, size_t n
)
493 { return ConvertStr(str
, n
, wxConvUTF8
); }
495 size_t PosToImpl(size_t pos
) const
497 if ( pos
== 0 || pos
== npos
)
500 return (begin() + pos
).impl() - m_impl
.begin();
503 void PosLenToImpl(size_t pos
, size_t len
, size_t *implPos
, size_t *implLen
) const;
505 size_t LenToImpl(size_t len
) const
508 PosLenToImpl(0, len
, &pos
, &len2
);
512 size_t PosFromImpl(size_t pos
) const
514 if ( pos
== 0 || pos
== npos
)
517 return const_iterator(m_impl
.begin() + pos
) - begin();
519 #endif // !wxUSE_UNICODE_UTF8/wxUSE_UNICODE_UTF8
523 typedef wxUniChar value_type
;
524 typedef wxUniChar char_type
;
525 typedef wxUniCharRef reference
;
526 typedef wxChar
* pointer
;
527 typedef const wxChar
* const_pointer
;
529 typedef size_t size_type
;
530 typedef wxUniChar const_reference
;
533 #if wxUSE_UNICODE_UTF8
534 // random access is not O(1), as required by Random Access Iterator
535 #define WX_STR_ITERATOR_TAG std::bidirectional_iterator_tag
537 #define WX_STR_ITERATOR_TAG std::random_access_iterator_tag
540 #define WX_STR_ITERATOR_TAG void /* dummy type */
543 #define WX_STR_ITERATOR_IMPL(iterator_name, pointer_type, \
544 reference_type, reference_ctor) \
546 typedef wxStringImpl::iterator_name underlying_iterator; \
548 typedef WX_STR_ITERATOR_TAG iterator_category; \
549 typedef wxUniChar value_type; \
550 typedef int difference_type; \
551 typedef reference_type reference; \
552 typedef pointer_type pointer; \
554 reference operator*() const { return reference_ctor; } \
555 reference operator[](size_t n) const { return *(*this + n); } \
557 iterator_name& operator++() \
558 { wxStringOperations::IncIter(m_cur); return *this; } \
559 iterator_name& operator--() \
560 { wxStringOperations::DecIter(m_cur); return *this; } \
561 iterator_name operator++(int) \
563 iterator_name tmp = *this; \
564 wxStringOperations::IncIter(m_cur); \
567 iterator_name operator--(int) \
569 iterator_name tmp = *this; \
570 wxStringOperations::DecIter(m_cur); \
574 iterator_name& operator+=(int n) \
576 m_cur = wxStringOperations::AddToIter(m_cur, n); \
579 iterator_name& operator+=(size_t n) \
581 m_cur = wxStringOperations::AddToIter(m_cur, (int)n); \
584 iterator_name& operator-=(int n) \
586 m_cur = wxStringOperations::AddToIter(m_cur, -n); \
589 iterator_name& operator-=(size_t n) \
591 m_cur = wxStringOperations::AddToIter(m_cur, -(int)n); \
595 difference_type operator-(const iterator_name& i) const \
596 { return wxStringOperations::DiffIters(m_cur, i.m_cur); } \
598 bool operator==(const iterator_name& i) const \
599 { return m_cur == i.m_cur; } \
600 bool operator!=(const iterator_name& i) const \
601 { return m_cur != i.m_cur; } \
603 bool operator<(const iterator_name& i) const \
604 { return m_cur < i.m_cur; } \
605 bool operator>(const iterator_name& i) const \
606 { return m_cur > i.m_cur; } \
607 bool operator<=(const iterator_name& i) const \
608 { return m_cur <= i.m_cur; } \
609 bool operator>=(const iterator_name& i) const \
610 { return m_cur >= i.m_cur; } \
613 /* for internal wxString use only: */ \
614 underlying_iterator impl() const { return m_cur; } \
616 friend class WXDLLIMPEXP_BASE wxString; \
617 friend class WXDLLIMPEXP_BASE wxCStrData; \
620 underlying_iterator m_cur
622 class const_iterator
;
624 #if wxUSE_UNICODE_UTF8
627 // NB: In UTF-8 build, (non-const) iterator needs to keep reference
628 // to the underlying wxStringImpl, because UTF-8 is variable-length
629 // encoding and changing the value pointer to by an iterator using
630 // its operator* requires calling wxStringImpl::replace() if the old
631 // and new values differ in their encoding's length.
633 WX_STR_ITERATOR_IMPL(iterator
, wxChar
*, wxUniCharRef
,
634 wxUniCharRef::CreateForString(m_str
, m_cur
));
637 iterator(const iterator
& i
) : m_cur(i
.m_cur
), m_str(i
.m_str
) {}
639 iterator
operator+(int n
) const
640 { return iterator(m_str
, wxStringOperations::AddToIter(m_cur
, n
)); }
641 iterator
operator+(size_t n
) const
642 { return iterator(m_str
, wxStringOperations::AddToIter(m_cur
, (int)n
)); }
643 iterator
operator-(int n
) const
644 { return iterator(m_str
, wxStringOperations::AddToIter(m_cur
, -n
)); }
645 iterator
operator-(size_t n
) const
646 { return iterator(m_str
, wxStringOperations::AddToIter(m_cur
, -(int)n
)); }
649 iterator(wxString
*str
, underlying_iterator ptr
)
650 : m_cur(ptr
), m_str(str
->m_impl
) {}
651 iterator(wxStringImpl
& str
, underlying_iterator ptr
)
652 : m_cur(ptr
), m_str(str
) {}
656 friend class const_iterator
;
659 size_t IterToImplPos(wxString::iterator i
) const
660 { return wxStringImpl::const_iterator(i
.impl()) - m_impl
.begin(); }
662 #else // !wxUSE_UNICODE_UTF8
666 WX_STR_ITERATOR_IMPL(iterator
, wxChar
*, wxUniCharRef
,
667 wxUniCharRef::CreateForString(m_cur
));
670 iterator(const iterator
& i
) : m_cur(i
.m_cur
) {}
672 iterator
operator+(int n
) const
673 { return iterator(wxStringOperations::AddToIter(m_cur
, n
)); }
674 iterator
operator+(size_t n
) const
675 { return iterator(wxStringOperations::AddToIter(m_cur
, (int)n
)); }
676 iterator
operator-(int n
) const
677 { return iterator(wxStringOperations::AddToIter(m_cur
, -n
)); }
678 iterator
operator-(size_t n
) const
679 { return iterator(wxStringOperations::AddToIter(m_cur
, -(int)n
)); }
682 // for internal wxString use only:
683 iterator(underlying_iterator ptr
) : m_cur(ptr
) {}
684 iterator(wxString
*WXUNUSED(str
), underlying_iterator ptr
) : m_cur(ptr
) {}
686 friend class const_iterator
;
688 #endif // wxUSE_UNICODE_UTF8/!wxUSE_UNICODE_UTF8
692 // NB: reference_type is intentionally value, not reference, the character
693 // may be encoded differently in wxString data:
694 WX_STR_ITERATOR_IMPL(const_iterator
, const wxChar
*, wxUniChar
,
695 wxStringOperations::DecodeChar(m_cur
));
698 const_iterator(const const_iterator
& i
) : m_cur(i
.m_cur
) {}
699 const_iterator(const iterator
& i
) : m_cur(i
.m_cur
) {}
701 const_iterator
operator+(int n
) const
702 { return const_iterator(wxStringOperations::AddToIter(m_cur
, n
)); }
703 const_iterator
operator+(size_t n
) const
704 { return const_iterator(wxStringOperations::AddToIter(m_cur
, (int)n
)); }
705 const_iterator
operator-(int n
) const
706 { return const_iterator(wxStringOperations::AddToIter(m_cur
, -n
)); }
707 const_iterator
operator-(size_t n
) const
708 { return const_iterator(wxStringOperations::AddToIter(m_cur
, -(int)n
)); }
711 // for internal wxString use only:
712 const_iterator(underlying_iterator ptr
) : m_cur(ptr
) {}
715 #undef WX_STR_ITERATOR_TAG
716 #undef WX_STR_ITERATOR_IMPL
718 friend class iterator
;
719 friend class const_iterator
;
721 template <typename T
>
722 class reverse_iterator_impl
725 typedef T iterator_type
;
727 typedef typename
T::iterator_category iterator_category
;
728 typedef typename
T::value_type value_type
;
729 typedef typename
T::difference_type difference_type
;
730 typedef typename
T::reference reference
;
731 typedef typename
T::pointer
*pointer
;
733 reverse_iterator_impl(iterator_type i
) : m_cur(i
) {}
734 reverse_iterator_impl(const reverse_iterator_impl
& ri
)
737 iterator_type
base() const { return m_cur
; }
739 reference
operator*() const { return *(m_cur
-1); }
740 reference
operator[](size_t n
) const { return *(*this + n
); }
742 reverse_iterator_impl
& operator++()
743 { --m_cur
; return *this; }
744 reverse_iterator_impl
operator++(int)
745 { reverse_iterator_impl tmp
= *this; --m_cur
; return tmp
; }
746 reverse_iterator_impl
& operator--()
747 { ++m_cur
; return *this; }
748 reverse_iterator_impl
operator--(int)
749 { reverse_iterator_impl tmp
= *this; ++m_cur
; return tmp
; }
751 // NB: explicit <T> in the functions below is to keep BCC 5.5 happy
752 reverse_iterator_impl
operator+(int n
) const
753 { return reverse_iterator_impl
<T
>(m_cur
- n
); }
754 reverse_iterator_impl
operator+(size_t n
) const
755 { return reverse_iterator_impl
<T
>(m_cur
- n
); }
756 reverse_iterator_impl
operator-(int n
) const
757 { return reverse_iterator_impl
<T
>(m_cur
+ n
); }
758 reverse_iterator_impl
operator-(size_t n
) const
759 { return reverse_iterator_impl
<T
>(m_cur
+ n
); }
760 reverse_iterator_impl
operator+=(int n
)
761 { m_cur
-= n
; return *this; }
762 reverse_iterator_impl
operator+=(size_t n
)
763 { m_cur
-= n
; return *this; }
764 reverse_iterator_impl
operator-=(int n
)
765 { m_cur
+= n
; return *this; }
766 reverse_iterator_impl
operator-=(size_t n
)
767 { m_cur
+= n
; return *this; }
769 unsigned operator-(const reverse_iterator_impl
& i
) const
770 { return i
.m_cur
- m_cur
; }
772 bool operator==(const reverse_iterator_impl
& ri
) const
773 { return m_cur
== ri
.m_cur
; }
774 bool operator!=(const reverse_iterator_impl
& ri
) const
775 { return !(*this == ri
); }
777 bool operator<(const reverse_iterator_impl
& i
) const
778 { return m_cur
> i
.m_cur
; }
779 bool operator>(const reverse_iterator_impl
& i
) const
780 { return m_cur
< i
.m_cur
; }
781 bool operator<=(const reverse_iterator_impl
& i
) const
782 { return m_cur
>= i
.m_cur
; }
783 bool operator>=(const reverse_iterator_impl
& i
) const
784 { return m_cur
<= i
.m_cur
; }
790 typedef reverse_iterator_impl
<iterator
> reverse_iterator
;
791 typedef reverse_iterator_impl
<const_iterator
> const_reverse_iterator
;
794 // used to transform an expression built using c_str() (and hence of type
795 // wxCStrData) to an iterator into the string
796 static const_iterator
CreateConstIterator(const wxCStrData
& data
)
798 return const_iterator(data
.m_str
->begin() + data
.m_offset
);
801 // in UTF-8 STL build, creation from std::string requires conversion under
802 // non-UTF8 locales, so we can't have and use wxString(wxStringImpl) ctor;
803 // instead we define dummy type that lets us have wxString ctor for creation
804 // from wxStringImpl that couldn't be used by user code (in all other builds,
805 // "standard" ctors can be used):
806 #if wxUSE_UNICODE_UTF8 && wxUSE_STL_BASED_WXSTRING
807 struct CtorFromStringImplTag
{};
809 wxString(CtorFromStringImplTag
* WXUNUSED(dummy
), const wxStringImpl
& src
)
812 static wxString
FromImpl(const wxStringImpl
& src
)
813 { return wxString((CtorFromStringImplTag
*)NULL
, src
); }
815 #if !wxUSE_STL_BASED_WXSTRING
816 wxString(const wxStringImpl
& src
) : m_impl(src
) { }
817 // else: already defined as wxString(wxStdString) below
819 static wxString
FromImpl(const wxStringImpl
& src
) { return wxString(src
); }
823 // constructors and destructor
824 // ctor for an empty string
828 wxString(const wxString
& stringSrc
) : m_impl(stringSrc
.m_impl
) { }
830 // string containing nRepeat copies of ch
831 wxString(wxUniChar ch
, size_t nRepeat
= 1)
832 { assign(nRepeat
, ch
); }
833 wxString(size_t nRepeat
, wxUniChar ch
)
834 { assign(nRepeat
, ch
); }
835 wxString(wxUniCharRef ch
, size_t nRepeat
= 1)
836 { assign(nRepeat
, ch
); }
837 wxString(size_t nRepeat
, wxUniCharRef ch
)
838 { assign(nRepeat
, ch
); }
839 wxString(char ch
, size_t nRepeat
= 1)
840 { assign(nRepeat
, ch
); }
841 wxString(size_t nRepeat
, char ch
)
842 { assign(nRepeat
, ch
); }
843 wxString(wchar_t ch
, size_t nRepeat
= 1)
844 { assign(nRepeat
, ch
); }
845 wxString(size_t nRepeat
, wchar_t ch
)
846 { assign(nRepeat
, ch
); }
848 // ctors from char* strings:
849 wxString(const char *psz
)
850 : m_impl(ImplStr(psz
)) {}
851 wxString(const char *psz
, const wxMBConv
& conv
)
852 : m_impl(ImplStr(psz
, conv
)) {}
853 wxString(const char *psz
, size_t nLength
)
854 { assign(psz
, nLength
); }
855 wxString(const char *psz
, const wxMBConv
& conv
, size_t nLength
)
857 SubstrBufFromMB
str(ImplStr(psz
, nLength
, conv
));
858 m_impl
.assign(str
.data
, str
.len
);
861 // and unsigned char*:
862 wxString(const unsigned char *psz
)
863 : m_impl(ImplStr((const char*)psz
)) {}
864 wxString(const unsigned char *psz
, const wxMBConv
& conv
)
865 : m_impl(ImplStr((const char*)psz
, conv
)) {}
866 wxString(const unsigned char *psz
, size_t nLength
)
867 { assign((const char*)psz
, nLength
); }
868 wxString(const unsigned char *psz
, const wxMBConv
& conv
, size_t nLength
)
870 SubstrBufFromMB
str(ImplStr((const char*)psz
, nLength
, conv
));
871 m_impl
.assign(str
.data
, str
.len
);
874 // ctors from wchar_t* strings:
875 wxString(const wchar_t *pwz
)
876 : m_impl(ImplStr(pwz
)) {}
877 wxString(const wchar_t *pwz
, const wxMBConv
& WXUNUSED(conv
))
878 : m_impl(ImplStr(pwz
)) {}
879 wxString(const wchar_t *pwz
, size_t nLength
)
880 { assign(pwz
, nLength
); }
881 wxString(const wchar_t *pwz
, const wxMBConv
& WXUNUSED(conv
), size_t nLength
)
882 { assign(pwz
, nLength
); }
884 wxString(const wxCharBuffer
& buf
)
885 { assign(buf
.data()); } // FIXME-UTF8: fix for embedded NUL and buffer length
886 wxString(const wxWCharBuffer
& buf
)
887 { assign(buf
.data()); } // FIXME-UTF8: fix for embedded NUL and buffer length
889 wxString(const wxCStrData
& cstr
)
890 : m_impl(cstr
.AsString().m_impl
) { }
892 // as we provide both ctors with this signature for both char and unsigned
893 // char string, we need to provide one for wxCStrData to resolve ambiguity
894 wxString(const wxCStrData
& cstr
, size_t nLength
)
895 : m_impl(cstr
.AsString().Mid(0, nLength
).m_impl
) {}
897 // and because wxString is convertible to wxCStrData and const wxChar *
898 // we also need to provide this one
899 wxString(const wxString
& str
, size_t nLength
)
900 : m_impl(str
.Mid(0, nLength
).m_impl
) {}
902 // even if we're not built with wxUSE_STL == 1 it is very convenient to allow
903 // implicit conversions from std::string to wxString and vice verse as this
904 // allows to use the same strings in non-GUI and GUI code, however we don't
905 // want to unconditionally add this ctor as it would make wx lib dependent on
906 // libstdc++ on some Linux versions which is bad, so instead we ask the
907 // client code to define this wxUSE_STD_STRING symbol if they need it
909 #if wxUSE_UNICODE_WCHAR
910 wxString(const wxStdWideString
& str
) : m_impl(str
) {}
911 #else // UTF-8 or ANSI
912 wxString(const wxStdWideString
& str
)
913 { assign(str
.c_str(), str
.length()); }
916 #if !wxUSE_UNICODE // ANSI build
917 // FIXME-UTF8: do this in UTF8 build #if wxUSE_UTF8_LOCALE_ONLY, too
918 wxString(const std::string
& str
) : m_impl(str
) {}
920 wxString(const std::string
& str
)
921 { assign(str
.c_str(), str
.length()); }
924 #if wxUSE_UNICODE_WCHAR && wxUSE_STL_BASED_WXSTRING
925 // wxStringImpl is std::string in the encoding we want
926 operator const wxStdWideString
&() const { return m_impl
; }
928 // wxStringImpl is either not std::string or needs conversion
929 operator wxStdWideString() const
930 // FIXME-UTF8: broken for embedded NULs
931 { return wxStdWideString(wc_str()); }
934 #if !wxUSE_UNICODE && wxUSE_STL_BASED_WXSTRING
935 // FIXME-UTF8: do this in UTF8 build #if wxUSE_UTF8_LOCALE_ONLY, too
936 // wxStringImpl is std::string in the encoding we want
937 operator const std::string
&() const { return m_impl
; }
939 // wxStringImpl is either not std::string or needs conversion
940 operator std::string() const
941 // FIXME-UTF8: broken for embedded NULs
942 { return std::string(mb_str()); }
945 #endif // wxUSE_STD_STRING
947 // first valid index position
948 const_iterator
begin() const { return const_iterator(m_impl
.begin()); }
949 iterator
begin() { return iterator(this, m_impl
.begin()); }
950 // position one after the last valid one
951 const_iterator
end() const { return const_iterator(m_impl
.end()); }
952 iterator
end() { return iterator(this, m_impl
.end()); }
954 // first element of the reversed string
955 const_reverse_iterator
rbegin() const
956 { return const_reverse_iterator(end()); }
957 reverse_iterator
rbegin()
958 { return reverse_iterator(end()); }
959 // one beyond the end of the reversed string
960 const_reverse_iterator
rend() const
961 { return const_reverse_iterator(begin()); }
962 reverse_iterator
rend()
963 { return reverse_iterator(begin()); }
965 // std::string methods:
966 #if wxUSE_UNICODE_UTF8
967 size_t length() const { return end() - begin(); } // FIXME-UTF8: optimize!
969 size_t length() const { return m_impl
.length(); }
972 size_type
size() const { return length(); }
973 size_type
max_size() const { return npos
; }
975 bool empty() const { return m_impl
.empty(); }
977 size_type
capacity() const { return m_impl
.capacity(); } // FIXME-UTF8
978 void reserve(size_t sz
) { m_impl
.reserve(sz
); } // FIXME-UTF8
980 void resize(size_t nSize
, wxUniChar ch
= wxT('\0'))
982 #if wxUSE_UNICODE_UTF8
985 size_t len
= length();
988 else if ( nSize
< len
)
991 append(nSize
- len
, ch
);
995 m_impl
.resize(nSize
, (wxStringCharType
)ch
);
998 wxString
substr(size_t nStart
= 0, size_t nLen
= npos
) const
1001 PosLenToImpl(nStart
, nLen
, &pos
, &len
);
1002 return FromImpl(m_impl
.substr(pos
, len
));
1005 // generic attributes & operations
1006 // as standard strlen()
1007 size_t Len() const { return length(); }
1008 // string contains any characters?
1009 bool IsEmpty() const { return empty(); }
1010 // empty string is "false", so !str will return true
1011 bool operator!() const { return empty(); }
1012 // truncate the string to given length
1013 wxString
& Truncate(size_t uiLen
);
1014 // empty string contents
1019 wxASSERT_MSG( empty(), _T("string not empty after call to Empty()?") );
1021 // empty the string and free memory
1024 wxString
tmp(wxEmptyString
);
1029 // Is an ascii value
1030 bool IsAscii() const;
1032 bool IsNumber() const;
1034 bool IsWord() const;
1036 // data access (all indexes are 0 based)
1038 wxUniChar
at(size_t n
) const
1039 { return *(begin() + n
); } // FIXME-UTF8: optimize?
1040 wxUniChar
GetChar(size_t n
) const
1042 // read/write access
1043 wxUniCharRef
at(size_t n
)
1044 { return *(begin() + n
); } // FIXME-UTF8: optimize?
1045 wxUniCharRef
GetWritableChar(size_t n
)
1048 void SetChar(size_t n
, wxUniChar ch
)
1051 // get last character
1052 wxUniChar
Last() const
1054 wxASSERT_MSG( !empty(), _T("wxString: index out of bounds") );
1056 return at(length() - 1);
1059 // get writable last character
1062 wxASSERT_MSG( !empty(), _T("wxString: index out of bounds") );
1063 return at(length() - 1);
1067 Note that we we must define all of the overloads below to avoid
1068 ambiguity when using str[0].
1070 wxUniChar
operator[](int n
) const
1072 wxUniChar
operator[](long n
) const
1074 wxUniChar
operator[](size_t n
) const
1076 #ifndef wxSIZE_T_IS_UINT
1077 wxUniChar
operator[](unsigned int n
) const
1079 #endif // size_t != unsigned int
1081 // operator versions of GetWriteableChar()
1082 wxUniCharRef
operator[](int n
)
1084 wxUniCharRef
operator[](long n
)
1086 wxUniCharRef
operator[](size_t n
)
1088 #ifndef wxSIZE_T_IS_UINT
1089 wxUniCharRef
operator[](unsigned int n
)
1091 #endif // size_t != unsigned int
1093 // explicit conversion to C string (use this with printf()!)
1094 wxCStrData
c_str() const { return wxCStrData(this); }
1095 wxCStrData
data() const { return c_str(); }
1097 // implicit conversion to C string
1098 operator wxCStrData() const { return c_str(); }
1099 operator const char*() const { return c_str(); }
1100 operator const wchar_t*() const { return c_str(); }
1102 // implicit conversion to untyped pointer for compatibility with previous
1103 // wxWidgets versions: this is the same as conversion to const char * so it
1105 operator const void*() const { return c_str(); }
1107 // identical to c_str(), for MFC compatibility
1108 const wxCStrData
GetData() const { return c_str(); }
1110 // explicit conversion to C string in internal representation (char*,
1111 // wchar_t*, UTF-8-encoded char*, depending on the build):
1112 const wxStringCharType
*wx_str() const { return m_impl
.c_str(); }
1114 // conversion to *non-const* multibyte or widestring buffer; modifying
1115 // returned buffer won't affect the string, these methods are only useful
1116 // for passing values to const-incorrect functions
1117 wxWritableCharBuffer
char_str(const wxMBConv
& conv
= wxConvLibc
) const
1118 { return mb_str(conv
); }
1119 wxWritableWCharBuffer
wchar_str() const { return wc_str(); }
1121 // conversion to/from plain (i.e. 7 bit) ASCII: this is useful for
1122 // converting numbers or strings which are certain not to contain special
1123 // chars (typically system functions, X atoms, environment variables etc.)
1125 // the behaviour of these functions with the strings containing anything
1126 // else than 7 bit ASCII characters is undefined, use at your own risk.
1128 static wxString
FromAscii(const char *ascii
); // string
1129 static wxString
FromAscii(const char ascii
); // char
1130 const wxCharBuffer
ToAscii() const;
1132 static wxString
FromAscii(const char *ascii
) { return wxString( ascii
); }
1133 static wxString
FromAscii(const char ascii
) { return wxString( ascii
); }
1134 const char *ToAscii() const { return c_str(); }
1135 #endif // Unicode/!Unicode
1137 // functions for storing binary data in wxString:
1139 static wxString
From8BitData(const char *data
, size_t len
)
1140 { return wxString(data
, wxConvISO8859_1
, len
); }
1141 // version for NUL-terminated data:
1142 static wxString
From8BitData(const char *data
)
1143 { return wxString(data
, wxConvISO8859_1
); }
1144 const wxCharBuffer
To8BitData() const { return mb_str(wxConvISO8859_1
); }
1146 static wxString
From8BitData(const char *data
, size_t len
)
1147 { return wxString(data
, len
); }
1148 // version for NUL-terminated data:
1149 static wxString
From8BitData(const char *data
)
1150 { return wxString(data
); }
1151 const char *To8BitData() const { return c_str(); }
1152 #endif // Unicode/ANSI
1154 // conversions with (possible) format conversions: have to return a
1155 // buffer with temporary data
1157 // the functions defined (in either Unicode or ANSI) mode are mb_str() to
1158 // return an ANSI (multibyte) string, wc_str() to return a wide string and
1159 // fn_str() to return a string which should be used with the OS APIs
1160 // accepting the file names. The return value is always the same, but the
1161 // type differs because a function may either return pointer to the buffer
1162 // directly or have to use intermediate buffer for translation.
1164 const wxCharBuffer
mb_str(const wxMBConv
& conv
= wxConvLibc
) const;
1166 const wxWX2MBbuf
mbc_str() const { return mb_str(*wxConvCurrent
); }
1168 #if wxUSE_UNICODE_WCHAR
1169 const wxChar
* wc_str() const { return wx_str(); }
1170 #elif wxUSE_UNICODE_UTF8
1171 const wxWCharBuffer
wc_str() const;
1173 // for compatibility with !wxUSE_UNICODE version
1174 const wxWX2WCbuf
wc_str(const wxMBConv
& WXUNUSED(conv
)) const
1175 { return wc_str(); }
1178 const wxCharBuffer
fn_str() const { return mb_str(wxConvFile
); }
1180 const wxWX2WCbuf
fn_str() const { return wc_str(); }
1181 #endif // wxMBFILES/!wxMBFILES
1184 const wxChar
* mb_str() const { return wx_str(); }
1186 // for compatibility with wxUSE_UNICODE version
1187 const wxChar
* mb_str(const wxMBConv
& WXUNUSED(conv
)) const { return wx_str(); }
1189 const wxWX2MBbuf
mbc_str() const { return mb_str(); }
1192 const wxWCharBuffer
wc_str(const wxMBConv
& conv
= wxConvLibc
) const;
1193 #endif // wxUSE_WCHAR_T
1195 const wxCharBuffer
fn_str() const { return wxConvFile
.cWC2WX( wc_str( wxConvLocal
) ); }
1197 const wxChar
* fn_str() const { return c_str(); }
1199 #endif // Unicode/ANSI
1201 // overloaded assignment
1202 // from another wxString
1203 wxString
& operator=(const wxString
& stringSrc
)
1204 { m_impl
= stringSrc
.m_impl
; return *this; }
1205 wxString
& operator=(const wxCStrData
& cstr
)
1206 { return *this = cstr
.AsString(); }
1208 wxString
& operator=(wxUniChar ch
)
1209 { m_impl
= wxStringOperations::EncodeChar(ch
); return *this; }
1210 wxString
& operator=(wxUniCharRef ch
)
1211 { return operator=((wxUniChar
)ch
); }
1212 wxString
& operator=(char ch
)
1213 { return operator=(wxUniChar(ch
)); }
1214 wxString
& operator=(unsigned char ch
)
1215 { return operator=(wxUniChar(ch
)); }
1216 wxString
& operator=(wchar_t ch
)
1217 { return operator=(wxUniChar(ch
)); }
1218 // from a C string - STL probably will crash on NULL,
1219 // so we need to compensate in that case
1220 #if wxUSE_STL_BASED_WXSTRING
1221 wxString
& operator=(const char *psz
)
1222 { if (psz
) m_impl
= ImplStr(psz
); else Clear(); return *this; }
1223 wxString
& operator=(const wchar_t *pwz
)
1224 { if (pwz
) m_impl
= ImplStr(pwz
); else Clear(); return *this; }
1226 wxString
& operator=(const char *psz
)
1227 { m_impl
= ImplStr(psz
); return *this; }
1228 wxString
& operator=(const wchar_t *pwz
)
1229 { m_impl
= ImplStr(pwz
); return *this; }
1231 wxString
& operator=(const unsigned char *psz
)
1232 { return operator=((const char*)psz
); }
1234 // from wxWCharBuffer
1235 wxString
& operator=(const wxWCharBuffer
& s
)
1236 { return operator=(s
.data()); } // FIXME-UTF8: fix for embedded NULs
1237 // from wxCharBuffer
1238 wxString
& operator=(const wxCharBuffer
& s
)
1239 { return operator=(s
.data()); } // FIXME-UTF8: fix for embedded NULs
1241 // string concatenation
1242 // in place concatenation
1244 Concatenate and return the result. Note that the left to right
1245 associativity of << allows to write things like "str << str1 << str2
1246 << ..." (unlike with +=)
1249 wxString
& operator<<(const wxString
& s
)
1251 #if WXWIN_COMPATIBILITY_2_8 && !wxUSE_STL_BASED_WXSTRING && !wxUSE_UNICODE_UTF8
1252 wxASSERT_MSG( s
.IsValid(),
1253 _T("did you forget to call UngetWriteBuf()?") );
1259 // string += C string
1260 wxString
& operator<<(const char *psz
)
1261 { append(psz
); return *this; }
1262 wxString
& operator<<(const wchar_t *pwz
)
1263 { append(pwz
); return *this; }
1264 wxString
& operator<<(const wxCStrData
& psz
)
1265 { append(psz
.AsString()); return *this; }
1267 wxString
& operator<<(wxUniChar ch
) { append(1, ch
); return *this; }
1268 wxString
& operator<<(wxUniCharRef ch
) { append(1, ch
); return *this; }
1269 wxString
& operator<<(char ch
) { append(1, ch
); return *this; }
1270 wxString
& operator<<(unsigned char ch
) { append(1, ch
); return *this; }
1271 wxString
& operator<<(wchar_t ch
) { append(1, ch
); return *this; }
1273 // string += buffer (i.e. from wxGetString)
1274 wxString
& operator<<(const wxWCharBuffer
& s
)
1275 { return operator<<((const wchar_t *)s
); }
1276 wxString
& operator<<(const wxCharBuffer
& s
)
1277 { return operator<<((const char *)s
); }
1279 // string += C string
1280 wxString
& Append(const wxString
& s
)
1282 // test for empty() to share the string if possible
1289 wxString
& Append(const char* psz
)
1290 { append(psz
); return *this; }
1291 wxString
& Append(const wchar_t* pwz
)
1292 { append(pwz
); return *this; }
1293 wxString
& Append(const wxCStrData
& psz
)
1294 { append(psz
); return *this; }
1295 wxString
& Append(const wxCharBuffer
& psz
)
1296 { append(psz
); return *this; }
1297 wxString
& Append(const wxWCharBuffer
& psz
)
1298 { append(psz
); return *this; }
1299 // append count copies of given character
1300 wxString
& Append(wxUniChar ch
, size_t count
= 1u)
1301 { append(count
, ch
); return *this; }
1302 wxString
& Append(wxUniCharRef ch
, size_t count
= 1u)
1303 { append(count
, ch
); return *this; }
1304 wxString
& Append(char ch
, size_t count
= 1u)
1305 { append(count
, ch
); return *this; }
1306 wxString
& Append(unsigned char ch
, size_t count
= 1u)
1307 { append(count
, ch
); return *this; }
1308 wxString
& Append(wchar_t ch
, size_t count
= 1u)
1309 { append(count
, ch
); return *this; }
1310 wxString
& Append(const char* psz
, size_t nLen
)
1311 { append(psz
, nLen
); return *this; }
1312 wxString
& Append(const wchar_t* pwz
, size_t nLen
)
1313 { append(pwz
, nLen
); return *this; }
1315 // prepend a string, return the string itself
1316 wxString
& Prepend(const wxString
& str
)
1317 { *this = str
+ *this; return *this; }
1319 // non-destructive concatenation
1321 friend wxString WXDLLIMPEXP_BASE
operator+(const wxString
& string1
,
1322 const wxString
& string2
);
1323 // string with a single char
1324 friend wxString WXDLLIMPEXP_BASE
operator+(const wxString
& string
, wxUniChar ch
);
1325 // char with a string
1326 friend wxString WXDLLIMPEXP_BASE
operator+(wxUniChar ch
, const wxString
& string
);
1327 // string with C string
1328 friend wxString WXDLLIMPEXP_BASE
operator+(const wxString
& string
,
1330 friend wxString WXDLLIMPEXP_BASE
operator+(const wxString
& string
,
1331 const wchar_t *pwz
);
1332 // C string with string
1333 friend wxString WXDLLIMPEXP_BASE
operator+(const char *psz
,
1334 const wxString
& string
);
1335 friend wxString WXDLLIMPEXP_BASE
operator+(const wchar_t *pwz
,
1336 const wxString
& string
);
1338 // stream-like functions
1339 // insert an int into string
1340 wxString
& operator<<(int i
)
1341 { return (*this) << Format(_T("%d"), i
); }
1342 // insert an unsigned int into string
1343 wxString
& operator<<(unsigned int ui
)
1344 { return (*this) << Format(_T("%u"), ui
); }
1345 // insert a long into string
1346 wxString
& operator<<(long l
)
1347 { return (*this) << Format(_T("%ld"), l
); }
1348 // insert an unsigned long into string
1349 wxString
& operator<<(unsigned long ul
)
1350 { return (*this) << Format(_T("%lu"), ul
); }
1351 #if defined wxLongLong_t && !defined wxLongLongIsLong
1352 // insert a long long if they exist and aren't longs
1353 wxString
& operator<<(wxLongLong_t ll
)
1355 const wxChar
*fmt
= _T("%") wxLongLongFmtSpec
_T("d");
1356 return (*this) << Format(fmt
, ll
);
1358 // insert an unsigned long long
1359 wxString
& operator<<(wxULongLong_t ull
)
1361 const wxChar
*fmt
= _T("%") wxLongLongFmtSpec
_T("u");
1362 return (*this) << Format(fmt
, ull
);
1365 // insert a float into string
1366 wxString
& operator<<(float f
)
1367 { return (*this) << Format(_T("%f"), f
); }
1368 // insert a double into string
1369 wxString
& operator<<(double d
)
1370 { return (*this) << Format(_T("%g"), d
); }
1372 // string comparison
1373 // case-sensitive comparison (returns a value < 0, = 0 or > 0)
1374 int Cmp(const char *psz
) const
1375 { return compare(psz
); }
1376 int Cmp(const wchar_t *pwz
) const
1377 { return compare(pwz
); }
1378 int Cmp(const wxString
& s
) const
1379 { return compare(s
); }
1380 int Cmp(const wxCStrData
& s
) const
1381 { return compare(s
); }
1382 int Cmp(const wxCharBuffer
& s
) const
1383 { return compare(s
); }
1384 int Cmp(const wxWCharBuffer
& s
) const
1385 { return compare(s
); }
1386 // same as Cmp() but not case-sensitive
1387 int CmpNoCase(const wxString
& s
) const;
1388 // test for the string equality, either considering case or not
1389 // (if compareWithCase then the case matters)
1390 bool IsSameAs(const wxString
& str
, bool compareWithCase
= true) const
1391 { return (compareWithCase
? Cmp(str
) : CmpNoCase(str
)) == 0; }
1392 bool IsSameAs(const char *str
, bool compareWithCase
= true) const
1393 { return (compareWithCase
? Cmp(str
) : CmpNoCase(str
)) == 0; }
1394 bool IsSameAs(const wchar_t *str
, bool compareWithCase
= true) const
1395 { return (compareWithCase
? Cmp(str
) : CmpNoCase(str
)) == 0; }
1396 bool IsSameAs(const wxCStrData
& str
, bool compareWithCase
= true) const
1397 { return IsSameAs(str
.AsString(), compareWithCase
); }
1398 bool IsSameAs(const wxCharBuffer
& str
, bool compareWithCase
= true) const
1399 { return IsSameAs(str
.data(), compareWithCase
); }
1400 bool IsSameAs(const wxWCharBuffer
& str
, bool compareWithCase
= true) const
1401 { return IsSameAs(str
.data(), compareWithCase
); }
1402 // comparison with a single character: returns true if equal
1403 bool IsSameAs(wxUniChar c
, bool compareWithCase
= true) const
1405 return (length() == 1) && (compareWithCase
? GetChar(0u) == c
1406 : wxToupper(GetChar(0u)) == wxToupper(c
));
1408 // FIXME-UTF8: remove these overloads
1409 bool IsSameAs(wxUniCharRef c
, bool compareWithCase
= true) const
1410 { return IsSameAs(wxUniChar(c
), compareWithCase
); }
1411 bool IsSameAs(char c
, bool compareWithCase
= true) const
1412 { return IsSameAs(wxUniChar(c
), compareWithCase
); }
1413 bool IsSameAs(unsigned char c
, bool compareWithCase
= true) const
1414 { return IsSameAs(wxUniChar(c
), compareWithCase
); }
1415 bool IsSameAs(wchar_t c
, bool compareWithCase
= true) const
1416 { return IsSameAs(wxUniChar(c
), compareWithCase
); }
1417 bool IsSameAs(int c
, bool compareWithCase
= true) const
1418 { return IsSameAs(wxUniChar(c
), compareWithCase
); }
1420 // simple sub-string extraction
1421 // return substring starting at nFirst of length nCount (or till the end
1422 // if nCount = default value)
1423 wxString
Mid(size_t nFirst
, size_t nCount
= npos
) const;
1425 // operator version of Mid()
1426 wxString
operator()(size_t start
, size_t len
) const
1427 { return Mid(start
, len
); }
1429 // check if the string starts with the given prefix and return the rest
1430 // of the string in the provided pointer if it is not NULL; otherwise
1432 bool StartsWith(const wxChar
*prefix
, wxString
*rest
= NULL
) const;
1433 // check if the string ends with the given suffix and return the
1434 // beginning of the string before the suffix in the provided pointer if
1435 // it is not NULL; otherwise return false
1436 bool EndsWith(const wxChar
*suffix
, wxString
*rest
= NULL
) const;
1438 // get first nCount characters
1439 wxString
Left(size_t nCount
) const;
1440 // get last nCount characters
1441 wxString
Right(size_t nCount
) const;
1442 // get all characters before the first occurance of ch
1443 // (returns the whole string if ch not found)
1444 wxString
BeforeFirst(wxUniChar ch
) const;
1445 // get all characters before the last occurence of ch
1446 // (returns empty string if ch not found)
1447 wxString
BeforeLast(wxUniChar ch
) const;
1448 // get all characters after the first occurence of ch
1449 // (returns empty string if ch not found)
1450 wxString
AfterFirst(wxUniChar ch
) const;
1451 // get all characters after the last occurence of ch
1452 // (returns the whole string if ch not found)
1453 wxString
AfterLast(wxUniChar ch
) const;
1455 // for compatibility only, use more explicitly named functions above
1456 wxString
Before(wxUniChar ch
) const { return BeforeLast(ch
); }
1457 wxString
After(wxUniChar ch
) const { return AfterFirst(ch
); }
1460 // convert to upper case in place, return the string itself
1461 wxString
& MakeUpper();
1462 // convert to upper case, return the copy of the string
1463 // Here's something to remember: BC++ doesn't like returns in inlines.
1464 wxString
Upper() const ;
1465 // convert to lower case in place, return the string itself
1466 wxString
& MakeLower();
1467 // convert to lower case, return the copy of the string
1468 wxString
Lower() const ;
1470 // trimming/padding whitespace (either side) and truncating
1471 // remove spaces from left or from right (default) side
1472 wxString
& Trim(bool bFromRight
= true);
1473 // add nCount copies chPad in the beginning or at the end (default)
1474 wxString
& Pad(size_t nCount
, wxUniChar chPad
= wxT(' '), bool bFromRight
= true);
1476 // searching and replacing
1477 // searching (return starting index, or -1 if not found)
1478 int Find(wxUniChar ch
, bool bFromEnd
= false) const; // like strchr/strrchr
1479 int Find(wxUniCharRef ch
, bool bFromEnd
= false) const
1480 { return Find(wxUniChar(ch
), bFromEnd
); }
1481 int Find(char ch
, bool bFromEnd
= false) const
1482 { return Find(wxUniChar(ch
), bFromEnd
); }
1483 int Find(unsigned char ch
, bool bFromEnd
= false) const
1484 { return Find(wxUniChar(ch
), bFromEnd
); }
1485 int Find(wchar_t ch
, bool bFromEnd
= false) const
1486 { return Find(wxUniChar(ch
), bFromEnd
); }
1487 // searching (return starting index, or -1 if not found)
1488 int Find(const wxString
& sub
) const // like strstr
1490 size_type idx
= find(sub
);
1491 return (idx
== npos
) ? wxNOT_FOUND
: (int)idx
;
1493 int Find(const char *sub
) const // like strstr
1495 size_type idx
= find(sub
);
1496 return (idx
== npos
) ? wxNOT_FOUND
: (int)idx
;
1498 int Find(const wchar_t *sub
) const // like strstr
1500 size_type idx
= find(sub
);
1501 return (idx
== npos
) ? wxNOT_FOUND
: (int)idx
;
1504 int Find(const wxCStrData
& sub
) const
1505 { return Find(sub
.AsString()); }
1506 int Find(const wxCharBuffer
& sub
) const
1507 { return Find(sub
.data()); }
1508 int Find(const wxWCharBuffer
& sub
) const
1509 { return Find(sub
.data()); }
1511 // replace first (or all of bReplaceAll) occurences of substring with
1512 // another string, returns the number of replacements made
1513 size_t Replace(const wxString
& strOld
,
1514 const wxString
& strNew
,
1515 bool bReplaceAll
= true);
1517 // check if the string contents matches a mask containing '*' and '?'
1518 bool Matches(const wxString
& mask
) const;
1520 // conversion to numbers: all functions return true only if the whole
1521 // string is a number and put the value of this number into the pointer
1522 // provided, the base is the numeric base in which the conversion should be
1523 // done and must be comprised between 2 and 36 or be 0 in which case the
1524 // standard C rules apply (leading '0' => octal, "0x" => hex)
1525 // convert to a signed integer
1526 bool ToLong(long *val
, int base
= 10) const;
1527 // convert to an unsigned integer
1528 bool ToULong(unsigned long *val
, int base
= 10) const;
1529 // convert to wxLongLong
1530 #if defined(wxLongLong_t)
1531 bool ToLongLong(wxLongLong_t
*val
, int base
= 10) const;
1532 // convert to wxULongLong
1533 bool ToULongLong(wxULongLong_t
*val
, int base
= 10) const;
1534 #endif // wxLongLong_t
1535 // convert to a double
1536 bool ToDouble(double *val
) const;
1539 #ifndef wxNEEDS_WXSTRING_PRINTF_MIXIN
1540 // formatted input/output
1541 // as sprintf(), returns the number of characters written or < 0 on error
1542 // (take 'this' into account in attribute parameter count)
1543 // int Printf(const wxString& format, ...);
1544 WX_DEFINE_VARARG_FUNC(int, Printf
, 1, (const wxString
&),
1545 DoPrintfWchar
, DoPrintfUtf8
)
1547 WX_DEFINE_VARARG_FUNC(int, Printf
, 1, (const char*)
1548 DoPrintfWchar
, DoPrintfUtf8
)
1549 WX_DEFINE_VARARG_FUNC(int, Printf
, 1, (const wchar_t*)
1550 DoPrintfWchar
, DoPrintfUtf8
)
1551 WX_DEFINE_VARARG_FUNC(int, Printf
, 1, (const wxCStrData
&)
1552 DoPrintfWchar
, DoPrintfUtf8
)
1554 #endif // !wxNEEDS_WXSTRING_PRINTF_MIXIN
1555 // as vprintf(), returns the number of characters written or < 0 on error
1556 int PrintfV(const wxString
& format
, va_list argptr
);
1558 #ifndef wxNEEDS_WXSTRING_PRINTF_MIXIN
1559 // returns the string containing the result of Printf() to it
1560 // static wxString Format(const wxString& format, ...) ATTRIBUTE_PRINTF_1;
1561 WX_DEFINE_VARARG_FUNC(static wxString
, Format
, 1, (const wxString
&),
1562 DoFormatWchar
, DoFormatUtf8
)
1564 // workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351
1565 WX_DEFINE_VARARG_FUNC(static wxString
, Format
, 1, (const char*),
1566 DoFormatWchar
, DoFormatUtf8
)
1567 WX_DEFINE_VARARG_FUNC(static wxString
, Format
, 1, (const wchar_t*),
1568 DoFormatWchar
, DoFormatUtf8
)
1569 WX_DEFINE_VARARG_FUNC(static wxString
, Format
, 1, (const wxCStrData
&),
1570 DoFormatWchar
, DoFormatUtf8
)
1573 // the same as above, but takes a va_list
1574 static wxString
FormatV(const wxString
& format
, va_list argptr
);
1576 // raw access to string memory
1577 // ensure that string has space for at least nLen characters
1578 // only works if the data of this string is not shared
1579 bool Alloc(size_t nLen
) { reserve(nLen
); /*return capacity() >= nLen;*/ return true; }
1580 // minimize the string's memory
1581 // only works if the data of this string is not shared
1583 #if WXWIN_COMPATIBILITY_2_8 && !wxUSE_STL_BASED_WXSTRING && !wxUSE_UNICODE_UTF8
1584 // These are deprecated, use wxStringBuffer or wxStringBufferLength instead
1586 // get writable buffer of at least nLen bytes. Unget() *must* be called
1587 // a.s.a.p. to put string back in a reasonable state!
1588 wxDEPRECATED( wxStringCharType
*GetWriteBuf(size_t nLen
) );
1589 // call this immediately after GetWriteBuf() has been used
1590 wxDEPRECATED( void UngetWriteBuf() );
1591 wxDEPRECATED( void UngetWriteBuf(size_t nLen
) );
1592 #endif // WXWIN_COMPATIBILITY_2_8 && !wxUSE_STL_BASED_WXSTRING && wxUSE_UNICODE_UTF8
1594 // wxWidgets version 1 compatibility functions
1597 wxString
SubString(size_t from
, size_t to
) const
1598 { return Mid(from
, (to
- from
+ 1)); }
1599 // values for second parameter of CompareTo function
1600 enum caseCompare
{exact
, ignoreCase
};
1601 // values for first parameter of Strip function
1602 enum stripType
{leading
= 0x1, trailing
= 0x2, both
= 0x3};
1604 #ifndef wxNEEDS_WXSTRING_PRINTF_MIXIN
1606 // (take 'this' into account in attribute parameter count)
1607 // int sprintf(const wxString& format, ...) ATTRIBUTE_PRINTF_2;
1608 WX_DEFINE_VARARG_FUNC(int, sprintf
, 1, (const wxString
&),
1609 DoPrintfWchar
, DoPrintfUtf8
)
1611 // workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351
1612 WX_DEFINE_VARARG_FUNC(int, sprintf
, 1, (const char*),
1613 DoPrintfWchar
, DoPrintfUtf8
)
1614 WX_DEFINE_VARARG_FUNC(int, sprintf
, 1, (const wchar_t*),
1615 DoPrintfWchar
, DoPrintfUtf8
)
1616 WX_DEFINE_VARARG_FUNC(int, sprintf
, 1, (const wxCStrData
&),
1617 DoPrintfWchar
, DoPrintfUtf8
)
1619 #endif // wxNEEDS_WXSTRING_PRINTF_MIXIN
1622 inline int CompareTo(const wxChar
* psz
, caseCompare cmp
= exact
) const
1623 { return cmp
== exact
? Cmp(psz
) : CmpNoCase(psz
); }
1626 size_t Length() const { return length(); }
1627 // Count the number of characters
1628 int Freq(wxUniChar ch
) const;
1630 void LowerCase() { MakeLower(); }
1632 void UpperCase() { MakeUpper(); }
1633 // use Trim except that it doesn't change this string
1634 wxString
Strip(stripType w
= trailing
) const;
1636 // use Find (more general variants not yet supported)
1637 size_t Index(const wxChar
* psz
) const { return Find(psz
); }
1638 size_t Index(wxUniChar ch
) const { return Find(ch
); }
1640 wxString
& Remove(size_t pos
) { return Truncate(pos
); }
1641 wxString
& RemoveLast(size_t n
= 1) { return Truncate(length() - n
); }
1643 wxString
& Remove(size_t nStart
, size_t nLen
)
1644 { return (wxString
&)erase( nStart
, nLen
); }
1647 int First( wxUniChar ch
) const { return Find(ch
); }
1648 int First( wxUniCharRef ch
) const { return Find(ch
); }
1649 int First( char ch
) const { return Find(ch
); }
1650 int First( unsigned char ch
) const { return Find(ch
); }
1651 int First( wchar_t ch
) const { return Find(ch
); }
1652 int First( const wxString
& str
) const { return Find(str
); }
1653 int Last( wxUniChar ch
) const { return Find(ch
, true); }
1654 bool Contains(const wxString
& str
) const { return Find(str
) != wxNOT_FOUND
; }
1657 bool IsNull() const { return empty(); }
1659 // std::string compatibility functions
1661 // take nLen chars starting at nPos
1662 wxString(const wxString
& str
, size_t nPos
, size_t nLen
)
1663 : m_impl(str
.m_impl
, nPos
, nLen
) { }
1664 // take all characters from first to last
1665 wxString(const_iterator first
, const_iterator last
)
1666 : m_impl(first
.impl(), last
.impl()) { }
1667 #if WXWIN_COMPATIBILITY_STRING_PTR_AS_ITER
1668 // the 2 overloads below are for compatibility with the existing code using
1669 // pointers instead of iterators
1670 wxString(const char *first
, const char *last
)
1672 SubstrBufFromMB
str(ImplStr(first
, last
- first
));
1673 m_impl
.assign(str
.data
, str
.len
);
1675 wxString(const wchar_t *first
, const wchar_t *last
)
1677 SubstrBufFromWC
str(ImplStr(first
, last
- first
));
1678 m_impl
.assign(str
.data
, str
.len
);
1680 // and this one is needed to compile code adding offsets to c_str() result
1681 wxString(const wxCStrData
& first
, const wxCStrData
& last
)
1682 : m_impl(CreateConstIterator(first
).impl(),
1683 CreateConstIterator(last
).impl())
1685 wxASSERT_MSG( first
.m_str
== last
.m_str
,
1686 _T("pointers must be into the same string") );
1688 #endif // WXWIN_COMPATIBILITY_STRING_PTR_AS_ITER
1690 // lib.string.modifiers
1691 // append elements str[pos], ..., str[pos+n]
1692 wxString
& append(const wxString
& str
, size_t pos
, size_t n
)
1695 str
.PosLenToImpl(pos
, n
, &from
, &len
);
1696 m_impl
.append(str
.m_impl
, from
, len
);
1700 wxString
& append(const wxString
& str
)
1701 { m_impl
.append(str
.m_impl
); return *this; }
1702 // append first n (or all if n == npos) characters of sz
1703 wxString
& append(const char *sz
)
1704 { m_impl
.append(ImplStr(sz
)); return *this; }
1705 wxString
& append(const wchar_t *sz
)
1706 { m_impl
.append(ImplStr(sz
)); return *this; }
1707 wxString
& append(const char *sz
, size_t n
)
1709 SubstrBufFromMB
str(ImplStr(sz
, n
));
1710 m_impl
.append(str
.data
, str
.len
);
1713 wxString
& append(const wchar_t *sz
, size_t n
)
1715 SubstrBufFromWC
str(ImplStr(sz
, n
));
1716 m_impl
.append(str
.data
, str
.len
);
1720 wxString
& append(const wxCStrData
& str
)
1721 { return append(str
.AsString()); }
1722 wxString
& append(const wxCharBuffer
& str
)
1723 { return append(str
.data()); }
1724 wxString
& append(const wxWCharBuffer
& str
)
1725 { return append(str
.data()); }
1727 // append n copies of ch
1728 wxString
& append(size_t n
, wxUniChar ch
)
1730 #if wxUSE_UNICODE_UTF8
1731 if ( !ch
.IsAscii() )
1732 m_impl
.append(wxStringOperations::EncodeNChars(n
, ch
));
1735 m_impl
.append(n
, (wxStringCharType
)ch
);
1738 // append from first to last
1739 wxString
& append(const_iterator first
, const_iterator last
)
1740 { m_impl
.append(first
.impl(), last
.impl()); return *this; }
1741 #if WXWIN_COMPATIBILITY_STRING_PTR_AS_ITER
1742 wxString
& append(const char *first
, const char *last
)
1743 { return append(first
, last
- first
); }
1744 wxString
& append(const wchar_t *first
, const wchar_t *last
)
1745 { return append(first
, last
- first
); }
1746 wxString
& append(const wxCStrData
& first
, const wxCStrData
& last
)
1747 { return append(CreateConstIterator(first
), CreateConstIterator(last
)); }
1748 #endif // WXWIN_COMPATIBILITY_STRING_PTR_AS_ITER
1750 // same as `this_string = str'
1751 wxString
& assign(const wxString
& str
)
1752 { m_impl
= str
.m_impl
; return *this; }
1753 wxString
& assign(const wxString
& str
, size_t len
)
1755 m_impl
.assign(str
.m_impl
, 0, str
.LenToImpl(len
));
1758 // same as ` = str[pos..pos + n]
1759 wxString
& assign(const wxString
& str
, size_t pos
, size_t n
)
1762 str
.PosLenToImpl(pos
, n
, &from
, &len
);
1763 m_impl
.assign(str
.m_impl
, from
, len
);
1766 // same as `= first n (or all if n == npos) characters of sz'
1767 wxString
& assign(const char *sz
)
1768 { m_impl
.assign(ImplStr(sz
)); return *this; }
1769 wxString
& assign(const wchar_t *sz
)
1770 { m_impl
.assign(ImplStr(sz
)); return *this; }
1771 wxString
& assign(const char *sz
, size_t n
)
1773 SubstrBufFromMB
str(ImplStr(sz
, n
));
1774 m_impl
.assign(str
.data
, str
.len
);
1777 wxString
& assign(const wchar_t *sz
, size_t n
)
1779 SubstrBufFromWC
str(ImplStr(sz
, n
));
1780 m_impl
.assign(str
.data
, str
.len
);
1784 wxString
& assign(const wxCStrData
& str
)
1785 { return assign(str
.AsString()); }
1786 wxString
& assign(const wxCharBuffer
& str
)
1787 { return assign(str
.data()); }
1788 wxString
& assign(const wxWCharBuffer
& str
)
1789 { return assign(str
.data()); }
1790 wxString
& assign(const wxCStrData
& str
, size_t len
)
1791 { return assign(str
.AsString(), len
); }
1792 wxString
& assign(const wxCharBuffer
& str
, size_t len
)
1793 { return assign(str
.data(), len
); }
1794 wxString
& assign(const wxWCharBuffer
& str
, size_t len
)
1795 { return assign(str
.data(), len
); }
1797 // same as `= n copies of ch'
1798 wxString
& assign(size_t n
, wxUniChar ch
)
1800 #if wxUSE_UNICODE_UTF8
1801 if ( !ch
.IsAscii() )
1802 m_impl
.assign(wxStringOperations::EncodeNChars(n
, ch
));
1805 m_impl
.assign(n
, (wxStringCharType
)ch
);
1809 wxString
& assign(size_t n
, wxUniCharRef ch
)
1810 { return assign(n
, wxUniChar(ch
)); }
1811 wxString
& assign(size_t n
, char ch
)
1812 { return assign(n
, wxUniChar(ch
)); }
1813 wxString
& assign(size_t n
, unsigned char ch
)
1814 { return assign(n
, wxUniChar(ch
)); }
1815 wxString
& assign(size_t n
, wchar_t ch
)
1816 { return assign(n
, wxUniChar(ch
)); }
1818 // assign from first to last
1819 wxString
& assign(const_iterator first
, const_iterator last
)
1820 { m_impl
.assign(first
.impl(), last
.impl()); return *this; }
1821 #if WXWIN_COMPATIBILITY_STRING_PTR_AS_ITER
1822 wxString
& assign(const char *first
, const char *last
)
1823 { return assign(first
, last
- first
); }
1824 wxString
& assign(const wchar_t *first
, const wchar_t *last
)
1825 { return assign(first
, last
- first
); }
1826 wxString
& assign(const wxCStrData
& first
, const wxCStrData
& last
)
1827 { return assign(CreateConstIterator(first
), CreateConstIterator(last
)); }
1828 #endif // WXWIN_COMPATIBILITY_STRING_PTR_AS_ITER
1830 // string comparison
1831 int compare(const wxString
& str
) const;
1832 int compare(const char* sz
) const;
1833 int compare(const wchar_t* sz
) const;
1834 int compare(const wxCStrData
& str
) const
1835 { return compare(str
.AsString()); }
1836 int compare(const wxCharBuffer
& str
) const
1837 { return compare(str
.data()); }
1838 int compare(const wxWCharBuffer
& str
) const
1839 { return compare(str
.data()); }
1840 // comparison with a substring
1841 int compare(size_t nStart
, size_t nLen
, const wxString
& str
) const;
1842 // comparison of 2 substrings
1843 int compare(size_t nStart
, size_t nLen
,
1844 const wxString
& str
, size_t nStart2
, size_t nLen2
) const;
1845 // substring comparison with first nCount characters of sz
1846 int compare(size_t nStart
, size_t nLen
,
1847 const char* sz
, size_t nCount
= npos
) const;
1848 int compare(size_t nStart
, size_t nLen
,
1849 const wchar_t* sz
, size_t nCount
= npos
) const;
1851 // insert another string
1852 wxString
& insert(size_t nPos
, const wxString
& str
)
1853 { insert(begin() + nPos
, str
.begin(), str
.end()); return *this; }
1854 // insert n chars of str starting at nStart (in str)
1855 wxString
& insert(size_t nPos
, const wxString
& str
, size_t nStart
, size_t n
)
1858 str
.PosLenToImpl(nStart
, n
, &from
, &len
);
1859 m_impl
.insert(PosToImpl(nPos
), str
.m_impl
, from
, len
);
1862 // insert first n (or all if n == npos) characters of sz
1863 wxString
& insert(size_t nPos
, const char *sz
)
1864 { m_impl
.insert(PosToImpl(nPos
), ImplStr(sz
)); return *this; }
1865 wxString
& insert(size_t nPos
, const wchar_t *sz
)
1866 { m_impl
.insert(PosToImpl(nPos
), ImplStr(sz
)); return *this; }
1867 wxString
& insert(size_t nPos
, const char *sz
, size_t n
)
1869 SubstrBufFromMB
str(ImplStr(sz
, n
));
1870 m_impl
.insert(PosToImpl(nPos
), str
.data
, str
.len
);
1873 wxString
& insert(size_t nPos
, const wchar_t *sz
, size_t n
)
1875 SubstrBufFromWC
str(ImplStr(sz
, n
));
1876 m_impl
.insert(PosToImpl(nPos
), str
.data
, str
.len
);
1879 // insert n copies of ch
1880 wxString
& insert(size_t nPos
, size_t n
, wxUniChar ch
)
1882 #if wxUSE_UNICODE_UTF8
1883 if ( !ch
.IsAscii() )
1884 m_impl
.insert(PosToImpl(nPos
), wxStringOperations::EncodeNChars(n
, ch
));
1887 m_impl
.insert(PosToImpl(nPos
), n
, (wxStringCharType
)ch
);
1890 iterator
insert(iterator it
, wxUniChar ch
)
1892 #if wxUSE_UNICODE_UTF8
1893 if ( !ch
.IsAscii() )
1895 size_t pos
= IterToImplPos(it
);
1896 m_impl
.insert(pos
, wxStringOperations::EncodeChar(ch
));
1897 return iterator(this, m_impl
.begin() + pos
);
1901 return iterator(this, m_impl
.insert(it
.impl(), (wxStringCharType
)ch
));
1903 void insert(iterator it
, const_iterator first
, const_iterator last
)
1904 { m_impl
.insert(it
.impl(), first
.impl(), last
.impl()); }
1905 #if WXWIN_COMPATIBILITY_STRING_PTR_AS_ITER
1906 void insert(iterator it
, const char *first
, const char *last
)
1907 { insert(it
- begin(), first
, last
- first
); }
1908 void insert(iterator it
, const wchar_t *first
, const wchar_t *last
)
1909 { insert(it
- begin(), first
, last
- first
); }
1910 void insert(iterator it
, const wxCStrData
& first
, const wxCStrData
& last
)
1911 { insert(it
, CreateConstIterator(first
), CreateConstIterator(last
)); }
1912 #endif // WXWIN_COMPATIBILITY_STRING_PTR_AS_ITER
1914 void insert(iterator it
, size_type n
, wxUniChar ch
)
1916 #if wxUSE_UNICODE_UTF8
1917 if ( !ch
.IsAscii() )
1918 m_impl
.insert(IterToImplPos(it
), wxStringOperations::EncodeNChars(n
, ch
));
1921 m_impl
.insert(it
.impl(), n
, (wxStringCharType
)ch
);
1924 // delete characters from nStart to nStart + nLen
1925 wxString
& erase(size_type pos
= 0, size_type n
= npos
)
1928 PosLenToImpl(pos
, n
, &from
, &len
);
1929 m_impl
.erase(from
, len
);
1932 // delete characters from first up to last
1933 iterator
erase(iterator first
, iterator last
)
1934 { return iterator(this, m_impl
.erase(first
.impl(), last
.impl())); }
1935 iterator
erase(iterator first
)
1936 { return iterator(this, m_impl
.erase(first
.impl())); }
1938 #ifdef wxSTRING_BASE_HASNT_CLEAR
1939 void clear() { erase(); }
1941 void clear() { m_impl
.clear(); }
1944 // replaces the substring of length nLen starting at nStart
1945 wxString
& replace(size_t nStart
, size_t nLen
, const char* sz
)
1948 PosLenToImpl(nStart
, nLen
, &from
, &len
);
1949 m_impl
.replace(from
, len
, ImplStr(sz
));
1952 wxString
& replace(size_t nStart
, size_t nLen
, const wchar_t* sz
)
1955 PosLenToImpl(nStart
, nLen
, &from
, &len
);
1956 m_impl
.replace(from
, len
, ImplStr(sz
));
1959 // replaces the substring of length nLen starting at nStart
1960 wxString
& replace(size_t nStart
, size_t nLen
, const wxString
& str
)
1963 PosLenToImpl(nStart
, nLen
, &from
, &len
);
1964 m_impl
.replace(from
, len
, str
.m_impl
);
1967 // replaces the substring with nCount copies of ch
1968 wxString
& replace(size_t nStart
, size_t nLen
, size_t nCount
, wxUniChar ch
)
1971 PosLenToImpl(nStart
, nLen
, &from
, &len
);
1972 #if wxUSE_UNICODE_UTF8
1973 if ( !ch
.IsAscii() )
1974 m_impl
.replace(from
, len
, wxStringOperations::EncodeNChars(nCount
, ch
));
1977 m_impl
.replace(from
, len
, nCount
, (wxStringCharType
)ch
);
1980 // replaces a substring with another substring
1981 wxString
& replace(size_t nStart
, size_t nLen
,
1982 const wxString
& str
, size_t nStart2
, size_t nLen2
)
1985 PosLenToImpl(nStart
, nLen
, &from
, &len
);
1988 str
.PosLenToImpl(nStart2
, nLen2
, &from2
, &len2
);
1990 m_impl
.replace(from
, len
, str
.m_impl
, from2
, len2
);
1993 // replaces the substring with first nCount chars of sz
1994 wxString
& replace(size_t nStart
, size_t nLen
,
1995 const char* sz
, size_t nCount
)
1998 PosLenToImpl(nStart
, nLen
, &from
, &len
);
2000 SubstrBufFromMB
str(ImplStr(sz
, nCount
));
2002 m_impl
.replace(from
, len
, str
.data
, str
.len
);
2005 wxString
& replace(size_t nStart
, size_t nLen
,
2006 const wchar_t* sz
, size_t nCount
)
2009 PosLenToImpl(nStart
, nLen
, &from
, &len
);
2011 SubstrBufFromWC
str(ImplStr(sz
, nCount
));
2013 m_impl
.replace(from
, len
, str
.data
, str
.len
);
2016 wxString
& replace(size_t nStart
, size_t nLen
,
2017 const wxString
& s
, size_t nCount
)
2020 PosLenToImpl(nStart
, nLen
, &from
, &len
);
2021 m_impl
.replace(from
, len
, s
.m_impl
.c_str(), s
.LenToImpl(nCount
));
2025 wxString
& replace(iterator first
, iterator last
, const char* s
)
2026 { m_impl
.replace(first
.impl(), last
.impl(), ImplStr(s
)); return *this; }
2027 wxString
& replace(iterator first
, iterator last
, const wchar_t* s
)
2028 { m_impl
.replace(first
.impl(), last
.impl(), ImplStr(s
)); return *this; }
2029 wxString
& replace(iterator first
, iterator last
, const char* s
, size_type n
)
2031 SubstrBufFromMB
str(ImplStr(s
, n
));
2032 m_impl
.replace(first
.impl(), last
.impl(), str
.data
, str
.len
);
2035 wxString
& replace(iterator first
, iterator last
, const wchar_t* s
, size_type n
)
2037 SubstrBufFromWC
str(ImplStr(s
, n
));
2038 m_impl
.replace(first
.impl(), last
.impl(), str
.data
, str
.len
);
2041 wxString
& replace(iterator first
, iterator last
, const wxString
& s
)
2042 { m_impl
.replace(first
.impl(), last
.impl(), s
.m_impl
); return *this; }
2043 wxString
& replace(iterator first
, iterator last
, size_type n
, wxUniChar ch
)
2045 #if wxUSE_UNICODE_UTF8
2046 if ( !ch
.IsAscii() )
2047 m_impl
.replace(first
.impl(), last
.impl(),
2048 wxStringOperations::EncodeNChars(n
, ch
));
2051 m_impl
.replace(first
.impl(), last
.impl(), n
, (wxStringCharType
)ch
);
2054 wxString
& replace(iterator first
, iterator last
,
2055 const_iterator first1
, const_iterator last1
)
2057 m_impl
.replace(first
.impl(), last
.impl(), first1
.impl(), last1
.impl());
2060 wxString
& replace(iterator first
, iterator last
,
2061 const char *first1
, const char *last1
)
2062 { replace(first
, last
, first1
, last1
- first1
); return *this; }
2063 wxString
& replace(iterator first
, iterator last
,
2064 const wchar_t *first1
, const wchar_t *last1
)
2065 { replace(first
, last
, first1
, last1
- first1
); return *this; }
2068 void swap(wxString
& str
)
2069 { m_impl
.swap(str
.m_impl
); }
2072 size_t find(const wxString
& str
, size_t nStart
= 0) const
2073 { return PosFromImpl(m_impl
.find(str
.m_impl
, PosToImpl(nStart
))); }
2075 // find first n characters of sz
2076 size_t find(const char* sz
, size_t nStart
= 0, size_t n
= npos
) const
2078 SubstrBufFromMB
str(ImplStr(sz
, n
));
2079 return PosFromImpl(m_impl
.find(str
.data
, PosToImpl(nStart
), str
.len
));
2081 size_t find(const wchar_t* sz
, size_t nStart
= 0, size_t n
= npos
) const
2083 SubstrBufFromWC
str(ImplStr(sz
, n
));
2084 return PosFromImpl(m_impl
.find(str
.data
, PosToImpl(nStart
), str
.len
));
2086 size_t find(const wxCharBuffer
& s
, size_t nStart
= 0, size_t n
= npos
) const
2087 { return find(s
.data(), nStart
, n
); }
2088 size_t find(const wxWCharBuffer
& s
, size_t nStart
= 0, size_t n
= npos
) const
2089 { return find(s
.data(), nStart
, n
); }
2090 size_t find(const wxCStrData
& s
, size_t nStart
= 0, size_t n
= npos
) const
2091 { return find(s
.AsWChar(), nStart
, n
); }
2093 // find the first occurence of character ch after nStart
2094 size_t find(wxUniChar ch
, size_t nStart
= 0) const
2096 return PosFromImpl(m_impl
.find(wxStringOperations::EncodeChar(ch
),
2097 PosToImpl(nStart
)));
2099 size_t find(wxUniCharRef ch
, size_t nStart
= 0) const
2100 { return find(wxUniChar(ch
), nStart
); }
2101 size_t find(char ch
, size_t nStart
= 0) const
2102 { return find(wxUniChar(ch
), nStart
); }
2103 size_t find(unsigned char ch
, size_t nStart
= 0) const
2104 { return find(wxUniChar(ch
), nStart
); }
2105 size_t find(wchar_t ch
, size_t nStart
= 0) const
2106 { return find(wxUniChar(ch
), nStart
); }
2108 // rfind() family is exactly like find() but works right to left
2110 // as find, but from the end
2111 size_t rfind(const wxString
& str
, size_t nStart
= npos
) const
2112 { return PosFromImpl(m_impl
.rfind(str
.m_impl
, PosToImpl(nStart
))); }
2114 // as find, but from the end
2115 size_t rfind(const char* sz
, size_t nStart
= npos
, size_t n
= npos
) const
2117 SubstrBufFromMB
str(ImplStr(sz
, n
));
2118 return PosFromImpl(m_impl
.rfind(str
.data
, PosToImpl(nStart
), str
.len
));
2120 size_t rfind(const wchar_t* sz
, size_t nStart
= npos
, size_t n
= npos
) const
2122 SubstrBufFromWC
str(ImplStr(sz
, n
));
2123 return PosFromImpl(m_impl
.rfind(str
.data
, PosToImpl(nStart
), str
.len
));
2125 size_t rfind(const wxCharBuffer
& s
, size_t nStart
= npos
, size_t n
= npos
) const
2126 { return rfind(s
.data(), nStart
, n
); }
2127 size_t rfind(const wxWCharBuffer
& s
, size_t nStart
= npos
, size_t n
= npos
) const
2128 { return rfind(s
.data(), nStart
, n
); }
2129 size_t rfind(const wxCStrData
& s
, size_t nStart
= npos
, size_t n
= npos
) const
2130 { return rfind(s
.AsWChar(), nStart
, n
); }
2131 // as find, but from the end
2132 size_t rfind(wxUniChar ch
, size_t nStart
= npos
) const
2134 return PosFromImpl(m_impl
.rfind(wxStringOperations::EncodeChar(ch
),
2135 PosToImpl(nStart
)));
2137 size_t rfind(wxUniCharRef ch
, size_t nStart
= npos
) const
2138 { return rfind(wxUniChar(ch
), nStart
); }
2139 size_t rfind(char ch
, size_t nStart
= npos
) const
2140 { return rfind(wxUniChar(ch
), nStart
); }
2141 size_t rfind(unsigned char ch
, size_t nStart
= npos
) const
2142 { return rfind(wxUniChar(ch
), nStart
); }
2143 size_t rfind(wchar_t ch
, size_t nStart
= npos
) const
2144 { return rfind(wxUniChar(ch
), nStart
); }
2146 // find first/last occurence of any character (not) in the set:
2147 #if wxUSE_STL_BASED_WXSTRING && !wxUSE_UNICODE_UTF8
2148 // FIXME-UTF8: this is not entirely correct, because it doesn't work if
2149 // sizeof(wchar_t)==2 and surrogates are present in the string;
2150 // should we care? Probably not.
2151 size_t find_first_of(const wxString
& str
, size_t nStart
= 0) const
2152 { return m_impl
.find_first_of(str
.m_impl
, nStart
); }
2153 size_t find_first_of(const char* sz
, size_t nStart
= 0) const
2154 { return m_impl
.find_first_of(ImplStr(sz
), nStart
); }
2155 size_t find_first_of(const wchar_t* sz
, size_t nStart
= 0) const
2156 { return m_impl
.find_first_of(ImplStr(sz
), nStart
); }
2157 size_t find_first_of(const char* sz
, size_t nStart
, size_t n
) const
2158 { return m_impl
.find_first_of(ImplStr(sz
), nStart
, n
); }
2159 size_t find_first_of(const wchar_t* sz
, size_t nStart
, size_t n
) const
2160 { return m_impl
.find_first_of(ImplStr(sz
), nStart
, n
); }
2161 size_t find_first_of(wxUniChar c
, size_t nStart
= 0) const
2162 { return m_impl
.find_first_of((wxChar
)c
, nStart
); }
2164 size_t find_last_of(const wxString
& str
, size_t nStart
= npos
) const
2165 { return m_impl
.find_last_of(str
.m_impl
, nStart
); }
2166 size_t find_last_of(const char* sz
, size_t nStart
= npos
) const
2167 { return m_impl
.find_last_of(ImplStr(sz
), nStart
); }
2168 size_t find_last_of(const wchar_t* sz
, size_t nStart
= npos
) const
2169 { return m_impl
.find_last_of(ImplStr(sz
), nStart
); }
2170 size_t find_last_of(const char* sz
, size_t nStart
, size_t n
) const
2171 { return m_impl
.find_last_of(ImplStr(sz
), nStart
, n
); }
2172 size_t find_last_of(const wchar_t* sz
, size_t nStart
, size_t n
) const
2173 { return m_impl
.find_last_of(ImplStr(sz
), nStart
, n
); }
2174 size_t find_last_of(wxUniChar c
, size_t nStart
= npos
) const
2175 { return m_impl
.find_last_of((wxChar
)c
, nStart
); }
2177 size_t find_first_not_of(const wxString
& str
, size_t nStart
= 0) const
2178 { return m_impl
.find_first_not_of(str
.m_impl
, nStart
); }
2179 size_t find_first_not_of(const char* sz
, size_t nStart
= 0) const
2180 { return m_impl
.find_first_not_of(ImplStr(sz
), nStart
); }
2181 size_t find_first_not_of(const wchar_t* sz
, size_t nStart
= 0) const
2182 { return m_impl
.find_first_not_of(ImplStr(sz
), nStart
); }
2183 size_t find_first_not_of(const char* sz
, size_t nStart
, size_t n
) const
2184 { return m_impl
.find_first_not_of(ImplStr(sz
), nStart
, n
); }
2185 size_t find_first_not_of(const wchar_t* sz
, size_t nStart
, size_t n
) const
2186 { return m_impl
.find_first_not_of(ImplStr(sz
), nStart
, n
); }
2187 size_t find_first_not_of(wxUniChar c
, size_t nStart
= 0) const
2188 { return m_impl
.find_first_not_of((wxChar
)c
, nStart
); }
2190 size_t find_last_not_of(const wxString
& str
, size_t nStart
= npos
) const
2191 { return m_impl
.find_last_not_of(str
.m_impl
, nStart
); }
2192 size_t find_last_not_of(const char* sz
, size_t nStart
= npos
) const
2193 { return m_impl
.find_last_not_of(ImplStr(sz
), nStart
); }
2194 size_t find_last_not_of(const wchar_t* sz
, size_t nStart
= npos
) const
2195 { return m_impl
.find_last_not_of(ImplStr(sz
), nStart
); }
2196 size_t find_last_not_of(const char* sz
, size_t nStart
, size_t n
) const
2197 { return m_impl
.find_last_not_of(ImplStr(sz
), nStart
, n
); }
2198 size_t find_last_not_of(const wchar_t* sz
, size_t nStart
, size_t n
) const
2199 { return m_impl
.find_last_not_of(ImplStr(sz
), nStart
, n
); }
2200 size_t find_last_not_of(wxUniChar c
, size_t nStart
= npos
) const
2201 { return m_impl
.find_last_not_of((wxChar
)c
, nStart
); }
2203 // we can't use std::string implementation in UTF-8 build, because the
2204 // character sets would be interpreted wrongly:
2206 // as strpbrk() but starts at nStart, returns npos if not found
2207 size_t find_first_of(const wxString
& str
, size_t nStart
= 0) const
2208 #if wxUSE_UNICODE // FIXME-UTF8: temporary
2209 { return find_first_of(str
.wc_str(), nStart
); }
2211 { return find_first_of(str
.mb_str(), nStart
); }
2214 size_t find_first_of(const char* sz
, size_t nStart
= 0) const;
2215 size_t find_first_of(const wchar_t* sz
, size_t nStart
= 0) const;
2216 size_t find_first_of(const char* sz
, size_t nStart
, size_t n
) const;
2217 size_t find_first_of(const wchar_t* sz
, size_t nStart
, size_t n
) const;
2218 // same as find(char, size_t)
2219 size_t find_first_of(wxUniChar c
, size_t nStart
= 0) const
2220 { return find(c
, nStart
); }
2221 // find the last (starting from nStart) char from str in this string
2222 size_t find_last_of (const wxString
& str
, size_t nStart
= npos
) const
2223 #if wxUSE_UNICODE // FIXME-UTF8: temporary
2224 { return find_last_of(str
.wc_str(), nStart
); }
2226 { return find_last_of(str
.mb_str(), nStart
); }
2229 size_t find_last_of (const char* sz
, size_t nStart
= npos
) const;
2230 size_t find_last_of (const wchar_t* sz
, size_t nStart
= npos
) const;
2231 size_t find_last_of(const char* sz
, size_t nStart
, size_t n
) const;
2232 size_t find_last_of(const wchar_t* sz
, size_t nStart
, size_t n
) const;
2234 size_t find_last_of(wxUniChar c
, size_t nStart
= npos
) const
2235 { return rfind(c
, nStart
); }
2237 // find first/last occurence of any character not in the set
2239 // as strspn() (starting from nStart), returns npos on failure
2240 size_t find_first_not_of(const wxString
& str
, size_t nStart
= 0) const
2241 #if wxUSE_UNICODE // FIXME-UTF8: temporary
2242 { return find_first_not_of(str
.wc_str(), nStart
); }
2244 { return find_first_not_of(str
.mb_str(), nStart
); }
2247 size_t find_first_not_of(const char* sz
, size_t nStart
= 0) const;
2248 size_t find_first_not_of(const wchar_t* sz
, size_t nStart
= 0) const;
2249 size_t find_first_not_of(const char* sz
, size_t nStart
, size_t n
) const;
2250 size_t find_first_not_of(const wchar_t* sz
, size_t nStart
, size_t n
) const;
2252 size_t find_first_not_of(wxUniChar ch
, size_t nStart
= 0) const;
2254 size_t find_last_not_of(const wxString
& str
, size_t nStart
= npos
) const
2255 #if wxUSE_UNICODE // FIXME-UTF8: temporary
2256 { return find_last_not_of(str
.wc_str(), nStart
); }
2258 { return find_last_not_of(str
.mb_str(), nStart
); }
2261 size_t find_last_not_of(const char* sz
, size_t nStart
= npos
) const;
2262 size_t find_last_not_of(const wchar_t* sz
, size_t nStart
= npos
) const;
2263 size_t find_last_not_of(const char* sz
, size_t nStart
, size_t n
) const;
2264 size_t find_last_not_of(const wchar_t* sz
, size_t nStart
, size_t n
) const;
2266 size_t find_last_not_of(wxUniChar ch
, size_t nStart
= npos
) const;
2267 #endif // wxUSE_STL_BASED_WXSTRING && !wxUSE_UNICODE_UTF8 or not
2269 // provide char/wchar_t/wxUniCharRef overloads for char-finding functions
2270 // above to resolve ambiguities:
2271 size_t find_first_of(wxUniCharRef ch
, size_t nStart
= 0) const
2272 { return find_first_of(wxUniChar(ch
), nStart
); }
2273 size_t find_first_of(char ch
, size_t nStart
= 0) const
2274 { return find_first_of(wxUniChar(ch
), nStart
); }
2275 size_t find_first_of(unsigned char ch
, size_t nStart
= 0) const
2276 { return find_first_of(wxUniChar(ch
), nStart
); }
2277 size_t find_first_of(wchar_t ch
, size_t nStart
= 0) const
2278 { return find_first_of(wxUniChar(ch
), nStart
); }
2279 size_t find_last_of(wxUniCharRef ch
, size_t nStart
= npos
) const
2280 { return find_last_of(wxUniChar(ch
), nStart
); }
2281 size_t find_last_of(char ch
, size_t nStart
= npos
) const
2282 { return find_last_of(wxUniChar(ch
), nStart
); }
2283 size_t find_last_of(unsigned char ch
, size_t nStart
= npos
) const
2284 { return find_last_of(wxUniChar(ch
), nStart
); }
2285 size_t find_last_of(wchar_t ch
, size_t nStart
= npos
) const
2286 { return find_last_of(wxUniChar(ch
), nStart
); }
2287 size_t find_first_not_of(wxUniCharRef ch
, size_t nStart
= 0) const
2288 { return find_first_not_of(wxUniChar(ch
), nStart
); }
2289 size_t find_first_not_of(char ch
, size_t nStart
= 0) const
2290 { return find_first_not_of(wxUniChar(ch
), nStart
); }
2291 size_t find_first_not_of(unsigned char ch
, size_t nStart
= 0) const
2292 { return find_first_not_of(wxUniChar(ch
), nStart
); }
2293 size_t find_first_not_of(wchar_t ch
, size_t nStart
= 0) const
2294 { return find_first_not_of(wxUniChar(ch
), nStart
); }
2295 size_t find_last_not_of(wxUniCharRef ch
, size_t nStart
= npos
) const
2296 { return find_last_not_of(wxUniChar(ch
), nStart
); }
2297 size_t find_last_not_of(char ch
, size_t nStart
= npos
) const
2298 { return find_last_not_of(wxUniChar(ch
), nStart
); }
2299 size_t find_last_not_of(unsigned char ch
, size_t nStart
= npos
) const
2300 { return find_last_not_of(wxUniChar(ch
), nStart
); }
2301 size_t find_last_not_of(wchar_t ch
, size_t nStart
= npos
) const
2302 { return find_last_not_of(wxUniChar(ch
), nStart
); }
2304 // and additional overloads for the versions taking strings:
2305 size_t find_first_of(const wxCStrData
& sz
, size_t nStart
= 0) const
2306 { return find_first_of(sz
.AsString(), nStart
); }
2307 size_t find_first_of(const wxCharBuffer
& sz
, size_t nStart
= 0) const
2308 { return find_first_of(sz
.data(), nStart
); }
2309 size_t find_first_of(const wxWCharBuffer
& sz
, size_t nStart
= 0) const
2310 { return find_first_of(sz
.data(), nStart
); }
2311 size_t find_first_of(const wxCStrData
& sz
, size_t nStart
, size_t n
) const
2312 { return find_first_of(sz
.AsWChar(), nStart
, n
); }
2313 size_t find_first_of(const wxCharBuffer
& sz
, size_t nStart
, size_t n
) const
2314 { return find_first_of(sz
.data(), nStart
, n
); }
2315 size_t find_first_of(const wxWCharBuffer
& sz
, size_t nStart
, size_t n
) const
2316 { return find_first_of(sz
.data(), nStart
, n
); }
2318 size_t find_last_of(const wxCStrData
& sz
, size_t nStart
= 0) const
2319 { return find_last_of(sz
.AsString(), nStart
); }
2320 size_t find_last_of(const wxCharBuffer
& sz
, size_t nStart
= 0) const
2321 { return find_last_of(sz
.data(), nStart
); }
2322 size_t find_last_of(const wxWCharBuffer
& sz
, size_t nStart
= 0) const
2323 { return find_last_of(sz
.data(), nStart
); }
2324 size_t find_last_of(const wxCStrData
& sz
, size_t nStart
, size_t n
) const
2325 { return find_last_of(sz
.AsWChar(), nStart
, n
); }
2326 size_t find_last_of(const wxCharBuffer
& sz
, size_t nStart
, size_t n
) const
2327 { return find_last_of(sz
.data(), nStart
, n
); }
2328 size_t find_last_of(const wxWCharBuffer
& sz
, size_t nStart
, size_t n
) const
2329 { return find_last_of(sz
.data(), nStart
, n
); }
2331 size_t find_first_not_of(const wxCStrData
& sz
, size_t nStart
= 0) const
2332 { return find_first_not_of(sz
.AsString(), nStart
); }
2333 size_t find_first_not_of(const wxCharBuffer
& sz
, size_t nStart
= 0) const
2334 { return find_first_not_of(sz
.data(), nStart
); }
2335 size_t find_first_not_of(const wxWCharBuffer
& sz
, size_t nStart
= 0) const
2336 { return find_first_not_of(sz
.data(), nStart
); }
2337 size_t find_first_not_of(const wxCStrData
& sz
, size_t nStart
, size_t n
) const
2338 { return find_first_not_of(sz
.AsWChar(), nStart
, n
); }
2339 size_t find_first_not_of(const wxCharBuffer
& sz
, size_t nStart
, size_t n
) const
2340 { return find_first_not_of(sz
.data(), nStart
, n
); }
2341 size_t find_first_not_of(const wxWCharBuffer
& sz
, size_t nStart
, size_t n
) const
2342 { return find_first_not_of(sz
.data(), nStart
, n
); }
2344 size_t find_last_not_of(const wxCStrData
& sz
, size_t nStart
= 0) const
2345 { return find_last_not_of(sz
.AsString(), nStart
); }
2346 size_t find_last_not_of(const wxCharBuffer
& sz
, size_t nStart
= 0) const
2347 { return find_last_not_of(sz
.data(), nStart
); }
2348 size_t find_last_not_of(const wxWCharBuffer
& sz
, size_t nStart
= 0) const
2349 { return find_last_not_of(sz
.data(), nStart
); }
2350 size_t find_last_not_of(const wxCStrData
& sz
, size_t nStart
, size_t n
) const
2351 { return find_last_not_of(sz
.AsWChar(), nStart
, n
); }
2352 size_t find_last_not_of(const wxCharBuffer
& sz
, size_t nStart
, size_t n
) const
2353 { return find_last_not_of(sz
.data(), nStart
, n
); }
2354 size_t find_last_not_of(const wxWCharBuffer
& sz
, size_t nStart
, size_t n
) const
2355 { return find_last_not_of(sz
.data(), nStart
, n
); }
2358 wxString
& operator+=(const wxString
& s
)
2359 { m_impl
+= s
.m_impl
; return *this; }
2360 // string += C string
2361 wxString
& operator+=(const char *psz
)
2362 { m_impl
+= ImplStr(psz
); return *this; }
2363 wxString
& operator+=(const wchar_t *pwz
)
2364 { m_impl
+= ImplStr(pwz
); return *this; }
2365 wxString
& operator+=(const wxCStrData
& s
)
2366 { m_impl
+= s
.AsString().m_impl
; return *this; }
2367 wxString
& operator+=(const wxCharBuffer
& s
)
2368 { return operator+=(s
.data()); }
2369 wxString
& operator+=(const wxWCharBuffer
& s
)
2370 { return operator+=(s
.data()); }
2372 wxString
& operator+=(wxUniChar ch
)
2373 { m_impl
+= wxStringOperations::EncodeChar(ch
); return *this; }
2374 wxString
& operator+=(wxUniCharRef ch
) { return *this += wxUniChar(ch
); }
2375 wxString
& operator+=(int ch
) { return *this += wxUniChar(ch
); }
2376 wxString
& operator+=(char ch
) { return *this += wxUniChar(ch
); }
2377 wxString
& operator+=(unsigned char ch
) { return *this += wxUniChar(ch
); }
2378 wxString
& operator+=(wchar_t ch
) { return *this += wxUniChar(ch
); }
2381 #if !wxUSE_STL_BASED_WXSTRING
2382 // helpers for wxStringBuffer and wxStringBufferLength
2383 wxStringCharType
*DoGetWriteBuf(size_t nLen
)
2384 { return m_impl
.DoGetWriteBuf(nLen
); }
2385 void DoUngetWriteBuf()
2386 { m_impl
.DoUngetWriteBuf(); }
2387 void DoUngetWriteBuf(size_t nLen
)
2388 { m_impl
.DoUngetWriteBuf(nLen
); }
2389 #endif // !wxUSE_STL_BASED_WXSTRING
2391 #ifndef wxNEEDS_WXSTRING_PRINTF_MIXIN
2392 #if !wxUSE_UTF8_LOCALE_ONLY
2393 int DoPrintfWchar(const wxChar
*format
, ...);
2394 static wxString
DoFormatWchar(const wxChar
*format
, ...);
2396 #if wxUSE_UNICODE_UTF8
2397 int DoPrintfUtf8(const char *format
, ...);
2398 static wxString
DoFormatUtf8(const char *format
, ...);
2402 #if !wxUSE_STL_BASED_WXSTRING
2403 // check string's data validity
2404 bool IsValid() const { return m_impl
.GetStringData()->IsValid(); }
2408 wxStringImpl m_impl
;
2410 // buffers for compatibility conversion from (char*)c_str() and
2411 // (wchar_t*)c_str():
2412 // FIXME-UTF8: bechmark various approaches to keeping compatibility buffers
2413 template<typename T
>
2414 struct ConvertedBuffer
2416 ConvertedBuffer() : m_buf(NULL
) {}
2420 operator T
*() const { return m_buf
; }
2422 ConvertedBuffer
& operator=(T
*str
)
2432 ConvertedBuffer
<char> m_convertedToChar
;
2434 #if !wxUSE_UNICODE_WCHAR
2435 ConvertedBuffer
<wchar_t> m_convertedToWChar
;
2438 friend class WXDLLIMPEXP_BASE wxCStrData
;
2439 friend class wxImplStringBuffer
;
2440 friend class wxImplStringBufferLength
;
2443 #ifdef wxNEEDS_WXSTRING_PRINTF_MIXIN
2444 #pragma warning (default:4275)
2447 // string iterator operators that satisfy STL Random Access Iterator
2449 inline wxString::iterator
operator+(int n
, wxString::iterator i
)
2451 inline wxString::iterator
operator+(size_t n
, wxString::iterator i
)
2453 inline wxString::const_iterator
operator+(int n
, wxString::const_iterator i
)
2455 inline wxString::const_iterator
operator+(size_t n
, wxString::const_iterator i
)
2457 inline wxString::reverse_iterator
operator+(int n
, wxString::reverse_iterator i
)
2459 inline wxString::reverse_iterator
operator+(size_t n
, wxString::reverse_iterator i
)
2461 inline wxString::const_reverse_iterator
operator+(int n
, wxString::const_reverse_iterator i
)
2463 inline wxString::const_reverse_iterator
operator+(size_t n
, wxString::const_reverse_iterator i
)
2466 // notice that even though for many compilers the friend declarations above are
2467 // enough, from the point of view of C++ standard we must have the declarations
2468 // here as friend ones are not injected in the enclosing namespace and without
2469 // them the code fails to compile with conforming compilers such as xlC or g++4
2470 wxString WXDLLIMPEXP_BASE
operator+(const wxString
& string1
, const wxString
& string2
);
2471 wxString WXDLLIMPEXP_BASE
operator+(const wxString
& string
, const char *psz
);
2472 wxString WXDLLIMPEXP_BASE
operator+(const wxString
& string
, const wchar_t *pwz
);
2473 wxString WXDLLIMPEXP_BASE
operator+(const char *psz
, const wxString
& string
);
2474 wxString WXDLLIMPEXP_BASE
operator+(const wchar_t *pwz
, const wxString
& string
);
2476 wxString WXDLLIMPEXP_BASE
operator+(const wxString
& string
, wxUniChar ch
);
2477 wxString WXDLLIMPEXP_BASE
operator+(wxUniChar ch
, const wxString
& string
);
2479 inline wxString
operator+(const wxString
& string
, wxUniCharRef ch
)
2480 { return string
+ (wxUniChar
)ch
; }
2481 inline wxString
operator+(const wxString
& string
, char ch
)
2482 { return string
+ wxUniChar(ch
); }
2483 inline wxString
operator+(const wxString
& string
, wchar_t ch
)
2484 { return string
+ wxUniChar(ch
); }
2485 inline wxString
operator+(wxUniCharRef ch
, const wxString
& string
)
2486 { return (wxUniChar
)ch
+ string
; }
2487 inline wxString
operator+(char ch
, const wxString
& string
)
2488 { return wxUniChar(ch
) + string
; }
2489 inline wxString
operator+(wchar_t ch
, const wxString
& string
)
2490 { return wxUniChar(ch
) + string
; }
2493 #if wxUSE_STL_BASED_WXSTRING
2494 // return an empty wxString (not very useful with wxUSE_STL == 1)
2495 inline const wxString
wxGetEmptyString() { return wxString(); }
2496 #else // !wxUSE_STL_BASED_WXSTRING
2497 // return an empty wxString (more efficient than wxString() here)
2498 inline const wxString
& wxGetEmptyString()
2500 return *(wxString
*)&wxEmptyString
;
2502 #endif // wxUSE_STL_BASED_WXSTRING/!wxUSE_STL_BASED_WXSTRING
2504 // ----------------------------------------------------------------------------
2505 // wxStringBuffer: a tiny class allowing to get a writable pointer into string
2506 // ----------------------------------------------------------------------------
2508 #if !wxUSE_STL_BASED_WXSTRING
2509 // string buffer for direct access to string data in their native
2511 class wxImplStringBuffer
2514 typedef wxStringCharType CharType
;
2516 wxImplStringBuffer(wxString
& str
, size_t lenWanted
= 1024)
2517 : m_str(str
), m_buf(NULL
)
2518 { m_buf
= m_str
.DoGetWriteBuf(lenWanted
); }
2520 ~wxImplStringBuffer() { m_str
.DoUngetWriteBuf(); }
2522 operator wxStringCharType
*() const { return m_buf
; }
2526 wxStringCharType
*m_buf
;
2528 DECLARE_NO_COPY_CLASS(wxImplStringBuffer
)
2531 class wxImplStringBufferLength
2534 typedef wxStringCharType CharType
;
2536 wxImplStringBufferLength(wxString
& str
, size_t lenWanted
= 1024)
2537 : m_str(str
), m_buf(NULL
), m_len(0), m_lenSet(false)
2539 m_buf
= m_str
.DoGetWriteBuf(lenWanted
);
2540 wxASSERT(m_buf
!= NULL
);
2543 ~wxImplStringBufferLength()
2546 m_str
.DoUngetWriteBuf(m_len
);
2549 operator wxStringCharType
*() const { return m_buf
; }
2550 void SetLength(size_t length
) { m_len
= length
; m_lenSet
= true; }
2554 wxStringCharType
*m_buf
;
2558 DECLARE_NO_COPY_CLASS(wxImplStringBufferLength
)
2561 #endif // !wxUSE_STL_BASED_WXSTRING
2563 template<typename T
>
2564 class wxStringTypeBufferBase
2569 wxStringTypeBufferBase(wxString
& str
, size_t lenWanted
= 1024)
2570 : m_str(str
), m_buf(lenWanted
)
2574 operator CharType
*() { return m_buf
.data(); }
2578 wxCharTypeBuffer
<CharType
> m_buf
;
2581 template<typename T
>
2582 class wxStringTypeBufferLengthBase
2587 wxStringTypeBufferLengthBase(wxString
& str
, size_t lenWanted
= 1024)
2588 : m_str(str
), m_buf(lenWanted
), m_len(0), m_lenSet(false)
2591 ~wxStringTypeBufferLengthBase()
2594 m_str
.assign(m_buf
.data(), m_len
);
2597 operator CharType
*() { return m_buf
.data(); }
2598 void SetLength(size_t length
) { m_len
= length
; m_lenSet
= true; }
2602 wxCharTypeBuffer
<CharType
> m_buf
;
2607 template<typename T
>
2608 class wxStringTypeBuffer
: public wxStringTypeBufferBase
<T
>
2611 wxStringTypeBuffer(wxString
& str
, size_t lenWanted
= 1024)
2612 : wxStringTypeBufferBase
<T
>(str
, lenWanted
) {}
2613 ~wxStringTypeBuffer()
2615 this->m_str
.assign(this->m_buf
.data());
2618 DECLARE_NO_COPY_CLASS(wxStringTypeBuffer
)
2621 template<typename T
>
2622 class wxStringTypeBufferLength
: public wxStringTypeBufferLengthBase
<T
>
2625 wxStringTypeBufferLength(wxString
& str
, size_t lenWanted
= 1024)
2626 : wxStringTypeBufferLengthBase
<T
>(str
, lenWanted
) {}
2628 ~wxStringTypeBufferLength()
2630 wxASSERT(this->m_lenSet
);
2631 this->m_str
.assign(this->m_buf
.data(), this->m_len
);
2634 DECLARE_NO_COPY_CLASS(wxStringTypeBufferLength
)
2637 #if wxUSE_STL_BASED_WXSTRING
2638 class wxImplStringBuffer
: public wxStringTypeBufferBase
<wxStringCharType
>
2641 wxImplStringBuffer(wxString
& str
, size_t lenWanted
= 1024)
2642 : wxStringTypeBufferBase
<wxStringCharType
>(str
, lenWanted
) {}
2643 ~wxImplStringBuffer()
2644 { m_str
.m_impl
.assign(m_buf
.data()); }
2646 DECLARE_NO_COPY_CLASS(wxImplStringBuffer
)
2649 class wxImplStringBufferLength
: public wxStringTypeBufferLengthBase
<wxStringCharType
>
2652 wxImplStringBufferLength(wxString
& str
, size_t lenWanted
= 1024)
2653 : wxStringTypeBufferLengthBase
<wxStringCharType
>(str
, lenWanted
) {}
2655 ~wxImplStringBufferLength()
2658 m_str
.m_impl
.assign(m_buf
.data(), m_len
);
2661 DECLARE_NO_COPY_CLASS(wxImplStringBufferLength
)
2663 #endif // wxUSE_STL_BASED_WXSTRING
2666 #if wxUSE_STL_BASED_WXSTRING || wxUSE_UNICODE_UTF8
2667 typedef wxStringTypeBuffer
<wxChar
> wxStringBuffer
;
2668 typedef wxStringTypeBufferLength
<wxChar
> wxStringBufferLength
;
2669 #else // if !wxUSE_STL_BASED_WXSTRING && !wxUSE_UNICODE_UTF8
2670 typedef wxImplStringBuffer wxStringBuffer
;
2671 typedef wxImplStringBufferLength wxStringBufferLength
;
2672 #endif // !wxUSE_STL_BASED_WXSTRING && !wxUSE_UNICODE_UTF8
2674 // ---------------------------------------------------------------------------
2675 // wxString comparison functions: operator versions are always case sensitive
2676 // ---------------------------------------------------------------------------
2678 #define wxCMP_WXCHAR_STRING(p, s, op) 0 op s.Cmp(p)
2680 wxDEFINE_ALL_COMPARISONS(const wxChar
*, const wxString
&, wxCMP_WXCHAR_STRING
)
2682 #undef wxCMP_WXCHAR_STRING
2684 // note that there is an optimization in operator==() and !=(): we (quickly)
2685 // checks the strings length first, before comparing their data
2686 inline bool operator==(const wxString
& s1
, const wxString
& s2
)
2687 { return (s1
.Len() == s2
.Len()) && (s1
.Cmp(s2
) == 0); }
2688 inline bool operator!=(const wxString
& s1
, const wxString
& s2
)
2689 { return (s1
.Len() != s2
.Len()) || (s1
.Cmp(s2
) != 0); }
2690 inline bool operator< (const wxString
& s1
, const wxString
& s2
)
2691 { return s1
.Cmp(s2
) < 0; }
2692 inline bool operator> (const wxString
& s1
, const wxString
& s2
)
2693 { return s1
.Cmp(s2
) > 0; }
2694 inline bool operator<=(const wxString
& s1
, const wxString
& s2
)
2695 { return s1
.Cmp(s2
) <= 0; }
2696 inline bool operator>=(const wxString
& s1
, const wxString
& s2
)
2697 { return s1
.Cmp(s2
) >= 0; }
2700 inline bool operator==(const wxString
& s1
, const wxWCharBuffer
& s2
)
2701 { return (s1
.Cmp((const wchar_t *)s2
) == 0); }
2702 inline bool operator==(const wxWCharBuffer
& s1
, const wxString
& s2
)
2703 { return (s2
.Cmp((const wchar_t *)s1
) == 0); }
2704 inline bool operator!=(const wxString
& s1
, const wxWCharBuffer
& s2
)
2705 { return (s1
.Cmp((const wchar_t *)s2
) != 0); }
2706 inline bool operator!=(const wxWCharBuffer
& s1
, const wxString
& s2
)
2707 { return (s2
.Cmp((const wchar_t *)s1
) != 0); }
2708 #else // !wxUSE_UNICODE
2709 inline bool operator==(const wxString
& s1
, const wxCharBuffer
& s2
)
2710 { return (s1
.Cmp((const char *)s2
) == 0); }
2711 inline bool operator==(const wxCharBuffer
& s1
, const wxString
& s2
)
2712 { return (s2
.Cmp((const char *)s1
) == 0); }
2713 inline bool operator!=(const wxString
& s1
, const wxCharBuffer
& s2
)
2714 { return (s1
.Cmp((const char *)s2
) != 0); }
2715 inline bool operator!=(const wxCharBuffer
& s1
, const wxString
& s2
)
2716 { return (s2
.Cmp((const char *)s1
) != 0); }
2717 #endif // wxUSE_UNICODE/!wxUSE_UNICODE
2720 inline wxString
operator+(const wxString
& string
, const wxWCharBuffer
& buf
)
2721 { return string
+ (const wchar_t *)buf
; }
2722 inline wxString
operator+(const wxWCharBuffer
& buf
, const wxString
& string
)
2723 { return (const wchar_t *)buf
+ string
; }
2724 #else // !wxUSE_UNICODE
2725 inline wxString
operator+(const wxString
& string
, const wxCharBuffer
& buf
)
2726 { return string
+ (const char *)buf
; }
2727 inline wxString
operator+(const wxCharBuffer
& buf
, const wxString
& string
)
2728 { return (const char *)buf
+ string
; }
2729 #endif // wxUSE_UNICODE/!wxUSE_UNICODE
2731 // comparison with char
2732 inline bool operator==(const wxUniChar
& c
, const wxString
& s
) { return s
.IsSameAs(c
); }
2733 inline bool operator==(const wxUniCharRef
& c
, const wxString
& s
) { return s
.IsSameAs(c
); }
2734 inline bool operator==(char c
, const wxString
& s
) { return s
.IsSameAs(c
); }
2735 inline bool operator==(wchar_t c
, const wxString
& s
) { return s
.IsSameAs(c
); }
2736 inline bool operator==(int c
, const wxString
& s
) { return s
.IsSameAs(c
); }
2737 inline bool operator==(const wxString
& s
, const wxUniChar
& c
) { return s
.IsSameAs(c
); }
2738 inline bool operator==(const wxString
& s
, const wxUniCharRef
& c
) { return s
.IsSameAs(c
); }
2739 inline bool operator==(const wxString
& s
, char c
) { return s
.IsSameAs(c
); }
2740 inline bool operator==(const wxString
& s
, wchar_t c
) { return s
.IsSameAs(c
); }
2741 inline bool operator!=(const wxUniChar
& c
, const wxString
& s
) { return !s
.IsSameAs(c
); }
2742 inline bool operator!=(const wxUniCharRef
& c
, const wxString
& s
) { return !s
.IsSameAs(c
); }
2743 inline bool operator!=(char c
, const wxString
& s
) { return !s
.IsSameAs(c
); }
2744 inline bool operator!=(wchar_t c
, const wxString
& s
) { return !s
.IsSameAs(c
); }
2745 inline bool operator!=(int c
, const wxString
& s
) { return !s
.IsSameAs(c
); }
2746 inline bool operator!=(const wxString
& s
, const wxUniChar
& c
) { return !s
.IsSameAs(c
); }
2747 inline bool operator!=(const wxString
& s
, const wxUniCharRef
& c
) { return !s
.IsSameAs(c
); }
2748 inline bool operator!=(const wxString
& s
, char c
) { return !s
.IsSameAs(c
); }
2749 inline bool operator!=(const wxString
& s
, wchar_t c
) { return !s
.IsSameAs(c
); }
2751 // comparison with C string in Unicode build
2754 #define wxCMP_CHAR_STRING(p, s, op) wxString(p) op s
2756 wxDEFINE_ALL_COMPARISONS(const char *, const wxString
&, wxCMP_CHAR_STRING
)
2758 #undef wxCMP_CHAR_STRING
2760 #endif // wxUSE_UNICODE
2762 // we also need to provide the operators for comparison with wxCStrData to
2763 // resolve ambiguity between operator(const wxChar *,const wxString &) and
2764 // operator(const wxChar *, const wxChar *) for "p == s.c_str()"
2766 // notice that these are (shallow) pointer comparisons, not (deep) string ones
2767 #define wxCMP_CHAR_CSTRDATA(p, s, op) p op s.AsChar()
2768 #define wxCMP_WCHAR_CSTRDATA(p, s, op) p op s.AsWChar()
2770 wxDEFINE_ALL_COMPARISONS(const wchar_t *, const wxCStrData
&, wxCMP_WCHAR_CSTRDATA
)
2771 wxDEFINE_ALL_COMPARISONS(const char *, const wxCStrData
&, wxCMP_CHAR_CSTRDATA
)
2773 #undef wxCMP_CHAR_CSTRDATA
2774 #undef wxCMP_WCHAR_CSTRDATA
2776 // ---------------------------------------------------------------------------
2777 // Implementation only from here until the end of file
2778 // ---------------------------------------------------------------------------
2780 #if wxUSE_STD_IOSTREAM
2782 #include "wx/iosfwrap.h"
2784 WXDLLIMPEXP_BASE wxSTD ostream
& operator<<(wxSTD ostream
&, const wxString
&);
2785 WXDLLIMPEXP_BASE wxSTD ostream
& operator<<(wxSTD ostream
&, const wxCStrData
&);
2786 WXDLLIMPEXP_BASE wxSTD ostream
& operator<<(wxSTD ostream
&, const wxCharBuffer
&);
2787 #ifndef __BORLANDC__
2788 WXDLLIMPEXP_BASE wxSTD ostream
& operator<<(wxSTD ostream
&, const wxWCharBuffer
&);
2791 #endif // wxSTD_STRING_COMPATIBILITY
2793 // ---------------------------------------------------------------------------
2794 // wxCStrData implementation
2795 // ---------------------------------------------------------------------------
2797 inline wxCStrData::wxCStrData(char *buf
)
2798 : m_str(new wxString(buf
)), m_offset(0), m_owned(true) {}
2799 inline wxCStrData::wxCStrData(wchar_t *buf
)
2800 : m_str(new wxString(buf
)), m_offset(0), m_owned(true) {}
2802 inline wxCStrData::wxCStrData(const wxCStrData
& data
)
2803 : m_str(data
.m_owned
? new wxString(*data
.m_str
) : data
.m_str
),
2804 m_offset(data
.m_offset
),
2805 m_owned(data
.m_owned
)
2809 inline wxCStrData::~wxCStrData()
2815 // simple cases for AsChar() and AsWChar(), the complicated ones are
2817 #if wxUSE_UNICODE_WCHAR
2818 inline const wchar_t* wxCStrData::AsWChar() const
2820 return m_str
->wx_str() + m_offset
;
2822 #endif // wxUSE_UNICODE_WCHAR
2825 inline const char* wxCStrData::AsChar() const
2827 return m_str
->wx_str() + m_offset
;
2829 #endif // !wxUSE_UNICODE
2831 inline const wxCharBuffer
wxCStrData::AsCharBuf() const
2834 return wxCharBuffer::CreateNonOwned(AsChar());
2836 return AsString().mb_str();
2840 inline const wxWCharBuffer
wxCStrData::AsWCharBuf() const
2842 #if wxUSE_UNICODE_WCHAR
2843 return wxWCharBuffer::CreateNonOwned(AsWChar());
2845 return AsString().wc_str();
2849 inline wxString
wxCStrData::AsString() const
2851 if ( m_offset
== 0 )
2854 return m_str
->Mid(m_offset
);
2857 inline const wxStringCharType
*wxCStrData::AsInternal() const
2859 return wxStringOperations::AddToIter(m_str
->wx_str(), m_offset
);
2862 inline wxUniChar
wxCStrData::operator*() const
2864 if ( m_str
->empty() )
2865 return wxUniChar(_T('\0'));
2867 return (*m_str
)[m_offset
];
2870 inline wxUniChar
wxCStrData::operator[](size_t n
) const
2872 // NB: we intentionally use operator[] and not at() here because the former
2873 // works for the terminating NUL while the latter does not
2874 return (*m_str
)[m_offset
+ n
];
2877 // ----------------------------------------------------------------------------
2878 // more wxCStrData operators
2879 // ----------------------------------------------------------------------------
2881 // we need to define those to allow "size_t pos = p - s.c_str()" where p is
2882 // some pointer into the string
2883 inline size_t operator-(const char *p
, const wxCStrData
& cs
)
2885 return p
- cs
.AsChar();
2888 inline size_t operator-(const wchar_t *p
, const wxCStrData
& cs
)
2890 return p
- cs
.AsWChar();
2893 // ----------------------------------------------------------------------------
2894 // implementation of wx[W]CharBuffer inline methods using wxCStrData
2895 // ----------------------------------------------------------------------------
2897 // FIXME-UTF8: move this to buffer.h
2898 inline wxCharBuffer::wxCharBuffer(const wxCStrData
& cstr
)
2899 : wxCharTypeBufferBase(cstr
.AsCharBuf())
2903 inline wxWCharBuffer::wxWCharBuffer(const wxCStrData
& cstr
)
2904 : wxCharTypeBufferBase(cstr
.AsWCharBuf())
2908 #if WXWIN_COMPATIBILITY_2_8
2909 // lot of code out there doesn't explicitly include wx/wxchar.h, but uses
2910 // CRT wrappers that are now declared in wx/wxcrt.h and wx/wxcrtvararg.h,
2911 // so let's include this header now that wxString is defined and it's safe
2913 #include "wx/wxchar.h"
2916 #endif // _WX_WXSTRING_H_