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