1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxString and wxArrayString classes
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
13 Efficient string class [more or less] compatible with MFC CString,
14 wxWindows version 1 wxString and std::string and some handy functions
15 missing from string.h.
18 #ifndef _WX_WXSTRINGH__
19 #define _WX_WXSTRINGH__
21 #if defined(__GNUG__) && !defined(__APPLE__)
22 #pragma interface "string.h"
25 // ----------------------------------------------------------------------------
26 // conditinal compilation
27 // ----------------------------------------------------------------------------
29 // compile the std::string compatibility functions if defined
30 #define wxSTD_STRING_COMPATIBILITY
32 // ----------------------------------------------------------------------------
34 // ----------------------------------------------------------------------------
36 #include "wx/defs.h" // everybody should include this
38 #if defined(__WXMAC__) || defined(__VISAGECPP__)
46 #if defined(__VISAGECPP__) && __IBMCPP__ >= 400
47 // problem in VACPP V4 with including stdlib.h multiple times
48 // strconv includes it anyway
62 #include <strings.h> // for strcasecmp()
63 #endif // HAVE_STRINGS_H
65 #include "wx/wxchar.h" // for wxChar
66 #include "wx/buffer.h" // for wxCharBuffer
67 #include "wx/strconv.h" // for wxConvertXXX() macros and wxMBConv classes
69 // ---------------------------------------------------------------------------
71 // ---------------------------------------------------------------------------
73 // casts [unfortunately!] needed to call some broken functions which require
74 // "char *" instead of "const char *"
75 #define WXSTRINGCAST (wxChar *)(const wxChar *)
76 #define wxCSTRINGCAST (wxChar *)(const wxChar *)
77 #define wxMBSTRINGCAST (char *)(const char *)
78 #define wxWCSTRINGCAST (wchar_t *)(const wchar_t *)
80 // implementation only
81 #define wxASSERT_VALID_INDEX(i) \
82 wxASSERT_MSG( (size_t)(i) <= Len(), _T("invalid index in wxString") )
84 // ----------------------------------------------------------------------------
86 // ----------------------------------------------------------------------------
88 #if defined(__VISAGECPP__) && __IBMCPP__ >= 400
89 // must define this static for VA or else you get multiply defined symbols everywhere
90 extern const unsigned int wxSTRING_MAXLEN
;
93 // maximum possible length for a string means "take all string" everywhere
94 // (as sizeof(StringData) is unknown here, we substract 100)
95 const unsigned int wxSTRING_MAXLEN
= UINT_MAX
- 100;
99 // ----------------------------------------------------------------------------
101 // ----------------------------------------------------------------------------
103 // global pointer to empty string
104 WXDLLEXPORT_DATA(extern const wxChar
*) wxEmptyString
;
106 // ---------------------------------------------------------------------------
107 // global functions complementing standard C string library replacements for
108 // strlen() and portable strcasecmp()
109 //---------------------------------------------------------------------------
111 // Use wxXXX() functions from wxchar.h instead! These functions are for
112 // backwards compatibility only.
114 // checks whether the passed in pointer is NULL and if the string is empty
115 inline bool IsEmpty(const char *p
) { return (!p
|| !*p
); }
117 // safe version of strlen() (returns 0 if passed NULL pointer)
118 inline size_t Strlen(const char *psz
)
119 { return psz
? strlen(psz
) : 0; }
121 // portable strcasecmp/_stricmp
122 inline int Stricmp(const char *psz1
, const char *psz2
)
124 #if defined(__VISUALC__) || ( defined(__MWERKS__) && defined(__INTEL__) )
125 return _stricmp(psz1
, psz2
);
126 #elif defined(__SC__)
127 return _stricmp(psz1
, psz2
);
128 #elif defined(__SALFORDC__)
129 return stricmp(psz1
, psz2
);
130 #elif defined(__BORLANDC__)
131 return stricmp(psz1
, psz2
);
132 #elif defined(__WATCOMC__)
133 return stricmp(psz1
, psz2
);
134 #elif defined(__DJGPP__)
135 return stricmp(psz1
, psz2
);
136 #elif defined(__EMX__)
137 return stricmp(psz1
, psz2
);
138 #elif defined(__WXPM__)
139 return stricmp(psz1
, psz2
);
140 #elif defined(__UNIX__) || defined(__GNUWIN32__)
141 return strcasecmp(psz1
, psz2
);
142 #elif defined(__MWERKS__) && !defined(__INTEL__)
143 register char c1
, c2
;
145 c1
= tolower(*psz1
++);
146 c2
= tolower(*psz2
++);
147 } while ( c1
&& (c1
== c2
) );
151 // almost all compilers/libraries provide this function (unfortunately under
152 // different names), that's why we don't implement our own which will surely
153 // be more efficient than this code (uncomment to use):
155 register char c1, c2;
157 c1 = tolower(*psz1++);
158 c2 = tolower(*psz2++);
159 } while ( c1 && (c1 == c2) );
164 #error "Please define string case-insensitive compare for your OS/compiler"
165 #endif // OS/compiler
168 // return an empty wxString
169 class WXDLLEXPORT wxString
; // not yet defined
170 inline const wxString
& wxGetEmptyString() { return *(wxString
*)&wxEmptyString
; }
172 // ---------------------------------------------------------------------------
173 // string data prepended with some housekeeping info (used by wxString class),
174 // is never used directly (but had to be put here to allow inlining)
175 // ---------------------------------------------------------------------------
177 struct WXDLLEXPORT wxStringData
179 int nRefs
; // reference count
180 size_t nDataLength
, // actual string length
181 nAllocLength
; // allocated memory size
183 // mimics declaration 'wxChar data[nAllocLength]'
184 wxChar
* data() const { return (wxChar
*)(this + 1); }
186 // empty string has a special ref count so it's never deleted
187 bool IsEmpty() const { return (nRefs
== -1); }
188 bool IsShared() const { return (nRefs
> 1); }
191 void Lock() { if ( !IsEmpty() ) nRefs
++; }
193 // VC++ will refuse to inline this function but profiling shows that it
195 #if defined(__VISUALC__) && (__VISUALC__ >= 1200)
198 void Unlock() { if ( !IsEmpty() && --nRefs
== 0) Free(); }
200 // VC++ free must take place in same DLL as allocation when using non dll
201 // run-time library (e.g. Multithreaded instead of Multithreaded DLL)
202 // we must not inline deallocation since allocation is not inlined
205 // if we had taken control over string memory (GetWriteBuf), it's
206 // intentionally put in invalid state
207 void Validate(bool b
) { nRefs
= (b
? 1 : 0); }
208 bool IsValid() const { return (nRefs
!= 0); }
211 // ---------------------------------------------------------------------------
212 // This is (yet another one) String class for C++ programmers. It doesn't use
213 // any of "advanced" C++ features (i.e. templates, exceptions, namespaces...)
214 // thus you should be able to compile it with practicaly any C++ compiler.
215 // This class uses copy-on-write technique, i.e. identical strings share the
216 // same memory as long as neither of them is changed.
218 // This class aims to be as compatible as possible with the new standard
219 // std::string class, but adds some additional functions and should be at
220 // least as efficient than the standard implementation.
222 // Performance note: it's more efficient to write functions which take "const
223 // String&" arguments than "const char *" if you assign the argument to
226 // It was compiled and tested under Win32, Linux (libc 5 & 6), Solaris 5.5.
229 // - ressource support (string tables in ressources)
230 // - more wide character (UNICODE) support
231 // - regular expressions support
232 // ---------------------------------------------------------------------------
234 class WXDLLEXPORT wxString
236 friend class WXDLLEXPORT wxArrayString
;
238 // NB: special care was taken in arranging the member functions in such order
239 // that all inline functions can be effectively inlined, verify that all
240 // performace critical functions are still inlined if you change order!
242 // points to data preceded by wxStringData structure with ref count info
245 // accessor to string data
246 wxStringData
* GetStringData() const { return (wxStringData
*)m_pchData
- 1; }
248 // string (re)initialization functions
249 // initializes the string to the empty value (must be called only from
250 // ctors, use Reinit() otherwise)
251 void Init() { m_pchData
= (wxChar
*)wxEmptyString
; }
252 // initializaes the string with (a part of) C-string
253 void InitWith(const wxChar
*psz
, size_t nPos
= 0, size_t nLen
= wxSTRING_MAXLEN
);
254 // as Init, but also frees old data
255 void Reinit() { GetStringData()->Unlock(); Init(); }
258 // allocates memory for string of length nLen
259 bool AllocBuffer(size_t nLen
);
260 // copies data to another string
261 bool AllocCopy(wxString
&, int, int) const;
262 // effectively copies data to string
263 bool AssignCopy(size_t, const wxChar
*);
265 // append a (sub)string
266 bool ConcatSelf(size_t nLen
, const wxChar
*src
);
268 // functions called before writing to the string: they copy it if there
269 // are other references to our data (should be the only owner when writing)
270 bool CopyBeforeWrite();
271 bool AllocBeforeWrite(size_t);
273 // if we hadn't made these operators private, it would be possible to
274 // compile "wxString s; s = 17;" without any warnings as 17 is implicitly
275 // converted to char in C and we do have operator=(char)
277 // NB: we don't need other versions (short/long and unsigned) as attempt
278 // to assign another numeric type to wxString will now result in
279 // ambiguity between operator=(char) and operator=(int)
280 wxString
& operator=(int);
282 // these methods are not implemented - there is _no_ conversion from int to
283 // string, you're doing something wrong if the compiler wants to call it!
285 // try `s << i' or `s.Printf("%d", i)' instead
289 // constructors and destructor
290 // ctor for an empty string
291 wxString() : m_pchData(NULL
) { Init(); }
293 wxString(const wxString
& stringSrc
) : m_pchData(NULL
)
295 wxASSERT_MSG( stringSrc
.GetStringData()->IsValid(),
296 _T("did you forget to call UngetWriteBuf()?") );
298 if ( stringSrc
.IsEmpty() ) {
299 // nothing to do for an empty string
303 m_pchData
= stringSrc
.m_pchData
; // share same data
304 GetStringData()->Lock(); // => one more copy
307 // string containing nRepeat copies of ch
308 wxString(wxChar ch
, size_t nRepeat
= 1);
309 // ctor takes first nLength characters from C string
310 // (default value of wxSTRING_MAXLEN means take all the string)
311 wxString(const wxChar
*psz
, size_t nLength
= wxSTRING_MAXLEN
)
313 { InitWith(psz
, 0, nLength
); }
314 wxString(const wxChar
*psz
, wxMBConv
& WXUNUSED(conv
), size_t nLength
= wxSTRING_MAXLEN
)
316 { InitWith(psz
, 0, nLength
); }
319 // from multibyte string
320 // (NB: nLength is right now number of Unicode characters, not
321 // characters in psz! So try not to use it yet!)
322 wxString(const char *psz
, wxMBConv
& conv
, size_t nLength
= wxSTRING_MAXLEN
);
323 // from wxWCharBuffer (i.e. return from wxGetString)
324 wxString(const wxWCharBuffer
& psz
)
325 { InitWith(psz
, 0, wxSTRING_MAXLEN
); }
327 // from C string (for compilers using unsigned char)
328 wxString(const unsigned char* psz
, size_t nLength
= wxSTRING_MAXLEN
)
330 { InitWith((const char*)psz
, 0, nLength
); }
333 // from wide (Unicode) string
334 wxString(const wchar_t *pwz
, wxMBConv
& conv
= wxConvLibc
, size_t nLength
= wxSTRING_MAXLEN
);
335 #endif // !wxUSE_WCHAR_T
338 wxString(const wxCharBuffer
& psz
)
340 { InitWith(psz
, 0, wxSTRING_MAXLEN
); }
341 #endif // Unicode/ANSI
343 // dtor is not virtual, this class must not be inherited from!
344 ~wxString() { GetStringData()->Unlock(); }
346 // generic attributes & operations
347 // as standard strlen()
348 size_t Len() const { return GetStringData()->nDataLength
; }
349 // string contains any characters?
350 bool IsEmpty() const { return Len() == 0; }
351 // empty string is "FALSE", so !str will return TRUE
352 bool operator!() const { return IsEmpty(); }
353 // truncate the string to given length
354 wxString
& Truncate(size_t uiLen
);
355 // empty string contents
360 wxASSERT_MSG( IsEmpty(), _T("string not empty after call to Empty()?") );
362 // empty the string and free memory
365 if ( !GetStringData()->IsEmpty() )
368 wxASSERT_MSG( !GetStringData()->nDataLength
&&
369 !GetStringData()->nAllocLength
,
370 _T("string should be empty after Clear()") );
375 bool IsAscii() const;
377 bool IsNumber() const;
381 // data access (all indexes are 0 based)
383 wxChar
GetChar(size_t n
) const
384 { wxASSERT_VALID_INDEX( n
); return m_pchData
[n
]; }
386 wxChar
& GetWritableChar(size_t n
)
387 { wxASSERT_VALID_INDEX( n
); CopyBeforeWrite(); return m_pchData
[n
]; }
389 void SetChar(size_t n
, wxChar ch
)
390 { wxASSERT_VALID_INDEX( n
); CopyBeforeWrite(); m_pchData
[n
] = ch
; }
392 // get last character
395 wxASSERT_MSG( !IsEmpty(), _T("wxString: index out of bounds") );
397 return m_pchData
[Len() - 1];
400 // get writable last character
403 wxASSERT_MSG( !IsEmpty(), _T("wxString: index out of bounds") );
405 return m_pchData
[Len()-1];
409 So why do we have all these overloaded operator[]s? A bit of history:
410 initially there was only one of them, taking size_t. Then people
411 started complaining because they wanted to use ints as indices (I
412 wonder why) and compilers were giving warnings about it, so we had to
413 add the operator[](int). Then it became apparent that you couldn't
414 write str[0] any longer because there was ambiguity between two
415 overloads and so you now had to write str[0u] (or, of course, use the
416 explicit casts to either int or size_t but nobody did this).
418 Finally, someone decided to compile wxWin on an Alpha machine and got
419 a surprize: str[0u] didn't compile there because it is of type
420 unsigned int and size_t is unsigned _long_ on Alpha and so there was
421 ambiguity between converting uint to int or ulong. To fix this one we
422 now add operator[](uint) for the machines where size_t is not already
423 the same as unsigned int - hopefully this fixes the problem (for some
426 The only real fix is, of course, to remove all versions but the one
430 // operator version of GetChar
431 wxChar
operator[](size_t n
) const
432 { wxASSERT_VALID_INDEX( n
); return m_pchData
[n
]; }
434 // operator version of GetChar
435 wxChar
operator[](int n
) const
436 { wxASSERT_VALID_INDEX( n
); return m_pchData
[n
]; }
438 // operator version of GetWriteableChar
439 wxChar
& operator[](size_t n
)
440 { wxASSERT_VALID_INDEX( n
); CopyBeforeWrite(); return m_pchData
[n
]; }
442 #ifndef wxSIZE_T_IS_UINT
443 // operator version of GetChar
444 wxChar
operator[](unsigned int n
) const
445 { wxASSERT_VALID_INDEX( n
); return m_pchData
[n
]; }
447 // operator version of GetWriteableChar
448 wxChar
& operator[](unsigned int n
)
449 { wxASSERT_VALID_INDEX( n
); CopyBeforeWrite(); return m_pchData
[n
]; }
450 #endif // size_t != unsigned int
452 // implicit conversion to C string
453 operator const wxChar
*() const { return m_pchData
; }
455 // explicit conversion to C string (use this with printf()!)
456 const wxChar
* c_str() const { return m_pchData
; }
457 // identical to c_str(), for wxWin 1.6x compatibility
458 const wxChar
* wx_str() const { return m_pchData
; }
459 // identical to c_str(), for MFC compatibility
460 const wxChar
* GetData() const { return m_pchData
; }
462 // conversion to/from plain (i.e. 7 bit) ASCII: this is useful for
463 // converting numbers or strings which are certain not to contain special
464 // chars (typically system functions, X atoms, environment variables etc.)
466 // the behaviour of these functions with the strings containing anything
467 // else than 7 bit ASCII characters is undefined, use at your own risk.
469 static wxString
FromAscii(const char *ascii
); // string
470 static wxString
FromAscii(const char ascii
); // char
471 const wxCharBuffer
ToAscii() const;
473 static wxString
FromAscii(const char *ascii
) { return wxString( ascii
); }
474 static wxString
FromAscii(const char ascii
) { return wxString( ascii
); }
475 const char *ToAscii() const { return c_str(); }
476 #endif // Unicode/!Unicode
478 // conversions with (possible) format conversions: have to return a
479 // buffer with temporary data
481 // the functions defined (in either Unicode or ANSI) mode are mb_str() to
482 // return an ANSI (multibyte) string, wc_str() to return a wide string and
483 // fn_str() to return a string which should be used with the OS APIs
484 // accepting the file names. The return value is always the same, but the
485 // type differs because a function may either return pointer to the buffer
486 // directly or have to use intermediate buffer for translation.
488 const wxCharBuffer
mb_str(wxMBConv
& conv
= wxConvLibc
) const
489 { return conv
.cWC2MB(m_pchData
); }
491 const wxWX2MBbuf
mbc_str() const { return mb_str(*wxConvCurrent
); }
493 const wxChar
* wc_str() const { return m_pchData
; }
495 // for compatibility with !wxUSE_UNICODE version
496 const wxChar
* wc_str(wxMBConv
& WXUNUSED(conv
)) const { return m_pchData
; }
499 const wxCharBuffer
fn_str() const { return mb_str(wxConvFile
); }
501 const wxChar
* fn_str() const { return m_pchData
; }
502 #endif // wxMBFILES/!wxMBFILES
504 const wxChar
* mb_str() const { return m_pchData
; }
506 // for compatibility with wxUSE_UNICODE version
507 const wxChar
* mb_str(wxMBConv
& WXUNUSED(conv
)) const { return m_pchData
; }
509 const wxWX2MBbuf
mbc_str() const { return mb_str(); }
512 const wxWCharBuffer
wc_str(wxMBConv
& conv
) const
513 { return conv
.cMB2WC(m_pchData
); }
514 #endif // wxUSE_WCHAR_T
516 const wxChar
* fn_str() const { return m_pchData
; }
517 #endif // Unicode/ANSI
519 // overloaded assignment
520 // from another wxString
521 wxString
& operator=(const wxString
& stringSrc
);
523 wxString
& operator=(wxChar ch
);
525 wxString
& operator=(const wxChar
*psz
);
527 // from wxWCharBuffer
528 wxString
& operator=(const wxWCharBuffer
& psz
)
529 { (void) operator=((const wchar_t *)psz
); return *this; }
531 // from another kind of C string
532 wxString
& operator=(const unsigned char* psz
);
534 // from a wide string
535 wxString
& operator=(const wchar_t *pwz
);
538 wxString
& operator=(const wxCharBuffer
& psz
)
539 { (void) operator=((const char *)psz
); return *this; }
540 #endif // Unicode/ANSI
542 // string concatenation
543 // in place concatenation
545 Concatenate and return the result. Note that the left to right
546 associativity of << allows to write things like "str << str1 << str2
547 << ..." (unlike with +=)
550 wxString
& operator<<(const wxString
& s
)
552 wxASSERT_MSG( s
.GetStringData()->IsValid(),
553 _T("did you forget to call UngetWriteBuf()?") );
555 ConcatSelf(s
.Len(), s
);
558 // string += C string
559 wxString
& operator<<(const wxChar
*psz
)
560 { ConcatSelf(wxStrlen(psz
), psz
); return *this; }
562 wxString
& operator<<(wxChar ch
) { ConcatSelf(1, &ch
); return *this; }
565 void operator+=(const wxString
& s
) { (void)operator<<(s
); }
566 // string += C string
567 void operator+=(const wxChar
*psz
) { (void)operator<<(psz
); }
569 void operator+=(wxChar ch
) { (void)operator<<(ch
); }
571 // string += buffer (i.e. from wxGetString)
573 wxString
& operator<<(const wxWCharBuffer
& s
)
574 { (void)operator<<((const wchar_t *)s
); return *this; }
575 void operator+=(const wxWCharBuffer
& s
)
576 { (void)operator<<((const wchar_t *)s
); }
577 #else // !wxUSE_UNICODE
578 wxString
& operator<<(const wxCharBuffer
& s
)
579 { (void)operator<<((const char *)s
); return *this; }
580 void operator+=(const wxCharBuffer
& s
)
581 { (void)operator<<((const char *)s
); }
582 #endif // wxUSE_UNICODE/!wxUSE_UNICODE
584 // string += C string
585 wxString
& Append(const wxString
& s
)
587 // test for IsEmpty() to share the string if possible
591 ConcatSelf(s
.Length(), s
.c_str());
594 wxString
& Append(const wxChar
* psz
)
595 { ConcatSelf(wxStrlen(psz
), psz
); return *this; }
596 // append count copies of given character
597 wxString
& Append(wxChar ch
, size_t count
= 1u)
598 { wxString
str(ch
, count
); return *this << str
; }
599 wxString
& Append(const wxChar
* psz
, size_t nLen
)
600 { ConcatSelf(nLen
, psz
); return *this; }
602 // prepend a string, return the string itself
603 wxString
& Prepend(const wxString
& str
)
604 { *this = str
+ *this; return *this; }
606 // non-destructive concatenation
608 friend wxString WXDLLEXPORT
operator+(const wxString
& string1
, const wxString
& string2
);
610 friend wxString WXDLLEXPORT
operator+(const wxString
& string
, wxChar ch
);
612 friend wxString WXDLLEXPORT
operator+(wxChar ch
, const wxString
& string
);
614 friend wxString WXDLLEXPORT
operator+(const wxString
& string
, const wxChar
*psz
);
616 friend wxString WXDLLEXPORT
operator+(const wxChar
*psz
, const wxString
& string
);
618 // stream-like functions
619 // insert an int into string
620 wxString
& operator<<(int i
)
621 { return (*this) << Format(_T("%d"), i
); }
622 // insert an unsigned int into string
623 wxString
& operator<<(unsigned int ui
)
624 { return (*this) << Format(_T("%u"), ui
); }
625 // insert a long into string
626 wxString
& operator<<(long l
)
627 { return (*this) << Format(_T("%ld"), l
); }
628 // insert an unsigned long into string
629 wxString
& operator<<(unsigned long ul
)
630 { return (*this) << Format(_T("%lu"), ul
); }
631 // insert a float into string
632 wxString
& operator<<(float f
)
633 { return (*this) << Format(_T("%f"), f
); }
634 // insert a double into string
635 wxString
& operator<<(double d
)
636 { return (*this) << Format(_T("%g"), d
); }
639 // case-sensitive comparison (returns a value < 0, = 0 or > 0)
640 int Cmp(const wxChar
*psz
) const { return wxStrcmp(c_str(), psz
); }
641 // same as Cmp() but not case-sensitive
642 int CmpNoCase(const wxChar
*psz
) const { return wxStricmp(c_str(), psz
); }
643 // test for the string equality, either considering case or not
644 // (if compareWithCase then the case matters)
645 bool IsSameAs(const wxChar
*psz
, bool compareWithCase
= TRUE
) const
646 { return (compareWithCase
? Cmp(psz
) : CmpNoCase(psz
)) == 0; }
647 // comparison with a signle character: returns TRUE if equal
648 bool IsSameAs(wxChar c
, bool compareWithCase
= TRUE
) const
650 return (Len() == 1) && (compareWithCase
? GetChar(0u) == c
651 : wxToupper(GetChar(0u)) == wxToupper(c
));
654 // simple sub-string extraction
655 // return substring starting at nFirst of length nCount (or till the end
656 // if nCount = default value)
657 wxString
Mid(size_t nFirst
, size_t nCount
= wxSTRING_MAXLEN
) const;
659 // operator version of Mid()
660 wxString
operator()(size_t start
, size_t len
) const
661 { return Mid(start
, len
); }
663 // check that the string starts with prefix and return the rest of the
664 // string in the provided pointer if it is not NULL, otherwise return
666 bool StartsWith(const wxChar
*prefix
, wxString
*rest
= NULL
) const;
668 // get first nCount characters
669 wxString
Left(size_t nCount
) const;
670 // get last nCount characters
671 wxString
Right(size_t nCount
) const;
672 // get all characters before the first occurance of ch
673 // (returns the whole string if ch not found)
674 wxString
BeforeFirst(wxChar ch
) const;
675 // get all characters before the last occurence of ch
676 // (returns empty string if ch not found)
677 wxString
BeforeLast(wxChar ch
) const;
678 // get all characters after the first occurence of ch
679 // (returns empty string if ch not found)
680 wxString
AfterFirst(wxChar ch
) const;
681 // get all characters after the last occurence of ch
682 // (returns the whole string if ch not found)
683 wxString
AfterLast(wxChar ch
) const;
685 // for compatibility only, use more explicitly named functions above
686 wxString
Before(wxChar ch
) const { return BeforeLast(ch
); }
687 wxString
After(wxChar ch
) const { return AfterFirst(ch
); }
690 // convert to upper case in place, return the string itself
691 wxString
& MakeUpper();
692 // convert to upper case, return the copy of the string
693 // Here's something to remember: BC++ doesn't like returns in inlines.
694 wxString
Upper() const ;
695 // convert to lower case in place, return the string itself
696 wxString
& MakeLower();
697 // convert to lower case, return the copy of the string
698 wxString
Lower() const ;
700 // trimming/padding whitespace (either side) and truncating
701 // remove spaces from left or from right (default) side
702 wxString
& Trim(bool bFromRight
= TRUE
);
703 // add nCount copies chPad in the beginning or at the end (default)
704 wxString
& Pad(size_t nCount
, wxChar chPad
= wxT(' '), bool bFromRight
= TRUE
);
706 // searching and replacing
707 // searching (return starting index, or -1 if not found)
708 int Find(wxChar ch
, bool bFromEnd
= FALSE
) const; // like strchr/strrchr
709 // searching (return starting index, or -1 if not found)
710 int Find(const wxChar
*pszSub
) const; // like strstr
711 // replace first (or all of bReplaceAll) occurences of substring with
712 // another string, returns the number of replacements made
713 size_t Replace(const wxChar
*szOld
,
715 bool bReplaceAll
= TRUE
);
717 // check if the string contents matches a mask containing '*' and '?'
718 bool Matches(const wxChar
*szMask
) const;
720 // conversion to numbers: all functions return TRUE only if the whole
721 // string is a number and put the value of this number into the pointer
722 // provided, the base is the numeric base in which the conversion should be
723 // done and must be comprised between 2 and 36 or be 0 in which case the
724 // standard C rules apply (leading '0' => octal, "0x" => hex)
725 // convert to a signed integer
726 bool ToLong(long *val
, int base
= 10) const;
727 // convert to an unsigned integer
728 bool ToULong(unsigned long *val
, int base
= 10) const;
729 // convert to a double
730 bool ToDouble(double *val
) const;
732 // formated input/output
733 // as sprintf(), returns the number of characters written or < 0 on error
734 // (take 'this' into account in attribute parameter count)
735 int Printf(const wxChar
*pszFormat
, ...) ATTRIBUTE_PRINTF_2
;
736 // as vprintf(), returns the number of characters written or < 0 on error
737 int PrintfV(const wxChar
* pszFormat
, va_list argptr
);
739 // returns the string containing the result of Printf() to it
740 static wxString
Format(const wxChar
*pszFormat
, ...) ATTRIBUTE_PRINTF_1
;
741 // the same as above, but takes a va_list
742 static wxString
FormatV(const wxChar
*pszFormat
, va_list argptr
);
744 // raw access to string memory
745 // ensure that string has space for at least nLen characters
746 // only works if the data of this string is not shared
747 bool Alloc(size_t nLen
);
748 // minimize the string's memory
749 // only works if the data of this string is not shared
751 // get writable buffer of at least nLen bytes. Unget() *must* be called
752 // a.s.a.p. to put string back in a reasonable state!
753 wxChar
*GetWriteBuf(size_t nLen
);
754 // call this immediately after GetWriteBuf() has been used
755 void UngetWriteBuf();
756 void UngetWriteBuf(size_t nLen
);
758 // wxWindows version 1 compatibility functions
761 wxString
SubString(size_t from
, size_t to
) const
762 { return Mid(from
, (to
- from
+ 1)); }
763 // values for second parameter of CompareTo function
764 enum caseCompare
{exact
, ignoreCase
};
765 // values for first parameter of Strip function
766 enum stripType
{leading
= 0x1, trailing
= 0x2, both
= 0x3};
769 // (take 'this' into account in attribute parameter count)
770 int sprintf(const wxChar
*pszFormat
, ...) ATTRIBUTE_PRINTF_2
;
773 inline int CompareTo(const wxChar
* psz
, caseCompare cmp
= exact
) const
774 { return cmp
== exact
? Cmp(psz
) : CmpNoCase(psz
); }
777 size_t Length() const { return Len(); }
778 // Count the number of characters
779 int Freq(wxChar ch
) const;
781 void LowerCase() { MakeLower(); }
783 void UpperCase() { MakeUpper(); }
784 // use Trim except that it doesn't change this string
785 wxString
Strip(stripType w
= trailing
) const;
787 // use Find (more general variants not yet supported)
788 size_t Index(const wxChar
* psz
) const { return Find(psz
); }
789 size_t Index(wxChar ch
) const { return Find(ch
); }
791 wxString
& Remove(size_t pos
) { return Truncate(pos
); }
792 wxString
& RemoveLast(size_t n
= 1) { return Truncate(Len() - n
); }
794 wxString
& Remove(size_t nStart
, size_t nLen
) { return erase( nStart
, nLen
); }
797 int First( const wxChar ch
) const { return Find(ch
); }
798 int First( const wxChar
* psz
) const { return Find(psz
); }
799 int First( const wxString
&str
) const { return Find(str
); }
800 int Last( const wxChar ch
) const { return Find(ch
, TRUE
); }
801 bool Contains(const wxString
& str
) const { return Find(str
) != -1; }
804 bool IsNull() const { return IsEmpty(); }
806 #ifdef wxSTD_STRING_COMPATIBILITY
807 // std::string compatibility functions
810 typedef wxChar value_type
;
811 typedef size_t size_type
;
812 typedef value_type
*iterator
;
813 typedef const value_type
*const_iterator
;
815 // an 'invalid' value for string index
816 static const size_t npos
;
819 // take nLen chars starting at nPos
820 wxString(const wxString
& str
, size_t nPos
, size_t nLen
)
823 wxASSERT_MSG( str
.GetStringData()->IsValid(),
824 _T("did you forget to call UngetWriteBuf()?") );
826 InitWith(str
.c_str(), nPos
, nLen
== npos
? 0 : nLen
);
828 // take all characters from pStart to pEnd
829 wxString(const void *pStart
, const void *pEnd
);
831 // lib.string.capacity
832 // return the length of the string
833 size_t size() const { return Len(); }
834 // return the length of the string
835 size_t length() const { return Len(); }
836 // return the maximum size of the string
837 size_t max_size() const { return wxSTRING_MAXLEN
; }
838 // resize the string, filling the space with c if c != 0
839 void resize(size_t nSize
, wxChar ch
= wxT('\0'));
840 // delete the contents of the string
841 void clear() { Empty(); }
842 // returns true if the string is empty
843 bool empty() const { return IsEmpty(); }
844 // inform string about planned change in size
845 void reserve(size_t sz
) { Alloc(sz
); }
848 // return the character at position n
849 wxChar
at(size_t n
) const { return GetChar(n
); }
850 // returns the writable character at position n
851 wxChar
& at(size_t n
) { return GetWritableChar(n
); }
853 // first valid index position
854 const_iterator
begin() const { return wx_str(); }
855 // position one after the last valid one
856 const_iterator
end() const { return wx_str() + length(); }
858 // first valid index position
859 iterator
begin() { CopyBeforeWrite(); return m_pchData
; }
860 // position one after the last valid one
861 iterator
end() { CopyBeforeWrite(); return m_pchData
+ length(); }
863 // lib.string.modifiers
865 wxString
& append(const wxString
& str
)
866 { *this += str
; return *this; }
867 // append elements str[pos], ..., str[pos+n]
868 wxString
& append(const wxString
& str
, size_t pos
, size_t n
)
869 { ConcatSelf(n
, str
.c_str() + pos
); return *this; }
870 // append first n (or all if n == npos) characters of sz
871 wxString
& append(const wxChar
*sz
, size_t n
= npos
)
872 { ConcatSelf(n
== npos
? wxStrlen(sz
) : n
, sz
); return *this; }
874 // append n copies of ch
875 wxString
& append(size_t n
, wxChar ch
) { return Pad(n
, ch
); }
877 // same as `this_string = str'
878 wxString
& assign(const wxString
& str
)
879 { return *this = str
; }
880 // same as ` = str[pos..pos + n]
881 wxString
& assign(const wxString
& str
, size_t pos
, size_t n
)
882 { Empty(); return Append(str
.c_str() + pos
, n
); }
883 // same as `= first n (or all if n == npos) characters of sz'
884 wxString
& assign(const wxChar
*sz
, size_t n
= npos
)
885 { Empty(); return Append(sz
, n
== npos
? wxStrlen(sz
) : n
); }
886 // same as `= n copies of ch'
887 wxString
& assign(size_t n
, wxChar ch
)
888 { Empty(); return Append(ch
, n
); }
890 // insert another string
891 wxString
& insert(size_t nPos
, const wxString
& str
);
892 // insert n chars of str starting at nStart (in str)
893 wxString
& insert(size_t nPos
, const wxString
& str
, size_t nStart
, size_t n
)
894 { return insert(nPos
, wxString((const wxChar
*)str
+ nStart
, n
)); }
896 // insert first n (or all if n == npos) characters of sz
897 wxString
& insert(size_t nPos
, const wxChar
*sz
, size_t n
= npos
)
898 { return insert(nPos
, wxString(sz
, n
)); }
899 // insert n copies of ch
900 wxString
& insert(size_t nPos
, size_t n
, wxChar ch
)
901 { return insert(nPos
, wxString(ch
, n
)); }
903 // delete characters from nStart to nStart + nLen
904 wxString
& erase(size_t nStart
= 0, size_t nLen
= npos
);
906 // replaces the substring of length nLen starting at nStart
907 wxString
& replace(size_t nStart
, size_t nLen
, const wxChar
* sz
);
908 // replaces the substring with nCount copies of ch
909 wxString
& replace(size_t nStart
, size_t nLen
, size_t nCount
, wxChar ch
);
910 // replaces a substring with another substring
911 wxString
& replace(size_t nStart
, size_t nLen
,
912 const wxString
& str
, size_t nStart2
, size_t nLen2
);
913 // replaces the substring with first nCount chars of sz
914 wxString
& replace(size_t nStart
, size_t nLen
,
915 const wxChar
* sz
, size_t nCount
);
918 void swap(wxString
& str
);
920 // All find() functions take the nStart argument which specifies the
921 // position to start the search on, the default value is 0. All functions
922 // return npos if there were no match.
925 size_t find(const wxString
& str
, size_t nStart
= 0) const;
927 // VC++ 1.5 can't cope with this syntax.
928 #if !defined(__VISUALC__) || defined(__WIN32__)
929 // find first n characters of sz
930 size_t find(const wxChar
* sz
, size_t nStart
= 0, size_t n
= npos
) const;
933 // Gives a duplicate symbol (presumably a case-insensitivity problem)
934 #if !defined(__BORLANDC__)
935 // find the first occurence of character ch after nStart
936 size_t find(wxChar ch
, size_t nStart
= 0) const;
938 // rfind() family is exactly like find() but works right to left
940 // as find, but from the end
941 size_t rfind(const wxString
& str
, size_t nStart
= npos
) const;
943 // VC++ 1.5 can't cope with this syntax.
944 #if !defined(__VISUALC__) || defined(__WIN32__)
945 // as find, but from the end
946 size_t rfind(const wxChar
* sz
, size_t nStart
= npos
,
947 size_t n
= npos
) const;
948 // as find, but from the end
949 size_t rfind(wxChar ch
, size_t nStart
= npos
) const;
952 // find first/last occurence of any character in the set
954 // as strpbrk() but starts at nStart, returns npos if not found
955 size_t find_first_of(const wxString
& str
, size_t nStart
= 0) const
956 { return find_first_of(str
.c_str(), nStart
); }
958 size_t find_first_of(const wxChar
* sz
, size_t nStart
= 0) const;
959 // same as find(char, size_t)
960 size_t find_first_of(wxChar c
, size_t nStart
= 0) const
961 { return find(c
, nStart
); }
962 // find the last (starting from nStart) char from str in this string
963 size_t find_last_of (const wxString
& str
, size_t nStart
= npos
) const
964 { return find_last_of(str
.c_str(), nStart
); }
966 size_t find_last_of (const wxChar
* sz
, size_t nStart
= npos
) const;
968 size_t find_last_of(wxChar c
, size_t nStart
= npos
) const
969 { return rfind(c
, nStart
); }
971 // find first/last occurence of any character not in the set
973 // as strspn() (starting from nStart), returns npos on failure
974 size_t find_first_not_of(const wxString
& str
, size_t nStart
= 0) const
975 { return find_first_not_of(str
.c_str(), nStart
); }
977 size_t find_first_not_of(const wxChar
* sz
, size_t nStart
= 0) const;
979 size_t find_first_not_of(wxChar ch
, size_t nStart
= 0) const;
981 size_t find_last_not_of(const wxString
& str
, size_t nStart
= npos
) const
982 { return find_first_not_of(str
.c_str(), nStart
); }
984 size_t find_last_not_of(const wxChar
* sz
, size_t nStart
= npos
) const;
986 size_t find_last_not_of(wxChar ch
, size_t nStart
= npos
) const;
988 // All compare functions return -1, 0 or 1 if the [sub]string is less,
989 // equal or greater than the compare() argument.
991 // just like strcmp()
992 int compare(const wxString
& str
) const { return Cmp(str
); }
993 // comparison with a substring
994 int compare(size_t nStart
, size_t nLen
, const wxString
& str
) const
995 { return Mid(nStart
, nLen
).Cmp(str
); }
996 // comparison of 2 substrings
997 int compare(size_t nStart
, size_t nLen
,
998 const wxString
& str
, size_t nStart2
, size_t nLen2
) const
999 { return Mid(nStart
, nLen
).Cmp(str
.Mid(nStart2
, nLen2
)); }
1000 // just like strcmp()
1001 int compare(const wxChar
* sz
) const { return Cmp(sz
); }
1002 // substring comparison with first nCount characters of sz
1003 int compare(size_t nStart
, size_t nLen
,
1004 const wxChar
* sz
, size_t nCount
= npos
) const
1005 { return Mid(nStart
, nLen
).Cmp(wxString(sz
, nCount
)); }
1007 // substring extraction
1008 wxString
substr(size_t nStart
= 0, size_t nLen
= npos
) const
1009 { return Mid(nStart
, nLen
); }
1010 #endif // wxSTD_STRING_COMPATIBILITY
1013 // ----------------------------------------------------------------------------
1014 // The string array uses it's knowledge of internal structure of the wxString
1015 // class to optimize string storage. Normally, we would store pointers to
1016 // string, but as wxString is, in fact, itself a pointer (sizeof(wxString) is
1017 // sizeof(char *)) we store these pointers instead. The cast to "wxString *" is
1018 // really all we need to turn such pointer into a string!
1020 // Of course, it can be called a dirty hack, but we use twice less memory and
1021 // this approach is also more speed efficient, so it's probably worth it.
1023 // Usage notes: when a string is added/inserted, a new copy of it is created,
1024 // so the original string may be safely deleted. When a string is retrieved
1025 // from the array (operator[] or Item() method), a reference is returned.
1026 // ----------------------------------------------------------------------------
1028 class WXDLLEXPORT wxArrayString
1031 // type of function used by wxArrayString::Sort()
1032 typedef int (*CompareFunction
)(const wxString
& first
,
1033 const wxString
& second
);
1035 // constructors and destructor
1038 : m_nSize(0), m_nCount(0), m_pItems(NULL
), m_autoSort(FALSE
)
1040 // if autoSort is TRUE, the array is always sorted (in alphabetical order)
1042 // NB: the reason for using int and not bool is that like this we can avoid
1043 // using this ctor for implicit conversions from "const char *" (which
1044 // we'd like to be implicitly converted to wxString instead!)
1046 // of course, using explicit would be even better - if all compilers
1048 wxArrayString(int autoSort
)
1049 : m_nSize(0), m_nCount(0), m_pItems(NULL
), m_autoSort(FALSE
)
1050 { Init(autoSort
!= 0); }
1052 wxArrayString(const wxArrayString
& array
);
1053 // assignment operator
1054 wxArrayString
& operator=(const wxArrayString
& src
);
1055 // not virtual, this class should not be derived from
1058 // memory management
1059 // empties the list, but doesn't release memory
1061 // empties the list and releases memory
1063 // preallocates memory for given number of items
1064 void Alloc(size_t nCount
);
1065 // minimzes the memory usage (by freeing all extra memory)
1069 // number of elements in the array
1070 size_t GetCount() const { return m_nCount
; }
1072 bool IsEmpty() const { return m_nCount
== 0; }
1073 // number of elements in the array (GetCount is preferred API)
1074 size_t Count() const { return m_nCount
; }
1076 // items access (range checking is done in debug version)
1077 // get item at position uiIndex
1078 wxString
& Item(size_t nIndex
) const
1080 wxASSERT_MSG( nIndex
< m_nCount
,
1081 _T("wxArrayString: index out of bounds") );
1083 return *(wxString
*)&(m_pItems
[nIndex
]);
1087 wxString
& operator[](size_t nIndex
) const { return Item(nIndex
); }
1089 wxString
& Last() const
1091 wxASSERT_MSG( !IsEmpty(),
1092 _T("wxArrayString: index out of bounds") );
1093 return Item(Count() - 1);
1096 // return a wxString[], useful for the controls which
1097 // take one in their ctor. You must delete[] it yourself
1098 // once you are done with it. Will return NULL if the
1099 // ArrayString was empty.
1100 wxString
* GetStringArray() const;
1103 // Search the element in the array, starting from the beginning if
1104 // bFromEnd is FALSE or from end otherwise. If bCase, comparison is case
1105 // sensitive (default). Returns index of the first item matched or
1107 int Index (const wxChar
*sz
, bool bCase
= TRUE
, bool bFromEnd
= FALSE
) const;
1108 // add new element at the end (if the array is not sorted), return its
1110 size_t Add(const wxString
& str
, size_t nInsert
= 1);
1111 // add new element at given position
1112 void Insert(const wxString
& str
, size_t uiIndex
, size_t nInsert
= 1);
1113 // expand the array to have count elements
1114 void SetCount(size_t count
);
1115 // remove first item matching this value
1116 void Remove(const wxChar
*sz
);
1117 // remove item by index
1118 void Remove(size_t nIndex
, size_t nRemove
= 1);
1119 void RemoveAt(size_t nIndex
, size_t nRemove
= 1) { Remove(nIndex
, nRemove
); }
1122 // sort array elements in alphabetical order (or reversed alphabetical
1123 // order if reverseOrder parameter is TRUE)
1124 void Sort(bool reverseOrder
= FALSE
);
1125 // sort array elements using specified comparaison function
1126 void Sort(CompareFunction compareFunction
);
1129 // compare two arrays case sensitively
1130 bool operator==(const wxArrayString
& a
) const;
1131 // compare two arrays case sensitively
1132 bool operator!=(const wxArrayString
& a
) const { return !(*this == a
); }
1135 void Init(bool autoSort
); // common part of all ctors
1136 void Copy(const wxArrayString
& src
); // copies the contents of another array
1139 void Grow(size_t nIncrement
= 0); // makes array bigger if needed
1140 void Free(); // free all the strings stored
1142 void DoSort(); // common part of all Sort() variants
1144 size_t m_nSize
, // current size of the array
1145 m_nCount
; // current number of elements
1147 wxChar
**m_pItems
; // pointer to data
1149 bool m_autoSort
; // if TRUE, keep the array always sorted
1152 class WXDLLEXPORT wxSortedArrayString
: public wxArrayString
1155 wxSortedArrayString() : wxArrayString(TRUE
)
1157 wxSortedArrayString(const wxArrayString
& array
) : wxArrayString(TRUE
)
1161 // ----------------------------------------------------------------------------
1162 // wxStringBuffer: a tiny class allowing to get a writable pointer into string
1163 // ----------------------------------------------------------------------------
1165 class WXDLLEXPORT wxStringBuffer
1168 wxStringBuffer(wxString
& str
, size_t lenWanted
= 1024)
1169 : m_str(str
), m_buf(NULL
)
1170 { m_buf
= m_str
.GetWriteBuf(lenWanted
); }
1172 ~wxStringBuffer() { m_str
.UngetWriteBuf(); }
1174 operator wxChar
*() const { return m_buf
; }
1180 DECLARE_NO_COPY_CLASS(wxStringBuffer
)
1183 // ---------------------------------------------------------------------------
1184 // wxString comparison functions: operator versions are always case sensitive
1185 // ---------------------------------------------------------------------------
1187 inline bool operator==(const wxString
& s1
, const wxString
& s2
)
1188 { return (s1
.Len() == s2
.Len()) && (s1
.Cmp(s2
) == 0); }
1189 inline bool operator==(const wxString
& s1
, const wxChar
* s2
)
1190 { return s1
.Cmp(s2
) == 0; }
1191 inline bool operator==(const wxChar
* s1
, const wxString
& s2
)
1192 { return s2
.Cmp(s1
) == 0; }
1193 inline bool operator!=(const wxString
& s1
, const wxString
& s2
)
1194 { return (s1
.Len() != s2
.Len()) || (s1
.Cmp(s2
) != 0); }
1195 inline bool operator!=(const wxString
& s1
, const wxChar
* s2
)
1196 { return s1
.Cmp(s2
) != 0; }
1197 inline bool operator!=(const wxChar
* s1
, const wxString
& s2
)
1198 { return s2
.Cmp(s1
) != 0; }
1199 inline bool operator< (const wxString
& s1
, const wxString
& s2
)
1200 { return s1
.Cmp(s2
) < 0; }
1201 inline bool operator< (const wxString
& s1
, const wxChar
* s2
)
1202 { return s1
.Cmp(s2
) < 0; }
1203 inline bool operator< (const wxChar
* s1
, const wxString
& s2
)
1204 { return s2
.Cmp(s1
) > 0; }
1205 inline bool operator> (const wxString
& s1
, const wxString
& s2
)
1206 { return s1
.Cmp(s2
) > 0; }
1207 inline bool operator> (const wxString
& s1
, const wxChar
* s2
)
1208 { return s1
.Cmp(s2
) > 0; }
1209 inline bool operator> (const wxChar
* s1
, const wxString
& s2
)
1210 { return s2
.Cmp(s1
) < 0; }
1211 inline bool operator<=(const wxString
& s1
, const wxString
& s2
)
1212 { return s1
.Cmp(s2
) <= 0; }
1213 inline bool operator<=(const wxString
& s1
, const wxChar
* s2
)
1214 { return s1
.Cmp(s2
) <= 0; }
1215 inline bool operator<=(const wxChar
* s1
, const wxString
& s2
)
1216 { return s2
.Cmp(s1
) >= 0; }
1217 inline bool operator>=(const wxString
& s1
, const wxString
& s2
)
1218 { return s1
.Cmp(s2
) >= 0; }
1219 inline bool operator>=(const wxString
& s1
, const wxChar
* s2
)
1220 { return s1
.Cmp(s2
) >= 0; }
1221 inline bool operator>=(const wxChar
* s1
, const wxString
& s2
)
1222 { return s2
.Cmp(s1
) <= 0; }
1224 // comparison with char
1225 inline bool operator==(wxChar c
, const wxString
& s
) { return s
.IsSameAs(c
); }
1226 inline bool operator==(const wxString
& s
, wxChar c
) { return s
.IsSameAs(c
); }
1227 inline bool operator!=(wxChar c
, const wxString
& s
) { return !s
.IsSameAs(c
); }
1228 inline bool operator!=(const wxString
& s
, wxChar c
) { return !s
.IsSameAs(c
); }
1231 inline bool operator==(const wxString
& s1
, const wxWCharBuffer
& s2
)
1232 { return (s1
.Cmp((const wchar_t *)s2
) == 0); }
1233 inline bool operator==(const wxWCharBuffer
& s1
, const wxString
& s2
)
1234 { return (s2
.Cmp((const wchar_t *)s1
) == 0); }
1235 inline bool operator!=(const wxString
& s1
, const wxWCharBuffer
& s2
)
1236 { return (s1
.Cmp((const wchar_t *)s2
) != 0); }
1237 inline bool operator!=(const wxWCharBuffer
& s1
, const wxString
& s2
)
1238 { return (s2
.Cmp((const wchar_t *)s1
) != 0); }
1239 #else // !wxUSE_UNICODE
1240 inline bool operator==(const wxString
& s1
, const wxCharBuffer
& s2
)
1241 { return (s1
.Cmp((const char *)s2
) == 0); }
1242 inline bool operator==(const wxCharBuffer
& s1
, const wxString
& s2
)
1243 { return (s2
.Cmp((const char *)s1
) == 0); }
1244 inline bool operator!=(const wxString
& s1
, const wxCharBuffer
& s2
)
1245 { return (s1
.Cmp((const char *)s2
) != 0); }
1246 inline bool operator!=(const wxCharBuffer
& s1
, const wxString
& s2
)
1247 { return (s2
.Cmp((const char *)s1
) != 0); }
1248 #endif // wxUSE_UNICODE/!wxUSE_UNICODE
1250 wxString WXDLLEXPORT
operator+(const wxString
& string1
, const wxString
& string2
);
1251 wxString WXDLLEXPORT
operator+(const wxString
& string
, wxChar ch
);
1252 wxString WXDLLEXPORT
operator+(wxChar ch
, const wxString
& string
);
1253 wxString WXDLLEXPORT
operator+(const wxString
& string
, const wxChar
*psz
);
1254 wxString WXDLLEXPORT
operator+(const wxChar
*psz
, const wxString
& string
);
1256 inline wxString
operator+(const wxString
& string
, const wxWCharBuffer
& buf
)
1257 { return string
+ (const wchar_t *)buf
; }
1258 inline wxString
operator+(const wxWCharBuffer
& buf
, const wxString
& string
)
1259 { return (const wchar_t *)buf
+ string
; }
1260 #else // !wxUSE_UNICODE
1261 inline wxString
operator+(const wxString
& string
, const wxCharBuffer
& buf
)
1262 { return string
+ (const char *)buf
; }
1263 inline wxString
operator+(const wxCharBuffer
& buf
, const wxString
& string
)
1264 { return (const char *)buf
+ string
; }
1265 #endif // wxUSE_UNICODE/!wxUSE_UNICODE
1267 // ---------------------------------------------------------------------------
1268 // Implementation only from here until the end of file
1269 // ---------------------------------------------------------------------------
1271 // don't pollute the library user's name space
1272 #undef wxASSERT_VALID_INDEX
1274 #if defined(wxSTD_STRING_COMPATIBILITY) && wxUSE_STD_IOSTREAM
1276 #include "wx/iosfwrap.h"
1278 WXDLLEXPORT wxSTD istream
& operator>>(wxSTD istream
&, wxString
&);
1279 WXDLLEXPORT wxSTD ostream
& operator<<(wxSTD ostream
&, const wxString
&);
1281 #endif // wxSTD_STRING_COMPATIBILITY
1283 #endif // _WX_WXSTRINGH__