// Created: 29/01/98
// RCS-ID: $Id$
// Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
-// Licence: wxWindows license
+// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
-#ifdef __WINE__
-#include <search.h>
-#endif
#ifdef __SALFORDC__
#include <clib.h>
} 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
#define STATISTICS_ADD(av, val)
#endif // WXSTRING_STATISTICS
+// ===========================================================================
+// 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
// ===========================================================================
size_t nLen;
if ( psz )
{
- // calculate the needed size ourselves or use a provide one
+ // calculate the needed size ourselves or use the provided one
nLen = nLength == wxSTRING_MAXLEN ? conv.MB2WC(NULL, psz, 0) : nLength;
}
else
if ( !AllocBuffer(nLen) )
{
wxFAIL_MSG( _T("out of memory in wxString::wxString") );
- return;
}
-
- // MB2WC wants the buffer size, not the string length
- if ( conv.MB2WC(m_pchData, psz, nLen + 1) != (size_t)-1 )
+ else
{
- // initialized ok
- return;
+ // MB2WC wants the buffer size, not the string length hence +1
+ nLen = conv.MB2WC(m_pchData, psz, nLen + 1);
+
+ if ( nLen != (size_t)-1 )
+ {
+ // initialized ok, set the real length as nLength specified by
+ // the caller could be greater than the real string length
+ GetStringData()->nDataLength = nLen;
+ m_pchData[nLen] = 0;
+ return;
+ }
+ //else: the conversion failed -- leave the string empty (what else?)
}
- //else: the conversion failed -- leave the string empty (what else?)
}
Init();
size_t nLen;
if ( pwz )
{
- // calculate the needed size ourselves or use a provide one
+ // calculate the needed size ourselves or use the provided one
nLen = nLength == wxSTRING_MAXLEN ? conv.WC2MB(NULL, pwz, 0) : nLength;
}
else
if ( !AllocBuffer(nLen) )
{
wxFAIL_MSG( _T("out of memory in wxString::wxString") );
- return;
}
-
- // WC2MB wants the buffer size, not the string length
- if ( conv.WC2MB(m_pchData, pwz, nLen + 1) != (size_t)-1 )
+ else
{
- // initialized ok
- return;
+ // WC2MB wants the buffer size, not the string length
+ if ( conv.WC2MB(m_pchData, pwz, nLen + 1) != (size_t)-1 )
+ {
+ // initialized ok
+ return;
+ }
+ //else: the conversion failed -- leave the string empty (what else?)
}
- //else: the conversion failed -- leave the string empty (what else?)
}
Init();
// ---------------------------------------------------------------------------
// add something to this string
-bool wxString::ConcatSelf(int nSrcLen, const wxChar *pszSrcData)
+bool wxString::ConcatSelf(size_t nSrcLen, const wxChar *pszSrcData)
{
STATISTICS_ADD(SummandLength, nSrcLen);
wxString res;
res += (wchar_t)(unsigned char) ascii;
-
+
return res;
}
}
// 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);
// ArrayString
// ============================================================================
+#include "wx/arrstr.h"
+
+#if !wxUSE_STL
+
// size increment = min(50% of current size, ARRAY_MAXSIZE_INCREMENT)
#define ARRAY_MAXSIZE_INCREMENT 4096
}
}
+#if WXWIN_COMPATIBILITY_2_4
+
// return a wxString[] as required for some control ctors.
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
{
}
// 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,
wxCHECK_RET( iIndex != wxNOT_FOUND,
wxT("removing inexistent element in wxArrayString::Remove") );
- Remove(iIndex);
+ RemoveAt(iIndex);
}
// ----------------------------------------------------------------------------
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()
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());
+}