X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/ca5e07c7683a6b4c63dc6d4d05c75ba46d0b0de8..3bb63e5c806e7ef549673822dc6e4d40aa9dbec9:/src/common/string.cpp diff --git a/src/common/string.cpp b/src/common/string.cpp index d0b3facc6b..42863abaa8 100644 --- a/src/common/string.cpp +++ b/src/common/string.cpp @@ -79,7 +79,7 @@ static const struct } g_strEmpty = { {-1, 0, 0}, wxT('\0') }; // empty C style string: points to 'string data' byte of g_strEmpty -extern const wxChar WXDLLEXPORT *wxEmptyString = &g_strEmpty.dummy; +extern const wxChar WXDLLIMPEXP_BASE *wxEmptyString = &g_strEmpty.dummy; // ---------------------------------------------------------------------------- // global functions @@ -164,10 +164,13 @@ wxSTD ostream& operator<<(wxSTD ostream& os, const wxString& str) // wxStringData class deallocation // =========================================================================== +#if defined(__VISUALC__) && defined(_MT) && !defined(_DLL) +# pragma message (__FILE__ ": building with Multithreaded non DLL runtime has a performance impact on wxString!") void wxStringData::Free() { free(this); } +#endif // =========================================================================== // wxString class core @@ -264,6 +267,7 @@ wxString::wxString(const char *psz, wxMBConv& conv, size_t nLength) if ( conv.MB2WC(m_pchData, psz, nLen + 1) != (size_t)-1 ) { // initialized ok + m_pchData[nLen] = 0; return; } //else: the conversion failed -- leave the string empty (what else?) @@ -770,7 +774,7 @@ wxString wxString::FromAscii(const char ascii) wxString res; res += (wchar_t)(unsigned char) ascii; - + return res; } @@ -954,8 +958,13 @@ wxString wxString::AfterFirst(wxChar ch) const } // replace first (or all) occurences of some substring with another one -size_t wxString::Replace(const wxChar *szOld, const wxChar *szNew, bool bReplaceAll) +size_t +wxString::Replace(const wxChar *szOld, const wxChar *szNew, bool bReplaceAll) { + // if we tried to replace an empty string we'd enter an infinite loop below + wxCHECK_MSG( szOld && *szOld && szNew, 0, + _T("wxString::Replace(): invalid parameter") ); + size_t uiCount = 0; // count of replacements made size_t uiOldLen = wxStrlen(szOld); @@ -1744,6 +1753,10 @@ wxString& wxString::replace(size_t nStart, size_t nLen, // ArrayString // ============================================================================ +#if !wxUSE_STL + +#include "wx/arrstr.h" + // size increment = min(50% of current size, ARRAY_MAXSIZE_INCREMENT) #define ARRAY_MAXSIZE_INCREMENT 4096 @@ -1897,6 +1910,8 @@ void wxArrayString::Shrink() } } +#if WXWIN_COMPATIBILITY_2_4 + // return a wxString[] as required for some control ctors. wxString* wxArrayString::GetStringArray() const { @@ -1912,6 +1927,8 @@ wxString* wxArrayString::GetStringArray() const return array; } +#endif // WXWIN_COMPATIBILITY_2_4 + // searches the array for an item (forward or backwards) int wxArrayString::Index(const wxChar *sz, bool bCase, bool bFromEnd) const { @@ -2042,7 +2059,7 @@ void wxArrayString::SetCount(size_t count) } // removes item from array (by index) -void wxArrayString::Remove(size_t nIndex, size_t nRemove) +void wxArrayString::RemoveAt(size_t nIndex, size_t nRemove) { wxCHECK_RET( nIndex < m_nCount, wxT("bad index in wxArrayString::Remove") ); wxCHECK_RET( nIndex + nRemove <= m_nCount, @@ -2065,7 +2082,7 @@ void wxArrayString::Remove(const wxChar *sz) wxCHECK_RET( iIndex != wxNOT_FOUND, wxT("removing inexistent element in wxArrayString::Remove") ); - Remove(iIndex); + RemoveAt(iIndex); } // ---------------------------------------------------------------------------- @@ -2133,16 +2150,16 @@ void wxArrayString::Sort(CompareFunction compareFunction) END_SORT(); } -void wxArrayString::Sort(bool reverseOrder) -{ - START_SORT(); - - wxASSERT( !gs_compareFunction ); // must have been reset to NULL - gs_sortAscending = !reverseOrder; +typedef int (wxC_CALLING_CONV * wxStringCompareFn)(const void *first, const void *second); - DoSort(); +void wxArrayString::Sort(CompareFunction2 compareFunction) +{ + qsort(m_pItems, m_nCount, sizeof(wxChar *), (wxStringCompareFn)compareFunction); +} - END_SORT(); +void wxArrayString::Sort(bool reverseOrder) +{ + Sort(reverseOrder ? wxStringSortDescending : wxStringSortAscending); } void wxArrayString::DoSort() @@ -2168,3 +2185,14 @@ bool wxArrayString::operator==(const wxArrayString& a) const return TRUE; } +#endif // !wxUSE_STL + +int wxStringSortAscending(wxString* s1, wxString* s2) +{ + return wxStrcmp(s1->c_str(), s2->c_str()); +} + +int wxStringSortDescending(wxString* s1, wxString* s2) +{ + return -wxStrcmp(s1->c_str(), s2->c_str()); +}