// static class variables definition
// ---------------------------------------------------------------------------
-#if !wxUSE_STL
+#if !wxUSE_STL_BASED_WXSTRING
//According to STL _must_ be a -1 size_t
const size_t wxStringBase::npos = (size_t) -1;
#endif
// static data
// ----------------------------------------------------------------------------
-#if wxUSE_STL
+#if wxUSE_STL_BASED_WXSTRING
extern const wxChar WXDLLIMPEXP_BASE *wxEmptyString = _T("");
#define STATISTICS_ADD(av, val)
#endif // WXSTRING_STATISTICS
-#if !wxUSE_STL
+#if !wxUSE_STL_BASED_WXSTRING
// ===========================================================================
// wxStringData class deallocation
return true;
}
-#endif // !wxUSE_STL
+#endif // !wxUSE_STL_BASED_WXSTRING
-#if !wxUSE_STL || !defined(HAVE_STD_STRING_COMPARE)
+#if !wxUSE_STL_BASED_WXSTRING || !defined(HAVE_STD_STRING_COMPARE)
-#if !wxUSE_STL
+#if !wxUSE_STL_BASED_WXSTRING
#define STRINGCLASS wxStringBase
#else
#define STRINGCLASS wxString
#undef STRINGCLASS
-#endif // !wxUSE_STL || !defined(HAVE_STD_STRING_COMPARE)
+#endif // !wxUSE_STL_BASED_WXSTRING || !defined(HAVE_STD_STRING_COMPARE)
// ===========================================================================
// wxString class core
return tmp.length() == length();
}
-#if !wxUSE_STL
+#if !wxUSE_STL_BASED_WXSTRING
// get the pointer to writable buffer of (at least) nLen bytes
wxChar *wxString::DoGetWriteBuf(size_t nLen)
{
}
#endif // WXWIN_COMPATIBILITY_2_8
-#endif // !wxUSE_STL
+#endif // !wxUSE_STL_BASED_WXSTRING
// ---------------------------------------------------------------------------
wxString operator+(const wxString& str1, const wxString& str2)
{
-#if !wxUSE_STL
+#if !wxUSE_STL_BASED_WXSTRING
wxASSERT( str1.GetStringData()->IsValid() );
wxASSERT( str2.GetStringData()->IsValid() );
#endif
wxString operator+(const wxString& str, wxUniChar ch)
{
-#if !wxUSE_STL
+#if !wxUSE_STL_BASED_WXSTRING
wxASSERT( str.GetStringData()->IsValid() );
#endif
wxString operator+(wxUniChar ch, const wxString& str)
{
-#if !wxUSE_STL
+#if !wxUSE_STL_BASED_WXSTRING
wxASSERT( str.GetStringData()->IsValid() );
#endif
wxString operator+(const wxString& str, const wxChar *psz)
{
-#if !wxUSE_STL
+#if !wxUSE_STL_BASED_WXSTRING
wxASSERT( str.GetStringData()->IsValid() );
#endif
wxString operator+(const wxChar *psz, const wxString& str)
{
-#if !wxUSE_STL
+#if !wxUSE_STL_BASED_WXSTRING
wxASSERT( str.GetStringData()->IsValid() );
#endif
{
return -s1->Cmp(*s2);
}
+
+
+
+// ===========================================================================
+// wxJoin and wxSplit
+// ===========================================================================
+
+#include "wx/tokenzr.h"
+
+wxString wxJoin(const wxArrayString& arr, const wxChar sep, const wxChar escape)
+{
+ size_t count = arr.size();
+ if ( count == 0 )
+ return wxEmptyString;
+
+ wxString str;
+
+ // pre-allocate memory using the estimation of the average length of the
+ // strings in the given array: this is very imprecise, of course, but
+ // better than nothing
+ str.reserve(count*(arr[0].length() + arr[count-1].length()) / 2);
+
+ if ( escape == wxT('\0') )
+ {
+ // escaping is disabled:
+ for ( size_t i = 0; i < count; i++ )
+ {
+ if ( i )
+ str += sep;
+ str += arr[i];
+ }
+ }
+ else // use escape character
+ {
+ for ( size_t n = 0; n < count; n++ )
+ {
+ if ( n )
+ str += sep;
+
+ for ( wxString::const_iterator i = arr[n].begin(),
+ end = arr[n].end();
+ i != end;
+ ++i )
+ {
+ const wxChar ch = *i;
+ if ( ch == sep )
+ str += escape; // escape this separator
+ str += ch;
+ }
+ }
+ }
+
+ str.Shrink(); // release extra memory if we allocated too much
+ return str;
+}
+
+wxArrayString wxSplit(const wxString& str, const wxChar sep, const wxChar escape)
+{
+ if ( escape == wxT('\0') )
+ {
+ // simple case: we don't need to honour the escape character
+ return wxStringTokenize(str, sep, wxTOKEN_RET_EMPTY_ALL);
+ }
+
+ wxArrayString ret;
+ wxString curr;
+ wxChar prev = wxT('\0');
+
+ for ( wxString::const_iterator i = str.begin(),
+ end = str.end();
+ i != end;
+ ++i )
+ {
+ const wxChar ch = *i;
+
+ if ( ch == sep )
+ {
+ if ( prev == escape )
+ {
+ // remove the escape character and don't consider this
+ // occurrence of 'sep' as a real separator
+ *curr.rbegin() = sep;
+ }
+ else // real separator
+ {
+ ret.push_back(curr);
+ curr.clear();
+ }
+ }
+ else // normal character
+ {
+ curr += ch;
+ }
+
+ prev = ch;
+ }
+
+ // add the last token
+ if ( !curr.empty() || prev == sep )
+ ret.Add(curr);
+
+ return ret;
+}