X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/c95e653ca42e6474c32d71e69a3fd8a2bc443fc4..ecdc118383f458bd7e684ab631f6e5d23cc6d251:/src/common/string.cpp diff --git a/src/common/string.cpp b/src/common/string.cpp index f413b031fd..c3bc9331cb 100644 --- a/src/common/string.cpp +++ b/src/common/string.cpp @@ -35,10 +35,6 @@ #include #include -#ifdef __SALFORDC__ - #include -#endif - #include "wx/hashmap.h" // string handling functions used by wxString: @@ -373,6 +369,9 @@ wxString::SubstrBufFromMB wxString::ConvertStr(const char *psz, size_t nLength, // UTF-8 sequence and psz may be invalid: if ( wxStringOperations::IsValidUtf8String(psz, nLength) ) { + // we must pass the real string length to SubstrBufFromMB ctor + if ( nLength == npos ) + nLength = psz ? strlen(psz) : 0; return SubstrBufFromMB(wxCharBuffer::CreateNonOwned(psz), nLength); } // else: do the roundtrip through wchar_t* @@ -1240,34 +1239,27 @@ size_t wxString::Replace(const wxString& strOld, size_t uiCount = 0; // count of replacements made - size_t uiOldLen = strOld.length(); - size_t uiNewLen = strNew.length(); - - size_t dwPos = 0; + const size_t uiOldLen = strOld.m_impl.length(); + const size_t uiNewLen = strNew.m_impl.length(); - while ( (*this)[dwPos] != wxT('\0') ) + for ( size_t dwPos = 0; dwPos < m_impl.length(); ) { - //DO NOT USE STRSTR HERE - //this string can contain embedded null characters, - //so strstr will function incorrectly - dwPos = find(strOld, dwPos); + dwPos = m_impl.find(strOld.m_impl, dwPos); if ( dwPos == npos ) - break; // exit the loop - else - { - //replace this occurance of the old string with the new one - replace(dwPos, uiOldLen, strNew, uiNewLen); + break; - //move up pos past the string that was replaced - dwPos += uiNewLen; + // replace this occurance of the old string with the new one + m_impl.replace(dwPos, uiOldLen, strNew.m_impl); - //increase replace count - ++uiCount; + // move up pos past the string that was replaced + dwPos += uiNewLen; - // stop now? - if ( !bReplaceAll ) - break; // exit the loop - } + // increase replace count + ++uiCount; + + // stop after the first one? + if ( !bReplaceAll ) + break; } return uiCount;