]>
Commit | Line | Data |
---|---|---|
a660d684 KB |
1 | \section{\class{wxString}}\label{wxstring} |
2 | ||
40b480c3 JS |
3 | wxString is a class representing a character string. Please see the |
4 | \helpref{wxString overview}{wxstringoverview} for more information about it. As explained | |
5 | there, wxString implements about 90\% of methods of the std::string class (iterators | |
6 | are not supported, nor all methods which use them). | |
7 | These standard functions are not documented in this manual so please see the STL documentation. | |
99f09bc1 | 8 | The behaviour of all these functions is identical to the behaviour described |
e2101186 | 9 | there (except that wxString is sensitive to null character). |
99f09bc1 | 10 | |
0aa35d19 VZ |
11 | You may notice that wxString sometimes has many functions which do the same |
12 | thing like, for example, \helpref{Length()}{wxstringlength}, | |
13 | \helpref{Len()}{wxstringlen} and {\tt length()} which all return the string | |
14 | length. In all cases of such duplication the {\tt std::string}-compatible | |
15 | method ({\tt length()} in this case, always the lowercase version) should be | |
fc2171bd | 16 | used as it will ensure smoother transition to {\tt std::string} when wxWidgets |
0aa35d19 VZ |
17 | starts using it instead of wxString. |
18 | ||
abc3d841 VZ |
19 | Also please note that in this manual \texttt{char} is sometimes used instead of |
20 | \texttt{wxChar} because it hasn't been fully updated yet. Please substitute as | |
21 | necessary and refer to the sources in case of a doubt. | |
22 | ||
23 | ||
b3324be2 JS |
24 | \wxheading{Derived from} |
25 | ||
26 | None | |
a660d684 | 27 | |
954b8ae6 JS |
28 | \wxheading{Include files} |
29 | ||
30 | <wx/string.h> | |
31 | ||
20e85460 JS |
32 | \wxheading{Predefined objects} |
33 | ||
34 | Objects: | |
35 | ||
36 | {\bf wxEmptyString} | |
37 | ||
b3324be2 JS |
38 | \wxheading{See also} |
39 | ||
40 | \overview{Overview}{wxstringoverview} | |
a660d684 | 41 | |
99f09bc1 VZ |
42 | \latexignore{\rtfignore{\wxheading{Function groups}}} |
43 | ||
15d83f72 | 44 | \membersection{Constructors and assignment operators}\label{constructorsinwxstring} |
99f09bc1 | 45 | |
2edb0bde | 46 | A string may be constructed either from a C string, (some number of copies of) |
99f09bc1 VZ |
47 | a single character or a wide (UNICODE) string. For all constructors (except the |
48 | default which creates an empty string) there is also a corresponding assignment | |
49 | operator. | |
50 | ||
51 | \helpref{wxString}{wxstringconstruct}\\ | |
52 | \helpref{operator $=$}{wxstringoperatorassign}\\ | |
53 | \helpref{\destruct{wxString}}{wxstringdestruct} | |
54 | ||
15d83f72 | 55 | \membersection{String length}\label{lengthfunctionsinwxstring} |
99f09bc1 VZ |
56 | |
57 | These functions return the string length and check whether the string is empty | |
58 | or empty it. | |
59 | ||
60 | \helpref{Len}{wxstringlen}\\ | |
61 | \helpref{IsEmpty}{wxstringisempty}\\ | |
62 | \helpref{operator!}{wxstringoperatornot}\\ | |
63 | \helpref{Empty}{wxstringempty}\\ | |
64 | \helpref{Clear}{wxstringclear} | |
65 | ||
15d83f72 | 66 | \membersection{Character access}\label{characteraccessinwxstring} |
99f09bc1 VZ |
67 | |
68 | Many functions in this section take a character index in the string. As with C | |
69 | strings and/or arrays, the indices start from $0$, so the first character of a | |
70 | string is string[$0$]. Attempt to access a character beyond the end of the | |
2edb0bde | 71 | string (which may be even $0$ if the string is empty) will provoke an assert |
99f09bc1 VZ |
72 | failure in \helpref{debug build}{debuggingoverview}, but no checks are done in |
73 | release builds. | |
74 | ||
75 | This section also contains both implicit and explicit conversions to C style | |
76 | strings. Although implicit conversion is quite convenient, it is advised to use | |
77 | explicit \helpref{c\_str()}{wxstringcstr} method for the sake of clarity. Also | |
fd34e3a5 | 78 | see \helpref{overview}{wxstringadvices} for the cases where it is necessary to |
99f09bc1 VZ |
79 | use it. |
80 | ||
81 | \helpref{GetChar}{wxstringgetchar}\\ | |
82 | \helpref{GetWritableChar}{wxstringgetwritablechar}\\ | |
83 | \helpref{SetChar}{wxstringsetchar}\\ | |
84 | \helpref{Last}{wxstringlast}\\ | |
85 | \helpref{operator []}{wxstringoperatorbracket}\\ | |
86 | \helpref{c\_str}{wxstringcstr}\\ | |
bd8465ff VS |
87 | \helpref{mb\_str}{wxstringmbstr}\\ |
88 | \helpref{wc\_str}{wxstringwcstr}\\ | |
89 | \helpref{fn\_str}{wxstringfnstr}\\ | |
99f09bc1 VZ |
90 | \helpref{operator const char*}{wxstringoperatorconstcharpt} |
91 | ||
15d83f72 | 92 | \membersection{Concatenation}\label{concatenationinwxstring} |
99f09bc1 VZ |
93 | |
94 | Anything may be concatenated (appended to) with a string. However, you can't | |
95 | append something to a C string (including literal constants), so to do this it | |
96 | should be converted to a wxString first. | |
97 | ||
98 | \helpref{operator \cinsert}{wxstringoperatorout}\\ | |
99 | \helpref{operator $+=$}{wxstringplusequal}\\ | |
100 | \helpref{operator $+$}{wxstringoperatorplus}\\ | |
101 | \helpref{Append}{wxstringappend}\\ | |
102 | \helpref{Prepend}{wxstringprepend} | |
103 | ||
15d83f72 | 104 | \membersection{Comparison}\label{comparisoninwxstring} |
99f09bc1 VZ |
105 | |
106 | The default comparison function \helpref{Cmp}{wxstringcmp} is case-sensitive and | |
107 | so is the default version of \helpref{IsSameAs}{wxstringissameas}. For case | |
108 | insensitive comparisons you should use \helpref{CmpNoCase}{wxstringcmpnocase} or | |
109 | give a second parameter to IsSameAs. This last function is may be more | |
110 | convenient if only equality of the strings matters because it returns a boolean | |
cc81d32f | 111 | true value if the strings are the same and not 0 (which is usually false in C) |
f6bcfd97 | 112 | as {\tt Cmp()} does. |
99f09bc1 VZ |
113 | |
114 | \helpref{Matches}{wxstringmatches} is a poor man's regular expression matcher: | |
115 | it only understands '*' and '?' metacharacters in the sense of DOS command line | |
116 | interpreter. | |
117 | ||
f6bcfd97 BP |
118 | \helpref{StartsWith}{wxstringstartswith} is helpful when parsing a line of |
119 | text which should start with some predefined prefix and is more efficient than | |
2edb0bde | 120 | doing direct string comparison as you would also have to precalculate the |
f6bcfd97 BP |
121 | length of the prefix then. |
122 | ||
99f09bc1 VZ |
123 | \helpref{Cmp}{wxstringcmp}\\ |
124 | \helpref{CmpNoCase}{wxstringcmpnocase}\\ | |
125 | \helpref{IsSameAs}{wxstringissameas}\\ | |
f6bcfd97 | 126 | \helpref{Matches}{wxstringmatches}\\ |
3affcd07 VZ |
127 | \helpref{StartsWith}{wxstringstartswith}\\ |
128 | \helpref{EndsWith}{wxstringendswith} | |
99f09bc1 | 129 | |
15d83f72 | 130 | \membersection{Substring extraction}\label{substringextractioninwxstring} |
99f09bc1 VZ |
131 | |
132 | These functions allow to extract substring from this string. All of them don't | |
133 | modify the original string and return a new string containing the extracted | |
134 | substring. | |
135 | ||
136 | \helpref{Mid}{wxstringmid}\\ | |
137 | \helpref{operator()}{wxstringoperatorparenth}\\ | |
138 | \helpref{Left}{wxstringleft}\\ | |
139 | \helpref{Right}{wxstringright}\\ | |
140 | \helpref{BeforeFirst}{wxstringbeforefirst}\\ | |
141 | \helpref{BeforeLast}{wxstringbeforelast}\\ | |
142 | \helpref{AfterFirst}{wxstringafterfirst}\\ | |
f6bcfd97 | 143 | \helpref{AfterLast}{wxstringafterlast}\\ |
3affcd07 VZ |
144 | \helpref{StartsWith}{wxstringstartswith}\\ |
145 | \helpref{EndsWith}{wxstringendswith} | |
146 | ||
99f09bc1 | 147 | |
15d83f72 | 148 | \membersection{Case conversion}\label{caseconversioninwxstring} |
99f09bc1 VZ |
149 | |
150 | The MakeXXX() variants modify the string in place, while the other functions | |
2edb0bde | 151 | return a new string which contains the original text converted to the upper or |
99f09bc1 VZ |
152 | lower case and leave the original string unchanged. |
153 | ||
154 | \helpref{MakeUpper}{wxstringmakeupper}\\ | |
155 | \helpref{Upper}{wxstringupper}\\ | |
156 | \helpref{MakeLower}{wxstringmakelower}\\ | |
157 | \helpref{Lower}{wxstringlower} | |
158 | ||
15d83f72 | 159 | \membersection{Searching and replacing}\label{searchingandreplacinginwxstring} |
99f09bc1 | 160 | |
40b480c3 | 161 | These functions replace the standard {\it strchr()} and {\it strstr()} |
99f09bc1 VZ |
162 | functions. |
163 | ||
164 | \helpref{Find}{wxstringfind}\\ | |
165 | \helpref{Replace}{wxstringreplace} | |
166 | ||
15d83f72 | 167 | \membersection{Conversion to numbers}\label{conversiontonumbersinwxstring} |
cd0b1709 VZ |
168 | |
169 | The string provides functions for conversion to signed and unsigned integer and | |
170 | floating point numbers. All three functions take a pointer to the variable to | |
cc81d32f | 171 | put the numeric value in and return true if the {\bf entire} string could be |
cd0b1709 VZ |
172 | converted to a number. |
173 | ||
174 | \helpref{ToLong}{wxstringtolong}\\ | |
175 | \helpref{ToULong}{wxstringtoulong}\\ | |
176 | \helpref{ToDouble}{wxstringtodouble} | |
177 | ||
15d83f72 | 178 | \membersection{Writing values into the string}\label{writingintostringinwxstring} |
99f09bc1 VZ |
179 | |
180 | Both formatted versions (\helpref{Printf}{wxstringprintf}) and stream-like | |
341e7d28 VZ |
181 | insertion operators exist (for basic types only). Additionally, the |
182 | \helpref{Format}{wxstringformat} function allows to use simply append | |
183 | formatted value to a string: | |
99f09bc1 | 184 | |
341e7d28 VZ |
185 | \begin{verbatim} |
186 | // the following 2 snippets are equivalent | |
187 | ||
188 | wxString s = "..."; | |
189 | s += wxString::Format("%d", n); | |
190 | ||
191 | wxString s; | |
192 | s.Printf("...%d", n); | |
193 | \end{verbatim} | |
194 | ||
195 | \helpref{Format}{wxstringformat}\\ | |
196 | \helpref{FormatV}{wxstringformatv}\\ | |
99f09bc1 VZ |
197 | \helpref{Printf}{wxstringprintf}\\ |
198 | \helpref{PrintfV}{wxstringprintfv}\\ | |
40b480c3 | 199 | \helpref{operator \cinsert}{wxstringoperatorout} |
99f09bc1 | 200 | |
15d83f72 | 201 | \membersection{Memory management}\label{memoryinwxstring} |
99f09bc1 | 202 | |
2edb0bde | 203 | These are "advanced" functions and they will be needed quite rarely. |
99f09bc1 VZ |
204 | \helpref{Alloc}{wxstringalloc} and \helpref{Shrink}{wxstringshrink} are only |
205 | interesting for optimization purposes. | |
206 | \helpref{GetWriteBuf}{wxstringgetwritebuf} may be very useful when working with | |
207 | some external API which requires the caller to provide a writable buffer, but | |
208 | extreme care should be taken when using it: before performing any other | |
209 | operation on the string \helpref{UngetWriteBuf}{wxstringungetwritebuf} {\bf | |
210 | must} be called! | |
211 | ||
212 | \helpref{Alloc}{wxstringalloc}\\ | |
213 | \helpref{Shrink}{wxstringshrink}\\ | |
214 | \helpref{GetWriteBuf}{wxstringgetwritebuf}\\ | |
215 | \helpref{UngetWriteBuf}{wxstringungetwritebuf} | |
216 | ||
15d83f72 | 217 | \membersection{Miscellaneous}\label{miscellaneousinwxstring} |
99f09bc1 VZ |
218 | |
219 | Other string functions. | |
220 | ||
221 | \helpref{Trim}{wxstringtrim}\\ | |
222 | \helpref{Pad}{wxstringpad}\\ | |
223 | \helpref{Truncate}{wxstringtruncate} | |
224 | ||
15d83f72 | 225 | \membersection{wxWidgets 1.xx compatibility functions}\label{backwardcompatibilityinwxstring} |
99f09bc1 | 226 | |
fc2171bd | 227 | These functions are deprecated, please consider using new wxWidgets 2.0 |
99f09bc1 VZ |
228 | functions instead of them (or, even better, std::string compatible variants). |
229 | ||
230 | \helpref{SubString}{wxstringsubstring}\\ | |
231 | \helpref{sprintf}{wxstringsprintf}\\ | |
232 | \helpref{CompareTo}{wxstringcompareto}\\ | |
233 | \helpref{Length}{wxstringlength}\\ | |
234 | \helpref{Freq}{wxstringfreq}\\ | |
235 | \helpref{LowerCase}{wxstringlowercase}\\ | |
236 | \helpref{UpperCase}{wxstringuppercase}\\ | |
237 | \helpref{Strip}{wxstringstrip}\\ | |
238 | \helpref{Index}{wxstringindex}\\ | |
239 | \helpref{Remove}{wxstringremove}\\ | |
240 | \helpref{First}{wxstringfirst}\\ | |
241 | \helpref{Last}{wxstringlast}\\ | |
242 | \helpref{Contains}{wxstringcontains}\\ | |
243 | \helpref{IsNull}{wxstringisnull}\\ | |
244 | \helpref{IsAscii}{wxstringisascii}\\ | |
245 | \helpref{IsNumber}{wxstringisnumber}\\ | |
246 | \helpref{IsWord}{wxstringisword} | |
247 | ||
ed93168b | 248 | \membersection{std::string compatibility functions}\label{wxstringat} |
99f09bc1 VZ |
249 | |
250 | The supported functions are only listed here, please see any STL reference for | |
251 | their documentation. | |
252 | ||
253 | \begin{verbatim} | |
254 | // take nLen chars starting at nPos | |
255 | wxString(const wxString& str, size_t nPos, size_t nLen); | |
256 | // take all characters from pStart to pEnd (poor man's iterators) | |
257 | wxString(const void *pStart, const void *pEnd); | |
258 | ||
259 | // lib.string.capacity | |
260 | // return the length of the string | |
261 | size_t size() const; | |
262 | // return the length of the string | |
263 | size_t length() const; | |
264 | // return the maximum size of the string | |
265 | size_t max_size() const; | |
266 | // resize the string, filling the space with c if c != 0 | |
267 | void resize(size_t nSize, char ch = '\0'); | |
268 | // delete the contents of the string | |
269 | void clear(); | |
270 | // returns true if the string is empty | |
271 | bool empty() const; | |
272 | ||
273 | // lib.string.access | |
274 | // return the character at position n | |
275 | char at(size_t n) const; | |
276 | // returns the writable character at position n | |
277 | char& at(size_t n); | |
278 | ||
279 | // lib.string.modifiers | |
280 | // append a string | |
281 | wxString& append(const wxString& str); | |
282 | // append elements str[pos], ..., str[pos+n] | |
283 | wxString& append(const wxString& str, size_t pos, size_t n); | |
284 | // append first n (or all if n == npos) characters of sz | |
285 | wxString& append(const char *sz, size_t n = npos); | |
286 | ||
287 | // append n copies of ch | |
288 | wxString& append(size_t n, char ch); | |
289 | ||
290 | // same as `this_string = str' | |
291 | wxString& assign(const wxString& str); | |
292 | // same as ` = str[pos..pos + n] | |
293 | wxString& assign(const wxString& str, size_t pos, size_t n); | |
294 | // same as `= first n (or all if n == npos) characters of sz' | |
295 | wxString& assign(const char *sz, size_t n = npos); | |
296 | // same as `= n copies of ch' | |
297 | wxString& assign(size_t n, char ch); | |
298 | ||
299 | // insert another string | |
300 | wxString& insert(size_t nPos, const wxString& str); | |
301 | // insert n chars of str starting at nStart (in str) | |
302 | wxString& insert(size_t nPos, const wxString& str, size_t nStart, size_t n); | |
303 | ||
304 | // insert first n (or all if n == npos) characters of sz | |
305 | wxString& insert(size_t nPos, const char *sz, size_t n = npos); | |
306 | // insert n copies of ch | |
307 | wxString& insert(size_t nPos, size_t n, char ch); | |
308 | ||
309 | // delete characters from nStart to nStart + nLen | |
310 | wxString& erase(size_t nStart = 0, size_t nLen = npos); | |
311 | ||
312 | // replaces the substring of length nLen starting at nStart | |
313 | wxString& replace(size_t nStart, size_t nLen, const char* sz); | |
314 | // replaces the substring with nCount copies of ch | |
315 | wxString& replace(size_t nStart, size_t nLen, size_t nCount, char ch); | |
316 | // replaces a substring with another substring | |
317 | wxString& replace(size_t nStart, size_t nLen, | |
318 | const wxString& str, size_t nStart2, size_t nLen2); | |
319 | // replaces the substring with first nCount chars of sz | |
320 | wxString& replace(size_t nStart, size_t nLen, | |
321 | const char* sz, size_t nCount); | |
322 | ||
323 | // swap two strings | |
324 | void swap(wxString& str); | |
325 | ||
326 | // All find() functions take the nStart argument which specifies the | |
327 | // position to start the search on, the default value is 0. All functions | |
328 | // return npos if there were no match. | |
329 | ||
330 | // find a substring | |
331 | size_t find(const wxString& str, size_t nStart = 0) const; | |
332 | ||
333 | // find first n characters of sz | |
334 | size_t find(const char* sz, size_t nStart = 0, size_t n = npos) const; | |
335 | ||
7335902d | 336 | // find the first occurrence of character ch after nStart |
99f09bc1 VZ |
337 | size_t find(char ch, size_t nStart = 0) const; |
338 | ||
339 | // rfind() family is exactly like find() but works right to left | |
340 | ||
341 | // as find, but from the end | |
342 | size_t rfind(const wxString& str, size_t nStart = npos) const; | |
343 | ||
344 | // as find, but from the end | |
345 | size_t rfind(const char* sz, size_t nStart = npos, | |
346 | size_t n = npos) const; | |
347 | // as find, but from the end | |
348 | size_t rfind(char ch, size_t nStart = npos) const; | |
349 | ||
7335902d | 350 | // find first/last occurrence of any character in the set |
99f09bc1 VZ |
351 | |
352 | // | |
353 | size_t find_first_of(const wxString& str, size_t nStart = 0) const; | |
354 | // | |
355 | size_t find_first_of(const char* sz, size_t nStart = 0) const; | |
356 | // same as find(char, size_t) | |
357 | size_t find_first_of(char c, size_t nStart = 0) const; | |
358 | // | |
359 | size_t find_last_of (const wxString& str, size_t nStart = npos) const; | |
360 | // | |
361 | size_t find_last_of (const char* s, size_t nStart = npos) const; | |
362 | // same as rfind(char, size_t) | |
363 | size_t find_last_of (char c, size_t nStart = npos) const; | |
364 | ||
7335902d | 365 | // find first/last occurrence of any character not in the set |
99f09bc1 VZ |
366 | |
367 | // | |
368 | size_t find_first_not_of(const wxString& str, size_t nStart = 0) const; | |
369 | // | |
370 | size_t find_first_not_of(const char* s, size_t nStart = 0) const; | |
371 | // | |
372 | size_t find_first_not_of(char ch, size_t nStart = 0) const; | |
373 | // | |
374 | size_t find_last_not_of(const wxString& str, size_t nStart=npos) const; | |
375 | // | |
376 | size_t find_last_not_of(const char* s, size_t nStart = npos) const; | |
377 | // | |
378 | size_t find_last_not_of(char ch, size_t nStart = npos) const; | |
379 | ||
380 | // All compare functions return a negative, zero or positive value | |
381 | // if the [sub]string is less, equal or greater than the compare() argument. | |
382 | ||
383 | // just like strcmp() | |
384 | int compare(const wxString& str) const; | |
385 | // comparison with a substring | |
386 | int compare(size_t nStart, size_t nLen, const wxString& str) const; | |
387 | // comparison of 2 substrings | |
388 | int compare(size_t nStart, size_t nLen, | |
389 | const wxString& str, size_t nStart2, size_t nLen2) const; | |
390 | // just like strcmp() | |
391 | int compare(const char* sz) const; | |
392 | // substring comparison with first nCount characters of sz | |
393 | int compare(size_t nStart, size_t nLen, | |
394 | const char* sz, size_t nCount = npos) const; | |
395 | ||
396 | // substring extraction | |
397 | wxString substr(size_t nStart = 0, size_t nLen = npos) const; | |
398 | \end{verbatim} | |
399 | ||
400 | %%%%% MEMBERS HERE %%%%% | |
401 | \helponly{\insertatlevel{2}{ | |
402 | ||
403 | \wxheading{Members} | |
404 | ||
405 | }} | |
a660d684 KB |
406 | |
407 | \membersection{wxString::wxString}\label{wxstringconstruct} | |
408 | ||
b3324be2 | 409 | \func{}{wxString}{\void} |
a660d684 | 410 | |
bd8465ff | 411 | Default constructor. Initializes the string to {\tt ""} (empty string). |
a660d684 | 412 | |
b3324be2 | 413 | \func{}{wxString}{\param{const wxString\&}{ x}} |
a660d684 | 414 | |
b3324be2 | 415 | Copy constructor. |
a660d684 | 416 | |
b3324be2 | 417 | \func{}{wxString}{\param{char}{ ch}, \param{size\_t}{ n = 1}} |
a660d684 | 418 | |
b3324be2 | 419 | Constructs a string of {\it n} copies of character {\it ch}. |
a660d684 | 420 | |
99f09bc1 | 421 | \func{}{wxString}{\param{const char*}{ psz}, \param{size\_t}{ nLength = wxSTRING\_MAXLEN}} |
a660d684 | 422 | |
b3324be2 | 423 | Takes first {\it nLength} characters from the C string {\it psz}. |
bd8465ff | 424 | The default value of {\tt wxSTRING\_MAXLEN} means to take all the string. |
f6bcfd97 BP |
425 | |
426 | Note that this constructor may be used even if {\it psz} points to a buffer | |
427 | with binary data (i.e. containing {\tt NUL} characters) as long as you provide | |
428 | the correct value for {\it nLength}. However, the default form of it works | |
429 | only with strings without intermediate {\tt NUL}s because it uses | |
430 | {\tt strlen()} to calculate the effective length and it would not give correct | |
431 | results otherwise. | |
a660d684 | 432 | |
99f09bc1 | 433 | \func{}{wxString}{\param{const unsigned char*}{ psz}, \param{size\_t}{ nLength = wxSTRING\_MAXLEN}} |
a660d684 | 434 | |
b3324be2 | 435 | For compilers using unsigned char: takes first {\it nLength} characters from the C string {\it psz}. |
bd8465ff | 436 | The default value of {\tt wxSTRING\_MAXLEN} means take all the string. |
a660d684 | 437 | |
bd8465ff VS |
438 | {\bf Note:} In Unicode build, all of the above constructors take |
439 | {\tt wchar\_t} arguments instead of {\tt char}. | |
a660d684 | 440 | |
bd8465ff VS |
441 | \wxheading{Constructors with conversion} |
442 | ||
443 | The following constructors allow you to construct wxString from wide string | |
444 | in ANSI build or from C string in Unicode build. | |
445 | ||
446 | \func{}{wxString}{\param{const wchar\_t*}{ psz}, \param{wxMBConv\&}{ conv}, \param{size\_t}{ nLength = wxSTRING\_MAXLEN}} | |
447 | ||
448 | Initializes the string from first \arg{nLength} characters of wide string. | |
449 | The default value of {\tt wxSTRING\_MAXLEN} means take all the string. | |
450 | In ANSI build, \arg{conv}'s | |
451 | \helpref{WC2MB}{wxmbconvwc2mb} method is called to | |
452 | convert \arg{psz} to wide string. It is ignored in Unicode build. | |
453 | ||
454 | \func{}{wxString}{\param{const char*}{ psz}, \param{wxMBConv\&}{ conv}, \param{size\_t}{ nLength = wxSTRING\_MAXLEN}} | |
455 | ||
456 | Initializes the string from first \arg{nLength} characters of C string. | |
457 | The default value of {\tt wxSTRING\_MAXLEN} means take all the string. | |
458 | In Unicode build, \arg{conv}'s | |
459 | \helpref{MB2WC}{wxmbconvmb2wc} method is called to | |
460 | convert \arg{psz} to wide string. It is ignored in ANSI build. | |
461 | ||
462 | \wxheading{See also} | |
463 | ||
464 | \helpref{wxMBConv classes}{mbconvclasses}, \helpref{mb\_str}{wxstringmbstr}, | |
465 | \helpref{wc\_str}{wxstringwcstr} | |
a660d684 | 466 | |
b3324be2 | 467 | \membersection{wxString::\destruct{wxString}}\label{wxstringdestruct} |
a660d684 | 468 | |
b3324be2 | 469 | \func{}{\destruct{wxString}}{\void} |
a660d684 | 470 | |
b3324be2 | 471 | String destructor. Note that this is not virtual, so wxString must not be inherited from. |
a660d684 | 472 | |
99f09bc1 VZ |
473 | \membersection{wxString::Alloc}\label{wxstringalloc} |
474 | ||
475 | \func{void}{Alloc}{\param{size\_t}{ nLen}} | |
476 | ||
477 | Preallocate enough space for wxString to store {\it nLen} characters. This function | |
478 | may be used to increase speed when the string is constructed by repeated | |
479 | concatenation as in | |
480 | ||
481 | \begin{verbatim} | |
a660d684 | 482 | |
99f09bc1 VZ |
483 | // delete all vowels from the string |
484 | wxString DeleteAllVowels(const wxString& original) | |
485 | { | |
486 | wxString result; | |
a660d684 | 487 | |
99f09bc1 | 488 | size_t len = original.length(); |
a660d684 | 489 | |
99f09bc1 VZ |
490 | result.Alloc(len); |
491 | ||
492 | for ( size_t n = 0; n < len; n++ ) | |
493 | { | |
494 | if ( strchr("aeuio", tolower(original[n])) == NULL ) | |
495 | result += original[n]; | |
496 | } | |
497 | ||
498 | return result; | |
499 | } | |
500 | ||
501 | \end{verbatim} | |
502 | ||
dbd94b75 | 503 | because it will avoid the need to reallocate string memory many times (in case |
99f09bc1 VZ |
504 | of long strings). Note that it does not set the maximal length of a string - it |
505 | will still expand if more than {\it nLen} characters are stored in it. Also, it | |
506 | does not truncate the existing string (use | |
507 | \helpref{Truncate()}{wxstringtruncate} for this) even if its current length is | |
508 | greater than {\it nLen} | |
509 | ||
510 | \membersection{wxString::Append}\label{wxstringappend} | |
b3324be2 JS |
511 | |
512 | \func{wxString\&}{Append}{\param{const char*}{ psz}} | |
a660d684 | 513 | |
b3324be2 | 514 | Concatenates {\it psz} to this string, returning a reference to it. |
a660d684 | 515 | |
b3324be2 | 516 | \func{wxString\&}{Append}{\param{char}{ ch}, \param{int}{ count = 1}} |
a660d684 | 517 | |
b3324be2 JS |
518 | Concatenates character {\it ch} to this string, {\it count} times, returning a reference |
519 | to it. | |
520 | ||
99f09bc1 | 521 | \membersection{wxString::AfterFirst}\label{wxstringafterfirst} |
b3324be2 | 522 | |
99f09bc1 | 523 | \constfunc{wxString}{AfterFirst}{\param{char}{ ch}} |
b3324be2 | 524 | |
7335902d | 525 | Gets all the characters after the first occurrence of {\it ch}. |
b3324be2 | 526 | Returns the empty string if {\it ch} is not found. |
a660d684 | 527 | |
99f09bc1 | 528 | \membersection{wxString::AfterLast}\label{wxstringafterlast} |
a660d684 | 529 | |
99f09bc1 VZ |
530 | \constfunc{wxString}{AfterLast}{\param{char}{ ch}} |
531 | ||
7335902d | 532 | Gets all the characters after the last occurrence of {\it ch}. |
99f09bc1 VZ |
533 | Returns the whole string if {\it ch} is not found. |
534 | ||
535 | \membersection{wxString::BeforeFirst}\label{wxstringbeforefirst} | |
536 | ||
537 | \constfunc{wxString}{BeforeFirst}{\param{char}{ ch}} | |
538 | ||
7335902d | 539 | Gets all characters before the first occurrence of {\it ch}. |
99f09bc1 VZ |
540 | Returns the whole string if {\it ch} is not found. |
541 | ||
542 | \membersection{wxString::BeforeLast}\label{wxstringbeforelast} | |
543 | ||
544 | \constfunc{wxString}{BeforeLast}{\param{char}{ ch}} | |
b3324be2 | 545 | |
7335902d | 546 | Gets all characters before the last occurrence of {\it ch}. |
99f09bc1 | 547 | Returns the empty string if {\it ch} is not found. |
a660d684 | 548 | |
ed93168b VZ |
549 | \membersection{wxString::c\_str}\label{wxstringcstr} |
550 | ||
f5409ef1 | 551 | \constfunc{const wxChar *}{c\_str}{\void} |
ed93168b | 552 | |
bd8465ff VS |
553 | Returns a pointer to the string data ({\tt const char*} in ANSI build, |
554 | {\tt const wchar\_t*} in Unicode build). | |
555 | ||
556 | \wxheading{See also} | |
557 | ||
558 | \helpref{mb\_str}{wxstringmbstr}, \helpref{wc\_str}{wxstringwcstr}, | |
559 | \helpref{fn\_str}{wxstringfnstr} | |
ed93168b VZ |
560 | |
561 | \membersection{wxString::Clear}\label{wxstringclear} | |
562 | ||
563 | \func{void}{Clear}{\void} | |
564 | ||
565 | Empties the string and frees memory occupied by it. | |
566 | ||
567 | See also: \helpref{Empty}{wxstringempty} | |
568 | ||
f7bd2698 JS |
569 | \membersection{wxString::Cmp}\label{wxstringcmp} |
570 | ||
06e317a3 VZ |
571 | \constfunc{int}{Cmp}{\param{const wxString\&}{ s}} |
572 | ||
f7bd2698 JS |
573 | \constfunc{int}{Cmp}{\param{const char*}{ psz}} |
574 | ||
575 | Case-sensitive comparison. | |
576 | ||
99f09bc1 | 577 | Returns a positive value if the string is greater than the argument, zero if |
f6bcfd97 | 578 | it is equal to it or a negative value if it is less than the argument (same semantics |
99f09bc1 | 579 | as the standard {\it strcmp()} function). |
f7bd2698 | 580 | |
99f09bc1 | 581 | See also \helpref{CmpNoCase}{wxstringcmpnocase}, \helpref{IsSameAs}{wxstringissameas}. |
f7bd2698 JS |
582 | |
583 | \membersection{wxString::CmpNoCase}\label{wxstringcmpnocase} | |
584 | ||
06e317a3 VZ |
585 | \constfunc{int}{CmpNoCase}{\param{const wxString\&}{ s}} |
586 | ||
f7bd2698 JS |
587 | \constfunc{int}{CmpNoCase}{\param{const char*}{ psz}} |
588 | ||
589 | Case-insensitive comparison. | |
590 | ||
99f09bc1 | 591 | Returns a positive value if the string is greater than the argument, zero if |
f6bcfd97 | 592 | it is equal to it or a negative value if it is less than the argument (same semantics |
99f09bc1 | 593 | as the standard {\it strcmp()} function). |
f7bd2698 | 594 | |
99f09bc1 | 595 | See also \helpref{Cmp}{wxstringcmp}, \helpref{IsSameAs}{wxstringissameas}. |
f7bd2698 | 596 | |
99f09bc1 | 597 | \membersection{wxString::CompareTo}\label{wxstringcompareto} |
a660d684 KB |
598 | |
599 | \begin{verbatim} | |
600 | #define NO_POS ((int)(-1)) // undefined position | |
b3324be2 | 601 | enum caseCompare {exact, ignoreCase}; |
a660d684 | 602 | \end{verbatim} |
ed93168b | 603 | |
b3324be2 | 604 | \constfunc{int}{CompareTo}{\param{const char*}{ psz}, \param{caseCompare}{ cmp = exact}} |
a660d684 | 605 | |
b3324be2 | 606 | Case-sensitive comparison. Returns 0 if equal, 1 if greater or -1 if less. |
a660d684 | 607 | |
99f09bc1 | 608 | \membersection{wxString::Contains}\label{wxstringcontains} |
a660d684 | 609 | |
99f09bc1 | 610 | \constfunc{bool}{Contains}{\param{const wxString\&}{ str}} |
a660d684 | 611 | |
dbd94b75 | 612 | Returns 1 if target appears anywhere in wxString; else 0. |
a660d684 | 613 | |
f7bd2698 | 614 | \membersection{wxString::Empty}\label{wxstringempty} |
a660d684 | 615 | |
f7bd2698 JS |
616 | \func{void}{Empty}{\void} |
617 | ||
ed93168b VZ |
618 | Makes the string empty, but doesn't free memory occupied by the string. |
619 | ||
620 | See also: \helpref{Clear()}{wxstringclear}. | |
f7bd2698 JS |
621 | |
622 | \membersection{wxString::Find}\label{wxstringfind} | |
623 | ||
cc81d32f | 624 | \constfunc{int}{Find}{\param{char}{ ch}, \param{bool}{ fromEnd = false}} |
f7bd2698 JS |
625 | |
626 | Searches for the given character. Returns the starting index, or -1 if not found. | |
627 | ||
628 | \constfunc{int}{Find}{\param{const char*}{ sz}} | |
629 | ||
630 | Searches for the given string. Returns the starting index, or -1 if not found. | |
a660d684 | 631 | |
b3324be2 | 632 | \membersection{wxString::First}\label{wxstringfirst} |
a660d684 | 633 | |
0aa35d19 | 634 | \func{int}{First}{\param{char}{ c}} |
a660d684 | 635 | |
0aa35d19 | 636 | \constfunc{int}{First}{\param{const char*}{ psz}} |
a660d684 | 637 | |
0aa35d19 | 638 | \constfunc{int}{First}{\param{const wxString\&}{ str}} |
a660d684 | 639 | |
0aa35d19 | 640 | Same as \helpref{Find}{wxstringfind}. |
a660d684 | 641 | |
bd8465ff VS |
642 | \membersection{wxString::fn\_str}\label{wxstringfnstr} |
643 | ||
644 | \constfunc{const wchar\_t*}{fn\_str}{\void} | |
645 | ||
646 | \constfunc{const char*}{fn\_str}{\void} | |
647 | ||
648 | \constfunc{const wxCharBuffer}{fn\_str}{\void} | |
649 | ||
650 | Returns string representation suitable for passing to OS' functions for | |
651 | file handling. In ANSI build, this is same as \helpref{c\_str}{wxstringcstr}. | |
652 | In Unicode build, returned value can be either wide character string | |
9c3d92c5 | 653 | or C string in charset matching the {\tt wxConvFileName} object, depending on |
bd8465ff VS |
654 | the OS. |
655 | ||
656 | \wxheading{See also} | |
657 | ||
658 | \helpref{wxMBConv}{wxmbconv}, | |
659 | \helpref{wc\_str}{wxstringwcstr}, \helpref{mb\_str}{wxstringwcstr} | |
660 | ||
341e7d28 VZ |
661 | \membersection{wxString::Format}\label{wxstringformat} |
662 | ||
663 | \func{static wxString}{Format}{\param{const wxChar }{*format}, \param{}{...}} | |
664 | ||
665 | This static function returns the string containing the result of calling | |
666 | \helpref{Printf}{wxstringprintf} with the passed parameters on it. | |
667 | ||
668 | \wxheading{See also} | |
669 | ||
670 | \helpref{FormatV}{wxstringformatv}, \helpref{Printf}{wxstringprintf} | |
671 | ||
672 | \membersection{wxString::FormatV}\label{wxstringformatv} | |
673 | ||
3980000c | 674 | \func{static wxString}{FormatV}{\param{const wxChar }{*format}, \param{va\_list }{argptr}} |
341e7d28 VZ |
675 | |
676 | This static function returns the string containing the result of calling | |
677 | \helpref{PrintfV}{wxstringprintfv} with the passed parameters on it. | |
678 | ||
679 | \wxheading{See also} | |
680 | ||
681 | \helpref{Format}{wxstringformat}, \helpref{PrintfV}{wxstringprintfv} | |
682 | ||
99f09bc1 VZ |
683 | \membersection{wxString::Freq}\label{wxstringfreq} |
684 | ||
f6bcfd97 | 685 | \constfunc{int}{Freq}{\param{char }{ch}} |
99f09bc1 | 686 | |
f6bcfd97 | 687 | Returns the number of occurrences of {\it ch} in the string. |
99f09bc1 | 688 | |
6d9d6350 JS |
689 | \membersection{wxString::FromAscii}\label{wxstringfromascii} |
690 | ||
691 | \func{static wxString }{FromAscii}{\param{const char*}{ s}} | |
692 | ||
693 | \func{static wxString }{FromAscii}{\param{const char}{ c}} | |
694 | ||
695 | Converts the string or character from an ASCII, 7-bit form | |
696 | to the native wxString representation. Most useful when using | |
fc2171bd | 697 | a Unicode build of wxWidgets. |
bd8465ff VS |
698 | Use \helpref{wxString constructors}{wxstringconstruct} if you |
699 | need to convert from another charset. | |
6d9d6350 | 700 | |
f7bd2698 | 701 | \membersection{wxString::GetChar}\label{wxstringgetchar} |
a660d684 | 702 | |
f7bd2698 | 703 | \constfunc{char}{GetChar}{\param{size\_t}{ n}} |
a660d684 | 704 | |
f7bd2698 | 705 | Returns the character at position {\it n} (read-only). |
a660d684 | 706 | |
99f09bc1 | 707 | \membersection{wxString::GetData}\label{wxstringgetdata} |
a660d684 | 708 | |
f5409ef1 | 709 | \constfunc{const wxChar*}{GetData}{\void} |
a660d684 | 710 | |
fc2171bd | 711 | wxWidgets compatibility conversion. Returns a constant pointer to the data in the string. |
a660d684 | 712 | |
f7bd2698 | 713 | \membersection{wxString::GetWritableChar}\label{wxstringgetwritablechar} |
a660d684 | 714 | |
f7bd2698 | 715 | \func{char\&}{GetWritableChar}{\param{size\_t}{ n}} |
a660d684 | 716 | |
f7bd2698 | 717 | Returns a reference to the character at position {\it n}. |
a660d684 | 718 | |
f7bd2698 | 719 | \membersection{wxString::GetWriteBuf}\label{wxstringgetwritebuf} |
a660d684 | 720 | |
9a55c2ee | 721 | \func{wxChar*}{GetWriteBuf}{\param{size\_t}{ len}} |
a660d684 | 722 | |
f7bd2698 | 723 | Returns a writable buffer of at least {\it len} bytes. |
8161ba08 JS |
724 | It returns a pointer to a new memory block, and the |
725 | existing data will not be copied. | |
a660d684 | 726 | |
f7bd2698 JS |
727 | Call \helpref{wxString::UngetWriteBuf}{wxstringungetwritebuf} as soon as possible |
728 | to put the string back into a reasonable state. | |
a660d684 | 729 | |
99f09bc1 | 730 | \membersection{wxString::Index}\label{wxstringindex} |
a660d684 | 731 | |
5ef056a3 | 732 | \constfunc{size\_t}{Index}{\param{char}{ ch}} |
a660d684 | 733 | |
f7bd2698 | 734 | \constfunc{size\_t}{Index}{\param{const char*}{ sz}} |
a660d684 | 735 | |
f7bd2698 | 736 | Same as \helpref{wxString::Find}{wxstringfind}. |
a660d684 | 737 | |
8a2c6ef8 JS |
738 | % TODO |
739 | %\membersection{wxString::insert}\label{wxstringinsert} | |
740 | % Wrong! | |
99f09bc1 | 741 | %\func{void}{insert}{\param{const wxString\&}{ str}, \param{size\_t}{ index}} |
8a2c6ef8 JS |
742 | % |
743 | %Add new element at the given position. | |
744 | % | |
99f09bc1 | 745 | \membersection{wxString::IsAscii}\label{wxstringisascii} |
a660d684 | 746 | |
f7bd2698 | 747 | \constfunc{bool}{IsAscii}{\void} |
a660d684 | 748 | |
cc81d32f | 749 | Returns true if the string contains only ASCII characters. |
a660d684 | 750 | |
f7bd2698 | 751 | \membersection{wxString::IsEmpty}\label{wxstringisempty} |
a660d684 | 752 | |
f7bd2698 | 753 | \constfunc{bool}{IsEmpty}{\void} |
a660d684 | 754 | |
cc81d32f | 755 | Returns true if the string is empty. |
a660d684 | 756 | |
99f09bc1 | 757 | \membersection{wxString::IsNull}\label{wxstringisnull} |
a660d684 | 758 | |
f7bd2698 | 759 | \constfunc{bool}{IsNull}{\void} |
a660d684 | 760 | |
cc81d32f | 761 | Returns true if the string is empty (same as \helpref{IsEmpty}{wxstringisempty}). |
a660d684 | 762 | |
99f09bc1 | 763 | \membersection{wxString::IsNumber}\label{wxstringisnumber} |
a660d684 | 764 | |
f7bd2698 JS |
765 | \constfunc{bool}{IsNumber}{\void} |
766 | ||
cc81d32f | 767 | Returns true if the string is an integer (with possible sign). |
f7bd2698 JS |
768 | |
769 | \membersection{wxString::IsSameAs}\label{wxstringissameas} | |
770 | ||
cc81d32f | 771 | \constfunc{bool}{IsSameAs}{\param{const char*}{ psz}, \param{bool}{ caseSensitive = true}} |
f7bd2698 JS |
772 | |
773 | Test for string equality, case-sensitive (default) or not. | |
774 | ||
cc81d32f | 775 | caseSensitive is true by default (case matters). |
a660d684 | 776 | |
cc81d32f | 777 | Returns true if strings are equal, false otherwise. |
f7bd2698 | 778 | |
4b4fae9b | 779 | See also \helpref{Cmp}{wxstringcmp}, \helpref{CmpNoCase}{wxstringcmpnocase} |
f33fee2a | 780 | |
cc81d32f | 781 | \constfunc{bool}{IsSameAs}{\param{char}{ c}, \param{bool}{ caseSensitive = true}} |
f33fee2a VZ |
782 | |
783 | Test whether the string is equal to the single character {\it c}. The test is | |
cc81d32f | 784 | case-sensitive if {\it caseSensitive} is true (default) or not if it is false. |
f33fee2a | 785 | |
cc81d32f | 786 | Returns true if the string is equal to the character, false otherwise. |
f33fee2a | 787 | |
4b4fae9b | 788 | See also \helpref{Cmp}{wxstringcmp}, \helpref{CmpNoCase}{wxstringcmpnocase} |
a660d684 | 789 | |
99f09bc1 | 790 | \membersection{wxString::IsWord}\label{wxstringisword} |
a660d684 | 791 | |
f7bd2698 | 792 | \constfunc{bool}{IsWord}{\void} |
a660d684 | 793 | |
cc81d32f | 794 | Returns true if the string is a word. TODO: what's the definition of a word? |
a660d684 | 795 | |
99f09bc1 | 796 | \membersection{wxString::Last}\label{wxstringlast} |
a660d684 | 797 | |
f7bd2698 | 798 | \constfunc{char}{Last}{\void} |
a660d684 | 799 | |
f7bd2698 | 800 | Returns the last character. |
a660d684 | 801 | |
f7bd2698 | 802 | \func{char\&}{Last}{\void} |
a660d684 | 803 | |
f7bd2698 | 804 | Returns a reference to the last character (writable). |
a660d684 | 805 | |
f7bd2698 JS |
806 | \membersection{wxString::Left}\label{wxstringleft} |
807 | ||
808 | \constfunc{wxString}{Left}{\param{size\_t}{ count}} | |
809 | ||
fefc4f15 | 810 | Returns the first {\it count} characters of the string. |
a660d684 | 811 | |
f7bd2698 | 812 | \membersection{wxString::Len}\label{wxstringlen} |
a660d684 | 813 | |
f7bd2698 JS |
814 | \constfunc{size\_t}{Len}{\void} |
815 | ||
816 | Returns the length of the string. | |
817 | ||
818 | \membersection{wxString::Length}\label{wxstringlength} | |
819 | ||
820 | \constfunc{size\_t}{Length}{\void} | |
821 | ||
822 | Returns the length of the string (same as Len). | |
a660d684 | 823 | |
99f09bc1 VZ |
824 | \membersection{wxString::Lower}\label{wxstringlower} |
825 | ||
826 | \constfunc{wxString}{Lower}{\void} | |
827 | ||
828 | Returns this string converted to the lower case. | |
829 | ||
830 | \membersection{wxString::LowerCase}\label{wxstringlowercase} | |
a660d684 | 831 | |
f7bd2698 JS |
832 | \func{void}{LowerCase}{\void} |
833 | ||
834 | Same as MakeLower. | |
835 | ||
836 | \membersection{wxString::MakeLower}\label{wxstringmakelower} | |
837 | ||
e16f8973 | 838 | \func{wxString\&}{MakeLower}{\void} |
f7bd2698 | 839 | |
e16f8973 | 840 | Converts all characters to lower case and returns the result. |
f7bd2698 JS |
841 | |
842 | \membersection{wxString::MakeUpper}\label{wxstringmakeupper} | |
843 | ||
e16f8973 | 844 | \func{wxString\&}{MakeUpper}{\void} |
f7bd2698 | 845 | |
e16f8973 | 846 | Converts all characters to upper case and returns the result. |
a660d684 | 847 | |
99f09bc1 | 848 | \membersection{wxString::Matches}\label{wxstringmatches} |
a660d684 | 849 | |
f7bd2698 JS |
850 | \constfunc{bool}{Matches}{\param{const char*}{ szMask}} |
851 | ||
cc81d32f | 852 | Returns true if the string contents matches a mask containing '*' and '?'. |
a660d684 | 853 | |
bd8465ff VS |
854 | \membersection{wxString::mb\_str}\label{wxstringmbstr} |
855 | ||
856 | \constfunc{const char*}{mb\_str}{\param{wxMBConv\&}{ conv}} | |
857 | ||
858 | \constfunc{const wxCharBuffer}{mb\_str}{\param{wxMBConv\&}{ conv}} | |
859 | ||
860 | Returns multibyte (C string) representation of the string. | |
861 | In Unicode build, converts using \arg{conv}'s \helpref{cWC2MB}{wxmbconvcwc2mb} | |
862 | method and returns wxCharBuffer. In ANSI build, this function is same | |
863 | as \helpref{c\_str}{wxstringcstr}. | |
864 | The macro wxWX2MBbuf is defined as the correct return type (without const). | |
865 | ||
866 | \wxheading{See also} | |
867 | ||
868 | \helpref{wxMBConv}{wxmbconv}, | |
869 | \helpref{c\_str}{wxstringcstr}, \helpref{wc\_str}{wxstringwcstr}, | |
870 | \helpref{fn\_str}{wxstringfnstr} | |
871 | ||
f7bd2698 | 872 | \membersection{wxString::Mid}\label{wxstringmid} |
a660d684 | 873 | |
99f09bc1 | 874 | \constfunc{wxString}{Mid}{\param{size\_t}{ first}, \param{size\_t}{ count = wxSTRING\_MAXLEN}} |
a660d684 | 875 | |
f7bd2698 JS |
876 | Returns a substring starting at {\it first}, with length {\it count}, or the rest of |
877 | the string if {\it count} is the default value. | |
878 | ||
879 | \membersection{wxString::Pad}\label{wxstringpad} | |
880 | ||
cc81d32f | 881 | \func{wxString\&}{Pad}{\param{size\_t}{ count}, \param{char}{ pad = ' '}, \param{bool}{ fromRight = true}} |
f7bd2698 JS |
882 | |
883 | Adds {\it count} copies of {\it pad} to the beginning, or to the end of the string (the default). | |
884 | ||
885 | Removes spaces from the left or from the right (default). | |
a660d684 | 886 | |
99f09bc1 | 887 | \membersection{wxString::Prepend}\label{wxstringprepend} |
a660d684 | 888 | |
f7bd2698 | 889 | \func{wxString\&}{Prepend}{\param{const wxString\&}{ str}} |
a660d684 | 890 | |
f7bd2698 | 891 | Prepends {\it str} to this string, returning a reference to this string. |
a660d684 | 892 | |
f7bd2698 | 893 | \membersection{wxString::Printf}\label{wxstringprintf} |
a660d684 | 894 | |
f7bd2698 JS |
895 | \func{int}{Printf}{\param{const char* }{pszFormat}, \param{}{...}} |
896 | ||
99f09bc1 VZ |
897 | Similar to the standard function {\it sprintf()}. Returns the number of |
898 | characters written, or an integer less than zero on error. | |
899 | ||
418ab1e7 | 900 | Note that if {\tt wxUSE\_PRINTF\_POS\_PARAMS} is set to 1, then this function supports |
412a5c57 VZ |
901 | Unix98-style positional parameters: |
902 | ||
903 | \begin{verbatim} | |
904 | wxString str; | |
905 | ||
906 | str.Printf(wxT("%d %d %d"), 1, 2, 3); | |
907 | // str now contains "1 2 3" | |
908 | ||
909 | str.Printf(wxT("%2$d %3$d %1$d"), 1, 2, 3); | |
910 | // str now contains "2 3 1" | |
911 | \end{verbatim} | |
912 | ||
99f09bc1 VZ |
913 | {\bf NB:} This function will use a safe version of {\it vsprintf()} (usually called |
914 | {\it vsnprintf()}) whenever available to always allocate the buffer of correct | |
915 | size. Unfortunately, this function is not available on all platforms and the | |
916 | dangerous {\it vsprintf()} will be used then which may lead to buffer overflows. | |
a660d684 | 917 | |
f7bd2698 JS |
918 | \membersection{wxString::PrintfV}\label{wxstringprintfv} |
919 | ||
920 | \func{int}{PrintfV}{\param{const char* }{pszFormat}, \param{va\_list}{ argPtr}} | |
921 | ||
922 | Similar to vprintf. Returns the number of characters written, or an integer less than zero | |
923 | on error. | |
a660d684 | 924 | |
99f09bc1 | 925 | \membersection{wxString::Remove}\label{wxstringremove} |
a660d684 | 926 | |
f7bd2698 JS |
927 | \func{wxString\&}{Remove}{\param{size\_t}{ pos}} |
928 | ||
929 | Same as Truncate. Removes the portion from {\it pos} to the end of the string. | |
930 | ||
931 | \func{wxString\&}{Remove}{\param{size\_t}{ pos}, \param{size\_t}{ len}} | |
932 | ||
08890e27 | 933 | Removes {\it len} characters from the string, starting at {\it pos}. |
f7bd2698 JS |
934 | |
935 | \membersection{wxString::RemoveLast}\label{wxstringremovelast} | |
a660d684 | 936 | |
f7bd2698 JS |
937 | \func{wxString\&}{RemoveLast}{\void} |
938 | ||
939 | Removes the last character. | |
a660d684 | 940 | |
99f09bc1 | 941 | \membersection{wxString::Replace}\label{wxstringreplace} |
a660d684 | 942 | |
cc81d32f | 943 | \func{size\_t}{Replace}{\param{const char*}{ szOld}, \param{const char*}{ szNew}, \param{bool}{ replaceAll = true}} |
f7bd2698 | 944 | |
7335902d | 945 | Replace first (or all) occurrences of substring with another one. |
f7bd2698 | 946 | |
7335902d | 947 | {\it replaceAll}: global replace (default), or only the first occurrence. |
f7bd2698 JS |
948 | |
949 | Returns the number of replacements made. | |
950 | ||
951 | \membersection{wxString::Right}\label{wxstringright} | |
952 | ||
953 | \constfunc{wxString}{Right}{\param{size\_t}{ count}} | |
a660d684 | 954 | |
f7bd2698 | 955 | Returns the last {\it count} characters. |
a660d684 | 956 | |
f7bd2698 | 957 | \membersection{wxString::SetChar}\label{wxstringsetchar} |
a660d684 | 958 | |
f7bd2698 JS |
959 | \func{void}{SetChar}{\param{size\_t}{ n}, \param{char}{ch}} |
960 | ||
961 | Sets the character at position {\it n}. | |
962 | ||
963 | \membersection{wxString::Shrink}\label{wxstringshrink} | |
964 | ||
965 | \func{void}{Shrink}{\void} | |
966 | ||
99f09bc1 VZ |
967 | Minimizes the string's memory. This can be useful after a call to |
968 | \helpref{Alloc()}{wxstringalloc} if too much memory were preallocated. | |
a660d684 KB |
969 | |
970 | \membersection{wxString::sprintf}\label{wxstringsprintf} | |
a660d684 | 971 | |
f7bd2698 | 972 | \func{void}{sprintf}{\param{const char* }{ fmt}} |
a660d684 | 973 | |
f7bd2698 | 974 | The same as Printf. |
a660d684 | 975 | |
f6bcfd97 BP |
976 | \membersection{wxString::StartsWith}\label{wxstringstartswith} |
977 | ||
978 | \constfunc{bool}{StartsWith}{\param{const wxChar }{*prefix}, \param{wxString }{*rest = NULL}} | |
979 | ||
980 | This function can be used to test if the string starts with the specified | |
cc81d32f | 981 | {\it prefix}. If it does, the function will return {\tt true} and put the rest |
f6bcfd97 | 982 | of the string (i.e. after the prefix) into {\it rest} string if it is not |
cc81d32f | 983 | {\tt NULL}. Otherwise, the function returns {\tt false} and doesn't modify the |
f6bcfd97 BP |
984 | {\it rest}. |
985 | ||
3affcd07 VZ |
986 | \membersection{wxString::EndsWith}\label{wxstringendswith} |
987 | ||
988 | \constfunc{bool}{EndsWith}{\param{const wxChar }{*suffix}, \param{wxString }{*rest = NULL}} | |
989 | ||
990 | This function can be used to test if the string ends with the specified | |
991 | {\it suffix}. If it does, the function will return {\tt true} and put the | |
992 | beginning of the string before the suffix into {\it rest} string if it is not | |
993 | {\tt NULL}. Otherwise, the function returns {\tt false} and doesn't | |
994 | modify the {\it rest}. | |
995 | ||
99f09bc1 | 996 | \membersection{wxString::Strip}\label{wxstringstrip} |
a660d684 KB |
997 | |
998 | \begin{verbatim} | |
f7bd2698 | 999 | enum stripType {leading = 0x1, trailing = 0x2, both = 0x3}; |
a660d684 KB |
1000 | \end{verbatim} |
1001 | ||
f7bd2698 | 1002 | \constfunc{wxString}{Strip}{\param{stripType}{ s = trailing}} |
a660d684 | 1003 | |
f7bd2698 JS |
1004 | Strip characters at the front and/or end. The same as Trim except that it |
1005 | doesn't change this string. | |
a660d684 | 1006 | |
99f09bc1 VZ |
1007 | \membersection{wxString::SubString}\label{wxstringsubstring} |
1008 | ||
f6bcfd97 | 1009 | \constfunc{wxString}{SubString}{\param{size\_t}{ from}, \param{size\_t}{ to}} |
99f09bc1 | 1010 | |
b855ef77 VZ |
1011 | Deprecated, use \helpref{Mid}{wxstringmid} instead (but note that parameters |
1012 | have different meaning). | |
1013 | ||
1014 | Returns the part of the string between the indices {\it from} and {\it to} | |
1015 | inclusive. | |
99f09bc1 | 1016 | |
6d9d6350 JS |
1017 | \membersection{wxString::ToAscii}\label{wxstringtoascii} |
1018 | ||
1019 | \constfunc{const char*}{ToAscii}{\void} | |
1020 | ||
1021 | Converts the string to an ASCII, 7-bit string (ANSI builds only). | |
1022 | ||
1023 | \constfunc{const wxCharBuffer}{ToAscii}{\void} | |
1024 | ||
1025 | Converts the string to an ASCII, 7-bit string in the form of | |
1026 | a wxCharBuffer (Unicode builds only). | |
1027 | ||
bd8465ff VS |
1028 | Note that this conversion only works if the string contains only ASCII |
1029 | characters. The \helpref{mb\_str}{wxstringmbstr} method provides more | |
1030 | powerful means of converting wxString to C string. | |
1031 | ||
cd0b1709 VZ |
1032 | \membersection{wxString::ToDouble}\label{wxstringtodouble} |
1033 | ||
f6bcfd97 | 1034 | \constfunc{bool}{ToDouble}{\param{double}{ *val}} |
cd0b1709 | 1035 | |
cc81d32f VS |
1036 | Attempts to convert the string to a floating point number. Returns true on |
1037 | success (the number is stored in the location pointed to by {\it val}) or false | |
cd0b1709 VZ |
1038 | if the string does not represent such number. |
1039 | ||
f6bcfd97 BP |
1040 | \wxheading{See also} |
1041 | ||
1042 | \helpref{wxString::ToLong}{wxstringtolong},\\ | |
1043 | \helpref{wxString::ToULong}{wxstringtoulong} | |
1044 | ||
cd0b1709 VZ |
1045 | \membersection{wxString::ToLong}\label{wxstringtolong} |
1046 | ||
538f35cc | 1047 | \constfunc{bool}{ToLong}{\param{long}{ *val}, \param{int }{base = $10$}} |
cd0b1709 | 1048 | |
4eb438cf | 1049 | Attempts to convert the string to a signed integer in base {\it base}. Returns |
cc81d32f VS |
1050 | {\tt true} on success in which case the number is stored in the location |
1051 | pointed to by {\it val} or {\tt false} if the string does not represent a | |
4eb438cf VZ |
1052 | valid number in the given base. |
1053 | ||
538f35cc VZ |
1054 | The value of {\it base} must be comprised between $2$ and $36$, inclusive, or |
1055 | be a special value $0$ which means that the usual rules of {\tt C} numbers are | |
1056 | applied: if the number starts with {\tt 0x} it is considered to be in base | |
1057 | $16$, if it starts with {\tt 0} - in base $8$ and in base $10$ otherwise. Note | |
1058 | that you may not want to specify the base $0$ if you are parsing the numbers | |
1059 | which may have leading zeroes as they can yield unexpected (to the user not | |
1060 | familiar with C) results. | |
cd0b1709 | 1061 | |
f6bcfd97 BP |
1062 | \wxheading{See also} |
1063 | ||
1064 | \helpref{wxString::ToDouble}{wxstringtodouble},\\ | |
1065 | \helpref{wxString::ToULong}{wxstringtoulong} | |
1066 | ||
cd0b1709 VZ |
1067 | \membersection{wxString::ToULong}\label{wxstringtoulong} |
1068 | ||
538f35cc | 1069 | \constfunc{bool}{ToULong}{\param{unsigned long}{ *val}, \param{int }{base = $10$}} |
4eb438cf | 1070 | |
3980000c | 1071 | Attempts to convert the string to an unsigned integer in base {\it base}. |
cc81d32f VS |
1072 | Returns {\tt true} on success in which case the number is stored in the |
1073 | location pointed to by {\it val} or {\tt false} if the string does not | |
731fa21e VZ |
1074 | represent a valid number in the given base. Please notice that this function |
1075 | behaves in the same way as the standard \texttt{strtoul()} and so it simply | |
1076 | converts negative numbers to unsigned representation instead of rejecting them | |
1077 | (e.g. $-1$ is returned as \texttt{ULONG\_MAX}). | |
cd0b1709 | 1078 | |
ec64d632 VZ |
1079 | See \helpref{wxString::ToLong}{wxstringtolong} for the more detailed |
1080 | description of the {\it base} parameter. | |
cd0b1709 | 1081 | |
f6bcfd97 BP |
1082 | \wxheading{See also} |
1083 | ||
1084 | \helpref{wxString::ToDouble}{wxstringtodouble},\\ | |
1085 | \helpref{wxString::ToLong}{wxstringtolong} | |
1086 | ||
f7bd2698 | 1087 | \membersection{wxString::Trim}\label{wxstringtrim} |
a660d684 | 1088 | |
cc81d32f | 1089 | \func{wxString\&}{Trim}{\param{bool}{ fromRight = true}} |
a660d684 | 1090 | |
4e43c815 VZ |
1091 | Removes white-space (space, tabs, form feed, newline and carriage return) from |
1092 | the left or from the right end of the string (right is default). | |
a660d684 | 1093 | |
f7bd2698 | 1094 | \membersection{wxString::Truncate}\label{wxstringtruncate} |
a660d684 | 1095 | |
f7bd2698 | 1096 | \func{wxString\&}{Truncate}{\param{size\_t}{ len}} |
a660d684 | 1097 | |
f7bd2698 | 1098 | Truncate the string to the given length. |
a660d684 | 1099 | |
f7bd2698 JS |
1100 | \membersection{wxString::UngetWriteBuf}\label{wxstringungetwritebuf} |
1101 | ||
1102 | \func{void}{UngetWriteBuf}{\void} | |
1103 | ||
448025b0 VZ |
1104 | \func{void}{UngetWriteBuf}{\param{size\_t }{len}} |
1105 | ||
1106 | Puts the string back into a reasonable state (in which it can be used | |
1107 | normally), after | |
f7bd2698 | 1108 | \rtfsp\helpref{wxString::GetWriteBuf}{wxstringgetwritebuf} was called. |
a660d684 | 1109 | |
448025b0 VZ |
1110 | The version of the function without the {\it len} parameter will calculate the |
1111 | new string length itself assuming that the string is terminated by the first | |
1112 | {\tt NUL} character in it while the second one will use the specified length | |
1113 | and thus is the only version which should be used with the strings with | |
1114 | embedded {\tt NUL}s (it is also slightly more efficient as {\tt strlen()} | |
1115 | doesn't have to be called). | |
1116 | ||
99f09bc1 VZ |
1117 | \membersection{wxString::Upper}\label{wxstringupper} |
1118 | ||
1119 | \constfunc{wxString}{Upper}{\void} | |
1120 | ||
1121 | Returns this string converted to upper case. | |
1122 | ||
1123 | \membersection{wxString::UpperCase}\label{wxstringuppercase} | |
a660d684 | 1124 | |
f7bd2698 JS |
1125 | \func{void}{UpperCase}{\void} |
1126 | ||
1127 | The same as MakeUpper. | |
a660d684 | 1128 | |
bd8465ff VS |
1129 | \membersection{wxString::wc\_str}\label{wxstringwcstr} |
1130 | ||
1131 | \constfunc{const wchar\_t*}{wc\_str}{\param{wxMBConv\&}{ conv}} | |
1132 | ||
1133 | \constfunc{const wxWCharBuffer}{wc\_str}{\param{wxMBConv\&}{ conv}} | |
1134 | ||
1135 | Returns wide character representation of the string. | |
1136 | In ANSI build, converts using \arg{conv}'s \helpref{cMB2WC}{wxmbconvcmb2wc} | |
1137 | method and returns wxWCharBuffer. In Unicode build, this function is same | |
1138 | as \helpref{c\_str}{wxstringcstr}. | |
1139 | The macro wxWX2WCbuf is defined as the correct return type (without const). | |
1140 | ||
1141 | \wxheading{See also} | |
1142 | ||
1143 | \helpref{wxMBConv}{wxmbconv}, | |
1144 | \helpref{c\_str}{wxstringcstr}, \helpref{mb\_str}{wxstringwcstr}, | |
1145 | \helpref{fn\_str}{wxstringfnstr} | |
1146 | ||
99f09bc1 VZ |
1147 | \membersection{wxString::operator!}\label{wxstringoperatornot} |
1148 | ||
1149 | \constfunc{bool}{operator!}{\void} | |
1150 | ||
cc81d32f | 1151 | Empty string is false, so !string will only return true if the string is empty. |
dbd94b75 | 1152 | This allows the tests for NULLness of a {\it const char *} pointer and emptiness |
99f09bc1 VZ |
1153 | of the string to look the same in the code and makes it easier to port old code |
1154 | to wxString. | |
1155 | ||
1156 | See also \helpref{IsEmpty()}{wxstringisempty}. | |
1157 | ||
a660d684 KB |
1158 | \membersection{wxString::operator $=$}\label{wxstringoperatorassign} |
1159 | ||
f7bd2698 JS |
1160 | \func{wxString\&}{operator $=$}{\param{const wxString\&}{ str}} |
1161 | ||
1162 | \func{wxString\&}{operator $=$}{\param{const char*}{ psz}} | |
1163 | ||
1164 | \func{wxString\&}{operator $=$}{\param{char}{ c}} | |
1165 | ||
1166 | \func{wxString\&}{operator $=$}{\param{const unsigned char*}{ psz}} | |
1167 | ||
1168 | \func{wxString\&}{operator $=$}{\param{const wchar\_t*}{ pwz}} | |
a660d684 | 1169 | |
99f09bc1 VZ |
1170 | Assignment: the effect of each operation is the same as for the corresponding |
1171 | constructor (see \helpref{wxString constructors}{wxstringconstruct}). | |
5de76427 | 1172 | |
f6bcfd97 | 1173 | \membersection{wxString::operator $+$}\label{wxstringoperatorplus} |
5de76427 | 1174 | |
dbd94b75 KH |
1175 | Concatenation: all these operators return a new string equal to the |
1176 | concatenation of the operands. | |
5de76427 JS |
1177 | |
1178 | \func{wxString}{operator $+$}{\param{const wxString\&}{ x}, \param{const wxString\&}{ y}} | |
1179 | ||
1180 | \func{wxString}{operator $+$}{\param{const wxString\&}{ x}, \param{const char*}{ y}} | |
1181 | ||
1182 | \func{wxString}{operator $+$}{\param{const wxString\&}{ x}, \param{char}{ y}} | |
1183 | ||
1184 | \func{wxString}{operator $+$}{\param{const char*}{ x}, \param{const wxString\&}{ y}} | |
1185 | ||
99f09bc1 | 1186 | \membersection{wxString::operator $+=$}\label{wxstringplusequal} |
a660d684 | 1187 | |
f7bd2698 JS |
1188 | \func{void}{operator $+=$}{\param{const wxString\&}{ str}} |
1189 | ||
1190 | \func{void}{operator $+=$}{\param{const char*}{ psz}} | |
1191 | ||
1192 | \func{void}{operator $+=$}{\param{char}{ c}} | |
a660d684 | 1193 | |
99f09bc1 | 1194 | Concatenation in place: the argument is appended to the string. |
a660d684 KB |
1195 | |
1196 | \membersection{wxString::operator []}\label{wxstringoperatorbracket} | |
1197 | ||
41884be3 | 1198 | \func{wxChar\&}{operator []}{\param{size\_t}{ i}} |
f7bd2698 | 1199 | |
41884be3 | 1200 | \constfunc{wxChar}{operator []}{\param{size\_t}{ i}} |
f7bd2698 | 1201 | |
41884be3 JS |
1202 | \func{wxChar\&}{operator []}{\param{int}{ i}} |
1203 | ||
1204 | \constfunc{wxChar}{operator []}{\param{int}{ i}} | |
a660d684 KB |
1205 | |
1206 | Element extraction. | |
1207 | ||
1208 | \membersection{wxString::operator ()}\label{wxstringoperatorparenth} | |
1209 | ||
f7bd2698 JS |
1210 | \func{wxString}{operator ()}{\param{size\_t}{ start}, \param{size\_t}{ len}} |
1211 | ||
1212 | Same as Mid (substring extraction). | |
a660d684 KB |
1213 | |
1214 | \membersection{wxString::operator \cinsert}\label{wxstringoperatorout} | |
f7bd2698 | 1215 | |
037267e1 | 1216 | \func{wxString\&}{operator \cinsert}{\param{const wxString\&}{ str}} |
f7bd2698 | 1217 | |
037267e1 | 1218 | \func{wxString\&}{operator \cinsert}{\param{const char*}{ psz}} |
f7bd2698 | 1219 | |
037267e1 | 1220 | \func{wxString\&}{operator \cinsert}{\param{char }{ch}} |
f7bd2698 JS |
1221 | |
1222 | Same as $+=$. | |
a660d684 | 1223 | |
99f09bc1 VZ |
1224 | \func{wxString\&}{operator \cinsert}{\param{int}{ i}} |
1225 | ||
1226 | \func{wxString\&}{operator \cinsert}{\param{float}{ f}} | |
1227 | ||
1228 | \func{wxString\&}{operator \cinsert}{\param{double}{ d}} | |
1229 | ||
1230 | These functions work as C++ stream insertion operators: they insert the given | |
1231 | value into the string. Precision or format cannot be set using them, you can use | |
1232 | \helpref{Printf}{wxstringprintf} for this. | |
1233 | ||
a660d684 | 1234 | \membersection{wxString::operator \cextract}\label{wxstringoperatorin} |
a660d684 | 1235 | |
f7bd2698 | 1236 | \func{friend istream\&}{operator \cextract}{\param{istream\&}{ is}, \param{wxString\&}{ str}} |
a660d684 | 1237 | |
f7bd2698 | 1238 | Extraction from a stream. |
a660d684 | 1239 | |
f7bd2698 | 1240 | \membersection{wxString::operator const char*}\label{wxstringoperatorconstcharpt} |
a660d684 | 1241 | |
f7bd2698 | 1242 | \constfunc{}{operator const char*}{\void} |
a660d684 | 1243 | |
f7bd2698 | 1244 | Implicit conversion to a C string. |
a660d684 | 1245 | |
99f09bc1 | 1246 | \membersection{Comparison operators}\label{wxstringcomparison} |
a660d684 | 1247 | |
f7bd2698 | 1248 | \func{bool}{operator $==$}{\param{const wxString\&}{ x}, \param{const wxString\&}{ y}} |
a660d684 | 1249 | |
f7bd2698 | 1250 | \func{bool}{operator $==$}{\param{const wxString\&}{ x}, \param{const char*}{ t}} |
a660d684 | 1251 | |
f7bd2698 | 1252 | \func{bool}{operator $!=$}{\param{const wxString\&}{ x}, \param{const wxString\&}{ y}} |
a660d684 | 1253 | |
f7bd2698 | 1254 | \func{bool}{operator $!=$}{\param{const wxString\&}{ x}, \param{const char*}{ t}} |
a660d684 | 1255 | |
f7bd2698 | 1256 | \func{bool}{operator $>$}{\param{const wxString\&}{ x}, \param{const wxString\&}{ y}} |
a660d684 | 1257 | |
f7bd2698 | 1258 | \func{bool}{operator $>$}{\param{const wxString\&}{ x}, \param{const char*}{ t}} |
a660d684 | 1259 | |
f7bd2698 | 1260 | \func{bool}{operator $>=$}{\param{const wxString\&}{ x}, \param{const wxString\&}{ y}} |
a660d684 | 1261 | |
f7bd2698 | 1262 | \func{bool}{operator $>=$}{\param{const wxString\&}{ x}, \param{const char*}{ t}} |
a660d684 | 1263 | |
f7bd2698 | 1264 | \func{bool}{operator $<$}{\param{const wxString\&}{ x}, \param{const wxString\&}{ y}} |
a660d684 | 1265 | |
f7bd2698 | 1266 | \func{bool}{operator $<$}{\param{const wxString\&}{ x}, \param{const char*}{ t}} |
a660d684 | 1267 | |
f7bd2698 | 1268 | \func{bool}{operator $<=$}{\param{const wxString\&}{ x}, \param{const wxString\&}{ y}} |
a660d684 | 1269 | |
f7bd2698 | 1270 | \func{bool}{operator $<=$}{\param{const wxString\&}{ x}, \param{const char*}{ t}} |
a660d684 | 1271 | |
f7bd2698 | 1272 | \wxheading{Remarks} |
a660d684 | 1273 | |
f7bd2698 | 1274 | These comparisons are case-sensitive. |
a660d684 | 1275 | |
1d218550 VZ |
1276 | |
1277 | \section{\class{wxStringBuffer}}\label{wxstringbuffer} | |
1278 | ||
1279 | This tiny class allows to conveniently access the \helpref{wxString}{wxstring} | |
dbd94b75 | 1280 | internal buffer as a writable pointer without any risk of forgetting to restore |
1d218550 VZ |
1281 | the string to the usable state later. |
1282 | ||
1283 | For example, assuming you have a low-level OS function called | |
1284 | {\tt GetMeaningOfLifeAsString(char *)} returning the value in the provided | |
1285 | buffer (which must be writable, of course) you might call it like this: | |
1286 | ||
1287 | \begin{verbatim} | |
1288 | wxString theAnswer; | |
1289 | GetMeaningOfLifeAsString(wxStringBuffer(theAnswer, 1024)); | |
1290 | if ( theAnswer != "42" ) | |
1291 | { | |
1292 | wxLogError("Something is very wrong!"); | |
1293 | } | |
1294 | \end{verbatim} | |
1295 | ||
5687a67c | 1296 | Note that the exact usage of this depends on whether on not wxUSE\_STL is enabled. If |
3103e8a9 | 1297 | wxUSE\_STL is enabled, wxStringBuffer creates a separate empty character buffer, and |
5687a67c RN |
1298 | if wxUSE\_STL is disabled, it uses GetWriteBuf() from wxString, keeping the same buffer |
1299 | wxString uses intact. In other words, relying on wxStringBuffer containing the old | |
1300 | wxString data is probably not a good idea if you want to build your program in both | |
1301 | with and without wxUSE\_STL. | |
1302 | ||
1d218550 VZ |
1303 | \wxheading{Derived from} |
1304 | ||
1305 | None | |
1306 | ||
1307 | \wxheading{Include files} | |
1308 | ||
1309 | <wx/string.h> | |
1310 | ||
1311 | \latexignore{\rtfignore{\wxheading{Members}}} | |
1312 | ||
08f1d438 | 1313 | \membersection{wxStringBuffer::wxStringBuffer}\label{wxstringbufferctor} |
1d218550 VZ |
1314 | |
1315 | \func{}{wxStringBuffer}{\param{const wxString\& }{str}, \param{size\_t }{len}} | |
1316 | ||
1317 | Constructs a writable string buffer object associated with the given string | |
2edb0bde | 1318 | and containing enough space for at least {\it len} characters. Basically, this |
1d218550 VZ |
1319 | is equivalent to calling \helpref{GetWriteBuf}{wxstringgetwritebuf} and |
1320 | saving the result. | |
1321 | ||
08f1d438 | 1322 | \membersection{wxStringBuffer::\destruct{wxStringBuffer}}\label{wxstringbufferdtor} |
1d218550 VZ |
1323 | |
1324 | \func{}{\destruct{wxStringBuffer}}{\void} | |
1325 | ||
1326 | Restores the string passed to the constructor to the usable state by calling | |
1327 | \helpref{UngetWriteBuf}{wxstringungetwritebuf} on it. | |
1328 | ||
08f1d438 | 1329 | \membersection{wxStringBuffer::operator wxChar *}\label{wxstringbufferwxchar} |
1d218550 | 1330 | |
c298ea48 RN |
1331 | \func{wxChar *}{operator wxChar *}{\void} |
1332 | ||
1333 | Returns the writable pointer to a buffer of the size at least equal to the | |
1334 | length specified in the constructor. | |
1335 | ||
1336 | ||
1337 | ||
1338 | \section{\class{wxStringBufferLength}}\label{wxstringbufferlength} | |
1339 | ||
1340 | This tiny class allows to conveniently access the \helpref{wxString}{wxstring} | |
1341 | internal buffer as a writable pointer without any risk of forgetting to restore | |
1342 | the string to the usable state later, and allows the user to set the internal | |
1343 | length of the string. | |
1344 | ||
1345 | For example, assuming you have a low-level OS function called | |
1346 | {\tt int GetMeaningOfLifeAsString(char *)} copying the value in the provided | |
1347 | buffer (which must be writable, of course), and returning the actual length | |
1348 | of the string, you might call it like this: | |
1349 | ||
1350 | \begin{verbatim} | |
1351 | wxString theAnswer; | |
1352 | wxStringBuffer theAnswerBuffer(theAnswer, 1024); | |
1353 | int nLength = GetMeaningOfLifeAsString(theAnswerBuffer); | |
1354 | theAnswerBuffer.SetLength(nLength); | |
1355 | if ( theAnswer != "42" ) | |
1356 | { | |
1357 | wxLogError("Something is very wrong!"); | |
1358 | } | |
1359 | \end{verbatim} | |
1360 | ||
5687a67c | 1361 | Note that the exact usage of this depends on whether on not wxUSE\_STL is enabled. If |
3103e8a9 | 1362 | wxUSE\_STL is enabled, wxStringBuffer creates a separate empty character buffer, and |
5687a67c RN |
1363 | if wxUSE\_STL is disabled, it uses GetWriteBuf() from wxString, keeping the same buffer |
1364 | wxString uses intact. In other words, relying on wxStringBuffer containing the old | |
1365 | wxString data is probably not a good idea if you want to build your program in both | |
1366 | with and without wxUSE\_STL. | |
1367 | ||
c298ea48 RN |
1368 | Note that SetLength {\tt must} be called before wxStringBufferLength destructs. |
1369 | ||
1370 | \wxheading{Derived from} | |
1371 | ||
1372 | None | |
1373 | ||
1374 | \wxheading{Include files} | |
1375 | ||
1376 | <wx/string.h> | |
1377 | ||
1378 | \latexignore{\rtfignore{\wxheading{Members}}} | |
1379 | ||
1380 | \membersection{wxStringBufferLength::wxStringBufferLength}\label{wxstringbufferlengthctor} | |
1381 | ||
9a75ba66 | 1382 | \func{}{wxStringBufferLength}{\param{const wxString\& }{str}, \param{size\_t }{len}} |
c298ea48 RN |
1383 | |
1384 | Constructs a writable string buffer object associated with the given string | |
1385 | and containing enough space for at least {\it len} characters. Basically, this | |
1386 | is equivalent to calling \helpref{GetWriteBuf}{wxstringgetwritebuf} and | |
1387 | saving the result. | |
1388 | ||
1389 | \membersection{wxStringBufferLength::\destruct{wxStringBufferLength}}\label{wxstringbufferlengthdtor} | |
1390 | ||
1391 | \func{}{\destruct{wxStringBufferLength}}{\void} | |
1392 | ||
1393 | Restores the string passed to the constructor to the usable state by calling | |
1394 | \helpref{UngetWriteBuf}{wxstringungetwritebuf} on it. | |
1395 | ||
1396 | \membersection{wxStringBufferLength::SetLength}\label{wxstringbufferlengthsetlength} | |
1397 | ||
1398 | \func{void}{SetLength}{\param{size\_t }{nLength}} | |
1399 | ||
1400 | Sets the internal length of the string referred to by wxStringBufferLength to | |
1401 | {\it nLength} characters. | |
1402 | ||
1403 | Must be called before wxStringBufferLength destructs. | |
1404 | ||
1405 | \membersection{wxStringBufferLength::operator wxChar *}\label{wxstringbufferlengthwxchar} | |
1406 | ||
1407 | \func{wxChar *}{operator wxChar *}{\void} | |
1d218550 VZ |
1408 | |
1409 | Returns the writable pointer to a buffer of the size at least equal to the | |
1410 | length specified in the constructor. | |
1411 | ||
1412 |