]> git.saurik.com Git - wxWidgets.git/blame - src/common/string.cpp
Added Property List classes to main library; added proplist sample; merged
[wxWidgets.git] / src / common / string.cpp
CommitLineData
c801d85f
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: string.cpp
3// Purpose: wxString class
4// Author: Vadim Zeitlin
5// Modified by:
6// Created: 29/01/98
7// RCS-ID: $Id$
8// Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
dd1eaa89 9// Licence: wxWindows license
c801d85f
KB
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation "string.h"
14#endif
15
16/*
17 * About ref counting:
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
21 */
22
23// ===========================================================================
24// headers, declarations, constants
25// ===========================================================================
26
27// For compilers that support precompilation, includes "wx.h".
28#include "wx/wxprec.h"
29
30#ifdef __BORLANDC__
31#pragma hdrstop
32#endif
33
34#ifndef WX_PRECOMP
3c024cc2
VZ
35 #include "wx/defs.h"
36 #include "wx/string.h"
37 #include "wx/intl.h"
c801d85f
KB
38#endif
39
40#include <ctype.h>
41#include <string.h>
42#include <stdlib.h>
43
4fabb575
JS
44// This probably isn't right, what should it be Vadim?
45// Otherwise we end up with no wxVsprintf defined.
46#ifdef __WXMOTIF__
47#define HAVE_VPRINTF
48#endif
49
fb4e5803
VZ
50#ifdef wxUSE_WCSRTOMBS
51 #include <wchar.h> // for wcsrtombs(), see comments where it's used
52#endif // GNU
53
c801d85f
KB
54#ifdef WXSTRING_IS_WXOBJECT
55 IMPLEMENT_DYNAMIC_CLASS(wxString, wxObject)
56#endif //WXSTRING_IS_WXOBJECT
57
3168a13f
VZ
58// allocating extra space for each string consumes more memory but speeds up
59// the concatenation operations (nLen is the current string's length)
77ca46e7
VZ
60// NB: EXTRA_ALLOC must be >= 0!
61#define EXTRA_ALLOC (19 - nLen % 16)
3168a13f 62
c801d85f
KB
63// ---------------------------------------------------------------------------
64// static class variables definition
65// ---------------------------------------------------------------------------
66
67#ifdef STD_STRING_COMPATIBILITY
68 const size_t wxString::npos = STRING_MAXLEN;
69#endif
70
3168a13f
VZ
71// ----------------------------------------------------------------------------
72// static data
73// ----------------------------------------------------------------------------
c801d85f 74
3c024cc2
VZ
75// for an empty string, GetStringData() will return this address: this
76// structure has the same layout as wxStringData and it's data() method will
77// return the empty string (dummy pointer)
78static const struct
79{
80 wxStringData data;
81 char dummy;
82} g_strEmpty = { {-1, 0, 0}, '\0' };
83
c801d85f 84// empty C style string: points to 'string data' byte of g_strEmpty
3c024cc2 85extern const char *g_szNul = &g_strEmpty.dummy;
c801d85f 86
89b892a2
VZ
87// ----------------------------------------------------------------------------
88// conditional compilation
89// ----------------------------------------------------------------------------
90
91// we want to find out if the current platform supports vsnprintf()-like
92// function: for Unix this is done with configure, for Windows we test the
93// compiler explicitly.
94#ifdef __WXMSW__
95 #ifdef _MSC_VER
96 #define wxVsprintf _vsnprintf
97 #endif
98#else // !Windows
99 #ifdef HAVE_VSNPRINTF
100 #define wxVsprintf vsnprintf
101 #endif
102#endif // Windows/!Windows
103
104#ifndef wxVsprintf
105 // in this case we'll use vsprintf() (which is ANSI and thus should be
106 // always available), but it's unsafe because it doesn't check for buffer
107 // size - so give a warning
108 #define wxVsprintf(buffer,len,format,argptr) vsprintf(buffer,format, argptr)
109 #pragma message("Using sprintf() because no snprintf()-like function defined")
110#endif
111
3168a13f 112// ----------------------------------------------------------------------------
c801d85f 113// global functions
3168a13f 114// ----------------------------------------------------------------------------
c801d85f
KB
115
116#ifdef STD_STRING_COMPATIBILITY
117
118// MS Visual C++ version 5.0 provides the new STL headers as well as the old
119// iostream ones.
120//
121// ATTN: you can _not_ use both of these in the same program!
fbc535ff
JS
122#if wxUSE_IOSTREAMH
123#include <iostream.h>
124#define NAMESPACE
125#else
126#include <iostream>
127# ifdef _MSC_VER
128 using namespace std;
129# endif
5f31d862
UU
130// for msvc (bcc50+ also) you don't need these NAMESPACE defines,
131// using namespace std; takes care of that.
fbc535ff
JS
132#define NAMESPACE std::
133#endif
134
a38b83c3 135#ifdef __WXMSW__
7aa88ac4
VZ
136 #ifdef _MSC_VER
137 #define wxVsprintf _vsnprintf
138 #endif
a38b83c3 139#else
7aa88ac4
VZ
140 #if defined ( HAVE_VSNPRINTF )
141 #define wxVsprintf vsnprintf
142 #endif
a38b83c3
KB
143#endif
144
145#ifndef wxVsprintf
7aa88ac4 146 // vsprintf() is ANSI so we can always use it, but it's unsafe!
a38b83c3
KB
147 #define wxVsprintf(buffer,len,format,argptr) vsprintf(buffer,format, argptr)
148 #pragma message("Using sprintf() because no snprintf()-like function defined")
a38b83c3 149#endif
fbc535ff 150
c801d85f
KB
151NAMESPACE istream& operator>>(NAMESPACE istream& is, wxString& WXUNUSED(str))
152{
153#if 0
154 int w = is.width(0);
155 if ( is.ipfx(0) ) {
156 NAMESPACE streambuf *sb = is.rdbuf();
157 str.erase();
158 while ( true ) {
159 int ch = sb->sbumpc ();
160 if ( ch == EOF ) {
161 is.setstate(NAMESPACE ios::eofbit);
162 break;
163 }
164 else if ( isspace(ch) ) {
165 sb->sungetc();
166 break;
167 }
dd1eaa89 168
c801d85f
KB
169 str += ch;
170 if ( --w == 1 )
171 break;
172 }
173 }
174
175 is.isfx();
176 if ( str.length() == 0 )
177 is.setstate(NAMESPACE ios::failbit);
178#endif
179 return is;
180}
181
182#endif //std::string compatibility
183
3168a13f
VZ
184// ----------------------------------------------------------------------------
185// private classes
186// ----------------------------------------------------------------------------
187
188// this small class is used to gather statistics for performance tuning
189//#define WXSTRING_STATISTICS
190#ifdef WXSTRING_STATISTICS
191 class Averager
192 {
193 public:
194 Averager(const char *sz) { m_sz = sz; m_nTotal = m_nCount = 0; }
2c3b684c 195 ~Averager()
3168a13f
VZ
196 { printf("wxString: average %s = %f\n", m_sz, ((float)m_nTotal)/m_nCount); }
197
c86f1403 198 void Add(size_t n) { m_nTotal += n; m_nCount++; }
3168a13f
VZ
199
200 private:
c86f1403 201 size_t m_nCount, m_nTotal;
3168a13f
VZ
202 const char *m_sz;
203 } g_averageLength("allocation size"),
204 g_averageSummandLength("summand length"),
205 g_averageConcatHit("hit probability in concat"),
206 g_averageInitialLength("initial string length");
207
208 #define STATISTICS_ADD(av, val) g_average##av.Add(val)
209#else
210 #define STATISTICS_ADD(av, val)
211#endif // WXSTRING_STATISTICS
212
c801d85f
KB
213// ===========================================================================
214// wxString class core
215// ===========================================================================
216
217// ---------------------------------------------------------------------------
218// construction
219// ---------------------------------------------------------------------------
220
c801d85f
KB
221// constructs string of <nLength> copies of character <ch>
222wxString::wxString(char ch, size_t nLength)
223{
224 Init();
225
226 if ( nLength > 0 ) {
227 AllocBuffer(nLength);
f1da2f03 228
c801d85f
KB
229 wxASSERT( sizeof(char) == 1 ); // can't use memset if not
230
231 memset(m_pchData, ch, nLength);
232 }
233}
234
235// takes nLength elements of psz starting at nPos
236void wxString::InitWith(const char *psz, size_t nPos, size_t nLength)
237{
238 Init();
239
240 wxASSERT( nPos <= Strlen(psz) );
241
242 if ( nLength == STRING_MAXLEN )
243 nLength = Strlen(psz + nPos);
244
3168a13f
VZ
245 STATISTICS_ADD(InitialLength, nLength);
246
c801d85f
KB
247 if ( nLength > 0 ) {
248 // trailing '\0' is written in AllocBuffer()
249 AllocBuffer(nLength);
250 memcpy(m_pchData, psz + nPos, nLength*sizeof(char));
251 }
252}
dd1eaa89 253
c801d85f
KB
254// the same as previous constructor, but for compilers using unsigned char
255wxString::wxString(const unsigned char* psz, size_t nLength)
256{
257 InitWith((const char *)psz, 0, nLength);
dd1eaa89
VZ
258}
259
c801d85f
KB
260#ifdef STD_STRING_COMPATIBILITY
261
c801d85f
KB
262// poor man's iterators are "void *" pointers
263wxString::wxString(const void *pStart, const void *pEnd)
264{
dd1eaa89 265 InitWith((const char *)pStart, 0,
c801d85f
KB
266 (const char *)pEnd - (const char *)pStart);
267}
268
269#endif //std::string compatibility
270
271// from wide string
272wxString::wxString(const wchar_t *pwz)
273{
274 // first get necessary size
fb4e5803
VZ
275
276 // NB: GNU libc5 wcstombs() is completely broken, don't use it (it doesn't
277 // honor the 3rd parameter, thus it will happily crash here).
278#ifdef wxUSE_WCSRTOMBS
279 // don't know if it's really needed (or if we can pass NULL), but better safe
280 // than quick
281 mbstate_t mbstate;
282 size_t nLen = wcsrtombs((char *) NULL, &pwz, 0, &mbstate);
283#else // !GNU libc
c67daf87 284 size_t nLen = wcstombs((char *) NULL, pwz, 0);
fb4e5803 285#endif // GNU
c801d85f
KB
286
287 // empty?
288 if ( nLen != 0 ) {
289 AllocBuffer(nLen);
290 wcstombs(m_pchData, pwz, nLen);
291 }
292 else {
293 Init();
294 }
295}
296
297// ---------------------------------------------------------------------------
298// memory allocation
299// ---------------------------------------------------------------------------
300
301// allocates memory needed to store a C string of length nLen
302void wxString::AllocBuffer(size_t nLen)
303{
304 wxASSERT( nLen > 0 ); //
305 wxASSERT( nLen <= INT_MAX-1 ); // max size (enough room for 1 extra)
306
3168a13f
VZ
307 STATISTICS_ADD(Length, nLen);
308
c801d85f
KB
309 // allocate memory:
310 // 1) one extra character for '\0' termination
311 // 2) sizeof(wxStringData) for housekeeping info
3168a13f
VZ
312 wxStringData* pData = (wxStringData*)
313 malloc(sizeof(wxStringData) + (nLen + EXTRA_ALLOC + 1)*sizeof(char));
c801d85f 314 pData->nRefs = 1;
c801d85f 315 pData->nDataLength = nLen;
3168a13f 316 pData->nAllocLength = nLen + EXTRA_ALLOC;
c801d85f 317 m_pchData = pData->data(); // data starts after wxStringData
3168a13f 318 m_pchData[nLen] = '\0';
c801d85f
KB
319}
320
c801d85f
KB
321// must be called before changing this string
322void wxString::CopyBeforeWrite()
323{
324 wxStringData* pData = GetStringData();
325
326 if ( pData->IsShared() ) {
327 pData->Unlock(); // memory not freed because shared
c86f1403 328 size_t nLen = pData->nDataLength;
3168a13f
VZ
329 AllocBuffer(nLen);
330 memcpy(m_pchData, pData->data(), nLen*sizeof(char));
c801d85f
KB
331 }
332
3bbb630a 333 wxASSERT( !GetStringData()->IsShared() ); // we must be the only owner
c801d85f
KB
334}
335
336// must be called before replacing contents of this string
337void wxString::AllocBeforeWrite(size_t nLen)
338{
339 wxASSERT( nLen != 0 ); // doesn't make any sense
340
341 // must not share string and must have enough space
3168a13f 342 wxStringData* pData = GetStringData();
c801d85f
KB
343 if ( pData->IsShared() || (nLen > pData->nAllocLength) ) {
344 // can't work with old buffer, get new one
345 pData->Unlock();
346 AllocBuffer(nLen);
347 }
348
f1da2f03 349 wxASSERT( !GetStringData()->IsShared() ); // we must be the only owner
c801d85f
KB
350}
351
dd1eaa89 352// allocate enough memory for nLen characters
c86f1403 353void wxString::Alloc(size_t nLen)
dd1eaa89
VZ
354{
355 wxStringData *pData = GetStringData();
356 if ( pData->nAllocLength <= nLen ) {
9fbd8b8d
VZ
357 if ( pData->IsEmpty() ) {
358 nLen += EXTRA_ALLOC;
359
360 wxStringData* pData = (wxStringData*)
361 malloc(sizeof(wxStringData) + (nLen + 1)*sizeof(char));
362 pData->nRefs = 1;
363 pData->nDataLength = 0;
364 pData->nAllocLength = nLen;
365 m_pchData = pData->data(); // data starts after wxStringData
366 m_pchData[0u] = '\0';
367 }
3168a13f
VZ
368 else if ( pData->IsShared() ) {
369 pData->Unlock(); // memory not freed because shared
c86f1403 370 size_t nOldLen = pData->nDataLength;
3168a13f 371 AllocBuffer(nLen);
9fbd8b8d 372 memcpy(m_pchData, pData->data(), nOldLen*sizeof(char));
3168a13f 373 }
dd1eaa89 374 else {
3168a13f
VZ
375 nLen += EXTRA_ALLOC;
376
dd1eaa89
VZ
377 wxStringData *p = (wxStringData *)
378 realloc(pData, sizeof(wxStringData) + (nLen + 1)*sizeof(char));
3168a13f
VZ
379
380 if ( p == NULL ) {
381 // @@@ what to do on memory error?
382 return;
dd1eaa89 383 }
3168a13f
VZ
384
385 // it's not important if the pointer changed or not (the check for this
386 // is not faster than assigning to m_pchData in all cases)
387 p->nAllocLength = nLen;
388 m_pchData = p->data();
dd1eaa89
VZ
389 }
390 }
391 //else: we've already got enough
392}
393
394// shrink to minimal size (releasing extra memory)
395void wxString::Shrink()
396{
397 wxStringData *pData = GetStringData();
3bbb630a
VZ
398
399 // this variable is unused in release build, so avoid the compiler warning by
400 // just not declaring it
401#ifdef __WXDEBUG__
402 void *p =
403#endif
404 realloc(pData, sizeof(wxStringData) + (pData->nDataLength + 1)*sizeof(char));
405
3168a13f 406 wxASSERT( p != NULL ); // can't free memory?
dd1eaa89
VZ
407 wxASSERT( p == pData ); // we're decrementing the size - block shouldn't move!
408}
409
c801d85f 410// get the pointer to writable buffer of (at least) nLen bytes
c86f1403 411char *wxString::GetWriteBuf(size_t nLen)
c801d85f
KB
412{
413 AllocBeforeWrite(nLen);
097c080b
VZ
414
415 wxASSERT( GetStringData()->nRefs == 1 );
416 GetStringData()->Validate(FALSE);
417
c801d85f
KB
418 return m_pchData;
419}
420
097c080b
VZ
421// put string back in a reasonable state after GetWriteBuf
422void wxString::UngetWriteBuf()
423{
424 GetStringData()->nDataLength = strlen(m_pchData);
425 GetStringData()->Validate(TRUE);
426}
427
c801d85f
KB
428// ---------------------------------------------------------------------------
429// data access
430// ---------------------------------------------------------------------------
431
432// all functions are inline in string.h
433
434// ---------------------------------------------------------------------------
435// assignment operators
436// ---------------------------------------------------------------------------
437
dd1eaa89 438// helper function: does real copy
c801d85f
KB
439void wxString::AssignCopy(size_t nSrcLen, const char *pszSrcData)
440{
441 if ( nSrcLen == 0 ) {
442 Reinit();
443 }
444 else {
445 AllocBeforeWrite(nSrcLen);
446 memcpy(m_pchData, pszSrcData, nSrcLen*sizeof(char));
447 GetStringData()->nDataLength = nSrcLen;
448 m_pchData[nSrcLen] = '\0';
449 }
450}
451
452// assigns one string to another
453wxString& wxString::operator=(const wxString& stringSrc)
454{
097c080b
VZ
455 wxASSERT( stringSrc.GetStringData()->IsValid() );
456
c801d85f
KB
457 // don't copy string over itself
458 if ( m_pchData != stringSrc.m_pchData ) {
459 if ( stringSrc.GetStringData()->IsEmpty() ) {
460 Reinit();
461 }
462 else {
463 // adjust references
464 GetStringData()->Unlock();
465 m_pchData = stringSrc.m_pchData;
466 GetStringData()->Lock();
467 }
468 }
469
470 return *this;
471}
472
473// assigns a single character
474wxString& wxString::operator=(char ch)
475{
476 AssignCopy(1, &ch);
477 return *this;
478}
479
480// assigns C string
481wxString& wxString::operator=(const char *psz)
482{
483 AssignCopy(Strlen(psz), psz);
484 return *this;
485}
486
487// same as 'signed char' variant
488wxString& wxString::operator=(const unsigned char* psz)
489{
490 *this = (const char *)psz;
491 return *this;
492}
493
494wxString& wxString::operator=(const wchar_t *pwz)
495{
496 wxString str(pwz);
497 *this = str;
498 return *this;
499}
500
501// ---------------------------------------------------------------------------
502// string concatenation
503// ---------------------------------------------------------------------------
504
c801d85f
KB
505// add something to this string
506void wxString::ConcatSelf(int nSrcLen, const char *pszSrcData)
507{
3168a13f 508 STATISTICS_ADD(SummandLength, nSrcLen);
c801d85f 509
05488905
VZ
510 // concatenating an empty string is a NOP
511 if ( nSrcLen > 0 ) {
512 wxStringData *pData = GetStringData();
513 size_t nLen = pData->nDataLength;
514 size_t nNewLen = nLen + nSrcLen;
c801d85f 515
05488905
VZ
516 // alloc new buffer if current is too small
517 if ( pData->IsShared() ) {
518 STATISTICS_ADD(ConcatHit, 0);
3168a13f 519
05488905
VZ
520 // we have to allocate another buffer
521 wxStringData* pOldData = GetStringData();
522 AllocBuffer(nNewLen);
523 memcpy(m_pchData, pOldData->data(), nLen*sizeof(char));
524 pOldData->Unlock();
525 }
526 else if ( nNewLen > pData->nAllocLength ) {
527 STATISTICS_ADD(ConcatHit, 0);
3168a13f 528
05488905
VZ
529 // we have to grow the buffer
530 Alloc(nNewLen);
531 }
532 else {
533 STATISTICS_ADD(ConcatHit, 1);
3168a13f 534
05488905
VZ
535 // the buffer is already big enough
536 }
3168a13f 537
05488905
VZ
538 // should be enough space
539 wxASSERT( nNewLen <= GetStringData()->nAllocLength );
3168a13f 540
05488905
VZ
541 // fast concatenation - all is done in our buffer
542 memcpy(m_pchData + nLen, pszSrcData, nSrcLen*sizeof(char));
3168a13f 543
05488905
VZ
544 m_pchData[nNewLen] = '\0'; // put terminating '\0'
545 GetStringData()->nDataLength = nNewLen; // and fix the length
546 }
547 //else: the string to append was empty
c801d85f
KB
548}
549
550/*
c801d85f
KB
551 * concatenation functions come in 5 flavours:
552 * string + string
553 * char + string and string + char
554 * C str + string and string + C str
555 */
556
557wxString operator+(const wxString& string1, const wxString& string2)
558{
097c080b
VZ
559 wxASSERT( string1.GetStringData()->IsValid() );
560 wxASSERT( string2.GetStringData()->IsValid() );
561
3168a13f
VZ
562 wxString s = string1;
563 s += string2;
564
c801d85f
KB
565 return s;
566}
567
3168a13f 568wxString operator+(const wxString& string, char ch)
c801d85f 569{
3168a13f
VZ
570 wxASSERT( string.GetStringData()->IsValid() );
571
572 wxString s = string;
573 s += ch;
097c080b 574
c801d85f
KB
575 return s;
576}
577
578wxString operator+(char ch, const wxString& string)
579{
097c080b
VZ
580 wxASSERT( string.GetStringData()->IsValid() );
581
3168a13f
VZ
582 wxString s = ch;
583 s += string;
584
c801d85f
KB
585 return s;
586}
587
588wxString operator+(const wxString& string, const char *psz)
589{
097c080b
VZ
590 wxASSERT( string.GetStringData()->IsValid() );
591
c801d85f 592 wxString s;
3168a13f
VZ
593 s.Alloc(Strlen(psz) + string.Len());
594 s = string;
595 s += psz;
596
c801d85f
KB
597 return s;
598}
599
600wxString operator+(const char *psz, const wxString& string)
601{
097c080b
VZ
602 wxASSERT( string.GetStringData()->IsValid() );
603
c801d85f 604 wxString s;
3168a13f
VZ
605 s.Alloc(Strlen(psz) + string.Len());
606 s = psz;
607 s += string;
608
c801d85f
KB
609 return s;
610}
611
612// ===========================================================================
613// other common string functions
614// ===========================================================================
615
616// ---------------------------------------------------------------------------
617// simple sub-string extraction
618// ---------------------------------------------------------------------------
619
620// helper function: clone the data attached to this string
621void wxString::AllocCopy(wxString& dest, int nCopyLen, int nCopyIndex) const
622{
3168a13f 623 if ( nCopyLen == 0 ) {
c801d85f
KB
624 dest.Init();
625 }
3168a13f 626 else {
c801d85f
KB
627 dest.AllocBuffer(nCopyLen);
628 memcpy(dest.m_pchData, m_pchData + nCopyIndex, nCopyLen*sizeof(char));
629 }
630}
631
632// extract string of length nCount starting at nFirst
c801d85f
KB
633wxString wxString::Mid(size_t nFirst, size_t nCount) const
634{
30d9011f
VZ
635 wxStringData *pData = GetStringData();
636 size_t nLen = pData->nDataLength;
637
638 // default value of nCount is STRING_MAXLEN and means "till the end"
639 if ( nCount == STRING_MAXLEN )
640 {
641 nCount = nLen - nFirst;
642 }
643
c801d85f 644 // out-of-bounds requests return sensible things
30d9011f
VZ
645 if ( nFirst + nCount > nLen )
646 {
647 nCount = nLen - nFirst;
648 }
c801d85f 649
30d9011f
VZ
650 if ( nFirst > nLen )
651 {
652 // AllocCopy() will return empty string
c801d85f 653 nCount = 0;
30d9011f 654 }
c801d85f
KB
655
656 wxString dest;
657 AllocCopy(dest, nCount, nFirst);
30d9011f 658
c801d85f
KB
659 return dest;
660}
661
662// extract nCount last (rightmost) characters
663wxString wxString::Right(size_t nCount) const
664{
665 if ( nCount > (size_t)GetStringData()->nDataLength )
666 nCount = GetStringData()->nDataLength;
667
668 wxString dest;
669 AllocCopy(dest, nCount, GetStringData()->nDataLength - nCount);
670 return dest;
671}
672
673// get all characters after the last occurence of ch
674// (returns the whole string if ch not found)
675wxString wxString::Right(char ch) const
676{
677 wxString str;
678 int iPos = Find(ch, TRUE);
679 if ( iPos == NOT_FOUND )
680 str = *this;
681 else
c8cfb486 682 str = c_str() + iPos + 1;
c801d85f
KB
683
684 return str;
685}
686
687// extract nCount first (leftmost) characters
688wxString wxString::Left(size_t nCount) const
689{
690 if ( nCount > (size_t)GetStringData()->nDataLength )
691 nCount = GetStringData()->nDataLength;
692
693 wxString dest;
694 AllocCopy(dest, nCount, 0);
695 return dest;
696}
697
698// get all characters before the first occurence of ch
699// (returns the whole string if ch not found)
700wxString wxString::Left(char ch) const
701{
702 wxString str;
703 for ( const char *pc = m_pchData; *pc != '\0' && *pc != ch; pc++ )
704 str += *pc;
705
706 return str;
707}
708
709/// get all characters before the last occurence of ch
710/// (returns empty string if ch not found)
711wxString wxString::Before(char ch) const
712{
713 wxString str;
714 int iPos = Find(ch, TRUE);
715 if ( iPos != NOT_FOUND && iPos != 0 )
d1c9bbf6 716 str = wxString(c_str(), iPos);
c801d85f
KB
717
718 return str;
719}
720
721/// get all characters after the first occurence of ch
722/// (returns empty string if ch not found)
723wxString wxString::After(char ch) const
724{
725 wxString str;
726 int iPos = Find(ch);
727 if ( iPos != NOT_FOUND )
728 str = c_str() + iPos + 1;
729
730 return str;
731}
732
733// replace first (or all) occurences of some substring with another one
c86f1403 734size_t wxString::Replace(const char *szOld, const char *szNew, bool bReplaceAll)
c801d85f 735{
c86f1403 736 size_t uiCount = 0; // count of replacements made
c801d85f 737
c86f1403 738 size_t uiOldLen = Strlen(szOld);
c801d85f
KB
739
740 wxString strTemp;
741 const char *pCurrent = m_pchData;
dd1eaa89 742 const char *pSubstr;
c801d85f
KB
743 while ( *pCurrent != '\0' ) {
744 pSubstr = strstr(pCurrent, szOld);
745 if ( pSubstr == NULL ) {
746 // strTemp is unused if no replacements were made, so avoid the copy
747 if ( uiCount == 0 )
748 return 0;
749
750 strTemp += pCurrent; // copy the rest
751 break; // exit the loop
752 }
753 else {
754 // take chars before match
755 strTemp.ConcatSelf(pSubstr - pCurrent, pCurrent);
756 strTemp += szNew;
757 pCurrent = pSubstr + uiOldLen; // restart after match
758
759 uiCount++;
760
761 // stop now?
762 if ( !bReplaceAll ) {
763 strTemp += pCurrent; // copy the rest
764 break; // exit the loop
765 }
766 }
767 }
768
769 // only done if there were replacements, otherwise would have returned above
770 *this = strTemp;
771
772 return uiCount;
773}
774
775bool wxString::IsAscii() const
776{
777 const char *s = (const char*) *this;
778 while(*s){
779 if(!isascii(*s)) return(FALSE);
780 s++;
781 }
782 return(TRUE);
783}
dd1eaa89 784
c801d85f
KB
785bool wxString::IsWord() const
786{
787 const char *s = (const char*) *this;
788 while(*s){
789 if(!isalpha(*s)) return(FALSE);
790 s++;
791 }
792 return(TRUE);
793}
dd1eaa89 794
c801d85f
KB
795bool wxString::IsNumber() const
796{
797 const char *s = (const char*) *this;
798 while(*s){
799 if(!isdigit(*s)) return(FALSE);
800 s++;
801 }
802 return(TRUE);
803}
804
c801d85f
KB
805wxString wxString::Strip(stripType w) const
806{
807 wxString s = *this;
808 if ( w & leading ) s.Trim(FALSE);
809 if ( w & trailing ) s.Trim(TRUE);
810 return s;
811}
812
c801d85f
KB
813// ---------------------------------------------------------------------------
814// case conversion
815// ---------------------------------------------------------------------------
816
817wxString& wxString::MakeUpper()
818{
819 CopyBeforeWrite();
820
821 for ( char *p = m_pchData; *p; p++ )
822 *p = (char)toupper(*p);
823
824 return *this;
825}
826
827wxString& wxString::MakeLower()
828{
829 CopyBeforeWrite();
dd1eaa89 830
c801d85f
KB
831 for ( char *p = m_pchData; *p; p++ )
832 *p = (char)tolower(*p);
833
834 return *this;
835}
836
837// ---------------------------------------------------------------------------
838// trimming and padding
839// ---------------------------------------------------------------------------
840
841// trims spaces (in the sense of isspace) from left or right side
842wxString& wxString::Trim(bool bFromRight)
843{
2c3b684c
VZ
844 // first check if we're going to modify the string at all
845 if ( !IsEmpty() &&
846 (
847 (bFromRight && isspace(GetChar(Len() - 1))) ||
848 (!bFromRight && isspace(GetChar(0u)))
849 )
850 )
c801d85f 851 {
2c3b684c
VZ
852 // ok, there is at least one space to trim
853 CopyBeforeWrite();
854
855 if ( bFromRight )
856 {
857 // find last non-space character
858 char *psz = m_pchData + GetStringData()->nDataLength - 1;
859 while ( isspace(*psz) && (psz >= m_pchData) )
860 psz--;
861
862 // truncate at trailing space start
863 *++psz = '\0';
864 GetStringData()->nDataLength = psz - m_pchData;
865 }
866 else
867 {
868 // find first non-space character
869 const char *psz = m_pchData;
870 while ( isspace(*psz) )
871 psz++;
872
873 // fix up data and length
874 int nDataLength = GetStringData()->nDataLength - (psz - m_pchData);
875 memmove(m_pchData, psz, (nDataLength + 1)*sizeof(char));
876 GetStringData()->nDataLength = nDataLength;
877 }
c801d85f
KB
878 }
879
880 return *this;
881}
882
883// adds nCount characters chPad to the string from either side
884wxString& wxString::Pad(size_t nCount, char chPad, bool bFromRight)
885{
886 wxString s(chPad, nCount);
887
888 if ( bFromRight )
889 *this += s;
890 else
891 {
892 s += *this;
893 *this = s;
894 }
895
896 return *this;
897}
898
899// truncate the string
900wxString& wxString::Truncate(size_t uiLen)
901{
79a773ba
VZ
902 if ( uiLen < Len() ) {
903 CopyBeforeWrite();
904
905 *(m_pchData + uiLen) = '\0';
906 GetStringData()->nDataLength = uiLen;
907 }
908 //else: nothing to do, string is already short enough
c801d85f
KB
909
910 return *this;
911}
912
913// ---------------------------------------------------------------------------
914// finding (return NOT_FOUND if not found and index otherwise)
915// ---------------------------------------------------------------------------
916
917// find a character
918int wxString::Find(char ch, bool bFromEnd) const
919{
920 const char *psz = bFromEnd ? strrchr(m_pchData, ch) : strchr(m_pchData, ch);
921
922 return (psz == NULL) ? NOT_FOUND : psz - m_pchData;
923}
924
925// find a sub-string (like strstr)
926int wxString::Find(const char *pszSub) const
927{
928 const char *psz = strstr(m_pchData, pszSub);
929
930 return (psz == NULL) ? NOT_FOUND : psz - m_pchData;
931}
932
7be07660
VZ
933// ---------------------------------------------------------------------------
934// stream-like operators
935// ---------------------------------------------------------------------------
936wxString& wxString::operator<<(int i)
937{
938 wxString res;
939 res.Printf("%d", i);
940
941 return (*this) << res;
942}
943
944wxString& wxString::operator<<(float f)
945{
946 wxString res;
947 res.Printf("%f", f);
948
949 return (*this) << res;
950}
951
952wxString& wxString::operator<<(double d)
953{
954 wxString res;
955 res.Printf("%g", d);
956
957 return (*this) << res;
958}
959
c801d85f 960// ---------------------------------------------------------------------------
9efd3367 961// formatted output
c801d85f
KB
962// ---------------------------------------------------------------------------
963int wxString::Printf(const char *pszFormat, ...)
964{
965 va_list argptr;
966 va_start(argptr, pszFormat);
967
968 int iLen = PrintfV(pszFormat, argptr);
969
970 va_end(argptr);
971
972 return iLen;
973}
974
975int wxString::PrintfV(const char* pszFormat, va_list argptr)
976{
7be07660 977 // static buffer to avoid dynamic memory allocation each time
9efd3367 978 static char s_szScratch[1024];
c801d85f 979
89b892a2
VZ
980 // NB: wxVsprintf() may return either less than the buffer size or -1 if there
981 // is not enough place depending on implementation
7be07660
VZ
982 int iLen = wxVsprintf(s_szScratch, WXSIZEOF(s_szScratch), pszFormat, argptr);
983 char *buffer;
89b892a2 984 if ( iLen < (int)WXSIZEOF(s_szScratch) ) {
7be07660
VZ
985 buffer = s_szScratch;
986 }
987 else {
988 int size = WXSIZEOF(s_szScratch) * 2;
989 buffer = (char *)malloc(size);
990 while ( buffer != NULL ) {
991 iLen = wxVsprintf(buffer, WXSIZEOF(s_szScratch), pszFormat, argptr);
992 if ( iLen < size ) {
993 // ok, there was enough space
994 break;
995 }
996
997 // still not enough, double it again
998 buffer = (char *)realloc(buffer, size *= 2);
999 }
1000
1001 if ( !buffer ) {
1002 // out of memory
1003 return -1;
1004 }
1005 }
1006
c801d85f 1007 AllocBeforeWrite(iLen);
7be07660
VZ
1008 strcpy(m_pchData, buffer);
1009
1010 if ( buffer != s_szScratch )
1011 free(buffer);
c801d85f
KB
1012
1013 return iLen;
1014}
1015
097c080b
VZ
1016// ----------------------------------------------------------------------------
1017// misc other operations
1018// ----------------------------------------------------------------------------
1019bool wxString::Matches(const char *pszMask) const
1020{
1021 // check char by char
1022 const char *pszTxt;
1023 for ( pszTxt = c_str(); *pszMask != '\0'; pszMask++, pszTxt++ ) {
1024 switch ( *pszMask ) {
1025 case '?':
1026 if ( *pszTxt == '\0' )
1027 return FALSE;
1028
1029 pszTxt++;
1030 pszMask++;
1031 break;
1032
1033 case '*':
1034 {
1035 // ignore special chars immediately following this one
1036 while ( *pszMask == '*' || *pszMask == '?' )
1037 pszMask++;
1038
1039 // if there is nothing more, match
1040 if ( *pszMask == '\0' )
1041 return TRUE;
1042
1043 // are there any other metacharacters in the mask?
c86f1403 1044 size_t uiLenMask;
097c080b
VZ
1045 const char *pEndMask = strpbrk(pszMask, "*?");
1046
1047 if ( pEndMask != NULL ) {
1048 // we have to match the string between two metachars
1049 uiLenMask = pEndMask - pszMask;
1050 }
1051 else {
1052 // we have to match the remainder of the string
1053 uiLenMask = strlen(pszMask);
1054 }
1055
1056 wxString strToMatch(pszMask, uiLenMask);
1057 const char* pMatch = strstr(pszTxt, strToMatch);
1058 if ( pMatch == NULL )
1059 return FALSE;
1060
1061 // -1 to compensate "++" in the loop
1062 pszTxt = pMatch + uiLenMask - 1;
1063 pszMask += uiLenMask - 1;
1064 }
1065 break;
1066
1067 default:
1068 if ( *pszMask != *pszTxt )
1069 return FALSE;
1070 break;
1071 }
1072 }
1073
1074 // match only if nothing left
1075 return *pszTxt == '\0';
1076}
1077
1fc5dd6f
JS
1078// Count the number of chars
1079int wxString::Freq(char ch) const
1080{
1081 int count = 0;
1082 int len = Len();
1083 for (int i = 0; i < len; i++)
1084 {
1085 if (GetChar(i) == ch)
1086 count ++;
1087 }
1088 return count;
1089}
1090
c801d85f
KB
1091// ---------------------------------------------------------------------------
1092// standard C++ library string functions
1093// ---------------------------------------------------------------------------
1094#ifdef STD_STRING_COMPATIBILITY
1095
1096wxString& wxString::insert(size_t nPos, const wxString& str)
1097{
097c080b 1098 wxASSERT( str.GetStringData()->IsValid() );
c801d85f
KB
1099 wxASSERT( nPos <= Len() );
1100
cb6780ff
VZ
1101 if ( !str.IsEmpty() ) {
1102 wxString strTmp;
1103 char *pc = strTmp.GetWriteBuf(Len() + str.Len());
1104 strncpy(pc, c_str(), nPos);
1105 strcpy(pc + nPos, str);
1106 strcpy(pc + nPos + str.Len(), c_str() + nPos);
1107 strTmp.UngetWriteBuf();
1108 *this = strTmp;
1109 }
dd1eaa89
VZ
1110
1111 return *this;
c801d85f
KB
1112}
1113
1114size_t wxString::find(const wxString& str, size_t nStart) const
1115{
097c080b 1116 wxASSERT( str.GetStringData()->IsValid() );
c801d85f
KB
1117 wxASSERT( nStart <= Len() );
1118
1119 const char *p = strstr(c_str() + nStart, str);
dd1eaa89 1120
c801d85f
KB
1121 return p == NULL ? npos : p - c_str();
1122}
1123
f0b3249b
JS
1124// VC++ 1.5 can't cope with the default argument in the header.
1125#if ! (defined(_MSC_VER) && !defined(__WIN32__))
c801d85f
KB
1126size_t wxString::find(const char* sz, size_t nStart, size_t n) const
1127{
1128 return find(wxString(sz, n == npos ? 0 : n), nStart);
1129}
f0b3249b 1130#endif
dd1eaa89 1131
62448488
JS
1132// Gives a duplicate symbol (presumably a case-insensitivity problem)
1133#if !defined(__BORLANDC__)
c801d85f
KB
1134size_t wxString::find(char ch, size_t nStart) const
1135{
1136 wxASSERT( nStart <= Len() );
1137
1138 const char *p = strchr(c_str() + nStart, ch);
dd1eaa89 1139
c801d85f
KB
1140 return p == NULL ? npos : p - c_str();
1141}
62448488 1142#endif
c801d85f
KB
1143
1144size_t wxString::rfind(const wxString& str, size_t nStart) const
1145{
097c080b 1146 wxASSERT( str.GetStringData()->IsValid() );
c801d85f
KB
1147 wxASSERT( nStart <= Len() );
1148
1149 // # could be quicker than that
1150 const char *p = c_str() + (nStart == npos ? Len() : nStart);
1151 while ( p >= c_str() + str.Len() ) {
1152 if ( strncmp(p - str.Len(), str, str.Len()) == 0 )
1153 return p - str.Len() - c_str();
1154 p--;
1155 }
dd1eaa89 1156
c801d85f
KB
1157 return npos;
1158}
dd1eaa89 1159
f0b3249b
JS
1160// VC++ 1.5 can't cope with the default argument in the header.
1161#if ! (defined(_MSC_VER) && !defined(__WIN32__))
c801d85f
KB
1162size_t wxString::rfind(const char* sz, size_t nStart, size_t n) const
1163{
1164 return rfind(wxString(sz, n == npos ? 0 : n), nStart);
1165}
1166
1167size_t wxString::rfind(char ch, size_t nStart) const
1168{
1169 wxASSERT( nStart <= Len() );
1170
1171 const char *p = strrchr(c_str() + nStart, ch);
dd1eaa89 1172
c801d85f
KB
1173 return p == NULL ? npos : p - c_str();
1174}
f0b3249b 1175#endif
c801d85f
KB
1176
1177wxString wxString::substr(size_t nStart, size_t nLen) const
1178{
1179 // npos means 'take all'
1180 if ( nLen == npos )
1181 nLen = 0;
1182
1183 wxASSERT( nStart + nLen <= Len() );
1184
1185 return wxString(c_str() + nStart, nLen == npos ? 0 : nLen);
1186}
1187
1188wxString& wxString::erase(size_t nStart, size_t nLen)
1189{
1190 wxString strTmp(c_str(), nStart);
1191 if ( nLen != npos ) {
1192 wxASSERT( nStart + nLen <= Len() );
1193
1194 strTmp.append(c_str() + nStart + nLen);
1195 }
1196
1197 *this = strTmp;
1198 return *this;
1199}
1200
1201wxString& wxString::replace(size_t nStart, size_t nLen, const char *sz)
1202{
1203 wxASSERT( nStart + nLen <= Strlen(sz) );
1204
1205 wxString strTmp;
1206 if ( nStart != 0 )
1207 strTmp.append(c_str(), nStart);
1208 strTmp += sz;
1209 strTmp.append(c_str() + nStart + nLen);
dd1eaa89 1210
c801d85f
KB
1211 *this = strTmp;
1212 return *this;
1213}
1214
1215wxString& wxString::replace(size_t nStart, size_t nLen, size_t nCount, char ch)
1216{
1217 return replace(nStart, nLen, wxString(ch, nCount));
1218}
1219
dd1eaa89 1220wxString& wxString::replace(size_t nStart, size_t nLen,
097c080b 1221 const wxString& str, size_t nStart2, size_t nLen2)
c801d85f
KB
1222{
1223 return replace(nStart, nLen, str.substr(nStart2, nLen2));
1224}
1225
dd1eaa89 1226wxString& wxString::replace(size_t nStart, size_t nLen,
c801d85f
KB
1227 const char* sz, size_t nCount)
1228{
1229 return replace(nStart, nLen, wxString(sz, nCount));
1230}
1231
1232#endif //std::string compatibility
1233
1234// ============================================================================
1235// ArrayString
1236// ============================================================================
1237
1238// size increment = max(50% of current size, ARRAY_MAXSIZE_INCREMENT)
1239#define ARRAY_MAXSIZE_INCREMENT 4096
1240#ifndef ARRAY_DEFAULT_INITIAL_SIZE // also defined in dynarray.h
1241 #define ARRAY_DEFAULT_INITIAL_SIZE (16)
1242#endif
1243
1244#define STRING(p) ((wxString *)(&(p)))
1245
1246// ctor
1247wxArrayString::wxArrayString()
1248{
1249 m_nSize =
1250 m_nCount = 0;
c67daf87 1251 m_pItems = (char **) NULL;
c801d85f
KB
1252}
1253
1254// copy ctor
1255wxArrayString::wxArrayString(const wxArrayString& src)
1256{
3bbb630a
VZ
1257 m_nSize =
1258 m_nCount = 0;
c67daf87 1259 m_pItems = (char **) NULL;
c801d85f 1260
4d14b524 1261 *this = src;
c801d85f
KB
1262}
1263
4d14b524 1264// assignment operator
c801d85f
KB
1265wxArrayString& wxArrayString::operator=(const wxArrayString& src)
1266{
d93f63db
VZ
1267 if ( m_nSize > 0 )
1268 Clear();
c801d85f 1269
4d14b524
VZ
1270 if ( src.m_nCount > ARRAY_DEFAULT_INITIAL_SIZE )
1271 Alloc(src.m_nCount);
c801d85f 1272
4d14b524
VZ
1273 // we can't just copy the pointers here because otherwise we would share
1274 // the strings with another array
c86f1403 1275 for ( size_t n = 0; n < src.m_nCount; n++ )
4d14b524 1276 Add(src[n]);
c801d85f 1277
3bbb630a
VZ
1278 if ( m_nCount != 0 )
1279 memcpy(m_pItems, src.m_pItems, m_nCount*sizeof(char *));
1280
c801d85f
KB
1281 return *this;
1282}
1283
1284// grow the array
1285void wxArrayString::Grow()
1286{
1287 // only do it if no more place
1288 if( m_nCount == m_nSize ) {
1289 if( m_nSize == 0 ) {
1290 // was empty, alloc some memory
1291 m_nSize = ARRAY_DEFAULT_INITIAL_SIZE;
1292 m_pItems = new char *[m_nSize];
1293 }
1294 else {
3bbb630a
VZ
1295 // otherwise when it's called for the first time, nIncrement would be 0
1296 // and the array would never be expanded
1297 wxASSERT( ARRAY_DEFAULT_INITIAL_SIZE != 0 );
1298
c801d85f 1299 // add 50% but not too much
3bbb630a 1300 size_t nIncrement = m_nSize < ARRAY_DEFAULT_INITIAL_SIZE
4d14b524 1301 ? ARRAY_DEFAULT_INITIAL_SIZE : m_nSize >> 1;
c801d85f
KB
1302 if ( nIncrement > ARRAY_MAXSIZE_INCREMENT )
1303 nIncrement = ARRAY_MAXSIZE_INCREMENT;
1304 m_nSize += nIncrement;
1305 char **pNew = new char *[m_nSize];
1306
1307 // copy data to new location
1308 memcpy(pNew, m_pItems, m_nCount*sizeof(char *));
1309
1310 // delete old memory (but do not release the strings!)
a3622daa 1311 wxDELETEA(m_pItems);
c801d85f
KB
1312
1313 m_pItems = pNew;
1314 }
1315 }
1316}
1317
1318void wxArrayString::Free()
1319{
1320 for ( size_t n = 0; n < m_nCount; n++ ) {
1321 STRING(m_pItems[n])->GetStringData()->Unlock();
1322 }
1323}
1324
1325// deletes all the strings from the list
1326void wxArrayString::Empty()
1327{
1328 Free();
1329
1330 m_nCount = 0;
1331}
1332
1333// as Empty, but also frees memory
1334void wxArrayString::Clear()
1335{
1336 Free();
1337
dd1eaa89 1338 m_nSize =
c801d85f
KB
1339 m_nCount = 0;
1340
a3622daa 1341 wxDELETEA(m_pItems);
c801d85f
KB
1342}
1343
1344// dtor
1345wxArrayString::~wxArrayString()
1346{
1347 Free();
1348
a3622daa 1349 wxDELETEA(m_pItems);
c801d85f
KB
1350}
1351
1352// pre-allocates memory (frees the previous data!)
1353void wxArrayString::Alloc(size_t nSize)
1354{
1355 wxASSERT( nSize > 0 );
1356
1357 // only if old buffer was not big enough
1358 if ( nSize > m_nSize ) {
1359 Free();
a3622daa 1360 wxDELETEA(m_pItems);
c801d85f
KB
1361 m_pItems = new char *[nSize];
1362 m_nSize = nSize;
1363 }
1364
1365 m_nCount = 0;
1366}
1367
1368// searches the array for an item (forward or backwards)
c801d85f
KB
1369int wxArrayString::Index(const char *sz, bool bCase, bool bFromEnd) const
1370{
1371 if ( bFromEnd ) {
1372 if ( m_nCount > 0 ) {
c86f1403 1373 size_t ui = m_nCount;
c801d85f
KB
1374 do {
1375 if ( STRING(m_pItems[--ui])->IsSameAs(sz, bCase) )
1376 return ui;
1377 }
1378 while ( ui != 0 );
1379 }
1380 }
1381 else {
c86f1403 1382 for( size_t ui = 0; ui < m_nCount; ui++ ) {
c801d85f
KB
1383 if( STRING(m_pItems[ui])->IsSameAs(sz, bCase) )
1384 return ui;
1385 }
1386 }
1387
1388 return NOT_FOUND;
1389}
1390
1391// add item at the end
097c080b 1392void wxArrayString::Add(const wxString& str)
c801d85f 1393{
097c080b
VZ
1394 wxASSERT( str.GetStringData()->IsValid() );
1395
c801d85f
KB
1396 Grow();
1397
1398 // the string data must not be deleted!
097c080b
VZ
1399 str.GetStringData()->Lock();
1400 m_pItems[m_nCount++] = (char *)str.c_str();
c801d85f
KB
1401}
1402
1403// add item at the given position
097c080b 1404void wxArrayString::Insert(const wxString& str, size_t nIndex)
c801d85f 1405{
097c080b
VZ
1406 wxASSERT( str.GetStringData()->IsValid() );
1407
1a5a8367 1408 wxCHECK_RET( nIndex <= m_nCount, ("bad index in wxArrayString::Insert") );
c801d85f
KB
1409
1410 Grow();
1411
dd1eaa89 1412 memmove(&m_pItems[nIndex + 1], &m_pItems[nIndex],
c801d85f
KB
1413 (m_nCount - nIndex)*sizeof(char *));
1414
097c080b
VZ
1415 str.GetStringData()->Lock();
1416 m_pItems[nIndex] = (char *)str.c_str();
c801d85f
KB
1417
1418 m_nCount++;
1419}
1420
1421// removes item from array (by index)
1422void wxArrayString::Remove(size_t nIndex)
1423{
1a5a8367 1424 wxCHECK_RET( nIndex <= m_nCount, _("bad index in wxArrayString::Remove") );
c801d85f
KB
1425
1426 // release our lock
1427 Item(nIndex).GetStringData()->Unlock();
1428
dd1eaa89 1429 memmove(&m_pItems[nIndex], &m_pItems[nIndex + 1],
c801d85f
KB
1430 (m_nCount - nIndex - 1)*sizeof(char *));
1431 m_nCount--;
1432}
1433
1434// removes item from array (by value)
1435void wxArrayString::Remove(const char *sz)
1436{
1437 int iIndex = Index(sz);
1438
9efd3367 1439 wxCHECK_RET( iIndex != NOT_FOUND,
1a5a8367 1440 _("removing inexistent element in wxArrayString::Remove") );
c801d85f 1441
c86f1403 1442 Remove(iIndex);
c801d85f
KB
1443}
1444
1445// sort array elements using passed comparaison function
1446
d355d3fe 1447void wxArrayString::Sort(bool WXUNUSED(bCase), bool WXUNUSED(bReverse) )
c801d85f
KB
1448{
1449 //@@@@ TO DO
1450 //qsort(m_pItems, m_nCount, sizeof(char *), fCmp);
1451}