]>
git.saurik.com Git - wxWidgets.git/blob - interface/string.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: documentation for wxStringBuffer class
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
13 This tiny class allows to conveniently access the wxString
14 internal buffer as a writable pointer without any risk of forgetting to restore
15 the string to the usable state later.
17 For example, assuming you have a low-level OS function called
18 @c GetMeaningOfLifeAsString(char *) returning the value in the provided
19 buffer (which must be writable, of course) you might call it like this:
23 GetMeaningOfLifeAsString(wxStringBuffer(theAnswer, 1024));
24 if ( theAnswer != "42" )
26 wxLogError("Something is very wrong!");
30 Note that the exact usage of this depends on whether on not wxUSE_STL is
32 wxUSE_STL is enabled, wxStringBuffer creates a separate empty character buffer,
34 if wxUSE_STL is disabled, it uses GetWriteBuf() from wxString, keeping the same
36 wxString uses intact. In other words, relying on wxStringBuffer containing the
38 wxString data is probably not a good idea if you want to build your program in
40 with and without wxUSE_STL.
49 Constructs a writable string buffer object associated with the given string
50 and containing enough space for at least @e len characters. Basically, this
51 is equivalent to calling wxString::GetWriteBuf and
54 wxStringBuffer(const wxString
& str
, size_t len
);
57 Restores the string passed to the constructor to the usable state by calling
58 wxString::UngetWriteBuf on it.
63 Returns the writable pointer to a buffer of the size at least equal to the
64 length specified in the constructor.
66 wxChar
* operator wxChar
*();
74 wxString is a class representing a character string. Please see the
75 @ref overview_wxstringoverview "wxString overview" for more information about
78 As explained there, wxString implements most of the methods of the std::string
80 These standard functions are not documented in this manual, please see the
82 The behaviour of all these functions is identical to the behaviour described
85 You may notice that wxString sometimes has many functions which do the same
86 thing like, for example, wxString::Length,
87 wxString::Len and @c length() which all return the string
88 length. In all cases of such duplication the @c std::string-compatible
89 method (@c length() in this case, always the lowercase version) should be
90 used as it will ensure smoother transition to @c std::string when wxWidgets
91 starts using it instead of wxString.
101 @ref overview_wxstringoverview "wxString overview", @ref overview_unicode
109 Initializes the string from first @e nLength characters of C string.
110 The default value of @c wxSTRING_MAXLEN means take all the string.
111 In Unicode build, @e conv's
112 wxMBConv::MB2WC method is called to
113 convert @e psz to wide string (the default converter uses current locale's
114 charset). It is ignored in ANSI build.
116 @sa @ref overview_mbconvclasses "wxMBConv classes", @ref mbstr()
117 mb_str, @ref wcstr() wc_str
120 wxString(const wxString
& x
);
121 wxString(wxChar ch
, size_t n
= 1);
122 wxString(const wxChar
* psz
, size_t nLength
= wxSTRING_MAXLEN
);
123 wxString(const unsigned char* psz
,
124 size_t nLength
= wxSTRING_MAXLEN
);
125 wxString(const wchar_t* psz
, const wxMBConv
& conv
,
126 size_t nLength
= wxSTRING_MAXLEN
);
127 wxString(const char* psz
, const wxMBConv
& conv
= wxConvLibc
,
128 size_t nLength
= wxSTRING_MAXLEN
);
132 String destructor. Note that this is not virtual, so wxString must not be
138 Gets all the characters after the first occurrence of @e ch.
139 Returns the empty string if @e ch is not found.
141 wxString
AfterFirst(wxChar ch
);
144 Gets all the characters after the last occurrence of @e ch.
145 Returns the whole string if @e ch is not found.
147 wxString
AfterLast(wxChar ch
);
150 Preallocate enough space for wxString to store @e nLen characters. This function
151 may be used to increase speed when the string is constructed by repeated
153 because it will avoid the need to reallocate string memory many times (in case
154 of long strings). Note that it does not set the maximal length of a string - it
155 will still expand if more than @e nLen characters are stored in it. Also, it
156 does not truncate the existing string (use
157 Truncate() for this) even if its current length is
160 void Alloc(size_t nLen
);
164 Concatenates character @e ch to this string, @e count times, returning a
168 wxString
Append(const wxChar
* psz
);
169 wxString
Append(wxChar ch
, int count
= 1);
173 Gets all characters before the first occurrence of @e ch.
174 Returns the whole string if @e ch is not found.
176 wxString
BeforeFirst(wxChar ch
);
179 Gets all characters before the last occurrence of @e ch.
180 Returns the empty string if @e ch is not found.
182 wxString
BeforeLast(wxChar ch
);
185 The MakeXXX() variants modify the string in place, while the other functions
186 return a new string which contains the original text converted to the upper or
187 lower case and leave the original string unchanged.
200 Many functions in this section take a character index in the string. As with C
201 strings and/or arrays, the indices start from 0, so the first character of a
202 string is string[0]. Attempt to access a character beyond the end of the
203 string (which may be even 0 if the string is empty) will provoke an assert
204 failure in @ref overview_debuggingoverview "debug build", but no checks are
208 This section also contains both implicit and explicit conversions to C style
209 strings. Although implicit conversion is quite convenient, it is advised to use
210 explicit @ref cstr() c_str method for the sake of clarity. Also
211 see overview for the cases where it is necessary to
222 @ref operatorbracket() "operator []"
232 @ref operatorconstcharpt() "operator const char*"
237 Empties the string and frees memory occupied by it.
245 Case-sensitive comparison.
247 Returns a positive value if the string is greater than the argument, zero if
248 it is equal to it or a negative value if it is less than the argument (same
250 as the standard @e strcmp() function).
252 See also CmpNoCase(), IsSameAs().
254 int Cmp(const wxString
& s
);
255 int Cmp(const wxChar
* psz
);
260 Case-insensitive comparison.
262 Returns a positive value if the string is greater than the argument, zero if
263 it is equal to it or a negative value if it is less than the argument (same
265 as the standard @e strcmp() function).
267 See also Cmp(), IsSameAs().
269 int CmpNoCase(const wxString
& s
);
270 int CmpNoCase(const wxChar
* psz
);
274 Case-sensitive comparison. Returns 0 if equal, 1 if greater or -1 if less.
276 This is a wxWidgets 1.xx compatibility function; use Cmp() instead.
278 int CompareTo(const wxChar
* psz
, caseCompare cmp
= exact
);
281 The default comparison function Cmp() is case-sensitive and
282 so is the default version of IsSameAs(). For case
283 insensitive comparisons you should use CmpNoCase() or
284 give a second parameter to IsSameAs. This last function is may be more
285 convenient if only equality of the strings matters because it returns a boolean
286 @true value if the strings are the same and not 0 (which is usually @false in
290 Matches() is a poor man's regular expression matcher:
291 it only understands '*' and '?' metacharacters in the sense of DOS command line
294 StartsWith() is helpful when parsing a line of
295 text which should start with some predefined prefix and is more efficient than
296 doing direct string comparison as you would also have to precalculate the
297 length of the prefix then.
317 bool operator ==(const wxString
& x
, const wxString
& y
);
318 bool operator ==(const wxString
& x
, const wxChar
* t
);
319 bool operator !=(const wxString
& x
, const wxString
& y
);
320 bool operator !=(const wxString
& x
, const wxChar
* t
);
321 bool operator(const wxString
& x
, const wxString
& y
);
322 bool operator(const wxString
& x
, const wxChar
* t
);
323 bool operator =(const wxString
& x
, const wxString
& y
);
324 bool operator =(const wxString
& x
, const wxChar
* t
);
325 bool operator(const wxString
& x
, const wxString
& y
);
326 bool operator(const wxString
& x
, const wxChar
* t
);
327 bool operator =(const wxString
& x
, const wxString
& y
);
328 bool operator =(const wxString
& x
, const wxChar
* t
);
332 Anything may be concatenated (appended to) with a string. However, you can't
333 append something to a C string (including literal constants), so to do this it
334 should be converted to a wxString first.
336 @ref operatorout() "operator "
338 @ref plusequal() "operator +="
340 @ref operatorplus() "operator +"
349 A string may be constructed either from a C string, (some number of copies of)
350 a single character or a wide (UNICODE) string. For all constructors (except the
351 default which creates an empty string) there is also a corresponding assignment
354 @ref construct() wxString
356 @ref operatorassign() "operator ="
358 @ref destruct() ~wxString
363 Returns @true if target appears anywhere in wxString; else @false.
365 This is a wxWidgets 1.xx compatibility function; you should not use it in new
368 bool Contains(const wxString
& str
);
371 The string provides functions for conversion to signed and unsigned integer and
372 floating point numbers. All three functions take a pointer to the variable to
373 put the numeric value in and return @true if the @b entire string could be
374 converted to a number.
389 Makes the string empty, but doesn't free memory occupied by the string.
396 This function can be used to test if the string ends with the specified
397 @e suffix. If it does, the function will return @true and put the
398 beginning of the string before the suffix into @e rest string if it is not
399 @NULL. Otherwise, the function returns @false and doesn't
402 bool EndsWith(const wxString
& suffix
, wxString rest
= @NULL
);
406 Searches for the given string. Returns the starting index, or @c wxNOT_FOUND if
409 int Find(wxUniChar ch
, bool fromEnd
= @
false);
410 int Find(const wxString
& sub
);
417 This is a wxWidgets 1.xx compatibility function; you should not use it in new
421 int First(const wxChar
* psz
);
422 int First(const wxString
& str
);
426 This static function returns the string containing the result of calling
427 Printf() with the passed parameters on it.
429 @sa FormatV(), Printf()
431 static wxString
Format(const wxChar format
, ...);
434 This static function returns the string containing the result of calling
435 PrintfV() with the passed parameters on it.
437 @sa Format(), PrintfV()
439 static wxString
FormatV(const wxChar format
, va_list argptr
);
442 Returns the number of occurrences of @e ch in the string.
444 This is a wxWidgets 1.xx compatibility function; you should not use it in new
451 Converts given buffer of binary data from 8-bit string to wxString. In Unicode
452 build, the string is interpreted as being in ISO-8859-1 encoding. The version
453 without @e len parameter takes NUL-terminated data.
455 This is a convenience method useful when storing binary data in wxString.
457 This function is new since wxWidgets version 2.8.4
459 @sa wxString::To8BitData
461 static wxString
From8BitData(const char* buf
, size_t len
);
462 static wxString
From8BitData(const char* buf
);
467 Converts the string or character from an ASCII, 7-bit form
468 to the native wxString representation. Most useful when using
469 a Unicode build of wxWidgets (note the use of @c char instead of @c wxChar).
470 Use @ref construct() "wxString constructors" if you
471 need to convert from another charset.
473 static wxString
FromAscii(const char* s
);
474 static wxString
FromAscii(const unsigned char* s
);
475 static wxString
FromAscii(const char* s
, size_t len
);
476 static wxString
FromAscii(const unsigned char* s
, size_t len
);
477 static wxString
FromAscii(char c
);
482 Converts C string encoded in UTF-8 to wxString.
484 Note that this method assumes that @e s is a valid UTF-8 sequence and
485 doesn't do any validation in release builds, it's validity is only checked in
488 static wxString
FromUTF8(const char* s
);
489 static wxString
FromUTF8(const char* s
, size_t len
);
493 Returns the character at position @e n (read-only).
495 wxChar
GetChar(size_t n
);
498 wxWidgets compatibility conversion. Returns a constant pointer to the data in
501 const wxChar
* GetData();
504 Returns a reference to the character at position @e n.
506 wxChar
GetWritableChar(size_t n
);
509 Returns a writable buffer of at least @e len bytes.
510 It returns a pointer to a new memory block, and the
511 existing data will not be copied.
513 Call UngetWriteBuf() as soon as
514 possible to put the string back into a reasonable state.
516 This method is deprecated, please use
518 wxStringBufferLength instead.
520 wxChar
* GetWriteBuf(size_t len
);
526 This is a wxWidgets 1.xx compatibility function; you should not use it in new
529 size_t Index(wxChar ch
);
530 size_t Index(const wxChar
* sz
);
534 Returns @true if the string contains only ASCII characters.
536 This is a wxWidgets 1.xx compatibility function; you should not use it in new
542 Returns @true if the string is empty.
547 Returns @true if the string is empty (same as wxString::IsEmpty).
549 This is a wxWidgets 1.xx compatibility function; you should not use it in new
555 Returns @true if the string is an integer (with possible sign).
557 This is a wxWidgets 1.xx compatibility function; you should not use it in new
564 Test whether the string is equal to the single character @e c. The test is
565 case-sensitive if @e caseSensitive is @true (default) or not if it is @c
568 Returns @true if the string is equal to the character, @false otherwise.
570 See also Cmp(), CmpNoCase()
572 bool IsSameAs(const wxChar
* psz
, bool caseSensitive
= @
true);
573 bool IsSameAs(wxChar c
, bool caseSensitive
= @
true);
577 Returns @true if the string is a word.
579 This is a wxWidgets 1.xx compatibility function; you should not use it in new
586 Returns a reference to the last character (writable).
588 This is a wxWidgets 1.xx compatibility function; you should not use it in new
596 Returns the first @e count characters of the string.
598 wxString
Left(size_t count
);
601 Returns the length of the string.
603 #define size_t Len() /* implementation is private */
606 Returns the length of the string (same as Len).
608 This is a wxWidgets 1.xx compatibility function; you should not use it in new
614 Returns this string converted to the lower case.
621 This is a wxWidgets 1.xx compatibility function; you should not use it in new
627 Converts all characters to lower case and returns the result.
629 wxString
MakeLower();
632 Converts all characters to upper case and returns the result.
634 wxString
MakeUpper();
637 Returns @true if the string contents matches a mask containing '*' and '?'.
639 bool Matches(const wxString
& mask
);
642 These are "advanced" functions and they will be needed quite rarely.
643 Alloc() and Shrink() are only
644 interesting for optimization purposes.
646 and wxStringBufferLength classes may be very
647 useful when working with some external API which requires the caller to provide
661 Returns a substring starting at @e first, with length @e count, or the rest of
662 the string if @e count is the default value.
664 #define wxString Mid(size_t first, size_t count = wxSTRING_MAXLEN) /* implementation is private */
667 Other string functions.
678 Adds @e count copies of @e pad to the beginning, or to the end of the string
681 Removes spaces from the left or from the right (default).
683 #define wxString Pad(size_t count, wxChar pad = ' ',
684 bool fromRight
= @
true) /* implementation is private */
687 Prepends @e str to this string, returning a reference to this string.
689 wxString
Prepend(const wxString
& str
);
692 Similar to the standard function @e sprintf(). Returns the number of
693 characters written, or an integer less than zero on error.
695 Note that if @c wxUSE_PRINTF_POS_PARAMS is set to 1, then this function supports
696 Unix98-style positional parameters:
697 @b NB: This function will use a safe version of @e vsprintf() (usually called
698 @e vsnprintf()) whenever available to always allocate the buffer of correct
699 size. Unfortunately, this function is not available on all platforms and the
700 dangerous @e vsprintf() will be used then which may lead to buffer overflows.
702 int Printf(const wxChar
* pszFormat
, ...);
705 Similar to vprintf. Returns the number of characters written, or an integer
709 int PrintfV(const wxChar
* pszFormat
, va_list argPtr
);
713 Removes @e len characters from the string, starting at @e pos.
715 This is a wxWidgets 1.xx compatibility function; you should not use it in new
718 wxString
Remove(size_t pos
);
719 wxString
Remove(size_t pos
, size_t len
);
723 Removes the last character.
725 wxString
RemoveLast();
728 Replace first (or all) occurrences of substring with another one.
730 @e replaceAll: global replace (default), or only the first occurrence.
732 Returns the number of replacements made.
734 size_t Replace(const wxString
& strOld
, const wxString
& strNew
,
735 bool replaceAll
= @
true);
738 Returns the last @e count characters.
740 wxString
Right(size_t count
);
743 These functions replace the standard @e strchr() and @e strstr()
753 Sets the character at position @e n.
755 void SetChar(size_t n
, wxChar ch
);
758 Minimizes the string's memory. This can be useful after a call to
759 Alloc() if too much memory were preallocated.
764 This function can be used to test if the string starts with the specified
765 @e prefix. If it does, the function will return @true and put the rest
766 of the string (i.e. after the prefix) into @e rest string if it is not
767 @NULL. Otherwise, the function returns @false and doesn't modify the
770 bool StartsWith(const wxString
& prefix
, wxString rest
= @NULL
);
773 These functions return the string length and check whether the string is empty
780 @ref operatornot() operator!
789 Strip characters at the front and/or end. The same as Trim except that it
790 doesn't change this string.
792 This is a wxWidgets 1.xx compatibility function; you should not use it in new
795 wxString
Strip(stripType s
= trailing
);
798 Returns the part of the string between the indices @e from and @e to
801 This is a wxWidgets 1.xx compatibility function, use Mid()
802 instead (but note that parameters have different meaning).
804 wxString
SubString(size_t from
, size_t to
);
807 These functions allow to extract substring from this string. All of them don't
808 modify the original string and return a new string containing the extracted
813 @ref operatorparenth() operator
835 Converts the string to an 8-bit string in ISO-8859-1 encoding in the form of
836 a wxCharBuffer (Unicode builds only).
838 This is a convenience method useful when storing binary data in wxString.
840 This function is new since wxWidgets version 2.8.4
842 @sa wxString::From8BitData
844 const char* To8BitData();
845 const wxCharBuffer
To8BitData();
850 Converts the string to an ASCII, 7-bit string in the form of
851 a wxCharBuffer (Unicode builds only) or a C string (ANSI builds).
853 Note that this conversion only works if the string contains only ASCII
854 characters. The @ref mbstr() mb_str method provides more
855 powerful means of converting wxString to C string.
857 const char* ToAscii();
858 const wxCharBuffer
ToAscii();
862 Attempts to convert the string to a floating point number. Returns @true on
863 success (the number is stored in the location pointed to by @e val) or @false
864 if the string does not represent such number (the value of @e val is not
865 modified in this case).
867 @sa ToLong(), ToULong()
869 bool ToDouble(double val
);
872 Attempts to convert the string to a signed integer in base @e base. Returns
873 @true on success in which case the number is stored in the location
874 pointed to by @e val or @false if the string does not represent a
875 valid number in the given base (the value of @e val is not modified
878 The value of @e base must be comprised between 2 and 36, inclusive, or
879 be a special value 0 which means that the usual rules of @c C numbers are
880 applied: if the number starts with @c 0x it is considered to be in base
881 16, if it starts with @c 0 - in base 8 and in base 10 otherwise. Note
882 that you may not want to specify the base 0 if you are parsing the numbers
883 which may have leading zeroes as they can yield unexpected (to the user not
884 familiar with C) results.
886 @sa ToDouble(), ToULong()
888 bool ToLong(long val
, int base
= 10);
891 This is exactly the same as ToLong() but works with 64
894 Notice that currently it doesn't work (always returns @false) if parsing of 64
895 bit numbers is not supported by the underlying C run-time library. Compilers
896 with C99 support and Microsoft Visual C++ version 7 and higher do support this.
898 @sa ToLong(), ToULongLong()
900 bool ToLongLong(wxLongLong_t val
, int base
= 10);
903 Attempts to convert the string to an unsigned integer in base @e base.
904 Returns @true on success in which case the number is stored in the
905 location pointed to by @e val or @false if the string does not
906 represent a valid number in the given base (the value of @e val is not
907 modified in this case). Please notice that this function
908 behaves in the same way as the standard @c strtoul() and so it simply
909 converts negative numbers to unsigned representation instead of rejecting them
910 (e.g. -1 is returned as @c ULONG_MAX).
912 See ToLong() for the more detailed
913 description of the @e base parameter.
915 @sa ToDouble(), ToLong()
917 bool ToULong(unsigned long val
, int base
= 10);
920 This is exactly the same as ToULong() but works with 64
923 Please see ToLongLong() for additional remarks.
925 bool ToULongLong(wxULongLong_t val
, int base
= 10);
929 Same as @ref wxString::utf8str utf8_str.
931 const char* ToUTF8();
932 const wxCharBuffer
ToUF8();
936 Removes white-space (space, tabs, form feed, newline and carriage return) from
937 the left or from the right end of the string (right is default).
939 wxString
Trim(bool fromRight
= @
true);
942 Truncate the string to the given length.
944 wxString
Truncate(size_t len
);
948 Puts the string back into a reasonable state (in which it can be used
950 GetWriteBuf() was called.
952 The version of the function without the @e len parameter will calculate the
953 new string length itself assuming that the string is terminated by the first
954 @c NUL character in it while the second one will use the specified length
955 and thus is the only version which should be used with the strings with
956 embedded @c NULs (it is also slightly more efficient as @c strlen()
957 doesn't have to be called).
959 This method is deprecated, please use
961 wxStringBufferLength instead.
963 void UngetWriteBuf();
964 void UngetWriteBuf(size_t len
);
968 Returns this string converted to upper case.
973 The same as MakeUpper.
975 This is a wxWidgets 1.xx compatibility function; you should not use it in new
981 Both formatted versions (wxString::Printf) and stream-like
982 insertion operators exist (for basic types only). Additionally, the
983 Format() function allows to use simply append
984 formatted value to a string:
993 @ref operatorout() "operator "
998 Returns a pointer to the string data (@c const char* in ANSI build,
999 @c const wchar_t* in Unicode build).
1001 Note that the returned value is not convertible to @c char* or
1002 @c wchar_t*, use @ref charstr() char_str or
1003 @ref wcharstr() wchar_string if you need to pass string value
1004 to a function expecting non-const pointer.
1006 @sa @ref mbstr() mb_str, @ref wcstr() wc_str, @ref
1007 fnstr() fn_str, @ref charstr() char_str, @ref
1008 wcharstr() wchar_string
1010 const wxChar
* c_str();
1013 Returns an object with string data that is implicitly convertible to
1014 @c char* pointer. Note that any change to the returned buffer is lost and so
1015 this function is only usable for passing strings to legacy libraries that
1016 don't have const-correct API. Use wxStringBuffer if
1017 you want to modify the string.
1019 @sa @ref mbstr() mb_str, @ref wcstr() wc_str, @ref
1020 fnstr() fn_str, @ref cstr() c_str, @ref
1021 wcharstr() wchar_str
1023 wxWritableCharBuffer
char_str(const wxMBConv
& conv
= wxConvLibc
);
1027 Returns string representation suitable for passing to OS' functions for
1028 file handling. In ANSI build, this is same as @ref cstr() c_str.
1029 In Unicode build, returned value can be either wide character string
1030 or C string in charset matching the @c wxConvFileName object, depending on
1033 @sa wxMBConv, @ref wcstr() wc_str, @ref wcstr() mb_str
1035 const wchar_t* fn_str();
1036 const char* fn_str();
1037 const wxCharBuffer
fn_str();
1042 Returns multibyte (C string) representation of the string.
1043 In Unicode build, converts using @e conv's wxMBConv::cWC2MB
1044 method and returns wxCharBuffer. In ANSI build, this function is same
1045 as @ref cstr() c_str.
1046 The macro wxWX2MBbuf is defined as the correct return type (without const).
1048 @sa wxMBConv, @ref cstr() c_str, @ref wcstr() wc_str, @ref
1049 fnstr() fn_str, @ref charstr() char_str
1051 const char* mb_str(const wxMBConv
& conv
= wxConvLibc
);
1052 const wxCharBuffer
mb_str(const wxMBConv
& conv
= wxConvLibc
);
1056 Extraction from a stream.
1058 friend istream
operator(istream
& is
, wxString
& str
);
1062 These functions work as C++ stream insertion operators: they insert the given
1063 value into the string. Precision or format cannot be set using them, you can
1067 wxString
operator(const wxString
& str
);
1068 wxString
operator(const wxChar
* psz
);
1069 wxString
operator(wxChar ch
);
1070 wxString
operator(int i
);
1071 wxString
operator(float f
);
1072 wxString
operator(double d
);
1076 Same as Mid (substring extraction).
1078 wxString
operator ()(size_t start
, size_t len
);
1082 Concatenation: all these operators return a new string equal to the
1083 concatenation of the operands.
1085 wxString
operator +(const wxString
& x
, const wxString
& y
);
1086 wxString
operator +(const wxString
& x
, const wxChar
* y
);
1087 wxString
operator +(const wxString
& x
, wxChar y
);
1088 wxString
operator +(const wxChar
* x
, const wxString
& y
);
1093 Concatenation in place: the argument is appended to the string.
1095 void operator +=(const wxString
& str
);
1096 void operator +=(const wxChar
* psz
);
1097 void operator +=(wxChar c
);
1102 Assignment: the effect of each operation is the same as for the corresponding
1103 constructor (see @ref construct() "wxString constructors").
1105 wxString
operator =(const wxString
& str
);
1106 wxString
operator =(const wxChar
* psz
);
1107 wxString
operator =(wxChar c
);
1114 wxChar
operator [](size_t i
);
1115 wxChar
operator [](size_t i
);
1116 wxChar
operator [](int i
);
1117 wxChar
operator [](int i
);
1121 Implicit conversion to a C string.
1123 operator const wxChar
*();
1126 Empty string is @false, so !string will only return @true if the string is
1128 This allows the tests for @NULLness of a @e const wxChar * pointer and emptiness
1129 of the string to look the same in the code and makes it easier to port old code
1137 The supported functions are only listed here, please see any STL reference for
1138 their documentation.
1144 Converts the strings contents to UTF-8 and returns it either as a temporary
1145 wxCharBuffer object or as a pointer to the internal string contents in
1148 const char* utf8_str();
1149 const wxCharBuffer
utf8_str();
1154 Returns wide character representation of the string.
1155 In ANSI build, converts using @e conv's wxMBConv::cMB2WC
1156 method and returns wxWCharBuffer. In Unicode build, this function is same
1157 as @ref cstr() c_str.
1158 The macro wxWX2WCbuf is defined as the correct return type (without const).
1160 @sa wxMBConv, @ref cstr() c_str, @ref wcstr() mb_str, @ref
1161 fnstr() fn_str, @ref wcharstr() wchar_str
1163 const wchar_t* wc_str(const wxMBConv
& conv
);
1164 const wxWCharBuffer
wc_str(const wxMBConv
& conv
);
1168 Returns an object with string data that is implicitly convertible to
1169 @c char* pointer. Note that changes to the returned buffer may or may
1170 not be lost (depending on the build) and so this function is only usable for
1171 passing strings to legacy libraries that don't have const-correct API. Use
1172 wxStringBuffer if you want to modify the string.
1174 @sa @ref mbstr() mb_str, @ref wcstr() wc_str, @ref
1175 fnstr() fn_str, @ref cstr() c_str, @ref
1178 wxWritableWCharBuffer
wchar_str();
1181 These functions are deprecated, please consider using new wxWidgets 2.0
1182 functions instead of them (or, even better, std::string compatible variants).
1220 @class wxStringBufferLength
1223 This tiny class allows to conveniently access the wxString
1224 internal buffer as a writable pointer without any risk of forgetting to restore
1225 the string to the usable state later, and allows the user to set the internal
1226 length of the string.
1228 For example, assuming you have a low-level OS function called
1229 @c int GetMeaningOfLifeAsString(char *) copying the value in the provided
1230 buffer (which must be writable, of course), and returning the actual length
1231 of the string, you might call it like this:
1235 wxStringBuffer theAnswerBuffer(theAnswer, 1024);
1236 int nLength = GetMeaningOfLifeAsString(theAnswerBuffer);
1237 theAnswerBuffer.SetLength(nLength);
1238 if ( theAnswer != "42" )
1240 wxLogError("Something is very wrong!");
1244 Note that the exact usage of this depends on whether on not wxUSE_STL is
1246 wxUSE_STL is enabled, wxStringBuffer creates a separate empty character buffer,
1248 if wxUSE_STL is disabled, it uses GetWriteBuf() from wxString, keeping the same
1250 wxString uses intact. In other words, relying on wxStringBuffer containing the
1252 wxString data is probably not a good idea if you want to build your program in
1254 with and without wxUSE_STL.
1256 Note that SetLength @c must be called before wxStringBufferLength destructs.
1261 class wxStringBufferLength
1265 Constructs a writable string buffer object associated with the given string
1266 and containing enough space for at least @e len characters. Basically, this
1267 is equivalent to calling wxString::GetWriteBuf and
1270 wxStringBufferLength(const wxString
& str
, size_t len
);
1273 Restores the string passed to the constructor to the usable state by calling
1274 wxString::UngetWriteBuf on it.
1276 ~wxStringBufferLength();
1279 Sets the internal length of the string referred to by wxStringBufferLength to
1280 @e nLength characters.
1282 Must be called before wxStringBufferLength destructs.
1284 void SetLength(size_t nLength
);
1287 Returns the writable pointer to a buffer of the size at least equal to the
1288 length specified in the constructor.
1290 wxChar
* operator wxChar
*();
1294 // ============================================================================
1295 // Global functions/macros
1296 // ============================================================================
1300 Converts its argument to string.
1301 See also: wxFromString.
1303 wxString
wxToString(const wxColour
& col
);
1304 wxString
wxToString(const wxFont
& col
);
1309 Converts string to the type of the second argument. Returns @true on success.
1310 See also: wxToString.
1312 bool wxFromString(const wxString
& str
, wxColour
* col
);
1313 bool wxFromString(const wxString
& str
, wxFont
* col
);