- }
-}
-
-int wxString::compare(const wxString& str) const
-{
- return ::wxDoCmp(m_impl.data(), m_impl.length(),
- str.m_impl.data(), str.m_impl.length());
-}
-
-int wxString::compare(size_t nStart, size_t nLen,
- const wxString& str) const
-{
- wxASSERT(nStart <= length());
- size_type strLen = length() - nStart;
- nLen = strLen < nLen ? strLen : nLen;
-
- size_t pos, len;
- PosLenToImpl(nStart, nLen, &pos, &len);
-
- return ::wxDoCmp(m_impl.data() + pos, len,
- str.m_impl.data(), str.m_impl.length());
-}
-
-int wxString::compare(size_t nStart, size_t nLen,
- const wxString& str,
- size_t nStart2, size_t nLen2) const
-{
- wxASSERT(nStart <= length());
- wxASSERT(nStart2 <= str.length());
- size_type strLen = length() - nStart,
- strLen2 = str.length() - nStart2;
- nLen = strLen < nLen ? strLen : nLen;
- nLen2 = strLen2 < nLen2 ? strLen2 : nLen2;
-
- size_t pos, len;
- PosLenToImpl(nStart, nLen, &pos, &len);
- size_t pos2, len2;
- str.PosLenToImpl(nStart2, nLen2, &pos2, &len2);
-
- return ::wxDoCmp(m_impl.data() + pos, len,
- str.m_impl.data() + pos2, len2);
-}
-
-int wxString::compare(const char* sz) const
-{
- SubstrBufFromMB str(ImplStr(sz, npos));
- if ( str.len == npos )
- str.len = wxStringStrlen(str.data);
- return ::wxDoCmp(m_impl.data(), m_impl.length(), str.data, str.len);
-}
-
-int wxString::compare(const wchar_t* sz) const
-{
- SubstrBufFromWC str(ImplStr(sz, npos));
- if ( str.len == npos )
- str.len = wxStringStrlen(str.data);
- return ::wxDoCmp(m_impl.data(), m_impl.length(), str.data, str.len);
-}
-
-int wxString::compare(size_t nStart, size_t nLen,
- const char* sz, size_t nCount) const
-{
- wxASSERT(nStart <= length());
- size_type strLen = length() - nStart;
- nLen = strLen < nLen ? strLen : nLen;
-
- size_t pos, len;
- PosLenToImpl(nStart, nLen, &pos, &len);
-
- SubstrBufFromMB str(ImplStr(sz, nCount));
- if ( str.len == npos )
- str.len = wxStringStrlen(str.data);
-
- return ::wxDoCmp(m_impl.data() + pos, len, str.data, str.len);
-}
-
-int wxString::compare(size_t nStart, size_t nLen,
- const wchar_t* sz, size_t nCount) const
-{
- wxASSERT(nStart <= length());
- size_type strLen = length() - nStart;
- nLen = strLen < nLen ? strLen : nLen;
-
- size_t pos, len;
- PosLenToImpl(nStart, nLen, &pos, &len);
-
- SubstrBufFromWC str(ImplStr(sz, nCount));
- if ( str.len == npos )
- str.len = wxStringStrlen(str.data);
-
- return ::wxDoCmp(m_impl.data() + pos, len, str.data, str.len);
-}
-
-#endif // HAVE_STD_STRING_COMPARE/!HAVE_STD_STRING_COMPARE
-
-// ===========================================================================
-// wxString class core
-// ===========================================================================
-
-// ---------------------------------------------------------------------------
-// construction and conversion
-// ---------------------------------------------------------------------------
-
-#if wxUSE_UNICODE
-/* static */
-wxString::SubstrBufFromMB wxString::ConvertStr(const char *psz, size_t nLength,
- const wxMBConv& conv)
-{
- // anything to do?
- if ( !psz || nLength == 0 )
- return SubstrBufFromMB();
-
- if ( nLength == npos )
- nLength = wxNO_LEN;
-
- size_t wcLen;
- wxWCharBuffer wcBuf(conv.cMB2WC(psz, nLength, &wcLen));
- if ( !wcLen )
- return SubstrBufFromMB();
- else
- return SubstrBufFromMB(wcBuf, wcLen);
-}
-#else
-/* static */
-wxString::SubstrBufFromWC wxString::ConvertStr(const wchar_t *pwz, size_t nLength,
- const wxMBConv& conv)
-{
- // anything to do?
- if ( !pwz || nLength == 0 )
- return SubstrBufFromWC();
-
- if ( nLength == npos )
- nLength = wxNO_LEN;
-
- size_t mbLen;
- wxCharBuffer mbBuf(conv.cWC2MB(pwz, nLength, &mbLen));
- if ( !mbLen )
- return SubstrBufFromWC();
- else
- return SubstrBufFromWC(mbBuf, mbLen);
-}
-#endif
-
-
-#if wxUSE_UNICODE
-
-// from multibyte string
-wxString::wxString(const char *psz, const wxMBConv& conv, size_t nLength)
-{
- // FIXME-UTF8: this will need changes
-
- // anything to do?
- if ( psz && nLength != 0 )
- {
- if ( nLength == npos )
- {
- nLength = wxNO_LEN;
- }
-
- size_t nLenWide;
- wxWCharBuffer wbuf = conv.cMB2WC(psz, nLength, &nLenWide);
-
- if ( nLenWide )
- assign(wbuf, nLenWide);
- }
-}
-
-wxString::wxString(const char *psz, size_t nLength)
-{
- assign(psz, nLength);
-}
-
-//Convert wxString in Unicode mode to a multi-byte string
-const wxCharBuffer wxString::mb_str(const wxMBConv& conv) const
-{
- return conv.cWC2MB(c_str(), length() + 1 /* size, not length */, NULL);
-}
-
-#else // ANSI
-
-#if wxUSE_WCHAR_T
-
-// from wide string
-wxString::wxString(const wchar_t *pwz, const wxMBConv& conv, size_t nLength)
-{
- // FIXME-UTF8: this will need changes
-
- // anything to do?
- if ( pwz && nLength != 0 )
- {
- if ( nLength == npos )
- {
- nLength = wxNO_LEN;
- }
-
- size_t nLenMB;
- wxCharBuffer buf = conv.cWC2MB(pwz, nLength, &nLenMB);
-
- if ( nLenMB )
- assign(buf, nLenMB);
- }
-
-}
-
-wxString::wxString(const wchar_t *pwz, size_t nLength)
-{
- assign(pwz, nLength);
-}
-
-//Converts this string to a wide character string if unicode
-//mode is not enabled and wxUSE_WCHAR_T is enabled
-const wxWCharBuffer wxString::wc_str(const wxMBConv& conv) const
-{
- return conv.cMB2WC(c_str(), length() + 1 /* size, not length */, NULL);
-}
-
-#endif // wxUSE_WCHAR_T
-
-#endif // Unicode/ANSI
-
-// shrink to minimal size (releasing extra memory)
-bool wxString::Shrink()
-{
- wxString tmp(begin(), end());
- swap(tmp);
- return tmp.length() == length();
-}
-
-#if !wxUSE_STL_BASED_WXSTRING && !wxUSE_UNICODE_UTF8
-// get the pointer to writable buffer of (at least) nLen bytes
-wxChar *wxStringImpl::DoGetWriteBuf(size_t nLen)
-{
- if ( !AllocBeforeWrite(nLen) ) {
- // allocation failure handled by caller
- return NULL;
- }
-
- wxASSERT( GetStringData()->nRefs == 1 );
- GetStringData()->Validate(false);
-
- return m_pchData;
-}
-
-// put string back in a reasonable state after GetWriteBuf
-void wxStringImpl::DoUngetWriteBuf()
-{
- DoUngetWriteBuf(wxStrlen(m_pchData));
-}
-
-void wxStringImpl::DoUngetWriteBuf(size_t nLen)
-{
- wxStringData * const pData = GetStringData();
-
- wxASSERT_MSG( nLen < pData->nAllocLength, _T("buffer overrun") );
-
- // the strings we store are always NUL-terminated
- pData->data()[nLen] = _T('\0');
- pData->nDataLength = nLen;
- pData->Validate(true);
-}
-
-// deprecated compatibility code:
-#if WXWIN_COMPATIBILITY_2_8
-wxChar *wxString::GetWriteBuf(size_t nLen)
-{
- return DoGetWriteBuf(nLen);
-}
-
-void wxString::UngetWriteBuf()
-{
- DoUngetWriteBuf();
-}
-
-void wxString::UngetWriteBuf(size_t nLen)
-{
- DoUngetWriteBuf(nLen);
-}
-#endif // WXWIN_COMPATIBILITY_2_8
-
-#endif // !wxUSE_STL_BASED_WXSTRING && !wxUSE_UNICODE_UTF8
-
-
-// ---------------------------------------------------------------------------
-// data access
-// ---------------------------------------------------------------------------
-
-// all functions are inline in string.h
-
-// ---------------------------------------------------------------------------
-// assignment operators
-// ---------------------------------------------------------------------------
-
-#if !wxUSE_UNICODE
-
-// same as 'signed char' variant
-wxString& wxString::operator=(const unsigned char* psz)
-{
- *this = (const char *)psz;
- return *this;