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