]> git.saurik.com Git - wxWidgets.git/blame - interface/wx/string.h
reworked font handling for osx
[wxWidgets.git] / interface / wx / string.h
CommitLineData
23324ae1
FM
1/////////////////////////////////////////////////////////////////////////////
2// Name: string.h
4701dc09 3// Purpose: interface of wxStringBuffer, wxString
23324ae1
FM
4// Author: wxWidgets team
5// RCS-ID: $Id$
6// Licence: wxWindows license
7/////////////////////////////////////////////////////////////////////////////
8
e54c96f1 9
23324ae1
FM
10/**
11 @class wxString
7c913512 12
a6919a6a
RR
13 The wxString class has been completely rewritten for wxWidgets 3.0
14 and this change was actually the main reason for the calling that
15 version wxWidgets 3.0.
16
062dc5fc 17 wxString is a class representing a Unicode character string.
727aa906
FM
18 wxString uses @c std::basic_string internally (even if @c wxUSE_STL is not defined)
19 to store its content (unless this is not supported by the compiler or disabled
20 specifically when building wxWidgets) and it therefore inherits
21 many features from @c std::basic_string. (Note that most implementations of
22 @c std::basic_string are thread-safe and don't use reference counting.)
23
24 These @c std::basic_string standard functions are only listed here, but
25 they are not fully documented in this manual; see the STL documentation
26 (http://www.cppreference.com/wiki/string/start) for more info.
a7d23734
RR
27 The behaviour of all these functions is identical to the behaviour
28 described there.
96c99165 29
8c1cd030 30 You may notice that wxString sometimes has several functions which do
727aa906
FM
31 the same thing like Length(), Len() and length() which all return the
32 string length. In all cases of such duplication the @c std::string
33 compatible methods should be used.
34
35 For informations about the internal encoding used by wxString and
36 for important warnings and advices for using it, please read
37 the @ref overview_string.
38
ca164e23 39 Since wxWidgets 3.0 wxString always stores Unicode strings, so you should
727aa906 40 be sure to read also @ref overview_unicode.
7c913512 41
4701dc09 42
ee49f540
FM
43 @section string_index Index of the member groups
44
45 Links for quick access to the various categories of wxString functions:
46 - @ref_member_group{ctor, Constructors and assignment operators}
47 - @ref_member_group{length, Length functions}
48 - @ref_member_group{ch_access, Character access functions}
49 - @ref_member_group{conv, Conversions functions}
50 - @ref_member_group{concat, Concatenation functions}
51 - @ref_member_group{cmp, Comparison functions}
52 - @ref_member_group{substring, Substring extraction functions}
53 - @ref_member_group{caseconv, Case conversion functions}
54 - @ref_member_group{search, Searching and replacing functions}
55 - @ref_member_group{numconv, Conversion to numbers functions}
56 - @ref_member_group{fmt, Formatting and printing functions}
57 - @ref_member_group{mem, Memory management functions}
58 - @ref_member_group{misc, Miscellaneous functions}
59 - @ref_member_group{iter, Iterator interface functions}
60 - @ref_member_group{stl, STL interface functions}
4701dc09 61
c3c772fa 62
23324ae1
FM
63 @library{wxbase}
64 @category{data}
7c913512 65
23324ae1 66 @stdobjects
4701dc09 67 ::wxEmptyString
7c913512 68
ee49f540
FM
69 @see @ref overview_string, @ref overview_unicode,
70 @ref group_funcmacro_string "String-related functions", wxUString,
71 wxCharBuffer, wxUniChar, wxStringTokenizer, wxStringBuffer, wxStringBufferLength
23324ae1 72*/
7c913512 73class wxString
23324ae1
FM
74{
75public:
062dc5fc 76 /**
f08b2466 77 @name Standard types
ee49f540
FM
78
79 Types used with wxString.
b33e2f63 80 */
f08b2466 81 //@{
b33e2f63
RR
82 typedef wxUniChar value_type;
83 typedef wxUniChar char_type;
84 typedef wxUniCharRef reference;
85 typedef wxChar* pointer;
86 typedef const wxChar* const_pointer;
87 typedef size_t size_type;
88 typedef wxUniChar const_reference;
89 //@}
90
ee49f540
FM
91
92 /**
93 @member_group_name{ctor, Constructors and assignment operators}
94
95 A string may be constructed either from a C string, (some number of copies of)
96 a single character or a wide (Unicode) string. For all constructors (except the
97 default which creates an empty string) there is also a corresponding assignment
98 operator.
99
100 See also the assign() STL-like function.
101 */
102 //@{
103
23324ae1 104 /**
96c99165 105 Default constructor
23324ae1
FM
106 */
107 wxString();
062dc5fc 108
96c99165 109 /**
4701dc09 110 Creates a string from another string.
ee49f540 111 Just increases the ref count by 1.
96c99165
RR
112 */
113 wxString(const wxString& stringSrc);
062dc5fc 114
96c99165
RR
115
116 /**
ee49f540 117 Constructs a string from the string literal @a psz using
8c1cd030 118 the current locale encoding to convert it to Unicode (wxConvLibc).
96c99165
RR
119 */
120 wxString(const char *psz);
121
122 /**
ee49f540
FM
123 Constructs a string from the string literal @a psz using
124 @a conv to convert it Unicode.
96c99165
RR
125 */
126 wxString(const char *psz, const wxMBConv& conv);
127
128 /**
ee49f540 129 Constructs a string from the first @a nLength character of the string literal @a psz using
8c1cd030 130 the current locale encoding to convert it to Unicode (wxConvLibc).
96c99165
RR
131 */
132 wxString(const char *psz, size_t nLength);
133
134 /**
ee49f540
FM
135 Constructs a string from the first @a nLength character of the string literal @a psz using
136 @a conv to convert it Unicode.
96c99165
RR
137 */
138 wxString(const char *psz, const wxMBConv& conv, size_t nLength);
139
140 /**
ee49f540 141 Constructs a string from the string literal @a pwz.
96c99165
RR
142 */
143 wxString(const wchar_t *pwz);
144
145 /**
ee49f540 146 Constructs a string from the first @a nLength characters of the string literal @a pwz.
96c99165
RR
147 */
148 wxString(const wchar_t *pwz, size_t nLength);
149
150 /**
ee49f540 151 Constructs a string from @a buf using the using the current locale
4701dc09 152 encoding to convert it to Unicode.
96c99165
RR
153 */
154 wxString(const wxCharBuffer& buf);
062dc5fc 155
96c99165 156 /**
ee49f540 157 Constructs a string from @a buf.
96c99165
RR
158 */
159 wxString(const wxWCharBuffer& buf);
160
161 /**
ee49f540 162 Constructs a string from @a str using the using the current locale encoding
8c1cd030 163 to convert it to Unicode (wxConvLibc).
96c99165
RR
164 */
165 wxString(const std::string& str);
062dc5fc 166
96c99165 167 /**
ee49f540 168 Constructs a string from @a str.
96c99165
RR
169 */
170 wxString(const std::wstring& str);
ee49f540 171
23324ae1 172 /**
4701dc09
FM
173 String destructor.
174
175 Note that this is not virtual, so wxString must not be inherited from.
23324ae1
FM
176 */
177 ~wxString();
178
179 /**
ee49f540 180 Assignment: see the relative wxString constructor.
23324ae1 181 */
ee49f540 182 wxString operator =(const wxString& str);
23324ae1
FM
183
184 /**
ee49f540 185 Assignment: see the relative wxString constructor.
23324ae1 186 */
ee49f540 187 wxString operator =(wxUniChar c);
0367b928 188
ee49f540
FM
189 //@}
190
0367b928 191
23324ae1 192
23324ae1 193 /**
ee49f540 194 @member_group_name{length, String length}
77da37be 195
ee49f540
FM
196 These functions return the string length and/or check whether the string
197 is empty.
198
199 See also the length(), size() or empty() STL-like functions.
77da37be 200 */
ee49f540
FM
201 //@{
202
77da37be
RR
203
204 /**
ee49f540 205 Returns the length of the string.
23324ae1 206 */
ee49f540 207 size_t Len() const;
77da37be
RR
208
209 /**
ee49f540
FM
210 Returns the length of the string (same as Len).
211 This is a wxWidgets 1.xx compatibility function; you should not use it in new
212 code.
77da37be 213 */
ee49f540 214 size_t Length() const;
77da37be
RR
215
216 /**
ee49f540 217 Returns @true if the string is empty.
77da37be 218 */
ee49f540 219 bool IsEmpty() const;
77da37be
RR
220
221 /**
ee49f540
FM
222 Returns @true if the string is empty (same as wxString::IsEmpty).
223 This is a wxWidgets 1.xx compatibility function; you should not use it in new
224 code.
77da37be 225 */
ee49f540 226 bool IsNull() const;
23324ae1
FM
227
228 /**
ee49f540
FM
229 Empty string is @false, so !string will only return @true if the
230 string is empty.
23324ae1 231
ee49f540 232 @see IsEmpty().
23324ae1 233 */
ee49f540 234 bool operator!() const;
23324ae1 235
ee49f540 236 //@}
0c7db140 237
0c7db140 238
0c7db140 239
23324ae1 240 /**
ee49f540
FM
241 @member_group_name{ch_access, Character access}
242
243 Many functions below take a character index in the string.
244 As with C strings and arrays, the indices start from 0, so the first character
245 of a string is string[0]. An attempt to access a character beyond the end of the
246 string (which may even be 0 if the string is empty) will provoke an assert
247 failure in @ref overview_debugging "debug builds", but no checks are
248 done in release builds.
23324ae1 249 */
ee49f540 250 //@{
23324ae1 251
06e9cf13 252 /**
ee49f540
FM
253 Returns the character at position @a n (read-only).
254 */
255 wxUniChar GetChar(size_t n) const;
06e9cf13 256
23324ae1 257 /**
ee49f540 258 wxWidgets compatibility conversion. Same as c_str().
23324ae1 259 */
ee49f540 260 const wxCStrData GetData() const;
23324ae1 261
23324ae1 262 /**
ee49f540 263 Returns a reference to the character at position @a n.
23324ae1 264 */
ee49f540 265 wxUniCharRef GetWritableChar(size_t n);
23324ae1 266
23324ae1 267 /**
ee49f540
FM
268 Returns a writable buffer of at least @a len bytes.
269
270 It returns a pointer to a new memory block, and the existing data will not be copied.
271 Call UngetWriteBuf() as soon as possible to put the string back into a reasonable state.
272
273 This method is deprecated, please use wxStringBuffer or wxStringBufferLength instead.
23324ae1 274 */
ee49f540 275 wxStringCharType* GetWriteBuf(size_t len);
23324ae1
FM
276
277 /**
ee49f540
FM
278 Puts the string back into a reasonable state (in which it can be used
279 normally), after GetWriteBuf() was called.
280
281 The version of the function without the @a len parameter will calculate the
282 new string length itself assuming that the string is terminated by the first
283 @c NUL character in it while the second one will use the specified length
284 and thus is the only version which should be used with the strings with
285 embedded @c NULs (it is also slightly more efficient as @c strlen()
286 doesn't have to be called).
23324ae1 287
ee49f540
FM
288 This method is deprecated, please use wxStringBuffer or wxStringBufferLength instead.
289 */
290 void UngetWriteBuf();
291
23324ae1 292 /**
ee49f540 293 @overload
23324ae1 294 */
ee49f540
FM
295 void UngetWriteBuf(size_t len);
296
23324ae1 297 /**
ee49f540 298 Sets the character at position @e n.
23324ae1 299 */
ee49f540 300 void SetChar(size_t n, wxUniChar ch);
062dc5fc 301
77da37be 302 /**
ee49f540
FM
303 Returns a the last character.
304
305 This is a wxWidgets 1.xx compatibility function;
306 you should not use it in new code.
77da37be 307 */
ee49f540
FM
308 wxUniChar Last() const;
309
23324ae1 310 /**
ee49f540
FM
311 Returns a reference to the last character (writable).
312
062dc5fc 313 This is a wxWidgets 1.xx compatibility function;
b33e2f63 314 you should not use it in new code.
23324ae1 315 */
ee49f540 316 wxUniCharRef Last();
23324ae1
FM
317
318 /**
ee49f540 319 Returns the @a i-th character of the string.
23324ae1 320 */
ee49f540 321 wxUniChar operator [](size_t i) const;
23324ae1
FM
322
323 /**
ee49f540 324 Returns a writable reference to the @a i-th character of the string.
23324ae1 325 */
ee49f540
FM
326 wxUniCharRef operator [](size_t i);
327
328 //@}
329
23324ae1
FM
330
331 /**
ee49f540
FM
332 @member_group_name{conv, Conversions}
333
334 This section contains both implicit and explicit conversions to C style
335 strings. Although implicit conversion is quite convenient, you are advised
336 to use wc_str() for the sake of clarity.
23324ae1 337 */
23324ae1 338 //@{
ee49f540 339
23324ae1 340 /**
ee49f540
FM
341 Returns a lightweight intermediate class which is in turn implicitly
342 convertible to both @c const @c char* and to @c const @c wchar_t*.
343 Given this ambiguity it is mostly better to use wc_str(), mb_str() or
344 utf8_str() instead.
70897a70 345
ee49f540 346 Please see the @ref overview_unicode for more information about it.
3c4f71cc 347
ee49f540
FM
348 Note that the returned value is not convertible to @c char* or
349 @c wchar_t*, use char_str() or wchar_str() if you need to pass
350 string value to a function expecting non-const pointer.
3c4f71cc 351
ee49f540 352 @see wc_str(), utf8_str(), c_str(), mb_str(), fn_str()
23324ae1 353 */
ee49f540 354 wxCStrData c_str() const;
23324ae1 355
23324ae1 356 /**
ee49f540
FM
357 Returns an object with string data that is implicitly convertible to
358 @c char* pointer. Note that any change to the returned buffer is lost and so
359 this function is only usable for passing strings to legacy libraries that
360 don't have const-correct API. Use wxStringBuffer if you want to modify
361 the string.
362
363 @see c_str()
23324ae1 364 */
ee49f540 365 wxWritableCharBuffer char_str(const wxMBConv& conv = wxConvLibc) const;
23324ae1 366
23324ae1 367 /**
ee49f540 368 Returns buffer of the specified type containing the string data.
cc209a51 369
ee49f540
FM
370 This method is only useful in template code, otherwise you should
371 directly call mb_str() or wc_str() if you need to retrieve a narrow or
372 wide string from this wxString. The template parameter @a t should be
373 either @c char or @c wchar_t.
23324ae1 374
ee49f540
FM
375 Notice that retrieving a char buffer in UTF-8 build will return the
376 internal string representation in UTF-8 while in wchar_t build the char
377 buffer will contain the conversion of the string to the encoding of the
378 current locale (and so can fail).
cc209a51 379
ee49f540
FM
380 @param len
381 If non-@NULL, filled with the length of the returned buffer.
cc209a51 382
ee49f540
FM
383 @return
384 buffer containing the string contents in the specified type,
385 notice that it may be @NULL if the conversion failed (e.g. Unicode
386 string couldn't be converted to the current encoding when @a T is
387 @c char).
388 */
389 template <typename T>
390 wxCharTypeBuffer<T> tchar_str(size_t *len = NULL) const;
cc209a51 391
23324ae1 392 /**
ee49f540
FM
393 Returns a string representation suitable for passing to OS' functions
394 for file handling.
23324ae1 395 */
ee49f540
FM
396 const wchar_t* fn_str() const;
397
23324ae1 398 /**
ee49f540 399 @overload
23324ae1 400 */
ee49f540 401 const char* fn_str() const;
23324ae1
FM
402
403 /**
ee49f540 404 @overload
23324ae1 405 */
ee49f540 406 const wxCharBuffer fn_str() const;
23324ae1
FM
407
408 /**
ee49f540
FM
409 Returns the multibyte (C string) representation of the string
410 using @e conv's wxMBConv::cWC2MB method and returns wxCharBuffer.
411
412 @see wc_str(), utf8_str(), c_str(), wxMBConv
23324ae1 413 */
ee49f540 414 const wxCharBuffer mb_str(const wxMBConv& conv = wxConvLibc) const;
23324ae1
FM
415
416 /**
ee49f540
FM
417 Converts the strings contents to UTF-8 and returns it either as a
418 temporary wxCharBuffer object or as a pointer to the internal
419 string contents in UTF-8 build.
ca164e23 420
ee49f540 421 @see wc_str(), c_str(), mb_str()
23324ae1 422 */
ee49f540
FM
423 const char* utf8_str() const;
424
23324ae1 425 /**
ee49f540 426 @overload
23324ae1 427 */
ee49f540 428 const wxCharBuffer utf8_str() const;
23324ae1
FM
429
430 /**
ee49f540
FM
431 Converts the strings contents to the wide character represention
432 and returns it as a temporary wxWCharBuffer object (Unix and OS X)
433 or returns a pointer to the internal string contents in wide character
434 mode (Windows).
23324ae1 435
ee49f540
FM
436 The macro wxWX2WCbuf is defined as the correct return type (without const).
437
438 @see utf8_str(), c_str(), mb_str(), fn_str(), wchar_str()
23324ae1 439 */
ee49f540 440 const wchar_t* wc_str() const;
23324ae1 441
23324ae1 442 /**
ee49f540 443 @overload
23324ae1 444 */
ee49f540 445 const wxWCharBuffer wc_str() const;
23324ae1
FM
446
447 /**
ee49f540
FM
448 Returns an object with string data that is implicitly convertible to
449 @c char* pointer. Note that changes to the returned buffer may or may
450 not be lost (depending on the build) and so this function is only usable for
451 passing strings to legacy libraries that don't have const-correct API. Use
452 wxStringBuffer if you want to modify the string.
453
454 @see mb_str(), wc_str(), fn_str(), c_str(), char_str()
23324ae1 455 */
ee49f540 456 wxWritableWCharBuffer wchar_str() const;
23324ae1 457
23324ae1 458 /**
ee49f540
FM
459 Explicit conversion to C string in the internal representation (either
460 wchar_t* or UTF-8-encoded char*, depending on the build).
23324ae1 461 */
ee49f540
FM
462 const wxStringCharType *wx_str() const;
463
23324ae1 464 /**
ee49f540
FM
465 Converts the string to an 8-bit string in ISO-8859-1 encoding in the
466 form of a wxCharBuffer (Unicode builds only).
467
468 This is a convenience method useful when storing binary data in
469 wxString. It should be used @em only for this purpose. It is only valid
470 to call this method on strings created using From8BitData().
471
472 @since 2.8.4
473
474 @see wxString::From8BitData()
23324ae1 475 */
ee49f540 476 const char* To8BitData() const;
23324ae1
FM
477
478 /**
ee49f540 479 @overload
23324ae1 480 */
ee49f540 481 const wxCharBuffer To8BitData() const;
23324ae1
FM
482
483 /**
ee49f540
FM
484 Converts the string to an ASCII, 7-bit string in the form of
485 a wxCharBuffer (Unicode builds only) or a C string (ANSI builds).
486 Note that this conversion only works if the string contains only ASCII
487 characters. The @ref mb_str() "mb_str" method provides more
488 powerful means of converting wxString to C string.
23324ae1 489 */
ee49f540 490 const char* ToAscii() const;
23324ae1
FM
491
492 /**
ee49f540 493 @overload
23324ae1 494 */
ee49f540 495 const wxCharBuffer ToAscii() const;
23324ae1
FM
496
497 /**
ee49f540 498 Same as utf8_str().
23324ae1 499 */
ee49f540 500 const char* ToUTF8() const;
23324ae1 501
0c7db140 502 /**
ee49f540 503 @overload
0c7db140 504 */
ee49f540 505 const wxCharBuffer ToUTF8() const;
0c7db140 506
ee49f540 507 //@}
0c7db140 508
23324ae1
FM
509
510 /**
ee49f540 511 @member_group_name{concat, Concatenation}
0c7db140 512
ee49f540
FM
513 Almost anything may be concatenated (appended to) with a string!
514
515 Note that the various operator<<() overloads work as C++ stream insertion
516 operators. They insert the given value into the string.
517 Precision and format cannot be set using them. Use Printf() instead.
23324ae1 518
ee49f540 519 See also the insert() and append() STL-like functions.
23324ae1 520 */
ee49f540 521 //@{
23324ae1 522
23324ae1 523 /**
ee49f540 524 Appends the string literal @a psz.
23324ae1 525 */
ee49f540 526 wxString& Append(const char* psz);
23324ae1
FM
527
528 /**
ee49f540 529 Appends the wide string literal @a pwz.
23324ae1 530 */
ee49f540 531 wxString& Append(const wchar_t* pwz);
23324ae1
FM
532
533 /**
ee49f540 534 Appends the string literal @a psz with max length @a nLen.
23324ae1 535 */
ee49f540 536 wxString& Append(const char* psz, size_t nLen);
23324ae1
FM
537
538 /**
ee49f540 539 Appends the wide string literal @a psz with max length @a nLen.
23324ae1 540 */
ee49f540 541 wxString& Append(const wchar_t* pwz, size_t nLen);
23324ae1
FM
542
543 /**
ee49f540 544 Appends the string @a s.
23324ae1 545 */
ee49f540 546 wxString& Append(const wxString& s);
23324ae1 547
23324ae1 548 /**
ee49f540 549 Appends the character @a ch @a count times.
23324ae1 550 */
ee49f540 551 wxString &Append(wxUniChar ch, size_t count = 1u);
23324ae1
FM
552
553 /**
ee49f540 554 Prepends @a str to this string, returning a reference to this string.
23324ae1 555 */
ee49f540 556 wxString& Prepend(const wxString& str);
23324ae1
FM
557
558 /**
ee49f540 559 Concatenation: returns a new string equal to the concatenation of the operands.
23324ae1 560 */
ee49f540
FM
561 wxString operator +(const wxString& x, const wxString& y);
562
23324ae1 563 /**
ee49f540 564 @overload
23324ae1 565 */
ee49f540 566 wxString operator +(const wxString& x, wxUniChar y);
23324ae1 567
ee49f540
FM
568 wxString& operator<<(const wxString& s);
569 wxString& operator<<(const char* psz);
570 wxString& operator<<(const wchar_t* pwz);
571 wxString& operator<<(const wxCStrData& psz);
572 wxString& operator<<(char ch);
573 wxString& operator<<(unsigned char ch);
574 wxString& operator<<(wchar_t ch);
575 wxString& operator<<(const wxCharBuffer& s);
576 wxString& operator<<(const wxWCharBuffer& s);
577 wxString& operator<<(wxUniCharRef ch);
578 wxString& operator<<(unsigned int ui);
579 wxString& operator<<(long l);
580 wxString& operator<<(unsigned long ul);
581 wxString& operator<<(wxLongLong_t ll);
582 wxString& operator<<(wxULongLong_t ul);
583 wxString& operator<<(float f);
584 wxString& operator<<(double d);
585
586 /**
587 Concatenation in place: the argument is appended to the string.
23324ae1 588 */
ee49f540
FM
589 void operator +=(const wxString& str);
590
591 /**
592 @overload
593 */
594 void operator +=(wxUniChar c);
595
596 //@}
597
23324ae1
FM
598
599 /**
ee49f540
FM
600 @member_group_name{cmp, Comparison}
601
602 The default comparison function Cmp() is case-sensitive and so is the default
603 version of IsSameAs(). For case insensitive comparisons you should use CmpNoCase()
604 or give a second parameter to IsSameAs(). This last function is maybe more
605 convenient if only equality of the strings matters because it returns a boolean
606 @true value if the strings are the same and not 0 (which is usually @false
607 in C) as Cmp() does.
608
609 Matches() is a poor man's regular expression matcher: it only understands
610 '*' and '?' metacharacters in the sense of DOS command line interpreter.
611
612 StartsWith() is helpful when parsing a line of text which should start
613 with some predefined prefix and is more efficient than doing direct string
614 comparison as you would also have to precalculate the length of the prefix.
615
616 See also the compare() STL-like function.
23324ae1 617 */
ee49f540
FM
618 //@{
619
620 /**
621 Case-sensitive comparison.
622 Returns a positive value if the string is greater than the argument,
623 zero if it is equal to it or a negative value if it is less than the
624 argument (same semantics as the standard @c strcmp() function).
625
626 @see CmpNoCase(), IsSameAs().
627 */
628 int Cmp(const wxString& s) const;
629
630 /**
631 Case-insensitive comparison.
632 Returns a positive value if the string is greater than the argument,
633 zero if it is equal to it or a negative value if it is less than the
634 argument (same semantics as the standard @c strcmp() function).
635
636 @see Cmp(), IsSameAs().
637 */
638 int CmpNoCase(const wxString& s) const;
639
640 /**
641 Test whether the string is equal to the single character @a c.
642
643 The test is case-sensitive if @a caseSensitive is @true (default) or not if it is
644 @false.
645
646 Returns @true if the string is equal to the character, @false otherwise.
647
648 @see Cmp(), CmpNoCase()
649 */
650 bool IsSameAs(const wxString &s, bool caseSensitive = true) const;
651
652 /**
653 @overload
654 */
655 bool IsSameAs(wxUniChar ch, bool caseSensitive = true) const;
656
657 /**
658 Returns @true if the string contents matches a mask containing '*' and '?'.
659 */
660 bool Matches(const wxString& mask) const;
23324ae1
FM
661
662 /**
7c913512 663 This function can be used to test if the string starts with the specified
ee49f540
FM
664 @a prefix.
665
666 If it does, the function will return @true and put the rest of the string
667 (i.e. after the prefix) into @a rest string if it is not @NULL.
668 Otherwise, the function returns @false and doesn't modify the @a rest.
23324ae1 669 */
6d95e7be 670 bool StartsWith(const wxString& prefix, wxString *rest = NULL) const;
23324ae1 671
23324ae1 672 /**
ee49f540
FM
673 This function can be used to test if the string ends with the specified
674 @e suffix. If it does, the function will return @true and put the
675 beginning of the string before the suffix into @e rest string if it is not
676 @NULL. Otherwise, the function returns @false and doesn't
677 modify the @e rest.
23324ae1 678 */
ee49f540
FM
679 bool EndsWith(const wxString& suffix, wxString *rest = NULL) const;
680
681 //@}
682
683
684 /**
685 @member_group_name{substring, Substring extraction}
686
687 These functions allow you to extract a substring from the string. The
688 original string is not modified and the function returns the extracted
689 substring.
690
691 See also the at() and the substr() STL-like functions.
692 */
693
694 /**
695 Returns a substring starting at @e first, with length @e count, or the rest of
696 the string if @a count is the default value.
697 */
698 wxString Mid(size_t first, size_t nCount = wxString::npos) const;
23324ae1
FM
699
700 /**
ee49f540 701 Returns the part of the string between the indices @a from and @a to
23324ae1 702 inclusive.
ee49f540 703
23324ae1
FM
704 This is a wxWidgets 1.xx compatibility function, use Mid()
705 instead (but note that parameters have different meaning).
706 */
328f5751 707 wxString SubString(size_t from, size_t to) const;
ee49f540
FM
708
709 /**
710 Same as Mid() (substring extraction).
711 */
712 wxString operator()(size_t start, size_t len) const;
713
714 /**
715 Returns the first @a count characters of the string.
716 */
717 wxString Left(size_t count) const;
718
719 /**
720 Returns the last @a count characters.
721 */
722 wxString Right(size_t count) const;
723
724 /**
725 Gets all the characters after the first occurrence of @e ch.
726 Returns the empty string if @e ch is not found.
727 */
728 wxString AfterFirst(wxUniChar ch) const;
729
730 /**
731 Gets all the characters after the last occurrence of @e ch.
732 Returns the whole string if @e ch is not found.
733 */
734 wxString AfterLast(wxUniChar ch) const;
735
736 /**
737 Gets all characters before the first occurrence of @e ch.
738 Returns the whole string if @a ch is not found.
739 */
740 wxString BeforeFirst(wxUniChar ch) const;
741
742 /**
743 Gets all characters before the last occurrence of @e ch.
744 Returns the empty string if @a ch is not found.
745 */
746 wxString BeforeLast(wxUniChar ch) const;
747
748 //@}
749
750
751 /**
752 @member_group_name{caseconv, Case conversion}
23324ae1 753
ee49f540
FM
754 The MakeXXX() variants modify the string in place, while the other functions
755 return a new string which contains the original text converted to the upper or
756 lower case and leave the original string unchanged.
757 */
23324ae1 758 //@{
ee49f540 759
23324ae1 760 /**
ee49f540
FM
761 Return the copy of the string with the first string character in the
762 upper case and the subsequent ones in the lower case.
70897a70 763
ee49f540 764 @since 2.9.0
3c4f71cc 765
ee49f540
FM
766 @see MakeCapitalized()
767 */
768 wxString Capitalize() const;
3c4f71cc 769
ee49f540
FM
770 /**
771 Returns this string converted to the lower case.
772
773 @see MakeLower()
23324ae1 774 */
ee49f540
FM
775 wxString Lower() const;
776
777 /**
778 Same as MakeLower.
779 This is a wxWidgets 1.xx compatibility function; you should not use it in new
780 code.
781 */
782 void LowerCase();
783
784 /**
785 Converts the first characters of the string to the upper case and all
786 the subsequent ones to the lower case and returns the result.
787
788 @since 2.9.0
789
790 @see Capitalize()
791 */
792 wxString& MakeCapitalized();
793
794 /**
795 Converts all characters to lower case and returns the reference to the
796 modified string.
797
798 @see Lower()
799 */
800 wxString& MakeLower();
801
802 /**
803 Converts all characters to upper case and returns the reference to the
804 modified string.
805
806 @see Upper()
807 */
808 wxString& MakeUpper();
809
810 /**
811 Returns this string converted to upper case.
812
813 @see MakeUpper()
814 */
815 wxString Upper() const;
816
817 /**
818 The same as MakeUpper().
819
820 This is a wxWidgets 1.xx compatibility function; you should not use it in new
821 code.
822 */
823 void UpperCase();
824
23324ae1 825 //@}
ee49f540
FM
826
827
828 /**
829 @member_group_name{search, Searching and replacing}
23324ae1 830
ee49f540
FM
831 These functions replace the standard @c strchr() and @c strstr()
832 functions.
833
834 See also the find(), rfind(), replace() STL-like functions.
835 */
23324ae1 836 //@{
ee49f540 837
23324ae1 838 /**
ee49f540
FM
839 Searches for the given character @a ch.
840 Returns the position or @c wxNOT_FOUND if not found.
23324ae1 841 */
ee49f540
FM
842 int Find(wxUniChar ch, bool fromEnd = false) const;
843
844 /**
845 Searches for the given string @a sub.
846 Returns the starting position or @c wxNOT_FOUND if not found.
847 */
848 int Find(const wxString& sub) const;
849
850 /**
851 Same as Find().
852
853 This is a wxWidgets 1.xx compatibility function;
854 you should not use it in new code.
855 */
856 int First(wxUniChar ch) const;
857
858 /**
859 Same as Find().
860
861 This is a wxWidgets 1.xx compatibility function;
862 you should not use it in new code.
863 */
864 int First(const wxString& str) const;
865
866 /**
867 Replace first (or all) occurrences of substring with another one.
868
869 @param strOld
870 The string to search for replacing.
871 @param strNew
872 The substitution string.
873 @param replaceAll
874 If @true a global replace will be done (default), otherwise only the
875 first occurrence will be replaced.
876
877 Returns the number of replacements made.
878 */
879 size_t Replace(const wxString& strOld, const wxString& strNew,
880 bool replaceAll = true);
881
23324ae1
FM
882 //@}
883
ee49f540
FM
884
885
886 /**
887 @member_group_name{numconv, Conversion to numbers}
888
889 The string provides functions for conversion to signed and unsigned integer and
890 floating point numbers. All functions take a pointer to the variable to
891 put the numeric value in and return @true if the @b entire string could be
892 converted to a number.
893 */
894 //@{
895
23324ae1
FM
896 /**
897 Attempts to convert the string to a floating point number. Returns @true on
898 success (the number is stored in the location pointed to by @e val) or @false
4cc4bfaf 899 if the string does not represent such number (the value of @a val is not
23324ae1 900 modified in this case).
3c4f71cc 901
4cc4bfaf 902 @see ToLong(), ToULong()
23324ae1 903 */
5267aefd 904 bool ToDouble(double* val) const;
23324ae1
FM
905
906 /**
907 Attempts to convert the string to a signed integer in base @e base. Returns
908 @true on success in which case the number is stored in the location
4cc4bfaf
FM
909 pointed to by @a val or @false if the string does not represent a
910 valid number in the given base (the value of @a val is not modified
23324ae1 911 in this case).
4cc4bfaf 912 The value of @a base must be comprised between 2 and 36, inclusive, or
23324ae1
FM
913 be a special value 0 which means that the usual rules of @c C numbers are
914 applied: if the number starts with @c 0x it is considered to be in base
915 16, if it starts with @c 0 - in base 8 and in base 10 otherwise. Note
916 that you may not want to specify the base 0 if you are parsing the numbers
917 which may have leading zeroes as they can yield unexpected (to the user not
918 familiar with C) results.
3c4f71cc 919
4cc4bfaf 920 @see ToDouble(), ToULong()
23324ae1 921 */
5267aefd 922 bool ToLong(long* val, int base = 10) const;
23324ae1
FM
923
924 /**
925 This is exactly the same as ToLong() but works with 64
926 bit integer numbers.
23324ae1
FM
927 Notice that currently it doesn't work (always returns @false) if parsing of 64
928 bit numbers is not supported by the underlying C run-time library. Compilers
929 with C99 support and Microsoft Visual C++ version 7 and higher do support this.
3c4f71cc 930
4cc4bfaf 931 @see ToLong(), ToULongLong()
23324ae1 932 */
5267aefd 933 bool ToLongLong(wxLongLong_t* val, int base = 10) const;
23324ae1
FM
934
935 /**
936 Attempts to convert the string to an unsigned integer in base @e base.
937 Returns @true on success in which case the number is stored in the
4cc4bfaf
FM
938 location pointed to by @a val or @false if the string does not
939 represent a valid number in the given base (the value of @a val is not
4701dc09
FM
940 modified in this case).
941
942 Please notice that this function behaves in the same way as the standard
943 @c strtoul() and so it simply converts negative numbers to unsigned
944 representation instead of rejecting them (e.g. -1 is returned as @c ULONG_MAX).
945
946 See ToLong() for the more detailed description of the @a base parameter.
3c4f71cc 947
4cc4bfaf 948 @see ToDouble(), ToLong()
23324ae1 949 */
5267aefd 950 bool ToULong(unsigned long* val, int base = 10) const;
23324ae1
FM
951
952 /**
953 This is exactly the same as ToULong() but works with 64
954 bit integer numbers.
23324ae1
FM
955 Please see ToLongLong() for additional remarks.
956 */
5267aefd 957 bool ToULongLong(wxULongLong_t* val, int base = 10) const;
23324ae1 958
23324ae1
FM
959 //@}
960
23324ae1
FM
961
962 /**
ee49f540 963 @member_group_name{fmt, Formatting and printing}
23324ae1 964
ee49f540
FM
965 Both formatted versions (Printf/() and stream-like insertion operators
966 exist (for basic types only).
967
968 See also the static Format() and FormatV() functions.
969 */
23324ae1 970 //@{
4701dc09 971
ee49f540
FM
972 /**
973 Similar to the standard function @e sprintf(). Returns the number of
974 characters written, or an integer less than zero on error.
975 Note that if @c wxUSE_PRINTF_POS_PARAMS is set to 1, then this function supports
976 Unix98-style positional parameters:
4701dc09 977
ee49f540
FM
978 @note This function will use a safe version of @e vsprintf() (usually called
979 @e vsnprintf()) whenever available to always allocate the buffer of correct
980 size. Unfortunately, this function is not available on all platforms and the
981 dangerous @e vsprintf() will be used then which may lead to buffer overflows.
23324ae1 982 */
ee49f540
FM
983 int Printf(const wxString& pszFormat, ...);
984
985 /**
986 Similar to vprintf. Returns the number of characters written, or an integer
987 less than zero
988 on error.
989 */
990 int PrintfV(const wxString& pszFormat, va_list argPtr);
991
23324ae1 992 //@}
ee49f540
FM
993
994
995 /**
996 @member_group_name{mem, Memory management}
23324ae1 997
ee49f540
FM
998 The following are "advanced" functions and they will be needed rarely.
999 Alloc() and Shrink() are only interesting for optimization purposes.
1000 wxStringBuffer and wxStringBufferLength classes may be very useful when working
1001 with some external API which requires the caller to provide a writable buffer.
1002
1003 See also the reserve() and resize() STL-like functions.
1004 */
1005 //@{
1006
23324ae1 1007 /**
ee49f540 1008 Preallocate enough space for wxString to store @a nLen characters.
0c7db140 1009
ee49f540
FM
1010 Please note that this method does the same thing as the standard
1011 reserve() one and shouldn't be used in new code.
1012
1013 This function may be used to increase speed when the string is
1014 constructed by repeated concatenation as in
1015
1016 @code
1017 // delete all vowels from the string
1018 wxString DeleteAllVowels(const wxString& original)
1019 {
1020 wxString result;
1021
1022 size_t len = original.length();
1023
1024 result.Alloc(len);
1025
1026 for ( size_t n = 0; n < len; n++ )
1027 {
1028 if ( strchr("aeuio", tolower(original[n])) == NULL )
1029 result += original[n];
1030 }
1031
1032 return result;
1033 }
1034 @endcode
1035
1036 because it will avoid the need to reallocate string memory many times
1037 (in case of long strings). Note that it does not set the maximal length
1038 of a string -- it will still expand if more than @a nLen characters are
1039 stored in it. Also, it does not truncate the existing string (use
1040 Truncate() for this) even if its current length is greater than @a nLen.
1041
1042 @return @true if memory was successfully allocated, @false otherwise.
23324ae1 1043 */
ee49f540 1044 bool Alloc(size_t nLen);
23324ae1
FM
1045
1046 /**
ee49f540
FM
1047 Minimizes the string's memory. This can be useful after a call to
1048 Alloc() if too much memory were preallocated.
23324ae1 1049 */
ee49f540 1050 bool Shrink();
23324ae1 1051
23324ae1 1052 /**
ee49f540 1053 Returns a deep copy of the string.
0c7db140 1054
ee49f540
FM
1055 That is, the returned string is guaranteed to not share data with this
1056 string when using reference-counted wxString implementation.
0c7db140 1057
ee49f540
FM
1058 This method is primarily useful for passing strings between threads
1059 (because wxString is not thread-safe). Unlike creating a copy using
1060 @c wxString(c_str()), Clone() handles embedded NULs correctly.
0c7db140 1061
ee49f540
FM
1062 @since 2.9.0
1063 */
1064 wxString Clone() const;
1065
1066 /**
1067 Empties the string and frees memory occupied by it.
1068
1069 @see Empty()
23324ae1 1070 */
ee49f540
FM
1071 void Clear();
1072
1073 //@}
1074
1075
23324ae1
FM
1076
1077 /**
ee49f540 1078 @member_group_name{misc, Miscellaneous}
3c4f71cc 1079
ee49f540 1080 Miscellaneous other string functions.
23324ae1 1081 */
ee49f540 1082 //@{
23324ae1 1083
062dc5fc 1084 /**
ee49f540
FM
1085 Returns @true if target appears anywhere in wxString; else @false.
1086
1087 This is a wxWidgets 1.xx compatibility function; you should not use it in new code.
1088 */
1089 bool Contains(const wxString& str) const;
062dc5fc 1090
ee49f540
FM
1091 /**
1092 Makes the string empty, but doesn't free memory occupied by the string.
1093
1094 @see Clear().
1095 */
1096 void Empty();
062dc5fc 1097
ee49f540
FM
1098 /**
1099 Returns the number of occurrences of @e ch in the string.
1100
1101 This is a wxWidgets 1.xx compatibility function; you should not use it in new code.
1102 */
1103 int Freq(wxUniChar ch) const;
062dc5fc 1104
ee49f540
FM
1105 /**
1106 Returns @true if the string contains only ASCII characters.
1107 See wxUniChar::IsAscii for more details.
4701dc09 1108
ee49f540
FM
1109 This is a wxWidgets 1.xx compatibility function; you should not use it in new
1110 code.
1111 */
1112 bool IsAscii() const;
062dc5fc 1113
23324ae1 1114 /**
ee49f540
FM
1115 Returns @true if the string is an integer (with possible sign).
1116
1117 This is a wxWidgets 1.xx compatibility function; you should not use it in new code.
23324ae1 1118 */
ee49f540 1119 bool IsNumber() const;
23324ae1 1120
23324ae1 1121 /**
ee49f540
FM
1122 Returns @true if the string is a word.
1123
1124 This is a wxWidgets 1.xx compatibility function; you should not use it in new code.
1125 */
1126 bool IsWord() const;
0c7db140 1127
ee49f540
FM
1128 /**
1129 Adds @a count copies of @a chPad to the beginning, or to the end of the
1130 string (the default).
1131
1132 Removes spaces from the left or from the right (default).
23324ae1 1133 */
ee49f540
FM
1134 wxString& Pad(size_t count, wxUniChar chPad = ' ', bool fromRight = true);
1135
1136 /**
1137 Removes all characters from the string starting at @a pos.
1138 Use Truncate() as a more readable alternative.
1139
1140 This is a wxWidgets 1.xx compatibility function; you should not use it in new code.
1141 */
1142 wxString& Remove(size_t pos);
1143
1144 /**
1145 Removes @a len characters from the string, starting at @a pos.
1146
1147 This is a wxWidgets 1.xx compatibility function; you should not use it in new code.
1148 */
1149 wxString& Remove(size_t pos, size_t len);
23324ae1
FM
1150
1151 /**
ee49f540 1152 Removes the last character.
23324ae1 1153 */
ee49f540 1154 wxString& RemoveLast(size_t n = 1);
bcc8c903
RR
1155
1156 /**
ee49f540
FM
1157 Strip characters at the front and/or end.
1158
1159 This is the same as Trim() except that it doesn't change this string.
1160
1161 This is a wxWidgets 1.xx compatibility function; you should not use it in new code.
bcc8c903 1162 */
ee49f540 1163 wxString Strip(stripType s = trailing) const;
23324ae1
FM
1164
1165 /**
ee49f540
FM
1166 Removes white-space (space, tabs, form feed, newline and carriage return) from
1167 the left or from the right end of the string (right is default).
23324ae1 1168 */
ee49f540 1169 wxString& Trim(bool fromRight = true);
23324ae1 1170
23324ae1 1171 /**
ee49f540 1172 Truncate the string to the given length.
23324ae1 1173 */
ee49f540
FM
1174 wxString& Truncate(size_t len);
1175
23324ae1
FM
1176 //@}
1177
ee49f540
FM
1178
1179
1180
23324ae1 1181 /**
ee49f540
FM
1182 @member_group_name{iter, Iterator interface}
1183
1184 These methods return iterators to the beginnnig or end of the string.
1185
1186 Please see any STL reference (e.g. http://www.cppreference.com/wiki/string/start)
1187 for their documentation.
23324ae1 1188 */
ee49f540
FM
1189 //@{
1190
1191 const_iterator begin() const;
1192 iterator begin();
1193 const_iterator end() const;
1194 iterator end();
1195
1196 const_reverse_iterator rbegin() const;
1197 reverse_iterator rbegin();
1198 const_reverse_iterator rend() const;
1199 reverse_iterator rend();
1200
23324ae1
FM
1201 //@}
1202
ee49f540
FM
1203
1204
23324ae1 1205 /**
ee49f540
FM
1206 @member_group_name{stl, STL interface}
1207
1208 The supported STL functions are listed here.
1209
1210 Please see any STL reference (e.g. http://www.cppreference.com/wiki/string/start)
1211 for their documentation.
23324ae1 1212 */
ee49f540
FM
1213 //@{
1214
1215 wxString& append(const wxString& str, size_t pos, size_t n);
1216 wxString& append(const wxString& str);
1217 wxString& append(const char *sz, size_t n);
1218 wxString& append(const wchar_t *sz, size_t n);
1219 wxString& append(size_t n, wxUniChar ch);
1220 wxString& append(const_iterator first, const_iterator last);
1221
1222 wxString& assign(const wxString& str, size_t pos, size_t n);
1223 wxString& assign(const wxString& str);
1224 wxString& assign(const char *sz, size_t n);
1225 wxString& assign(const wchar_t *sz, size_t n);
1226 wxString& assign(size_t n, wxUniChar ch);
1227 wxString& assign(const_iterator first, const_iterator last);
1228
1229 wxUniChar at(size_t n) const;
1230 wxUniCharRef at(size_t n);
1231
1232 void clear();
1233
1234 size_type capacity() const;
1235
1236 int compare(const wxString& str) const;
1237 int compare(size_t nStart, size_t nLen, const wxString& str) const;
1238 int compare(size_t nStart, size_t nLen,
1239 const wxString& str, size_t nStart2, size_t nLen2) const;
1240 int compare(size_t nStart, size_t nLen,
1241 const char* sz, size_t nCount = npos) const;
1242 int compare(size_t nStart, size_t nLen,
1243 const wchar_t* sz, size_t nCount = npos) const;
1244
1245 wxCStrData data() const;
1246
1247 bool empty() const;
1248
1249 wxString& erase(size_type pos = 0, size_type n = npos);
1250 iterator erase(iterator first, iterator last);
1251 iterator erase(iterator first);
1252
1253 size_t find(const wxString& str, size_t nStart = 0) const;
1254 size_t find(const char* sz, size_t nStart = 0, size_t n = npos) const;
1255 size_t find(const wchar_t* sz, size_t nStart = 0, size_t n = npos) const;
1256 size_t find(wxUniChar ch, size_t nStart = 0) const;
1257 size_t find_first_of(const char* sz, size_t nStart = 0) const;
1258 size_t find_first_of(const wchar_t* sz, size_t nStart = 0) const;
1259 size_t find_first_of(const char* sz, size_t nStart, size_t n) const;
1260 size_t find_first_of(const wchar_t* sz, size_t nStart, size_t n) const;
1261 size_t find_first_of(wxUniChar c, size_t nStart = 0) const;
1262 size_t find_last_of (const wxString& str, size_t nStart = npos) const;
1263 size_t find_last_of (const char* sz, size_t nStart = npos) const;
1264 size_t find_last_of (const wchar_t* sz, size_t nStart = npos) const;
1265 size_t find_last_of(const char* sz, size_t nStart, size_t n) const;
1266 size_t find_last_of(const wchar_t* sz, size_t nStart, size_t n) const;
1267 size_t find_last_of(wxUniChar c, size_t nStart = npos) const;
1268 size_t find_first_not_of(const wxString& str, size_t nStart = 0) const;
1269 size_t find_first_not_of(const char* sz, size_t nStart = 0) const;
1270 size_t find_first_not_of(const wchar_t* sz, size_t nStart = 0) const;
1271 size_t find_first_not_of(const char* sz, size_t nStart, size_t n) const;
1272 size_t find_first_not_of(const wchar_t* sz, size_t nStart, size_t n) const;
1273 size_t find_first_not_of(wxUniChar ch, size_t nStart = 0) const;
1274 size_t find_last_not_of(const wxString& str, size_t nStart = npos) const;
1275 size_t find_last_not_of(const char* sz, size_t nStart = npos) const;
1276 size_t find_last_not_of(const wchar_t* sz, size_t nStart = npos) const;
1277 size_t find_last_not_of(const char* sz, size_t nStart, size_t n) const;
1278 size_t find_last_not_of(const wchar_t* sz, size_t nStart, size_t n) const;
1279
1280 wxString& insert(size_t nPos, const wxString& str);
1281 wxString& insert(size_t nPos, const wxString& str, size_t nStart, size_t n);
1282 wxString& insert(size_t nPos, const char *sz, size_t n);
1283 wxString& insert(size_t nPos, const wchar_t *sz, size_t n);
1284 wxString& insert(size_t nPos, size_t n, wxUniChar ch);
1285 iterator insert(iterator it, wxUniChar ch);
1286 void insert(iterator it, const_iterator first, const_iterator last);
1287 void insert(iterator it, size_type n, wxUniChar ch);
1288
1289 size_t length() const;
1290
1291 size_type max_size() const;
1292
1293 void reserve(size_t sz);
1294 void resize(size_t nSize, wxUniChar ch = '\0');
1295
1296 wxString& replace(size_t nStart, size_t nLen, const wxString& str);
1297 wxString& replace(size_t nStart, size_t nLen, size_t nCount, wxUniChar ch);
1298 wxString& replace(size_t nStart, size_t nLen,
1299 const wxString& str, size_t nStart2, size_t nLen2);
1300 wxString& replace(size_t nStart, size_t nLen,
1301 const char* sz, size_t nCount);
1302 wxString& replace(size_t nStart, size_t nLen,
1303 const wchar_t* sz, size_t nCount);
1304 wxString& replace(size_t nStart, size_t nLen,
1305 const wxString& s, size_t nCount);
1306 wxString& replace(iterator first, iterator last, const wxString& s);
1307 wxString& replace(iterator first, iterator last, const char* s, size_type n);
1308 wxString& replace(iterator first, iterator last, const wchar_t* s, size_type n);
1309 wxString& replace(iterator first, iterator last, size_type n, wxUniChar ch);
1310 wxString& replace(iterator first, iterator last,
1311 const_iterator first1, const_iterator last1);
1312 wxString& replace(iterator first, iterator last,
1313 const char *first1, const char *last1);
1314 wxString& replace(iterator first, iterator last,
1315 const wchar_t *first1, const wchar_t *last1);
1316
1317 size_t rfind(const wxString& str, size_t nStart = npos) const;
1318 size_t rfind(const char* sz, size_t nStart = npos, size_t n = npos) const;
1319 size_t rfind(const wchar_t* sz, size_t nStart = npos, size_t n = npos) const;
1320 size_t rfind(wxUniChar ch, size_t nStart = npos) const;
1321
1322 size_type size() const;
1323 wxString substr(size_t nStart = 0, size_t nLen = npos) const;
1324 void swap(wxString& str);
1325
23324ae1 1326 //@}
ee49f540
FM
1327
1328
1329
1330 // STATIC FUNCTIONS
1331 // Keep these functions separed from the other groups or Doxygen gets confused
1332 // -----------------------------------------------------------------------------
23324ae1 1333
23324ae1 1334 /**
ee49f540 1335 An 'invalid' value for string index
23324ae1 1336 */
ee49f540 1337 static const size_t npos;
23324ae1
FM
1338
1339 /**
ee49f540
FM
1340 This static function returns the string containing the result of calling
1341 Printf() with the passed parameters on it.
062dc5fc 1342
ee49f540 1343 @see FormatV(), Printf()
23324ae1 1344 */
ee49f540 1345 static wxString Format(const wxString& format, ...);
23324ae1 1346
23324ae1 1347 /**
ee49f540
FM
1348 This static function returns the string containing the result of calling
1349 PrintfV() with the passed parameters on it.
0c7db140 1350
ee49f540 1351 @see Format(), PrintfV()
23324ae1 1352 */
ee49f540 1353 static wxString FormatV(const wxString& format, va_list argptr);
23324ae1
FM
1354
1355 //@{
1356 /**
ee49f540
FM
1357 Converts given buffer of binary data from 8-bit string to wxString. In
1358 Unicode build, the string is interpreted as being in ISO-8859-1
1359 encoding. The version without @e len parameter takes NUL-terminated
1360 data.
062dc5fc 1361
ee49f540
FM
1362 This is a convenience method useful when storing binary data in
1363 wxString. It should be used @em only for that purpose and only in
1364 conjunction with To8BitData(). Use mb_str() for conversion of character
1365 data to known encoding.
3c4f71cc 1366
ee49f540
FM
1367 @since 2.8.4
1368
1369 @see wxString::To8BitData()
23324ae1 1370 */
ee49f540
FM
1371 static wxString From8BitData(const char* buf, size_t len);
1372 static wxString From8BitData(const char* buf);
23324ae1
FM
1373 //@}
1374
ee49f540 1375 //@{
23324ae1 1376 /**
ee49f540
FM
1377 Converts the string or character from an ASCII, 7-bit form
1378 to the native wxString representation.
23324ae1 1379 */
ee49f540
FM
1380 static wxString FromAscii(const char* s);
1381 static wxString FromAscii(const unsigned char* s);
1382 static wxString FromAscii(const char* s, size_t len);
1383 static wxString FromAscii(const unsigned char* s, size_t len);
1384 static wxString FromAscii(char c);
1385 //@}
23324ae1 1386
ee49f540 1387 //@{
0c7db140 1388 /**
ee49f540 1389 Converts C string encoded in UTF-8 to wxString.
6307d716 1390
ee49f540 1391 If @a s is not a valid UTF-8 string, an empty string is returned.
6307d716 1392
ee49f540
FM
1393 Notice that when using UTF-8 wxWidgets build there is a more efficient
1394 alternative to this function called FromUTF8Unchecked() which, unlike
1395 this one, doesn't check that the input string is valid.
062dc5fc 1396
ee49f540 1397 @since 2.8.4
b33e2f63 1398 */
ee49f540
FM
1399 static wxString FromUTF8(const char* s);
1400 static wxString FromUTF8(const char* s, size_t len);
f08b2466 1401 //@}
b33e2f63 1402
ee49f540 1403 //@{
f08b2466 1404 /**
ee49f540
FM
1405 Converts C string encoded in UTF-8 to wxString without checking its
1406 validity.
062dc5fc 1407
ee49f540
FM
1408 This method assumes that @a s is a valid UTF-8 sequence and doesn't do
1409 any validation (although an assert failure is triggered in debug builds
1410 if the string is invalid). Only use it if you are absolutely sure that
1411 @a s is a correct UTF-8 string (e.g. because it comes from another
1412 library using UTF-8) and if the performance matters, otherwise use
1413 slower (in UTF-8 build) but safer FromUTF8(). Passing a bad UTF-8
1414 string to this function will result in creating a corrupted wxString
1415 and all the subsequent operations on it will be undefined.
1416
1417 @since 2.8.9
f08b2466 1418 */
ee49f540
FM
1419 static wxString FromUTF8Unchecked(const char* s);
1420 static wxString FromUTF8Unchecked(const char* s, size_t len);
b33e2f63 1421 //@}
23324ae1
FM
1422};
1423
457f3abf
BP
1424
1425
57bf907d
FM
1426//@{
1427/**
457f3abf 1428 Comparison operator for string types.
57bf907d
FM
1429*/
1430inline bool operator==(const wxString& s1, const wxString& s2);
1431inline bool operator!=(const wxString& s1, const wxString& s2);
1432inline bool operator< (const wxString& s1, const wxString& s2);
1433inline bool operator> (const wxString& s1, const wxString& s2);
1434inline bool operator<=(const wxString& s1, const wxString& s2);
1435inline bool operator>=(const wxString& s1, const wxString& s2);
1436inline bool operator==(const wxString& s1, const wxCStrData& s2);
1437inline bool operator==(const wxCStrData& s1, const wxString& s2);
1438inline bool operator!=(const wxString& s1, const wxCStrData& s2);
1439inline bool operator!=(const wxCStrData& s1, const wxString& s2);
1440inline bool operator==(const wxString& s1, const wxWCharBuffer& s2);
1441inline bool operator==(const wxWCharBuffer& s1, const wxString& s2);
1442inline bool operator!=(const wxString& s1, const wxWCharBuffer& s2);
1443inline bool operator!=(const wxWCharBuffer& s1, const wxString& s2);
1444inline bool operator==(const wxString& s1, const wxCharBuffer& s2);
1445inline bool operator==(const wxCharBuffer& s1, const wxString& s2);
1446inline bool operator!=(const wxString& s1, const wxCharBuffer& s2);
1447inline bool operator!=(const wxCharBuffer& s1, const wxString& s2);
457f3abf 1448//@}
57bf907d 1449
457f3abf 1450//@{
57bf907d 1451/**
457f3abf 1452 Comparison operators char types.
57bf907d
FM
1453*/
1454inline bool operator==(const wxUniChar& c, const wxString& s);
1455inline bool operator==(const wxUniCharRef& c, const wxString& s);
1456inline bool operator==(char c, const wxString& s);
1457inline bool operator==(wchar_t c, const wxString& s);
1458inline bool operator==(int c, const wxString& s);
1459inline bool operator==(const wxString& s, const wxUniChar& c);
1460inline bool operator==(const wxString& s, const wxUniCharRef& c);
1461inline bool operator==(const wxString& s, char c);
1462inline bool operator==(const wxString& s, wchar_t c);
1463inline bool operator!=(const wxUniChar& c, const wxString& s);
1464inline bool operator!=(const wxUniCharRef& c, const wxString& s);
1465inline bool operator!=(char c, const wxString& s);
1466inline bool operator!=(wchar_t c, const wxString& s);
1467inline bool operator!=(int c, const wxString& s);
1468inline bool operator!=(const wxString& s, const wxUniChar& c);
1469inline bool operator!=(const wxString& s, const wxUniCharRef& c);
1470inline bool operator!=(const wxString& s, char c);
1471inline bool operator!=(const wxString& s, wchar_t c);
1472//@}
1473
e54c96f1 1474/**
4701dc09
FM
1475 The global wxString instance of an empty string.
1476 Used extensively in the entire wxWidgets API.
e54c96f1
FM
1477*/
1478wxString wxEmptyString;
1479
1480
1481
23324ae1
FM
1482/**
1483 @class wxStringBufferLength
7c913512 1484
4701dc09
FM
1485 This tiny class allows you to conveniently access the wxString internal buffer
1486 as a writable pointer without any risk of forgetting to restore the string to
1487 the usable state later, and allows the user to set the internal length of the string.
7c913512
FM
1488
1489 For example, assuming you have a low-level OS function called
4701dc09 1490 @c "int GetMeaningOfLifeAsString(char *)" copying the value in the provided
23324ae1
FM
1491 buffer (which must be writable, of course), and returning the actual length
1492 of the string, you might call it like this:
7c913512 1493
23324ae1 1494 @code
4701dc09 1495 wxString theAnswer;
23324ae1
FM
1496 wxStringBuffer theAnswerBuffer(theAnswer, 1024);
1497 int nLength = GetMeaningOfLifeAsString(theAnswerBuffer);
1498 theAnswerBuffer.SetLength(nLength);
1499 if ( theAnswer != "42" )
23324ae1 1500 wxLogError("Something is very wrong!");
23324ae1 1501 @endcode
7c913512 1502
4701dc09
FM
1503 @todo
1504 the example above does not make use of wxStringBufferLength??
1505
bcc8c903 1506 Note that the exact usage of this depends on whether or not wxUSE_STL is
0c7db140 1507 enabled. If wxUSE_STL is enabled, wxStringBuffer creates a separate empty
bcc8c903 1508 character buffer, and if wxUSE_STL is disabled, it uses GetWriteBuf() from
0c7db140
VZ
1509 wxString, keeping the same buffer wxString uses intact. In other words,
1510 relying on wxStringBuffer containing the old wxString data is not a good
bcc8c903 1511 idea if you want to build your program both with and without wxUSE_STL.
7c913512 1512
4701dc09
FM
1513 Note that wxStringBuffer::SetLength @b must be called before
1514 wxStringBufferLength destructs.
7c913512 1515
23324ae1 1516 @library{wxbase}
bcc8c903 1517 @category{data}
23324ae1 1518*/
7c913512 1519class wxStringBufferLength
23324ae1
FM
1520{
1521public:
1522 /**
1523 Constructs a writable string buffer object associated with the given string
4701dc09
FM
1524 and containing enough space for at least @a len characters.
1525
1526 Basically, this is equivalent to calling wxString::GetWriteBuf and
23324ae1
FM
1527 saving the result.
1528 */
1529 wxStringBufferLength(const wxString& str, size_t len);
1530
1531 /**
7c913512 1532 Restores the string passed to the constructor to the usable state by calling
23324ae1
FM
1533 wxString::UngetWriteBuf on it.
1534 */
1535 ~wxStringBufferLength();
1536
1537 /**
7c913512 1538 Sets the internal length of the string referred to by wxStringBufferLength to
4cc4bfaf 1539 @a nLength characters.
4701dc09 1540
23324ae1
FM
1541 Must be called before wxStringBufferLength destructs.
1542 */
1543 void SetLength(size_t nLength);
1544
1545 /**
1546 Returns the writable pointer to a buffer of the size at least equal to the
1547 length specified in the constructor.
1548 */
4cc4bfaf 1549 wxChar* operator wxChar *();
23324ae1
FM
1550};
1551
727aa906
FM
1552
1553/**
1554 @class wxStringBuffer
1555
1556 This tiny class allows you to conveniently access the wxString internal buffer
1557 as a writable pointer without any risk of forgetting to restore the string
1558 to the usable state later.
1559
1560 For example, assuming you have a low-level OS function called
1561 @c "GetMeaningOfLifeAsString(char *)" returning the value in the provided
1562 buffer (which must be writable, of course) you might call it like this:
1563
1564 @code
1565 wxString theAnswer;
1566 GetMeaningOfLifeAsString(wxStringBuffer(theAnswer, 1024));
1567 if ( theAnswer != "42" )
1568 wxLogError("Something is very wrong!");
1569 @endcode
1570
1571 Note that the exact usage of this depends on whether or not @c wxUSE_STL is
1572 enabled. If @c wxUSE_STL is enabled, wxStringBuffer creates a separate empty
1573 character buffer, and if @c wxUSE_STL is disabled, it uses GetWriteBuf() from
1574 wxString, keeping the same buffer wxString uses intact. In other words,
1575 relying on wxStringBuffer containing the old wxString data is not a good
1576 idea if you want to build your program both with and without @c wxUSE_STL.
1577
1578 @library{wxbase}
1579 @category{data}
1580*/
1581class wxStringBuffer
1582{
1583public:
1584 /**
1585 Constructs a writable string buffer object associated with the given string
1586 and containing enough space for at least @a len characters.
1587 Basically, this is equivalent to calling wxString::GetWriteBuf() and
1588 saving the result.
1589 */
1590 wxStringBuffer(const wxString& str, size_t len);
1591
1592 /**
1593 Restores the string passed to the constructor to the usable state by calling
1594 wxString::UngetWriteBuf() on it.
1595 */
1596 ~wxStringBuffer();
1597
1598 /**
1599 Returns the writable pointer to a buffer of the size at least equal to the
1600 length specified in the constructor.
1601 */
1602 wxStringCharType* operator wxStringCharType *();
1603};
cbec0f40
FM
1604
1605
1606/** @addtogroup group_funcmacro_string */
1607//@{
1608
1609/**
1610 Allows to extend a function with the signature:
1611 @code bool SomeFunc(const wxUniChar& c) @endcode
1612 which operates on a single character, to an entire wxString.
1613
1614 E.g. if you want to check if an entire string contains only digits,
1615 you can do:
1616 @code
1617 if (wxStringCheck<wxIsdigit>(myString))
1618 ... // the entire string contains oly digits!
1619 else
1620 ... // at least one character of myString is not a digit
1621 @endcode
1622
1623 @return @true if the given function returns a non-zero value for all
1624 characters of the @a val string.
1625*/
1626template<bool (T)(const wxUniChar& c)>
413eac73 1627 inline bool wxStringCheck(const wxString& val);
cbec0f40
FM
1628
1629//@}