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