]>
git.saurik.com Git - wxWidgets.git/blob - interface/string.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxStringBuffer
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 @a 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
*();
75 wxString is a class representing a character string. Please see the
76 @ref overview_wxstringoverview "wxString overview" for more information about
79 As explained there, wxString implements most of the methods of the std::string
81 These standard functions are not documented in this manual, please see the
83 The behaviour of all these functions is identical to the behaviour described
86 You may notice that wxString sometimes has many functions which do the same
87 thing like, for example, wxString::Length,
88 wxString::Len and @c length() which all return the string
89 length. In all cases of such duplication the @c std::string-compatible
90 method (@c length() in this case, always the lowercase version) should be
91 used as it will ensure smoother transition to @c std::string when wxWidgets
92 starts using it instead of wxString.
98 ::Objects:, ::wxEmptyString,
100 @see @ref overview_wxstringoverview "wxString overview", @ref overview_unicode
108 Initializes the string from first @a nLength characters of C string.
109 The default value of @c wxSTRING_MAXLEN means take all the string.
110 In Unicode build, @e conv's
111 wxMBConv::MB2WC method is called to
112 convert @a psz to wide string (the default converter uses current locale's
113 charset). It is ignored in ANSI build.
115 @see @ref overview_mbconvclasses "wxMBConv classes", @ref mbstr()
116 mb_str, @ref wcstr() wc_str
119 wxString(const wxString
& x
);
120 wxString(wxChar ch
, size_t n
= 1);
121 wxString(const wxChar
* psz
, size_t nLength
= wxSTRING_MAXLEN
);
122 wxString(const unsigned char* psz
,
123 size_t nLength
= wxSTRING_MAXLEN
);
124 wxString(const wchar_t* psz
, const wxMBConv
& conv
,
125 size_t nLength
= wxSTRING_MAXLEN
);
126 wxString(const char* psz
, const wxMBConv
& conv
= wxConvLibc
,
127 size_t nLength
= wxSTRING_MAXLEN
);
131 String destructor. Note that this is not virtual, so wxString must not be
137 Gets all the characters after the first occurrence of @e ch.
138 Returns the empty string if @a ch is not found.
140 wxString
AfterFirst(wxChar ch
) const;
143 Gets all the characters after the last occurrence of @e ch.
144 Returns the whole string if @a ch is not found.
146 wxString
AfterLast(wxChar ch
) const;
149 Preallocate enough space for wxString to store @a nLen characters.
151 Please note that this method does the same thing as the standard
152 reserve() one and shouldn't be used in new code.
154 This function may be used to increase speed when the string is
155 constructed by repeated concatenation as in
158 // delete all vowels from the string
159 wxString DeleteAllVowels(const wxString& original)
163 size_t len = original.length();
167 for ( size_t n = 0; n < len; n++ )
169 if ( strchr("aeuio", tolower(original[n])) == NULL )
170 result += original[n];
177 because it will avoid the need to reallocate string memory many times
178 (in case of long strings). Note that it does not set the maximal length
179 of a string -- it will still expand if more than @a nLen characters are
180 stored in it. Also, it does not truncate the existing string (use
181 Truncate() for this) even if its current length is greater than @a nLen.
183 @return @true if memory was successfully allocated, @false otherwise.
185 bool Alloc(size_t nLen
);
189 Concatenates character @a ch to this string, @a count times, returning a
193 wxString
Append(const wxChar
* psz
);
194 wxString
Append(wxChar ch
, int count
= 1);
198 Gets all characters before the first occurrence of @e ch.
199 Returns the whole string if @a ch is not found.
201 wxString
BeforeFirst(wxChar ch
) const;
204 Gets all characters before the last occurrence of @e ch.
205 Returns the empty string if @a ch is not found.
207 wxString
BeforeLast(wxChar ch
) const;
210 The MakeXXX() variants modify the string in place, while the other functions
211 return a new string which contains the original text converted to the upper or
212 lower case and leave the original string unchanged.
224 Many functions in this section take a character index in the string. As with C
225 strings and/or arrays, the indices start from 0, so the first character of a
226 string is string[0]. Attempt to access a character beyond the end of the
227 string (which may be even 0 if the string is empty) will provoke an assert
228 failure in @ref overview_debuggingoverview "debug build", but no checks are
231 This section also contains both implicit and explicit conversions to C style
232 strings. Although implicit conversion is quite convenient, it is advised to use
233 explicit @ref cstr() c_str method for the sake of clarity. Also
234 see overview() for the cases where it is necessary to
244 @ref operatorbracket() "operator []"
254 @ref operatorconstcharpt() "operator const char*"
259 Empties the string and frees memory occupied by it.
266 Case-sensitive comparison.
267 Returns a positive value if the string is greater than the argument, zero if
268 it is equal to it or a negative value if it is less than the argument (same
270 as the standard @e strcmp() function).
271 See also CmpNoCase(), IsSameAs().
273 int Cmp(const wxString
& s
) const;
274 const int Cmp(const wxChar
* psz
) const;
279 Case-insensitive comparison.
280 Returns a positive value if the string is greater than the argument, zero if
281 it is equal to it or a negative value if it is less than the argument (same
283 as the standard @e strcmp() function).
284 See also Cmp(), IsSameAs().
286 int CmpNoCase(const wxString
& s
) const;
287 const int CmpNoCase(const wxChar
* psz
) const;
291 Case-sensitive comparison. Returns 0 if equal, 1 if greater or -1 if less.
292 This is a wxWidgets 1.xx compatibility function; use Cmp() instead.
294 int CompareTo(const wxChar
* psz
, caseCompare cmp
= exact
) const;
297 The default comparison function Cmp() is case-sensitive and
298 so is the default version of IsSameAs(). For case
299 insensitive comparisons you should use CmpNoCase() or
300 give a second parameter to IsSameAs. This last function is may be more
301 convenient if only equality of the strings matters because it returns a boolean
302 @true value if the strings are the same and not 0 (which is usually @false in
305 Matches() is a poor man's regular expression matcher:
306 it only understands '*' and '?' metacharacters in the sense of DOS command line
308 StartsWith() is helpful when parsing a line of
309 text which should start with some predefined prefix and is more efficient than
310 doing direct string comparison as you would also have to precalculate the
311 length of the prefix then.
330 bool operator ==(const wxString
& x
, const wxString
& y
);
331 bool operator ==(const wxString
& x
, const wxChar
* t
);
332 bool operator !=(const wxString
& x
, const wxString
& y
);
333 bool operator !=(const wxString
& x
, const wxChar
* t
);
334 bool operator(const wxString
& x
, const wxString
& y
);
335 bool operator(const wxString
& x
, const wxChar
* t
);
336 bool operator =(const wxString
& x
, const wxString
& y
);
337 bool operator =(const wxString
& x
, const wxChar
* t
);
338 bool operator(const wxString
& x
, const wxString
& y
);
339 bool operator(const wxString
& x
, const wxChar
* t
);
340 bool operator =(const wxString
& x
, const wxString
& y
);
341 bool operator =(const wxString
& x
, const wxChar
* t
);
345 Anything may be concatenated (appended to) with a string. However, you can't
346 append something to a C string (including literal constants), so to do this it
347 should be converted to a wxString first.
348 @ref operatorout() "operator "
350 @ref plusequal() "operator +="
352 @ref operatorplus() "operator +"
361 A string may be constructed either from a C string, (some number of copies of)
362 a single character or a wide (UNICODE) string. For all constructors (except the
363 default which creates an empty string) there is also a corresponding assignment
365 @ref construct() wxString
367 @ref operatorassign() "operator ="
369 @ref destruct() ~wxString
374 Returns @true if target appears anywhere in wxString; else @false.
375 This is a wxWidgets 1.xx compatibility function; you should not use it in new
378 bool Contains(const wxString
& str
) const;
381 The string provides functions for conversion to signed and unsigned integer and
382 floating point numbers. All three functions take a pointer to the variable to
383 put the numeric value in and return @true if the @b entire string could be
384 converted to a number.
398 Makes the string empty, but doesn't free memory occupied by the string.
404 This function can be used to test if the string ends with the specified
405 @e suffix. If it does, the function will return @true and put the
406 beginning of the string before the suffix into @a rest string if it is not
407 @NULL. Otherwise, the function returns @false and doesn't
410 bool EndsWith(const wxString
& suffix
, wxString rest
= NULL
) const;
414 Searches for the given string. Returns the starting index, or @c wxNOT_FOUND if
417 int Find(wxUniChar ch
, bool fromEnd
= false) const;
418 const int Find(const wxString
& sub
) const;
424 This is a wxWidgets 1.xx compatibility function; you should not use it in new
427 int First(wxChar c
) const;
428 int First(const wxChar
* psz
) const;
429 const int First(const wxString
& str
) const;
433 This static function returns the string containing the result of calling
434 Printf() with the passed parameters on it.
436 @see FormatV(), Printf()
438 static wxString
Format(const wxChar format
, ...);
441 This static function returns the string containing the result of calling
442 PrintfV() with the passed parameters on it.
444 @see Format(), PrintfV()
446 static wxString
FormatV(const wxChar format
, va_list argptr
);
449 Returns the number of occurrences of @a ch in the string.
450 This is a wxWidgets 1.xx compatibility function; you should not use it in new
453 int Freq(wxChar ch
) const;
457 Converts given buffer of binary data from 8-bit string to wxString. In Unicode
458 build, the string is interpreted as being in ISO-8859-1 encoding. The version
459 without @a len parameter takes NUL-terminated data.
460 This is a convenience method useful when storing binary data in wxString.
464 @see wxString::To8BitData
466 static wxString
From8BitData(const char* buf
, size_t len
);
467 static wxString
From8BitData(const char* buf
);
472 Converts the string or character from an ASCII, 7-bit form
473 to the native wxString representation. Most useful when using
474 a Unicode build of wxWidgets (note the use of @c char instead of @c wxChar).
475 Use @ref construct() "wxString constructors" if you
476 need to convert from another charset.
478 static wxString
FromAscii(const char* s
);
479 static wxString
FromAscii(const unsigned char* s
);
480 static wxString
FromAscii(const char* s
, size_t len
);
481 static wxString
FromAscii(const unsigned char* s
, size_t len
);
482 static wxString
FromAscii(char c
);
487 Converts C string encoded in UTF-8 to wxString.
488 Note that this method assumes that @a s is a valid UTF-8 sequence and
489 doesn't do any validation in release builds, it's validity is only checked in
492 static wxString
FromUTF8(const char* s
);
493 static wxString
FromUTF8(const char* s
, size_t len
);
497 Returns the character at position @a n (read-only).
499 wxChar
GetChar(size_t n
) const;
502 wxWidgets compatibility conversion. Returns a constant pointer to the data in
505 const wxChar
* GetData() const;
508 Returns a reference to the character at position @e n.
510 wxChar
GetWritableChar(size_t n
);
513 Returns a writable buffer of at least @a len bytes.
514 It returns a pointer to a new memory block, and the
515 existing data will not be copied.
516 Call UngetWriteBuf() as soon as
517 possible to put the string back into a reasonable state.
518 This method is deprecated, please use
520 wxStringBufferLength instead.
522 wxChar
* GetWriteBuf(size_t len
);
527 This is a wxWidgets 1.xx compatibility function; you should not use it in new
530 size_t Index(wxChar ch
) const;
531 const size_t Index(const wxChar
* sz
) const;
535 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
539 bool IsAscii() const;
542 Returns @true if the string is empty.
544 bool IsEmpty() const;
547 Returns @true if the string is empty (same as wxString::IsEmpty).
548 This is a wxWidgets 1.xx compatibility function; you should not use it in new
554 Returns @true if the string is an integer (with possible sign).
555 This is a wxWidgets 1.xx compatibility function; you should not use it in new
558 bool IsNumber() const;
562 Test whether the string is equal to the single character @e c. The test is
563 case-sensitive if @a caseSensitive is @true (default) or not if it is @c
565 Returns @true if the string is equal to the character, @false otherwise.
566 See also Cmp(), CmpNoCase()
568 bool IsSameAs(const wxChar
* psz
, bool caseSensitive
= true) const;
569 const bool IsSameAs(wxChar c
, bool caseSensitive
= true) const;
573 Returns @true if the string is a word.
574 This is a wxWidgets 1.xx compatibility function; you should not use it in new
581 Returns a reference to the last character (writable).
582 This is a wxWidgets 1.xx compatibility function; you should not use it in new
590 Returns the first @a count characters of the string.
592 wxString
Left(size_t count
) const;
595 Returns the length of the string.
600 Returns the length of the string (same as Len).
601 This is a wxWidgets 1.xx compatibility function; you should not use it in new
604 size_t Length() const;
607 Returns this string converted to the lower case.
609 wxString
Lower() const;
613 This is a wxWidgets 1.xx compatibility function; you should not use it in new
619 Converts all characters to lower case and returns the result.
621 wxString
MakeLower();
624 Converts all characters to upper case and returns the result.
626 wxString
MakeUpper();
629 Returns @true if the string contents matches a mask containing '*' and '?'.
631 bool Matches(const wxString
& mask
) const;
634 These are "advanced" functions and they will be needed quite rarely.
635 Alloc() and Shrink() are only
636 interesting for optimization purposes.
638 and wxStringBufferLength classes may be very
639 useful when working with some external API which requires the caller to provide
652 Returns a substring starting at @e first, with length @e count, or the rest of
653 the string if @a count is the default value.
655 wxString
Mid(size_t first
, size_t count
= wxSTRING_MAXLEN
) const;
658 Other string functions.
668 Adds @a count copies of @a pad to the beginning, or to the end of the string
670 Removes spaces from the left or from the right (default).
672 wxString
Pad(size_t count
, wxChar pad
= ' ',
673 bool fromRight
= true);
676 Prepends @a str to this string, returning a reference to this string.
678 wxString
Prepend(const wxString
& str
);
681 Similar to the standard function @e sprintf(). Returns the number of
682 characters written, or an integer less than zero on error.
683 Note that if @c wxUSE_PRINTF_POS_PARAMS is set to 1, then this function supports
684 Unix98-style positional parameters:
686 @note This function will use a safe version of @e vsprintf() (usually called
687 @e vsnprintf()) whenever available to always allocate the buffer of correct
688 size. Unfortunately, this function is not available on all platforms and the
689 dangerous @e vsprintf() will be used then which may lead to buffer overflows.
691 int Printf(const wxChar
* pszFormat
, ...);
694 Similar to vprintf. Returns the number of characters written, or an integer
698 int PrintfV(const wxChar
* pszFormat
, va_list argPtr
);
702 Removes @a len characters from the string, starting at @e pos.
703 This is a wxWidgets 1.xx compatibility function; you should not use it in new
706 wxString
Remove(size_t pos
);
707 wxString
Remove(size_t pos
, size_t len
);
711 Removes the last character.
713 wxString
RemoveLast();
716 Replace first (or all) occurrences of substring with another one.
717 @e replaceAll: global replace (default), or only the first occurrence.
718 Returns the number of replacements made.
720 size_t Replace(const wxString
& strOld
, const wxString
& strNew
,
721 bool replaceAll
= true);
724 Returns the last @a count characters.
726 wxString
Right(size_t count
) const;
729 These functions replace the standard @e strchr() and @e strstr()
738 Sets the character at position @e n.
740 void SetChar(size_t n
, wxChar ch
);
743 Minimizes the string's memory. This can be useful after a call to
744 Alloc() if too much memory were preallocated.
749 This function can be used to test if the string starts with the specified
750 @e prefix. If it does, the function will return @true and put the rest
751 of the string (i.e. after the prefix) into @a rest string if it is not
752 @NULL. Otherwise, the function returns @false and doesn't modify the
755 bool StartsWith(const wxString
& prefix
, wxString rest
= NULL
) const;
758 These functions return the string length and check whether the string is empty
764 @ref operatornot() operator!
773 Strip characters at the front and/or end. The same as Trim except that it
774 doesn't change this string.
775 This is a wxWidgets 1.xx compatibility function; you should not use it in new
778 wxString
Strip(stripType s
= trailing
) const;
781 Returns the part of the string between the indices @a from and @e to
783 This is a wxWidgets 1.xx compatibility function, use Mid()
784 instead (but note that parameters have different meaning).
786 wxString
SubString(size_t from
, size_t to
) const;
789 These functions allow to extract substring from this string. All of them don't
790 modify the original string and return a new string containing the extracted
794 @ref operatorparenth() operator
816 Converts the string to an 8-bit string in ISO-8859-1 encoding in the form of
817 a wxCharBuffer (Unicode builds only).
818 This is a convenience method useful when storing binary data in wxString.
822 @see wxString::From8BitData
824 const char* To8BitData() const;
825 const const wxCharBuffer
To8BitData() const;
830 Converts the string to an ASCII, 7-bit string in the form of
831 a wxCharBuffer (Unicode builds only) or a C string (ANSI builds).
832 Note that this conversion only works if the string contains only ASCII
833 characters. The @ref mbstr() mb_str method provides more
834 powerful means of converting wxString to C string.
836 const char* ToAscii() const;
837 const const wxCharBuffer
ToAscii() const;
841 Attempts to convert the string to a floating point number. Returns @true on
842 success (the number is stored in the location pointed to by @e val) or @false
843 if the string does not represent such number (the value of @a val is not
844 modified in this case).
846 @see ToLong(), ToULong()
848 bool ToDouble(double val
) const;
851 Attempts to convert the string to a signed integer in base @e base. Returns
852 @true on success in which case the number is stored in the location
853 pointed to by @a val or @false if the string does not represent a
854 valid number in the given base (the value of @a val is not modified
856 The value of @a base must be comprised between 2 and 36, inclusive, or
857 be a special value 0 which means that the usual rules of @c C numbers are
858 applied: if the number starts with @c 0x it is considered to be in base
859 16, if it starts with @c 0 - in base 8 and in base 10 otherwise. Note
860 that you may not want to specify the base 0 if you are parsing the numbers
861 which may have leading zeroes as they can yield unexpected (to the user not
862 familiar with C) results.
864 @see ToDouble(), ToULong()
866 bool ToLong(long val
, int base
= 10) const;
869 This is exactly the same as ToLong() but works with 64
871 Notice that currently it doesn't work (always returns @false) if parsing of 64
872 bit numbers is not supported by the underlying C run-time library. Compilers
873 with C99 support and Microsoft Visual C++ version 7 and higher do support this.
875 @see ToLong(), ToULongLong()
877 bool ToLongLong(wxLongLong_t val
, int base
= 10) const;
880 Attempts to convert the string to an unsigned integer in base @e base.
881 Returns @true on success in which case the number is stored in the
882 location pointed to by @a val or @false if the string does not
883 represent a valid number in the given base (the value of @a val is not
884 modified in this case). Please notice that this function
885 behaves in the same way as the standard @c strtoul() and so it simply
886 converts negative numbers to unsigned representation instead of rejecting them
887 (e.g. -1 is returned as @c ULONG_MAX).
888 See ToLong() for the more detailed
889 description of the @a base parameter.
891 @see ToDouble(), ToLong()
893 bool ToULong(unsigned long val
, int base
= 10) const;
896 This is exactly the same as ToULong() but works with 64
898 Please see ToLongLong() for additional remarks.
900 bool ToULongLong(wxULongLong_t val
, int base
= 10) const;
904 Same as @ref wxString::utf8str utf8_str.
906 const char* ToUTF8() const;
907 const const wxCharBuffer
ToUF8() const;
911 Removes white-space (space, tabs, form feed, newline and carriage return) from
912 the left or from the right end of the string (right is default).
914 wxString
Trim(bool fromRight
= true);
917 Truncate the string to the given length.
919 wxString
Truncate(size_t len
);
923 Puts the string back into a reasonable state (in which it can be used
925 GetWriteBuf() was called.
926 The version of the function without the @a len parameter will calculate the
927 new string length itself assuming that the string is terminated by the first
928 @c NUL character in it while the second one will use the specified length
929 and thus is the only version which should be used with the strings with
930 embedded @c NULs (it is also slightly more efficient as @c strlen()
931 doesn't have to be called).
932 This method is deprecated, please use
934 wxStringBufferLength instead.
936 void UngetWriteBuf();
937 void UngetWriteBuf(size_t len
);
941 Returns this string converted to upper case.
943 wxString
Upper() const;
946 The same as MakeUpper.
947 This is a wxWidgets 1.xx compatibility function; you should not use it in new
953 Both formatted versions (wxString::Printf) and stream-like
954 insertion operators exist (for basic types only). Additionally, the
955 Format() function allows to use simply append
956 formatted value to a string:
966 @ref operatorout() "operator "
971 Returns a pointer to the string data (@c const char* in ANSI build,
972 @c const wchar_t* in Unicode build).
973 Note that the returned value is not convertible to @c char* or
974 @c wchar_t*, use @ref charstr() char_str or
975 @ref wcharstr() wchar_string if you need to pass string value
976 to a function expecting non-const pointer.
978 @see @ref mbstr() mb_str, @ref wcstr() wc_str, @ref
979 fnstr() fn_str, @ref charstr() char_str, @ref
980 wcharstr() wchar_string
982 const wxChar
* c_str() const;
985 Returns an object with string data that is implicitly convertible to
986 @c char* pointer. Note that any change to the returned buffer is lost and so
987 this function is only usable for passing strings to legacy libraries that
988 don't have const-correct API. Use wxStringBuffer if
989 you want to modify the string.
991 @see @ref mbstr() mb_str, @ref wcstr() wc_str, @ref
992 fnstr() fn_str, @ref cstr() c_str, @ref
995 wxWritableCharBuffer
char_str(const wxMBConv
& conv
= wxConvLibc
) const;
999 Returns string representation suitable for passing to OS' functions for
1000 file handling. In ANSI build, this is same as @ref cstr() c_str.
1001 In Unicode build, returned value can be either wide character string
1002 or C string in charset matching the @c wxConvFileName object, depending on
1005 @see wxMBConv, @ref wcstr() wc_str, @ref wcstr() mb_str
1007 const wchar_t* fn_str() const;
1008 const const char* fn_str() const;
1009 const const wxCharBuffer
fn_str() const;
1014 Returns multibyte (C string) representation of the string.
1015 In Unicode build, converts using @e conv's wxMBConv::cWC2MB
1016 method and returns wxCharBuffer. In ANSI build, this function is same
1017 as @ref cstr() c_str.
1018 The macro wxWX2MBbuf is defined as the correct return type (without const).
1020 @see wxMBConv, @ref cstr() c_str, @ref wcstr() wc_str, @ref
1021 fnstr() fn_str, @ref charstr() char_str
1023 const char* mb_str(const wxMBConv
& conv
= wxConvLibc
) const;
1024 const const wxCharBuffer
mb_str(const wxMBConv
& conv
= wxConvLibc
) const;
1028 Extraction from a stream.
1030 friend istream
operator(istream
& is
, wxString
& str
);
1034 These functions work as C++ stream insertion operators: they insert the given
1035 value into the string. Precision or format cannot be set using them, you can
1039 wxString
operator(const wxString
& str
);
1040 wxString
operator(const wxChar
* psz
);
1041 wxString
operator(wxChar ch
);
1042 wxString
operator(int i
);
1043 wxString
operator(float f
);
1044 wxString
operator(double d
);
1048 Same as Mid (substring extraction).
1050 wxString
operator ()(size_t start
, size_t len
);
1054 Concatenation: all these operators return a new string equal to the
1055 concatenation of the operands.
1057 wxString
operator +(const wxString
& x
, const wxString
& y
);
1058 wxString
operator +(const wxString
& x
, const wxChar
* y
);
1059 wxString
operator +(const wxString
& x
, wxChar y
);
1060 wxString
operator +(const wxChar
* x
, const wxString
& y
);
1065 Concatenation in place: the argument is appended to the string.
1067 void operator +=(const wxString
& str
);
1068 void operator +=(const wxChar
* psz
);
1069 void operator +=(wxChar c
);
1074 Assignment: the effect of each operation is the same as for the corresponding
1075 constructor (see @ref construct() "wxString constructors").
1077 wxString
operator =(const wxString
& str
);
1078 wxString
operator =(const wxChar
* psz
);
1079 wxString
operator =(wxChar c
);
1086 wxChar
operator [](size_t i
) const;
1087 wxChar
operator [](size_t i
) const;
1088 const wxChar
operator [](int i
) const;
1089 wxChar
operator [](int i
) const;
1093 Implicit conversion to a C string.
1095 operator const wxChar
*() const;
1098 Empty string is @false, so !string will only return @true if the string is
1100 This allows the tests for @NULLness of a @e const wxChar * pointer and emptiness
1101 of the string to look the same in the code and makes it easier to port old code
1105 bool operator!() const;
1108 The supported functions are only listed here, please see any STL reference for
1109 their documentation.
1115 Converts the strings contents to UTF-8 and returns it either as a temporary
1116 wxCharBuffer object or as a pointer to the internal string contents in
1119 const char* utf8_str() const;
1120 const const wxCharBuffer
utf8_str() const;
1125 Returns wide character representation of the string.
1126 In ANSI build, converts using @e conv's wxMBConv::cMB2WC
1127 method and returns wxWCharBuffer. In Unicode build, this function is same
1128 as @ref cstr() c_str.
1129 The macro wxWX2WCbuf is defined as the correct return type (without const).
1131 @see wxMBConv, @ref cstr() c_str, @ref wcstr() mb_str, @ref
1132 fnstr() fn_str, @ref wcharstr() wchar_str
1134 const wchar_t* wc_str(const wxMBConv
& conv
) const;
1135 const const wxWCharBuffer
wc_str(const wxMBConv
& conv
) const;
1139 Returns an object with string data that is implicitly convertible to
1140 @c char* pointer. Note that changes to the returned buffer may or may
1141 not be lost (depending on the build) and so this function is only usable for
1142 passing strings to legacy libraries that don't have const-correct API. Use
1143 wxStringBuffer if you want to modify the string.
1145 @see @ref mbstr() mb_str, @ref wcstr() wc_str, @ref
1146 fnstr() fn_str, @ref cstr() c_str, @ref
1149 wxWritableWCharBuffer
wchar_str() const;
1152 These functions are deprecated, please consider using new wxWidgets 2.0
1153 functions instead of them (or, even better, std::string compatible variants).
1198 wxString wxEmptyString
;
1204 @class wxStringBufferLength
1207 This tiny class allows to conveniently access the wxString
1208 internal buffer as a writable pointer without any risk of forgetting to restore
1209 the string to the usable state later, and allows the user to set the internal
1210 length of the string.
1212 For example, assuming you have a low-level OS function called
1213 @c int GetMeaningOfLifeAsString(char *) copying the value in the provided
1214 buffer (which must be writable, of course), and returning the actual length
1215 of the string, you might call it like this:
1219 wxStringBuffer theAnswerBuffer(theAnswer, 1024);
1220 int nLength = GetMeaningOfLifeAsString(theAnswerBuffer);
1221 theAnswerBuffer.SetLength(nLength);
1222 if ( theAnswer != "42" )
1224 wxLogError("Something is very wrong!");
1228 Note that the exact usage of this depends on whether on not wxUSE_STL is
1230 wxUSE_STL is enabled, wxStringBuffer creates a separate empty character buffer,
1232 if wxUSE_STL is disabled, it uses GetWriteBuf() from wxString, keeping the same
1234 wxString uses intact. In other words, relying on wxStringBuffer containing the
1236 wxString data is probably not a good idea if you want to build your program in
1238 with and without wxUSE_STL.
1240 Note that SetLength @c must be called before wxStringBufferLength destructs.
1245 class wxStringBufferLength
1249 Constructs a writable string buffer object associated with the given string
1250 and containing enough space for at least @a len characters. Basically, this
1251 is equivalent to calling wxString::GetWriteBuf and
1254 wxStringBufferLength(const wxString
& str
, size_t len
);
1257 Restores the string passed to the constructor to the usable state by calling
1258 wxString::UngetWriteBuf on it.
1260 ~wxStringBufferLength();
1263 Sets the internal length of the string referred to by wxStringBufferLength to
1264 @a nLength characters.
1265 Must be called before wxStringBufferLength destructs.
1267 void SetLength(size_t nLength
);
1270 Returns the writable pointer to a buffer of the size at least equal to the
1271 length specified in the constructor.
1273 wxChar
* operator wxChar
*();