- wxString& RemoveLast() { return Truncate(Len() - 1); }
-
- // Robert Roebling
-
- wxString& Remove(size_t nStart, size_t nLen) { return erase( nStart, nLen ); }
-
- size_t First( const char ch ) const { return find(ch); }
- size_t First( const char* psz ) const { return find(psz); }
- size_t First( const wxString &str ) const { return find(str); }
-
- size_t Last( const char ch ) const { return rfind(ch,0); }
- size_t Last( const char* psz ) const { return rfind(psz,0); }
- size_t Last( const wxString &str ) const { return rfind(str,0); }
-
- /// same as IsEmpty
- bool IsNull() const { return IsEmpty(); }
- //@}
-
-#ifdef STD_STRING_COMPATIBILITY
- /** @name std::string compatibility functions */
-
- /// an 'invalid' value for string index
- static const size_t npos;
-
- //@{
- /** @name constructors */
- //@{
- /// take nLen chars starting at nPos
- wxString(const wxString& s, size_t nPos, size_t nLen = npos);
- /// take all characters from pStart to pEnd
- wxString(const void *pStart, const void *pEnd);
- //@}
- /** @name lib.string.capacity */
- //@{
- /// return the length of the string
- size_t size() const { return Len(); }
- /// return the length of the string
- size_t length() const { return Len(); }
- /// return the maximum size of the string
- size_t max_size() const { return STRING_MAXLEN; }
- /// resize the string, filling the space with c if c != 0
- void resize(size_t nSize, char ch = '\0');
- /// delete the contents of the string
- void clear() { Empty(); }
- /// returns true if the string is empty
- bool empty() const { return IsEmpty(); }
- //@}
- /** @name lib.string.access */
- //@{
- /// return the character at position n
- char at(size_t n) const { return GetChar(n); }
- /// returns the writable character at position n
- char& at(size_t n) { return GetWritableChar(n); }
- //@}
- /** @name lib.string.modifiers */
- //@{
- /** @name append something to the end of this one */
- //@{
- /// append a string
- wxString& append(const wxString& str)
- { *this += str; return *this; }
- /// append elements str[pos], ..., str[pos+n]
- wxString& append(const wxString& str, size_t pos, size_t n)
- { ConcatSelf(n, str.c_str() + pos); return *this; }
- /// append first n (or all if n == npos) characters of sz
- wxString& append(const char *sz, size_t n = npos)
- { ConcatSelf(n == npos ? Strlen(sz) : n, sz); return *this; }
-
- /// append n copies of ch
- wxString& append(size_t n, char ch) { return Pad(n, ch); }
- //@}
-
- /** @name replaces the contents of this string with another one */
- //@{
- /// same as `this_string = str'
- wxString& assign(const wxString& str) { return (*this) = str; }
- /// same as ` = str[pos..pos + n]
- wxString& assign(const wxString& str, size_t pos, size_t n)
- { return *this = wxString((const char *)str + pos, n); }
- /// same as `= first n (or all if n == npos) characters of sz'
- wxString& assign(const char *sz, size_t n = npos)
- { return *this = wxString(sz, n); }
- /// same as `= n copies of ch'
- wxString& assign(size_t n, char ch)
- { return *this = wxString(ch, n); }
-
- //@}
-
- /** @name inserts something at position nPos into this one */
- //@{
- /// insert another string
- wxString& insert(size_t nPos, const wxString& str);
- /// insert n chars of str starting at nStart (in str)
- wxString& insert(size_t nPos, const wxString& str, size_t nStart, size_t n)
- { return insert(nPos, wxString((const char *)str + nStart, n)); }
-
- /// insert first n (or all if n == npos) characters of sz
- wxString& insert(size_t nPos, const char *sz, size_t n = npos)
- { return insert(nPos, wxString(sz, n)); }
- /// insert n copies of ch
- wxString& insert(size_t nPos, size_t n, char ch)
- { return insert(nPos, wxString(ch, n)); }
-
- //@}
-
- /** @name deletes a part of the string */
- //@{
- /// delete characters from nStart to nStart + nLen
- wxString& erase(size_t nStart = 0, size_t nLen = npos);
- //@}
-
- /** @name replaces a substring of this string with another one */
- //@{
- /// replaces the substring of length nLen starting at nStart
- wxString& replace(size_t nStart, size_t nLen, const char* sz);
- /// replaces the substring with nCount copies of ch
- wxString& replace(size_t nStart, size_t nLen, size_t nCount, char ch);
- /// replaces a substring with another substring
- wxString& replace(size_t nStart, size_t nLen,
- const wxString& str, size_t nStart2, size_t nLen2);
- /// replaces the substring with first nCount chars of sz
- wxString& replace(size_t nStart, size_t nLen,
- const char* sz, size_t nCount);
- //@}
- //@}
-
- /// swap two strings
- void swap(wxString& str);
-
- /** @name string operations */
- //@{
- /** All find() functions take the nStart argument which specifies
- the position to start the search on, the default value is 0.
-
- All functions return npos if there were no match.
-
- @name string search
- */
- //@{
- /**
- @name find a match for the string/character in this string
- */
- //@{
- /// find a substring
- size_t find(const wxString& str, size_t nStart = 0) const;
-
- // VC++ 1.5 can't cope with this syntax.
-#if ! (defined(_MSC_VER) && !defined(__WIN32__))
- /// find first n characters of sz
- size_t find(const char* sz, size_t nStart = 0, size_t n = npos) const;
-#endif
- /// find the first occurence of character ch after nStart
- size_t find(char ch, size_t nStart = 0) const;
-
- // wxWin compatibility
- inline bool Contains(const wxString& str) { return (Find(str) != -1); }
-
- //@}
-
- /**
- @name rfind() family is exactly like find() but works right to left
- */
- //@{
- /// as find, but from the end
- size_t rfind(const wxString& str, size_t nStart = npos) const;
- /// as find, but from the end
- // VC++ 1.5 can't cope with this syntax.
-#if ! (defined(_MSC_VER) && !defined(__WIN32__))
- size_t rfind(const char* sz, size_t nStart = npos,
- size_t n = npos) const;
- /// as find, but from the end
- size_t rfind(char ch, size_t nStart = npos) const;
-#endif
- //@}
-
- /**
- @name find first/last occurence of any character in the set
- */
- //@{
- ///
- size_t find_first_of(const wxString& str, size_t nStart = 0) const;
- ///
- size_t find_first_of(const char* sz, size_t nStart = 0) const;
- /// same as find(char, size_t)
- size_t find_first_of(char c, size_t nStart = 0) const;
-
- ///
- size_t find_last_of (const wxString& str, size_t nStart = npos) const;
- ///
- size_t find_last_of (const char* s, size_t nStart = npos) const;
- /// same as rfind(char, size_t)
- size_t find_last_of (char c, size_t nStart = npos) const;
- //@}
-
- /**
- @name find first/last occurence of any character not in the set
- */
- //@{
- ///
- size_t find_first_not_of(const wxString& str, size_t nStart = 0) const;
- ///
- size_t find_first_not_of(const char* s, size_t nStart = 0) const;
- ///
- size_t find_first_not_of(char ch, size_t nStart = 0) const;
-
- ///
- size_t find_last_not_of(const wxString& str, size_t nStart=npos) const;
- ///
- size_t find_last_not_of(const char* s, size_t nStart = npos) const;
- ///
- size_t find_last_not_of(char ch, size_t nStart = npos) const;
- //@}
- //@}
-
- /**
- All compare functions return -1, 0 or 1 if the [sub]string
- is less, equal or greater than the compare() argument.
-
- @name comparison
- */
- //@{
- /// just like strcmp()
- int compare(const wxString& str) const { return Cmp(str); }
- /// comparaison with a substring
- int compare(size_t nStart, size_t nLen, const wxString& str) const;
- /// comparaison of 2 substrings
- int compare(size_t nStart, size_t nLen,
- const wxString& str, size_t nStart2, size_t nLen2) const;
- /// just like strcmp()
- int compare(const char* sz) const { return Cmp(sz); }
- /// substring comparaison with first nCount characters of sz
- int compare(size_t nStart, size_t nLen,
- const char* sz, size_t nCount = npos) const;
- //@}
- wxString substr(size_t nStart = 0, size_t nLen = npos) const;
- //@}
-#endif
-
-protected:
- // points to data preceded by wxStringData structure with ref count info
- char *m_pchData;
-
- // accessor to string data
- wxStringData* GetStringData() const { return (wxStringData*)m_pchData - 1; }
-
- // string (re)initialization functions
- // initializes the string to the empty value (must be called only from
- // ctors, use Reinit() otherwise)
- void Init() { m_pchData = (char *)g_szNul; }
- // initializaes the string with (a part of) C-string
- void InitWith(const char *psz, size_t nPos = 0, size_t nLen = STRING_MAXLEN);
- // as Init, but also frees old data
- inline void Reinit();
-
- // memory allocation
- // allocates memory for string of lenght nLen
- void AllocBuffer(size_t nLen);
- // copies data to another string
- void AllocCopy(wxString&, int, int) const;
- // effectively copies data to string
- void AssignCopy(size_t, const char *);
-
- // append a (sub)string
- void ConcatCopy(int nLen1, const char *src1, int nLen2, const char *src2);
- void ConcatSelf(int nLen, const char *src);
-
- // functions called before writing to the string: they copy it if there
- // other references (should be the only owner when writing)
- void CopyBeforeWrite();
- void AllocBeforeWrite(size_t);
+ wxString& RemoveLast(size_t n = 1) { return Truncate(length() - n); }
+
+ wxString& Remove(size_t nStart, size_t nLen)
+ { return (wxString&)erase( nStart, nLen ); }
+
+ // use Find()
+ int First( wxUniChar ch ) const { return Find(ch); }
+ int First( wxUniCharRef ch ) const { return Find(ch); }
+ int First( char ch ) const { return Find(ch); }
+ int First( unsigned char ch ) const { return Find(ch); }
+ int First( wchar_t ch ) const { return Find(ch); }
+ int First( const wxString& str ) const { return Find(str); }
+ int Last( wxUniChar ch ) const { return Find(ch, true); }
+ bool Contains(const wxString& str) const { return Find(str) != wxNOT_FOUND; }
+
+ // use empty()
+ bool IsNull() const { return empty(); }
+
+ // std::string compatibility functions
+
+ // take nLen chars starting at nPos
+ wxString(const wxString& str, size_t nPos, size_t nLen)
+ { assign(str, nPos, nLen); }
+ // take all characters from first to last
+ wxString(const_iterator first, const_iterator last)
+ : m_impl(first.impl(), last.impl()) { }
+#if WXWIN_COMPATIBILITY_STRING_PTR_AS_ITER
+ // the 2 overloads below are for compatibility with the existing code using
+ // pointers instead of iterators
+ wxString(const char *first, const char *last)
+ {
+ SubstrBufFromMB str(ImplStr(first, last - first));
+ m_impl.assign(str.data, str.len);
+ }
+ wxString(const wchar_t *first, const wchar_t *last)
+ {
+ SubstrBufFromWC str(ImplStr(first, last - first));
+ m_impl.assign(str.data, str.len);
+ }
+ // and this one is needed to compile code adding offsets to c_str() result
+ wxString(const wxCStrData& first, const wxCStrData& last)
+ : m_impl(CreateConstIterator(first).impl(),
+ CreateConstIterator(last).impl())
+ {
+ wxASSERT_MSG( first.m_str == last.m_str,
+ _T("pointers must be into the same string") );
+ }
+#endif // WXWIN_COMPATIBILITY_STRING_PTR_AS_ITER
+
+ // lib.string.modifiers
+ // append elements str[pos], ..., str[pos+n]
+ wxString& append(const wxString& str, size_t pos, size_t n)
+ {
+ size_t from, len;
+ str.PosLenToImpl(pos, n, &from, &len);
+ m_impl.append(str.m_impl, from, len);
+ return *this;
+ }
+ // append a string
+ wxString& append(const wxString& str)
+ { m_impl.append(str.m_impl); return *this; }
+ // append first n (or all if n == npos) characters of sz
+ wxString& append(const char *sz)
+ { m_impl.append(ImplStr(sz)); return *this; }
+ wxString& append(const wchar_t *sz)
+ { m_impl.append(ImplStr(sz)); return *this; }
+ wxString& append(const char *sz, size_t n)
+ {
+ SubstrBufFromMB str(ImplStr(sz, n));
+ m_impl.append(str.data, str.len);
+ return *this;
+ }
+ wxString& append(const wchar_t *sz, size_t n)
+ {
+ SubstrBufFromWC str(ImplStr(sz, n));
+ m_impl.append(str.data, str.len);
+ return *this;
+ }
+
+ wxString& append(const wxCStrData& str)
+ { return append(str.AsString()); }
+ wxString& append(const wxCharBuffer& str)
+ { return append(str.data()); }
+ wxString& append(const wxWCharBuffer& str)
+ { return append(str.data()); }
+
+ // append n copies of ch
+ wxString& append(size_t n, wxUniChar ch)
+ {
+#if wxUSE_UNICODE_UTF8
+ if ( !ch.IsAscii() )
+ m_impl.append(wxStringOperations::EncodeNChars(n, ch));
+ else
+#endif
+ m_impl.append(n, (wxStringCharType)ch);
+ return *this;
+ }
+ // append from first to last
+ wxString& append(const_iterator first, const_iterator last)
+ { m_impl.append(first.impl(), last.impl()); return *this; }
+#if WXWIN_COMPATIBILITY_STRING_PTR_AS_ITER
+ wxString& append(const char *first, const char *last)
+ { return append(first, last - first); }
+ wxString& append(const wchar_t *first, const wchar_t *last)
+ { return append(first, last - first); }
+ wxString& append(const wxCStrData& first, const wxCStrData& last)
+ { return append(CreateConstIterator(first), CreateConstIterator(last)); }
+#endif // WXWIN_COMPATIBILITY_STRING_PTR_AS_ITER
+
+ // same as `this_string = str'
+ wxString& assign(const wxString& str)
+ { m_impl = str.m_impl; return *this; }
+ wxString& assign(const wxString& str, size_t len)
+ {
+ m_impl.assign(str.m_impl, 0, str.LenToImpl(len));
+ return *this;
+ }
+ // same as ` = str[pos..pos + n]
+ wxString& assign(const wxString& str, size_t pos, size_t n)
+ {
+ size_t from, len;
+ str.PosLenToImpl(pos, n, &from, &len);
+ m_impl.assign(str.m_impl, from, len);
+ return *this;
+ }
+ // same as `= first n (or all if n == npos) characters of sz'
+ wxString& assign(const char *sz)
+ { m_impl.assign(ImplStr(sz)); return *this; }
+ wxString& assign(const wchar_t *sz)
+ { m_impl.assign(ImplStr(sz)); return *this; }
+ wxString& assign(const char *sz, size_t n)
+ {
+ SubstrBufFromMB str(ImplStr(sz, n));
+ m_impl.assign(str.data, str.len);
+ return *this;
+ }
+ wxString& assign(const wchar_t *sz, size_t n)
+ {
+ SubstrBufFromWC str(ImplStr(sz, n));
+ m_impl.assign(str.data, str.len);
+ return *this;
+ }
+
+ wxString& assign(const wxCStrData& str)
+ { return assign(str.AsString()); }
+ wxString& assign(const wxCharBuffer& str)
+ { return assign(str.data()); }
+ wxString& assign(const wxWCharBuffer& str)
+ { return assign(str.data()); }
+ wxString& assign(const wxCStrData& str, size_t len)
+ { return assign(str.AsString(), len); }
+ wxString& assign(const wxCharBuffer& str, size_t len)
+ { return assign(str.data(), len); }
+ wxString& assign(const wxWCharBuffer& str, size_t len)
+ { return assign(str.data(), len); }
+
+ // same as `= n copies of ch'
+ wxString& assign(size_t n, wxUniChar ch)
+ {
+#if wxUSE_UNICODE_UTF8
+ if ( !ch.IsAscii() )
+ m_impl.assign(wxStringOperations::EncodeNChars(n, ch));
+ else
+#endif
+ m_impl.assign(n, (wxStringCharType)ch);
+ return *this;
+ }
+
+ wxString& assign(size_t n, wxUniCharRef ch)
+ { return assign(n, wxUniChar(ch)); }
+ wxString& assign(size_t n, char ch)
+ { return assign(n, wxUniChar(ch)); }
+ wxString& assign(size_t n, unsigned char ch)
+ { return assign(n, wxUniChar(ch)); }
+ wxString& assign(size_t n, wchar_t ch)
+ { return assign(n, wxUniChar(ch)); }
+
+ // assign from first to last
+ wxString& assign(const_iterator first, const_iterator last)
+ { m_impl.assign(first.impl(), last.impl()); return *this; }
+#if WXWIN_COMPATIBILITY_STRING_PTR_AS_ITER
+ wxString& assign(const char *first, const char *last)
+ { return assign(first, last - first); }
+ wxString& assign(const wchar_t *first, const wchar_t *last)
+ { return assign(first, last - first); }
+ wxString& assign(const wxCStrData& first, const wxCStrData& last)
+ { return assign(CreateConstIterator(first), CreateConstIterator(last)); }
+#endif // WXWIN_COMPATIBILITY_STRING_PTR_AS_ITER
+
+ // string comparison
+ int compare(const wxString& str) const;
+ int compare(const char* sz) const;
+ int compare(const wchar_t* sz) const;
+ int compare(const wxCStrData& str) const
+ { return compare(str.AsString()); }
+ int compare(const wxCharBuffer& str) const
+ { return compare(str.data()); }
+ int compare(const wxWCharBuffer& str) const
+ { return compare(str.data()); }
+ // comparison with a substring
+ int compare(size_t nStart, size_t nLen, const wxString& str) const;
+ // comparison of 2 substrings
+ int compare(size_t nStart, size_t nLen,
+ const wxString& str, size_t nStart2, size_t nLen2) const;
+ // substring comparison with first nCount characters of sz
+ int compare(size_t nStart, size_t nLen,
+ const char* sz, size_t nCount = npos) const;
+ int compare(size_t nStart, size_t nLen,
+ const wchar_t* sz, size_t nCount = npos) const;
+
+ // insert another string
+ wxString& insert(size_t nPos, const wxString& str)
+ { insert(begin() + nPos, str.begin(), str.end()); return *this; }
+ // insert n chars of str starting at nStart (in str)
+ wxString& insert(size_t nPos, const wxString& str, size_t nStart, size_t n)
+ {
+ size_t from, len;
+ str.PosLenToImpl(nStart, n, &from, &len);
+ m_impl.insert(PosToImpl(nPos), str.m_impl, from, len);
+ return *this;
+ }
+ // insert first n (or all if n == npos) characters of sz
+ wxString& insert(size_t nPos, const char *sz)
+ { m_impl.insert(PosToImpl(nPos), ImplStr(sz)); return *this; }
+ wxString& insert(size_t nPos, const wchar_t *sz)
+ { m_impl.insert(PosToImpl(nPos), ImplStr(sz)); return *this; }
+ wxString& insert(size_t nPos, const char *sz, size_t n)
+ {
+ SubstrBufFromMB str(ImplStr(sz, n));
+ m_impl.insert(PosToImpl(nPos), str.data, str.len);
+ return *this;
+ }
+ wxString& insert(size_t nPos, const wchar_t *sz, size_t n)
+ {
+ SubstrBufFromWC str(ImplStr(sz, n));
+ m_impl.insert(PosToImpl(nPos), str.data, str.len);
+ return *this;
+ }
+ // insert n copies of ch
+ wxString& insert(size_t nPos, size_t n, wxUniChar ch)
+ {
+#if wxUSE_UNICODE_UTF8
+ if ( !ch.IsAscii() )
+ m_impl.insert(PosToImpl(nPos), wxStringOperations::EncodeNChars(n, ch));
+ else
+#endif
+ m_impl.insert(PosToImpl(nPos), n, (wxStringCharType)ch);
+ return *this;
+ }
+ iterator insert(iterator it, wxUniChar ch)
+ {
+#if wxUSE_UNICODE_UTF8
+ if ( !ch.IsAscii() )
+ {
+ size_t pos = IterToImplPos(it);
+ m_impl.insert(pos, wxStringOperations::EncodeChar(ch));
+ return iterator(this, m_impl.begin() + pos);
+ }
+ else
+#endif
+ return iterator(this, m_impl.insert(it.impl(), (wxStringCharType)ch));
+ }
+ void insert(iterator it, const_iterator first, const_iterator last)
+ { m_impl.insert(it.impl(), first.impl(), last.impl()); }
+#if WXWIN_COMPATIBILITY_STRING_PTR_AS_ITER
+ void insert(iterator it, const char *first, const char *last)
+ { insert(it - begin(), first, last - first); }
+ void insert(iterator it, const wchar_t *first, const wchar_t *last)
+ { insert(it - begin(), first, last - first); }
+ void insert(iterator it, const wxCStrData& first, const wxCStrData& last)
+ { insert(it, CreateConstIterator(first), CreateConstIterator(last)); }
+#endif // WXWIN_COMPATIBILITY_STRING_PTR_AS_ITER
+
+ void insert(iterator it, size_type n, wxUniChar ch)
+ {
+#if wxUSE_UNICODE_UTF8
+ if ( !ch.IsAscii() )
+ m_impl.insert(IterToImplPos(it), wxStringOperations::EncodeNChars(n, ch));
+ else
+#endif
+ m_impl.insert(it.impl(), n, (wxStringCharType)ch);
+ }
+
+ // delete characters from nStart to nStart + nLen
+ wxString& erase(size_type pos = 0, size_type n = npos)
+ {
+ size_t from, len;
+ PosLenToImpl(pos, n, &from, &len);
+ m_impl.erase(from, len);
+ return *this;
+ }
+ // delete characters from first up to last
+ iterator erase(iterator first, iterator last)
+ { return iterator(this, m_impl.erase(first.impl(), last.impl())); }
+ iterator erase(iterator first)
+ { return iterator(this, m_impl.erase(first.impl())); }
+
+#ifdef wxSTRING_BASE_HASNT_CLEAR
+ void clear() { erase(); }
+#else
+ void clear() { m_impl.clear(); }
+#endif
+
+ // replaces the substring of length nLen starting at nStart
+ wxString& replace(size_t nStart, size_t nLen, const char* sz)
+ {
+ size_t from, len;
+ PosLenToImpl(nStart, nLen, &from, &len);
+ m_impl.replace(from, len, ImplStr(sz));
+ return *this;
+ }
+ wxString& replace(size_t nStart, size_t nLen, const wchar_t* sz)
+ {
+ size_t from, len;
+ PosLenToImpl(nStart, nLen, &from, &len);
+ m_impl.replace(from, len, ImplStr(sz));
+ return *this;
+ }
+ // replaces the substring of length nLen starting at nStart
+ wxString& replace(size_t nStart, size_t nLen, const wxString& str)
+ {
+ size_t from, len;
+ PosLenToImpl(nStart, nLen, &from, &len);
+ m_impl.replace(from, len, str.m_impl);
+ return *this;
+ }
+ // replaces the substring with nCount copies of ch
+ wxString& replace(size_t nStart, size_t nLen, size_t nCount, wxUniChar ch)
+ {
+ size_t from, len;
+ PosLenToImpl(nStart, nLen, &from, &len);
+#if wxUSE_UNICODE_UTF8
+ if ( !ch.IsAscii() )
+ m_impl.replace(from, len, wxStringOperations::EncodeNChars(nCount, ch));
+ else
+#endif
+ m_impl.replace(from, len, nCount, (wxStringCharType)ch);
+ return *this;
+ }
+ // replaces a substring with another substring
+ wxString& replace(size_t nStart, size_t nLen,
+ const wxString& str, size_t nStart2, size_t nLen2)
+ {
+ size_t from, len;
+ PosLenToImpl(nStart, nLen, &from, &len);
+
+ size_t from2, len2;
+ str.PosLenToImpl(nStart2, nLen2, &from2, &len2);
+
+ m_impl.replace(from, len, str.m_impl, from2, len2);
+ return *this;
+ }
+ // replaces the substring with first nCount chars of sz
+ wxString& replace(size_t nStart, size_t nLen,
+ const char* sz, size_t nCount)
+ {
+ size_t from, len;
+ PosLenToImpl(nStart, nLen, &from, &len);
+
+ SubstrBufFromMB str(ImplStr(sz, nCount));
+
+ m_impl.replace(from, len, str.data, str.len);
+ return *this;
+ }
+ wxString& replace(size_t nStart, size_t nLen,
+ const wchar_t* sz, size_t nCount)
+ {
+ size_t from, len;
+ PosLenToImpl(nStart, nLen, &from, &len);
+
+ SubstrBufFromWC str(ImplStr(sz, nCount));
+
+ m_impl.replace(from, len, str.data, str.len);
+ return *this;
+ }
+ wxString& replace(size_t nStart, size_t nLen,
+ const wxString& s, size_t nCount)
+ {
+ size_t from, len;
+ PosLenToImpl(nStart, nLen, &from, &len);
+ m_impl.replace(from, len, s.m_impl.c_str(), s.LenToImpl(nCount));
+ return *this;
+ }
+
+ wxString& replace(iterator first, iterator last, const char* s)
+ { m_impl.replace(first.impl(), last.impl(), ImplStr(s)); return *this; }
+ wxString& replace(iterator first, iterator last, const wchar_t* s)
+ { m_impl.replace(first.impl(), last.impl(), ImplStr(s)); return *this; }
+ wxString& replace(iterator first, iterator last, const char* s, size_type n)
+ {
+ SubstrBufFromMB str(ImplStr(s, n));
+ m_impl.replace(first.impl(), last.impl(), str.data, str.len);
+ return *this;
+ }
+ wxString& replace(iterator first, iterator last, const wchar_t* s, size_type n)
+ {
+ SubstrBufFromWC str(ImplStr(s, n));
+ m_impl.replace(first.impl(), last.impl(), str.data, str.len);
+ return *this;
+ }
+ wxString& replace(iterator first, iterator last, const wxString& s)
+ { m_impl.replace(first.impl(), last.impl(), s.m_impl); return *this; }
+ wxString& replace(iterator first, iterator last, size_type n, wxUniChar ch)
+ {
+#if wxUSE_UNICODE_UTF8
+ if ( !ch.IsAscii() )
+ m_impl.replace(first.impl(), last.impl(),
+ wxStringOperations::EncodeNChars(n, ch));
+ else
+#endif
+ m_impl.replace(first.impl(), last.impl(), n, (wxStringCharType)ch);
+ return *this;
+ }
+ wxString& replace(iterator first, iterator last,
+ const_iterator first1, const_iterator last1)
+ {
+ m_impl.replace(first.impl(), last.impl(), first1.impl(), last1.impl());
+ return *this;
+ }
+ wxString& replace(iterator first, iterator last,
+ const char *first1, const char *last1)
+ { replace(first, last, first1, last1 - first1); return *this; }
+ wxString& replace(iterator first, iterator last,
+ const wchar_t *first1, const wchar_t *last1)
+ { replace(first, last, first1, last1 - first1); return *this; }
+
+ // swap two strings
+ void swap(wxString& str)
+ { m_impl.swap(str.m_impl); }
+
+ // find a substring
+ size_t find(const wxString& str, size_t nStart = 0) const
+ { return PosFromImpl(m_impl.find(str.m_impl, PosToImpl(nStart))); }
+
+ // find first n characters of sz
+ size_t find(const char* sz, size_t nStart = 0, size_t n = npos) const
+ {
+ SubstrBufFromMB str(ImplStr(sz, n));
+ return PosFromImpl(m_impl.find(str.data, PosToImpl(nStart), str.len));
+ }
+ size_t find(const wchar_t* sz, size_t nStart = 0, size_t n = npos) const
+ {
+ SubstrBufFromWC str(ImplStr(sz, n));
+ return PosFromImpl(m_impl.find(str.data, PosToImpl(nStart), str.len));
+ }
+ size_t find(const wxCharBuffer& s, size_t nStart = 0, size_t n = npos) const
+ { return find(s.data(), nStart, n); }
+ size_t find(const wxWCharBuffer& s, size_t nStart = 0, size_t n = npos) const
+ { return find(s.data(), nStart, n); }
+ size_t find(const wxCStrData& s, size_t nStart = 0, size_t n = npos) const
+ { return find(s.AsWChar(), nStart, n); }
+
+ // find the first occurence of character ch after nStart
+ size_t find(wxUniChar ch, size_t nStart = 0) const
+ {
+ return PosFromImpl(m_impl.find(wxStringOperations::EncodeChar(ch),
+ PosToImpl(nStart)));
+ }
+ size_t find(wxUniCharRef ch, size_t nStart = 0) const
+ { return find(wxUniChar(ch), nStart); }
+ size_t find(char ch, size_t nStart = 0) const
+ { return find(wxUniChar(ch), nStart); }
+ size_t find(unsigned char ch, size_t nStart = 0) const
+ { return find(wxUniChar(ch), nStart); }
+ size_t find(wchar_t ch, size_t nStart = 0) const
+ { return find(wxUniChar(ch), nStart); }
+
+ // rfind() family is exactly like find() but works right to left
+
+ // as find, but from the end
+ size_t rfind(const wxString& str, size_t nStart = npos) const
+ { return PosFromImpl(m_impl.rfind(str.m_impl, PosToImpl(nStart))); }
+
+ // as find, but from the end
+ size_t rfind(const char* sz, size_t nStart = npos, size_t n = npos) const
+ {
+ SubstrBufFromMB str(ImplStr(sz, n));
+ return PosFromImpl(m_impl.rfind(str.data, PosToImpl(nStart), str.len));
+ }
+ size_t rfind(const wchar_t* sz, size_t nStart = npos, size_t n = npos) const
+ {
+ SubstrBufFromWC str(ImplStr(sz, n));
+ return PosFromImpl(m_impl.rfind(str.data, PosToImpl(nStart), str.len));
+ }
+ size_t rfind(const wxCharBuffer& s, size_t nStart = npos, size_t n = npos) const
+ { return rfind(s.data(), nStart, n); }
+ size_t rfind(const wxWCharBuffer& s, size_t nStart = npos, size_t n = npos) const
+ { return rfind(s.data(), nStart, n); }
+ size_t rfind(const wxCStrData& s, size_t nStart = npos, size_t n = npos) const
+ { return rfind(s.AsWChar(), nStart, n); }
+ // as find, but from the end
+ size_t rfind(wxUniChar ch, size_t nStart = npos) const
+ {
+ return PosFromImpl(m_impl.rfind(wxStringOperations::EncodeChar(ch),
+ PosToImpl(nStart)));
+ }
+ size_t rfind(wxUniCharRef ch, size_t nStart = npos) const
+ { return rfind(wxUniChar(ch), nStart); }
+ size_t rfind(char ch, size_t nStart = npos) const
+ { return rfind(wxUniChar(ch), nStart); }
+ size_t rfind(unsigned char ch, size_t nStart = npos) const
+ { return rfind(wxUniChar(ch), nStart); }
+ size_t rfind(wchar_t ch, size_t nStart = npos) const
+ { return rfind(wxUniChar(ch), nStart); }
+
+ // find first/last occurence of any character (not) in the set:
+#if wxUSE_STL_BASED_WXSTRING && !wxUSE_UNICODE_UTF8
+ // FIXME-UTF8: this is not entirely correct, because it doesn't work if
+ // sizeof(wchar_t)==2 and surrogates are present in the string;
+ // should we care? Probably not.
+ size_t find_first_of(const wxString& str, size_t nStart = 0) const
+ { return m_impl.find_first_of(str.m_impl, nStart); }
+ size_t find_first_of(const char* sz, size_t nStart = 0) const
+ { return m_impl.find_first_of(ImplStr(sz), nStart); }
+ size_t find_first_of(const wchar_t* sz, size_t nStart = 0) const
+ { return m_impl.find_first_of(ImplStr(sz), nStart); }
+ size_t find_first_of(const char* sz, size_t nStart, size_t n) const
+ { return m_impl.find_first_of(ImplStr(sz), nStart, n); }
+ size_t find_first_of(const wchar_t* sz, size_t nStart, size_t n) const
+ { return m_impl.find_first_of(ImplStr(sz), nStart, n); }
+ size_t find_first_of(wxUniChar c, size_t nStart = 0) const
+ { return m_impl.find_first_of((wxChar)c, nStart); }
+
+ size_t find_last_of(const wxString& str, size_t nStart = npos) const
+ { return m_impl.find_last_of(str.m_impl, nStart); }
+ size_t find_last_of(const char* sz, size_t nStart = npos) const
+ { return m_impl.find_last_of(ImplStr(sz), nStart); }
+ size_t find_last_of(const wchar_t* sz, size_t nStart = npos) const
+ { return m_impl.find_last_of(ImplStr(sz), nStart); }
+ size_t find_last_of(const char* sz, size_t nStart, size_t n) const
+ { return m_impl.find_last_of(ImplStr(sz), nStart, n); }
+ size_t find_last_of(const wchar_t* sz, size_t nStart, size_t n) const
+ { return m_impl.find_last_of(ImplStr(sz), nStart, n); }
+ size_t find_last_of(wxUniChar c, size_t nStart = npos) const
+ { return m_impl.find_last_of((wxChar)c, nStart); }
+
+ size_t find_first_not_of(const wxString& str, size_t nStart = 0) const
+ { return m_impl.find_first_not_of(str.m_impl, nStart); }
+ size_t find_first_not_of(const char* sz, size_t nStart = 0) const
+ { return m_impl.find_first_not_of(ImplStr(sz), nStart); }
+ size_t find_first_not_of(const wchar_t* sz, size_t nStart = 0) const
+ { return m_impl.find_first_not_of(ImplStr(sz), nStart); }
+ size_t find_first_not_of(const char* sz, size_t nStart, size_t n) const
+ { return m_impl.find_first_not_of(ImplStr(sz), nStart, n); }
+ size_t find_first_not_of(const wchar_t* sz, size_t nStart, size_t n) const
+ { return m_impl.find_first_not_of(ImplStr(sz), nStart, n); }
+ size_t find_first_not_of(wxUniChar c, size_t nStart = 0) const
+ { return m_impl.find_first_not_of((wxChar)c, nStart); }
+
+ size_t find_last_not_of(const wxString& str, size_t nStart = npos) const
+ { return m_impl.find_last_not_of(str.m_impl, nStart); }
+ size_t find_last_not_of(const char* sz, size_t nStart = npos) const
+ { return m_impl.find_last_not_of(ImplStr(sz), nStart); }
+ size_t find_last_not_of(const wchar_t* sz, size_t nStart = npos) const
+ { return m_impl.find_last_not_of(ImplStr(sz), nStart); }
+ size_t find_last_not_of(const char* sz, size_t nStart, size_t n) const
+ { return m_impl.find_last_not_of(ImplStr(sz), nStart, n); }
+ size_t find_last_not_of(const wchar_t* sz, size_t nStart, size_t n) const
+ { return m_impl.find_last_not_of(ImplStr(sz), nStart, n); }
+ size_t find_last_not_of(wxUniChar c, size_t nStart = npos) const
+ { return m_impl.find_last_not_of((wxChar)c, nStart); }
+#else
+ // we can't use std::string implementation in UTF-8 build, because the
+ // character sets would be interpreted wrongly:
+
+ // as strpbrk() but starts at nStart, returns npos if not found
+ size_t find_first_of(const wxString& str, size_t nStart = 0) const
+#if wxUSE_UNICODE // FIXME-UTF8: temporary
+ { return find_first_of(str.wc_str(), nStart); }
+#else
+ { return find_first_of(str.mb_str(), nStart); }
+#endif
+ // same as above
+ size_t find_first_of(const char* sz, size_t nStart = 0) const;
+ size_t find_first_of(const wchar_t* sz, size_t nStart = 0) const;
+ size_t find_first_of(const char* sz, size_t nStart, size_t n) const;
+ size_t find_first_of(const wchar_t* sz, size_t nStart, size_t n) const;
+ // same as find(char, size_t)
+ size_t find_first_of(wxUniChar c, size_t nStart = 0) const
+ { return find(c, nStart); }
+ // find the last (starting from nStart) char from str in this string
+ size_t find_last_of (const wxString& str, size_t nStart = npos) const
+#if wxUSE_UNICODE // FIXME-UTF8: temporary
+ { return find_last_of(str.wc_str(), nStart); }
+#else
+ { return find_last_of(str.mb_str(), nStart); }
+#endif
+ // same as above
+ size_t find_last_of (const char* sz, size_t nStart = npos) const;
+ size_t find_last_of (const wchar_t* sz, size_t nStart = npos) const;
+ size_t find_last_of(const char* sz, size_t nStart, size_t n) const;
+ size_t find_last_of(const wchar_t* sz, size_t nStart, size_t n) const;
+ // same as above
+ size_t find_last_of(wxUniChar c, size_t nStart = npos) const
+ { return rfind(c, nStart); }
+
+ // find first/last occurence of any character not in the set
+
+ // as strspn() (starting from nStart), returns npos on failure
+ size_t find_first_not_of(const wxString& str, size_t nStart = 0) const
+#if wxUSE_UNICODE // FIXME-UTF8: temporary
+ { return find_first_not_of(str.wc_str(), nStart); }
+#else
+ { return find_first_not_of(str.mb_str(), nStart); }
+#endif
+ // same as above
+ size_t find_first_not_of(const char* sz, size_t nStart = 0) const;
+ size_t find_first_not_of(const wchar_t* sz, size_t nStart = 0) const;
+ size_t find_first_not_of(const char* sz, size_t nStart, size_t n) const;
+ size_t find_first_not_of(const wchar_t* sz, size_t nStart, size_t n) const;
+ // same as above
+ size_t find_first_not_of(wxUniChar ch, size_t nStart = 0) const;
+ // as strcspn()
+ size_t find_last_not_of(const wxString& str, size_t nStart = npos) const
+#if wxUSE_UNICODE // FIXME-UTF8: temporary
+ { return find_last_not_of(str.wc_str(), nStart); }
+#else
+ { return find_last_not_of(str.mb_str(), nStart); }
+#endif
+ // same as above
+ size_t find_last_not_of(const char* sz, size_t nStart = npos) const;
+ size_t find_last_not_of(const wchar_t* sz, size_t nStart = npos) const;
+ size_t find_last_not_of(const char* sz, size_t nStart, size_t n) const;
+ size_t find_last_not_of(const wchar_t* sz, size_t nStart, size_t n) const;
+ // same as above
+ size_t find_last_not_of(wxUniChar ch, size_t nStart = npos) const;
+#endif // wxUSE_STL_BASED_WXSTRING && !wxUSE_UNICODE_UTF8 or not
+
+ // provide char/wchar_t/wxUniCharRef overloads for char-finding functions
+ // above to resolve ambiguities:
+ size_t find_first_of(wxUniCharRef ch, size_t nStart = 0) const
+ { return find_first_of(wxUniChar(ch), nStart); }
+ size_t find_first_of(char ch, size_t nStart = 0) const
+ { return find_first_of(wxUniChar(ch), nStart); }
+ size_t find_first_of(unsigned char ch, size_t nStart = 0) const
+ { return find_first_of(wxUniChar(ch), nStart); }
+ size_t find_first_of(wchar_t ch, size_t nStart = 0) const
+ { return find_first_of(wxUniChar(ch), nStart); }
+ size_t find_last_of(wxUniCharRef ch, size_t nStart = npos) const
+ { return find_last_of(wxUniChar(ch), nStart); }
+ size_t find_last_of(char ch, size_t nStart = npos) const
+ { return find_last_of(wxUniChar(ch), nStart); }
+ size_t find_last_of(unsigned char ch, size_t nStart = npos) const
+ { return find_last_of(wxUniChar(ch), nStart); }
+ size_t find_last_of(wchar_t ch, size_t nStart = npos) const
+ { return find_last_of(wxUniChar(ch), nStart); }
+ size_t find_first_not_of(wxUniCharRef ch, size_t nStart = 0) const
+ { return find_first_not_of(wxUniChar(ch), nStart); }
+ size_t find_first_not_of(char ch, size_t nStart = 0) const
+ { return find_first_not_of(wxUniChar(ch), nStart); }
+ size_t find_first_not_of(unsigned char ch, size_t nStart = 0) const
+ { return find_first_not_of(wxUniChar(ch), nStart); }
+ size_t find_first_not_of(wchar_t ch, size_t nStart = 0) const
+ { return find_first_not_of(wxUniChar(ch), nStart); }
+ size_t find_last_not_of(wxUniCharRef ch, size_t nStart = npos) const
+ { return find_last_not_of(wxUniChar(ch), nStart); }
+ size_t find_last_not_of(char ch, size_t nStart = npos) const
+ { return find_last_not_of(wxUniChar(ch), nStart); }
+ size_t find_last_not_of(unsigned char ch, size_t nStart = npos) const
+ { return find_last_not_of(wxUniChar(ch), nStart); }
+ size_t find_last_not_of(wchar_t ch, size_t nStart = npos) const
+ { return find_last_not_of(wxUniChar(ch), nStart); }
+
+ // and additional overloads for the versions taking strings:
+ size_t find_first_of(const wxCStrData& sz, size_t nStart = 0) const
+ { return find_first_of(sz.AsString(), nStart); }
+ size_t find_first_of(const wxCharBuffer& sz, size_t nStart = 0) const
+ { return find_first_of(sz.data(), nStart); }
+ size_t find_first_of(const wxWCharBuffer& sz, size_t nStart = 0) const
+ { return find_first_of(sz.data(), nStart); }
+ size_t find_first_of(const wxCStrData& sz, size_t nStart, size_t n) const
+ { return find_first_of(sz.AsWChar(), nStart, n); }
+ size_t find_first_of(const wxCharBuffer& sz, size_t nStart, size_t n) const
+ { return find_first_of(sz.data(), nStart, n); }
+ size_t find_first_of(const wxWCharBuffer& sz, size_t nStart, size_t n) const
+ { return find_first_of(sz.data(), nStart, n); }
+
+ size_t find_last_of(const wxCStrData& sz, size_t nStart = 0) const
+ { return find_last_of(sz.AsString(), nStart); }
+ size_t find_last_of(const wxCharBuffer& sz, size_t nStart = 0) const
+ { return find_last_of(sz.data(), nStart); }
+ size_t find_last_of(const wxWCharBuffer& sz, size_t nStart = 0) const
+ { return find_last_of(sz.data(), nStart); }
+ size_t find_last_of(const wxCStrData& sz, size_t nStart, size_t n) const
+ { return find_last_of(sz.AsWChar(), nStart, n); }
+ size_t find_last_of(const wxCharBuffer& sz, size_t nStart, size_t n) const
+ { return find_last_of(sz.data(), nStart, n); }
+ size_t find_last_of(const wxWCharBuffer& sz, size_t nStart, size_t n) const
+ { return find_last_of(sz.data(), nStart, n); }
+
+ size_t find_first_not_of(const wxCStrData& sz, size_t nStart = 0) const
+ { return find_first_not_of(sz.AsString(), nStart); }
+ size_t find_first_not_of(const wxCharBuffer& sz, size_t nStart = 0) const
+ { return find_first_not_of(sz.data(), nStart); }
+ size_t find_first_not_of(const wxWCharBuffer& sz, size_t nStart = 0) const
+ { return find_first_not_of(sz.data(), nStart); }
+ size_t find_first_not_of(const wxCStrData& sz, size_t nStart, size_t n) const
+ { return find_first_not_of(sz.AsWChar(), nStart, n); }
+ size_t find_first_not_of(const wxCharBuffer& sz, size_t nStart, size_t n) const
+ { return find_first_not_of(sz.data(), nStart, n); }
+ size_t find_first_not_of(const wxWCharBuffer& sz, size_t nStart, size_t n) const
+ { return find_first_not_of(sz.data(), nStart, n); }
+
+ size_t find_last_not_of(const wxCStrData& sz, size_t nStart = 0) const
+ { return find_last_not_of(sz.AsString(), nStart); }
+ size_t find_last_not_of(const wxCharBuffer& sz, size_t nStart = 0) const
+ { return find_last_not_of(sz.data(), nStart); }
+ size_t find_last_not_of(const wxWCharBuffer& sz, size_t nStart = 0) const
+ { return find_last_not_of(sz.data(), nStart); }
+ size_t find_last_not_of(const wxCStrData& sz, size_t nStart, size_t n) const
+ { return find_last_not_of(sz.AsWChar(), nStart, n); }
+ size_t find_last_not_of(const wxCharBuffer& sz, size_t nStart, size_t n) const
+ { return find_last_not_of(sz.data(), nStart, n); }
+ size_t find_last_not_of(const wxWCharBuffer& sz, size_t nStart, size_t n) const
+ { return find_last_not_of(sz.data(), nStart, n); }
+
+ // string += string
+ wxString& operator+=(const wxString& s)
+ { m_impl += s.m_impl; return *this; }
+ // string += C string
+ wxString& operator+=(const char *psz)
+ { m_impl += ImplStr(psz); return *this; }
+ wxString& operator+=(const wchar_t *pwz)
+ { m_impl += ImplStr(pwz); return *this; }
+ wxString& operator+=(const wxCStrData& s)
+ { m_impl += s.AsString().m_impl; return *this; }
+ wxString& operator+=(const wxCharBuffer& s)
+ { return operator+=(s.data()); }
+ wxString& operator+=(const wxWCharBuffer& s)
+ { return operator+=(s.data()); }
+ // string += char
+ wxString& operator+=(wxUniChar ch)
+ { m_impl += wxStringOperations::EncodeChar(ch); return *this; }
+ wxString& operator+=(wxUniCharRef ch) { return *this += wxUniChar(ch); }
+ wxString& operator+=(int ch) { return *this += wxUniChar(ch); }
+ wxString& operator+=(char ch) { return *this += wxUniChar(ch); }
+ wxString& operator+=(unsigned char ch) { return *this += wxUniChar(ch); }
+ wxString& operator+=(wchar_t ch) { return *this += wxUniChar(ch); }
+
+private:
+#if !wxUSE_STL_BASED_WXSTRING
+ // helpers for wxStringBuffer and wxStringBufferLength
+ wxStringCharType *DoGetWriteBuf(size_t nLen)
+ { return m_impl.DoGetWriteBuf(nLen); }
+ void DoUngetWriteBuf()
+ { m_impl.DoUngetWriteBuf(); }
+ void DoUngetWriteBuf(size_t nLen)
+ { m_impl.DoUngetWriteBuf(nLen); }
+#endif // !wxUSE_STL_BASED_WXSTRING
+
+#ifndef wxNEEDS_WXSTRING_PRINTF_MIXIN
+ #if !wxUSE_UTF8_LOCALE_ONLY
+ int DoPrintfWchar(const wxChar *format, ...);
+ static wxString DoFormatWchar(const wxChar *format, ...);
+ #endif
+ #if wxUSE_UNICODE_UTF8
+ int DoPrintfUtf8(const char *format, ...);
+ static wxString DoFormatUtf8(const char *format, ...);
+ #endif
+#endif
+
+#if !wxUSE_STL_BASED_WXSTRING
+ // check string's data validity
+ bool IsValid() const { return m_impl.GetStringData()->IsValid(); }
+#endif
+
+private:
+ wxStringImpl m_impl;
+
+#ifdef __VISUALC__
+ // "struct 'ConvertedBuffer<T>' needs to have dll-interface to be used by
+ // clients of class 'wxString'" - this is private, we don't care
+ #pragma warning (disable:4251)
+#endif
+
+ // buffers for compatibility conversion from (char*)c_str() and
+ // (wchar_t*)c_str():
+ // FIXME-UTF8: bechmark various approaches to keeping compatibility buffers
+ template<typename T>
+ struct ConvertedBuffer
+ {
+ ConvertedBuffer() : m_buf(NULL) {}
+ ~ConvertedBuffer()
+ { free(m_buf); }
+
+ operator T*() const { return m_buf; }
+
+ ConvertedBuffer& operator=(T *str)
+ {
+ free(m_buf);
+ m_buf = str;
+ return *this;
+ }
+
+ T *m_buf;
+ };
+#if wxUSE_UNICODE && !wxUSE_UTF8_LOCALE_ONLY
+ ConvertedBuffer<char> m_convertedToChar;
+#endif
+#if !wxUSE_UNICODE_WCHAR
+ ConvertedBuffer<wchar_t> m_convertedToWChar;
+#endif
+
+#ifdef __VISUALC__
+ #pragma warning (default:4251)
+#endif
+
+#if wxUSE_UNICODE_UTF8
+ // FIXME-UTF8: (try to) move this elsewhere (TLS) or solve differently
+ // assigning to character pointer to by wxString::interator may
+ // change the underlying wxStringImpl iterator, so we have to
+ // keep track of all iterators and update them as necessary:
+ struct wxStringIteratorNodeHead
+ {
+ wxStringIteratorNodeHead() : ptr(NULL) {}
+ wxStringIteratorNode *ptr;
+
+ // copying is disallowed as it would result in more than one pointer into
+ // the same linked list
+ DECLARE_NO_COPY_CLASS(wxStringIteratorNodeHead)
+ };
+
+ wxStringIteratorNodeHead m_iterators;
+
+ friend class WXDLLIMPEXP_FWD_BASE wxStringIteratorNode;
+ friend class WXDLLIMPEXP_FWD_BASE wxUniCharRef;
+#endif // wxUSE_UNICODE_UTF8
+
+ friend class WXDLLIMPEXP_FWD_BASE wxCStrData;
+ friend class wxStringInternalBuffer;
+ friend class wxStringInternalBufferLength;