]>
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$ | |
526954c5 | 6 | // Licence: wxWindows licence |
23324ae1 FM |
7 | ///////////////////////////////////////////////////////////////////////////// |
8 | ||
e54c96f1 | 9 | |
23324ae1 FM |
10 | /** |
11 | @class wxString | |
7c913512 | 12 | |
e33efe48 VZ |
13 | String class for passing textual data to or receiving it from wxWidgets. |
14 | ||
15 | @note | |
16 | While the use of wxString is unavoidable in wxWidgets program, you are | |
17 | encouraged to use the standard string classes @c std::string or @c | |
18 | std::wstring in your applications and convert them to and from wxString | |
19 | only when interacting with wxWidgets. | |
20 | ||
21 | ||
22 | wxString is a class representing a Unicode character string but with | |
23 | methods taking or returning both @c wchar_t wide characters and @c wchar_t* | |
24 | wide strings and traditional @c char characters and @c char* strings. The | |
25 | dual nature of wxString API makes it simple to use in all cases and, | |
26 | importantly, allows the code written for either ANSI or Unicode builds of | |
27 | the previous wxWidgets versions to compile and work correctly with the | |
28 | single unified Unicode build of wxWidgets 3.0. It is also mostly | |
29 | transparent when using wxString with the few exceptions described below. | |
30 | ||
31 | ||
32 | @section string_api API overview | |
33 | ||
34 | wxString tries to be similar to both @c std::string and @c std::wstring and | |
35 | can mostly be used as either class. It provides practically all of the | |
36 | methods of these classes, which behave exactly the same as in the standard | |
37 | C++, and so are not documented here (please see any standard library | |
38 | documentation, for example http://en.cppreference.com/w/cpp/string for more | |
39 | details). | |
40 | ||
41 | In addition to these standard methods, wxString adds functions dealing with | |
42 | the conversions between different string encodings, described below, as | |
43 | well as many extra helpers such as functions for formatted output | |
44 | (Printf(), Format(), ...), case conversion (MakeUpper(), Capitalize(), ...) | |
45 | and various others (Trim(), StartsWith(), Matches(), ...). All of the | |
46 | non-standard methods follow wxWidgets "CamelCase" naming convention and are | |
47 | documented here. | |
48 | ||
49 | Notice that some wxString methods exist in several versions for | |
50 | compatibility reasons. For example all of length(), Length() and Len() are | |
51 | provided. In such cases it is recommended to use the standard string-like | |
52 | method, i.e. length() in this case. | |
53 | ||
54 | ||
55 | @section string_conv Converting to and from wxString | |
56 | ||
57 | wxString can be created from: | |
58 | - ASCII string guaranteed to contain only 7 bit characters using | |
59 | wxString::FromAscii(). | |
60 | - Narrow @c char* string in the current locale encoding using implicit | |
61 | wxString::wxString(const char*) constructor. | |
62 | - Narrow @c char* string in UTF-8 encoding using wxString::FromUTF8(). | |
63 | - Narrow @c char* string in the given encoding using | |
64 | wxString::wxString(const char*, const wxMBConv&) constructor passing a | |
65 | wxCSConv corresponding to the encoding as the second argument. | |
66 | - Standard @c std::string using implicit wxString::wxString(const | |
67 | std::string&) constructor. Notice that this constructor supposes that | |
68 | the string contains data in the current locale encoding, use FromUTF8() | |
69 | or the constructor taking wxMBConv if this is not the case. | |
70 | - Wide @c wchar_t* string using implicit wxString::wxString(const | |
71 | wchar_t*) constructor. | |
72 | - Standard @c std::wstring using implicit wxString::wxString(const | |
73 | std::wstring&) constructor. | |
74 | ||
75 | Notice that many of the constructors are implicit, meaning that you don't | |
76 | even need to write them at all to pass the existing string to some | |
77 | wxWidgets function taking a wxString. | |
78 | ||
79 | Similarly, wxString can be converted to: | |
80 | - ASCII string using wxString::ToAscii(). This is a potentially | |
81 | destructive operation as all non-ASCII string characters are replaced | |
82 | with a placeholder character. | |
83 | - String in the current locale encoding implicitly or using c_str() or | |
84 | mb_str() methods. This is a potentially destructive operation as an @e | |
85 | empty string is returned if the conversion fails. | |
86 | - String in UTF-8 encoding using wxString::utf8_str(). | |
87 | - String in any given encoding using mb_str() with the appropriate | |
88 | wxMBConv object. This is also a potentially destructive operation. | |
89 | - Standard @c std::string using wxString::ToStdString(). The contents | |
90 | of the returned string use the current locale encoding, so this | |
91 | conversion is potentially destructive as well. | |
92 | - Wide C string using wxString::wc_str(). | |
93 | - Standard @c std::wstring using wxString::ToStdWstring(). | |
94 | ||
95 | @note If you built wxWidgets with @c wxUSE_STL set to 1, the implicit | |
96 | conversions to both narrow and wide C strings are disabled and replaced | |
97 | with implicit conversions to @c std::string and @c std::wstring. | |
98 | ||
99 | Please notice that the conversions marked as "potentially destructive" | |
100 | above can result in loss of data if their result is not checked, so you | |
101 | need to verify that converting the contents of a non-empty Unicode string | |
102 | to a non-UTF-8 multibyte encoding results in non-empty string. The simplest | |
103 | and best way to ensure that the conversion never fails is to always use | |
104 | UTF-8. | |
105 | ||
106 | ||
107 | @section string_gotchas Traps for the unwary | |
108 | ||
109 | As mentioned above, wxString tries to be compatible with both narrow and | |
110 | wide standard string classes and mostly does it transparently, but there | |
111 | are some exceptions. | |
112 | ||
113 | @subsection string_gotchas_element String element access | |
114 | ||
115 | Some problems are caused by wxString::operator[]() which returns an object | |
116 | of a special proxy class allowing to assign either a simple @c char or a @c | |
117 | wchar_t to the given index. Because of this, the return type of this | |
118 | operator is neither @c char nor @c wchar_t nor a reference to one of these | |
119 | types but wxUniCharRef which is not a primitive type and hence can't be | |
120 | used in the @c switch statement. So the following code does @e not compile | |
121 | @code | |
122 | wxString s(...); | |
123 | switch ( s[n] ) { | |
124 | case 'A': | |
125 | ... | |
126 | break; | |
127 | } | |
128 | @endcode | |
129 | and you need to use | |
130 | @code | |
131 | switch ( s[n].GetValue() ) { | |
132 | ... | |
133 | } | |
134 | @endcode | |
135 | instead. Alternatively, you can use an explicit cast: | |
136 | @code | |
137 | switch ( static_cast<char>(s[n]) ) { | |
138 | ... | |
139 | } | |
140 | @endcode | |
141 | but notice that this will result in an assert failure if the character at | |
142 | the given position is not representable as a single @c char in the current | |
143 | encoding, so you may want to cast to @c int instead if non-ASCII values can | |
144 | be used. | |
145 | ||
146 | Another consequence of this unusual return type arises when it is used with | |
147 | template deduction or C++11 @c auto keyword. Unlike with the normal | |
148 | references which are deduced to be of the referenced type, the deduced type | |
149 | for wxUniCharRef is wxUniCharRef itself. This results in potentially | |
150 | unexpected behaviour, for example: | |
151 | @code | |
152 | wxString s("abc"); | |
153 | auto c = s[0]; | |
154 | c = 'x'; // Modifies the string! | |
155 | wxASSERT( s == "xbc" ); | |
156 | @endcode | |
157 | Due to this, either explicitly specify the variable type: | |
158 | @code | |
159 | int c = s[0]; | |
160 | c = 'x'; // Doesn't modify the string any more. | |
161 | wxASSERT( s == "abc" ); | |
162 | @endcode | |
163 | or explicitly convert the return value: | |
164 | @code | |
165 | auto c = s[0].GetValue(); | |
166 | c = 'x'; // Doesn't modify the string neither. | |
167 | wxASSERT( s == "abc" ); | |
168 | @endcode | |
169 | ||
170 | ||
171 | @subsection string_gotchas_conv Conversion to C string | |
172 | ||
173 | A different class of problems happens due to the dual nature of the return | |
174 | value of wxString::c_str() method, which is also used for implicit | |
175 | conversions. The result of calls to this method is convertible to either | |
176 | narrow @c char* string or wide @c wchar_t* string and so, again, has | |
177 | neither the former nor the latter type. Usually, the correct type will be | |
178 | chosen depending on how you use the result but sometimes the compiler can't | |
179 | choose it because of an ambiguity, e.g.: | |
180 | @code | |
181 | // Some non-wxWidgets functions existing for both narrow and wide | |
182 | // strings: | |
183 | void dump_text(const char* text); // Version (1) | |
184 | void dump_text(const wchar_t* text); // Version (2) | |
185 | ||
186 | wxString s(...); | |
187 | dump_text(s); // ERROR: ambiguity. | |
188 | dump_text(s.c_str()); // ERROR: still ambiguous. | |
189 | @endcode | |
190 | In this case you need to explicitly convert to the type that you need to | |
191 | use or use a different, non-ambiguous, conversion function (which is | |
192 | usually the best choice): | |
193 | @code | |
194 | dump_text(static_cast<const char*>(s)); // OK, calls (1) | |
195 | dump_text(static_cast<const wchar_t*>(s.c_str())); // OK, calls (2) | |
196 | dump_text(s.mb_str()); // OK, calls (1) | |
197 | dump_text(s.wc_str()); // OK, calls (2) | |
198 | dump_text(s.wx_str()); // OK, calls ??? | |
199 | @endcode | |
200 | ||
201 | @subsection string_vararg Using wxString with vararg functions | |
202 | ||
203 | A special subclass of the problems arising due to the polymorphic nature of | |
204 | wxString::c_str() result type happens when using functions taking an | |
205 | arbitrary number of arguments, such as the standard @c printf(). Due to the | |
206 | rules of the C++ language, the types for the "variable" arguments of such | |
207 | functions are not specified and hence the compiler cannot convert wxString | |
208 | objects, or the objects returned by wxString::c_str(), to these unknown | |
209 | types automatically. Hence neither wxString objects nor the results of most | |
210 | of the conversion functions can be passed as vararg arguments: | |
211 | @code | |
212 | // ALL EXAMPLES HERE DO NOT WORK, DO NOT USE THEM! | |
213 | printf("Don't do this: %s", s); | |
214 | printf("Don't do that: %s", s.c_str()); | |
215 | printf("Nor even this: %s", s.mb_str()); | |
216 | wprintf("And even not always this: %s", s.wc_str()); | |
217 | @endcode | |
218 | Instead you need to either explicitly cast to the needed type: | |
219 | @code | |
220 | // These examples work but are not the best solution, see below. | |
221 | printf("You can do this: %s", static_cast<const char*>(s)); | |
222 | printf("Or this: %s", static_cast<const char*>(s.c_str())); | |
223 | printf("And this: %s", static_cast<const char*>(s.mb_str())); | |
224 | wprintf("Or this: %s", static_cast<const wchar_t*>(s.wc_str())); | |
225 | @endcode | |
226 | But a better solution is to use wxWidgets-provided functions, if possible, | |
227 | as is the case for @c printf family of functions: | |
228 | @code | |
229 | // This is the recommended way. | |
230 | wxPrintf("You can do just this: %s", s); | |
231 | wxPrintf("And this (but it is redundant): %s", s.c_str()); | |
232 | wxPrintf("And this (not using Unicode): %s", s.mb_str()); | |
233 | wxPrintf("And this (always Unicode): %s", s.wc_str()); | |
234 | @endcode | |
235 | Notice that wxPrintf() replaces both @c printf() and @c wprintf() and | |
236 | accepts wxString objects, results of c_str() calls but also @c char* and | |
237 | @c wchar_t* strings directly. | |
238 | ||
239 | wxWidgets provides wx-prefixed equivalents to all the standard vararg | |
240 | functions and a few more, notably wxString::Format(), wxLogMessage(), | |
241 | wxLogError() and other log functions. But if you can't use one of those | |
242 | functions and need to pass wxString objects to non-wx vararg functions, you | |
243 | need to use the explicit casts as explained above. | |
244 | ||
245 | ||
246 | @section string_performance Performance characteristics | |
247 | ||
248 | wxString uses @c std::basic_string internally to store its content (unless | |
249 | this is not supported by the compiler or disabled specifically when | |
250 | building wxWidgets) and it therefore inherits many features from @c | |
251 | std::basic_string. In particular, most modern implementations of @c | |
252 | std::basic_string are thread-safe and don't use reference counting (making | |
253 | copying large strings potentially expensive) and so wxString has the same | |
254 | characteristics. | |
255 | ||
256 | By default, wxString uses @c std::basic_string specialized for the | |
257 | platform-dependent @c wchar_t type, meaning that it is not memory-efficient | |
258 | for ASCII strings, especially under Unix platforms where every ASCII | |
259 | character, normally fitting in a byte, is represented by a 4 byte @c | |
260 | wchar_t. | |
261 | ||
262 | It is possible to build wxWidgets with @c wxUSE_UNICODE_UTF8 set to 1 in | |
263 | which case an UTF-8-encoded string representation is stored in @c | |
264 | std::basic_string specialized for @c char, i.e. the usual @c std::string. | |
265 | In this case the memory efficiency problem mentioned above doesn't arise | |
266 | but run-time performance of many wxString methods changes dramatically, in | |
267 | particular accessing the N-th character of the string becomes an operation | |
268 | taking O(N) time instead of O(1), i.e. constant, time by default. Thus, if | |
269 | you do use this so called UTF-8 build, you should avoid using indices to | |
270 | access the strings whenever possible and use the iterators instead. As an | |
271 | example, traversing the string using iterators is an O(N), where N is the | |
272 | string length, operation in both the normal ("wchar_t") and UTF-8 builds | |
273 | but doing it using indices becomes O(N^2) in UTF-8 case meaning that simply | |
274 | checking every character of a reasonably long (e.g. a couple of millions | |
275 | elements) string can take an unreasonably long time. | |
276 | ||
277 | However, if you do use iterators, UTF-8 build can be a better choice than | |
278 | the default build, especially for the memory-constrained embedded systems. | |
279 | Notice also that GTK+ and DirectFB use UTF-8 internally, so using this | |
280 | build not only saves memory for ASCII strings but also avoids conversions | |
281 | between wxWidgets and the underlying toolkit. | |
7c913512 | 282 | |
4701dc09 | 283 | |
ee49f540 FM |
284 | @section string_index Index of the member groups |
285 | ||
286 | Links for quick access to the various categories of wxString functions: | |
287 | - @ref_member_group{ctor, Constructors and assignment operators} | |
288 | - @ref_member_group{length, Length functions} | |
289 | - @ref_member_group{ch_access, Character access functions} | |
290 | - @ref_member_group{conv, Conversions functions} | |
291 | - @ref_member_group{concat, Concatenation functions} | |
292 | - @ref_member_group{cmp, Comparison functions} | |
293 | - @ref_member_group{substring, Substring extraction functions} | |
294 | - @ref_member_group{caseconv, Case conversion functions} | |
295 | - @ref_member_group{search, Searching and replacing functions} | |
296 | - @ref_member_group{numconv, Conversion to numbers functions} | |
297 | - @ref_member_group{fmt, Formatting and printing functions} | |
298 | - @ref_member_group{mem, Memory management functions} | |
299 | - @ref_member_group{misc, Miscellaneous functions} | |
300 | - @ref_member_group{iter, Iterator interface functions} | |
301 | - @ref_member_group{stl, STL interface functions} | |
4701dc09 | 302 | |
c3c772fa | 303 | |
23324ae1 FM |
304 | @library{wxbase} |
305 | @category{data} | |
7c913512 | 306 | |
23324ae1 | 307 | @stdobjects |
4701dc09 | 308 | ::wxEmptyString |
7c913512 | 309 | |
155032f9 | 310 | @see @ref overview_string, @ref overview_unicode, |
ee49f540 FM |
311 | @ref group_funcmacro_string "String-related functions", wxUString, |
312 | wxCharBuffer, wxUniChar, wxStringTokenizer, wxStringBuffer, wxStringBufferLength | |
23324ae1 | 313 | */ |
7c913512 | 314 | class wxString |
23324ae1 FM |
315 | { |
316 | public: | |
062dc5fc | 317 | /** |
f08b2466 | 318 | @name Standard types |
155032f9 | 319 | |
ee49f540 | 320 | Types used with wxString. |
b33e2f63 | 321 | */ |
f08b2466 | 322 | //@{ |
b33e2f63 RR |
323 | typedef wxUniChar value_type; |
324 | typedef wxUniChar char_type; | |
325 | typedef wxUniCharRef reference; | |
326 | typedef wxChar* pointer; | |
327 | typedef const wxChar* const_pointer; | |
328 | typedef size_t size_type; | |
329 | typedef wxUniChar const_reference; | |
330 | //@} | |
331 | ||
ee49f540 FM |
332 | |
333 | /** | |
334 | @member_group_name{ctor, Constructors and assignment operators} | |
335 | ||
336 | A string may be constructed either from a C string, (some number of copies of) | |
337 | a single character or a wide (Unicode) string. For all constructors (except the | |
338 | default which creates an empty string) there is also a corresponding assignment | |
339 | operator. | |
155032f9 | 340 | |
ee49f540 FM |
341 | See also the assign() STL-like function. |
342 | */ | |
343 | //@{ | |
155032f9 | 344 | |
23324ae1 | 345 | /** |
96c99165 | 346 | Default constructor |
23324ae1 FM |
347 | */ |
348 | wxString(); | |
062dc5fc | 349 | |
96c99165 | 350 | /** |
4701dc09 | 351 | Creates a string from another string. |
ee49f540 | 352 | Just increases the ref count by 1. |
96c99165 RR |
353 | */ |
354 | wxString(const wxString& stringSrc); | |
062dc5fc | 355 | |
474e9711 VZ |
356 | /** |
357 | Construct a string consisting of @a nRepeat copies of ch. | |
358 | */ | |
359 | wxString(wxUniChar ch, size_t nRepeat = 1); | |
360 | ||
361 | /** | |
362 | Construct a string consisting of @a nRepeat copies of ch. | |
363 | */ | |
364 | wxString(wxUniCharRef ch, size_t nRepeat = 1); | |
365 | ||
366 | /** | |
367 | Construct a string consisting of @a nRepeat copies of ch | |
368 | converted to Unicode using the current locale encoding. | |
369 | */ | |
370 | wxString(char ch, size_t nRepeat = 1); | |
371 | ||
372 | /** | |
373 | Construct a string consisting of @a nRepeat copies of ch. | |
374 | */ | |
375 | wxString(wchar_t ch, size_t nRepeat = 1); | |
96c99165 RR |
376 | |
377 | /** | |
ee49f540 | 378 | Constructs a string from the string literal @a psz using |
8c1cd030 | 379 | the current locale encoding to convert it to Unicode (wxConvLibc). |
96c99165 RR |
380 | */ |
381 | wxString(const char *psz); | |
382 | ||
383 | /** | |
ee49f540 FM |
384 | Constructs a string from the string literal @a psz using |
385 | @a conv to convert it Unicode. | |
96c99165 RR |
386 | */ |
387 | wxString(const char *psz, const wxMBConv& conv); | |
388 | ||
389 | /** | |
ee49f540 | 390 | Constructs a string from the first @a nLength character of the string literal @a psz using |
8c1cd030 | 391 | the current locale encoding to convert it to Unicode (wxConvLibc). |
96c99165 RR |
392 | */ |
393 | wxString(const char *psz, size_t nLength); | |
394 | ||
395 | /** | |
ee49f540 FM |
396 | Constructs a string from the first @a nLength character of the string literal @a psz using |
397 | @a conv to convert it Unicode. | |
96c99165 RR |
398 | */ |
399 | wxString(const char *psz, const wxMBConv& conv, size_t nLength); | |
400 | ||
401 | /** | |
ee49f540 | 402 | Constructs a string from the string literal @a pwz. |
96c99165 RR |
403 | */ |
404 | wxString(const wchar_t *pwz); | |
405 | ||
406 | /** | |
ee49f540 | 407 | Constructs a string from the first @a nLength characters of the string literal @a pwz. |
96c99165 RR |
408 | */ |
409 | wxString(const wchar_t *pwz, size_t nLength); | |
410 | ||
411 | /** | |
ee49f540 | 412 | Constructs a string from @a buf using the using the current locale |
4701dc09 | 413 | encoding to convert it to Unicode. |
96c99165 RR |
414 | */ |
415 | wxString(const wxCharBuffer& buf); | |
062dc5fc | 416 | |
96c99165 | 417 | /** |
ee49f540 | 418 | Constructs a string from @a buf. |
96c99165 RR |
419 | */ |
420 | wxString(const wxWCharBuffer& buf); | |
421 | ||
422 | /** | |
ee49f540 | 423 | Constructs a string from @a str using the using the current locale encoding |
8c1cd030 | 424 | to convert it to Unicode (wxConvLibc). |
e3ab6952 VZ |
425 | |
426 | @see ToStdString() | |
96c99165 RR |
427 | */ |
428 | wxString(const std::string& str); | |
062dc5fc | 429 | |
96c99165 | 430 | /** |
ee49f540 | 431 | Constructs a string from @a str. |
e3ab6952 VZ |
432 | |
433 | @see ToStdWstring() | |
96c99165 RR |
434 | */ |
435 | wxString(const std::wstring& str); | |
155032f9 | 436 | |
23324ae1 | 437 | /** |
4701dc09 FM |
438 | String destructor. |
439 | ||
440 | Note that this is not virtual, so wxString must not be inherited from. | |
23324ae1 FM |
441 | */ |
442 | ~wxString(); | |
443 | ||
444 | /** | |
ee49f540 | 445 | Assignment: see the relative wxString constructor. |
23324ae1 | 446 | */ |
ee49f540 | 447 | wxString operator =(const wxString& str); |
23324ae1 FM |
448 | |
449 | /** | |
ee49f540 | 450 | Assignment: see the relative wxString constructor. |
23324ae1 | 451 | */ |
ee49f540 | 452 | wxString operator =(wxUniChar c); |
0367b928 | 453 | |
ee49f540 | 454 | //@} |
155032f9 | 455 | |
0367b928 | 456 | |
23324ae1 | 457 | |
23324ae1 | 458 | /** |
ee49f540 | 459 | @member_group_name{length, String length} |
77da37be | 460 | |
ee49f540 FM |
461 | These functions return the string length and/or check whether the string |
462 | is empty. | |
155032f9 | 463 | |
ee49f540 | 464 | See also the length(), size() or empty() STL-like functions. |
77da37be | 465 | */ |
ee49f540 | 466 | //@{ |
155032f9 | 467 | |
77da37be RR |
468 | |
469 | /** | |
ee49f540 | 470 | Returns the length of the string. |
23324ae1 | 471 | */ |
ee49f540 | 472 | size_t Len() const; |
77da37be RR |
473 | |
474 | /** | |
ee49f540 FM |
475 | Returns the length of the string (same as Len). |
476 | This is a wxWidgets 1.xx compatibility function; you should not use it in new | |
477 | code. | |
77da37be | 478 | */ |
ee49f540 | 479 | size_t Length() const; |
77da37be RR |
480 | |
481 | /** | |
ee49f540 | 482 | Returns @true if the string is empty. |
77da37be | 483 | */ |
ee49f540 | 484 | bool IsEmpty() const; |
77da37be RR |
485 | |
486 | /** | |
ee49f540 FM |
487 | Returns @true if the string is empty (same as wxString::IsEmpty). |
488 | This is a wxWidgets 1.xx compatibility function; you should not use it in new | |
489 | code. | |
77da37be | 490 | */ |
ee49f540 | 491 | bool IsNull() const; |
23324ae1 FM |
492 | |
493 | /** | |
ee49f540 FM |
494 | Empty string is @false, so !string will only return @true if the |
495 | string is empty. | |
23324ae1 | 496 | |
ee49f540 | 497 | @see IsEmpty(). |
23324ae1 | 498 | */ |
ee49f540 | 499 | bool operator!() const; |
23324ae1 | 500 | |
ee49f540 | 501 | //@} |
0c7db140 | 502 | |
0c7db140 | 503 | |
0c7db140 | 504 | |
23324ae1 | 505 | /** |
ee49f540 FM |
506 | @member_group_name{ch_access, Character access} |
507 | ||
155032f9 VZ |
508 | Many functions below take a character index in the string. |
509 | As with C strings and arrays, the indices start from 0, so the first character | |
ee49f540 FM |
510 | of a string is string[0]. An attempt to access a character beyond the end of the |
511 | string (which may even be 0 if the string is empty) will provoke an assert | |
512 | failure in @ref overview_debugging "debug builds", but no checks are | |
513 | done in release builds. | |
23324ae1 | 514 | */ |
ee49f540 | 515 | //@{ |
23324ae1 | 516 | |
06e9cf13 | 517 | /** |
ee49f540 FM |
518 | Returns the character at position @a n (read-only). |
519 | */ | |
520 | wxUniChar GetChar(size_t n) const; | |
06e9cf13 | 521 | |
23324ae1 | 522 | /** |
ee49f540 | 523 | wxWidgets compatibility conversion. Same as c_str(). |
23324ae1 | 524 | */ |
ee49f540 | 525 | const wxCStrData GetData() const; |
23324ae1 | 526 | |
23324ae1 | 527 | /** |
ee49f540 | 528 | Returns a reference to the character at position @a n. |
23324ae1 | 529 | */ |
ee49f540 | 530 | wxUniCharRef GetWritableChar(size_t n); |
23324ae1 | 531 | |
23324ae1 | 532 | /** |
ee49f540 | 533 | Returns a writable buffer of at least @a len bytes. |
155032f9 | 534 | |
ee49f540 FM |
535 | It returns a pointer to a new memory block, and the existing data will not be copied. |
536 | Call UngetWriteBuf() as soon as possible to put the string back into a reasonable state. | |
155032f9 | 537 | |
ee49f540 | 538 | This method is deprecated, please use wxStringBuffer or wxStringBufferLength instead. |
23324ae1 | 539 | */ |
ee49f540 | 540 | wxStringCharType* GetWriteBuf(size_t len); |
23324ae1 FM |
541 | |
542 | /** | |
ee49f540 FM |
543 | Puts the string back into a reasonable state (in which it can be used |
544 | normally), after GetWriteBuf() was called. | |
545 | ||
546 | The version of the function without the @a len parameter will calculate the | |
547 | new string length itself assuming that the string is terminated by the first | |
548 | @c NUL character in it while the second one will use the specified length | |
549 | and thus is the only version which should be used with the strings with | |
550 | embedded @c NULs (it is also slightly more efficient as @c strlen() | |
551 | doesn't have to be called). | |
23324ae1 | 552 | |
ee49f540 FM |
553 | This method is deprecated, please use wxStringBuffer or wxStringBufferLength instead. |
554 | */ | |
555 | void UngetWriteBuf(); | |
155032f9 | 556 | |
23324ae1 | 557 | /** |
ee49f540 | 558 | @overload |
23324ae1 | 559 | */ |
ee49f540 | 560 | void UngetWriteBuf(size_t len); |
155032f9 | 561 | |
23324ae1 | 562 | /** |
ee49f540 | 563 | Sets the character at position @e n. |
23324ae1 | 564 | */ |
ee49f540 | 565 | void SetChar(size_t n, wxUniChar ch); |
062dc5fc | 566 | |
77da37be | 567 | /** |
57ab6f23 | 568 | Returns the last character. |
155032f9 | 569 | |
ee49f540 FM |
570 | This is a wxWidgets 1.xx compatibility function; |
571 | you should not use it in new code. | |
77da37be | 572 | */ |
ee49f540 | 573 | wxUniChar Last() const; |
155032f9 | 574 | |
23324ae1 | 575 | /** |
ee49f540 | 576 | Returns a reference to the last character (writable). |
155032f9 | 577 | |
062dc5fc | 578 | This is a wxWidgets 1.xx compatibility function; |
b33e2f63 | 579 | you should not use it in new code. |
23324ae1 | 580 | */ |
ee49f540 | 581 | wxUniCharRef Last(); |
23324ae1 FM |
582 | |
583 | /** | |
ee49f540 | 584 | Returns the @a i-th character of the string. |
23324ae1 | 585 | */ |
ee49f540 | 586 | wxUniChar operator [](size_t i) const; |
23324ae1 FM |
587 | |
588 | /** | |
ee49f540 | 589 | Returns a writable reference to the @a i-th character of the string. |
23324ae1 | 590 | */ |
ee49f540 | 591 | wxUniCharRef operator [](size_t i); |
155032f9 | 592 | |
ee49f540 | 593 | //@} |
155032f9 | 594 | |
23324ae1 FM |
595 | |
596 | /** | |
ee49f540 | 597 | @member_group_name{conv, Conversions} |
155032f9 | 598 | |
ee49f540 FM |
599 | This section contains both implicit and explicit conversions to C style |
600 | strings. Although implicit conversion is quite convenient, you are advised | |
601 | to use wc_str() for the sake of clarity. | |
23324ae1 | 602 | */ |
23324ae1 | 603 | //@{ |
ee49f540 | 604 | |
23324ae1 | 605 | /** |
ee49f540 FM |
606 | Returns a lightweight intermediate class which is in turn implicitly |
607 | convertible to both @c const @c char* and to @c const @c wchar_t*. | |
608 | Given this ambiguity it is mostly better to use wc_str(), mb_str() or | |
609 | utf8_str() instead. | |
70897a70 | 610 | |
ee49f540 | 611 | Please see the @ref overview_unicode for more information about it. |
3c4f71cc | 612 | |
ee49f540 FM |
613 | Note that the returned value is not convertible to @c char* or |
614 | @c wchar_t*, use char_str() or wchar_str() if you need to pass | |
615 | string value to a function expecting non-const pointer. | |
3c4f71cc | 616 | |
ee49f540 | 617 | @see wc_str(), utf8_str(), c_str(), mb_str(), fn_str() |
23324ae1 | 618 | */ |
ee49f540 | 619 | wxCStrData c_str() const; |
23324ae1 | 620 | |
23324ae1 | 621 | /** |
ee49f540 FM |
622 | Returns an object with string data that is implicitly convertible to |
623 | @c char* pointer. Note that any change to the returned buffer is lost and so | |
624 | this function is only usable for passing strings to legacy libraries that | |
625 | don't have const-correct API. Use wxStringBuffer if you want to modify | |
626 | the string. | |
627 | ||
628 | @see c_str() | |
23324ae1 | 629 | */ |
ee49f540 | 630 | wxWritableCharBuffer char_str(const wxMBConv& conv = wxConvLibc) const; |
23324ae1 | 631 | |
23324ae1 | 632 | /** |
ee49f540 | 633 | Returns buffer of the specified type containing the string data. |
cc209a51 | 634 | |
ee49f540 FM |
635 | This method is only useful in template code, otherwise you should |
636 | directly call mb_str() or wc_str() if you need to retrieve a narrow or | |
637 | wide string from this wxString. The template parameter @a t should be | |
638 | either @c char or @c wchar_t. | |
23324ae1 | 639 | |
ee49f540 FM |
640 | Notice that retrieving a char buffer in UTF-8 build will return the |
641 | internal string representation in UTF-8 while in wchar_t build the char | |
642 | buffer will contain the conversion of the string to the encoding of the | |
643 | current locale (and so can fail). | |
cc209a51 | 644 | |
ee49f540 FM |
645 | @param len |
646 | If non-@NULL, filled with the length of the returned buffer. | |
cc209a51 | 647 | |
ee49f540 FM |
648 | @return |
649 | buffer containing the string contents in the specified type, | |
650 | notice that it may be @NULL if the conversion failed (e.g. Unicode | |
651 | string couldn't be converted to the current encoding when @a T is | |
652 | @c char). | |
653 | */ | |
654 | template <typename T> | |
655 | wxCharTypeBuffer<T> tchar_str(size_t *len = NULL) const; | |
cc209a51 | 656 | |
23324ae1 | 657 | /** |
ee49f540 FM |
658 | Returns a string representation suitable for passing to OS' functions |
659 | for file handling. | |
23324ae1 | 660 | */ |
ee49f540 | 661 | const wchar_t* fn_str() const; |
155032f9 | 662 | |
23324ae1 | 663 | /** |
ee49f540 | 664 | @overload |
23324ae1 | 665 | */ |
ee49f540 | 666 | const char* fn_str() const; |
23324ae1 FM |
667 | |
668 | /** | |
ee49f540 | 669 | @overload |
23324ae1 | 670 | */ |
ee49f540 | 671 | const wxCharBuffer fn_str() const; |
23324ae1 FM |
672 | |
673 | /** | |
ee49f540 FM |
674 | Returns the multibyte (C string) representation of the string |
675 | using @e conv's wxMBConv::cWC2MB method and returns wxCharBuffer. | |
676 | ||
677 | @see wc_str(), utf8_str(), c_str(), wxMBConv | |
23324ae1 | 678 | */ |
ee49f540 | 679 | const wxCharBuffer mb_str(const wxMBConv& conv = wxConvLibc) const; |
23324ae1 FM |
680 | |
681 | /** | |
ee49f540 FM |
682 | Converts the strings contents to UTF-8 and returns it either as a |
683 | temporary wxCharBuffer object or as a pointer to the internal | |
684 | string contents in UTF-8 build. | |
ca164e23 | 685 | |
ee49f540 | 686 | @see wc_str(), c_str(), mb_str() |
23324ae1 | 687 | */ |
197380a0 | 688 | const wxScopedCharBuffer utf8_str() const; |
23324ae1 FM |
689 | |
690 | /** | |
57ab6f23 | 691 | Converts the strings contents to the wide character representation |
ee49f540 FM |
692 | and returns it as a temporary wxWCharBuffer object (Unix and OS X) |
693 | or returns a pointer to the internal string contents in wide character | |
694 | mode (Windows). | |
23324ae1 | 695 | |
ee49f540 FM |
696 | The macro wxWX2WCbuf is defined as the correct return type (without const). |
697 | ||
698 | @see utf8_str(), c_str(), mb_str(), fn_str(), wchar_str() | |
23324ae1 | 699 | */ |
ee49f540 | 700 | const wchar_t* wc_str() const; |
23324ae1 | 701 | |
23324ae1 | 702 | /** |
ee49f540 | 703 | @overload |
23324ae1 | 704 | */ |
ee49f540 | 705 | const wxWCharBuffer wc_str() const; |
23324ae1 FM |
706 | |
707 | /** | |
ee49f540 FM |
708 | Returns an object with string data that is implicitly convertible to |
709 | @c char* pointer. Note that changes to the returned buffer may or may | |
710 | not be lost (depending on the build) and so this function is only usable for | |
711 | passing strings to legacy libraries that don't have const-correct API. Use | |
712 | wxStringBuffer if you want to modify the string. | |
713 | ||
714 | @see mb_str(), wc_str(), fn_str(), c_str(), char_str() | |
23324ae1 | 715 | */ |
ee49f540 | 716 | wxWritableWCharBuffer wchar_str() const; |
23324ae1 | 717 | |
23324ae1 | 718 | /** |
ee49f540 FM |
719 | Explicit conversion to C string in the internal representation (either |
720 | wchar_t* or UTF-8-encoded char*, depending on the build). | |
23324ae1 | 721 | */ |
ee49f540 | 722 | const wxStringCharType *wx_str() const; |
155032f9 | 723 | |
23324ae1 | 724 | /** |
ee49f540 FM |
725 | Converts the string to an 8-bit string in ISO-8859-1 encoding in the |
726 | form of a wxCharBuffer (Unicode builds only). | |
727 | ||
728 | This is a convenience method useful when storing binary data in | |
729 | wxString. It should be used @em only for this purpose. It is only valid | |
730 | to call this method on strings created using From8BitData(). | |
731 | ||
732 | @since 2.8.4 | |
733 | ||
734 | @see wxString::From8BitData() | |
23324ae1 | 735 | */ |
908c4056 | 736 | const wxScopedCharBuffer To8BitData() const; |
23324ae1 FM |
737 | |
738 | /** | |
ee49f540 FM |
739 | Converts the string to an ASCII, 7-bit string in the form of |
740 | a wxCharBuffer (Unicode builds only) or a C string (ANSI builds). | |
e33efe48 VZ |
741 | |
742 | Note that this conversion is only lossless if the string contains only | |
743 | ASCII characters as all the non-ASCII ones are replaced with the @c '_' | |
744 | (underscore) character. | |
745 | ||
746 | Use mb_str() or utf8_str() to convert to other encodings. | |
23324ae1 | 747 | */ |
ee49f540 | 748 | const char* ToAscii() const; |
23324ae1 FM |
749 | |
750 | /** | |
ee49f540 | 751 | @overload |
23324ae1 | 752 | */ |
ee49f540 | 753 | const wxCharBuffer ToAscii() const; |
23324ae1 | 754 | |
e3ab6952 VZ |
755 | /** |
756 | Return the string as an std::string in current locale encoding. | |
757 | ||
758 | Note that if the conversion of (Unicode) string contents to the current | |
759 | locale fails, the return string will be empty. Be sure to check for | |
760 | this to avoid silent data loss. | |
761 | ||
762 | Instead of using this function it's also possible to write | |
763 | @code | |
764 | std::string s; | |
765 | wxString wxs; | |
766 | ... | |
767 | s = std::string(wxs); | |
768 | @endcode | |
769 | but using ToStdString() may make the code more clear. | |
770 | ||
771 | @since 2.9.1 | |
772 | */ | |
773 | std::string ToStdString() const; | |
774 | ||
775 | /** | |
776 | Return the string as an std::wstring. | |
777 | ||
778 | Unlike ToStdString(), there is no danger of data loss when using this | |
779 | function. | |
780 | ||
781 | @since 2.9.1 | |
782 | */ | |
783 | std::wstring ToStdWstring() const; | |
784 | ||
23324ae1 | 785 | /** |
ee49f540 | 786 | Same as utf8_str(). |
23324ae1 | 787 | */ |
197380a0 | 788 | const wxScopedCharBuffer ToUTF8() const; |
0c7db140 | 789 | |
ee49f540 | 790 | //@} |
0c7db140 | 791 | |
23324ae1 FM |
792 | |
793 | /** | |
ee49f540 | 794 | @member_group_name{concat, Concatenation} |
0c7db140 | 795 | |
ee49f540 | 796 | Almost anything may be concatenated (appended to) with a string! |
155032f9 VZ |
797 | |
798 | Note that the various operator<<() overloads work as C++ stream insertion | |
799 | operators. They insert the given value into the string. | |
ee49f540 | 800 | Precision and format cannot be set using them. Use Printf() instead. |
23324ae1 | 801 | |
ee49f540 | 802 | See also the insert() and append() STL-like functions. |
23324ae1 | 803 | */ |
ee49f540 | 804 | //@{ |
23324ae1 | 805 | |
23324ae1 | 806 | /** |
ee49f540 | 807 | Appends the string literal @a psz. |
23324ae1 | 808 | */ |
ee49f540 | 809 | wxString& Append(const char* psz); |
23324ae1 FM |
810 | |
811 | /** | |
ee49f540 | 812 | Appends the wide string literal @a pwz. |
23324ae1 | 813 | */ |
ee49f540 | 814 | wxString& Append(const wchar_t* pwz); |
23324ae1 FM |
815 | |
816 | /** | |
ee49f540 | 817 | Appends the string literal @a psz with max length @a nLen. |
23324ae1 | 818 | */ |
ee49f540 | 819 | wxString& Append(const char* psz, size_t nLen); |
23324ae1 FM |
820 | |
821 | /** | |
ee49f540 | 822 | Appends the wide string literal @a psz with max length @a nLen. |
23324ae1 | 823 | */ |
ee49f540 | 824 | wxString& Append(const wchar_t* pwz, size_t nLen); |
23324ae1 FM |
825 | |
826 | /** | |
ee49f540 | 827 | Appends the string @a s. |
23324ae1 | 828 | */ |
ee49f540 | 829 | wxString& Append(const wxString& s); |
23324ae1 | 830 | |
23324ae1 | 831 | /** |
ee49f540 | 832 | Appends the character @a ch @a count times. |
23324ae1 | 833 | */ |
ee49f540 | 834 | wxString &Append(wxUniChar ch, size_t count = 1u); |
23324ae1 FM |
835 | |
836 | /** | |
ee49f540 | 837 | Prepends @a str to this string, returning a reference to this string. |
23324ae1 | 838 | */ |
ee49f540 | 839 | wxString& Prepend(const wxString& str); |
23324ae1 FM |
840 | |
841 | /** | |
ee49f540 | 842 | Concatenation: returns a new string equal to the concatenation of the operands. |
23324ae1 | 843 | */ |
ee49f540 | 844 | wxString operator +(const wxString& x, const wxString& y); |
155032f9 | 845 | |
23324ae1 | 846 | /** |
ee49f540 | 847 | @overload |
23324ae1 | 848 | */ |
ee49f540 | 849 | wxString operator +(const wxString& x, wxUniChar y); |
23324ae1 | 850 | |
ee49f540 FM |
851 | wxString& operator<<(const wxString& s); |
852 | wxString& operator<<(const char* psz); | |
853 | wxString& operator<<(const wchar_t* pwz); | |
854 | wxString& operator<<(const wxCStrData& psz); | |
855 | wxString& operator<<(char ch); | |
856 | wxString& operator<<(unsigned char ch); | |
857 | wxString& operator<<(wchar_t ch); | |
858 | wxString& operator<<(const wxCharBuffer& s); | |
859 | wxString& operator<<(const wxWCharBuffer& s); | |
4d056a68 | 860 | wxString& operator<<(wxUniChar ch); |
ee49f540 FM |
861 | wxString& operator<<(wxUniCharRef ch); |
862 | wxString& operator<<(unsigned int ui); | |
863 | wxString& operator<<(long l); | |
864 | wxString& operator<<(unsigned long ul); | |
865 | wxString& operator<<(wxLongLong_t ll); | |
866 | wxString& operator<<(wxULongLong_t ul); | |
867 | wxString& operator<<(float f); | |
868 | wxString& operator<<(double d); | |
869 | ||
870 | /** | |
871 | Concatenation in place: the argument is appended to the string. | |
23324ae1 | 872 | */ |
ee49f540 | 873 | void operator +=(const wxString& str); |
155032f9 | 874 | |
ee49f540 FM |
875 | /** |
876 | @overload | |
877 | */ | |
878 | void operator +=(wxUniChar c); | |
155032f9 | 879 | |
ee49f540 | 880 | //@} |
155032f9 | 881 | |
23324ae1 FM |
882 | |
883 | /** | |
ee49f540 FM |
884 | @member_group_name{cmp, Comparison} |
885 | ||
886 | The default comparison function Cmp() is case-sensitive and so is the default | |
887 | version of IsSameAs(). For case insensitive comparisons you should use CmpNoCase() | |
888 | or give a second parameter to IsSameAs(). This last function is maybe more | |
889 | convenient if only equality of the strings matters because it returns a boolean | |
890 | @true value if the strings are the same and not 0 (which is usually @false | |
891 | in C) as Cmp() does. | |
892 | ||
893 | Matches() is a poor man's regular expression matcher: it only understands | |
894 | '*' and '?' metacharacters in the sense of DOS command line interpreter. | |
895 | ||
896 | StartsWith() is helpful when parsing a line of text which should start | |
897 | with some predefined prefix and is more efficient than doing direct string | |
898 | comparison as you would also have to precalculate the length of the prefix. | |
155032f9 | 899 | |
ee49f540 | 900 | See also the compare() STL-like function. |
23324ae1 | 901 | */ |
ee49f540 FM |
902 | //@{ |
903 | ||
904 | /** | |
905 | Case-sensitive comparison. | |
906 | Returns a positive value if the string is greater than the argument, | |
907 | zero if it is equal to it or a negative value if it is less than the | |
908 | argument (same semantics as the standard @c strcmp() function). | |
909 | ||
910 | @see CmpNoCase(), IsSameAs(). | |
911 | */ | |
912 | int Cmp(const wxString& s) const; | |
913 | ||
914 | /** | |
915 | Case-insensitive comparison. | |
916 | Returns a positive value if the string is greater than the argument, | |
917 | zero if it is equal to it or a negative value if it is less than the | |
918 | argument (same semantics as the standard @c strcmp() function). | |
919 | ||
920 | @see Cmp(), IsSameAs(). | |
921 | */ | |
922 | int CmpNoCase(const wxString& s) const; | |
923 | ||
924 | /** | |
155032f9 VZ |
925 | Test whether the string is equal to another string @a s. |
926 | ||
ee49f540 FM |
927 | The test is case-sensitive if @a caseSensitive is @true (default) or not if it is |
928 | @false. | |
155032f9 VZ |
929 | |
930 | @return @true if the string is equal to the other one, @false otherwise. | |
931 | ||
ee49f540 FM |
932 | @see Cmp(), CmpNoCase() |
933 | */ | |
155032f9 VZ |
934 | bool IsSameAs(const wxString& s, bool caseSensitive = true) const; |
935 | ||
ee49f540 | 936 | /** |
155032f9 VZ |
937 | Test whether the string is equal to the single character @a ch. |
938 | ||
939 | The test is case-sensitive if @a caseSensitive is @true (default) or not if it is | |
940 | @false. | |
941 | ||
942 | @return @true if the string is equal to this character, @false otherwise. | |
943 | ||
944 | @see Cmp(), CmpNoCase() | |
ee49f540 FM |
945 | */ |
946 | bool IsSameAs(wxUniChar ch, bool caseSensitive = true) const; | |
947 | ||
948 | /** | |
949 | Returns @true if the string contents matches a mask containing '*' and '?'. | |
950 | */ | |
951 | bool Matches(const wxString& mask) const; | |
23324ae1 FM |
952 | |
953 | /** | |
7c913512 | 954 | This function can be used to test if the string starts with the specified |
155032f9 VZ |
955 | @a prefix. |
956 | ||
957 | If it does, the function will return @true and put the rest of the string | |
ee49f540 FM |
958 | (i.e. after the prefix) into @a rest string if it is not @NULL. |
959 | Otherwise, the function returns @false and doesn't modify the @a rest. | |
23324ae1 | 960 | */ |
6d95e7be | 961 | bool StartsWith(const wxString& prefix, wxString *rest = NULL) const; |
23324ae1 | 962 | |
23324ae1 | 963 | /** |
ee49f540 FM |
964 | This function can be used to test if the string ends with the specified |
965 | @e suffix. If it does, the function will return @true and put the | |
966 | beginning of the string before the suffix into @e rest string if it is not | |
967 | @NULL. Otherwise, the function returns @false and doesn't | |
968 | modify the @e rest. | |
23324ae1 | 969 | */ |
ee49f540 | 970 | bool EndsWith(const wxString& suffix, wxString *rest = NULL) const; |
155032f9 | 971 | |
ee49f540 | 972 | //@} |
155032f9 VZ |
973 | |
974 | ||
ee49f540 FM |
975 | /** |
976 | @member_group_name{substring, Substring extraction} | |
977 | ||
978 | These functions allow you to extract a substring from the string. The | |
979 | original string is not modified and the function returns the extracted | |
980 | substring. | |
155032f9 | 981 | |
ee49f540 FM |
982 | See also the at() and the substr() STL-like functions. |
983 | */ | |
984 | ||
985 | /** | |
986 | Returns a substring starting at @e first, with length @e count, or the rest of | |
987 | the string if @a count is the default value. | |
988 | */ | |
989 | wxString Mid(size_t first, size_t nCount = wxString::npos) const; | |
23324ae1 FM |
990 | |
991 | /** | |
ee49f540 | 992 | Returns the part of the string between the indices @a from and @a to |
23324ae1 | 993 | inclusive. |
155032f9 | 994 | |
23324ae1 FM |
995 | This is a wxWidgets 1.xx compatibility function, use Mid() |
996 | instead (but note that parameters have different meaning). | |
997 | */ | |
328f5751 | 998 | wxString SubString(size_t from, size_t to) const; |
155032f9 | 999 | |
ee49f540 FM |
1000 | /** |
1001 | Same as Mid() (substring extraction). | |
1002 | */ | |
1003 | wxString operator()(size_t start, size_t len) const; | |
1004 | ||
1005 | /** | |
1006 | Returns the first @a count characters of the string. | |
1007 | */ | |
1008 | wxString Left(size_t count) const; | |
1009 | ||
1010 | /** | |
1011 | Returns the last @a count characters. | |
1012 | */ | |
1013 | wxString Right(size_t count) const; | |
1014 | ||
1015 | /** | |
1016 | Gets all the characters after the first occurrence of @e ch. | |
1017 | Returns the empty string if @e ch is not found. | |
1018 | */ | |
1019 | wxString AfterFirst(wxUniChar ch) const; | |
1020 | ||
1021 | /** | |
1022 | Gets all the characters after the last occurrence of @e ch. | |
1023 | Returns the whole string if @e ch is not found. | |
1024 | */ | |
1025 | wxString AfterLast(wxUniChar ch) const; | |
1026 | ||
1027 | /** | |
1028 | Gets all characters before the first occurrence of @e ch. | |
1029 | Returns the whole string if @a ch is not found. | |
6becc1e6 VZ |
1030 | |
1031 | @param ch The character to look for. | |
1032 | @param rest Filled with the part of the string following the first | |
1033 | occurrence of @a ch or cleared if it was not found. The same string | |
1034 | is returned by AfterFirst() but it is more efficient to use this | |
1035 | output parameter if both the "before" and "after" parts are needed | |
1036 | than calling both functions one after the other. This parameter is | |
1037 | available in wxWidgets version 2.9.2 and later only. | |
1038 | @return Part of the string before the first occurrence of @a ch. | |
ee49f540 | 1039 | */ |
6becc1e6 | 1040 | wxString BeforeFirst(wxUniChar ch, wxString *rest = NULL) const; |
ee49f540 FM |
1041 | |
1042 | /** | |
1043 | Gets all characters before the last occurrence of @e ch. | |
1044 | Returns the empty string if @a ch is not found. | |
6becc1e6 VZ |
1045 | |
1046 | @param ch The character to look for. | |
1047 | @param rest Filled with the part of the string following the last | |
1048 | occurrence of @a ch or the copy of this string if it was not found. | |
1049 | The same string is returned by AfterLast() but it is more efficient | |
1050 | to use this output parameter if both the "before" and "after" parts | |
1051 | are needed than calling both functions one after the other. This | |
1052 | parameter is available in wxWidgets version 2.9.2 and later only. | |
1053 | @return Part of the string before the last occurrence of @a ch. | |
ee49f540 | 1054 | */ |
6becc1e6 | 1055 | wxString BeforeLast(wxUniChar ch, wxString *rest = NULL) const; |
155032f9 | 1056 | |
ee49f540 | 1057 | //@} |
155032f9 VZ |
1058 | |
1059 | ||
ee49f540 FM |
1060 | /** |
1061 | @member_group_name{caseconv, Case conversion} | |
23324ae1 | 1062 | |
ee49f540 FM |
1063 | The MakeXXX() variants modify the string in place, while the other functions |
1064 | return a new string which contains the original text converted to the upper or | |
1065 | lower case and leave the original string unchanged. | |
1066 | */ | |
23324ae1 | 1067 | //@{ |
ee49f540 | 1068 | |
23324ae1 | 1069 | /** |
ee49f540 FM |
1070 | Return the copy of the string with the first string character in the |
1071 | upper case and the subsequent ones in the lower case. | |
70897a70 | 1072 | |
ee49f540 | 1073 | @since 2.9.0 |
3c4f71cc | 1074 | |
ee49f540 FM |
1075 | @see MakeCapitalized() |
1076 | */ | |
1077 | wxString Capitalize() const; | |
3c4f71cc | 1078 | |
ee49f540 FM |
1079 | /** |
1080 | Returns this string converted to the lower case. | |
1081 | ||
1082 | @see MakeLower() | |
23324ae1 | 1083 | */ |
ee49f540 FM |
1084 | wxString Lower() const; |
1085 | ||
1086 | /** | |
1087 | Same as MakeLower. | |
1088 | This is a wxWidgets 1.xx compatibility function; you should not use it in new | |
1089 | code. | |
1090 | */ | |
1091 | void LowerCase(); | |
1092 | ||
1093 | /** | |
1094 | Converts the first characters of the string to the upper case and all | |
1095 | the subsequent ones to the lower case and returns the result. | |
1096 | ||
1097 | @since 2.9.0 | |
1098 | ||
1099 | @see Capitalize() | |
1100 | */ | |
1101 | wxString& MakeCapitalized(); | |
1102 | ||
1103 | /** | |
1104 | Converts all characters to lower case and returns the reference to the | |
1105 | modified string. | |
1106 | ||
1107 | @see Lower() | |
1108 | */ | |
1109 | wxString& MakeLower(); | |
1110 | ||
1111 | /** | |
1112 | Converts all characters to upper case and returns the reference to the | |
1113 | modified string. | |
1114 | ||
1115 | @see Upper() | |
1116 | */ | |
1117 | wxString& MakeUpper(); | |
155032f9 | 1118 | |
ee49f540 FM |
1119 | /** |
1120 | Returns this string converted to upper case. | |
1121 | ||
1122 | @see MakeUpper() | |
1123 | */ | |
1124 | wxString Upper() const; | |
1125 | ||
1126 | /** | |
1127 | The same as MakeUpper(). | |
1128 | ||
1129 | This is a wxWidgets 1.xx compatibility function; you should not use it in new | |
1130 | code. | |
1131 | */ | |
1132 | void UpperCase(); | |
155032f9 | 1133 | |
23324ae1 | 1134 | //@} |
155032f9 VZ |
1135 | |
1136 | ||
ee49f540 FM |
1137 | /** |
1138 | @member_group_name{search, Searching and replacing} | |
23324ae1 | 1139 | |
ee49f540 FM |
1140 | These functions replace the standard @c strchr() and @c strstr() |
1141 | functions. | |
155032f9 | 1142 | |
ee49f540 FM |
1143 | See also the find(), rfind(), replace() STL-like functions. |
1144 | */ | |
23324ae1 | 1145 | //@{ |
ee49f540 | 1146 | |
23324ae1 | 1147 | /** |
155032f9 | 1148 | Searches for the given character @a ch. |
ee49f540 | 1149 | Returns the position or @c wxNOT_FOUND if not found. |
23324ae1 | 1150 | */ |
ee49f540 FM |
1151 | int Find(wxUniChar ch, bool fromEnd = false) const; |
1152 | ||
1153 | /** | |
155032f9 | 1154 | Searches for the given string @a sub. |
ee49f540 FM |
1155 | Returns the starting position or @c wxNOT_FOUND if not found. |
1156 | */ | |
1157 | int Find(const wxString& sub) const; | |
1158 | ||
1159 | /** | |
1160 | Same as Find(). | |
155032f9 | 1161 | |
ee49f540 FM |
1162 | This is a wxWidgets 1.xx compatibility function; |
1163 | you should not use it in new code. | |
1164 | */ | |
1165 | int First(wxUniChar ch) const; | |
1166 | ||
1167 | /** | |
1168 | Same as Find(). | |
155032f9 | 1169 | |
ee49f540 FM |
1170 | This is a wxWidgets 1.xx compatibility function; |
1171 | you should not use it in new code. | |
1172 | */ | |
1173 | int First(const wxString& str) const; | |
1174 | ||
1175 | /** | |
1176 | Replace first (or all) occurrences of substring with another one. | |
155032f9 | 1177 | |
ee49f540 FM |
1178 | @param strOld |
1179 | The string to search for replacing. | |
1180 | @param strNew | |
1181 | The substitution string. | |
1182 | @param replaceAll | |
155032f9 | 1183 | If @true a global replace will be done (default), otherwise only the |
ee49f540 | 1184 | first occurrence will be replaced. |
155032f9 | 1185 | |
ee49f540 FM |
1186 | Returns the number of replacements made. |
1187 | */ | |
1188 | size_t Replace(const wxString& strOld, const wxString& strNew, | |
1189 | bool replaceAll = true); | |
1190 | ||
23324ae1 FM |
1191 | //@} |
1192 | ||
ee49f540 FM |
1193 | |
1194 | ||
1195 | /** | |
1196 | @member_group_name{numconv, Conversion to numbers} | |
1197 | ||
1198 | The string provides functions for conversion to signed and unsigned integer and | |
69d31e31 VZ |
1199 | floating point numbers. |
1200 | ||
1201 | All functions take a pointer to the variable to put the numeric value | |
1202 | in and return @true if the @b entire string could be converted to a | |
1203 | number. Notice if there is a valid number in the beginning of the | |
1204 | string, it is returned in the output parameter even if the function | |
1205 | returns @false because there is more text following it. | |
1206 | */ | |
ee49f540 FM |
1207 | //@{ |
1208 | ||
23324ae1 | 1209 | /** |
155032f9 VZ |
1210 | Attempts to convert the string to a floating point number. |
1211 | ||
1212 | Returns @true on success (the number is stored in the location pointed to by | |
1213 | @a val) or @false if the string does not represent such number (the value of | |
69d31e31 | 1214 | @a val may still be modified in this case). |
155032f9 | 1215 | |
529e491c FM |
1216 | Note that unlike ToCDouble() this function uses a localized version of |
1217 | @c wxStrtod() and thus needs as decimal point (and thousands separator) the | |
1218 | locale-specific decimal point. Thus you should use this function only when | |
1219 | you are sure that this string contains a floating point number formatted with | |
1220 | the rules of the locale currently in use (see wxLocale). | |
155032f9 | 1221 | |
6686fbad VZ |
1222 | Also notice that even this function is locale-specific it does not |
1223 | support strings with thousands separators in them, even if the current | |
1224 | locale uses digits grouping. You may use wxNumberFormatter::FromString() | |
1225 | to parse such strings. | |
1226 | ||
1227 | Please refer to the documentation of the standard function @c strtod() | |
1228 | for more details about the supported syntax. | |
3c4f71cc | 1229 | |
529e491c | 1230 | @see ToCDouble(), ToLong(), ToULong() |
23324ae1 | 1231 | */ |
5267aefd | 1232 | bool ToDouble(double* val) const; |
23324ae1 FM |
1233 | |
1234 | /** | |
69d31e31 VZ |
1235 | Variant of ToDouble() always working in "C" locale. |
1236 | ||
529e491c FM |
1237 | Works like ToDouble() but unlike it this function expects the floating point |
1238 | number to be formatted always with the rules dictated by the "C" locale | |
1239 | (in particular, the decimal point must be a dot), independently from the | |
1240 | current application-wide locale (see wxLocale). | |
1241 | ||
1242 | @see ToDouble(), ToLong(), ToULong() | |
1243 | */ | |
1244 | bool ToCDouble(double* val) const; | |
1245 | ||
1246 | /** | |
155032f9 VZ |
1247 | Attempts to convert the string to a signed integer in base @a base. |
1248 | ||
529e491c | 1249 | Returns @true on success in which case the number is stored in the location |
4cc4bfaf | 1250 | pointed to by @a val or @false if the string does not represent a |
69d31e31 VZ |
1251 | valid number in the given base (the value of @a val may still be |
1252 | modified in this case). | |
155032f9 | 1253 | |
4cc4bfaf | 1254 | The value of @a base must be comprised between 2 and 36, inclusive, or |
23324ae1 FM |
1255 | be a special value 0 which means that the usual rules of @c C numbers are |
1256 | applied: if the number starts with @c 0x it is considered to be in base | |
1257 | 16, if it starts with @c 0 - in base 8 and in base 10 otherwise. Note | |
1258 | that you may not want to specify the base 0 if you are parsing the numbers | |
1259 | which may have leading zeroes as they can yield unexpected (to the user not | |
1260 | familiar with C) results. | |
155032f9 | 1261 | |
529e491c | 1262 | Note that unlike ToCLong() this function uses a localized version of |
155032f9 | 1263 | @c wxStrtol(). Thus you should use this function only when you are sure |
529e491c FM |
1264 | that this string contains an integer number formatted with |
1265 | the rules of the locale currently in use (see wxLocale). | |
155032f9 | 1266 | |
6686fbad VZ |
1267 | As with ToDouble(), this function does not support strings containing |
1268 | thousands separators even if the current locale uses digits grouping. | |
1269 | You may use wxNumberFormatter::FromString() to parse such strings. | |
1270 | ||
1271 | Please refer to the documentation of the standard function @c strtol() | |
1272 | for more details about the supported syntax. | |
3c4f71cc | 1273 | |
529e491c | 1274 | @see ToCDouble(), ToDouble(), ToULong() |
23324ae1 | 1275 | */ |
5267aefd | 1276 | bool ToLong(long* val, int base = 10) const; |
23324ae1 FM |
1277 | |
1278 | /** | |
69d31e31 VZ |
1279 | Variant of ToLong() always working in "C" locale. |
1280 | ||
529e491c | 1281 | Works like ToLong() but unlike it this function expects the integer |
155032f9 | 1282 | number to be formatted always with the rules dictated by the "C" locale, |
529e491c FM |
1283 | independently from the current application-wide locale (see wxLocale). |
1284 | ||
1285 | @see ToDouble(), ToLong(), ToULong() | |
1286 | */ | |
1287 | bool ToCLong(long* val, int base = 10) const; | |
1288 | ||
1289 | /** | |
1290 | This is exactly the same as ToLong() but works with 64 bit integer numbers. | |
155032f9 | 1291 | |
23324ae1 FM |
1292 | Notice that currently it doesn't work (always returns @false) if parsing of 64 |
1293 | bit numbers is not supported by the underlying C run-time library. Compilers | |
1294 | with C99 support and Microsoft Visual C++ version 7 and higher do support this. | |
3c4f71cc | 1295 | |
4cc4bfaf | 1296 | @see ToLong(), ToULongLong() |
23324ae1 | 1297 | */ |
5267aefd | 1298 | bool ToLongLong(wxLongLong_t* val, int base = 10) const; |
23324ae1 FM |
1299 | |
1300 | /** | |
529e491c | 1301 | Attempts to convert the string to an unsigned integer in base @a base. |
155032f9 | 1302 | |
23324ae1 | 1303 | Returns @true on success in which case the number is stored in the |
4cc4bfaf | 1304 | location pointed to by @a val or @false if the string does not |
69d31e31 VZ |
1305 | represent a valid number in the given base (the value of @a val may |
1306 | still be modified in this case). | |
4701dc09 FM |
1307 | |
1308 | Please notice that this function behaves in the same way as the standard | |
1309 | @c strtoul() and so it simply converts negative numbers to unsigned | |
1310 | representation instead of rejecting them (e.g. -1 is returned as @c ULONG_MAX). | |
1311 | ||
529e491c FM |
1312 | See ToLong() for the more detailed description of the @a base parameter |
1313 | (and of the locale-specific behaviour of this function). | |
3c4f71cc | 1314 | |
529e491c | 1315 | @see ToCULong(), ToDouble(), ToLong() |
23324ae1 | 1316 | */ |
5267aefd | 1317 | bool ToULong(unsigned long* val, int base = 10) const; |
23324ae1 | 1318 | |
529e491c | 1319 | /** |
69d31e31 VZ |
1320 | Variant of ToULong() always working in "C" locale. |
1321 | ||
529e491c | 1322 | Works like ToULong() but unlike it this function expects the integer |
155032f9 | 1323 | number to be formatted always with the rules dictated by the "C" locale, |
529e491c FM |
1324 | independently from the current application-wide locale (see wxLocale). |
1325 | ||
1326 | @see ToDouble(), ToLong(), ToULong() | |
1327 | */ | |
1328 | bool ToCULong(unsigned long* val, int base = 10) const; | |
1329 | ||
23324ae1 | 1330 | /** |
69d31e31 VZ |
1331 | This is exactly the same as ToULong() but works with 64 bit integer |
1332 | numbers. | |
1333 | ||
23324ae1 FM |
1334 | Please see ToLongLong() for additional remarks. |
1335 | */ | |
5267aefd | 1336 | bool ToULongLong(wxULongLong_t* val, int base = 10) const; |
23324ae1 | 1337 | |
23324ae1 FM |
1338 | //@} |
1339 | ||
23324ae1 FM |
1340 | |
1341 | /** | |
ee49f540 | 1342 | @member_group_name{fmt, Formatting and printing} |
23324ae1 | 1343 | |
ee49f540 | 1344 | Both formatted versions (Printf/() and stream-like insertion operators |
155032f9 VZ |
1345 | exist (for basic types only). |
1346 | ||
ee49f540 FM |
1347 | See also the static Format() and FormatV() functions. |
1348 | */ | |
23324ae1 | 1349 | //@{ |
4701dc09 | 1350 | |
ee49f540 FM |
1351 | /** |
1352 | Similar to the standard function @e sprintf(). Returns the number of | |
1353 | characters written, or an integer less than zero on error. | |
1354 | Note that if @c wxUSE_PRINTF_POS_PARAMS is set to 1, then this function supports | |
1355 | Unix98-style positional parameters: | |
4701dc09 | 1356 | |
8329f1d1 VZ |
1357 | @code |
1358 | wxString str; | |
1359 | ||
1360 | str.Printf(wxT("%d %d %d"), 1, 2, 3); | |
1361 | // str now contains "1 2 3" | |
1362 | ||
1363 | str.Printf(wxT("%2$d %3$d %1$d"), 1, 2, 3); | |
1364 | // str now contains "2 3 1" | |
1365 | @endcode | |
1366 | ||
ee49f540 FM |
1367 | @note This function will use a safe version of @e vsprintf() (usually called |
1368 | @e vsnprintf()) whenever available to always allocate the buffer of correct | |
1369 | size. Unfortunately, this function is not available on all platforms and the | |
1370 | dangerous @e vsprintf() will be used then which may lead to buffer overflows. | |
23324ae1 | 1371 | */ |
ee49f540 FM |
1372 | int Printf(const wxString& pszFormat, ...); |
1373 | ||
1374 | /** | |
1375 | Similar to vprintf. Returns the number of characters written, or an integer | |
1376 | less than zero | |
1377 | on error. | |
1378 | */ | |
1379 | int PrintfV(const wxString& pszFormat, va_list argPtr); | |
1380 | ||
23324ae1 | 1381 | //@} |
155032f9 VZ |
1382 | |
1383 | ||
ee49f540 FM |
1384 | /** |
1385 | @member_group_name{mem, Memory management} | |
23324ae1 | 1386 | |
155032f9 VZ |
1387 | The following are "advanced" functions and they will be needed rarely. |
1388 | Alloc() and Shrink() are only interesting for optimization purposes. | |
1389 | wxStringBuffer and wxStringBufferLength classes may be very useful when working | |
ee49f540 | 1390 | with some external API which requires the caller to provide a writable buffer. |
155032f9 | 1391 | |
ee49f540 FM |
1392 | See also the reserve() and resize() STL-like functions. |
1393 | */ | |
1394 | //@{ | |
155032f9 | 1395 | |
23324ae1 | 1396 | /** |
ee49f540 | 1397 | Preallocate enough space for wxString to store @a nLen characters. |
0c7db140 | 1398 | |
ee49f540 FM |
1399 | Please note that this method does the same thing as the standard |
1400 | reserve() one and shouldn't be used in new code. | |
1401 | ||
1402 | This function may be used to increase speed when the string is | |
1403 | constructed by repeated concatenation as in | |
1404 | ||
1405 | @code | |
1406 | // delete all vowels from the string | |
1407 | wxString DeleteAllVowels(const wxString& original) | |
1408 | { | |
1409 | wxString result; | |
1410 | ||
1411 | size_t len = original.length(); | |
1412 | ||
1413 | result.Alloc(len); | |
1414 | ||
1415 | for ( size_t n = 0; n < len; n++ ) | |
1416 | { | |
1417 | if ( strchr("aeuio", tolower(original[n])) == NULL ) | |
1418 | result += original[n]; | |
1419 | } | |
1420 | ||
1421 | return result; | |
1422 | } | |
1423 | @endcode | |
1424 | ||
1425 | because it will avoid the need to reallocate string memory many times | |
1426 | (in case of long strings). Note that it does not set the maximal length | |
1427 | of a string -- it will still expand if more than @a nLen characters are | |
1428 | stored in it. Also, it does not truncate the existing string (use | |
1429 | Truncate() for this) even if its current length is greater than @a nLen. | |
1430 | ||
1431 | @return @true if memory was successfully allocated, @false otherwise. | |
23324ae1 | 1432 | */ |
ee49f540 | 1433 | bool Alloc(size_t nLen); |
23324ae1 FM |
1434 | |
1435 | /** | |
ee49f540 FM |
1436 | Minimizes the string's memory. This can be useful after a call to |
1437 | Alloc() if too much memory were preallocated. | |
23324ae1 | 1438 | */ |
ee49f540 | 1439 | bool Shrink(); |
23324ae1 | 1440 | |
23324ae1 | 1441 | /** |
ee49f540 | 1442 | Returns a deep copy of the string. |
0c7db140 | 1443 | |
ee49f540 FM |
1444 | That is, the returned string is guaranteed to not share data with this |
1445 | string when using reference-counted wxString implementation. | |
0c7db140 | 1446 | |
ee49f540 FM |
1447 | This method is primarily useful for passing strings between threads |
1448 | (because wxString is not thread-safe). Unlike creating a copy using | |
1449 | @c wxString(c_str()), Clone() handles embedded NULs correctly. | |
0c7db140 | 1450 | |
ee49f540 FM |
1451 | @since 2.9.0 |
1452 | */ | |
1453 | wxString Clone() const; | |
1454 | ||
1455 | /** | |
1456 | Empties the string and frees memory occupied by it. | |
155032f9 | 1457 | |
ee49f540 | 1458 | @see Empty() |
23324ae1 | 1459 | */ |
ee49f540 | 1460 | void Clear(); |
155032f9 | 1461 | |
ee49f540 FM |
1462 | //@} |
1463 | ||
1464 | ||
23324ae1 FM |
1465 | |
1466 | /** | |
ee49f540 | 1467 | @member_group_name{misc, Miscellaneous} |
3c4f71cc | 1468 | |
ee49f540 | 1469 | Miscellaneous other string functions. |
23324ae1 | 1470 | */ |
ee49f540 | 1471 | //@{ |
23324ae1 | 1472 | |
062dc5fc | 1473 | /** |
ee49f540 | 1474 | Returns @true if target appears anywhere in wxString; else @false. |
155032f9 | 1475 | |
ee49f540 FM |
1476 | This is a wxWidgets 1.xx compatibility function; you should not use it in new code. |
1477 | */ | |
1478 | bool Contains(const wxString& str) const; | |
062dc5fc | 1479 | |
ee49f540 FM |
1480 | /** |
1481 | Makes the string empty, but doesn't free memory occupied by the string. | |
155032f9 | 1482 | |
ee49f540 FM |
1483 | @see Clear(). |
1484 | */ | |
1485 | void Empty(); | |
062dc5fc | 1486 | |
ee49f540 FM |
1487 | /** |
1488 | Returns the number of occurrences of @e ch in the string. | |
155032f9 | 1489 | |
ee49f540 FM |
1490 | This is a wxWidgets 1.xx compatibility function; you should not use it in new code. |
1491 | */ | |
1492 | int Freq(wxUniChar ch) const; | |
062dc5fc | 1493 | |
ee49f540 FM |
1494 | /** |
1495 | Returns @true if the string contains only ASCII characters. | |
1496 | See wxUniChar::IsAscii for more details. | |
4701dc09 | 1497 | |
ee49f540 FM |
1498 | This is a wxWidgets 1.xx compatibility function; you should not use it in new |
1499 | code. | |
1500 | */ | |
1501 | bool IsAscii() const; | |
062dc5fc | 1502 | |
23324ae1 | 1503 | /** |
ee49f540 | 1504 | Returns @true if the string is an integer (with possible sign). |
155032f9 | 1505 | |
ee49f540 | 1506 | This is a wxWidgets 1.xx compatibility function; you should not use it in new code. |
23324ae1 | 1507 | */ |
ee49f540 | 1508 | bool IsNumber() const; |
23324ae1 | 1509 | |
23324ae1 | 1510 | /** |
ee49f540 | 1511 | Returns @true if the string is a word. |
155032f9 | 1512 | |
ee49f540 FM |
1513 | This is a wxWidgets 1.xx compatibility function; you should not use it in new code. |
1514 | */ | |
1515 | bool IsWord() const; | |
0c7db140 | 1516 | |
ee49f540 FM |
1517 | /** |
1518 | Adds @a count copies of @a chPad to the beginning, or to the end of the | |
1519 | string (the default). | |
155032f9 | 1520 | |
ee49f540 | 1521 | Removes spaces from the left or from the right (default). |
23324ae1 | 1522 | */ |
ee49f540 | 1523 | wxString& Pad(size_t count, wxUniChar chPad = ' ', bool fromRight = true); |
155032f9 | 1524 | |
ee49f540 FM |
1525 | /** |
1526 | Removes all characters from the string starting at @a pos. | |
1527 | Use Truncate() as a more readable alternative. | |
155032f9 | 1528 | |
ee49f540 FM |
1529 | This is a wxWidgets 1.xx compatibility function; you should not use it in new code. |
1530 | */ | |
1531 | wxString& Remove(size_t pos); | |
155032f9 | 1532 | |
ee49f540 FM |
1533 | /** |
1534 | Removes @a len characters from the string, starting at @a pos. | |
155032f9 | 1535 | |
ee49f540 FM |
1536 | This is a wxWidgets 1.xx compatibility function; you should not use it in new code. |
1537 | */ | |
1538 | wxString& Remove(size_t pos, size_t len); | |
23324ae1 FM |
1539 | |
1540 | /** | |
ee49f540 | 1541 | Removes the last character. |
23324ae1 | 1542 | */ |
ee49f540 | 1543 | wxString& RemoveLast(size_t n = 1); |
bcc8c903 RR |
1544 | |
1545 | /** | |
155032f9 VZ |
1546 | Strip characters at the front and/or end. |
1547 | ||
ee49f540 | 1548 | This is the same as Trim() except that it doesn't change this string. |
155032f9 | 1549 | |
ee49f540 | 1550 | This is a wxWidgets 1.xx compatibility function; you should not use it in new code. |
bcc8c903 | 1551 | */ |
ee49f540 | 1552 | wxString Strip(stripType s = trailing) const; |
23324ae1 FM |
1553 | |
1554 | /** | |
ee49f540 FM |
1555 | Removes white-space (space, tabs, form feed, newline and carriage return) from |
1556 | the left or from the right end of the string (right is default). | |
23324ae1 | 1557 | */ |
ee49f540 | 1558 | wxString& Trim(bool fromRight = true); |
23324ae1 | 1559 | |
23324ae1 | 1560 | /** |
ee49f540 | 1561 | Truncate the string to the given length. |
23324ae1 | 1562 | */ |
ee49f540 | 1563 | wxString& Truncate(size_t len); |
155032f9 | 1564 | |
23324ae1 FM |
1565 | //@} |
1566 | ||
ee49f540 FM |
1567 | |
1568 | ||
1569 | ||
23324ae1 | 1570 | /** |
ee49f540 FM |
1571 | @member_group_name{iter, Iterator interface} |
1572 | ||
57ab6f23 | 1573 | These methods return iterators to the beginning or end of the string. |
155032f9 | 1574 | |
ee49f540 FM |
1575 | Please see any STL reference (e.g. http://www.cppreference.com/wiki/string/start) |
1576 | for their documentation. | |
23324ae1 | 1577 | */ |
ee49f540 | 1578 | //@{ |
155032f9 | 1579 | |
ee49f540 FM |
1580 | const_iterator begin() const; |
1581 | iterator begin(); | |
1582 | const_iterator end() const; | |
1583 | iterator end(); | |
1584 | ||
1585 | const_reverse_iterator rbegin() const; | |
1586 | reverse_iterator rbegin(); | |
1587 | const_reverse_iterator rend() const; | |
1588 | reverse_iterator rend(); | |
155032f9 | 1589 | |
23324ae1 FM |
1590 | //@} |
1591 | ||
ee49f540 FM |
1592 | |
1593 | ||
23324ae1 | 1594 | /** |
ee49f540 FM |
1595 | @member_group_name{stl, STL interface} |
1596 | ||
155032f9 VZ |
1597 | The supported STL functions are listed here. |
1598 | ||
ee49f540 FM |
1599 | Please see any STL reference (e.g. http://www.cppreference.com/wiki/string/start) |
1600 | for their documentation. | |
23324ae1 | 1601 | */ |
ee49f540 | 1602 | //@{ |
155032f9 | 1603 | |
ee49f540 FM |
1604 | wxString& append(const wxString& str, size_t pos, size_t n); |
1605 | wxString& append(const wxString& str); | |
1606 | wxString& append(const char *sz, size_t n); | |
1607 | wxString& append(const wchar_t *sz, size_t n); | |
1608 | wxString& append(size_t n, wxUniChar ch); | |
1609 | wxString& append(const_iterator first, const_iterator last); | |
1610 | ||
1611 | wxString& assign(const wxString& str, size_t pos, size_t n); | |
1612 | wxString& assign(const wxString& str); | |
1613 | wxString& assign(const char *sz, size_t n); | |
1614 | wxString& assign(const wchar_t *sz, size_t n); | |
1615 | wxString& assign(size_t n, wxUniChar ch); | |
1616 | wxString& assign(const_iterator first, const_iterator last); | |
1617 | ||
1618 | wxUniChar at(size_t n) const; | |
1619 | wxUniCharRef at(size_t n); | |
1620 | ||
1621 | void clear(); | |
1622 | ||
1623 | size_type capacity() const; | |
1624 | ||
1625 | int compare(const wxString& str) const; | |
1626 | int compare(size_t nStart, size_t nLen, const wxString& str) const; | |
1627 | int compare(size_t nStart, size_t nLen, | |
1628 | const wxString& str, size_t nStart2, size_t nLen2) const; | |
1629 | int compare(size_t nStart, size_t nLen, | |
1630 | const char* sz, size_t nCount = npos) const; | |
1631 | int compare(size_t nStart, size_t nLen, | |
1632 | const wchar_t* sz, size_t nCount = npos) const; | |
1633 | ||
1634 | wxCStrData data() const; | |
1635 | ||
1636 | bool empty() const; | |
1637 | ||
1638 | wxString& erase(size_type pos = 0, size_type n = npos); | |
1639 | iterator erase(iterator first, iterator last); | |
1640 | iterator erase(iterator first); | |
1641 | ||
1642 | size_t find(const wxString& str, size_t nStart = 0) const; | |
1643 | size_t find(const char* sz, size_t nStart = 0, size_t n = npos) const; | |
1644 | size_t find(const wchar_t* sz, size_t nStart = 0, size_t n = npos) const; | |
1645 | size_t find(wxUniChar ch, size_t nStart = 0) const; | |
1646 | size_t find_first_of(const char* sz, size_t nStart = 0) const; | |
1647 | size_t find_first_of(const wchar_t* sz, size_t nStart = 0) const; | |
1648 | size_t find_first_of(const char* sz, size_t nStart, size_t n) const; | |
1649 | size_t find_first_of(const wchar_t* sz, size_t nStart, size_t n) const; | |
1650 | size_t find_first_of(wxUniChar c, size_t nStart = 0) const; | |
1651 | size_t find_last_of (const wxString& str, size_t nStart = npos) const; | |
1652 | size_t find_last_of (const char* sz, size_t nStart = npos) const; | |
1653 | size_t find_last_of (const wchar_t* sz, size_t nStart = npos) const; | |
1654 | size_t find_last_of(const char* sz, size_t nStart, size_t n) const; | |
1655 | size_t find_last_of(const wchar_t* sz, size_t nStart, size_t n) const; | |
1656 | size_t find_last_of(wxUniChar c, size_t nStart = npos) const; | |
1657 | size_t find_first_not_of(const wxString& str, size_t nStart = 0) const; | |
1658 | size_t find_first_not_of(const char* sz, size_t nStart = 0) const; | |
1659 | size_t find_first_not_of(const wchar_t* sz, size_t nStart = 0) const; | |
1660 | size_t find_first_not_of(const char* sz, size_t nStart, size_t n) const; | |
1661 | size_t find_first_not_of(const wchar_t* sz, size_t nStart, size_t n) const; | |
1662 | size_t find_first_not_of(wxUniChar ch, size_t nStart = 0) const; | |
1663 | size_t find_last_not_of(const wxString& str, size_t nStart = npos) const; | |
1664 | size_t find_last_not_of(const char* sz, size_t nStart = npos) const; | |
1665 | size_t find_last_not_of(const wchar_t* sz, size_t nStart = npos) const; | |
1666 | size_t find_last_not_of(const char* sz, size_t nStart, size_t n) const; | |
1667 | size_t find_last_not_of(const wchar_t* sz, size_t nStart, size_t n) const; | |
1668 | ||
1669 | wxString& insert(size_t nPos, const wxString& str); | |
1670 | wxString& insert(size_t nPos, const wxString& str, size_t nStart, size_t n); | |
1671 | wxString& insert(size_t nPos, const char *sz, size_t n); | |
1672 | wxString& insert(size_t nPos, const wchar_t *sz, size_t n); | |
1673 | wxString& insert(size_t nPos, size_t n, wxUniChar ch); | |
1674 | iterator insert(iterator it, wxUniChar ch); | |
1675 | void insert(iterator it, const_iterator first, const_iterator last); | |
1676 | void insert(iterator it, size_type n, wxUniChar ch); | |
1677 | ||
1678 | size_t length() const; | |
1679 | ||
1680 | size_type max_size() const; | |
1681 | ||
1682 | void reserve(size_t sz); | |
1683 | void resize(size_t nSize, wxUniChar ch = '\0'); | |
1684 | ||
1685 | wxString& replace(size_t nStart, size_t nLen, const wxString& str); | |
1686 | wxString& replace(size_t nStart, size_t nLen, size_t nCount, wxUniChar ch); | |
1687 | wxString& replace(size_t nStart, size_t nLen, | |
1688 | const wxString& str, size_t nStart2, size_t nLen2); | |
1689 | wxString& replace(size_t nStart, size_t nLen, | |
1690 | const char* sz, size_t nCount); | |
1691 | wxString& replace(size_t nStart, size_t nLen, | |
1692 | const wchar_t* sz, size_t nCount); | |
1693 | wxString& replace(size_t nStart, size_t nLen, | |
1694 | const wxString& s, size_t nCount); | |
1695 | wxString& replace(iterator first, iterator last, const wxString& s); | |
1696 | wxString& replace(iterator first, iterator last, const char* s, size_type n); | |
1697 | wxString& replace(iterator first, iterator last, const wchar_t* s, size_type n); | |
1698 | wxString& replace(iterator first, iterator last, size_type n, wxUniChar ch); | |
1699 | wxString& replace(iterator first, iterator last, | |
1700 | const_iterator first1, const_iterator last1); | |
1701 | wxString& replace(iterator first, iterator last, | |
1702 | const char *first1, const char *last1); | |
1703 | wxString& replace(iterator first, iterator last, | |
1704 | const wchar_t *first1, const wchar_t *last1); | |
1705 | ||
1706 | size_t rfind(const wxString& str, size_t nStart = npos) const; | |
1707 | size_t rfind(const char* sz, size_t nStart = npos, size_t n = npos) const; | |
1708 | size_t rfind(const wchar_t* sz, size_t nStart = npos, size_t n = npos) const; | |
1709 | size_t rfind(wxUniChar ch, size_t nStart = npos) const; | |
1710 | ||
1711 | size_type size() const; | |
1712 | wxString substr(size_t nStart = 0, size_t nLen = npos) const; | |
1713 | void swap(wxString& str); | |
155032f9 | 1714 | |
23324ae1 | 1715 | //@} |
155032f9 | 1716 | |
ee49f540 FM |
1717 | |
1718 | ||
1719 | // STATIC FUNCTIONS | |
57ab6f23 | 1720 | // Keep these functions separated from the other groups or Doxygen gets confused |
ee49f540 | 1721 | // ----------------------------------------------------------------------------- |
23324ae1 | 1722 | |
23324ae1 | 1723 | /** |
ee49f540 | 1724 | An 'invalid' value for string index |
23324ae1 | 1725 | */ |
ee49f540 | 1726 | static const size_t npos; |
23324ae1 FM |
1727 | |
1728 | /** | |
ee49f540 FM |
1729 | This static function returns the string containing the result of calling |
1730 | Printf() with the passed parameters on it. | |
062dc5fc | 1731 | |
ee49f540 | 1732 | @see FormatV(), Printf() |
23324ae1 | 1733 | */ |
ee49f540 | 1734 | static wxString Format(const wxString& format, ...); |
23324ae1 | 1735 | |
23324ae1 | 1736 | /** |
ee49f540 FM |
1737 | This static function returns the string containing the result of calling |
1738 | PrintfV() with the passed parameters on it. | |
0c7db140 | 1739 | |
ee49f540 | 1740 | @see Format(), PrintfV() |
23324ae1 | 1741 | */ |
ee49f540 | 1742 | static wxString FormatV(const wxString& format, va_list argptr); |
23324ae1 FM |
1743 | |
1744 | //@{ | |
1745 | /** | |
ee49f540 FM |
1746 | Converts given buffer of binary data from 8-bit string to wxString. In |
1747 | Unicode build, the string is interpreted as being in ISO-8859-1 | |
1748 | encoding. The version without @e len parameter takes NUL-terminated | |
1749 | data. | |
062dc5fc | 1750 | |
ee49f540 FM |
1751 | This is a convenience method useful when storing binary data in |
1752 | wxString. It should be used @em only for that purpose and only in | |
1753 | conjunction with To8BitData(). Use mb_str() for conversion of character | |
1754 | data to known encoding. | |
3c4f71cc | 1755 | |
ee49f540 FM |
1756 | @since 2.8.4 |
1757 | ||
1758 | @see wxString::To8BitData() | |
23324ae1 | 1759 | */ |
ee49f540 FM |
1760 | static wxString From8BitData(const char* buf, size_t len); |
1761 | static wxString From8BitData(const char* buf); | |
23324ae1 FM |
1762 | //@} |
1763 | ||
ee49f540 | 1764 | //@{ |
23324ae1 | 1765 | /** |
ee49f540 FM |
1766 | Converts the string or character from an ASCII, 7-bit form |
1767 | to the native wxString representation. | |
23324ae1 | 1768 | */ |
ee49f540 FM |
1769 | static wxString FromAscii(const char* s); |
1770 | static wxString FromAscii(const unsigned char* s); | |
1771 | static wxString FromAscii(const char* s, size_t len); | |
1772 | static wxString FromAscii(const unsigned char* s, size_t len); | |
1773 | static wxString FromAscii(char c); | |
1774 | //@} | |
23324ae1 | 1775 | |
951201d8 VZ |
1776 | /** |
1777 | Returns a string with the textual representation of the number in C | |
1778 | locale. | |
1779 | ||
1780 | Unlike FromDouble() the string returned by this function always uses | |
1781 | the period character as decimal separator, independently of the current | |
fd3a4cb9 | 1782 | locale. Otherwise its behaviour is identical to the other function. |
951201d8 VZ |
1783 | |
1784 | @since 2.9.1 | |
1785 | ||
1786 | @see ToCDouble() | |
1787 | */ | |
fd3a4cb9 | 1788 | static wxString FromCDouble(double val, int precision = -1); |
951201d8 VZ |
1789 | |
1790 | /** | |
1791 | Returns a string with the textual representation of the number. | |
1792 | ||
fd3a4cb9 VZ |
1793 | For the default value of @a precision, this function behaves as a |
1794 | simple wrapper for @code wxString::Format("%g", val) @endcode. If @a | |
1795 | precision is positive (or zero), the @c %.Nf format is used with the | |
1796 | given precision value. | |
951201d8 VZ |
1797 | |
1798 | Notice that the string returned by this function uses the decimal | |
1799 | separator appropriate for the current locale, e.g. @c "," and not a | |
1800 | period in French locale. Use FromCDouble() if this is unwanted. | |
1801 | ||
fd3a4cb9 VZ |
1802 | @param val |
1803 | The value to format. | |
1804 | @param precision | |
1805 | The number of fractional digits to use in or -1 to use the most | |
1806 | appropriate format. This parameter is new in wxWidgets 2.9.2. | |
1807 | ||
951201d8 VZ |
1808 | @since 2.9.1 |
1809 | ||
1810 | @see ToDouble() | |
1811 | */ | |
fd3a4cb9 | 1812 | static wxString FromDouble(double val, int precision = -1); |
951201d8 | 1813 | |
ee49f540 | 1814 | //@{ |
0c7db140 | 1815 | /** |
ee49f540 | 1816 | Converts C string encoded in UTF-8 to wxString. |
6307d716 | 1817 | |
ee49f540 | 1818 | If @a s is not a valid UTF-8 string, an empty string is returned. |
6307d716 | 1819 | |
ee49f540 FM |
1820 | Notice that when using UTF-8 wxWidgets build there is a more efficient |
1821 | alternative to this function called FromUTF8Unchecked() which, unlike | |
1822 | this one, doesn't check that the input string is valid. | |
062dc5fc | 1823 | |
ee49f540 | 1824 | @since 2.8.4 |
b33e2f63 | 1825 | */ |
ee49f540 FM |
1826 | static wxString FromUTF8(const char* s); |
1827 | static wxString FromUTF8(const char* s, size_t len); | |
f08b2466 | 1828 | //@} |
b33e2f63 | 1829 | |
ee49f540 | 1830 | //@{ |
f08b2466 | 1831 | /** |
ee49f540 FM |
1832 | Converts C string encoded in UTF-8 to wxString without checking its |
1833 | validity. | |
062dc5fc | 1834 | |
ee49f540 FM |
1835 | This method assumes that @a s is a valid UTF-8 sequence and doesn't do |
1836 | any validation (although an assert failure is triggered in debug builds | |
1837 | if the string is invalid). Only use it if you are absolutely sure that | |
1838 | @a s is a correct UTF-8 string (e.g. because it comes from another | |
1839 | library using UTF-8) and if the performance matters, otherwise use | |
1840 | slower (in UTF-8 build) but safer FromUTF8(). Passing a bad UTF-8 | |
1841 | string to this function will result in creating a corrupted wxString | |
1842 | and all the subsequent operations on it will be undefined. | |
1843 | ||
1844 | @since 2.8.9 | |
f08b2466 | 1845 | */ |
ee49f540 FM |
1846 | static wxString FromUTF8Unchecked(const char* s); |
1847 | static wxString FromUTF8Unchecked(const char* s, size_t len); | |
b33e2f63 | 1848 | //@} |
23324ae1 FM |
1849 | }; |
1850 | ||
457f3abf BP |
1851 | |
1852 | ||
57bf907d FM |
1853 | //@{ |
1854 | /** | |
457f3abf | 1855 | Comparison operator for string types. |
57bf907d FM |
1856 | */ |
1857 | inline bool operator==(const wxString& s1, const wxString& s2); | |
1858 | inline bool operator!=(const wxString& s1, const wxString& s2); | |
1859 | inline bool operator< (const wxString& s1, const wxString& s2); | |
1860 | inline bool operator> (const wxString& s1, const wxString& s2); | |
1861 | inline bool operator<=(const wxString& s1, const wxString& s2); | |
1862 | inline bool operator>=(const wxString& s1, const wxString& s2); | |
1863 | inline bool operator==(const wxString& s1, const wxCStrData& s2); | |
1864 | inline bool operator==(const wxCStrData& s1, const wxString& s2); | |
1865 | inline bool operator!=(const wxString& s1, const wxCStrData& s2); | |
1866 | inline bool operator!=(const wxCStrData& s1, const wxString& s2); | |
1867 | inline bool operator==(const wxString& s1, const wxWCharBuffer& s2); | |
1868 | inline bool operator==(const wxWCharBuffer& s1, const wxString& s2); | |
1869 | inline bool operator!=(const wxString& s1, const wxWCharBuffer& s2); | |
1870 | inline bool operator!=(const wxWCharBuffer& s1, const wxString& s2); | |
1871 | inline bool operator==(const wxString& s1, const wxCharBuffer& s2); | |
1872 | inline bool operator==(const wxCharBuffer& s1, const wxString& s2); | |
1873 | inline bool operator!=(const wxString& s1, const wxCharBuffer& s2); | |
1874 | inline bool operator!=(const wxCharBuffer& s1, const wxString& s2); | |
457f3abf | 1875 | //@} |
57bf907d | 1876 | |
457f3abf | 1877 | //@{ |
57bf907d | 1878 | /** |
457f3abf | 1879 | Comparison operators char types. |
57bf907d FM |
1880 | */ |
1881 | inline bool operator==(const wxUniChar& c, const wxString& s); | |
1882 | inline bool operator==(const wxUniCharRef& c, const wxString& s); | |
1883 | inline bool operator==(char c, const wxString& s); | |
1884 | inline bool operator==(wchar_t c, const wxString& s); | |
1885 | inline bool operator==(int c, const wxString& s); | |
1886 | inline bool operator==(const wxString& s, const wxUniChar& c); | |
1887 | inline bool operator==(const wxString& s, const wxUniCharRef& c); | |
1888 | inline bool operator==(const wxString& s, char c); | |
1889 | inline bool operator==(const wxString& s, wchar_t c); | |
1890 | inline bool operator!=(const wxUniChar& c, const wxString& s); | |
1891 | inline bool operator!=(const wxUniCharRef& c, const wxString& s); | |
1892 | inline bool operator!=(char c, const wxString& s); | |
1893 | inline bool operator!=(wchar_t c, const wxString& s); | |
1894 | inline bool operator!=(int c, const wxString& s); | |
1895 | inline bool operator!=(const wxString& s, const wxUniChar& c); | |
1896 | inline bool operator!=(const wxString& s, const wxUniCharRef& c); | |
1897 | inline bool operator!=(const wxString& s, char c); | |
1898 | inline bool operator!=(const wxString& s, wchar_t c); | |
1899 | //@} | |
1900 | ||
e54c96f1 | 1901 | /** |
4701dc09 FM |
1902 | The global wxString instance of an empty string. |
1903 | Used extensively in the entire wxWidgets API. | |
e54c96f1 FM |
1904 | */ |
1905 | wxString wxEmptyString; | |
1906 | ||
1907 | ||
1908 | ||
23324ae1 FM |
1909 | /** |
1910 | @class wxStringBufferLength | |
7c913512 | 1911 | |
4701dc09 FM |
1912 | This tiny class allows you to conveniently access the wxString internal buffer |
1913 | as a writable pointer without any risk of forgetting to restore the string to | |
1914 | the usable state later, and allows the user to set the internal length of the string. | |
7c913512 FM |
1915 | |
1916 | For example, assuming you have a low-level OS function called | |
4701dc09 | 1917 | @c "int GetMeaningOfLifeAsString(char *)" copying the value in the provided |
23324ae1 FM |
1918 | buffer (which must be writable, of course), and returning the actual length |
1919 | of the string, you might call it like this: | |
7c913512 | 1920 | |
23324ae1 | 1921 | @code |
4701dc09 | 1922 | wxString theAnswer; |
2839804c | 1923 | wxStringBufferLength theAnswerBuffer(theAnswer, 1024); |
23324ae1 FM |
1924 | int nLength = GetMeaningOfLifeAsString(theAnswerBuffer); |
1925 | theAnswerBuffer.SetLength(nLength); | |
1926 | if ( theAnswer != "42" ) | |
23324ae1 | 1927 | wxLogError("Something is very wrong!"); |
23324ae1 | 1928 | @endcode |
7c913512 | 1929 | |
bcc8c903 | 1930 | Note that the exact usage of this depends on whether or not wxUSE_STL is |
0c7db140 | 1931 | enabled. If wxUSE_STL is enabled, wxStringBuffer creates a separate empty |
bcc8c903 | 1932 | character buffer, and if wxUSE_STL is disabled, it uses GetWriteBuf() from |
0c7db140 VZ |
1933 | wxString, keeping the same buffer wxString uses intact. In other words, |
1934 | relying on wxStringBuffer containing the old wxString data is not a good | |
bcc8c903 | 1935 | idea if you want to build your program both with and without wxUSE_STL. |
7c913512 | 1936 | |
4701dc09 FM |
1937 | Note that wxStringBuffer::SetLength @b must be called before |
1938 | wxStringBufferLength destructs. | |
7c913512 | 1939 | |
23324ae1 | 1940 | @library{wxbase} |
bcc8c903 | 1941 | @category{data} |
23324ae1 | 1942 | */ |
7c913512 | 1943 | class wxStringBufferLength |
23324ae1 FM |
1944 | { |
1945 | public: | |
1946 | /** | |
1947 | Constructs a writable string buffer object associated with the given string | |
4701dc09 FM |
1948 | and containing enough space for at least @a len characters. |
1949 | ||
1950 | Basically, this is equivalent to calling wxString::GetWriteBuf and | |
23324ae1 FM |
1951 | saving the result. |
1952 | */ | |
1953 | wxStringBufferLength(const wxString& str, size_t len); | |
1954 | ||
1955 | /** | |
7c913512 | 1956 | Restores the string passed to the constructor to the usable state by calling |
23324ae1 FM |
1957 | wxString::UngetWriteBuf on it. |
1958 | */ | |
1959 | ~wxStringBufferLength(); | |
1960 | ||
1961 | /** | |
7c913512 | 1962 | Sets the internal length of the string referred to by wxStringBufferLength to |
4cc4bfaf | 1963 | @a nLength characters. |
4701dc09 | 1964 | |
23324ae1 FM |
1965 | Must be called before wxStringBufferLength destructs. |
1966 | */ | |
1967 | void SetLength(size_t nLength); | |
1968 | ||
1969 | /** | |
1970 | Returns the writable pointer to a buffer of the size at least equal to the | |
1971 | length specified in the constructor. | |
1972 | */ | |
4cc4bfaf | 1973 | wxChar* operator wxChar *(); |
23324ae1 FM |
1974 | }; |
1975 | ||
727aa906 FM |
1976 | |
1977 | /** | |
1978 | @class wxStringBuffer | |
1979 | ||
1980 | This tiny class allows you to conveniently access the wxString internal buffer | |
1981 | as a writable pointer without any risk of forgetting to restore the string | |
1982 | to the usable state later. | |
1983 | ||
1984 | For example, assuming you have a low-level OS function called | |
1985 | @c "GetMeaningOfLifeAsString(char *)" returning the value in the provided | |
1986 | buffer (which must be writable, of course) you might call it like this: | |
1987 | ||
1988 | @code | |
1989 | wxString theAnswer; | |
1990 | GetMeaningOfLifeAsString(wxStringBuffer(theAnswer, 1024)); | |
1991 | if ( theAnswer != "42" ) | |
1992 | wxLogError("Something is very wrong!"); | |
1993 | @endcode | |
1994 | ||
1995 | Note that the exact usage of this depends on whether or not @c wxUSE_STL is | |
1996 | enabled. If @c wxUSE_STL is enabled, wxStringBuffer creates a separate empty | |
1997 | character buffer, and if @c wxUSE_STL is disabled, it uses GetWriteBuf() from | |
1998 | wxString, keeping the same buffer wxString uses intact. In other words, | |
1999 | relying on wxStringBuffer containing the old wxString data is not a good | |
2000 | idea if you want to build your program both with and without @c wxUSE_STL. | |
2001 | ||
2002 | @library{wxbase} | |
2003 | @category{data} | |
2004 | */ | |
2005 | class wxStringBuffer | |
2006 | { | |
2007 | public: | |
2008 | /** | |
2009 | Constructs a writable string buffer object associated with the given string | |
2010 | and containing enough space for at least @a len characters. | |
2011 | Basically, this is equivalent to calling wxString::GetWriteBuf() and | |
2012 | saving the result. | |
2013 | */ | |
2014 | wxStringBuffer(const wxString& str, size_t len); | |
2015 | ||
2016 | /** | |
2017 | Restores the string passed to the constructor to the usable state by calling | |
2018 | wxString::UngetWriteBuf() on it. | |
2019 | */ | |
2020 | ~wxStringBuffer(); | |
2021 | ||
2022 | /** | |
2023 | Returns the writable pointer to a buffer of the size at least equal to the | |
2024 | length specified in the constructor. | |
2025 | */ | |
2026 | wxStringCharType* operator wxStringCharType *(); | |
2027 | }; | |
cbec0f40 FM |
2028 | |
2029 | ||
2030 | /** @addtogroup group_funcmacro_string */ | |
2031 | //@{ | |
2032 | ||
2033 | /** | |
2034 | Allows to extend a function with the signature: | |
2035 | @code bool SomeFunc(const wxUniChar& c) @endcode | |
2036 | which operates on a single character, to an entire wxString. | |
2037 | ||
2038 | E.g. if you want to check if an entire string contains only digits, | |
2039 | you can do: | |
2040 | @code | |
2041 | if (wxStringCheck<wxIsdigit>(myString)) | |
04783062 | 2042 | ... // the entire string contains only digits! |
cbec0f40 FM |
2043 | else |
2044 | ... // at least one character of myString is not a digit | |
2045 | @endcode | |
2046 | ||
2047 | @return @true if the given function returns a non-zero value for all | |
2048 | characters of the @a val string. | |
2049 | */ | |
2050 | template<bool (T)(const wxUniChar& c)> | |
413eac73 | 2051 | inline bool wxStringCheck(const wxString& val); |
cbec0f40 FM |
2052 | |
2053 | //@} |