]>
Commit | Line | Data |
---|---|---|
a7ea63e2 VS |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: wx/stringimpl.h | |
3 | // Purpose: wxStringImpl class, implementation of wxString | |
4 | // Author: Vadim Zeitlin | |
5 | // Modified by: | |
6 | // Created: 29/01/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr> | |
9 | // Licence: wxWindows licence | |
10 | /////////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | /* | |
13 | This header implements std::string-like string class, wxStringImpl, that is | |
14 | used by wxString to store the data. Alternatively, if wxUSE_STL=1, | |
15 | wxStringImpl is just a typedef to std:: string class. | |
16 | */ | |
17 | ||
18 | #ifndef _WX_WXSTRINGIMPL_H__ | |
19 | #define _WX_WXSTRINGIMPL_H__ | |
20 | ||
21 | // ---------------------------------------------------------------------------- | |
22 | // headers | |
23 | // ---------------------------------------------------------------------------- | |
24 | ||
25 | #include "wx/defs.h" // everybody should include this | |
2523e9b7 | 26 | #include "wx/chartype.h" // for wxChar |
52de37c7 | 27 | #include "wx/wxcrtbase.h" // for wxStrlen() etc. |
a7ea63e2 | 28 | |
745817ff VS |
29 | #include <stdlib.h> |
30 | ||
a7ea63e2 VS |
31 | // --------------------------------------------------------------------------- |
32 | // macros | |
33 | // --------------------------------------------------------------------------- | |
34 | ||
35 | // implementation only | |
36 | #define wxASSERT_VALID_INDEX(i) \ | |
9a83f860 | 37 | wxASSERT_MSG( (size_t)(i) <= length(), wxT("invalid index in wxString") ) |
a7ea63e2 VS |
38 | |
39 | ||
40 | // ---------------------------------------------------------------------------- | |
41 | // global data | |
42 | // ---------------------------------------------------------------------------- | |
43 | ||
44 | // global pointer to empty string | |
45 | extern WXDLLIMPEXP_DATA_BASE(const wxChar*) wxEmptyString; | |
81727065 VS |
46 | #if wxUSE_UNICODE_UTF8 |
47 | // FIXME-UTF8: we should have only one wxEmptyString | |
48 | extern WXDLLIMPEXP_DATA_BASE(const wxStringCharType*) wxEmptyStringImpl; | |
49 | #endif | |
a7ea63e2 VS |
50 | |
51 | ||
52 | // ---------------------------------------------------------------------------- | |
53 | // deal with STL/non-STL/non-STL-but-wxUSE_STD_STRING | |
54 | // ---------------------------------------------------------------------------- | |
55 | ||
4f29051b VZ |
56 | // using STL implies using std::string |
57 | #if wxUSE_STL | |
58 | #undef wxUSE_STD_STRING | |
59 | #define wxUSE_STD_STRING 1 | |
60 | #endif | |
61 | ||
62 | // we use STL-based string internally if we use std::string at all now, there | |
63 | // should be no reason to prefer our internal implement but if you really need | |
64 | // it you can predefine wxUSE_STL_BASED_WXSTRING as 0 when building the library | |
65 | #ifndef wxUSE_STL_BASED_WXSTRING | |
66 | #define wxUSE_STL_BASED_WXSTRING wxUSE_STD_STRING | |
67 | #endif | |
a7ea63e2 VS |
68 | |
69 | // in both cases we need to define wxStdString | |
70 | #if wxUSE_STL_BASED_WXSTRING || wxUSE_STD_STRING | |
71 | ||
72 | #include "wx/beforestd.h" | |
73 | #include <string> | |
74 | #include "wx/afterstd.h" | |
75 | ||
59953bf4 VS |
76 | #ifdef HAVE_STD_WSTRING |
77 | typedef std::wstring wxStdWideString; | |
78 | #else | |
79 | typedef std::basic_string<wchar_t> wxStdWideString; | |
80 | #endif | |
81 | ||
a7ea63e2 | 82 | #if wxUSE_UNICODE_WCHAR |
59953bf4 | 83 | typedef wxStdWideString wxStdString; |
a7ea63e2 VS |
84 | #else |
85 | typedef std::string wxStdString; | |
86 | #endif | |
87 | ||
59953bf4 VS |
88 | #endif // wxUSE_STL_BASED_WXSTRING || wxUSE_STD_STRING |
89 | ||
a7ea63e2 VS |
90 | |
91 | #if wxUSE_STL_BASED_WXSTRING | |
92 | ||
93 | // we always want ctor from std::string when using std::string internally | |
94 | #undef wxUSE_STD_STRING | |
95 | #define wxUSE_STD_STRING 1 | |
96 | ||
b8088349 VZ |
97 | // the versions of std::string included with gcc 2.95 and VC6 (for which |
98 | // _MSC_VER == 1200) and eVC4 (_MSC_VER == 1201) lack clear() method | |
a7ea63e2 | 99 | #if (defined(__GNUG__) && (__GNUG__ < 3)) || \ |
88eb6b7c | 100 | !wxCHECK_VISUALC_VERSION(7) || defined(__EVC4__) |
a7ea63e2 VS |
101 | #define wxSTRING_BASE_HASNT_CLEAR |
102 | #endif | |
103 | ||
104 | typedef wxStdString wxStringImpl; | |
105 | #else // if !wxUSE_STL_BASED_WXSTRING | |
106 | ||
107 | // in non-STL mode, compare() is implemented in wxString and not wxStringImpl | |
108 | #undef HAVE_STD_STRING_COMPARE | |
109 | ||
110 | // --------------------------------------------------------------------------- | |
111 | // string data prepended with some housekeeping info (used by wxString class), | |
112 | // is never used directly (but had to be put here to allow inlining) | |
113 | // --------------------------------------------------------------------------- | |
114 | ||
115 | struct WXDLLIMPEXP_BASE wxStringData | |
116 | { | |
117 | int nRefs; // reference count | |
118 | size_t nDataLength, // actual string length | |
119 | nAllocLength; // allocated memory size | |
120 | ||
81727065 VS |
121 | // mimics declaration 'wxStringCharType data[nAllocLength]' |
122 | wxStringCharType* data() const { return (wxStringCharType*)(this + 1); } | |
a7ea63e2 VS |
123 | |
124 | // empty string has a special ref count so it's never deleted | |
125 | bool IsEmpty() const { return (nRefs == -1); } | |
126 | bool IsShared() const { return (nRefs > 1); } | |
127 | ||
128 | // lock/unlock | |
129 | void Lock() { if ( !IsEmpty() ) nRefs++; } | |
130 | ||
131 | // VC++ will refuse to inline Unlock but profiling shows that it is wrong | |
132 | #if defined(__VISUALC__) && (__VISUALC__ >= 1200) | |
133 | __forceinline | |
134 | #endif | |
135 | // VC++ free must take place in same DLL as allocation when using non dll | |
136 | // run-time library (e.g. Multithreaded instead of Multithreaded DLL) | |
137 | #if defined(__VISUALC__) && defined(_MT) && !defined(_DLL) | |
138 | void Unlock() { if ( !IsEmpty() && --nRefs == 0) Free(); } | |
139 | // we must not inline deallocation since allocation is not inlined | |
140 | void Free(); | |
141 | #else | |
142 | void Unlock() { if ( !IsEmpty() && --nRefs == 0) free(this); } | |
143 | #endif | |
144 | ||
145 | // if we had taken control over string memory (GetWriteBuf), it's | |
146 | // intentionally put in invalid state | |
147 | void Validate(bool b) { nRefs = (b ? 1 : 0); } | |
148 | bool IsValid() const { return (nRefs != 0); } | |
149 | }; | |
150 | ||
151 | class WXDLLIMPEXP_BASE wxStringImpl | |
152 | { | |
153 | public: | |
154 | // an 'invalid' value for string index, moved to this place due to a CW bug | |
155 | static const size_t npos; | |
156 | ||
157 | protected: | |
158 | // points to data preceded by wxStringData structure with ref count info | |
159 | wxStringCharType *m_pchData; | |
160 | ||
161 | // accessor to string data | |
162 | wxStringData* GetStringData() const { return (wxStringData*)m_pchData - 1; } | |
163 | ||
164 | // string (re)initialization functions | |
165 | // initializes the string to the empty value (must be called only from | |
166 | // ctors, use Reinit() otherwise) | |
81727065 VS |
167 | #if wxUSE_UNICODE_UTF8 |
168 | void Init() { m_pchData = (wxStringCharType *)wxEmptyStringImpl; } // FIXME-UTF8 | |
169 | #else | |
a7ea63e2 | 170 | void Init() { m_pchData = (wxStringCharType *)wxEmptyString; } |
81727065 | 171 | #endif |
a7ea63e2 VS |
172 | // initializes the string with (a part of) C-string |
173 | void InitWith(const wxStringCharType *psz, size_t nPos = 0, size_t nLen = npos); | |
174 | // as Init, but also frees old data | |
175 | void Reinit() { GetStringData()->Unlock(); Init(); } | |
176 | ||
177 | // memory allocation | |
178 | // allocates memory for string of length nLen | |
179 | bool AllocBuffer(size_t nLen); | |
180 | // effectively copies data to string | |
181 | bool AssignCopy(size_t, const wxStringCharType *); | |
182 | ||
183 | // append a (sub)string | |
184 | bool ConcatSelf(size_t nLen, const wxStringCharType *src, size_t nMaxLen); | |
185 | bool ConcatSelf(size_t nLen, const wxStringCharType *src) | |
186 | { return ConcatSelf(nLen, src, nLen); } | |
187 | ||
188 | // functions called before writing to the string: they copy it if there | |
189 | // are other references to our data (should be the only owner when writing) | |
190 | bool CopyBeforeWrite(); | |
191 | bool AllocBeforeWrite(size_t); | |
192 | ||
193 | // compatibility with wxString | |
194 | bool Alloc(size_t nLen); | |
195 | ||
196 | public: | |
197 | // standard types | |
198 | typedef wxStringCharType value_type; | |
199 | typedef wxStringCharType char_type; | |
200 | typedef size_t size_type; | |
201 | typedef value_type& reference; | |
202 | typedef const value_type& const_reference; | |
203 | typedef value_type* pointer; | |
204 | typedef const value_type* const_pointer; | |
f2a1b1bd VZ |
205 | |
206 | // macro to define the bulk of iterator and const_iterator classes | |
207 | #define WX_DEFINE_STRINGIMPL_ITERATOR(iterator_name, ref_type, ptr_type) \ | |
208 | public: \ | |
209 | typedef wxStringCharType value_type; \ | |
210 | typedef ref_type reference; \ | |
211 | typedef ptr_type pointer; \ | |
89360a8c | 212 | typedef int difference_type; \ |
f2a1b1bd | 213 | \ |
39c20230 | 214 | iterator_name() : m_ptr(NULL) { } \ |
f2a1b1bd VZ |
215 | iterator_name(pointer ptr) : m_ptr(ptr) { } \ |
216 | \ | |
217 | reference operator*() const { return *m_ptr; } \ | |
218 | \ | |
219 | iterator_name& operator++() { m_ptr++; return *this; } \ | |
220 | iterator_name operator++(int) \ | |
221 | { \ | |
222 | const iterator_name tmp(*this); \ | |
223 | m_ptr++; \ | |
224 | return tmp; \ | |
225 | } \ | |
226 | \ | |
227 | iterator_name& operator--() { m_ptr--; return *this; } \ | |
228 | iterator_name operator--(int) \ | |
229 | { \ | |
230 | const iterator_name tmp(*this); \ | |
231 | m_ptr--; \ | |
232 | return tmp; \ | |
233 | } \ | |
234 | \ | |
b5343e06 | 235 | iterator_name operator+(ptrdiff_t n) const \ |
f2a1b1bd | 236 | { return iterator_name(m_ptr + n); } \ |
b5343e06 | 237 | iterator_name operator-(ptrdiff_t n) const \ |
15c12109 | 238 | { return iterator_name(m_ptr - n); } \ |
b5343e06 | 239 | iterator_name& operator+=(ptrdiff_t n) \ |
f2a1b1bd | 240 | { m_ptr += n; return *this; } \ |
b5343e06 | 241 | iterator_name& operator-=(ptrdiff_t n) \ |
f2a1b1bd VZ |
242 | { m_ptr -= n; return *this; } \ |
243 | \ | |
89360a8c | 244 | difference_type operator-(const iterator_name& i) const \ |
f2a1b1bd VZ |
245 | { return m_ptr - i.m_ptr; } \ |
246 | \ | |
247 | bool operator==(const iterator_name& i) const \ | |
248 | { return m_ptr == i.m_ptr; } \ | |
249 | bool operator!=(const iterator_name& i) const \ | |
250 | { return m_ptr != i.m_ptr; } \ | |
251 | \ | |
252 | bool operator<(const iterator_name& i) const \ | |
253 | { return m_ptr < i.m_ptr; } \ | |
254 | bool operator>(const iterator_name& i) const \ | |
255 | { return m_ptr > i.m_ptr; } \ | |
256 | bool operator<=(const iterator_name& i) const \ | |
257 | { return m_ptr <= i.m_ptr; } \ | |
258 | bool operator>=(const iterator_name& i) const \ | |
259 | { return m_ptr >= i.m_ptr; } \ | |
260 | \ | |
261 | private: \ | |
262 | /* for wxStringImpl use only */ \ | |
fb252067 | 263 | pointer GetPtr() const { return m_ptr; } \ |
f2a1b1bd | 264 | \ |
b5dbe15d | 265 | friend class wxStringImpl; \ |
f2a1b1bd VZ |
266 | \ |
267 | pointer m_ptr | |
268 | ||
7c2b62db VZ |
269 | // we need to declare const_iterator in wxStringImpl scope, the friend |
270 | // declaration inside iterator class itself is not enough, or at least not | |
271 | // for g++ 3.4 (g++ 4 is ok) | |
b5dbe15d | 272 | class WXDLLIMPEXP_FWD_BASE const_iterator; |
7c2b62db | 273 | |
541aa821 | 274 | class WXDLLIMPEXP_BASE iterator |
f2a1b1bd VZ |
275 | { |
276 | WX_DEFINE_STRINGIMPL_ITERATOR(iterator, | |
277 | wxStringCharType&, | |
278 | wxStringCharType*); | |
279 | ||
280 | friend class const_iterator; | |
281 | }; | |
282 | ||
541aa821 | 283 | class WXDLLIMPEXP_BASE const_iterator |
f2a1b1bd VZ |
284 | { |
285 | public: | |
286 | const_iterator(iterator i) : m_ptr(i.m_ptr) { } | |
287 | ||
288 | WX_DEFINE_STRINGIMPL_ITERATOR(const_iterator, | |
289 | const wxStringCharType&, | |
290 | const wxStringCharType*); | |
291 | }; | |
292 | ||
89360a8c VS |
293 | #undef WX_DEFINE_STRINGIMPL_ITERATOR |
294 | ||
a7ea63e2 VS |
295 | |
296 | // constructors and destructor | |
297 | // ctor for an empty string | |
298 | wxStringImpl() { Init(); } | |
299 | // copy ctor | |
300 | wxStringImpl(const wxStringImpl& stringSrc) | |
301 | { | |
302 | wxASSERT_MSG( stringSrc.GetStringData()->IsValid(), | |
9a83f860 | 303 | wxT("did you forget to call UngetWriteBuf()?") ); |
a7ea63e2 VS |
304 | |
305 | if ( stringSrc.empty() ) { | |
306 | // nothing to do for an empty string | |
307 | Init(); | |
308 | } | |
309 | else { | |
310 | m_pchData = stringSrc.m_pchData; // share same data | |
311 | GetStringData()->Lock(); // => one more copy | |
312 | } | |
313 | } | |
314 | // string containing nRepeat copies of ch | |
315 | wxStringImpl(size_type nRepeat, wxStringCharType ch); | |
316 | // ctor takes first nLength characters from C string | |
317 | // (default value of npos means take all the string) | |
318 | wxStringImpl(const wxStringCharType *psz) | |
319 | { InitWith(psz, 0, npos); } | |
320 | wxStringImpl(const wxStringCharType *psz, size_t nLength) | |
321 | { InitWith(psz, 0, nLength); } | |
322 | // take nLen chars starting at nPos | |
323 | wxStringImpl(const wxStringImpl& str, size_t nPos, size_t nLen) | |
324 | { | |
325 | wxASSERT_MSG( str.GetStringData()->IsValid(), | |
9a83f860 | 326 | wxT("did you forget to call UngetWriteBuf()?") ); |
a7ea63e2 VS |
327 | Init(); |
328 | size_t strLen = str.length() - nPos; nLen = strLen < nLen ? strLen : nLen; | |
329 | InitWith(str.c_str(), nPos, nLen); | |
330 | } | |
f2a1b1bd VZ |
331 | // take everything between start and end |
332 | wxStringImpl(const_iterator start, const_iterator end); | |
a7ea63e2 | 333 | |
59953bf4 VS |
334 | |
335 | // ctor from and conversion to std::string | |
336 | #if wxUSE_STD_STRING | |
337 | wxStringImpl(const wxStdString& impl) | |
338 | { InitWith(impl.c_str(), 0, impl.length()); } | |
339 | ||
340 | operator wxStdString() const | |
341 | { return wxStdString(c_str(), length()); } | |
342 | #endif | |
343 | ||
5dd09653 VZ |
344 | #if defined(__VISUALC__) && (__VISUALC__ >= 1200) |
345 | // disable warning about Unlock() below not being inlined (first, it | |
346 | // seems to be inlined nevertheless and second, even if it isn't, there | |
347 | // is nothing we can do about this | |
348 | #pragma warning(push) | |
349 | #pragma warning (disable:4714) | |
350 | #endif | |
59953bf4 | 351 | |
a7ea63e2 VS |
352 | // dtor is not virtual, this class must not be inherited from! |
353 | ~wxStringImpl() | |
354 | { | |
a7ea63e2 VS |
355 | GetStringData()->Unlock(); |
356 | } | |
357 | ||
358 | #if defined(__VISUALC__) && (__VISUALC__ >= 1200) | |
5dd09653 | 359 | #pragma warning(pop) |
a7ea63e2 | 360 | #endif |
5dd09653 | 361 | |
a7ea63e2 VS |
362 | // overloaded assignment |
363 | // from another wxString | |
364 | wxStringImpl& operator=(const wxStringImpl& stringSrc); | |
365 | // from a character | |
366 | wxStringImpl& operator=(wxStringCharType ch); | |
367 | // from a C string | |
368 | wxStringImpl& operator=(const wxStringCharType *psz); | |
369 | ||
370 | // return the length of the string | |
371 | size_type length() const { return GetStringData()->nDataLength; } | |
372 | // return the length of the string | |
373 | size_type size() const { return length(); } | |
374 | // return the maximum size of the string | |
375 | size_type max_size() const { return npos; } | |
376 | // resize the string, filling the space with c if c != 0 | |
377 | void resize(size_t nSize, wxStringCharType ch = '\0'); | |
378 | // delete the contents of the string | |
379 | void clear() { erase(0, npos); } | |
380 | // returns true if the string is empty | |
381 | bool empty() const { return length() == 0; } | |
382 | // inform string about planned change in size | |
383 | void reserve(size_t sz) { Alloc(sz); } | |
384 | size_type capacity() const { return GetStringData()->nAllocLength; } | |
385 | ||
386 | // lib.string.access | |
387 | // return the character at position n | |
87c7fc67 | 388 | value_type operator[](size_type n) const { return m_pchData[n]; } |
a7ea63e2 VS |
389 | value_type at(size_type n) const |
390 | { wxASSERT_VALID_INDEX( n ); return m_pchData[n]; } | |
391 | // returns the writable character at position n | |
87c7fc67 | 392 | reference operator[](size_type n) { CopyBeforeWrite(); return m_pchData[n]; } |
a7ea63e2 VS |
393 | reference at(size_type n) |
394 | { | |
395 | wxASSERT_VALID_INDEX( n ); | |
396 | CopyBeforeWrite(); | |
397 | return m_pchData[n]; | |
398 | } // FIXME-UTF8: not useful for us...? | |
399 | ||
400 | // lib.string.modifiers | |
401 | // append elements str[pos], ..., str[pos+n] | |
402 | wxStringImpl& append(const wxStringImpl& str, size_t pos, size_t n) | |
403 | { | |
404 | wxASSERT(pos <= str.length()); | |
405 | ConcatSelf(n, str.c_str() + pos, str.length() - pos); | |
406 | return *this; | |
407 | } | |
408 | // append a string | |
409 | wxStringImpl& append(const wxStringImpl& str) | |
410 | { ConcatSelf(str.length(), str.c_str()); return *this; } | |
411 | // append first n (or all if n == npos) characters of sz | |
412 | wxStringImpl& append(const wxStringCharType *sz) | |
52de37c7 | 413 | { ConcatSelf(wxStrlen(sz), sz); return *this; } |
a7ea63e2 VS |
414 | wxStringImpl& append(const wxStringCharType *sz, size_t n) |
415 | { ConcatSelf(n, sz); return *this; } | |
416 | // append n copies of ch | |
417 | wxStringImpl& append(size_t n, wxStringCharType ch); | |
418 | // append from first to last | |
419 | wxStringImpl& append(const_iterator first, const_iterator last) | |
fb252067 | 420 | { ConcatSelf(last - first, first.GetPtr()); return *this; } |
a7ea63e2 VS |
421 | |
422 | // same as `this_string = str' | |
423 | wxStringImpl& assign(const wxStringImpl& str) | |
424 | { return *this = str; } | |
425 | // same as ` = str[pos..pos + n] | |
426 | wxStringImpl& assign(const wxStringImpl& str, size_t pos, size_t n) | |
d545bded | 427 | { return replace(0, npos, str, pos, n); } |
a7ea63e2 VS |
428 | // same as `= first n (or all if n == npos) characters of sz' |
429 | wxStringImpl& assign(const wxStringCharType *sz) | |
d545bded | 430 | { return replace(0, npos, sz, wxStrlen(sz)); } |
a7ea63e2 | 431 | wxStringImpl& assign(const wxStringCharType *sz, size_t n) |
d545bded | 432 | { return replace(0, npos, sz, n); } |
a7ea63e2 VS |
433 | // same as `= n copies of ch' |
434 | wxStringImpl& assign(size_t n, wxStringCharType ch) | |
d545bded | 435 | { return replace(0, npos, n, ch); } |
a7ea63e2 VS |
436 | // assign from first to last |
437 | wxStringImpl& assign(const_iterator first, const_iterator last) | |
d545bded | 438 | { return replace(begin(), end(), first, last); } |
a7ea63e2 VS |
439 | |
440 | // first valid index position | |
441 | const_iterator begin() const { return m_pchData; } | |
442 | iterator begin(); | |
443 | // position one after the last valid one | |
444 | const_iterator end() const { return m_pchData + length(); } | |
445 | iterator end(); | |
446 | ||
447 | // insert another string | |
448 | wxStringImpl& insert(size_t nPos, const wxStringImpl& str) | |
449 | { | |
450 | wxASSERT( str.GetStringData()->IsValid() ); | |
451 | return insert(nPos, str.c_str(), str.length()); | |
452 | } | |
453 | // insert n chars of str starting at nStart (in str) | |
454 | wxStringImpl& insert(size_t nPos, const wxStringImpl& str, size_t nStart, size_t n) | |
455 | { | |
456 | wxASSERT( str.GetStringData()->IsValid() ); | |
457 | wxASSERT( nStart < str.length() ); | |
458 | size_t strLen = str.length() - nStart; | |
459 | n = strLen < n ? strLen : n; | |
460 | return insert(nPos, str.c_str() + nStart, n); | |
461 | } | |
462 | // insert first n (or all if n == npos) characters of sz | |
463 | wxStringImpl& insert(size_t nPos, const wxStringCharType *sz, size_t n = npos); | |
464 | // insert n copies of ch | |
81727065 | 465 | wxStringImpl& insert(size_t nPos, size_t n, wxStringCharType ch) |
a7ea63e2 | 466 | { return insert(nPos, wxStringImpl(n, ch)); } |
81727065 | 467 | iterator insert(iterator it, wxStringCharType ch) |
a7ea63e2 VS |
468 | { size_t idx = it - begin(); insert(idx, 1, ch); return begin() + idx; } |
469 | void insert(iterator it, const_iterator first, const_iterator last) | |
fb252067 | 470 | { insert(it - begin(), first.GetPtr(), last - first); } |
a7ea63e2 VS |
471 | void insert(iterator it, size_type n, wxStringCharType ch) |
472 | { insert(it - begin(), n, ch); } | |
473 | ||
474 | // delete characters from nStart to nStart + nLen | |
475 | wxStringImpl& erase(size_type pos = 0, size_type n = npos); | |
476 | iterator erase(iterator first, iterator last) | |
477 | { | |
478 | size_t idx = first - begin(); | |
479 | erase(idx, last - first); | |
480 | return begin() + idx; | |
481 | } | |
482 | iterator erase(iterator first); | |
483 | ||
484 | // explicit conversion to C string (use this with printf()!) | |
485 | const wxStringCharType* c_str() const { return m_pchData; } | |
486 | const wxStringCharType* data() const { return m_pchData; } | |
487 | ||
488 | // replaces the substring of length nLen starting at nStart | |
d545bded VZ |
489 | wxStringImpl& replace(size_t nStart, size_t nLen, const wxStringCharType* sz) |
490 | { return replace(nStart, nLen, sz, npos); } | |
a7ea63e2 VS |
491 | // replaces the substring of length nLen starting at nStart |
492 | wxStringImpl& replace(size_t nStart, size_t nLen, const wxStringImpl& str) | |
d545bded | 493 | { return replace(nStart, nLen, str.c_str(), str.length()); } |
a7ea63e2 | 494 | // replaces the substring with nCount copies of ch |
d545bded VZ |
495 | wxStringImpl& replace(size_t nStart, size_t nLen, |
496 | size_t nCount, wxStringCharType ch) | |
497 | { return replace(nStart, nLen, wxStringImpl(nCount, ch)); } | |
a7ea63e2 VS |
498 | // replaces a substring with another substring |
499 | wxStringImpl& replace(size_t nStart, size_t nLen, | |
d545bded VZ |
500 | const wxStringImpl& str, size_t nStart2, size_t nLen2) |
501 | { return replace(nStart, nLen, str.substr(nStart2, nLen2)); } | |
a7ea63e2 VS |
502 | // replaces the substring with first nCount chars of sz |
503 | wxStringImpl& replace(size_t nStart, size_t nLen, | |
504 | const wxStringCharType* sz, size_t nCount); | |
d545bded | 505 | |
a7ea63e2 VS |
506 | wxStringImpl& replace(iterator first, iterator last, const_pointer s) |
507 | { return replace(first - begin(), last - first, s); } | |
508 | wxStringImpl& replace(iterator first, iterator last, const_pointer s, | |
509 | size_type n) | |
510 | { return replace(first - begin(), last - first, s, n); } | |
511 | wxStringImpl& replace(iterator first, iterator last, const wxStringImpl& s) | |
512 | { return replace(first - begin(), last - first, s); } | |
513 | wxStringImpl& replace(iterator first, iterator last, size_type n, wxStringCharType c) | |
514 | { return replace(first - begin(), last - first, n, c); } | |
515 | wxStringImpl& replace(iterator first, iterator last, | |
516 | const_iterator first1, const_iterator last1) | |
fb252067 | 517 | { return replace(first - begin(), last - first, first1.GetPtr(), last1 - first1); } |
a7ea63e2 VS |
518 | |
519 | // swap two strings | |
520 | void swap(wxStringImpl& str); | |
521 | ||
522 | // All find() functions take the nStart argument which specifies the | |
523 | // position to start the search on, the default value is 0. All functions | |
524 | // return npos if there were no match. | |
525 | ||
526 | // find a substring | |
527 | size_t find(const wxStringImpl& str, size_t nStart = 0) const; | |
528 | ||
529 | // find first n characters of sz | |
530 | size_t find(const wxStringCharType* sz, size_t nStart = 0, size_t n = npos) const; | |
531 | ||
f2a1b1bd | 532 | // find the first occurrence of character ch after nStart |
a7ea63e2 VS |
533 | size_t find(wxStringCharType ch, size_t nStart = 0) const; |
534 | ||
535 | // rfind() family is exactly like find() but works right to left | |
536 | ||
537 | // as find, but from the end | |
538 | size_t rfind(const wxStringImpl& str, size_t nStart = npos) const; | |
539 | ||
540 | // as find, but from the end | |
541 | size_t rfind(const wxStringCharType* sz, size_t nStart = npos, | |
542 | size_t n = npos) const; | |
543 | // as find, but from the end | |
544 | size_t rfind(wxStringCharType ch, size_t nStart = npos) const; | |
545 | ||
546 | size_type copy(wxStringCharType* s, size_type n, size_type pos = 0); | |
547 | ||
548 | // substring extraction | |
549 | wxStringImpl substr(size_t nStart = 0, size_t nLen = npos) const; | |
550 | ||
551 | // string += string | |
552 | wxStringImpl& operator+=(const wxStringImpl& s) { return append(s); } | |
553 | // string += C string | |
554 | wxStringImpl& operator+=(const wxStringCharType *psz) { return append(psz); } | |
555 | // string += char | |
556 | wxStringImpl& operator+=(wxStringCharType ch) { return append(1, ch); } | |
557 | ||
a7ea63e2 VS |
558 | // helpers for wxStringBuffer and wxStringBufferLength |
559 | wxStringCharType *DoGetWriteBuf(size_t nLen); | |
560 | void DoUngetWriteBuf(); | |
561 | void DoUngetWriteBuf(size_t nLen); | |
a7ea63e2 | 562 | |
b5dbe15d | 563 | friend class WXDLLIMPEXP_FWD_BASE wxString; |
a7ea63e2 VS |
564 | }; |
565 | ||
566 | #endif // !wxUSE_STL_BASED_WXSTRING | |
567 | ||
568 | // don't pollute the library user's name space | |
569 | #undef wxASSERT_VALID_INDEX | |
570 | ||
571 | #endif // _WX_WXSTRINGIMPL_H__ |