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