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