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