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