-// ---------------------------------------------------------------------------
-// standard C++ library string functions
-// ---------------------------------------------------------------------------
-
-#ifdef wxSTD_STRING_COMPATIBILITY
-
-void wxString::resize(size_t nSize, wxChar ch)
-{
- size_t len = length();
-
- if ( nSize < len )
- {
- Truncate(nSize);
- }
- else if ( nSize > len )
- {
- *this += wxString(ch, nSize - len);
- }
- //else: we have exactly the specified length, nothing to do
-}
-
-void wxString::swap(wxString& str)
-{
- // this is slightly less efficient than fiddling with m_pchData directly,
- // but it is still quite efficient as we don't copy the string here because
- // ref count always stays positive
- wxString tmp = str;
- str = *this;
- *this = str;
-}
-
-wxString& wxString::insert(size_t nPos, const wxString& str)
-{
- wxASSERT( str.GetStringData()->IsValid() );
- wxASSERT( nPos <= Len() );
-
- if ( !str.IsEmpty() ) {
- wxString strTmp;
- wxChar *pc = strTmp.GetWriteBuf(Len() + str.Len());
- wxStrncpy(pc, c_str(), nPos);
- wxStrcpy(pc + nPos, str);
- wxStrcpy(pc + nPos + str.Len(), c_str() + nPos);
- strTmp.UngetWriteBuf();
- *this = strTmp;
- }
-
- return *this;
-}
-
-size_t wxString::find(const wxString& str, size_t nStart) const
-{
- wxASSERT( str.GetStringData()->IsValid() );
- wxASSERT( nStart <= Len() );
-
- const wxChar *p = wxStrstr(c_str() + nStart, str);
-
- return p == NULL ? npos : p - c_str();
-}
-
-// VC++ 1.5 can't cope with the default argument in the header.
-#if !defined(__VISUALC__) || defined(__WIN32__)
-size_t wxString::find(const wxChar* sz, size_t nStart, size_t n) const
-{
- return find(wxString(sz, n), nStart);
-}
-#endif // VC++ 1.5
-
-// Gives a duplicate symbol (presumably a case-insensitivity problem)
-#if !defined(__BORLANDC__)
-size_t wxString::find(wxChar ch, size_t nStart) const
-{
- wxASSERT( nStart <= Len() );
-
- const wxChar *p = wxStrchr(c_str() + nStart, ch);
-
- return p == NULL ? npos : p - c_str();
-}
-#endif
-
-size_t wxString::rfind(const wxString& str, size_t nStart) const
-{
- wxASSERT( str.GetStringData()->IsValid() );
- wxASSERT( nStart == npos || nStart <= Len() );
-
- // TODO could be made much quicker than that
- const wxChar *p = c_str() + (nStart == npos ? Len() : nStart);
- while ( p >= c_str() + str.Len() ) {
- if ( wxStrncmp(p - str.Len(), str, str.Len()) == 0 )
- return p - str.Len() - c_str();
- p--;
- }
-
- return npos;
-}
-
-// VC++ 1.5 can't cope with the default argument in the header.
-#if !defined(__VISUALC__) || defined(__WIN32__)
-size_t wxString::rfind(const wxChar* sz, size_t nStart, size_t n) const
-{
- return rfind(wxString(sz, n == npos ? wxSTRING_MAXLEN : n), nStart);
-}
-
-size_t wxString::rfind(wxChar ch, size_t nStart) const
-{
- if ( nStart == npos )
- {
- nStart = Len();
- }
- else
- {
- wxASSERT( nStart <= Len() );
- }
-
- const wxChar *p = wxStrrchr(c_str(), ch);
-
- if ( p == NULL )
- return npos;
-
- size_t result = p - c_str();
- return ( result > nStart ) ? npos : result;
-}
-#endif // VC++ 1.5
-
-size_t wxString::find_first_of(const wxChar* sz, size_t nStart) const
-{
- const wxChar *start = c_str() + nStart;
- const wxChar *firstOf = wxStrpbrk(start, sz);
- if ( firstOf )
- return firstOf - c_str();
- else
- return npos;
-}
-
-size_t wxString::find_last_of(const wxChar* sz, size_t nStart) const
-{
- if ( nStart == npos )
- {
- nStart = Len();
- }
- else
- {
- wxASSERT( nStart <= Len() );
- }
-
- for ( const wxChar *p = c_str() + length() - 1; p >= c_str(); p-- )
- {
- if ( wxStrchr(sz, *p) )
- return p - c_str();
- }
-
- return npos;
-}
-
-size_t wxString::find_first_not_of(const wxChar* sz, size_t nStart) const
-{
- if ( nStart == npos )
- {
- nStart = Len();
- }
- else
- {
- wxASSERT( nStart <= Len() );
- }
-
- size_t nAccept = wxStrspn(c_str() + nStart, sz);
- if ( nAccept >= length() - nStart )
- return npos;
- else
- return nAccept;
-}
-
-size_t wxString::find_first_not_of(wxChar ch, size_t nStart) const
-{
- wxASSERT( nStart <= Len() );
-
- for ( const wxChar *p = c_str() + nStart; *p; p++ )
- {
- if ( *p != ch )
- return p - c_str();
- }
-
- return npos;
-}
-
-size_t wxString::find_last_not_of(const wxChar* sz, size_t nStart) const
-{
- if ( nStart == npos )
- {
- nStart = Len();
- }
- else
- {
- wxASSERT( nStart <= Len() );
- }
-
- for ( const wxChar *p = c_str() + nStart - 1; p >= c_str(); p-- )
- {
- if ( !wxStrchr(sz, *p) )
- return p - c_str();
- }
-
- return npos;
-}
-
-size_t wxString::find_last_not_of(wxChar ch, size_t nStart) const
-{
- if ( nStart == npos )
- {
- nStart = Len();
- }
- else
- {
- wxASSERT( nStart <= Len() );
- }
-
- for ( const wxChar *p = c_str() + nStart - 1; p >= c_str(); p-- )
- {
- if ( *p != ch )
- return p - c_str();
- }
-
- return npos;
-}
-
-wxString& wxString::erase(size_t nStart, size_t nLen)
-{
- wxString strTmp(c_str(), nStart);
- if ( nLen != npos ) {
- wxASSERT( nStart + nLen <= Len() );
-
- strTmp.append(c_str() + nStart + nLen);
- }
-
- *this = strTmp;
- return *this;
-}
-
-wxString& wxString::replace(size_t nStart, size_t nLen, const wxChar *sz)
-{
- wxASSERT_MSG( nStart + nLen <= Len(),
- _T("index out of bounds in wxString::replace") );
-
- wxString strTmp;
- strTmp.Alloc(Len()); // micro optimisation to avoid multiple mem allocs
-
- if ( nStart != 0 )
- strTmp.append(c_str(), nStart);
- strTmp << sz << c_str() + nStart + nLen;
-
- *this = strTmp;
- return *this;
-}
-
-wxString& wxString::replace(size_t nStart, size_t nLen, size_t nCount, wxChar ch)
-{
- return replace(nStart, nLen, wxString(ch, nCount));
-}
-
-wxString& wxString::replace(size_t nStart, size_t nLen,
- const wxString& str, size_t nStart2, size_t nLen2)
-{
- return replace(nStart, nLen, str.substr(nStart2, nLen2));
-}
-
-wxString& wxString::replace(size_t nStart, size_t nLen,
- const wxChar* sz, size_t nCount)
-{
- return replace(nStart, nLen, wxString(sz, nCount));
-}
-
-#endif //std::string compatibility
-