1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxString class
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "string.h"
18 * 1) all empty strings use g_strEmpty, nRefs = -1 (set in Init())
19 * 2) AllocBuffer() sets nRefs to 1, Lock() increments it by one
20 * 3) Unlock() decrements nRefs and frees memory if it goes to 0
23 // ===========================================================================
24 // headers, declarations, constants
25 // ===========================================================================
27 // For compilers that support precompilation, includes "wx.h".
28 #include "wx/wxprec.h"
36 #include "wx/string.h"
39 #include <wx/thread.h>
52 #include <wchar.h> // for wcsrtombs(), see comments where it's used
55 #ifdef WXSTRING_IS_WXOBJECT
56 IMPLEMENT_DYNAMIC_CLASS(wxString
, wxObject
)
57 #endif //WXSTRING_IS_WXOBJECT
60 #undef wxUSE_EXPERIMENTAL_PRINTF
61 #define wxUSE_EXPERIMENTAL_PRINTF 1
64 // allocating extra space for each string consumes more memory but speeds up
65 // the concatenation operations (nLen is the current string's length)
66 // NB: EXTRA_ALLOC must be >= 0!
67 #define EXTRA_ALLOC (19 - nLen % 16)
69 // ---------------------------------------------------------------------------
70 // static class variables definition
71 // ---------------------------------------------------------------------------
73 #ifdef wxSTD_STRING_COMPATIBILITY
74 const size_t wxString::npos
= wxSTRING_MAXLEN
;
75 #endif // wxSTD_STRING_COMPATIBILITY
77 // ----------------------------------------------------------------------------
79 // ----------------------------------------------------------------------------
81 // for an empty string, GetStringData() will return this address: this
82 // structure has the same layout as wxStringData and it's data() method will
83 // return the empty string (dummy pointer)
88 } g_strEmpty
= { {-1, 0, 0}, wxT('\0') };
90 // empty C style string: points to 'string data' byte of g_strEmpty
91 extern const wxChar WXDLLEXPORT
*wxEmptyString
= &g_strEmpty
.dummy
;
93 // ----------------------------------------------------------------------------
94 // conditional compilation
95 // ----------------------------------------------------------------------------
97 #if !defined(__WXSW__) && wxUSE_UNICODE
98 #ifdef wxUSE_EXPERIMENTAL_PRINTF
99 #undef wxUSE_EXPERIMENTAL_PRINTF
101 #define wxUSE_EXPERIMENTAL_PRINTF 1
104 // we want to find out if the current platform supports vsnprintf()-like
105 // function: for Unix this is done with configure, for Windows we test the
106 // compiler explicitly.
109 #define wxVsnprintf _vsnprintf
112 #ifdef HAVE_VSNPRINTF
113 #define wxVsnprintf vsnprintf
115 #endif // Windows/!Windows
118 // in this case we'll use vsprintf() (which is ANSI and thus should be
119 // always available), but it's unsafe because it doesn't check for buffer
120 // size - so give a warning
121 #define wxVsnprintf(buffer,len,format,argptr) vsprintf(buffer,format, argptr)
123 #if defined(__VISUALC__)
124 #pragma message("Using sprintf() because no snprintf()-like function defined")
125 #elif defined(__GNUG__) && !defined(__UNIX__)
126 #warning "Using sprintf() because no snprintf()-like function defined"
127 #elif defined(__MWERKS__)
128 #warning "Using sprintf() because no snprintf()-like function defined"
130 #endif // no vsnprintf
133 // AIX has vsnprintf, but there's no prototype in the system headers.
134 extern "C" int vsnprintf(char* str
, size_t n
, const char* format
, va_list ap
);
137 // ----------------------------------------------------------------------------
139 // ----------------------------------------------------------------------------
141 #if defined(wxSTD_STRING_COMPATIBILITY) && wxUSE_STD_IOSTREAM
143 // MS Visual C++ version 5.0 provides the new STL headers as well as the old
146 // ATTN: you can _not_ use both of these in the same program!
148 istream
& operator>>(istream
& is
, wxString
& WXUNUSED(str
))
153 streambuf
*sb
= is
.rdbuf();
156 int ch
= sb
->sbumpc ();
158 is
.setstate(ios::eofbit
);
161 else if ( isspace(ch
) ) {
173 if ( str
.length() == 0 )
174 is
.setstate(ios::failbit
);
179 ostream
& operator<<(ostream
& os
, const wxString
& str
)
185 #endif //std::string compatibility
187 // ----------------------------------------------------------------------------
189 // ----------------------------------------------------------------------------
191 // this small class is used to gather statistics for performance tuning
192 //#define WXSTRING_STATISTICS
193 #ifdef WXSTRING_STATISTICS
197 Averager(const char *sz
) { m_sz
= sz
; m_nTotal
= m_nCount
= 0; }
199 { printf("wxString: average %s = %f\n", m_sz
, ((float)m_nTotal
)/m_nCount
); }
201 void Add(size_t n
) { m_nTotal
+= n
; m_nCount
++; }
204 size_t m_nCount
, m_nTotal
;
206 } g_averageLength("allocation size"),
207 g_averageSummandLength("summand length"),
208 g_averageConcatHit("hit probability in concat"),
209 g_averageInitialLength("initial string length");
211 #define STATISTICS_ADD(av, val) g_average##av.Add(val)
213 #define STATISTICS_ADD(av, val)
214 #endif // WXSTRING_STATISTICS
216 // ===========================================================================
217 // wxString class core
218 // ===========================================================================
220 // ---------------------------------------------------------------------------
222 // ---------------------------------------------------------------------------
224 // constructs string of <nLength> copies of character <ch>
225 wxString::wxString(wxChar ch
, size_t nLength
)
230 AllocBuffer(nLength
);
233 // memset only works on char
234 for (size_t n
=0; n
<nLength
; n
++) m_pchData
[n
] = ch
;
236 memset(m_pchData
, ch
, nLength
);
241 // takes nLength elements of psz starting at nPos
242 void wxString::InitWith(const wxChar
*psz
, size_t nPos
, size_t nLength
)
246 wxASSERT( nPos
<= wxStrlen(psz
) );
248 if ( nLength
== wxSTRING_MAXLEN
)
249 nLength
= wxStrlen(psz
+ nPos
);
251 STATISTICS_ADD(InitialLength
, nLength
);
254 // trailing '\0' is written in AllocBuffer()
255 AllocBuffer(nLength
);
256 memcpy(m_pchData
, psz
+ nPos
, nLength
*sizeof(wxChar
));
260 #ifdef wxSTD_STRING_COMPATIBILITY
262 // poor man's iterators are "void *" pointers
263 wxString::wxString(const void *pStart
, const void *pEnd
)
265 InitWith((const wxChar
*)pStart
, 0,
266 (const wxChar
*)pEnd
- (const wxChar
*)pStart
);
269 #endif //std::string compatibility
273 // from multibyte string
274 wxString::wxString(const char *psz
, wxMBConv
& conv
, size_t nLength
)
276 // first get necessary size
277 size_t nLen
= psz
? conv
.MB2WC((wchar_t *) NULL
, psz
, 0) : 0;
279 // nLength is number of *Unicode* characters here!
280 if ((nLen
!= (size_t)-1) && (nLen
> nLength
))
284 if ( (nLen
!= 0) && (nLen
!= (size_t)-1) ) {
286 conv
.MB2WC(m_pchData
, psz
, nLen
);
297 wxString::wxString(const wchar_t *pwz
)
299 // first get necessary size
300 size_t nLen
= pwz
? wxWC2MB((char *) NULL
, pwz
, 0) : 0;
303 if ( (nLen
!= 0) && (nLen
!= (size_t)-1) ) {
305 wxWC2MB(m_pchData
, pwz
, nLen
);
311 #endif // wxUSE_WCHAR_T
313 #endif // Unicode/ANSI
315 // ---------------------------------------------------------------------------
317 // ---------------------------------------------------------------------------
319 // allocates memory needed to store a C string of length nLen
320 void wxString::AllocBuffer(size_t nLen
)
322 wxASSERT( nLen
> 0 ); //
323 wxASSERT( nLen
<= INT_MAX
-1 ); // max size (enough room for 1 extra)
325 STATISTICS_ADD(Length
, nLen
);
328 // 1) one extra character for '\0' termination
329 // 2) sizeof(wxStringData) for housekeeping info
330 wxStringData
* pData
= (wxStringData
*)
331 malloc(sizeof(wxStringData
) + (nLen
+ EXTRA_ALLOC
+ 1)*sizeof(wxChar
));
333 pData
->nDataLength
= nLen
;
334 pData
->nAllocLength
= nLen
+ EXTRA_ALLOC
;
335 m_pchData
= pData
->data(); // data starts after wxStringData
336 m_pchData
[nLen
] = wxT('\0');
339 // must be called before changing this string
340 void wxString::CopyBeforeWrite()
342 wxStringData
* pData
= GetStringData();
344 if ( pData
->IsShared() ) {
345 pData
->Unlock(); // memory not freed because shared
346 size_t nLen
= pData
->nDataLength
;
348 memcpy(m_pchData
, pData
->data(), nLen
*sizeof(wxChar
));
351 wxASSERT( !GetStringData()->IsShared() ); // we must be the only owner
354 // must be called before replacing contents of this string
355 void wxString::AllocBeforeWrite(size_t nLen
)
357 wxASSERT( nLen
!= 0 ); // doesn't make any sense
359 // must not share string and must have enough space
360 wxStringData
* pData
= GetStringData();
361 if ( pData
->IsShared() || (nLen
> pData
->nAllocLength
) ) {
362 // can't work with old buffer, get new one
367 // update the string length
368 pData
->nDataLength
= nLen
;
371 wxASSERT( !GetStringData()->IsShared() ); // we must be the only owner
374 // allocate enough memory for nLen characters
375 void wxString::Alloc(size_t nLen
)
377 wxStringData
*pData
= GetStringData();
378 if ( pData
->nAllocLength
<= nLen
) {
379 if ( pData
->IsEmpty() ) {
382 wxStringData
* pData
= (wxStringData
*)
383 malloc(sizeof(wxStringData
) + (nLen
+ 1)*sizeof(wxChar
));
385 pData
->nDataLength
= 0;
386 pData
->nAllocLength
= nLen
;
387 m_pchData
= pData
->data(); // data starts after wxStringData
388 m_pchData
[0u] = wxT('\0');
390 else if ( pData
->IsShared() ) {
391 pData
->Unlock(); // memory not freed because shared
392 size_t nOldLen
= pData
->nDataLength
;
394 memcpy(m_pchData
, pData
->data(), nOldLen
*sizeof(wxChar
));
399 wxStringData
*p
= (wxStringData
*)
400 realloc(pData
, sizeof(wxStringData
) + (nLen
+ 1)*sizeof(wxChar
));
403 // @@@ what to do on memory error?
407 // it's not important if the pointer changed or not (the check for this
408 // is not faster than assigning to m_pchData in all cases)
409 p
->nAllocLength
= nLen
;
410 m_pchData
= p
->data();
413 //else: we've already got enough
416 // shrink to minimal size (releasing extra memory)
417 void wxString::Shrink()
419 wxStringData
*pData
= GetStringData();
421 // this variable is unused in release build, so avoid the compiler warning by
422 // just not declaring it
426 realloc(pData
, sizeof(wxStringData
) + (pData
->nDataLength
+ 1)*sizeof(wxChar
));
428 wxASSERT( p
!= NULL
); // can't free memory?
429 wxASSERT( p
== pData
); // we're decrementing the size - block shouldn't move!
432 // get the pointer to writable buffer of (at least) nLen bytes
433 wxChar
*wxString::GetWriteBuf(size_t nLen
)
435 AllocBeforeWrite(nLen
);
437 wxASSERT( GetStringData()->nRefs
== 1 );
438 GetStringData()->Validate(FALSE
);
443 // put string back in a reasonable state after GetWriteBuf
444 void wxString::UngetWriteBuf()
446 GetStringData()->nDataLength
= wxStrlen(m_pchData
);
447 GetStringData()->Validate(TRUE
);
450 // ---------------------------------------------------------------------------
452 // ---------------------------------------------------------------------------
454 // all functions are inline in string.h
456 // ---------------------------------------------------------------------------
457 // assignment operators
458 // ---------------------------------------------------------------------------
460 // helper function: does real copy
461 void wxString::AssignCopy(size_t nSrcLen
, const wxChar
*pszSrcData
)
463 if ( nSrcLen
== 0 ) {
467 AllocBeforeWrite(nSrcLen
);
468 memcpy(m_pchData
, pszSrcData
, nSrcLen
*sizeof(wxChar
));
469 GetStringData()->nDataLength
= nSrcLen
;
470 m_pchData
[nSrcLen
] = wxT('\0');
474 // assigns one string to another
475 wxString
& wxString::operator=(const wxString
& stringSrc
)
477 wxASSERT( stringSrc
.GetStringData()->IsValid() );
479 // don't copy string over itself
480 if ( m_pchData
!= stringSrc
.m_pchData
) {
481 if ( stringSrc
.GetStringData()->IsEmpty() ) {
486 GetStringData()->Unlock();
487 m_pchData
= stringSrc
.m_pchData
;
488 GetStringData()->Lock();
495 // assigns a single character
496 wxString
& wxString::operator=(wxChar ch
)
503 wxString
& wxString::operator=(const wxChar
*psz
)
505 AssignCopy(wxStrlen(psz
), psz
);
511 // same as 'signed char' variant
512 wxString
& wxString::operator=(const unsigned char* psz
)
514 *this = (const char *)psz
;
519 wxString
& wxString::operator=(const wchar_t *pwz
)
529 // ---------------------------------------------------------------------------
530 // string concatenation
531 // ---------------------------------------------------------------------------
533 // add something to this string
534 void wxString::ConcatSelf(int nSrcLen
, const wxChar
*pszSrcData
)
536 STATISTICS_ADD(SummandLength
, nSrcLen
);
538 // concatenating an empty string is a NOP
540 wxStringData
*pData
= GetStringData();
541 size_t nLen
= pData
->nDataLength
;
542 size_t nNewLen
= nLen
+ nSrcLen
;
544 // alloc new buffer if current is too small
545 if ( pData
->IsShared() ) {
546 STATISTICS_ADD(ConcatHit
, 0);
548 // we have to allocate another buffer
549 wxStringData
* pOldData
= GetStringData();
550 AllocBuffer(nNewLen
);
551 memcpy(m_pchData
, pOldData
->data(), nLen
*sizeof(wxChar
));
554 else if ( nNewLen
> pData
->nAllocLength
) {
555 STATISTICS_ADD(ConcatHit
, 0);
557 // we have to grow the buffer
561 STATISTICS_ADD(ConcatHit
, 1);
563 // the buffer is already big enough
566 // should be enough space
567 wxASSERT( nNewLen
<= GetStringData()->nAllocLength
);
569 // fast concatenation - all is done in our buffer
570 memcpy(m_pchData
+ nLen
, pszSrcData
, nSrcLen
*sizeof(wxChar
));
572 m_pchData
[nNewLen
] = wxT('\0'); // put terminating '\0'
573 GetStringData()->nDataLength
= nNewLen
; // and fix the length
575 //else: the string to append was empty
579 * concatenation functions come in 5 flavours:
581 * char + string and string + char
582 * C str + string and string + C str
585 wxString
operator+(const wxString
& string1
, const wxString
& string2
)
587 wxASSERT( string1
.GetStringData()->IsValid() );
588 wxASSERT( string2
.GetStringData()->IsValid() );
590 wxString s
= string1
;
596 wxString
operator+(const wxString
& string
, wxChar ch
)
598 wxASSERT( string
.GetStringData()->IsValid() );
606 wxString
operator+(wxChar ch
, const wxString
& string
)
608 wxASSERT( string
.GetStringData()->IsValid() );
616 wxString
operator+(const wxString
& string
, const wxChar
*psz
)
618 wxASSERT( string
.GetStringData()->IsValid() );
621 s
.Alloc(wxStrlen(psz
) + string
.Len());
628 wxString
operator+(const wxChar
*psz
, const wxString
& string
)
630 wxASSERT( string
.GetStringData()->IsValid() );
633 s
.Alloc(wxStrlen(psz
) + string
.Len());
640 // ===========================================================================
641 // other common string functions
642 // ===========================================================================
644 // ---------------------------------------------------------------------------
645 // simple sub-string extraction
646 // ---------------------------------------------------------------------------
648 // helper function: clone the data attached to this string
649 void wxString::AllocCopy(wxString
& dest
, int nCopyLen
, int nCopyIndex
) const
651 if ( nCopyLen
== 0 ) {
655 dest
.AllocBuffer(nCopyLen
);
656 memcpy(dest
.m_pchData
, m_pchData
+ nCopyIndex
, nCopyLen
*sizeof(wxChar
));
660 // extract string of length nCount starting at nFirst
661 wxString
wxString::Mid(size_t nFirst
, size_t nCount
) const
663 wxStringData
*pData
= GetStringData();
664 size_t nLen
= pData
->nDataLength
;
666 // default value of nCount is wxSTRING_MAXLEN and means "till the end"
667 if ( nCount
== wxSTRING_MAXLEN
)
669 nCount
= nLen
- nFirst
;
672 // out-of-bounds requests return sensible things
673 if ( nFirst
+ nCount
> nLen
)
675 nCount
= nLen
- nFirst
;
680 // AllocCopy() will return empty string
685 AllocCopy(dest
, nCount
, nFirst
);
690 // extract nCount last (rightmost) characters
691 wxString
wxString::Right(size_t nCount
) const
693 if ( nCount
> (size_t)GetStringData()->nDataLength
)
694 nCount
= GetStringData()->nDataLength
;
697 AllocCopy(dest
, nCount
, GetStringData()->nDataLength
- nCount
);
701 // get all characters after the last occurence of ch
702 // (returns the whole string if ch not found)
703 wxString
wxString::AfterLast(wxChar ch
) const
706 int iPos
= Find(ch
, TRUE
);
707 if ( iPos
== wxNOT_FOUND
)
710 str
= c_str() + iPos
+ 1;
715 // extract nCount first (leftmost) characters
716 wxString
wxString::Left(size_t nCount
) const
718 if ( nCount
> (size_t)GetStringData()->nDataLength
)
719 nCount
= GetStringData()->nDataLength
;
722 AllocCopy(dest
, nCount
, 0);
726 // get all characters before the first occurence of ch
727 // (returns the whole string if ch not found)
728 wxString
wxString::BeforeFirst(wxChar ch
) const
731 for ( const wxChar
*pc
= m_pchData
; *pc
!= wxT('\0') && *pc
!= ch
; pc
++ )
737 /// get all characters before the last occurence of ch
738 /// (returns empty string if ch not found)
739 wxString
wxString::BeforeLast(wxChar ch
) const
742 int iPos
= Find(ch
, TRUE
);
743 if ( iPos
!= wxNOT_FOUND
&& iPos
!= 0 )
744 str
= wxString(c_str(), iPos
);
749 /// get all characters after the first occurence of ch
750 /// (returns empty string if ch not found)
751 wxString
wxString::AfterFirst(wxChar ch
) const
755 if ( iPos
!= wxNOT_FOUND
)
756 str
= c_str() + iPos
+ 1;
761 // replace first (or all) occurences of some substring with another one
762 size_t wxString::Replace(const wxChar
*szOld
, const wxChar
*szNew
, bool bReplaceAll
)
764 size_t uiCount
= 0; // count of replacements made
766 size_t uiOldLen
= wxStrlen(szOld
);
769 const wxChar
*pCurrent
= m_pchData
;
770 const wxChar
*pSubstr
;
771 while ( *pCurrent
!= wxT('\0') ) {
772 pSubstr
= wxStrstr(pCurrent
, szOld
);
773 if ( pSubstr
== NULL
) {
774 // strTemp is unused if no replacements were made, so avoid the copy
778 strTemp
+= pCurrent
; // copy the rest
779 break; // exit the loop
782 // take chars before match
783 strTemp
.ConcatSelf(pSubstr
- pCurrent
, pCurrent
);
785 pCurrent
= pSubstr
+ uiOldLen
; // restart after match
790 if ( !bReplaceAll
) {
791 strTemp
+= pCurrent
; // copy the rest
792 break; // exit the loop
797 // only done if there were replacements, otherwise would have returned above
803 bool wxString::IsAscii() const
805 const wxChar
*s
= (const wxChar
*) *this;
807 if(!isascii(*s
)) return(FALSE
);
813 bool wxString::IsWord() const
815 const wxChar
*s
= (const wxChar
*) *this;
817 if(!wxIsalpha(*s
)) return(FALSE
);
823 bool wxString::IsNumber() const
825 const wxChar
*s
= (const wxChar
*) *this;
827 if(!wxIsdigit(*s
)) return(FALSE
);
833 wxString
wxString::Strip(stripType w
) const
836 if ( w
& leading
) s
.Trim(FALSE
);
837 if ( w
& trailing
) s
.Trim(TRUE
);
841 // ---------------------------------------------------------------------------
843 // ---------------------------------------------------------------------------
845 wxString
& wxString::MakeUpper()
849 for ( wxChar
*p
= m_pchData
; *p
; p
++ )
850 *p
= (wxChar
)wxToupper(*p
);
855 wxString
& wxString::MakeLower()
859 for ( wxChar
*p
= m_pchData
; *p
; p
++ )
860 *p
= (wxChar
)wxTolower(*p
);
865 // ---------------------------------------------------------------------------
866 // trimming and padding
867 // ---------------------------------------------------------------------------
869 // trims spaces (in the sense of isspace) from left or right side
870 wxString
& wxString::Trim(bool bFromRight
)
872 // first check if we're going to modify the string at all
875 (bFromRight
&& wxIsspace(GetChar(Len() - 1))) ||
876 (!bFromRight
&& wxIsspace(GetChar(0u)))
880 // ok, there is at least one space to trim
885 // find last non-space character
886 wxChar
*psz
= m_pchData
+ GetStringData()->nDataLength
- 1;
887 while ( wxIsspace(*psz
) && (psz
>= m_pchData
) )
890 // truncate at trailing space start
892 GetStringData()->nDataLength
= psz
- m_pchData
;
896 // find first non-space character
897 const wxChar
*psz
= m_pchData
;
898 while ( wxIsspace(*psz
) )
901 // fix up data and length
902 int nDataLength
= GetStringData()->nDataLength
- (psz
- (const wxChar
*) m_pchData
);
903 memmove(m_pchData
, psz
, (nDataLength
+ 1)*sizeof(wxChar
));
904 GetStringData()->nDataLength
= nDataLength
;
911 // adds nCount characters chPad to the string from either side
912 wxString
& wxString::Pad(size_t nCount
, wxChar chPad
, bool bFromRight
)
914 wxString
s(chPad
, nCount
);
927 // truncate the string
928 wxString
& wxString::Truncate(size_t uiLen
)
930 if ( uiLen
< Len() ) {
933 *(m_pchData
+ uiLen
) = wxT('\0');
934 GetStringData()->nDataLength
= uiLen
;
936 //else: nothing to do, string is already short enough
941 // ---------------------------------------------------------------------------
942 // finding (return wxNOT_FOUND if not found and index otherwise)
943 // ---------------------------------------------------------------------------
946 int wxString::Find(wxChar ch
, bool bFromEnd
) const
948 const wxChar
*psz
= bFromEnd
? wxStrrchr(m_pchData
, ch
) : wxStrchr(m_pchData
, ch
);
950 return (psz
== NULL
) ? wxNOT_FOUND
: psz
- (const wxChar
*) m_pchData
;
953 // find a sub-string (like strstr)
954 int wxString::Find(const wxChar
*pszSub
) const
956 const wxChar
*psz
= wxStrstr(m_pchData
, pszSub
);
958 return (psz
== NULL
) ? wxNOT_FOUND
: psz
- (const wxChar
*) m_pchData
;
961 // ---------------------------------------------------------------------------
962 // stream-like operators
963 // ---------------------------------------------------------------------------
964 wxString
& wxString::operator<<(int i
)
967 res
.Printf(wxT("%d"), i
);
969 return (*this) << res
;
972 wxString
& wxString::operator<<(float f
)
975 res
.Printf(wxT("%f"), f
);
977 return (*this) << res
;
980 wxString
& wxString::operator<<(double d
)
983 res
.Printf(wxT("%g"), d
);
985 return (*this) << res
;
988 // ---------------------------------------------------------------------------
990 // ---------------------------------------------------------------------------
991 int wxString::Printf(const wxChar
*pszFormat
, ...)
994 va_start(argptr
, pszFormat
);
996 int iLen
= PrintfV(pszFormat
, argptr
);
1003 int wxString::PrintfV(const wxChar
* pszFormat
, va_list argptr
)
1005 // static buffer to avoid dynamic memory allocation each time
1006 char s_szScratch
[1024]; // using static buffer causes internal compiler err
1009 // protect the static buffer
1010 static wxCriticalSection critsect
;
1011 wxCriticalSectionLocker
lock(critsect
);
1015 #if wxUSE_EXPERIMENTAL_PRINTF
1016 // the new implementation
1019 for (size_t n
= 0; pszFormat
[n
]; n
++)
1020 if (pszFormat
[n
] == wxT('%')) {
1021 static char s_szFlags
[256] = "%";
1023 bool adj_left
= FALSE
, in_prec
= FALSE
,
1024 prec_dot
= FALSE
, done
= FALSE
;
1026 size_t min_width
= 0, max_width
= wxSTRING_MAXLEN
;
1028 #define CHECK_PREC if (in_prec && !prec_dot) { s_szFlags[flagofs++] = '.'; prec_dot = TRUE; }
1029 switch (pszFormat
[++n
]) {
1043 s_szFlags
[flagofs
++] = pszFormat
[n
];
1048 s_szFlags
[flagofs
++] = pszFormat
[n
];
1055 // dot will be auto-added to s_szFlags if non-negative number follows
1060 s_szFlags
[flagofs
++] = pszFormat
[n
];
1065 s_szFlags
[flagofs
++] = pszFormat
[n
];
1071 s_szFlags
[flagofs
++] = pszFormat
[n
];
1076 s_szFlags
[flagofs
++] = pszFormat
[n
];
1080 int len
= va_arg(argptr
, int);
1087 adj_left
= !adj_left
;
1088 s_szFlags
[flagofs
++] = '-';
1093 flagofs
+= ::sprintf(s_szFlags
+flagofs
,"%d",len
);
1096 case wxT('1'): case wxT('2'): case wxT('3'):
1097 case wxT('4'): case wxT('5'): case wxT('6'):
1098 case wxT('7'): case wxT('8'): case wxT('9'):
1102 while ((pszFormat
[n
]>=wxT('0')) && (pszFormat
[n
]<=wxT('9'))) {
1103 s_szFlags
[flagofs
++] = pszFormat
[n
];
1104 len
= len
*10 + (pszFormat
[n
] - wxT('0'));
1107 if (in_prec
) max_width
= len
;
1108 else min_width
= len
;
1109 n
--; // the main loop pre-increments n again
1119 s_szFlags
[flagofs
++] = pszFormat
[n
];
1120 s_szFlags
[flagofs
] = '\0';
1122 int val
= va_arg(argptr
, int);
1123 ::sprintf(s_szScratch
, s_szFlags
, val
);
1125 else if (ilen
== -1) {
1126 short int val
= va_arg(argptr
, short int);
1127 ::sprintf(s_szScratch
, s_szFlags
, val
);
1129 else if (ilen
== 1) {
1130 long int val
= va_arg(argptr
, long int);
1131 ::sprintf(s_szScratch
, s_szFlags
, val
);
1133 else if (ilen
== 2) {
1134 #if SIZEOF_LONG_LONG
1135 long long int val
= va_arg(argptr
, long long int);
1136 ::sprintf(s_szScratch
, s_szFlags
, val
);
1138 long int val
= va_arg(argptr
, long int);
1139 ::sprintf(s_szScratch
, s_szFlags
, val
);
1142 else if (ilen
== 3) {
1143 size_t val
= va_arg(argptr
, size_t);
1144 ::sprintf(s_szScratch
, s_szFlags
, val
);
1146 *this += wxString(s_szScratch
);
1155 s_szFlags
[flagofs
++] = pszFormat
[n
];
1156 s_szFlags
[flagofs
] = '\0';
1158 long double val
= va_arg(argptr
, long double);
1159 ::sprintf(s_szScratch
, s_szFlags
, val
);
1161 double val
= va_arg(argptr
, double);
1162 ::sprintf(s_szScratch
, s_szFlags
, val
);
1164 *this += wxString(s_szScratch
);
1169 void *val
= va_arg(argptr
, void *);
1171 s_szFlags
[flagofs
++] = pszFormat
[n
];
1172 s_szFlags
[flagofs
] = '\0';
1173 ::sprintf(s_szScratch
, s_szFlags
, val
);
1174 *this += wxString(s_szScratch
);
1180 wxChar val
= va_arg(argptr
, int);
1181 // we don't need to honor padding here, do we?
1188 // wx extension: we'll let %hs mean non-Unicode strings
1189 char *val
= va_arg(argptr
, char *);
1191 // ASCII->Unicode constructor handles max_width right
1192 wxString
s(val
, wxConvLibc
, max_width
);
1194 size_t len
= wxSTRING_MAXLEN
;
1196 for (len
= 0; val
[len
] && (len
<max_width
); len
++);
1197 } else val
= wxT("(null)");
1198 wxString
s(val
, len
);
1200 if (s
.Len() < min_width
)
1201 s
.Pad(min_width
- s
.Len(), wxT(' '), adj_left
);
1204 wxChar
*val
= va_arg(argptr
, wxChar
*);
1205 size_t len
= wxSTRING_MAXLEN
;
1207 for (len
= 0; val
[len
] && (len
<max_width
); len
++);
1208 } else val
= wxT("(null)");
1209 wxString
s(val
, len
);
1210 if (s
.Len() < min_width
)
1211 s
.Pad(min_width
- s
.Len(), wxT(' '), adj_left
);
1218 int *val
= va_arg(argptr
, int *);
1221 else if (ilen
== -1) {
1222 short int *val
= va_arg(argptr
, short int *);
1225 else if (ilen
>= 1) {
1226 long int *val
= va_arg(argptr
, long int *);
1232 if (wxIsalpha(pszFormat
[n
]))
1233 // probably some flag not taken care of here yet
1234 s_szFlags
[flagofs
++] = pszFormat
[n
];
1237 *this += wxT('%'); // just to pass the glibc tst-printf.c
1245 } else *this += pszFormat
[n
];
1248 // NB: wxVsnprintf() may return either less than the buffer size or -1 if there
1249 // is not enough place depending on implementation
1250 int iLen
= wxVsnprintf(s_szScratch
, WXSIZEOF(s_szScratch
), pszFormat
, argptr
);
1252 if ( iLen
< (int)WXSIZEOF(s_szScratch
) ) {
1253 buffer
= s_szScratch
;
1256 int size
= WXSIZEOF(s_szScratch
) * 2;
1257 buffer
= (char *)malloc(size
);
1258 while ( buffer
!= NULL
) {
1259 iLen
= wxVsnprintf(buffer
, WXSIZEOF(s_szScratch
), pszFormat
, argptr
);
1260 if ( iLen
< size
) {
1261 // ok, there was enough space
1265 // still not enough, double it again
1266 buffer
= (char *)realloc(buffer
, size
*= 2);
1278 if ( buffer
!= s_szScratch
)
1285 // ----------------------------------------------------------------------------
1286 // misc other operations
1287 // ----------------------------------------------------------------------------
1289 // returns TRUE if the string matches the pattern which may contain '*' and
1290 // '?' metacharacters (as usual, '?' matches any character and '*' any number
1292 bool wxString::Matches(const wxChar
*pszMask
) const
1294 // check char by char
1295 const wxChar
*pszTxt
;
1296 for ( pszTxt
= c_str(); *pszMask
!= wxT('\0'); pszMask
++, pszTxt
++ ) {
1297 switch ( *pszMask
) {
1299 if ( *pszTxt
== wxT('\0') )
1302 // pszText and pszMask will be incremented in the loop statement
1308 // ignore special chars immediately following this one
1309 while ( *pszMask
== wxT('*') || *pszMask
== wxT('?') )
1312 // if there is nothing more, match
1313 if ( *pszMask
== wxT('\0') )
1316 // are there any other metacharacters in the mask?
1318 const wxChar
*pEndMask
= wxStrpbrk(pszMask
, wxT("*?"));
1320 if ( pEndMask
!= NULL
) {
1321 // we have to match the string between two metachars
1322 uiLenMask
= pEndMask
- pszMask
;
1325 // we have to match the remainder of the string
1326 uiLenMask
= wxStrlen(pszMask
);
1329 wxString
strToMatch(pszMask
, uiLenMask
);
1330 const wxChar
* pMatch
= wxStrstr(pszTxt
, strToMatch
);
1331 if ( pMatch
== NULL
)
1334 // -1 to compensate "++" in the loop
1335 pszTxt
= pMatch
+ uiLenMask
- 1;
1336 pszMask
+= uiLenMask
- 1;
1341 if ( *pszMask
!= *pszTxt
)
1347 // match only if nothing left
1348 return *pszTxt
== wxT('\0');
1351 // Count the number of chars
1352 int wxString::Freq(wxChar ch
) const
1356 for (int i
= 0; i
< len
; i
++)
1358 if (GetChar(i
) == ch
)
1364 // convert to upper case, return the copy of the string
1365 wxString
wxString::Upper() const
1366 { wxString
s(*this); return s
.MakeUpper(); }
1368 // convert to lower case, return the copy of the string
1369 wxString
wxString::Lower() const { wxString
s(*this); return s
.MakeLower(); }
1371 int wxString::sprintf(const wxChar
*pszFormat
, ...)
1374 va_start(argptr
, pszFormat
);
1375 int iLen
= PrintfV(pszFormat
, argptr
);
1380 // ---------------------------------------------------------------------------
1381 // standard C++ library string functions
1382 // ---------------------------------------------------------------------------
1383 #ifdef wxSTD_STRING_COMPATIBILITY
1385 wxString
& wxString::insert(size_t nPos
, const wxString
& str
)
1387 wxASSERT( str
.GetStringData()->IsValid() );
1388 wxASSERT( nPos
<= Len() );
1390 if ( !str
.IsEmpty() ) {
1392 wxChar
*pc
= strTmp
.GetWriteBuf(Len() + str
.Len());
1393 wxStrncpy(pc
, c_str(), nPos
);
1394 wxStrcpy(pc
+ nPos
, str
);
1395 wxStrcpy(pc
+ nPos
+ str
.Len(), c_str() + nPos
);
1396 strTmp
.UngetWriteBuf();
1403 size_t wxString::find(const wxString
& str
, size_t nStart
) const
1405 wxASSERT( str
.GetStringData()->IsValid() );
1406 wxASSERT( nStart
<= Len() );
1408 const wxChar
*p
= wxStrstr(c_str() + nStart
, str
);
1410 return p
== NULL
? npos
: p
- c_str();
1413 // VC++ 1.5 can't cope with the default argument in the header.
1414 #if !defined(__VISUALC__) || defined(__WIN32__)
1415 size_t wxString::find(const wxChar
* sz
, size_t nStart
, size_t n
) const
1417 return find(wxString(sz
, n
== npos
? 0 : n
), nStart
);
1421 // Gives a duplicate symbol (presumably a case-insensitivity problem)
1422 #if !defined(__BORLANDC__)
1423 size_t wxString::find(wxChar ch
, size_t nStart
) const
1425 wxASSERT( nStart
<= Len() );
1427 const wxChar
*p
= wxStrchr(c_str() + nStart
, ch
);
1429 return p
== NULL
? npos
: p
- c_str();
1433 size_t wxString::rfind(const wxString
& str
, size_t nStart
) const
1435 wxASSERT( str
.GetStringData()->IsValid() );
1436 wxASSERT( nStart
<= Len() );
1438 // TODO could be made much quicker than that
1439 const wxChar
*p
= c_str() + (nStart
== npos
? Len() : nStart
);
1440 while ( p
>= c_str() + str
.Len() ) {
1441 if ( wxStrncmp(p
- str
.Len(), str
, str
.Len()) == 0 )
1442 return p
- str
.Len() - c_str();
1449 // VC++ 1.5 can't cope with the default argument in the header.
1450 #if !defined(__VISUALC__) || defined(__WIN32__)
1451 size_t wxString::rfind(const wxChar
* sz
, size_t nStart
, size_t n
) const
1453 return rfind(wxString(sz
, n
== npos
? 0 : n
), nStart
);
1456 size_t wxString::rfind(wxChar ch
, size_t nStart
) const
1458 if ( nStart
== npos
)
1464 wxASSERT( nStart
<= Len() );
1467 const wxChar
*p
= wxStrrchr(c_str(), ch
);
1472 size_t result
= p
- c_str();
1473 return ( result
> nStart
) ? npos
: result
;
1477 size_t wxString::find_first_of(const wxChar
* sz
, size_t nStart
) const
1479 const wxChar
*start
= c_str() + nStart
;
1480 const wxChar
*firstOf
= wxStrpbrk(start
, sz
);
1482 return firstOf
- start
;
1487 size_t wxString::find_last_of(const wxChar
* sz
, size_t nStart
) const
1489 if ( nStart
== npos
)
1495 wxASSERT( nStart
<= Len() );
1498 for ( const wxChar
*p
= c_str() + length() - 1; p
>= c_str(); p
-- )
1500 if ( wxStrchr(sz
, *p
) )
1507 size_t wxString::find_first_not_of(const wxChar
* sz
, size_t nStart
) const
1509 if ( nStart
== npos
)
1515 wxASSERT( nStart
<= Len() );
1518 size_t nAccept
= wxStrspn(c_str() + nStart
, sz
);
1519 if ( nAccept
>= length() - nStart
)
1525 size_t wxString::find_first_not_of(wxChar ch
, size_t nStart
) const
1527 wxASSERT( nStart
<= Len() );
1529 for ( const wxChar
*p
= c_str() + nStart
; *p
; p
++ )
1538 size_t wxString::find_last_not_of(const wxChar
* sz
, size_t nStart
) const
1540 if ( nStart
== npos
)
1546 wxASSERT( nStart
<= Len() );
1549 for ( const wxChar
*p
= c_str() + nStart
- 1; p
>= c_str(); p
-- )
1551 if ( !wxStrchr(sz
, *p
) )
1558 size_t wxString::find_last_not_of(wxChar ch
, size_t nStart
) const
1560 if ( nStart
== npos
)
1566 wxASSERT( nStart
<= Len() );
1569 for ( const wxChar
*p
= c_str() + nStart
- 1; p
>= c_str(); p
-- )
1578 wxString
wxString::substr(size_t nStart
, size_t nLen
) const
1580 // npos means 'take all'
1584 wxASSERT( nStart
+ nLen
<= Len() );
1586 return wxString(c_str() + nStart
, nLen
== npos
? 0 : nLen
);
1589 wxString
& wxString::erase(size_t nStart
, size_t nLen
)
1591 wxString
strTmp(c_str(), nStart
);
1592 if ( nLen
!= npos
) {
1593 wxASSERT( nStart
+ nLen
<= Len() );
1595 strTmp
.append(c_str() + nStart
+ nLen
);
1602 wxString
& wxString::replace(size_t nStart
, size_t nLen
, const wxChar
*sz
)
1604 wxASSERT( nStart
+ nLen
<= wxStrlen(sz
) );
1608 strTmp
.append(c_str(), nStart
);
1610 strTmp
.append(c_str() + nStart
+ nLen
);
1616 wxString
& wxString::replace(size_t nStart
, size_t nLen
, size_t nCount
, wxChar ch
)
1618 return replace(nStart
, nLen
, wxString(ch
, nCount
));
1621 wxString
& wxString::replace(size_t nStart
, size_t nLen
,
1622 const wxString
& str
, size_t nStart2
, size_t nLen2
)
1624 return replace(nStart
, nLen
, str
.substr(nStart2
, nLen2
));
1627 wxString
& wxString::replace(size_t nStart
, size_t nLen
,
1628 const wxChar
* sz
, size_t nCount
)
1630 return replace(nStart
, nLen
, wxString(sz
, nCount
));
1633 #endif //std::string compatibility
1635 // ============================================================================
1637 // ============================================================================
1639 // size increment = max(50% of current size, ARRAY_MAXSIZE_INCREMENT)
1640 #define ARRAY_MAXSIZE_INCREMENT 4096
1641 #ifndef ARRAY_DEFAULT_INITIAL_SIZE // also defined in dynarray.h
1642 #define ARRAY_DEFAULT_INITIAL_SIZE (16)
1645 #define STRING(p) ((wxString *)(&(p)))
1648 wxArrayString::wxArrayString(bool autoSort
)
1652 m_pItems
= (wxChar
**) NULL
;
1653 m_autoSort
= autoSort
;
1657 wxArrayString::wxArrayString(const wxArrayString
& src
)
1661 m_pItems
= (wxChar
**) NULL
;
1662 m_autoSort
= src
.m_autoSort
;
1667 // assignment operator
1668 wxArrayString
& wxArrayString::operator=(const wxArrayString
& src
)
1678 void wxArrayString::Copy(const wxArrayString
& src
)
1680 if ( src
.m_nCount
> ARRAY_DEFAULT_INITIAL_SIZE
)
1681 Alloc(src
.m_nCount
);
1683 // we can't just copy the pointers here because otherwise we would share
1684 // the strings with another array because strings are ref counted
1686 if ( m_nCount
!= 0 )
1687 memcpy(m_pItems
, src
.m_pItems
, m_nCount
*sizeof(wxChar
*));
1690 for ( size_t n
= 0; n
< src
.m_nCount
; n
++ )
1693 // if the other array is auto sorted too, we're already sorted, but
1694 // otherwise we should rearrange the items
1695 if ( m_autoSort
&& !src
.m_autoSort
)
1700 void wxArrayString::Grow()
1702 // only do it if no more place
1703 if( m_nCount
== m_nSize
) {
1704 if( m_nSize
== 0 ) {
1705 // was empty, alloc some memory
1706 m_nSize
= ARRAY_DEFAULT_INITIAL_SIZE
;
1707 m_pItems
= new wxChar
*[m_nSize
];
1710 // otherwise when it's called for the first time, nIncrement would be 0
1711 // and the array would never be expanded
1712 #if defined(__VISAGECPP__) && defined(__WXDEBUG__)
1713 int array_size
= ARRAY_DEFAULT_INITIAL_SIZE
;
1714 wxASSERT( array_size
!= 0 );
1716 wxASSERT( ARRAY_DEFAULT_INITIAL_SIZE
!= 0 );
1719 // add 50% but not too much
1720 size_t nIncrement
= m_nSize
< ARRAY_DEFAULT_INITIAL_SIZE
1721 ? ARRAY_DEFAULT_INITIAL_SIZE
: m_nSize
>> 1;
1722 if ( nIncrement
> ARRAY_MAXSIZE_INCREMENT
)
1723 nIncrement
= ARRAY_MAXSIZE_INCREMENT
;
1724 m_nSize
+= nIncrement
;
1725 wxChar
**pNew
= new wxChar
*[m_nSize
];
1727 // copy data to new location
1728 memcpy(pNew
, m_pItems
, m_nCount
*sizeof(wxChar
*));
1730 // delete old memory (but do not release the strings!)
1731 wxDELETEA(m_pItems
);
1738 void wxArrayString::Free()
1740 for ( size_t n
= 0; n
< m_nCount
; n
++ ) {
1741 STRING(m_pItems
[n
])->GetStringData()->Unlock();
1745 // deletes all the strings from the list
1746 void wxArrayString::Empty()
1753 // as Empty, but also frees memory
1754 void wxArrayString::Clear()
1761 wxDELETEA(m_pItems
);
1765 wxArrayString::~wxArrayString()
1769 wxDELETEA(m_pItems
);
1772 // pre-allocates memory (frees the previous data!)
1773 void wxArrayString::Alloc(size_t nSize
)
1775 wxASSERT( nSize
> 0 );
1777 // only if old buffer was not big enough
1778 if ( nSize
> m_nSize
) {
1780 wxDELETEA(m_pItems
);
1781 m_pItems
= new wxChar
*[nSize
];
1788 // minimizes the memory usage by freeing unused memory
1789 void wxArrayString::Shrink()
1791 // only do it if we have some memory to free
1792 if( m_nCount
< m_nSize
) {
1793 // allocates exactly as much memory as we need
1794 wxChar
**pNew
= new wxChar
*[m_nCount
];
1796 // copy data to new location
1797 memcpy(pNew
, m_pItems
, m_nCount
*sizeof(wxChar
*));
1803 // searches the array for an item (forward or backwards)
1804 int wxArrayString::Index(const wxChar
*sz
, bool bCase
, bool bFromEnd
) const
1807 // use binary search in the sorted array
1808 wxASSERT_MSG( bCase
&& !bFromEnd
,
1809 wxT("search parameters ignored for auto sorted array") );
1818 res
= wxStrcmp(sz
, m_pItems
[i
]);
1830 // use linear search in unsorted array
1832 if ( m_nCount
> 0 ) {
1833 size_t ui
= m_nCount
;
1835 if ( STRING(m_pItems
[--ui
])->IsSameAs(sz
, bCase
) )
1842 for( size_t ui
= 0; ui
< m_nCount
; ui
++ ) {
1843 if( STRING(m_pItems
[ui
])->IsSameAs(sz
, bCase
) )
1852 // add item at the end
1853 size_t wxArrayString::Add(const wxString
& str
)
1856 // insert the string at the correct position to keep the array sorted
1864 res
= wxStrcmp(str
, m_pItems
[i
]);
1875 wxASSERT_MSG( lo
== hi
, wxT("binary search broken") );
1882 wxASSERT( str
.GetStringData()->IsValid() );
1886 // the string data must not be deleted!
1887 str
.GetStringData()->Lock();
1890 m_pItems
[m_nCount
] = (wxChar
*)str
.c_str(); // const_cast
1896 // add item at the given position
1897 void wxArrayString::Insert(const wxString
& str
, size_t nIndex
)
1899 wxASSERT( str
.GetStringData()->IsValid() );
1901 wxCHECK_RET( nIndex
<= m_nCount
, wxT("bad index in wxArrayString::Insert") );
1905 memmove(&m_pItems
[nIndex
+ 1], &m_pItems
[nIndex
],
1906 (m_nCount
- nIndex
)*sizeof(wxChar
*));
1908 str
.GetStringData()->Lock();
1909 m_pItems
[nIndex
] = (wxChar
*)str
.c_str();
1914 // removes item from array (by index)
1915 void wxArrayString::Remove(size_t nIndex
)
1917 wxCHECK_RET( nIndex
<= m_nCount
, wxT("bad index in wxArrayString::Remove") );
1920 Item(nIndex
).GetStringData()->Unlock();
1922 memmove(&m_pItems
[nIndex
], &m_pItems
[nIndex
+ 1],
1923 (m_nCount
- nIndex
- 1)*sizeof(wxChar
*));
1927 // removes item from array (by value)
1928 void wxArrayString::Remove(const wxChar
*sz
)
1930 int iIndex
= Index(sz
);
1932 wxCHECK_RET( iIndex
!= wxNOT_FOUND
,
1933 wxT("removing inexistent element in wxArrayString::Remove") );
1938 // ----------------------------------------------------------------------------
1940 // ----------------------------------------------------------------------------
1942 // we can only sort one array at a time with the quick-sort based
1945 // need a critical section to protect access to gs_compareFunction and
1946 // gs_sortAscending variables
1947 static wxCriticalSection
*gs_critsectStringSort
= NULL
;
1949 // call this before the value of the global sort vars is changed/after
1950 // you're finished with them
1951 #define START_SORT() wxASSERT( !gs_critsectStringSort ); \
1952 gs_critsectStringSort = new wxCriticalSection; \
1953 gs_critsectStringSort->Enter()
1954 #define END_SORT() gs_critsectStringSort->Leave(); \
1955 delete gs_critsectStringSort; \
1956 gs_critsectStringSort = NULL
1958 #define START_SORT()
1960 #endif // wxUSE_THREADS
1962 // function to use for string comparaison
1963 static wxArrayString::CompareFunction gs_compareFunction
= NULL
;
1965 // if we don't use the compare function, this flag tells us if we sort the
1966 // array in ascending or descending order
1967 static bool gs_sortAscending
= TRUE
;
1969 // function which is called by quick sort
1970 static int LINKAGEMODE
wxStringCompareFunction(const void *first
, const void *second
)
1972 wxString
*strFirst
= (wxString
*)first
;
1973 wxString
*strSecond
= (wxString
*)second
;
1975 if ( gs_compareFunction
) {
1976 return gs_compareFunction(*strFirst
, *strSecond
);
1979 // maybe we should use wxStrcoll
1980 int result
= wxStrcmp(strFirst
->c_str(), strSecond
->c_str());
1982 return gs_sortAscending
? result
: -result
;
1986 // sort array elements using passed comparaison function
1987 void wxArrayString::Sort(CompareFunction compareFunction
)
1991 wxASSERT( !gs_compareFunction
); // must have been reset to NULL
1992 gs_compareFunction
= compareFunction
;
1999 void wxArrayString::Sort(bool reverseOrder
)
2003 wxASSERT( !gs_compareFunction
); // must have been reset to NULL
2004 gs_sortAscending
= !reverseOrder
;
2011 void wxArrayString::DoSort()
2013 wxCHECK_RET( !m_autoSort
, wxT("can't use this method with sorted arrays") );
2015 // just sort the pointers using qsort() - of course it only works because
2016 // wxString() *is* a pointer to its data
2017 qsort(m_pItems
, m_nCount
, sizeof(wxChar
*), wxStringCompareFunction
);