]> git.saurik.com Git - wxWidgets.git/blame - src/common/string.cpp
PCH-less compilation fix
[wxWidgets.git] / src / common / string.cpp
CommitLineData
c801d85f 1/////////////////////////////////////////////////////////////////////////////
8898456d 2// Name: src/common/string.cpp
c801d85f 3// Purpose: wxString class
59059feb 4// Author: Vadim Zeitlin, Ryan Norton
c801d85f
KB
5// Modified by:
6// Created: 29/01/98
7// RCS-ID: $Id$
8// Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
59059feb 9// (c) 2004 Ryan Norton <wxprojects@comcast.net>
65571936 10// Licence: wxWindows licence
c801d85f
KB
11/////////////////////////////////////////////////////////////////////////////
12
c801d85f
KB
13// ===========================================================================
14// headers, declarations, constants
15// ===========================================================================
16
17// For compilers that support precompilation, includes "wx.h".
18#include "wx/wxprec.h"
19
20#ifdef __BORLANDC__
8898456d 21 #pragma hdrstop
c801d85f
KB
22#endif
23
24#ifndef WX_PRECOMP
8898456d 25 #include "wx/string.h"
2523e9b7 26 #include "wx/wxcrtvararg.h"
6b769f3d 27#endif
c801d85f
KB
28
29#include <ctype.h>
92df97b8
WS
30
31#ifndef __WXWINCE__
32 #include <errno.h>
33#endif
34
c801d85f
KB
35#include <string.h>
36#include <stdlib.h>
9a08c20e 37
ce3ed50d 38#ifdef __SALFORDC__
8898456d 39 #include <clib.h>
ce3ed50d
JS
40#endif
41
8116a0c5 42#include "wx/hashmap.h"
8f93a29f
VS
43
44// string handling functions used by wxString:
45#if wxUSE_UNICODE_UTF8
46 #define wxStringMemcpy memcpy
47 #define wxStringMemcmp memcmp
48 #define wxStringMemchr memchr
49 #define wxStringStrlen strlen
50#else
51 #define wxStringMemcpy wxTmemcpy
52 #define wxStringMemcmp wxTmemcmp
a7ea63e2
VS
53 #define wxStringMemchr wxTmemchr
54 #define wxStringStrlen wxStrlen
55#endif
8f93a29f 56
e87b7833 57
a7ea63e2
VS
58// ---------------------------------------------------------------------------
59// static class variables definition
60// ---------------------------------------------------------------------------
e87b7833 61
a7ea63e2
VS
62//According to STL _must_ be a -1 size_t
63const size_t wxString::npos = (size_t) -1;
8f93a29f 64
a7ea63e2
VS
65// ----------------------------------------------------------------------------
66// global functions
67// ----------------------------------------------------------------------------
e87b7833 68
a7ea63e2 69#if wxUSE_STD_IOSTREAM
8f93a29f 70
a7ea63e2 71#include <iostream>
8f93a29f 72
a7ea63e2 73wxSTD ostream& operator<<(wxSTD ostream& os, const wxCStrData& str)
8f93a29f 74{
04abe4bc 75// FIXME-UTF8: always, not only if wxUSE_UNICODE
a7ea63e2 76#if wxUSE_UNICODE && !defined(__BORLANDC__)
681e4412 77 return os << (const wchar_t*)str.AsWCharBuf();
a7ea63e2 78#else
681e4412 79 return os << (const char*)str.AsCharBuf();
a7ea63e2 80#endif
8f93a29f
VS
81}
82
04abe4bc
VS
83wxSTD ostream& operator<<(wxSTD ostream& os, const wxString& str)
84{
85 return os << str.c_str();
86}
87
88wxSTD ostream& operator<<(wxSTD ostream& os, const wxCharBuffer& str)
89{
90 return os << str.data();
91}
92
93#ifndef __BORLANDC__
94wxSTD ostream& operator<<(wxSTD ostream& os, const wxWCharBuffer& str)
95{
96 return os << str.data();
97}
98#endif
99
a7ea63e2 100#endif // wxUSE_STD_IOSTREAM
e87b7833 101
81727065
VS
102// ===========================================================================
103// wxString class core
104// ===========================================================================
105
106#if wxUSE_UNICODE_UTF8
107
81727065
VS
108void wxString::PosLenToImpl(size_t pos, size_t len,
109 size_t *implPos, size_t *implLen) const
110{
111 if ( pos == npos )
112 *implPos = npos;
113 else
114 {
115 const_iterator i = begin() + pos;
cf9a878b 116 *implPos = wxStringImpl::const_iterator(i.impl()) - m_impl.begin();
81727065
VS
117 if ( len == npos )
118 *implLen = npos;
119 else
120 {
121 // too large length is interpreted as "to the end of the string"
122 // FIXME-UTF8: verify this is the case in std::string, assert
123 // otherwise
124 if ( pos + len > length() )
125 len = length() - pos;
126
cf9a878b 127 *implLen = (i + len).impl() - i.impl();
81727065
VS
128 }
129 }
130}
131
132#endif // wxUSE_UNICODE_UTF8
133
11aac4ba
VS
134// ----------------------------------------------------------------------------
135// wxCStrData converted strings caching
136// ----------------------------------------------------------------------------
137
132276cf
VS
138// FIXME-UTF8: temporarily disabled because it doesn't work with global
139// string objects; re-enable after fixing this bug and benchmarking
140// performance to see if using a hash is a good idea at all
141#if 0
142
11aac4ba
VS
143// For backward compatibility reasons, it must be possible to assign the value
144// returned by wxString::c_str() to a char* or wchar_t* variable and work with
145// it. Returning wxCharBuffer from (const char*)c_str() wouldn't do the trick,
146// because the memory would be freed immediately, but it has to be valid as long
147// as the string is not modified, so that code like this still works:
148//
149// const wxChar *s = str.c_str();
150// while ( s ) { ... }
151
152// FIXME-UTF8: not thread safe!
153// FIXME-UTF8: we currently clear the cached conversion only when the string is
154// destroyed, but we should do it when the string is modified, to
155// keep memory usage down
156// FIXME-UTF8: we do the conversion every time As[W]Char() is called, but if we
157// invalidated the cache on every change, we could keep the previous
158// conversion
159// FIXME-UTF8: add tracing of usage of these two methods - new code is supposed
160// to use mb_str() or wc_str() instead of (const [w]char*)c_str()
161
162template<typename T>
163static inline void DeleteStringFromConversionCache(T& hash, const wxString *s)
164{
6c4ebcda 165 typename T::iterator i = hash.find(wxConstCast(s, wxString));
11aac4ba
VS
166 if ( i != hash.end() )
167 {
168 free(i->second);
169 hash.erase(i);
170 }
171}
172
173#if wxUSE_UNICODE
6c4ebcda
VS
174// NB: non-STL implementation doesn't compile with "const wxString*" key type,
175// so we have to use wxString* here and const-cast when used
11aac4ba
VS
176WX_DECLARE_HASH_MAP(wxString*, char*, wxPointerHash, wxPointerEqual,
177 wxStringCharConversionCache);
178static wxStringCharConversionCache gs_stringsCharCache;
179
180const char* wxCStrData::AsChar() const
181{
182 // remove previously cache value, if any (see FIXMEs above):
183 DeleteStringFromConversionCache(gs_stringsCharCache, m_str);
184
185 // convert the string and keep it:
6c4ebcda
VS
186 const char *s = gs_stringsCharCache[wxConstCast(m_str, wxString)] =
187 m_str->mb_str().release();
11aac4ba
VS
188
189 return s + m_offset;
190}
191#endif // wxUSE_UNICODE
192
193#if !wxUSE_UNICODE_WCHAR
194WX_DECLARE_HASH_MAP(wxString*, wchar_t*, wxPointerHash, wxPointerEqual,
195 wxStringWCharConversionCache);
196static wxStringWCharConversionCache gs_stringsWCharCache;
197
198const wchar_t* wxCStrData::AsWChar() const
199{
200 // remove previously cache value, if any (see FIXMEs above):
201 DeleteStringFromConversionCache(gs_stringsWCharCache, m_str);
202
203 // convert the string and keep it:
6c4ebcda
VS
204 const wchar_t *s = gs_stringsWCharCache[wxConstCast(m_str, wxString)] =
205 m_str->wc_str().release();
11aac4ba
VS
206
207 return s + m_offset;
208}
209#endif // !wxUSE_UNICODE_WCHAR
210
11aac4ba
VS
211wxString::~wxString()
212{
213#if wxUSE_UNICODE
214 // FIXME-UTF8: do this only if locale is not UTF8 if wxUSE_UNICODE_UTF8
215 DeleteStringFromConversionCache(gs_stringsCharCache, this);
216#endif
217#if !wxUSE_UNICODE_WCHAR
218 DeleteStringFromConversionCache(gs_stringsWCharCache, this);
219#endif
220}
132276cf
VS
221#endif
222
111d9948 223#if wxUSE_UNICODE && !wxUSE_UTF8_LOCALE_ONLY
132276cf
VS
224const char* wxCStrData::AsChar() const
225{
111d9948
VS
226#if wxUSE_UNICODE_UTF8
227 if ( wxLocaleIsUtf8 )
228 return AsInternal();
229#endif
230 // under non-UTF8 locales, we have to convert the internal UTF-8
231 // representation using wxConvLibc and cache the result
232
132276cf 233 wxString *str = wxConstCast(m_str, wxString);
05f32fc3
VS
234
235 // convert the string:
2a7431e1
VZ
236 //
237 // FIXME-UTF8: we'd like to do the conversion in the existing buffer (if we
238 // have it) but it's unfortunately not obvious to implement
239 // because we don't know how big buffer do we need for the
240 // given string length (in case of multibyte encodings, e.g.
241 // ISO-2022-JP or UTF-8 when internal representation is wchar_t)
242 //
243 // One idea would be to store more than just m_convertedToChar
244 // in wxString: then we could record the length of the string
245 // which was converted the last time and try to reuse the same
246 // buffer if the current length is not greater than it (this
247 // could still fail because string could have been modified in
248 // place but it would work most of the time, so we'd do it and
249 // only allocate the new buffer if in-place conversion returned
250 // an error). We could also store a bit saying if the string
251 // was modified since the last conversion (and update it in all
252 // operation modifying the string, of course) to avoid unneeded
253 // consequential conversions. But both of these ideas require
254 // adding more fields to wxString and require profiling results
255 // to be sure that we really gain enough from them to justify
256 // doing it.
05f32fc3
VS
257 wxCharBuffer buf(str->mb_str());
258
28be59b4
VZ
259 // if it failed, return empty string and not NULL to avoid crashes in code
260 // written with either wxWidgets 2 wxString or std::string behaviour in
261 // mind: neither of them ever returns NULL and so we shouldn't neither
262 if ( !buf )
263 return "";
264
05f32fc3
VS
265 if ( str->m_convertedToChar &&
266 strlen(buf) == strlen(str->m_convertedToChar) )
267 {
268 // keep the same buffer for as long as possible, so that several calls
269 // to c_str() in a row still work:
270 strcpy(str->m_convertedToChar, buf);
271 }
272 else
273 {
274 str->m_convertedToChar = buf.release();
275 }
276
277 // and keep it:
132276cf
VS
278 return str->m_convertedToChar + m_offset;
279}
111d9948 280#endif // wxUSE_UNICODE && !wxUSE_UTF8_LOCALE_ONLY
132276cf
VS
281
282#if !wxUSE_UNICODE_WCHAR
283const wchar_t* wxCStrData::AsWChar() const
284{
285 wxString *str = wxConstCast(m_str, wxString);
05f32fc3
VS
286
287 // convert the string:
288 wxWCharBuffer buf(str->wc_str());
289
28be59b4
VZ
290 // notice that here, unlike above in AsChar(), conversion can't fail as our
291 // internal UTF-8 is always well-formed -- or the string was corrupted and
292 // all bets are off anyhow
293
05f32fc3
VS
294 // FIXME-UTF8: do the conversion in-place in the existing buffer
295 if ( str->m_convertedToWChar &&
296 wxWcslen(buf) == wxWcslen(str->m_convertedToWChar) )
297 {
298 // keep the same buffer for as long as possible, so that several calls
299 // to c_str() in a row still work:
300 memcpy(str->m_convertedToWChar, buf, sizeof(wchar_t) * wxWcslen(buf));
301 }
302 else
303 {
304 str->m_convertedToWChar = buf.release();
305 }
306
307 // and keep it:
132276cf
VS
308 return str->m_convertedToWChar + m_offset;
309}
310#endif // !wxUSE_UNICODE_WCHAR
311
312// ===========================================================================
313// wxString class core
314// ===========================================================================
315
316// ---------------------------------------------------------------------------
317// construction and conversion
318// ---------------------------------------------------------------------------
11aac4ba 319
81727065 320#if wxUSE_UNICODE_WCHAR
8f93a29f
VS
321/* static */
322wxString::SubstrBufFromMB wxString::ConvertStr(const char *psz, size_t nLength,
04abe4bc 323 const wxMBConv& conv)
8f93a29f
VS
324{
325 // anything to do?
326 if ( !psz || nLength == 0 )
81727065 327 return SubstrBufFromMB(L"", 0);
8f93a29f
VS
328
329 if ( nLength == npos )
330 nLength = wxNO_LEN;
331
332 size_t wcLen;
333 wxWCharBuffer wcBuf(conv.cMB2WC(psz, nLength, &wcLen));
334 if ( !wcLen )
81727065 335 return SubstrBufFromMB(_T(""), 0);
8f93a29f
VS
336 else
337 return SubstrBufFromMB(wcBuf, wcLen);
338}
81727065
VS
339#endif // wxUSE_UNICODE_WCHAR
340
341#if wxUSE_UNICODE_UTF8
342/* static */
343wxString::SubstrBufFromMB wxString::ConvertStr(const char *psz, size_t nLength,
344 const wxMBConv& conv)
345{
81727065
VS
346 // anything to do?
347 if ( !psz || nLength == 0 )
348 return SubstrBufFromMB("", 0);
349
111d9948
VS
350 // if psz is already in UTF-8, we don't have to do the roundtrip to
351 // wchar_t* and back:
352 if ( conv.IsUTF8() )
353 {
354 // we need to validate the input because UTF8 iterators assume valid
355 // UTF-8 sequence and psz may be invalid:
356 if ( wxStringOperations::IsValidUtf8String(psz, nLength) )
357 {
358 return SubstrBufFromMB(wxCharBuffer::CreateNonOwned(psz), nLength);
359 }
360 // else: do the roundtrip through wchar_t*
361 }
362
81727065
VS
363 if ( nLength == npos )
364 nLength = wxNO_LEN;
365
366 // first convert to wide string:
367 size_t wcLen;
368 wxWCharBuffer wcBuf(conv.cMB2WC(psz, nLength, &wcLen));
369 if ( !wcLen )
370 return SubstrBufFromMB("", 0);
371
372 // and then to UTF-8:
4fdfe2f3 373 SubstrBufFromMB buf(ConvertStr(wcBuf, wcLen, wxMBConvStrictUTF8()));
81727065
VS
374 // widechar -> UTF-8 conversion isn't supposed to ever fail:
375 wxASSERT_MSG( buf.data, _T("conversion to UTF-8 failed") );
376
377 return buf;
378}
379#endif // wxUSE_UNICODE_UTF8
380
381#if wxUSE_UNICODE_UTF8 || !wxUSE_UNICODE
8f93a29f
VS
382/* static */
383wxString::SubstrBufFromWC wxString::ConvertStr(const wchar_t *pwz, size_t nLength,
04abe4bc 384 const wxMBConv& conv)
8f93a29f
VS
385{
386 // anything to do?
387 if ( !pwz || nLength == 0 )
81727065 388 return SubstrBufFromWC("", 0);
8f93a29f
VS
389
390 if ( nLength == npos )
391 nLength = wxNO_LEN;
392
393 size_t mbLen;
394 wxCharBuffer mbBuf(conv.cWC2MB(pwz, nLength, &mbLen));
395 if ( !mbLen )
81727065 396 return SubstrBufFromWC("", 0);
8f93a29f
VS
397 else
398 return SubstrBufFromWC(mbBuf, mbLen);
399}
81727065 400#endif // wxUSE_UNICODE_UTF8 || !wxUSE_UNICODE
8f93a29f
VS
401
402
81727065 403#if wxUSE_UNICODE_WCHAR
e87b7833 404
06386448 405//Convert wxString in Unicode mode to a multi-byte string
830f8f11 406const wxCharBuffer wxString::mb_str(const wxMBConv& conv) const
265d5cce 407{
81727065 408 return conv.cWC2MB(wx_str(), length() + 1 /* size, not length */, NULL);
e87b7833
MB
409}
410
81727065 411#elif wxUSE_UNICODE_UTF8
e87b7833 412
81727065
VS
413const wxWCharBuffer wxString::wc_str() const
414{
4fdfe2f3
VZ
415 return wxMBConvStrictUTF8().cMB2WC
416 (
417 m_impl.c_str(),
418 m_impl.length() + 1, // size, not length
419 NULL
420 );
81727065
VS
421}
422
423const wxCharBuffer wxString::mb_str(const wxMBConv& conv) const
424{
111d9948
VS
425 if ( conv.IsUTF8() )
426 return wxCharBuffer::CreateNonOwned(m_impl.c_str());
427
81727065
VS
428 // FIXME-UTF8: use wc_str() here once we have buffers with length
429
430 size_t wcLen;
4fdfe2f3
VZ
431 wxWCharBuffer wcBuf(wxMBConvStrictUTF8().cMB2WC
432 (
433 m_impl.c_str(),
434 m_impl.length() + 1, // size
435 &wcLen
436 ));
81727065
VS
437 if ( !wcLen )
438 return wxCharBuffer("");
439
4f696af8 440 return conv.cWC2MB(wcBuf, wcLen+1, NULL);
81727065
VS
441}
442
443#else // ANSI
eec47cc6 444
7663d0d4 445//Converts this string to a wide character string if unicode
06386448 446//mode is not enabled and wxUSE_WCHAR_T is enabled
830f8f11 447const wxWCharBuffer wxString::wc_str(const wxMBConv& conv) const
265d5cce 448{
81727065 449 return conv.cMB2WC(wx_str(), length() + 1 /* size, not length */, NULL);
265d5cce 450}
7663d0d4 451
e87b7833
MB
452#endif // Unicode/ANSI
453
454// shrink to minimal size (releasing extra memory)
455bool wxString::Shrink()
456{
457 wxString tmp(begin(), end());
458 swap(tmp);
459 return tmp.length() == length();
460}
461
d8a4b666 462// deprecated compatibility code:
a7ea63e2 463#if WXWIN_COMPATIBILITY_2_8 && !wxUSE_STL_BASED_WXSTRING && !wxUSE_UNICODE_UTF8
c87a0bc8 464wxStringCharType *wxString::GetWriteBuf(size_t nLen)
d8a4b666
VS
465{
466 return DoGetWriteBuf(nLen);
467}
468
469void wxString::UngetWriteBuf()
470{
471 DoUngetWriteBuf();
472}
473
474void wxString::UngetWriteBuf(size_t nLen)
475{
476 DoUngetWriteBuf(nLen);
477}
a7ea63e2 478#endif // WXWIN_COMPATIBILITY_2_8 && !wxUSE_STL_BASED_WXSTRING && !wxUSE_UNICODE_UTF8
e87b7833 479
d8a4b666 480
e87b7833
MB
481// ---------------------------------------------------------------------------
482// data access
483// ---------------------------------------------------------------------------
484
485// all functions are inline in string.h
486
487// ---------------------------------------------------------------------------
e8f59039 488// concatenation operators
e87b7833
MB
489// ---------------------------------------------------------------------------
490
c801d85f 491/*
c801d85f
KB
492 * concatenation functions come in 5 flavours:
493 * string + string
494 * char + string and string + char
495 * C str + string and string + C str
496 */
497
b1801e0e 498wxString operator+(const wxString& str1, const wxString& str2)
c801d85f 499{
992527a5 500#if !wxUSE_STL_BASED_WXSTRING
8f93a29f
VS
501 wxASSERT( str1.IsValid() );
502 wxASSERT( str2.IsValid() );
e87b7833 503#endif
097c080b 504
3458e408
WS
505 wxString s = str1;
506 s += str2;
3168a13f 507
3458e408 508 return s;
c801d85f
KB
509}
510
c9f78968 511wxString operator+(const wxString& str, wxUniChar ch)
c801d85f 512{
992527a5 513#if !wxUSE_STL_BASED_WXSTRING
8f93a29f 514 wxASSERT( str.IsValid() );
e87b7833 515#endif
3168a13f 516
3458e408
WS
517 wxString s = str;
518 s += ch;
097c080b 519
3458e408 520 return s;
c801d85f
KB
521}
522
c9f78968 523wxString operator+(wxUniChar ch, const wxString& str)
c801d85f 524{
992527a5 525#if !wxUSE_STL_BASED_WXSTRING
8f93a29f 526 wxASSERT( str.IsValid() );
e87b7833 527#endif
097c080b 528
3458e408
WS
529 wxString s = ch;
530 s += str;
3168a13f 531
3458e408 532 return s;
c801d85f
KB
533}
534
8f93a29f 535wxString operator+(const wxString& str, const char *psz)
c801d85f 536{
992527a5 537#if !wxUSE_STL_BASED_WXSTRING
8f93a29f 538 wxASSERT( str.IsValid() );
e87b7833 539#endif
097c080b 540
3458e408 541 wxString s;
8f93a29f 542 if ( !s.Alloc(strlen(psz) + str.length()) ) {
3458e408
WS
543 wxFAIL_MSG( _T("out of memory in wxString::operator+") );
544 }
545 s += str;
546 s += psz;
3168a13f 547
3458e408 548 return s;
c801d85f
KB
549}
550
8f93a29f 551wxString operator+(const wxString& str, const wchar_t *pwz)
c801d85f 552{
992527a5 553#if !wxUSE_STL_BASED_WXSTRING
8f93a29f
VS
554 wxASSERT( str.IsValid() );
555#endif
556
557 wxString s;
558 if ( !s.Alloc(wxWcslen(pwz) + str.length()) ) {
559 wxFAIL_MSG( _T("out of memory in wxString::operator+") );
560 }
561 s += str;
562 s += pwz;
563
564 return s;
565}
566
567wxString operator+(const char *psz, const wxString& str)
568{
a7ea63e2
VS
569#if !wxUSE_STL_BASED_WXSTRING
570 wxASSERT( str.IsValid() );
571#endif
572
573 wxString s;
574 if ( !s.Alloc(strlen(psz) + str.length()) ) {
575 wxFAIL_MSG( _T("out of memory in wxString::operator+") );
576 }
577 s = psz;
578 s += str;
579
580 return s;
581}
582
583wxString operator+(const wchar_t *pwz, const wxString& str)
584{
585#if !wxUSE_STL_BASED_WXSTRING
586 wxASSERT( str.IsValid() );
587#endif
588
589 wxString s;
590 if ( !s.Alloc(wxWcslen(pwz) + str.length()) ) {
591 wxFAIL_MSG( _T("out of memory in wxString::operator+") );
592 }
593 s = pwz;
594 s += str;
595
596 return s;
597}
598
599// ---------------------------------------------------------------------------
600// string comparison
601// ---------------------------------------------------------------------------
602
52de37c7
VS
603bool wxString::IsSameAs(wxUniChar c, bool compareWithCase) const
604{
605 return (length() == 1) && (compareWithCase ? GetChar(0u) == c
606 : wxToupper(GetChar(0u)) == wxToupper(c));
607}
608
a7ea63e2
VS
609#ifdef HAVE_STD_STRING_COMPARE
610
611// NB: Comparison code (both if HAVE_STD_STRING_COMPARE and if not) works with
612// UTF-8 encoded strings too, thanks to UTF-8's design which allows us to
613// sort strings in characters code point order by sorting the byte sequence
614// in byte values order (i.e. what strcmp() and memcmp() do).
615
616int wxString::compare(const wxString& str) const
617{
618 return m_impl.compare(str.m_impl);
619}
620
621int wxString::compare(size_t nStart, size_t nLen,
622 const wxString& str) const
623{
624 size_t pos, len;
625 PosLenToImpl(nStart, nLen, &pos, &len);
626 return m_impl.compare(pos, len, str.m_impl);
627}
628
629int wxString::compare(size_t nStart, size_t nLen,
630 const wxString& str,
631 size_t nStart2, size_t nLen2) const
632{
633 size_t pos, len;
634 PosLenToImpl(nStart, nLen, &pos, &len);
635
636 size_t pos2, len2;
637 str.PosLenToImpl(nStart2, nLen2, &pos2, &len2);
638
639 return m_impl.compare(pos, len, str.m_impl, pos2, len2);
640}
641
642int wxString::compare(const char* sz) const
643{
644 return m_impl.compare(ImplStr(sz));
645}
646
647int wxString::compare(const wchar_t* sz) const
648{
649 return m_impl.compare(ImplStr(sz));
650}
651
652int wxString::compare(size_t nStart, size_t nLen,
653 const char* sz, size_t nCount) const
654{
655 size_t pos, len;
656 PosLenToImpl(nStart, nLen, &pos, &len);
657
658 SubstrBufFromMB str(ImplStr(sz, nCount));
659
660 return m_impl.compare(pos, len, str.data, str.len);
661}
662
663int wxString::compare(size_t nStart, size_t nLen,
664 const wchar_t* sz, size_t nCount) const
665{
666 size_t pos, len;
667 PosLenToImpl(nStart, nLen, &pos, &len);
668
669 SubstrBufFromWC str(ImplStr(sz, nCount));
670
671 return m_impl.compare(pos, len, str.data, str.len);
672}
673
674#else // !HAVE_STD_STRING_COMPARE
675
676static inline int wxDoCmp(const wxStringCharType* s1, size_t l1,
677 const wxStringCharType* s2, size_t l2)
678{
679 if( l1 == l2 )
680 return wxStringMemcmp(s1, s2, l1);
681 else if( l1 < l2 )
682 {
683 int ret = wxStringMemcmp(s1, s2, l1);
684 return ret == 0 ? -1 : ret;
685 }
686 else
687 {
688 int ret = wxStringMemcmp(s1, s2, l2);
689 return ret == 0 ? +1 : ret;
690 }
691}
692
693int wxString::compare(const wxString& str) const
694{
695 return ::wxDoCmp(m_impl.data(), m_impl.length(),
696 str.m_impl.data(), str.m_impl.length());
697}
698
699int wxString::compare(size_t nStart, size_t nLen,
700 const wxString& str) const
701{
702 wxASSERT(nStart <= length());
703 size_type strLen = length() - nStart;
704 nLen = strLen < nLen ? strLen : nLen;
705
706 size_t pos, len;
707 PosLenToImpl(nStart, nLen, &pos, &len);
708
709 return ::wxDoCmp(m_impl.data() + pos, len,
710 str.m_impl.data(), str.m_impl.length());
711}
712
713int wxString::compare(size_t nStart, size_t nLen,
714 const wxString& str,
715 size_t nStart2, size_t nLen2) const
716{
717 wxASSERT(nStart <= length());
718 wxASSERT(nStart2 <= str.length());
719 size_type strLen = length() - nStart,
720 strLen2 = str.length() - nStart2;
721 nLen = strLen < nLen ? strLen : nLen;
722 nLen2 = strLen2 < nLen2 ? strLen2 : nLen2;
723
724 size_t pos, len;
725 PosLenToImpl(nStart, nLen, &pos, &len);
726 size_t pos2, len2;
727 str.PosLenToImpl(nStart2, nLen2, &pos2, &len2);
728
729 return ::wxDoCmp(m_impl.data() + pos, len,
730 str.m_impl.data() + pos2, len2);
731}
732
733int wxString::compare(const char* sz) const
734{
735 SubstrBufFromMB str(ImplStr(sz, npos));
736 if ( str.len == npos )
737 str.len = wxStringStrlen(str.data);
738 return ::wxDoCmp(m_impl.data(), m_impl.length(), str.data, str.len);
739}
740
741int wxString::compare(const wchar_t* sz) const
742{
743 SubstrBufFromWC str(ImplStr(sz, npos));
744 if ( str.len == npos )
745 str.len = wxStringStrlen(str.data);
746 return ::wxDoCmp(m_impl.data(), m_impl.length(), str.data, str.len);
747}
748
749int wxString::compare(size_t nStart, size_t nLen,
750 const char* sz, size_t nCount) const
751{
752 wxASSERT(nStart <= length());
753 size_type strLen = length() - nStart;
754 nLen = strLen < nLen ? strLen : nLen;
097c080b 755
a7ea63e2
VS
756 size_t pos, len;
757 PosLenToImpl(nStart, nLen, &pos, &len);
3168a13f 758
a7ea63e2
VS
759 SubstrBufFromMB str(ImplStr(sz, nCount));
760 if ( str.len == npos )
761 str.len = wxStringStrlen(str.data);
762
763 return ::wxDoCmp(m_impl.data() + pos, len, str.data, str.len);
c801d85f
KB
764}
765
a7ea63e2
VS
766int wxString::compare(size_t nStart, size_t nLen,
767 const wchar_t* sz, size_t nCount) const
8f93a29f 768{
a7ea63e2
VS
769 wxASSERT(nStart <= length());
770 size_type strLen = length() - nStart;
771 nLen = strLen < nLen ? strLen : nLen;
8f93a29f 772
a7ea63e2
VS
773 size_t pos, len;
774 PosLenToImpl(nStart, nLen, &pos, &len);
8f93a29f 775
a7ea63e2
VS
776 SubstrBufFromWC str(ImplStr(sz, nCount));
777 if ( str.len == npos )
778 str.len = wxStringStrlen(str.data);
779
780 return ::wxDoCmp(m_impl.data() + pos, len, str.data, str.len);
8f93a29f
VS
781}
782
a7ea63e2
VS
783#endif // HAVE_STD_STRING_COMPARE/!HAVE_STD_STRING_COMPARE
784
785
8f93a29f
VS
786// ---------------------------------------------------------------------------
787// find_{first,last}_[not]_of functions
788// ---------------------------------------------------------------------------
789
790#if !wxUSE_STL_BASED_WXSTRING || wxUSE_UNICODE_UTF8
c801d85f 791
8f93a29f
VS
792// NB: All these functions are implemented with the argument being wxChar*,
793// i.e. widechar string in any Unicode build, even though native string
794// representation is char* in the UTF-8 build. This is because we couldn't
795// use memchr() to determine if a character is in a set encoded as UTF-8.
796
797size_t wxString::find_first_of(const wxChar* sz, size_t nStart) const
dcb68102 798{
8f93a29f 799 return find_first_of(sz, nStart, wxStrlen(sz));
dcb68102
RN
800}
801
8f93a29f 802size_t wxString::find_first_not_of(const wxChar* sz, size_t nStart) const
dcb68102 803{
8f93a29f 804 return find_first_not_of(sz, nStart, wxStrlen(sz));
dcb68102
RN
805}
806
8f93a29f 807size_t wxString::find_first_of(const wxChar* sz, size_t nStart, size_t n) const
dcb68102 808{
8f93a29f 809 wxASSERT_MSG( nStart <= length(), _T("invalid index") );
dcb68102 810
8f93a29f
VS
811 size_t idx = nStart;
812 for ( const_iterator i = begin() + nStart; i != end(); ++idx, ++i )
dcb68102 813 {
8f93a29f
VS
814 if ( wxTmemchr(sz, *i, n) )
815 return idx;
dcb68102 816 }
8f93a29f
VS
817
818 return npos;
819}
820
821size_t wxString::find_first_not_of(const wxChar* sz, size_t nStart, size_t n) const
822{
823 wxASSERT_MSG( nStart <= length(), _T("invalid index") );
824
825 size_t idx = nStart;
826 for ( const_iterator i = begin() + nStart; i != end(); ++idx, ++i )
dcb68102 827 {
8f93a29f
VS
828 if ( !wxTmemchr(sz, *i, n) )
829 return idx;
830 }
831
832 return npos;
833}
834
835
836size_t wxString::find_last_of(const wxChar* sz, size_t nStart) const
837{
838 return find_last_of(sz, nStart, wxStrlen(sz));
839}
840
841size_t wxString::find_last_not_of(const wxChar* sz, size_t nStart) const
842{
843 return find_last_not_of(sz, nStart, wxStrlen(sz));
844}
845
846size_t wxString::find_last_of(const wxChar* sz, size_t nStart, size_t n) const
847{
848 size_t len = length();
849
850 if ( nStart == npos )
851 {
852 nStart = len - 1;
dcb68102 853 }
2c09fb3b 854 else
dcb68102 855 {
8f93a29f 856 wxASSERT_MSG( nStart <= len, _T("invalid index") );
dcb68102 857 }
8f93a29f
VS
858
859 size_t idx = nStart;
860 for ( const_reverse_iterator i = rbegin() + (len - nStart - 1);
861 i != rend(); --idx, ++i )
862 {
863 if ( wxTmemchr(sz, *i, n) )
864 return idx;
865 }
866
867 return npos;
dcb68102
RN
868}
869
8f93a29f 870size_t wxString::find_last_not_of(const wxChar* sz, size_t nStart, size_t n) const
dcb68102 871{
8f93a29f
VS
872 size_t len = length();
873
874 if ( nStart == npos )
875 {
876 nStart = len - 1;
877 }
878 else
879 {
880 wxASSERT_MSG( nStart <= len, _T("invalid index") );
881 }
882
883 size_t idx = nStart;
884 for ( const_reverse_iterator i = rbegin() + (len - nStart - 1);
885 i != rend(); --idx, ++i )
886 {
887 if ( !wxTmemchr(sz, *i, n) )
888 return idx;
889 }
890
891 return npos;
dcb68102
RN
892}
893
8f93a29f 894size_t wxString::find_first_not_of(wxUniChar ch, size_t nStart) const
dcb68102 895{
8f93a29f
VS
896 wxASSERT_MSG( nStart <= length(), _T("invalid index") );
897
898 size_t idx = nStart;
899 for ( const_iterator i = begin() + nStart; i != end(); ++idx, ++i )
900 {
901 if ( *i != ch )
902 return idx;
903 }
904
905 return npos;
906}
907
908size_t wxString::find_last_not_of(wxUniChar ch, size_t nStart) const
909{
910 size_t len = length();
911
912 if ( nStart == npos )
913 {
914 nStart = len - 1;
915 }
916 else
917 {
918 wxASSERT_MSG( nStart <= len, _T("invalid index") );
919 }
920
921 size_t idx = nStart;
922 for ( const_reverse_iterator i = rbegin() + (len - nStart - 1);
923 i != rend(); --idx, ++i )
924 {
925 if ( *i != ch )
926 return idx;
927 }
928
929 return npos;
930}
931
932// the functions above were implemented for wchar_t* arguments in Unicode
933// build and char* in ANSI build; below are implementations for the other
934// version:
935#if wxUSE_UNICODE
936 #define wxOtherCharType char
937 #define STRCONV (const wxChar*)wxConvLibc.cMB2WC
938#else
939 #define wxOtherCharType wchar_t
940 #define STRCONV (const wxChar*)wxConvLibc.cWC2MB
941#endif
942
943size_t wxString::find_first_of(const wxOtherCharType* sz, size_t nStart) const
944 { return find_first_of(STRCONV(sz), nStart); }
945
946size_t wxString::find_first_of(const wxOtherCharType* sz, size_t nStart,
947 size_t n) const
948 { return find_first_of(STRCONV(sz, n, NULL), nStart, n); }
949size_t wxString::find_last_of(const wxOtherCharType* sz, size_t nStart) const
950 { return find_last_of(STRCONV(sz), nStart); }
951size_t wxString::find_last_of(const wxOtherCharType* sz, size_t nStart,
952 size_t n) const
953 { return find_last_of(STRCONV(sz, n, NULL), nStart, n); }
954size_t wxString::find_first_not_of(const wxOtherCharType* sz, size_t nStart) const
955 { return find_first_not_of(STRCONV(sz), nStart); }
956size_t wxString::find_first_not_of(const wxOtherCharType* sz, size_t nStart,
957 size_t n) const
958 { return find_first_not_of(STRCONV(sz, n, NULL), nStart, n); }
959size_t wxString::find_last_not_of(const wxOtherCharType* sz, size_t nStart) const
960 { return find_last_not_of(STRCONV(sz), nStart); }
961size_t wxString::find_last_not_of(const wxOtherCharType* sz, size_t nStart,
962 size_t n) const
963 { return find_last_not_of(STRCONV(sz, n, NULL), nStart, n); }
964
965#undef wxOtherCharType
966#undef STRCONV
967
968#endif // !wxUSE_STL_BASED_WXSTRING || wxUSE_UNICODE_UTF8
969
970// ===========================================================================
971// other common string functions
972// ===========================================================================
973
974int wxString::CmpNoCase(const wxString& s) const
975{
976 // FIXME-UTF8: use wxUniChar::ToLower/ToUpper once added
977
8f93a29f
VS
978 const_iterator i1 = begin();
979 const_iterator end1 = end();
980 const_iterator i2 = s.begin();
981 const_iterator end2 = s.end();
982
0d8b0f94 983 for ( ; i1 != end1 && i2 != end2; ++i1, ++i2 )
8f93a29f
VS
984 {
985 wxUniChar lower1 = (wxChar)wxTolower(*i1);
986 wxUniChar lower2 = (wxChar)wxTolower(*i2);
987 if ( lower1 != lower2 )
988 return lower1 < lower2 ? -1 : 1;
989 }
990
991 size_t len1 = length();
992 size_t len2 = s.length();
dcb68102 993
8f93a29f
VS
994 if ( len1 < len2 )
995 return -1;
996 else if ( len1 > len2 )
997 return 1;
998 return 0;
dcb68102
RN
999}
1000
1001
b1ac3b56 1002#if wxUSE_UNICODE
e015c2a3 1003
cf6bedce
SC
1004#ifdef __MWERKS__
1005#ifndef __SCHAR_MAX__
1006#define __SCHAR_MAX__ 127
1007#endif
1008#endif
1009
e6310bbc 1010wxString wxString::FromAscii(const char *ascii, size_t len)
b1ac3b56 1011{
e6310bbc 1012 if (!ascii || len == 0)
b1ac3b56 1013 return wxEmptyString;
e015c2a3 1014
b1ac3b56 1015 wxString res;
e015c2a3 1016
e6310bbc 1017 {
6798451b 1018 wxStringInternalBuffer buf(res, len);
602a857b 1019 wxStringCharType *dest = buf;
c1eada83 1020
602a857b
VS
1021 for ( ; len > 0; --len )
1022 {
1023 unsigned char c = (unsigned char)*ascii++;
1024 wxASSERT_MSG( c < 0x80,
1025 _T("Non-ASCII value passed to FromAscii().") );
c1eada83 1026
602a857b
VS
1027 *dest++ = (wchar_t)c;
1028 }
e015c2a3
VZ
1029 }
1030
b1ac3b56
RR
1031 return res;
1032}
1033
e6310bbc
VS
1034wxString wxString::FromAscii(const char *ascii)
1035{
0081dd72 1036 return FromAscii(ascii, wxStrlen(ascii));
e6310bbc
VS
1037}
1038
c5288c5c 1039wxString wxString::FromAscii(char ascii)
2b5f62a0
VZ
1040{
1041 // What do we do with '\0' ?
1042
c1eada83 1043 unsigned char c = (unsigned char)ascii;
8760bc65 1044
c1eada83
VS
1045 wxASSERT_MSG( c < 0x80, _T("Non-ASCII value passed to FromAscii().") );
1046
1047 // NB: the cast to wchar_t causes interpretation of 'ascii' as Latin1 value
1048 return wxString(wxUniChar((wchar_t)c));
2b5f62a0
VZ
1049}
1050
b1ac3b56
RR
1051const wxCharBuffer wxString::ToAscii() const
1052{
e015c2a3
VZ
1053 // this will allocate enough space for the terminating NUL too
1054 wxCharBuffer buffer(length());
6e394fc6 1055 char *dest = buffer.data();
e015c2a3 1056
c1eada83 1057 for ( const_iterator i = begin(); i != end(); ++i )
b1ac3b56 1058 {
c1eada83
VS
1059 wxUniChar c(*i);
1060 // FIXME-UTF8: unify substituted char ('_') with wxUniChar ('?')
1061 *dest++ = c.IsAscii() ? (char)c : '_';
e015c2a3
VZ
1062
1063 // the output string can't have embedded NULs anyhow, so we can safely
1064 // stop at first of them even if we do have any
c1eada83 1065 if ( !c )
e015c2a3 1066 break;
b1ac3b56 1067 }
e015c2a3 1068
b1ac3b56
RR
1069 return buffer;
1070}
e015c2a3 1071
c1eada83 1072#endif // wxUSE_UNICODE
b1ac3b56 1073
c801d85f 1074// extract string of length nCount starting at nFirst
c801d85f
KB
1075wxString wxString::Mid(size_t nFirst, size_t nCount) const
1076{
73f507f5 1077 size_t nLen = length();
30d9011f 1078
73f507f5
WS
1079 // default value of nCount is npos and means "till the end"
1080 if ( nCount == npos )
1081 {
1082 nCount = nLen - nFirst;
1083 }
30d9011f 1084
73f507f5
WS
1085 // out-of-bounds requests return sensible things
1086 if ( nFirst + nCount > nLen )
1087 {
1088 nCount = nLen - nFirst;
1089 }
c801d85f 1090
73f507f5
WS
1091 if ( nFirst > nLen )
1092 {
1093 // AllocCopy() will return empty string
1094 return wxEmptyString;
1095 }
c801d85f 1096
73f507f5
WS
1097 wxString dest(*this, nFirst, nCount);
1098 if ( dest.length() != nCount )
1099 {
1100 wxFAIL_MSG( _T("out of memory in wxString::Mid") );
1101 }
30d9011f 1102
73f507f5 1103 return dest;
c801d85f
KB
1104}
1105
e87b7833 1106// check that the string starts with prefix and return the rest of the string
d775fa82 1107// in the provided pointer if it is not NULL, otherwise return false
c5e7a7d7 1108bool wxString::StartsWith(const wxString& prefix, wxString *rest) const
f6bcfd97 1109{
c5e7a7d7
VS
1110 if ( compare(0, prefix.length(), prefix) != 0 )
1111 return false;
f6bcfd97
BP
1112
1113 if ( rest )
1114 {
1115 // put the rest of the string into provided pointer
c5e7a7d7 1116 rest->assign(*this, prefix.length(), npos);
f6bcfd97
BP
1117 }
1118
d775fa82 1119 return true;
f6bcfd97
BP
1120}
1121
3affcd07
VZ
1122
1123// check that the string ends with suffix and return the rest of it in the
1124// provided pointer if it is not NULL, otherwise return false
c5e7a7d7 1125bool wxString::EndsWith(const wxString& suffix, wxString *rest) const
3affcd07 1126{
c5e7a7d7 1127 int start = length() - suffix.length();
81727065
VS
1128
1129 if ( start < 0 || compare(start, npos, suffix) != 0 )
3affcd07
VZ
1130 return false;
1131
1132 if ( rest )
1133 {
1134 // put the rest of the string into provided pointer
1135 rest->assign(*this, 0, start);
1136 }
1137
1138 return true;
1139}
1140
1141
c801d85f
KB
1142// extract nCount last (rightmost) characters
1143wxString wxString::Right(size_t nCount) const
1144{
e87b7833
MB
1145 if ( nCount > length() )
1146 nCount = length();
c801d85f 1147
e87b7833
MB
1148 wxString dest(*this, length() - nCount, nCount);
1149 if ( dest.length() != nCount ) {
b1801e0e
GD
1150 wxFAIL_MSG( _T("out of memory in wxString::Right") );
1151 }
c801d85f
KB
1152 return dest;
1153}
1154
1155// get all characters after the last occurence of ch
1156// (returns the whole string if ch not found)
c9f78968 1157wxString wxString::AfterLast(wxUniChar ch) const
c801d85f
KB
1158{
1159 wxString str;
d775fa82 1160 int iPos = Find(ch, true);
3c67202d 1161 if ( iPos == wxNOT_FOUND )
c801d85f
KB
1162 str = *this;
1163 else
c9f78968 1164 str = wx_str() + iPos + 1;
c801d85f
KB
1165
1166 return str;
1167}
1168
1169// extract nCount first (leftmost) characters
1170wxString wxString::Left(size_t nCount) const
1171{
e87b7833
MB
1172 if ( nCount > length() )
1173 nCount = length();
c801d85f 1174
e87b7833
MB
1175 wxString dest(*this, 0, nCount);
1176 if ( dest.length() != nCount ) {
b1801e0e
GD
1177 wxFAIL_MSG( _T("out of memory in wxString::Left") );
1178 }
c801d85f
KB
1179 return dest;
1180}
1181
1182// get all characters before the first occurence of ch
1183// (returns the whole string if ch not found)
c9f78968 1184wxString wxString::BeforeFirst(wxUniChar ch) const
c801d85f 1185{
e87b7833
MB
1186 int iPos = Find(ch);
1187 if ( iPos == wxNOT_FOUND ) iPos = length();
1188 return wxString(*this, 0, iPos);
c801d85f
KB
1189}
1190
1191/// get all characters before the last occurence of ch
1192/// (returns empty string if ch not found)
c9f78968 1193wxString wxString::BeforeLast(wxUniChar ch) const
c801d85f
KB
1194{
1195 wxString str;
d775fa82 1196 int iPos = Find(ch, true);
3c67202d 1197 if ( iPos != wxNOT_FOUND && iPos != 0 )
d1c9bbf6 1198 str = wxString(c_str(), iPos);
c801d85f
KB
1199
1200 return str;
1201}
1202
1203/// get all characters after the first occurence of ch
1204/// (returns empty string if ch not found)
c9f78968 1205wxString wxString::AfterFirst(wxUniChar ch) const
c801d85f
KB
1206{
1207 wxString str;
1208 int iPos = Find(ch);
3c67202d 1209 if ( iPos != wxNOT_FOUND )
c9f78968 1210 str = wx_str() + iPos + 1;
c801d85f
KB
1211
1212 return str;
1213}
1214
1215// replace first (or all) occurences of some substring with another one
8a540c88
VS
1216size_t wxString::Replace(const wxString& strOld,
1217 const wxString& strNew, bool bReplaceAll)
c801d85f 1218{
a8f1f1b2 1219 // if we tried to replace an empty string we'd enter an infinite loop below
8a540c88 1220 wxCHECK_MSG( !strOld.empty(), 0,
a8f1f1b2
VZ
1221 _T("wxString::Replace(): invalid parameter") );
1222
510bb748 1223 size_t uiCount = 0; // count of replacements made
c801d85f 1224
8a540c88
VS
1225 size_t uiOldLen = strOld.length();
1226 size_t uiNewLen = strNew.length();
c801d85f 1227
510bb748 1228 size_t dwPos = 0;
c801d85f 1229
8a540c88 1230 while ( (*this)[dwPos] != wxT('\0') )
510bb748
RN
1231 {
1232 //DO NOT USE STRSTR HERE
1233 //this string can contain embedded null characters,
1234 //so strstr will function incorrectly
8a540c88 1235 dwPos = find(strOld, dwPos);
ad5bb7d6 1236 if ( dwPos == npos )
510bb748 1237 break; // exit the loop
ad5bb7d6 1238 else
510bb748
RN
1239 {
1240 //replace this occurance of the old string with the new one
8a540c88 1241 replace(dwPos, uiOldLen, strNew, uiNewLen);
510bb748 1242
2df0258e
RN
1243 //move up pos past the string that was replaced
1244 dwPos += uiNewLen;
510bb748
RN
1245
1246 //increase replace count
1247 ++uiCount;
ad5bb7d6 1248
510bb748 1249 // stop now?
ad5bb7d6 1250 if ( !bReplaceAll )
510bb748
RN
1251 break; // exit the loop
1252 }
c801d85f 1253 }
c801d85f 1254
510bb748 1255 return uiCount;
c801d85f
KB
1256}
1257
1258bool wxString::IsAscii() const
1259{
a4a44612
VS
1260 for ( const_iterator i = begin(); i != end(); ++i )
1261 {
1262 if ( !(*i).IsAscii() )
1263 return false;
1264 }
1265
1266 return true;
c801d85f 1267}
dd1eaa89 1268
c801d85f
KB
1269bool wxString::IsWord() const
1270{
a4a44612
VS
1271 for ( const_iterator i = begin(); i != end(); ++i )
1272 {
1273 if ( !wxIsalpha(*i) )
1274 return false;
1275 }
1276
1277 return true;
c801d85f 1278}
dd1eaa89 1279
c801d85f
KB
1280bool wxString::IsNumber() const
1281{
a4a44612
VS
1282 if ( empty() )
1283 return true;
1284
1285 const_iterator i = begin();
1286
1287 if ( *i == _T('-') || *i == _T('+') )
1288 ++i;
1289
1290 for ( ; i != end(); ++i )
1291 {
1292 if ( !wxIsdigit(*i) )
1293 return false;
1294 }
1295
1296 return true;
c801d85f
KB
1297}
1298
c801d85f
KB
1299wxString wxString::Strip(stripType w) const
1300{
1301 wxString s = *this;
d775fa82
WS
1302 if ( w & leading ) s.Trim(false);
1303 if ( w & trailing ) s.Trim(true);
c801d85f
KB
1304 return s;
1305}
1306
c801d85f
KB
1307// ---------------------------------------------------------------------------
1308// case conversion
1309// ---------------------------------------------------------------------------
1310
1311wxString& wxString::MakeUpper()
1312{
e87b7833
MB
1313 for ( iterator it = begin(), en = end(); it != en; ++it )
1314 *it = (wxChar)wxToupper(*it);
c801d85f
KB
1315
1316 return *this;
1317}
1318
1319wxString& wxString::MakeLower()
1320{
e87b7833
MB
1321 for ( iterator it = begin(), en = end(); it != en; ++it )
1322 *it = (wxChar)wxTolower(*it);
c801d85f
KB
1323
1324 return *this;
1325}
1326
1327// ---------------------------------------------------------------------------
1328// trimming and padding
1329// ---------------------------------------------------------------------------
1330
d775fa82 1331// some compilers (VC++ 6.0 not to name them) return true for a call to
576c608d
VZ
1332