]> git.saurik.com Git - wxWidgets.git/blame - include/wx/string.h
wxGLCanvas works again
[wxWidgets.git] / include / wx / string.h
CommitLineData
3c67202d 1///////////////////////////////////////////////////////////////////////////////
c801d85f 2// Name: string.h
3c67202d 3// Purpose: wxString and wxArrayString classes
c801d85f
KB
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
3c67202d 10///////////////////////////////////////////////////////////////////////////////
c801d85f 11
34138703
JS
12#ifndef _WX_WXSTRINGH__
13#define _WX_WXSTRINGH__
c801d85f
KB
14
15#ifdef __GNUG__
0d3820b3 16#pragma interface "string.h"
c801d85f
KB
17#endif
18
17dff81c 19#ifdef __WXMAC__
3f4a0c5b 20 #include <ctype.h>
17dff81c 21#endif
3f4a0c5b 22
c801d85f
KB
23#include <string.h>
24#include <stdio.h>
25#include <stdarg.h>
26#include <limits.h>
dd1eaa89 27#include <stdlib.h>
c801d85f 28
57493f9f 29#ifdef HAVE_STRINGS_H
1bfcb0b6
VZ
30 #include <strings.h> // for strcasecmp()
31#endif // AIX
32
8fd0f20b 33#ifndef WX_PRECOMP
3f4a0c5b
VZ
34 #include "wx/defs.h"
35
dd1eaa89
VZ
36 #ifdef WXSTRING_IS_WXOBJECT
37 #include "wx/object.h"
38 #endif
3f4a0c5b 39#endif // !PCH
8fd0f20b 40
c801d85f 41#include "wx/debug.h"
2bb67b80
OK
42#include "wx/wxchar.h"
43#include "wx/buffer.h"
c801d85f 44
3c67202d
VZ
45/*
46 Efficient string class [more or less] compatible with MFC CString,
47 wxWindows version 1 wxString and std::string and some handy functions
48 missing from string.h.
49*/
c801d85f
KB
50
51// ---------------------------------------------------------------------------
52// macros
53// ---------------------------------------------------------------------------
54
3c67202d
VZ
55// compile the std::string compatibility functions if defined
56#define wxSTD_STRING_COMPATIBILITY
c801d85f 57
3c67202d 58// define to derive wxString from wxObject
a3ef5bf5 59#ifdef WXSTRING_IS_WXOBJECT
c801d85f 60#undef WXSTRING_IS_WXOBJECT
a3ef5bf5 61#endif
c801d85f 62
3c67202d 63// maximum possible length for a string means "take all string" everywhere
c801d85f 64// (as sizeof(StringData) is unknown here we substract 100)
566b84d2 65const unsigned int wxSTRING_MAXLEN = UINT_MAX - 100;
c801d85f
KB
66
67// 'naughty' cast
2bb67b80
OK
68#define WXSTRINGCAST (wxChar *)(const wxChar *)
69#define MBSTRINGCAST (char *)(const char *)
70#define WCSTRINGCAST (wchar_t *)(const wchar_t *)
c801d85f 71
3c67202d 72// implementation only
b1269691 73#define ASSERT_VALID_INDEX(i) wxASSERT( (unsigned)(i) <= Len() )
c801d85f
KB
74
75// ---------------------------------------------------------------------------
3c67202d
VZ
76// Global functions complementing standard C string library replacements for
77// strlen() and portable strcasecmp()
78//---------------------------------------------------------------------------
2bb67b80 79// USE wx* FUNCTIONS IN wx/wxchar.h INSTEAD - THIS IS ONLY FOR BINARY COMPATIBILITY
88150e60 80
3c67202d 81// checks whether the passed in pointer is NULL and if the string is empty
dbda9e86 82inline bool WXDLLEXPORT IsEmpty(const char *p) { return (!p || !*p); }
c801d85f 83
3c67202d
VZ
84// safe version of strlen() (returns 0 if passed NULL pointer)
85inline size_t WXDLLEXPORT Strlen(const char *psz)
c801d85f
KB
86 { return psz ? strlen(psz) : 0; }
87
3c67202d 88// portable strcasecmp/_stricmp
dd1eaa89
VZ
89inline int WXDLLEXPORT Stricmp(const char *psz1, const char *psz2)
90{
8be97d65 91#if defined(__VISUALC__) || ( defined(__MWERKS__) && defined(__INTEL__) )
dd1eaa89 92 return _stricmp(psz1, psz2);
2432b92d
JS
93#elif defined(__SC__)
94 return _stricmp(psz1, psz2);
a3ef5bf5
JS
95#elif defined(__SALFORDC__)
96 return stricmp(psz1, psz2);
dd1eaa89
VZ
97#elif defined(__BORLANDC__)
98 return stricmp(psz1, psz2);
7be1f0d9
JS
99#elif defined(__WATCOMC__)
100 return stricmp(psz1, psz2);
d4b67f95 101#elif defined(__UNIX__) || defined(__GNUWIN32__)
dd1eaa89 102 return strcasecmp(psz1, psz2);
8be97d65 103#elif defined(__MWERKS__) && !defined(__INTEL__)
17dff81c
SC
104 register char c1, c2;
105 do {
106 c1 = tolower(*psz1++);
107 c2 = tolower(*psz2++);
108 } while ( c1 && (c1 == c2) );
109
110 return c1 - c2;
dd1eaa89
VZ
111#else
112 // almost all compilers/libraries provide this function (unfortunately under
113 // different names), that's why we don't implement our own which will surely
114 // be more efficient than this code (uncomment to use):
115 /*
116 register char c1, c2;
117 do {
118 c1 = tolower(*psz1++);
119 c2 = tolower(*psz2++);
120 } while ( c1 && (c1 == c2) );
121
122 return c1 - c2;
123 */
124
125 #error "Please define string case-insensitive compare for your OS/compiler"
126#endif // OS/compiler
127}
c801d85f 128
f04f3991
VZ
129// ----------------------------------------------------------------------------
130// global data
131// ----------------------------------------------------------------------------
132
2bb67b80 133WXDLLEXPORT_DATA(extern const wxChar*) wxEmptyString;
3c67202d 134
f04f3991 135// global pointer to empty string
2bb67b80 136WXDLLEXPORT_DATA(extern const wxChar*) g_szNul;
f04f3991
VZ
137
138// return an empty wxString
f7bd2698 139class WXDLLEXPORT wxString; // not yet defined
f04f3991
VZ
140inline const wxString& wxGetEmptyString() { return *(wxString *)&g_szNul; }
141
c801d85f 142// ---------------------------------------------------------------------------
f04f3991 143// string data prepended with some housekeeping info (used by wxString class),
c801d85f
KB
144// is never used directly (but had to be put here to allow inlining)
145// ---------------------------------------------------------------------------
146struct WXDLLEXPORT wxStringData
147{
148 int nRefs; // reference count
3c024cc2 149 size_t nDataLength, // actual string length
c801d85f
KB
150 nAllocLength; // allocated memory size
151
2bb67b80
OK
152 // mimics declaration 'wxChar data[nAllocLength]'
153 wxChar* data() const { return (wxChar*)(this + 1); }
c801d85f
KB
154
155 // empty string has a special ref count so it's never deleted
dbda9e86
JS
156 bool IsEmpty() const { return (nRefs == -1); }
157 bool IsShared() const { return (nRefs > 1); }
c801d85f
KB
158
159 // lock/unlock
dd1eaa89
VZ
160 void Lock() { if ( !IsEmpty() ) nRefs++; }
161 void Unlock() { if ( !IsEmpty() && --nRefs == 0) free(this); }
8fd0f20b 162
dd1eaa89 163 // if we had taken control over string memory (GetWriteBuf), it's
8fd0f20b 164 // intentionally put in invalid state
dbda9e86
JS
165 void Validate(bool b) { nRefs = (b ? 1 : 0); }
166 bool IsValid() const { return (nRefs != 0); }
c801d85f
KB
167};
168
2bb67b80
OK
169// ---------------------------------------------------------------------------
170// types of multibyte<->Unicode conversions
171// ---------------------------------------------------------------------------
172class WXDLLEXPORT wxMBConv
173{
174 public:
175 virtual size_t MB2WC(wchar_t *buf, const char *psz, size_t n) const;
176 virtual size_t WC2MB(char *buf, const wchar_t *psz, size_t n) const;
177 const wxWCharBuffer cMB2WC(const char *psz) const
178 {
179 size_t nLen = MB2WC((wchar_t *) NULL, psz, 0);
180 wxWCharBuffer buf(nLen);
181 MB2WC(WCSTRINGCAST buf, psz, nLen);
182 return buf;
183 }
184 const wxCharBuffer cWC2MB(const wchar_t *psz) const
185 {
186 size_t nLen = WC2MB((char *) NULL, psz, 0);
187 wxCharBuffer buf(nLen);
188 WC2MB(MBSTRINGCAST buf, psz, nLen);
189 return buf;
190 }
191#if wxUSE_UNICODE
192 const wxWCharBuffer cMB2WX(const char *psz) const { return cMB2WC(psz); }
193 const wxCharBuffer cWX2MB(const wchar_t *psz) const { return cWC2MB(psz); }
194 const wchar_t* cWC2WX(const wchar_t *psz) const { return psz; }
195 const wchar_t* cMB2WC(const wchar_t *psz) const { return psz; }
196#else
197 const char* cMB2WX(const char *psz) const { return psz; }
198 const char* cWX2MB(const char *psz) const { return psz; }
199 const wxCharBuffer cWC2WX(const wchar_t *psz) const { return cWC2MB(psz); }
200 const wxWCharBuffer cWX2WC(const char *psz) const { return cMB2WC(psz); }
201#endif
202};
d41bba91 203WXDLLEXPORT_DATA(extern wxMBConv) wxConv_libc;
2bb67b80 204
d41bba91
OK
205#define wxANOTHER_MBCONV(type) \
206class type : public wxMBConv { \
207 public: \
208 virtual size_t MB2WC(wchar_t *buf, const char *psz, size_t n) const; \
209 virtual size_t WC2MB(char *buf, const wchar_t *psz, size_t n) const; \
210}
211
212WXDLLEXPORT_DATA(extern wxANOTHER_MBCONV(wxMBConv_file)) wxConv_file;
213WXDLLEXPORT_DATA(extern wxANOTHER_MBCONV(wxMBConv_UTF7)) wxConv_UTF7;
214WXDLLEXPORT_DATA(extern wxANOTHER_MBCONV(wxMBConv_UTF8)) wxConv_UTF8;
2f000c95
VZ
215#if defined(__WXGTK__) && (GTK_MINOR_VERSION > 0)
216 WXDLLEXPORT_DATA(extern wxANOTHER_MBCONV(wxMBConv_gdk)) wxConv_gdk;
217#endif // GTK > 1.0
d41bba91 218
a69f7aa8 219class wxCharacterSet;
d41bba91 220class WXDLLEXPORT wxCSConv : public wxMBConv
2bb67b80
OK
221{
222 private:
a86f1d4a
OK
223 wxChar *m_name;
224 wxCharacterSet *m_cset;
225 bool m_deferred;
551df6f2 226 void SetName(const wxChar *charset);
2bb67b80
OK
227 public:
228 wxCSConv(const wxChar *charset);
a86f1d4a
OK
229 virtual ~wxCSConv();
230 void LoadNow();
4300d6cb
OK
231 virtual size_t MB2WC(wchar_t *buf, const char *psz, size_t n) const;
232 virtual size_t WC2MB(char *buf, const wchar_t *psz, size_t n) const;
2bb67b80
OK
233};
234
a69f7aa8
OK
235WXDLLEXPORT_DATA(extern wxCSConv) wxConv_local;
236
237WXDLLEXPORT_DATA(extern wxMBConv *) wxConv_current;
238
2bb67b80 239// filenames are multibyte on Unix and probably widechar on Windows?
111edd48 240#if defined(__UNIX__) || defined(__BORLANDC__)
2bb67b80
OK
241#define wxMBFILES 1
242#else
243#define wxMBFILES 0
244#endif
245
246#if wxMBFILES
247#define wxFNCONV(name) wxConv_file.cWX2MB(name)
248#define FNSTRINGCAST MBSTRINGCAST
249#else
250#define wxFNCONV(name) name
251#define FNSTRINGCAST WXSTRINGCAST
252#endif
253
c801d85f 254// ---------------------------------------------------------------------------
3c67202d
VZ
255// This is (yet another one) String class for C++ programmers. It doesn't use
256// any of "advanced" C++ features (i.e. templates, exceptions, namespaces...)
257// thus you should be able to compile it with practicaly any C++ compiler.
258// This class uses copy-on-write technique, i.e. identical strings share the
259// same memory as long as neither of them is changed.
260//
261// This class aims to be as compatible as possible with the new standard
262// std::string class, but adds some additional functions and should be at
263// least as efficient than the standard implementation.
264//
265// Performance note: it's more efficient to write functions which take "const
266// String&" arguments than "const char *" if you assign the argument to
267// another string.
268//
269// It was compiled and tested under Win32, Linux (libc 5 & 6), Solaris 5.5.
270//
271// To do:
272// - ressource support (string tables in ressources)
273// - more wide character (UNICODE) support
274// - regular expressions support
c801d85f 275// ---------------------------------------------------------------------------
3c67202d 276
c801d85f 277#ifdef WXSTRING_IS_WXOBJECT
3c67202d
VZ
278class WXDLLEXPORT wxString : public wxObject
279{
c801d85f
KB
280 DECLARE_DYNAMIC_CLASS(wxString)
281#else //WXSTRING_IS_WXOBJECT
3c67202d
VZ
282class WXDLLEXPORT wxString
283{
c801d85f
KB
284#endif //WXSTRING_IS_WXOBJECT
285
fbcb4166 286friend class WXDLLEXPORT wxArrayString;
c801d85f 287
3c67202d
VZ
288 // NB: special care was taken in arranging the member functions in such order
289 // that all inline functions can be effectively inlined, verify that all
290 // performace critical functions are still inlined if you change order!
dd1eaa89
VZ
291private:
292 // points to data preceded by wxStringData structure with ref count info
2bb67b80 293 wxChar *m_pchData;
dd1eaa89
VZ
294
295 // accessor to string data
296 wxStringData* GetStringData() const { return (wxStringData*)m_pchData - 1; }
297
6b95b20d
VZ
298 // string (re)initialization functions
299 // initializes the string to the empty value (must be called only from
300 // ctors, use Reinit() otherwise)
2bb67b80 301 void Init() { m_pchData = (wxChar *)g_szNul; }
6b95b20d 302 // initializaes the string with (a part of) C-string
2bb67b80 303 void InitWith(const wxChar *psz, size_t nPos = 0, size_t nLen = wxSTRING_MAXLEN);
6b95b20d
VZ
304 // as Init, but also frees old data
305 void Reinit() { GetStringData()->Unlock(); Init(); }
306
307 // memory allocation
308 // allocates memory for string of lenght nLen
309 void AllocBuffer(size_t nLen);
310 // copies data to another string
311 void AllocCopy(wxString&, int, int) const;
312 // effectively copies data to string
2bb67b80 313 void AssignCopy(size_t, const wxChar *);
6b95b20d
VZ
314
315 // append a (sub)string
2bb67b80 316 void ConcatSelf(int nLen, const wxChar *src);
6b95b20d
VZ
317
318 // functions called before writing to the string: they copy it if there
319 // are other references to our data (should be the only owner when writing)
320 void CopyBeforeWrite();
321 void AllocBeforeWrite(size_t);
322
c606a9a4
VZ
323 // this method is not implemented - there is _no_ conversion from int to
324 // string, you're doing something wrong if the compiler wants to call it!
325 //
326 // try `s << i' or `s.Printf("%d", i)' instead
327 wxString(int);
328 wxString(long);
329
c801d85f 330public:
3c67202d
VZ
331 // constructors and destructor
332 // ctor for an empty string
6b95b20d 333 wxString() { Init(); }
3c67202d 334 // copy ctor
6b95b20d
VZ
335 wxString(const wxString& stringSrc)
336 {
337 wxASSERT( stringSrc.GetStringData()->IsValid() );
338
339 if ( stringSrc.IsEmpty() ) {
340 // nothing to do for an empty string
341 Init();
342 }
343 else {
344 m_pchData = stringSrc.m_pchData; // share same data
345 GetStringData()->Lock(); // => one more copy
346 }
347 }
3c67202d 348 // string containing nRepeat copies of ch
2bb67b80 349 wxString(wxChar ch, size_t nRepeat = 1);
3c67202d 350 // ctor takes first nLength characters from C string
566b84d2 351 // (default value of wxSTRING_MAXLEN means take all the string)
2bb67b80 352 wxString(const wxChar *psz, size_t nLength = wxSTRING_MAXLEN)
6b95b20d 353 { InitWith(psz, 0, nLength); }
2bb67b80
OK
354#if wxUSE_UNICODE
355 // from multibyte string
356 // (NB: nLength is right now number of Unicode characters, not
357 // characters in psz! So try not to use it yet!)
358 wxString(const char *psz, wxMBConv& conv = wxConv_libc, size_t nLength = wxSTRING_MAXLEN);
359 // from wxWCharBuffer (i.e. return from wxGetString)
360 wxString(const wxWCharBuffer& psz)
361 { InitWith(psz, 0, wxSTRING_MAXLEN); }
362#else
3c67202d 363 // from C string (for compilers using unsigned char)
2bb67b80
OK
364 wxString(const unsigned char* psz, size_t nLength = wxSTRING_MAXLEN)
365 { InitWith((const char*)psz, 0, nLength); }
3a309a64
OK
366 // from multibyte string
367 wxString(const char *psz, wxMBConv& WXUNUSED(conv), size_t nLength = wxSTRING_MAXLEN)
368 { InitWith(psz, 0, nLength); }
2bb67b80 369 // from wide (Unicode) string
c801d85f 370 wxString(const wchar_t *pwz);
2bb67b80
OK
371 // from wxCharBuffer
372 wxString(const wxCharBuffer& psz)
373 { InitWith(psz, 0, wxSTRING_MAXLEN); }
374#endif
3c67202d 375 // dtor is not virtual, this class must not be inherited from!
6b95b20d 376 ~wxString() { GetStringData()->Unlock(); }
c801d85f 377
3c67202d
VZ
378 // generic attributes & operations
379 // as standard strlen()
47d67540 380 size_t Len() const { return GetStringData()->nDataLength; }
3c67202d 381 // string contains any characters?
dd1eaa89 382 bool IsEmpty() const { return Len() == 0; }
dcfde592
VZ
383 // empty string is "FALSE", so !str will return TRUE
384 bool operator!() const { return IsEmpty(); }
3c67202d 385 // empty string contents
dd1eaa89
VZ
386 void Empty()
387 {
2c3b684c 388 if ( !IsEmpty() )
dd1eaa89
VZ
389 Reinit();
390
7be07660 391 // should be empty
dd1eaa89 392 wxASSERT( GetStringData()->nDataLength == 0 );
7be07660 393 }
3c67202d 394 // empty the string and free memory
7be07660
VZ
395 void Clear()
396 {
397 if ( !GetStringData()->IsEmpty() )
398 Reinit();
399
400 wxASSERT( GetStringData()->nDataLength == 0 ); // should be empty
401 wxASSERT( GetStringData()->nAllocLength == 0 ); // and not own any memory
dd1eaa89
VZ
402 }
403
3c67202d
VZ
404 // contents test
405 // Is an ascii value
c801d85f 406 bool IsAscii() const;
3c67202d 407 // Is a number
c801d85f 408 bool IsNumber() const;
3c67202d 409 // Is a word
c801d85f 410 bool IsWord() const;
c801d85f 411
3c67202d
VZ
412 // data access (all indexes are 0 based)
413 // read access
2bb67b80 414 wxChar GetChar(size_t n) const
dd1eaa89 415 { ASSERT_VALID_INDEX( n ); return m_pchData[n]; }
3c67202d 416 // read/write access
2bb67b80 417 wxChar& GetWritableChar(size_t n)
dd1eaa89 418 { ASSERT_VALID_INDEX( n ); CopyBeforeWrite(); return m_pchData[n]; }
3c67202d 419 // write access
2bb67b80 420 void SetChar(size_t n, wxChar ch)
c801d85f
KB
421 { ASSERT_VALID_INDEX( n ); CopyBeforeWrite(); m_pchData[n] = ch; }
422
3c67202d 423 // get last character
2bb67b80 424 wxChar Last() const
c801d85f 425 { wxASSERT( !IsEmpty() ); return m_pchData[Len() - 1]; }
3c67202d 426 // get writable last character
2bb67b80 427 wxChar& Last()
c801d85f
KB
428 { wxASSERT( !IsEmpty() ); CopyBeforeWrite(); return m_pchData[Len()-1]; }
429
57493f9f
VZ
430 // under Unix it is tested with configure, assume it works on other
431 // platforms (there might be overloading problems if size_t and int are
432 // the same type)
227b5cd7 433#if !defined(__UNIX__) || wxUSE_SIZE_T_STRING_OPERATOR
3c67202d 434 // operator version of GetChar
2bb67b80 435 wxChar operator[](size_t n) const
c801d85f 436 { ASSERT_VALID_INDEX( n ); return m_pchData[n]; }
22552603 437#endif
c5248639 438
3c67202d 439 // operator version of GetChar
2bb67b80 440 wxChar operator[](int n) const
c801d85f 441 { ASSERT_VALID_INDEX( n ); return m_pchData[n]; }
3c67202d 442 // operator version of GetWritableChar
2bb67b80 443 wxChar& operator[](size_t n)
c801d85f
KB
444 { ASSERT_VALID_INDEX( n ); CopyBeforeWrite(); return m_pchData[n]; }
445
3c67202d 446 // implicit conversion to C string
2bb67b80 447 operator const wxChar*() const { return m_pchData; }
3c67202d 448 // explicit conversion to C string (use this with printf()!)
2bb67b80 449 const wxChar* c_str() const { return m_pchData; }
3c67202d 450 //
2bb67b80
OK
451 const wxChar* GetData() const { return m_pchData; }
452#if wxUSE_UNICODE
453 const wxCharBuffer mb_str(wxMBConv& conv = wxConv_libc) const { return conv.cWC2MB(m_pchData); }
454 const wxChar* wc_str(wxMBConv& WXUNUSED(conv) = wxConv_libc) const { return m_pchData; }
455#if wxMBFILES
456 const wxCharBuffer fn_str() const { return mb_str(wxConv_file); }
457#else
458 const wxChar* fn_str() const { return m_pchData; }
459#endif
460#else
461 const wxChar* mb_str(wxMBConv& WXUNUSED(conv) = wxConv_libc ) const { return m_pchData; }
462 const wxWCharBuffer wc_str(wxMBConv& conv) const { return conv.cMB2WC(m_pchData); }
463 const wxChar* fn_str() const { return m_pchData; }
464#endif
a69f7aa8
OK
465 // for convenience
466 const wxWX2MBbuf mbc_str() const { return mb_str(*wxConv_current); }
c801d85f 467
3c67202d
VZ
468 // overloaded assignment
469 // from another wxString
c801d85f 470 wxString& operator=(const wxString& stringSrc);
3c67202d 471 // from a character
2bb67b80 472 wxString& operator=(wxChar ch);
3c67202d 473 // from a C string
2bb67b80 474 wxString& operator=(const wxChar *psz);
111bb7f2
OK
475#if wxUSE_UNICODE
476 // from wxWCharBuffer
477 wxString& operator=(const wxWCharBuffer& psz) { return operator=((const wchar_t *)psz); }
478#else
3c67202d 479 // from another kind of C string
c801d85f 480 wxString& operator=(const unsigned char* psz);
3c67202d 481 // from a wide string
c801d85f 482 wxString& operator=(const wchar_t *pwz);
111bb7f2
OK
483 // from wxCharBuffer
484 wxString& operator=(const wxCharBuffer& psz) { return operator=((const char *)psz); }
2bb67b80 485#endif
3c67202d
VZ
486
487 // string concatenation
488 // in place concatenation
489 /*
490 Concatenate and return the result. Note that the left to right
491 associativity of << allows to write things like "str << str1 << str2
492 << ..." (unlike with +=)
493 */
494 // string += string
dd1eaa89
VZ
495 wxString& operator<<(const wxString& s)
496 {
497 wxASSERT( s.GetStringData()->IsValid() );
498
499 ConcatSelf(s.Len(), s);
500 return *this;
501 }
3c67202d 502 // string += C string
2bb67b80
OK
503 wxString& operator<<(const wxChar *psz)
504 { ConcatSelf(wxStrlen(psz), psz); return *this; }
3c67202d 505 // string += char
2bb67b80 506 wxString& operator<<(wxChar ch) { ConcatSelf(1, &ch); return *this; }
dd1eaa89 507
3c67202d 508 // string += string
6b95b20d 509 void operator+=(const wxString& s) { (void)operator<<(s); }
3c67202d 510 // string += C string
2bb67b80 511 void operator+=(const wxChar *psz) { (void)operator<<(psz); }
3c67202d 512 // string += char
2bb67b80
OK
513 void operator+=(wxChar ch) { (void)operator<<(ch); }
514
515 // string += buffer (i.e. from wxGetString)
516#if wxUSE_UNICODE
517 wxString& operator<<(const wxWCharBuffer& s) { (void)operator<<((const wchar_t *)s); return *this; }
518 void operator+=(const wxWCharBuffer& s) { (void)operator<<((const wchar_t *)s); }
519#else
520 wxString& operator<<(const wxCharBuffer& s) { (void)operator<<((const char *)s); return *this; }
521 void operator+=(const wxCharBuffer& s) { (void)operator<<((const char *)s); }
522#endif
6b95b20d 523
3c67202d 524 // string += C string
2bb67b80
OK
525 wxString& Append(const wxChar* psz)
526 { ConcatSelf(wxStrlen(psz), psz); return *this; }
3c67202d 527 // append count copies of given character
2bb67b80 528 wxString& Append(wxChar ch, size_t count = 1u)
3c67202d
VZ
529 { wxString str(ch, count); return *this << str; }
530
531 // prepend a string, return the string itself
532 wxString& Prepend(const wxString& str)
533 { *this = str + *this; return *this; }
534
535 // non-destructive concatenation
536 //
c33534e5 537 friend wxString WXDLLEXPORT operator+(const wxString& string1, const wxString& string2);
3c67202d 538 //
2bb67b80 539 friend wxString WXDLLEXPORT operator+(const wxString& string, wxChar ch);
3c67202d 540 //
2bb67b80 541 friend wxString WXDLLEXPORT operator+(wxChar ch, const wxString& string);
3c67202d 542 //
2bb67b80 543 friend wxString WXDLLEXPORT operator+(const wxString& string, const wxChar *psz);
3c67202d 544 //
2bb67b80 545 friend wxString WXDLLEXPORT operator+(const wxChar *psz, const wxString& string);
3c67202d
VZ
546
547 // stream-like functions
548 // insert an int into string
549 wxString& operator<<(int i);
550 // insert a float into string
551 wxString& operator<<(float f);
552 // insert a double into string
553 wxString& operator<<(double d);
c84c52de 554
3c67202d 555 // string comparison
30b21f9a 556 // case-sensitive comparison (returns a value < 0, = 0 or > 0)
2bb67b80 557 int Cmp(const wxChar *psz) const { return wxStrcmp(c_str(), psz); }
3c67202d 558 // same as Cmp() but not case-sensitive
2bb67b80 559 int CmpNoCase(const wxChar *psz) const { return wxStricmp(c_str(), psz); }
3c67202d
VZ
560 // test for the string equality, either considering case or not
561 // (if compareWithCase then the case matters)
2bb67b80 562 bool IsSameAs(const wxChar *psz, bool compareWithCase = TRUE) const
3c67202d
VZ
563 { return (compareWithCase ? Cmp(psz) : CmpNoCase(psz)) == 0; }
564
565 // simple sub-string extraction
566 // return substring starting at nFirst of length nCount (or till the end
567 // if nCount = default value)
566b84d2 568 wxString Mid(size_t nFirst, size_t nCount = wxSTRING_MAXLEN) const;
3c67202d
VZ
569
570 // operator version of Mid()
571 wxString operator()(size_t start, size_t len) const
572 { return Mid(start, len); }
573
574 // get first nCount characters
c801d85f 575 wxString Left(size_t nCount) const;
3c67202d 576 // get last nCount characters
c801d85f 577 wxString Right(size_t nCount) const;
3c67202d
VZ
578 // get all characters before the first occurence of ch
579 // (returns the whole string if ch not found)
2bb67b80 580 wxString BeforeFirst(wxChar ch) const;
3c67202d
VZ
581 // get all characters before the last occurence of ch
582 // (returns empty string if ch not found)
2bb67b80 583 wxString BeforeLast(wxChar ch) const;
3c67202d
VZ
584 // get all characters after the first occurence of ch
585 // (returns empty string if ch not found)
2bb67b80 586 wxString AfterFirst(wxChar ch) const;
3c67202d
VZ
587 // get all characters after the last occurence of ch
588 // (returns the whole string if ch not found)
2bb67b80 589 wxString AfterLast(wxChar ch) const;
3c67202d
VZ
590
591 // for compatibility only, use more explicitly named functions above
2bb67b80
OK
592 wxString Before(wxChar ch) const { return BeforeLast(ch); }
593 wxString After(wxChar ch) const { return AfterFirst(ch); }
3c67202d
VZ
594
595 // case conversion
c84c52de 596 // convert to upper case in place, return the string itself
c801d85f 597 wxString& MakeUpper();
c84c52de 598 // convert to upper case, return the copy of the string
03ab016d
JS
599 // Here's something to remember: BC++ doesn't like returns in inlines.
600 wxString Upper() const ;
c84c52de 601 // convert to lower case in place, return the string itself
c801d85f 602 wxString& MakeLower();
c84c52de 603 // convert to lower case, return the copy of the string
03ab016d 604 wxString Lower() const ;
c801d85f 605
3c67202d
VZ
606 // trimming/padding whitespace (either side) and truncating
607 // remove spaces from left or from right (default) side
c801d85f 608 wxString& Trim(bool bFromRight = TRUE);
3c67202d 609 // add nCount copies chPad in the beginning or at the end (default)
2bb67b80 610 wxString& Pad(size_t nCount, wxChar chPad = _T(' '), bool bFromRight = TRUE);
3c67202d 611 // truncate string to given length
c801d85f 612 wxString& Truncate(size_t uiLen);
dd1eaa89 613
3c67202d
VZ
614 // searching and replacing
615 // searching (return starting index, or -1 if not found)
2bb67b80 616 int Find(wxChar ch, bool bFromEnd = FALSE) const; // like strchr/strrchr
3c67202d 617 // searching (return starting index, or -1 if not found)
2bb67b80 618 int Find(const wxChar *pszSub) const; // like strstr
3c67202d
VZ
619 // replace first (or all of bReplaceAll) occurences of substring with
620 // another string, returns the number of replacements made
2bb67b80
OK
621 size_t Replace(const wxChar *szOld,
622 const wxChar *szNew,
3c67202d
VZ
623 bool bReplaceAll = TRUE);
624
625 // check if the string contents matches a mask containing '*' and '?'
2bb67b80 626 bool Matches(const wxChar *szMask) const;
c801d85f 627
3c67202d
VZ
628 // formated input/output
629 // as sprintf(), returns the number of characters written or < 0 on error
2bb67b80 630 int Printf(const wxChar *pszFormat, ...);
3c67202d 631 // as vprintf(), returns the number of characters written or < 0 on error
2bb67b80 632 int PrintfV(const wxChar* pszFormat, va_list argptr);
dd1eaa89 633
3c67202d
VZ
634 // raw access to string memory
635 // ensure that string has space for at least nLen characters
dd1eaa89 636 // only works if the data of this string is not shared
c86f1403 637 void Alloc(size_t nLen);
3c67202d 638 // minimize the string's memory
dd1eaa89
VZ
639 // only works if the data of this string is not shared
640 void Shrink();
3c67202d
VZ
641 // get writable buffer of at least nLen bytes. Unget() *must* be called
642 // a.s.a.p. to put string back in a reasonable state!
2bb67b80 643 wxChar *GetWriteBuf(size_t nLen);
3c67202d 644 // call this immediately after GetWriteBuf() has been used
8fd0f20b 645 void UngetWriteBuf();
c801d85f 646
3c67202d
VZ
647 // wxWindows version 1 compatibility functions
648
649 // use Mid()
650 wxString SubString(size_t from, size_t to) const
651 { return Mid(from, (to - from + 1)); }
652 // values for second parameter of CompareTo function
c801d85f 653 enum caseCompare {exact, ignoreCase};
3c67202d 654 // values for first parameter of Strip function
c801d85f 655 enum stripType {leading = 0x1, trailing = 0x2, both = 0x3};
8870c26e 656
3c67202d 657 // use Printf()
2bb67b80 658 int sprintf(const wxChar *pszFormat, ...);
c801d85f 659
3c67202d 660 // use Cmp()
2bb67b80 661 inline int CompareTo(const wxChar* psz, caseCompare cmp = exact) const
6b95b20d 662 { return cmp == exact ? Cmp(psz) : CmpNoCase(psz); }
c801d85f 663
3c67202d 664 // use Len
c801d85f 665 size_t Length() const { return Len(); }
3c67202d 666 // Count the number of characters
2bb67b80 667 int Freq(wxChar ch) const;
3c67202d 668 // use MakeLower
c801d85f 669 void LowerCase() { MakeLower(); }
3c67202d 670 // use MakeUpper
c801d85f 671 void UpperCase() { MakeUpper(); }
3c67202d 672 // use Trim except that it doesn't change this string
c801d85f
KB
673 wxString Strip(stripType w = trailing) const;
674
3c67202d 675 // use Find (more general variants not yet supported)
2bb67b80
OK
676 size_t Index(const wxChar* psz) const { return Find(psz); }
677 size_t Index(wxChar ch) const { return Find(ch); }
3c67202d 678 // use Truncate
c801d85f
KB
679 wxString& Remove(size_t pos) { return Truncate(pos); }
680 wxString& RemoveLast() { return Truncate(Len() - 1); }
681
3ed358cb 682 wxString& Remove(size_t nStart, size_t nLen) { return erase( nStart, nLen ); }
dd1eaa89 683
3c67202d 684 // use Find()
2bb67b80
OK
685 int First( const wxChar ch ) const { return Find(ch); }
686 int First( const wxChar* psz ) const { return Find(psz); }
3ed358cb 687 int First( const wxString &str ) const { return Find(str); }
2bb67b80 688 int Last( const wxChar ch ) const { return Find(ch, TRUE); }
3c67202d 689 bool Contains(const wxString& str) const { return Find(str) != -1; }
c801d85f 690
3c67202d 691 // use IsEmpty()
c801d85f 692 bool IsNull() const { return IsEmpty(); }
c801d85f 693
3c67202d
VZ
694#ifdef wxSTD_STRING_COMPATIBILITY
695 // std::string compatibility functions
dd1eaa89 696
3c67202d 697 // an 'invalid' value for string index
c801d85f 698 static const size_t npos;
dd1eaa89 699
3c67202d
VZ
700 // constructors
701 // take nLen chars starting at nPos
702 wxString(const wxString& str, size_t nPos, size_t nLen)
703 {
704 wxASSERT( str.GetStringData()->IsValid() );
705 InitWith(str.c_str(), nPos, nLen == npos ? 0 : nLen);
706 }
707 // take all characters from pStart to pEnd
708 wxString(const void *pStart, const void *pEnd);
709
710 // lib.string.capacity
711 // return the length of the string
712 size_t size() const { return Len(); }
713 // return the length of the string
714 size_t length() const { return Len(); }
715 // return the maximum size of the string
566b84d2 716 size_t max_size() const { return wxSTRING_MAXLEN; }
3c67202d 717 // resize the string, filling the space with c if c != 0
2bb67b80 718 void resize(size_t nSize, wxChar ch = _T('\0'));
3c67202d
VZ
719 // delete the contents of the string
720 void clear() { Empty(); }
721 // returns true if the string is empty
722 bool empty() const { return IsEmpty(); }
723
724 // lib.string.access
725 // return the character at position n
2bb67b80 726 wxChar at(size_t n) const { return GetChar(n); }
3c67202d 727 // returns the writable character at position n
2bb67b80 728 wxChar& at(size_t n) { return GetWritableChar(n); }
3c67202d
VZ
729
730 // lib.string.modifiers
731 // append a string
732 wxString& append(const wxString& str)
733 { *this += str; return *this; }
734 // append elements str[pos], ..., str[pos+n]
735 wxString& append(const wxString& str, size_t pos, size_t n)
736 { ConcatSelf(n, str.c_str() + pos); return *this; }
737 // append first n (or all if n == npos) characters of sz
2bb67b80
OK
738 wxString& append(const wxChar *sz, size_t n = npos)
739 { ConcatSelf(n == npos ? wxStrlen(sz) : n, sz); return *this; }
3c67202d
VZ
740
741 // append n copies of ch
2bb67b80 742 wxString& append(size_t n, wxChar ch) { return Pad(n, ch); }
3c67202d
VZ
743
744 // same as `this_string = str'
745 wxString& assign(const wxString& str) { return (*this) = str; }
746 // same as ` = str[pos..pos + n]
747 wxString& assign(const wxString& str, size_t pos, size_t n)
2bb67b80 748 { return *this = wxString((const wxChar *)str + pos, n); }
3c67202d 749 // same as `= first n (or all if n == npos) characters of sz'
2bb67b80 750 wxString& assign(const wxChar *sz, size_t n = npos)
3c67202d
VZ
751 { return *this = wxString(sz, n); }
752 // same as `= n copies of ch'
2bb67b80 753 wxString& assign(size_t n, wxChar ch)
3c67202d
VZ
754 { return *this = wxString(ch, n); }
755
756 // insert another string
757 wxString& insert(size_t nPos, const wxString& str);
758 // insert n chars of str starting at nStart (in str)
759 wxString& insert(size_t nPos, const wxString& str, size_t nStart, size_t n)
2bb67b80 760 { return insert(nPos, wxString((const wxChar *)str + nStart, n)); }
3c67202d
VZ
761
762 // insert first n (or all if n == npos) characters of sz
2bb67b80 763 wxString& insert(size_t nPos, const wxChar *sz, size_t n = npos)
3c67202d
VZ
764 { return insert(nPos, wxString(sz, n)); }
765 // insert n copies of ch
2bb67b80 766 wxString& insert(size_t nPos, size_t n, wxChar ch)
3c67202d
VZ
767 { return insert(nPos, wxString(ch, n)); }
768
769 // delete characters from nStart to nStart + nLen
770 wxString& erase(size_t nStart = 0, size_t nLen = npos);
771
772 // replaces the substring of length nLen starting at nStart
2bb67b80 773 wxString& replace(size_t nStart, size_t nLen, const wxChar* sz);
3c67202d 774 // replaces the substring with nCount copies of ch
2bb67b80 775 wxString& replace(size_t nStart, size_t nLen, size_t nCount, wxChar ch);
3c67202d
VZ
776 // replaces a substring with another substring
777 wxString& replace(size_t nStart, size_t nLen,
778 const wxString& str, size_t nStart2, size_t nLen2);
779 // replaces the substring with first nCount chars of sz
780 wxString& replace(size_t nStart, size_t nLen,
2bb67b80 781 const wxChar* sz, size_t nCount);
3c67202d
VZ
782
783 // swap two strings
784 void swap(wxString& str);
785
786 // All find() functions take the nStart argument which specifies the
787 // position to start the search on, the default value is 0. All functions
788 // return npos if there were no match.
789
790 // find a substring
791 size_t find(const wxString& str, size_t nStart = 0) const;
792
793 // VC++ 1.5 can't cope with this syntax.
3f4a0c5b 794#if !defined(__VISUALC__) || defined(__WIN32__)
3c67202d 795 // find first n characters of sz
2bb67b80 796 size_t find(const wxChar* sz, size_t nStart = 0, size_t n = npos) const;
6b0eb19f 797#endif
3c67202d
VZ
798
799 // Gives a duplicate symbol (presumably a case-insensitivity problem)
62448488 800#if !defined(__BORLANDC__)
3c67202d 801 // find the first occurence of character ch after nStart
2bb67b80 802 size_t find(wxChar ch, size_t nStart = 0) const;
62448488 803#endif
3c67202d
VZ
804 // rfind() family is exactly like find() but works right to left
805
806 // as find, but from the end
807 size_t rfind(const wxString& str, size_t nStart = npos) const;
808
809 // VC++ 1.5 can't cope with this syntax.
3f4a0c5b 810#if !defined(__VISUALC__) || defined(__WIN32__)
3c67202d 811 // as find, but from the end
2bb67b80 812 size_t rfind(const wxChar* sz, size_t nStart = npos,
3c67202d
VZ
813 size_t n = npos) const;
814 // as find, but from the end
2bb67b80 815 size_t rfind(wxChar ch, size_t nStart = npos) const;
c801d85f 816#endif
3c67202d
VZ
817
818 // find first/last occurence of any character in the set
819
820 //
821 size_t find_first_of(const wxString& str, size_t nStart = 0) const;
822 //
2bb67b80 823 size_t find_first_of(const wxChar* sz, size_t nStart = 0) const;
3c67202d 824 // same as find(char, size_t)
2bb67b80 825 size_t find_first_of(wxChar c, size_t nStart = 0) const;
3c67202d
VZ
826 //
827 size_t find_last_of (const wxString& str, size_t nStart = npos) const;
828 //
2bb67b80 829 size_t find_last_of (const wxChar* s, size_t nStart = npos) const;
3c67202d 830 // same as rfind(char, size_t)
2bb67b80 831 size_t find_last_of (wxChar c, size_t nStart = npos) const;
3c67202d
VZ
832
833 // find first/last occurence of any character not in the set
834
835 //
836 size_t find_first_not_of(const wxString& str, size_t nStart = 0) const;
837 //
2bb67b80 838 size_t find_first_not_of(const wxChar* s, size_t nStart = 0) const;
3c67202d 839 //
2bb67b80 840 size_t find_first_not_of(wxChar ch, size_t nStart = 0) const;
3c67202d
VZ
841 //
842 size_t find_last_not_of(const wxString& str, size_t nStart=npos) const;
843 //
2bb67b80 844 size_t find_last_not_of(const wxChar* s, size_t nStart = npos) const;
3c67202d 845 //
2bb67b80 846 size_t find_last_not_of(wxChar ch, size_t nStart = npos) const;
3c67202d
VZ
847
848 // All compare functions return -1, 0 or 1 if the [sub]string is less,
849 // equal or greater than the compare() argument.
850
851 // just like strcmp()
852 int compare(const wxString& str) const { return Cmp(str); }
853 // comparison with a substring
854 int compare(size_t nStart, size_t nLen, const wxString& str) const;
855 // comparison of 2 substrings
856 int compare(size_t nStart, size_t nLen,
857 const wxString& str, size_t nStart2, size_t nLen2) const;
858 // just like strcmp()
2bb67b80 859 int compare(const wxChar* sz) const { return Cmp(sz); }
3c67202d
VZ
860 // substring comparison with first nCount characters of sz
861 int compare(size_t nStart, size_t nLen,
2bb67b80 862 const wxChar* sz, size_t nCount = npos) const;
3c67202d
VZ
863
864 // substring extraction
865 wxString substr(size_t nStart = 0, size_t nLen = npos) const;
866#endif // wxSTD_STRING_COMPATIBILITY
c801d85f
KB
867};
868
869// ----------------------------------------------------------------------------
3c67202d
VZ
870// The string array uses it's knowledge of internal structure of the wxString
871// class to optimize string storage. Normally, we would store pointers to
872// string, but as wxString is, in fact, itself a pointer (sizeof(wxString) is
873// sizeof(char *)) we store these pointers instead. The cast to "wxString *" is
874// really all we need to turn such pointer into a string!
875//
876// Of course, it can be called a dirty hack, but we use twice less memory and
877// this approach is also more speed efficient, so it's probably worth it.
878//
879// Usage notes: when a string is added/inserted, a new copy of it is created,
880// so the original string may be safely deleted. When a string is retrieved
881// from the array (operator[] or Item() method), a reference is returned.
c801d85f 882// ----------------------------------------------------------------------------
fbcb4166 883class WXDLLEXPORT wxArrayString
c801d85f
KB
884{
885public:
30b21f9a
VZ
886 // type of function used by wxArrayString::Sort()
887 typedef int (*CompareFunction)(const wxString& first,
888 const wxString& second);
889
3c67202d
VZ
890 // constructors and destructor
891 // default ctor
c801d85f 892 wxArrayString();
3c67202d 893 // copy ctor
c801d85f 894 wxArrayString(const wxArrayString& array);
3c67202d 895 // assignment operator
c801d85f 896 wxArrayString& operator=(const wxArrayString& src);
3c67202d 897 // not virtual, this class should not be derived from
c801d85f 898 ~wxArrayString();
c801d85f 899
3c67202d
VZ
900 // memory management
901 // empties the list, but doesn't release memory
c801d85f 902 void Empty();
3c67202d 903 // empties the list and releases memory
c801d85f 904 void Clear();
3c67202d 905 // preallocates memory for given number of items
c801d85f 906 void Alloc(size_t nCount);
3c67202d 907 // minimzes the memory usage (by freeing all extra memory)
dd1eaa89 908 void Shrink();
3c67202d
VZ
909
910 // simple accessors
911 // number of elements in the array
912 size_t GetCount() const { return m_nCount; }
913 // is it empty?
914 bool IsEmpty() const { return m_nCount == 0; }
915 // number of elements in the array (GetCount is preferred API)
916 size_t Count() const { return m_nCount; }
917
918 // items access (range checking is done in debug version)
919 // get item at position uiIndex
c801d85f
KB
920 wxString& Item(size_t nIndex) const
921 { wxASSERT( nIndex < m_nCount ); return *(wxString *)&(m_pItems[nIndex]); }
3c67202d 922 // same as Item()
c801d85f 923 wxString& operator[](size_t nIndex) const { return Item(nIndex); }
3c67202d 924 // get last item
c801d85f 925 wxString& Last() const { wxASSERT( !IsEmpty() ); return Item(Count() - 1); }
3c67202d
VZ
926
927 // item management
928 // Search the element in the array, starting from the beginning if
929 // bFromEnd is FALSE or from end otherwise. If bCase, comparison is case
930 // sensitive (default). Returns index of the first item matched or
931 // wxNOT_FOUND
2bb67b80 932 int Index (const wxChar *sz, bool bCase = TRUE, bool bFromEnd = FALSE) const;
3c67202d
VZ
933 // add new element at the end
934 void Add(const wxString& str);
935 // add new element at given position
c86f1403 936 void Insert(const wxString& str, size_t uiIndex);
3c67202d 937 // remove first item matching this value
2bb67b80 938 void Remove(const wxChar *sz);
3c67202d 939 // remove item by index
c801d85f 940 void Remove(size_t nIndex);
c801d85f 941
30b21f9a
VZ
942 // sorting
943 // sort array elements in alphabetical order (or reversed alphabetical
944 // order if reverseOrder parameter is TRUE)
945 void Sort(bool reverseOrder = FALSE);
946 // sort array elements using specified comparaison function
947 void Sort(CompareFunction compareFunction);
c801d85f
KB
948
949private:
950 void Grow(); // makes array bigger if needed
951 void Free(); // free the string stored
952
30b21f9a
VZ
953 void DoSort(); // common part of all Sort() variants
954
3c67202d 955 size_t m_nSize, // current size of the array
c801d85f
KB
956 m_nCount; // current number of elements
957
2bb67b80 958 wxChar **m_pItems; // pointer to data
c801d85f
KB
959};
960
c801d85f 961// ---------------------------------------------------------------------------
3c67202d 962// wxString comparison functions: operator versions are always case sensitive
c801d85f 963// ---------------------------------------------------------------------------
3c67202d 964//
a3ef5bf5 965inline bool operator==(const wxString& s1, const wxString& s2) { return (s1.Cmp(s2) == 0); }
3c67202d 966//
2bb67b80 967inline bool operator==(const wxString& s1, const wxChar * s2) { return (s1.Cmp(s2) == 0); }
3c67202d 968//
2bb67b80 969inline bool operator==(const wxChar * s1, const wxString& s2) { return (s2.Cmp(s1) == 0); }
3c67202d 970//
a3ef5bf5 971inline bool operator!=(const wxString& s1, const wxString& s2) { return (s1.Cmp(s2) != 0); }
3c67202d 972//
2bb67b80 973inline bool operator!=(const wxString& s1, const wxChar * s2) { return (s1.Cmp(s2) != 0); }
3c67202d 974//
2bb67b80 975inline bool operator!=(const wxChar * s1, const wxString& s2) { return (s2.Cmp(s1) != 0); }
3c67202d 976//
a3ef5bf5 977inline bool operator< (const wxString& s1, const wxString& s2) { return (s1.Cmp(s2) < 0); }
3c67202d 978//
2bb67b80 979inline bool operator< (const wxString& s1, const wxChar * s2) { return (s1.Cmp(s2) < 0); }
3c67202d 980//
2bb67b80 981inline bool operator< (const wxChar * s1, const wxString& s2) { return (s2.Cmp(s1) > 0); }
3c67202d 982//
a3ef5bf5 983inline bool operator> (const wxString& s1, const wxString& s2) { return (s1.Cmp(s2) > 0); }
3c67202d 984//
2bb67b80 985inline bool operator> (const wxString& s1, const wxChar * s2) { return (s1.Cmp(s2) > 0); }
3c67202d 986//
2bb67b80 987inline bool operator> (const wxChar * s1, const wxString& s2) { return (s2.Cmp(s1) < 0); }
3c67202d 988//
a3ef5bf5 989inline bool operator<=(const wxString& s1, const wxString& s2) { return (s1.Cmp(s2) <= 0); }
3c67202d 990//
2bb67b80 991inline bool operator<=(const wxString& s1, const wxChar * s2) { return (s1.Cmp(s2) <= 0); }
3c67202d 992//
2bb67b80 993inline bool operator<=(const wxChar * s1, const wxString& s2) { return (s2.Cmp(s1) >= 0); }
3c67202d 994//
a3ef5bf5 995inline bool operator>=(const wxString& s1, const wxString& s2) { return (s1.Cmp(s2) >= 0); }
3c67202d 996//
2bb67b80 997inline bool operator>=(const wxString& s1, const wxChar * s2) { return (s1.Cmp(s2) >= 0); }
3c67202d 998//
2bb67b80 999inline bool operator>=(const wxChar * s1, const wxString& s2) { return (s2.Cmp(s1) <= 0); }
3c67202d 1000
ed7174ba 1001wxString WXDLLEXPORT operator+(const wxString& string1, const wxString& string2);
2bb67b80
OK
1002wxString WXDLLEXPORT operator+(const wxString& string, wxChar ch);
1003wxString WXDLLEXPORT operator+(wxChar ch, const wxString& string);
1004wxString WXDLLEXPORT operator+(const wxString& string, const wxChar *psz);
1005wxString WXDLLEXPORT operator+(const wxChar *psz, const wxString& string);
028a2b5d 1006#if wxUSE_UNICODE
c6cee672 1007inline wxString WXDLLEXPORT operator+(const wxString& string, const wxWCharBuffer& buf)
028a2b5d 1008{ return string + (const wchar_t *)buf; }
c6cee672 1009inline wxString WXDLLEXPORT operator+(const wxWCharBuffer& buf, const wxString& string)
bf88baa6 1010{ return (const wchar_t *)buf + string; }
028a2b5d 1011#else
c6cee672 1012inline wxString WXDLLEXPORT operator+(const wxString& string, const wxCharBuffer& buf)
028a2b5d 1013{ return string + (const char *)buf; }
c6cee672 1014inline wxString WXDLLEXPORT operator+(const wxCharBuffer& buf, const wxString& string)
bf88baa6 1015{ return (const char *)buf + string; }
028a2b5d 1016#endif
f04f3991 1017
c801d85f 1018// ---------------------------------------------------------------------------
3c67202d 1019// Implementation only from here until the end of file
c801d85f
KB
1020// ---------------------------------------------------------------------------
1021
3c67202d 1022#ifdef wxSTD_STRING_COMPATIBILITY
c801d85f 1023
3f4a0c5b 1024#include "wx/ioswrap.h"
c801d85f 1025
184b5d99 1026WXDLLEXPORT istream& operator>>(istream& is, wxString& str);
c801d85f 1027
3c67202d 1028#endif // wxSTD_STRING_COMPATIBILITY
c801d85f 1029
34138703 1030#endif // _WX_WXSTRINGH__