]>
Commit | Line | Data |
---|---|---|
872d8fea PC |
1 | // Versatile string -*- C++ -*- |
2 | ||
5b9daa7e | 3 | // Copyright (C) 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc. |
872d8fea PC |
4 | // |
5 | // This file is part of the GNU ISO C++ Library. This library is free | |
6 | // software; you can redistribute it and/or modify it under the | |
7 | // terms of the GNU General Public License as published by the | |
748086b7 | 8 | // Free Software Foundation; either version 3, or (at your option) |
872d8fea PC |
9 | // any later version. |
10 | ||
11 | // This library is distributed in the hope that it will be useful, | |
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | // GNU General Public License for more details. | |
15 | ||
748086b7 JJ |
16 | // Under Section 7 of GPL version 3, you are granted additional |
17 | // permissions described in the GCC Runtime Library Exception, version | |
18 | // 3.1, as published by the Free Software Foundation. | |
19 | ||
20 | // You should have received a copy of the GNU General Public License and | |
21 | // a copy of the GCC Runtime Library Exception along with this program; | |
22 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see | |
23 | // <http://www.gnu.org/licenses/>. | |
872d8fea PC |
24 | |
25 | /** @file ext/vstring.h | |
26 | * This file is a GNU extension to the Standard C++ Library. | |
27 | */ | |
28 | ||
29 | #ifndef _VSTRING_H | |
30 | #define _VSTRING_H 1 | |
31 | ||
32 | #pragma GCC system_header | |
33 | ||
988499f4 | 34 | #include <initializer_list> |
872d8fea PC |
35 | #include <ext/vstring_util.h> |
36 | #include <ext/rc_string_base.h> | |
37 | #include <ext/sso_string_base.h> | |
38 | ||
3cbc7af0 BK |
39 | _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) |
40 | ||
872d8fea PC |
41 | /** |
42 | * @class __versa_string vstring.h | |
43 | * @brief Managing sequences of characters and character-like objects. | |
44 | */ | |
45 | ||
46 | // Template class __versa_string | |
47 | template<typename _CharT, typename _Traits, typename _Alloc, | |
48 | template <typename, typename, typename> class _Base> | |
49 | class __versa_string | |
50 | : private _Base<_CharT, _Traits, _Alloc> | |
51 | { | |
52 | typedef _Base<_CharT, _Traits, _Alloc> __vstring_base; | |
53 | typedef typename __vstring_base::_CharT_alloc_type _CharT_alloc_type; | |
54 | ||
55 | // Types: | |
56 | public: | |
57 | typedef _Traits traits_type; | |
58 | typedef typename _Traits::char_type value_type; | |
59 | typedef _Alloc allocator_type; | |
60 | typedef typename _CharT_alloc_type::size_type size_type; | |
61 | typedef typename _CharT_alloc_type::difference_type difference_type; | |
62 | typedef typename _CharT_alloc_type::reference reference; | |
63 | typedef typename _CharT_alloc_type::const_reference const_reference; | |
64 | typedef typename _CharT_alloc_type::pointer pointer; | |
65 | typedef typename _CharT_alloc_type::const_pointer const_pointer; | |
66 | typedef __gnu_cxx::__normal_iterator<pointer, __versa_string> iterator; | |
67 | typedef __gnu_cxx::__normal_iterator<const_pointer, __versa_string> | |
68 | const_iterator; | |
69 | typedef std::reverse_iterator<const_iterator> const_reverse_iterator; | |
70 | typedef std::reverse_iterator<iterator> reverse_iterator; | |
71 | ||
486516b6 | 72 | // Data Member (public): |
872d8fea PC |
73 | /// Value returned by various member functions when they fail. |
74 | static const size_type npos = static_cast<size_type>(-1); | |
75 | ||
76 | private: | |
77 | size_type | |
78 | _M_check(size_type __pos, const char* __s) const | |
79 | { | |
80 | if (__pos > this->size()) | |
81 | std::__throw_out_of_range(__N(__s)); | |
82 | return __pos; | |
83 | } | |
84 | ||
85 | void | |
86 | _M_check_length(size_type __n1, size_type __n2, const char* __s) const | |
87 | { | |
88 | if (this->max_size() - (this->size() - __n1) < __n2) | |
89 | std::__throw_length_error(__N(__s)); | |
90 | } | |
91 | ||
92 | // NB: _M_limit doesn't check for a bad __pos value. | |
93 | size_type | |
94 | _M_limit(size_type __pos, size_type __off) const | |
95 | { | |
96 | const bool __testoff = __off < this->size() - __pos; | |
97 | return __testoff ? __off : this->size() - __pos; | |
98 | } | |
99 | ||
100 | // True if _Rep and source do not overlap. | |
101 | bool | |
102 | _M_disjunct(const _CharT* __s) const | |
103 | { | |
104 | return (std::less<const _CharT*>()(__s, this->_M_data()) | |
105 | || std::less<const _CharT*>()(this->_M_data() | |
106 | + this->size(), __s)); | |
107 | } | |
108 | ||
109 | // For the internal use we have functions similar to `begin'/`end' | |
110 | // but they do not call _M_leak. | |
111 | iterator | |
112 | _M_ibegin() const | |
113 | { return iterator(this->_M_data()); } | |
114 | ||
115 | iterator | |
116 | _M_iend() const | |
117 | { return iterator(this->_M_data() + this->_M_length()); } | |
118 | ||
119 | public: | |
120 | // Construct/copy/destroy: | |
121 | // NB: We overload ctors in some cases instead of using default | |
122 | // arguments, per 17.4.4.4 para. 2 item 2. | |
123 | ||
124 | /** | |
125 | * @brief Default constructor creates an empty string. | |
126 | */ | |
127 | __versa_string() | |
128 | : __vstring_base() { } | |
129 | ||
130 | /** | |
131 | * @brief Construct an empty string using allocator @a a. | |
132 | */ | |
133 | explicit | |
134 | __versa_string(const _Alloc& __a) | |
135 | : __vstring_base(__a) { } | |
136 | ||
137 | // NB: per LWG issue 42, semantics different from IS: | |
138 | /** | |
139 | * @brief Construct string with copy of value of @a str. | |
5b9daa7e | 140 | * @param __str Source string. |
872d8fea PC |
141 | */ |
142 | __versa_string(const __versa_string& __str) | |
143 | : __vstring_base(__str) { } | |
144 | ||
053cc380 PC |
145 | #ifdef __GXX_EXPERIMENTAL_CXX0X__ |
146 | /** | |
147 | * @brief String move constructor. | |
5b9daa7e | 148 | * @param __str Source string. |
053cc380 | 149 | * |
5b9daa7e BK |
150 | * The newly-constructed %string contains the exact contents of |
151 | * @a str. The contents of @a str are a valid, but unspecified | |
152 | * string. | |
053cc380 PC |
153 | */ |
154 | __versa_string(__versa_string&& __str) | |
155 | : __vstring_base(std::forward<__vstring_base>(__str)) { } | |
988499f4 JM |
156 | |
157 | /** | |
158 | * @brief Construct string from an initializer list. | |
5b9daa7e BK |
159 | * @param __l std::initializer_list of characters. |
160 | * @param __a Allocator to use (default is default allocator). | |
988499f4 | 161 | */ |
1e58e43b PC |
162 | __versa_string(std::initializer_list<_CharT> __l, |
163 | const _Alloc& __a = _Alloc()) | |
164 | : __vstring_base(__l.begin(), __l.end(), __a) { } | |
053cc380 PC |
165 | #endif |
166 | ||
872d8fea PC |
167 | /** |
168 | * @brief Construct string as copy of a substring. | |
5b9daa7e BK |
169 | * @param __str Source string. |
170 | * @param __pos Index of first character to copy from. | |
171 | * @param __n Number of characters to copy (default remainder). | |
872d8fea PC |
172 | */ |
173 | __versa_string(const __versa_string& __str, size_type __pos, | |
174 | size_type __n = npos) | |
175 | : __vstring_base(__str._M_data() | |
176 | + __str._M_check(__pos, | |
177 | "__versa_string::__versa_string"), | |
178 | __str._M_data() + __str._M_limit(__pos, __n) | |
179 | + __pos, _Alloc()) { } | |
180 | ||
181 | /** | |
182 | * @brief Construct string as copy of a substring. | |
5b9daa7e BK |
183 | * @param __str Source string. |
184 | * @param __pos Index of first character to copy from. | |
185 | * @param __n Number of characters to copy. | |
186 | * @param __a Allocator to use. | |
872d8fea PC |
187 | */ |
188 | __versa_string(const __versa_string& __str, size_type __pos, | |
189 | size_type __n, const _Alloc& __a) | |
190 | : __vstring_base(__str._M_data() | |
191 | + __str._M_check(__pos, | |
192 | "__versa_string::__versa_string"), | |
193 | __str._M_data() + __str._M_limit(__pos, __n) | |
194 | + __pos, __a) { } | |
195 | ||
196 | /** | |
197 | * @brief Construct string initialized by a character array. | |
5b9daa7e BK |
198 | * @param __s Source character array. |
199 | * @param __n Number of characters to copy. | |
200 | * @param __a Allocator to use (default is default allocator). | |
872d8fea | 201 | * |
5df9ac4b | 202 | * NB: @a __s must have at least @a __n characters, '\\0' has no special |
872d8fea PC |
203 | * meaning. |
204 | */ | |
205 | __versa_string(const _CharT* __s, size_type __n, | |
206 | const _Alloc& __a = _Alloc()) | |
207 | : __vstring_base(__s, __s + __n, __a) { } | |
208 | ||
209 | /** | |
210 | * @brief Construct string as copy of a C string. | |
5b9daa7e BK |
211 | * @param __s Source C string. |
212 | * @param __a Allocator to use (default is default allocator). | |
872d8fea PC |
213 | */ |
214 | __versa_string(const _CharT* __s, const _Alloc& __a = _Alloc()) | |
215 | : __vstring_base(__s, __s ? __s + traits_type::length(__s) : | |
216 | __s + npos, __a) { } | |
217 | ||
218 | /** | |
219 | * @brief Construct string as multiple characters. | |
5b9daa7e BK |
220 | * @param __n Number of characters. |
221 | * @param __c Character to use. | |
222 | * @param __a Allocator to use (default is default allocator). | |
872d8fea PC |
223 | */ |
224 | __versa_string(size_type __n, _CharT __c, const _Alloc& __a = _Alloc()) | |
225 | : __vstring_base(__n, __c, __a) { } | |
226 | ||
227 | /** | |
228 | * @brief Construct string as copy of a range. | |
5b9daa7e BK |
229 | * @param __beg Start of range. |
230 | * @param __end End of range. | |
231 | * @param __a Allocator to use (default is default allocator). | |
872d8fea PC |
232 | */ |
233 | template<class _InputIterator> | |
234 | __versa_string(_InputIterator __beg, _InputIterator __end, | |
235 | const _Alloc& __a = _Alloc()) | |
236 | : __vstring_base(__beg, __end, __a) { } | |
237 | ||
238 | /** | |
239 | * @brief Destroy the string instance. | |
240 | */ | |
241 | ~__versa_string() { } | |
242 | ||
243 | /** | |
244 | * @brief Assign the value of @a str to this string. | |
5b9daa7e | 245 | * @param __str Source string. |
872d8fea PC |
246 | */ |
247 | __versa_string& | |
248 | operator=(const __versa_string& __str) | |
249 | { return this->assign(__str); } | |
250 | ||
053cc380 PC |
251 | #ifdef __GXX_EXPERIMENTAL_CXX0X__ |
252 | /** | |
253 | * @brief String move assignment operator. | |
5b9daa7e | 254 | * @param __str Source string. |
053cc380 | 255 | * |
5b9daa7e BK |
256 | * The contents of @a __str are moved into this string (without |
257 | * copying). @a __str is a valid, but unspecified string. | |
053cc380 PC |
258 | */ |
259 | __versa_string& | |
260 | operator=(__versa_string&& __str) | |
261 | { | |
262 | if (this != &__str) | |
263 | this->swap(__str); | |
264 | return *this; | |
265 | } | |
988499f4 JM |
266 | |
267 | /** | |
268 | * @brief Set value to string constructed from initializer list. | |
5b9daa7e | 269 | * @param __l std::initializer_list. |
988499f4 JM |
270 | */ |
271 | __versa_string& | |
272 | operator=(std::initializer_list<_CharT> __l) | |
273 | { | |
1e58e43b | 274 | this->assign(__l.begin(), __l.end()); |
988499f4 JM |
275 | return *this; |
276 | } | |
053cc380 PC |
277 | #endif |
278 | ||
872d8fea | 279 | /** |
5b9daa7e BK |
280 | * @brief Copy contents of @a __s into this string. |
281 | * @param __s Source null-terminated string. | |
872d8fea PC |
282 | */ |
283 | __versa_string& | |
284 | operator=(const _CharT* __s) | |
285 | { return this->assign(__s); } | |
286 | ||
287 | /** | |
288 | * @brief Set value to string of length 1. | |
5b9daa7e | 289 | * @param __c Source character. |
872d8fea PC |
290 | * |
291 | * Assigning to a character makes this string length 1 and | |
5b9daa7e | 292 | * (*this)[0] == @a __c. |
872d8fea PC |
293 | */ |
294 | __versa_string& | |
295 | operator=(_CharT __c) | |
296 | { | |
297 | this->assign(1, __c); | |
298 | return *this; | |
299 | } | |
300 | ||
301 | // Iterators: | |
302 | /** | |
303 | * Returns a read/write iterator that points to the first character in | |
304 | * the %string. Unshares the string. | |
305 | */ | |
306 | iterator | |
307 | begin() | |
308 | { | |
309 | this->_M_leak(); | |
310 | return iterator(this->_M_data()); | |
311 | } | |
312 | ||
313 | /** | |
314 | * Returns a read-only (constant) iterator that points to the first | |
315 | * character in the %string. | |
316 | */ | |
317 | const_iterator | |
318 | begin() const | |
319 | { return const_iterator(this->_M_data()); } | |
320 | ||
321 | /** | |
322 | * Returns a read/write iterator that points one past the last | |
323 | * character in the %string. Unshares the string. | |
324 | */ | |
325 | iterator | |
326 | end() | |
327 | { | |
328 | this->_M_leak(); | |
329 | return iterator(this->_M_data() + this->size()); | |
330 | } | |
331 | ||
332 | /** | |
333 | * Returns a read-only (constant) iterator that points one past the | |
334 | * last character in the %string. | |
335 | */ | |
336 | const_iterator | |
337 | end() const | |
338 | { return const_iterator(this->_M_data() + this->size()); } | |
339 | ||
340 | /** | |
341 | * Returns a read/write reverse iterator that points to the last | |
342 | * character in the %string. Iteration is done in reverse element | |
343 | * order. Unshares the string. | |
344 | */ | |
345 | reverse_iterator | |
346 | rbegin() | |
347 | { return reverse_iterator(this->end()); } | |
348 | ||
349 | /** | |
350 | * Returns a read-only (constant) reverse iterator that points | |
351 | * to the last character in the %string. Iteration is done in | |
352 | * reverse element order. | |
353 | */ | |
354 | const_reverse_iterator | |
355 | rbegin() const | |
356 | { return const_reverse_iterator(this->end()); } | |
357 | ||
358 | /** | |
359 | * Returns a read/write reverse iterator that points to one before the | |
360 | * first character in the %string. Iteration is done in reverse | |
361 | * element order. Unshares the string. | |
362 | */ | |
363 | reverse_iterator | |
364 | rend() | |
365 | { return reverse_iterator(this->begin()); } | |
366 | ||
367 | /** | |
368 | * Returns a read-only (constant) reverse iterator that points | |
369 | * to one before the first character in the %string. Iteration | |
370 | * is done in reverse element order. | |
371 | */ | |
372 | const_reverse_iterator | |
373 | rend() const | |
374 | { return const_reverse_iterator(this->begin()); } | |
375 | ||
0cd50f89 PC |
376 | #ifdef __GXX_EXPERIMENTAL_CXX0X__ |
377 | /** | |
378 | * Returns a read-only (constant) iterator that points to the first | |
379 | * character in the %string. | |
380 | */ | |
381 | const_iterator | |
382 | cbegin() const | |
383 | { return const_iterator(this->_M_data()); } | |
384 | ||
385 | /** | |
386 | * Returns a read-only (constant) iterator that points one past the | |
387 | * last character in the %string. | |
388 | */ | |
389 | const_iterator | |
390 | cend() const | |
391 | { return const_iterator(this->_M_data() + this->size()); } | |
392 | ||
393 | /** | |
394 | * Returns a read-only (constant) reverse iterator that points | |
395 | * to the last character in the %string. Iteration is done in | |
396 | * reverse element order. | |
397 | */ | |
398 | const_reverse_iterator | |
399 | crbegin() const | |
400 | { return const_reverse_iterator(this->end()); } | |
401 | ||
402 | /** | |
403 | * Returns a read-only (constant) reverse iterator that points | |
404 | * to one before the first character in the %string. Iteration | |
405 | * is done in reverse element order. | |
406 | */ | |
407 | const_reverse_iterator | |
408 | crend() const | |
409 | { return const_reverse_iterator(this->begin()); } | |
410 | #endif | |
411 | ||
872d8fea PC |
412 | public: |
413 | // Capacity: | |
414 | /// Returns the number of characters in the string, not including any | |
415 | /// null-termination. | |
416 | size_type | |
417 | size() const | |
418 | { return this->_M_length(); } | |
419 | ||
420 | /// Returns the number of characters in the string, not including any | |
421 | /// null-termination. | |
422 | size_type | |
423 | length() const | |
424 | { return this->_M_length(); } | |
425 | ||
426 | /// Returns the size() of the largest possible %string. | |
427 | size_type | |
428 | max_size() const | |
486516b6 | 429 | { return this->_M_max_size(); } |
872d8fea PC |
430 | |
431 | /** | |
432 | * @brief Resizes the %string to the specified number of characters. | |
5b9daa7e BK |
433 | * @param __n Number of characters the %string should contain. |
434 | * @param __c Character to fill any new elements. | |
872d8fea PC |
435 | * |
436 | * This function will %resize the %string to the specified | |
437 | * number of characters. If the number is smaller than the | |
438 | * %string's current size the %string is truncated, otherwise | |
5b9daa7e | 439 | * the %string is extended and new elements are set to @a __c. |
872d8fea PC |
440 | */ |
441 | void | |
442 | resize(size_type __n, _CharT __c); | |
443 | ||
444 | /** | |
445 | * @brief Resizes the %string to the specified number of characters. | |
5b9daa7e | 446 | * @param __n Number of characters the %string should contain. |
872d8fea | 447 | * |
5b9daa7e BK |
448 | * This function will resize the %string to the specified |
449 | * length. If the new size is smaller than the %string's | |
450 | * current size the %string is truncated, otherwise the %string | |
451 | * is extended and new characters are default-constructed. For | |
452 | * basic types such as char, this means setting them to 0. | |
872d8fea PC |
453 | */ |
454 | void | |
455 | resize(size_type __n) | |
456 | { this->resize(__n, _CharT()); } | |
457 | ||
458 | /** | |
5b9daa7e BK |
459 | * Returns the total number of characters that the %string can |
460 | * hold before needing to allocate more memory. | |
872d8fea PC |
461 | */ |
462 | size_type | |
463 | capacity() const | |
464 | { return this->_M_capacity(); } | |
465 | ||
466 | /** | |
467 | * @brief Attempt to preallocate enough memory for specified number of | |
468 | * characters. | |
5b9daa7e BK |
469 | * @param __res_arg Number of characters required. |
470 | * @throw std::length_error If @a __res_arg exceeds @c max_size(). | |
872d8fea PC |
471 | * |
472 | * This function attempts to reserve enough memory for the | |
473 | * %string to hold the specified number of characters. If the | |
474 | * number requested is more than max_size(), length_error is | |
475 | * thrown. | |
476 | * | |
477 | * The advantage of this function is that if optimal code is a | |
5b9daa7e BK |
478 | * necessity and the user can determine the string length that |
479 | * will be required, the user can reserve the memory in | |
480 | * %advance, and thus prevent a possible reallocation of memory | |
481 | * and copying of %string data. | |
872d8fea PC |
482 | */ |
483 | void | |
484 | reserve(size_type __res_arg = 0) | |
cf882919 | 485 | { this->_M_reserve(__res_arg); } |
872d8fea PC |
486 | |
487 | /** | |
488 | * Erases the string, making it empty. | |
489 | */ | |
490 | void | |
491 | clear() | |
7867a3f7 | 492 | { this->_M_clear(); } |
872d8fea PC |
493 | |
494 | /** | |
495 | * Returns true if the %string is empty. Equivalent to *this == "". | |
496 | */ | |
497 | bool | |
498 | empty() const | |
499 | { return this->size() == 0; } | |
500 | ||
501 | // Element access: | |
502 | /** | |
503 | * @brief Subscript access to the data contained in the %string. | |
5b9daa7e | 504 | * @param __pos The index of the character to access. |
872d8fea PC |
505 | * @return Read-only (constant) reference to the character. |
506 | * | |
507 | * This operator allows for easy, array-style, data access. | |
508 | * Note that data access with this operator is unchecked and | |
509 | * out_of_range lookups are not defined. (For checked lookups | |
510 | * see at().) | |
511 | */ | |
512 | const_reference | |
513 | operator[] (size_type __pos) const | |
514 | { | |
515 | _GLIBCXX_DEBUG_ASSERT(__pos <= this->size()); | |
516 | return this->_M_data()[__pos]; | |
517 | } | |
518 | ||
519 | /** | |
520 | * @brief Subscript access to the data contained in the %string. | |
5b9daa7e | 521 | * @param __pos The index of the character to access. |
872d8fea PC |
522 | * @return Read/write reference to the character. |
523 | * | |
524 | * This operator allows for easy, array-style, data access. | |
525 | * Note that data access with this operator is unchecked and | |
526 | * out_of_range lookups are not defined. (For checked lookups | |
527 | * see at().) Unshares the string. | |
528 | */ | |
529 | reference | |
530 | operator[](size_type __pos) | |
531 | { | |
df108331 PC |
532 | // allow pos == size() as v3 extension: |
533 | _GLIBCXX_DEBUG_ASSERT(__pos <= this->size()); | |
534 | // but be strict in pedantic mode: | |
535 | _GLIBCXX_DEBUG_PEDASSERT(__pos < this->size()); | |
872d8fea PC |
536 | this->_M_leak(); |
537 | return this->_M_data()[__pos]; | |
538 | } | |
539 | ||
540 | /** | |
541 | * @brief Provides access to the data contained in the %string. | |
5b9daa7e | 542 | * @param __n The index of the character to access. |
872d8fea | 543 | * @return Read-only (const) reference to the character. |
5b9daa7e | 544 | * @throw std::out_of_range If @a __n is an invalid index. |
872d8fea | 545 | * |
5b9daa7e BK |
546 | * This function provides for safer data access. The parameter |
547 | * is first checked that it is in the range of the string. The | |
548 | * function throws out_of_range if the check fails. | |
872d8fea PC |
549 | */ |
550 | const_reference | |
551 | at(size_type __n) const | |
552 | { | |
553 | if (__n >= this->size()) | |
554 | std::__throw_out_of_range(__N("__versa_string::at")); | |
555 | return this->_M_data()[__n]; | |
556 | } | |
557 | ||
558 | /** | |
559 | * @brief Provides access to the data contained in the %string. | |
5b9daa7e | 560 | * @param __n The index of the character to access. |
872d8fea | 561 | * @return Read/write reference to the character. |
5b9daa7e | 562 | * @throw std::out_of_range If @a __n is an invalid index. |
872d8fea | 563 | * |
5b9daa7e BK |
564 | * This function provides for safer data access. The parameter |
565 | * is first checked that it is in the range of the string. The | |
566 | * function throws out_of_range if the check fails. Success | |
567 | * results in unsharing the string. | |
872d8fea PC |
568 | */ |
569 | reference | |
570 | at(size_type __n) | |
571 | { | |
572 | if (__n >= this->size()) | |
573 | std::__throw_out_of_range(__N("__versa_string::at")); | |
574 | this->_M_leak(); | |
575 | return this->_M_data()[__n]; | |
576 | } | |
577 | ||
07d8d70f PC |
578 | #ifdef __GXX_EXPERIMENTAL_CXX0X__ |
579 | /** | |
580 | * Returns a read/write reference to the data at the first | |
581 | * element of the %string. | |
582 | */ | |
583 | reference | |
584 | front() | |
585 | { return *begin(); } | |
586 | ||
587 | /** | |
588 | * Returns a read-only (constant) reference to the data at the first | |
589 | * element of the %string. | |
590 | */ | |
591 | const_reference | |
592 | front() const | |
593 | { return *begin(); } | |
594 | ||
595 | /** | |
596 | * Returns a read/write reference to the data at the last | |
597 | * element of the %string. | |
598 | */ | |
599 | reference | |
600 | back() | |
601 | { return *(end() - 1); } | |
602 | ||
603 | /** | |
604 | * Returns a read-only (constant) reference to the data at the | |
605 | * last element of the %string. | |
606 | */ | |
607 | const_reference | |
608 | back() const | |
609 | { return *(end() - 1); } | |
610 | #endif | |
611 | ||
872d8fea PC |
612 | // Modifiers: |
613 | /** | |
614 | * @brief Append a string to this string. | |
5b9daa7e | 615 | * @param __str The string to append. |
872d8fea PC |
616 | * @return Reference to this string. |
617 | */ | |
618 | __versa_string& | |
619 | operator+=(const __versa_string& __str) | |
620 | { return this->append(__str); } | |
621 | ||
622 | /** | |
623 | * @brief Append a C string. | |
5b9daa7e | 624 | * @param __s The C string to append. |
872d8fea PC |
625 | * @return Reference to this string. |
626 | */ | |
627 | __versa_string& | |
628 | operator+=(const _CharT* __s) | |
629 | { return this->append(__s); } | |
630 | ||
631 | /** | |
632 | * @brief Append a character. | |
5b9daa7e | 633 | * @param __c The character to append. |
872d8fea PC |
634 | * @return Reference to this string. |
635 | */ | |
636 | __versa_string& | |
637 | operator+=(_CharT __c) | |
638 | { | |
639 | this->push_back(__c); | |
640 | return *this; | |
641 | } | |
642 | ||
988499f4 JM |
643 | #ifdef __GXX_EXPERIMENTAL_CXX0X__ |
644 | /** | |
645 | * @brief Append an initializer_list of characters. | |
5b9daa7e | 646 | * @param __l The initializer_list of characters to be appended. |
988499f4 JM |
647 | * @return Reference to this string. |
648 | */ | |
649 | __versa_string& | |
650 | operator+=(std::initializer_list<_CharT> __l) | |
651 | { return this->append(__l.begin(), __l.end()); } | |
652 | #endif // __GXX_EXPERIMENTAL_CXX0X__ | |
653 | ||
872d8fea PC |
654 | /** |
655 | * @brief Append a string to this string. | |
5b9daa7e | 656 | * @param __str The string to append. |
872d8fea PC |
657 | * @return Reference to this string. |
658 | */ | |
659 | __versa_string& | |
cf882919 PC |
660 | append(const __versa_string& __str) |
661 | { return _M_append(__str._M_data(), __str.size()); } | |
872d8fea PC |
662 | |
663 | /** | |
664 | * @brief Append a substring. | |
5b9daa7e BK |
665 | * @param __str The string to append. |
666 | * @param __pos Index of the first character of str to append. | |
667 | * @param __n The number of characters to append. | |
872d8fea PC |
668 | * @return Reference to this string. |
669 | * @throw std::out_of_range if @a pos is not a valid index. | |
670 | * | |
5b9daa7e BK |
671 | * This function appends @a __n characters from @a __str |
672 | * starting at @a __pos to this string. If @a __n is is larger | |
673 | * than the number of available characters in @a __str, the | |
674 | * remainder of @a __str is appended. | |
872d8fea PC |
675 | */ |
676 | __versa_string& | |
cf882919 PC |
677 | append(const __versa_string& __str, size_type __pos, size_type __n) |
678 | { return _M_append(__str._M_data() | |
679 | + __str._M_check(__pos, "__versa_string::append"), | |
680 | __str._M_limit(__pos, __n)); } | |
872d8fea PC |
681 | |
682 | /** | |
683 | * @brief Append a C substring. | |
5b9daa7e BK |
684 | * @param __s The C string to append. |
685 | * @param __n The number of characters to append. | |
872d8fea PC |
686 | * @return Reference to this string. |
687 | */ | |
688 | __versa_string& | |
cf882919 PC |
689 | append(const _CharT* __s, size_type __n) |
690 | { | |
691 | __glibcxx_requires_string_len(__s, __n); | |
692 | _M_check_length(size_type(0), __n, "__versa_string::append"); | |
693 | return _M_append(__s, __n); | |
694 | } | |
872d8fea PC |
695 | |
696 | /** | |
697 | * @brief Append a C string. | |
5b9daa7e | 698 | * @param __s The C string to append. |
872d8fea PC |
699 | * @return Reference to this string. |
700 | */ | |
701 | __versa_string& | |
702 | append(const _CharT* __s) | |
703 | { | |
704 | __glibcxx_requires_string(__s); | |
cf882919 PC |
705 | const size_type __n = traits_type::length(__s); |
706 | _M_check_length(size_type(0), __n, "__versa_string::append"); | |
707 | return _M_append(__s, __n); | |
872d8fea PC |
708 | } |
709 | ||
710 | /** | |
711 | * @brief Append multiple characters. | |
5b9daa7e BK |
712 | * @param __n The number of characters to append. |
713 | * @param __c The character to use. | |
872d8fea PC |
714 | * @return Reference to this string. |
715 | * | |
716 | * Appends n copies of c to this string. | |
717 | */ | |
718 | __versa_string& | |
cf882919 PC |
719 | append(size_type __n, _CharT __c) |
720 | { return _M_replace_aux(this->size(), size_type(0), __n, __c); } | |
872d8fea | 721 | |
988499f4 JM |
722 | #ifdef __GXX_EXPERIMENTAL_CXX0X__ |
723 | /** | |
724 | * @brief Append an initializer_list of characters. | |
5b9daa7e | 725 | * @param __l The initializer_list of characters to append. |
988499f4 JM |
726 | * @return Reference to this string. |
727 | */ | |
728 | __versa_string& | |
729 | append(std::initializer_list<_CharT> __l) | |
730 | { return this->append(__l.begin(), __l.end()); } | |
731 | #endif // __GXX_EXPERIMENTAL_CXX0X__ | |
732 | ||
872d8fea PC |
733 | /** |
734 | * @brief Append a range of characters. | |
5b9daa7e BK |
735 | * @param __first Iterator referencing the first character to append. |
736 | * @param __last Iterator marking the end of the range. | |
872d8fea PC |
737 | * @return Reference to this string. |
738 | * | |
739 | * Appends characters in the range [first,last) to this string. | |
740 | */ | |
741 | template<class _InputIterator> | |
742 | __versa_string& | |
743 | append(_InputIterator __first, _InputIterator __last) | |
744 | { return this->replace(_M_iend(), _M_iend(), __first, __last); } | |
745 | ||
746 | /** | |
747 | * @brief Append a single character. | |
5b9daa7e | 748 | * @param __c Character to append. |
872d8fea PC |
749 | */ |
750 | void | |
751 | push_back(_CharT __c) | |
752 | { | |
cf882919 PC |
753 | const size_type __size = this->size(); |
754 | if (__size + 1 > this->capacity() || this->_M_is_shared()) | |
755 | this->_M_mutate(__size, size_type(0), 0, size_type(1)); | |
756 | traits_type::assign(this->_M_data()[__size], __c); | |
757 | this->_M_set_length(__size + 1); | |
872d8fea PC |
758 | } |
759 | ||
760 | /** | |
761 | * @brief Set value to contents of another string. | |
5b9daa7e | 762 | * @param __str Source string to use. |
872d8fea PC |
763 | * @return Reference to this string. |
764 | */ | |
765 | __versa_string& | |
766 | assign(const __versa_string& __str) | |
767 | { | |
768 | this->_M_assign(__str); | |
769 | return *this; | |
770 | } | |
771 | ||
772 | /** | |
773 | * @brief Set value to a substring of a string. | |
5b9daa7e BK |
774 | * @param __str The string to use. |
775 | * @param __pos Index of the first character of str. | |
776 | * @param __n Number of characters to use. | |
872d8fea | 777 | * @return Reference to this string. |
5b9daa7e | 778 | * @throw std::out_of_range if @a __pos is not a valid index. |
872d8fea | 779 | * |
5b9daa7e BK |
780 | * This function sets this string to the substring of @a __str |
781 | * consisting of @a __n characters at @a __pos. If @a __n is | |
782 | * is larger than the number of available characters in @a | |
783 | * __str, the remainder of @a __str is used. | |
872d8fea PC |
784 | */ |
785 | __versa_string& | |
786 | assign(const __versa_string& __str, size_type __pos, size_type __n) | |
cf882919 PC |
787 | { return _M_replace(size_type(0), this->size(), __str._M_data() |
788 | + __str._M_check(__pos, "__versa_string::assign"), | |
789 | __str._M_limit(__pos, __n)); } | |
872d8fea PC |
790 | |
791 | /** | |
792 | * @brief Set value to a C substring. | |
5b9daa7e BK |
793 | * @param __s The C string to use. |
794 | * @param __n Number of characters to use. | |
872d8fea PC |
795 | * @return Reference to this string. |
796 | * | |
5b9daa7e BK |
797 | * This function sets the value of this string to the first @a |
798 | * __n characters of @a __s. If @a __n is is larger than the | |
799 | * number of available characters in @a __s, the remainder of | |
800 | * @a __s is used. | |
872d8fea PC |
801 | */ |
802 | __versa_string& | |
cf882919 PC |
803 | assign(const _CharT* __s, size_type __n) |
804 | { | |
805 | __glibcxx_requires_string_len(__s, __n); | |
806 | return _M_replace(size_type(0), this->size(), __s, __n); | |
807 | } | |
872d8fea PC |
808 | |
809 | /** | |
810 | * @brief Set value to contents of a C string. | |
5b9daa7e | 811 | * @param __s The C string to use. |
872d8fea PC |
812 | * @return Reference to this string. |
813 | * | |
5b9daa7e BK |
814 | * This function sets the value of this string to the value of |
815 | * @a __s. The data is copied, so there is no dependence on @a | |
816 | * __s once the function returns. | |
872d8fea PC |
817 | */ |
818 | __versa_string& | |
819 | assign(const _CharT* __s) | |
820 | { | |
821 | __glibcxx_requires_string(__s); | |
cf882919 PC |
822 | return _M_replace(size_type(0), this->size(), __s, |
823 | traits_type::length(__s)); | |
872d8fea PC |
824 | } |
825 | ||
826 | /** | |
827 | * @brief Set value to multiple characters. | |
5b9daa7e BK |
828 | * @param __n Length of the resulting string. |
829 | * @param __c The character to use. | |
872d8fea PC |
830 | * @return Reference to this string. |
831 | * | |
5b9daa7e BK |
832 | * This function sets the value of this string to @a __n copies of |
833 | * character @a __c. | |
872d8fea PC |
834 | */ |
835 | __versa_string& | |
836 | assign(size_type __n, _CharT __c) | |
837 | { return _M_replace_aux(size_type(0), this->size(), __n, __c); } | |
838 | ||
839 | /** | |
840 | * @brief Set value to a range of characters. | |
5b9daa7e BK |
841 | * @param __first Iterator referencing the first character to append. |
842 | * @param __last Iterator marking the end of the range. | |
872d8fea PC |
843 | * @return Reference to this string. |
844 | * | |
5b9daa7e BK |
845 | * Sets value of string to characters in the range |
846 | * [first,last). | |
872d8fea PC |
847 | */ |
848 | template<class _InputIterator> | |
849 | __versa_string& | |
850 | assign(_InputIterator __first, _InputIterator __last) | |
851 | { return this->replace(_M_ibegin(), _M_iend(), __first, __last); } | |
852 | ||
988499f4 JM |
853 | #ifdef __GXX_EXPERIMENTAL_CXX0X__ |
854 | /** | |
855 | * @brief Set value to an initializer_list of characters. | |
5b9daa7e | 856 | * @param __l The initializer_list of characters to assign. |
988499f4 JM |
857 | * @return Reference to this string. |
858 | */ | |
859 | __versa_string& | |
860 | assign(std::initializer_list<_CharT> __l) | |
861 | { return this->assign(__l.begin(), __l.end()); } | |
862 | #endif // __GXX_EXPERIMENTAL_CXX0X__ | |
863 | ||
872d8fea PC |
864 | /** |
865 | * @brief Insert multiple characters. | |
5b9daa7e BK |
866 | * @param __p Iterator referencing location in string to insert at. |
867 | * @param __n Number of characters to insert | |
868 | * @param __c The character to insert. | |
872d8fea PC |
869 | * @throw std::length_error If new length exceeds @c max_size(). |
870 | * | |
5b9daa7e BK |
871 | * Inserts @a __n copies of character @a __c starting at the |
872 | * position referenced by iterator @a __p. If adding | |
873 | * characters causes the length to exceed max_size(), | |
874 | * length_error is thrown. The value of the string doesn't | |
875 | * change if an error is thrown. | |
872d8fea PC |
876 | */ |
877 | void | |
878 | insert(iterator __p, size_type __n, _CharT __c) | |
879 | { this->replace(__p, __p, __n, __c); } | |
880 | ||
881 | /** | |
882 | * @brief Insert a range of characters. | |
5b9daa7e BK |
883 | * @param __p Iterator referencing location in string to insert at. |
884 | * @param __beg Start of range. | |
885 | * @param __end End of range. | |
872d8fea PC |
886 | * @throw std::length_error If new length exceeds @c max_size(). |
887 | * | |
5b9daa7e BK |
888 | * Inserts characters in range [beg,end). If adding characters |
889 | * causes the length to exceed max_size(), length_error is | |
890 | * thrown. The value of the string doesn't change if an error | |
891 | * is thrown. | |
872d8fea PC |
892 | */ |
893 | template<class _InputIterator> | |
894 | void | |
895 | insert(iterator __p, _InputIterator __beg, _InputIterator __end) | |
896 | { this->replace(__p, __p, __beg, __end); } | |
897 | ||
988499f4 JM |
898 | #ifdef __GXX_EXPERIMENTAL_CXX0X__ |
899 | /** | |
900 | * @brief Insert an initializer_list of characters. | |
5b9daa7e BK |
901 | * @param __p Iterator referencing location in string to insert at. |
902 | * @param __l The initializer_list of characters to insert. | |
988499f4 JM |
903 | * @throw std::length_error If new length exceeds @c max_size(). |
904 | */ | |
905 | void | |
906 | insert(iterator __p, std::initializer_list<_CharT> __l) | |
907 | { this->insert(__p, __l.begin(), __l.end()); } | |
908 | #endif // __GXX_EXPERIMENTAL_CXX0X__ | |
909 | ||
872d8fea PC |
910 | /** |
911 | * @brief Insert value of a string. | |
5b9daa7e BK |
912 | * @param __pos1 Iterator referencing location in string to insert at. |
913 | * @param __str The string to insert. | |
872d8fea PC |
914 | * @return Reference to this string. |
915 | * @throw std::length_error If new length exceeds @c max_size(). | |
916 | * | |
5b9daa7e BK |
917 | * Inserts value of @a __str starting at @a __pos1. If adding |
918 | * characters causes the length to exceed max_size(), | |
919 | * length_error is thrown. The value of the string doesn't | |
920 | * change if an error is thrown. | |
872d8fea PC |
921 | */ |
922 | __versa_string& | |
923 | insert(size_type __pos1, const __versa_string& __str) | |
cf882919 PC |
924 | { return this->replace(__pos1, size_type(0), |
925 | __str._M_data(), __str.size()); } | |
872d8fea PC |
926 | |
927 | /** | |
928 | * @brief Insert a substring. | |
5b9daa7e BK |
929 | * @param __pos1 Iterator referencing location in string to insert at. |
930 | * @param __str The string to insert. | |
931 | * @param __pos2 Start of characters in str to insert. | |
932 | * @param __n Number of characters to insert. | |
872d8fea PC |
933 | * @return Reference to this string. |
934 | * @throw std::length_error If new length exceeds @c max_size(). | |
5b9daa7e BK |
935 | * @throw std::out_of_range If @a __pos1 > size() or |
936 | * @a __pos2 > @a __str.size(). | |
937 | * | |
938 | * Starting at @a __pos1, insert @a __n character of @a __str | |
939 | * beginning with @a __pos2. If adding characters causes the | |
940 | * length to exceed max_size(), length_error is thrown. If @a | |
941 | * __pos1 is beyond the end of this string or @a __pos2 is | |
942 | * beyond the end of @a __str, out_of_range is thrown. The | |
943 | * value of the string doesn't change if an error is thrown. | |
872d8fea PC |
944 | */ |
945 | __versa_string& | |
946 | insert(size_type __pos1, const __versa_string& __str, | |
947 | size_type __pos2, size_type __n) | |
cf882919 PC |
948 | { return this->replace(__pos1, size_type(0), __str._M_data() |
949 | + __str._M_check(__pos2, "__versa_string::insert"), | |
950 | __str._M_limit(__pos2, __n)); } | |
872d8fea PC |
951 | |
952 | /** | |
953 | * @brief Insert a C substring. | |
5b9daa7e BK |
954 | * @param __pos Iterator referencing location in string to insert at. |
955 | * @param __s The C string to insert. | |
956 | * @param __n The number of characters to insert. | |
872d8fea PC |
957 | * @return Reference to this string. |
958 | * @throw std::length_error If new length exceeds @c max_size(). | |
5b9daa7e | 959 | * @throw std::out_of_range If @a __pos is beyond the end of this |
872d8fea PC |
960 | * string. |
961 | * | |
5b9daa7e BK |
962 | * Inserts the first @a __n characters of @a __s starting at @a |
963 | * __pos. If adding characters causes the length to exceed | |
964 | * max_size(), length_error is thrown. If @a __pos is beyond | |
965 | * end(), out_of_range is thrown. The value of the string | |
966 | * doesn't change if an error is thrown. | |
872d8fea PC |
967 | */ |
968 | __versa_string& | |
cf882919 PC |
969 | insert(size_type __pos, const _CharT* __s, size_type __n) |
970 | { return this->replace(__pos, size_type(0), __s, __n); } | |
872d8fea PC |
971 | |
972 | /** | |
973 | * @brief Insert a C string. | |
5b9daa7e BK |
974 | * @param __pos Iterator referencing location in string to insert at. |
975 | * @param __s The C string to insert. | |
872d8fea PC |
976 | * @return Reference to this string. |
977 | * @throw std::length_error If new length exceeds @c max_size(). | |
5b9daa7e | 978 | * @throw std::out_of_range If @a __pos is beyond the end of this |
872d8fea PC |
979 | * string. |
980 | * | |
5b9daa7e BK |
981 | * Inserts the first @a __n characters of @a __s starting at @a |
982 | * __pos. If adding characters causes the length to exceed | |
983 | * max_size(), length_error is thrown. If @a __pos is beyond | |
984 | * end(), out_of_range is thrown. The value of the string | |
985 | * doesn't change if an error is thrown. | |
872d8fea PC |
986 | */ |
987 | __versa_string& | |
988 | insert(size_type __pos, const _CharT* __s) | |
989 | { | |
990 | __glibcxx_requires_string(__s); | |
cf882919 PC |
991 | return this->replace(__pos, size_type(0), __s, |
992 | traits_type::length(__s)); | |
872d8fea PC |
993 | } |
994 | ||
995 | /** | |
996 | * @brief Insert multiple characters. | |
5b9daa7e BK |
997 | * @param __pos Index in string to insert at. |
998 | * @param __n Number of characters to insert | |
999 | * @param __c The character to insert. | |
872d8fea PC |
1000 | * @return Reference to this string. |
1001 | * @throw std::length_error If new length exceeds @c max_size(). | |
5b9daa7e | 1002 | * @throw std::out_of_range If @a __pos is beyond the end of this |
872d8fea PC |
1003 | * string. |
1004 | * | |
5b9daa7e BK |
1005 | * Inserts @a __n copies of character @a __c starting at index |
1006 | * @a __pos. If adding characters causes the length to exceed | |
1007 | * max_size(), length_error is thrown. If @a __pos > length(), | |
1008 | * out_of_range is thrown. The value of the string doesn't | |
1009 | * change if an error is thrown. | |
872d8fea PC |
1010 | */ |
1011 | __versa_string& | |
1012 | insert(size_type __pos, size_type __n, _CharT __c) | |
1013 | { return _M_replace_aux(_M_check(__pos, "__versa_string::insert"), | |
1014 | size_type(0), __n, __c); } | |
1015 | ||
1016 | /** | |
1017 | * @brief Insert one character. | |
5b9daa7e BK |
1018 | * @param __p Iterator referencing position in string to insert at. |
1019 | * @param __c The character to insert. | |
872d8fea PC |
1020 | * @return Iterator referencing newly inserted char. |
1021 | * @throw std::length_error If new length exceeds @c max_size(). | |
1022 | * | |
5b9daa7e BK |
1023 | * Inserts character @a __c at position referenced by @a __p. |
1024 | * If adding character causes the length to exceed max_size(), | |
1025 | * length_error is thrown. If @a __p is beyond end of string, | |
1026 | * out_of_range is thrown. The value of the string doesn't | |
1027 | * change if an error is thrown. | |
872d8fea PC |
1028 | */ |
1029 | iterator | |
1030 | insert(iterator __p, _CharT __c) | |
1031 | { | |
1032 | _GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend()); | |
1033 | const size_type __pos = __p - _M_ibegin(); | |
1034 | _M_replace_aux(__pos, size_type(0), size_type(1), __c); | |
1035 | this->_M_set_leaked(); | |
cf882919 | 1036 | return iterator(this->_M_data() + __pos); |
872d8fea PC |
1037 | } |
1038 | ||
1039 | /** | |
1040 | * @brief Remove characters. | |
5b9daa7e BK |
1041 | * @param __pos Index of first character to remove (default 0). |
1042 | * @param __n Number of characters to remove (default remainder). | |
872d8fea | 1043 | * @return Reference to this string. |
5b9daa7e | 1044 | * @throw std::out_of_range If @a __pos is beyond the end of this |
872d8fea PC |
1045 | * string. |
1046 | * | |
5b9daa7e BK |
1047 | * Removes @a __n characters from this string starting at @a |
1048 | * __pos. The length of the string is reduced by @a __n. If | |
1049 | * there are < @a __n characters to remove, the remainder of | |
1050 | * the string is truncated. If @a __p is beyond end of string, | |
1051 | * out_of_range is thrown. The value of the string doesn't | |
1052 | * change if an error is thrown. | |
872d8fea PC |
1053 | */ |
1054 | __versa_string& | |
1055 | erase(size_type __pos = 0, size_type __n = npos) | |
1056 | { | |
cf882919 PC |
1057 | this->_M_erase(_M_check(__pos, "__versa_string::erase"), |
1058 | _M_limit(__pos, __n)); | |
872d8fea PC |
1059 | return *this; |
1060 | } | |
1061 | ||
1062 | /** | |
1063 | * @brief Remove one character. | |
5b9daa7e | 1064 | * @param __position Iterator referencing the character to remove. |
872d8fea PC |
1065 | * @return iterator referencing same location after removal. |
1066 | * | |
5b9daa7e BK |
1067 | * Removes the character at @a __position from this string. The |
1068 | * value of the string doesn't change if an error is thrown. | |
872d8fea PC |
1069 | */ |
1070 | iterator | |
1071 | erase(iterator __position) | |
1072 | { | |
1073 | _GLIBCXX_DEBUG_PEDASSERT(__position >= _M_ibegin() | |
1074 | && __position < _M_iend()); | |
1075 | const size_type __pos = __position - _M_ibegin(); | |
cf882919 | 1076 | this->_M_erase(__pos, size_type(1)); |
872d8fea | 1077 | this->_M_set_leaked(); |
cf882919 | 1078 | return iterator(this->_M_data() + __pos); |
872d8fea PC |
1079 | } |
1080 | ||
1081 | /** | |
1082 | * @brief Remove a range of characters. | |
5b9daa7e BK |
1083 | * @param __first Iterator referencing the first character to remove. |
1084 | * @param __last Iterator referencing the end of the range. | |
872d8fea PC |
1085 | * @return Iterator referencing location of first after removal. |
1086 | * | |
5b9daa7e BK |
1087 | * Removes the characters in the range [first,last) from this |
1088 | * string. The value of the string doesn't change if an error | |
1089 | * is thrown. | |
872d8fea PC |
1090 | */ |
1091 | iterator | |
1092 | erase(iterator __first, iterator __last) | |
1093 | { | |
1094 | _GLIBCXX_DEBUG_PEDASSERT(__first >= _M_ibegin() && __first <= __last | |
1095 | && __last <= _M_iend()); | |
1096 | const size_type __pos = __first - _M_ibegin(); | |
cf882919 | 1097 | this->_M_erase(__pos, __last - __first); |
872d8fea | 1098 | this->_M_set_leaked(); |
cf882919 | 1099 | return iterator(this->_M_data() + __pos); |
872d8fea PC |
1100 | } |
1101 | ||
1102 | /** | |
1103 | * @brief Replace characters with value from another string. | |
5b9daa7e BK |
1104 | * @param __pos Index of first character to replace. |
1105 | * @param __n Number of characters to be replaced. | |
1106 | * @param __str String to insert. | |
872d8fea | 1107 | * @return Reference to this string. |
5b9daa7e | 1108 | * @throw std::out_of_range If @a __pos is beyond the end of this |
872d8fea PC |
1109 | * string. |
1110 | * @throw std::length_error If new length exceeds @c max_size(). | |
1111 | * | |
5b9daa7e BK |
1112 | * Removes the characters in the range [pos,pos+n) from this |
1113 | * string. In place, the value of @a __str is inserted. If @a | |
1114 | * __pos is beyond end of string, out_of_range is thrown. If | |
1115 | * the length of the result exceeds max_size(), length_error is | |
1116 | * thrown. The value of the string doesn't change if an error | |
1117 | * is thrown. | |
872d8fea PC |
1118 | */ |
1119 | __versa_string& | |
1120 | replace(size_type __pos, size_type __n, const __versa_string& __str) | |
1121 | { return this->replace(__pos, __n, __str._M_data(), __str.size()); } | |
1122 | ||
1123 | /** | |
1124 | * @brief Replace characters with value from another string. | |
5b9daa7e BK |
1125 | * @param __pos1 Index of first character to replace. |
1126 | * @param __n1 Number of characters to be replaced. | |
1127 | * @param __str String to insert. | |
1128 | * @param __pos2 Index of first character of str to use. | |
1129 | * @param __n2 Number of characters from str to use. | |
872d8fea | 1130 | * @return Reference to this string. |
5b9daa7e | 1131 | * @throw std::out_of_range If @a __pos1 > size() or @a __pos2 > |
872d8fea PC |
1132 | * str.size(). |
1133 | * @throw std::length_error If new length exceeds @c max_size(). | |
1134 | * | |
5b9daa7e BK |
1135 | * Removes the characters in the range [pos1,pos1 + n) from |
1136 | * this string. In place, the value of @a __str is inserted. | |
1137 | * If @a __pos is beyond end of string, out_of_range is thrown. | |
1138 | * If the length of the result exceeds max_size(), length_error | |
1139 | * is thrown. The value of the string doesn't change if an | |
1140 | * error is thrown. | |
872d8fea PC |
1141 | */ |
1142 | __versa_string& | |
1143 | replace(size_type __pos1, size_type __n1, const __versa_string& __str, | |
1144 | size_type __pos2, size_type __n2) | |
1145 | { | |
1146 | return this->replace(__pos1, __n1, __str._M_data() | |
1147 | + __str._M_check(__pos2, | |
1148 | "__versa_string::replace"), | |
1149 | __str._M_limit(__pos2, __n2)); | |
1150 | } | |
1151 | ||
1152 | /** | |
1153 | * @brief Replace characters with value of a C substring. | |
5b9daa7e BK |
1154 | * @param __pos Index of first character to replace. |
1155 | * @param __n1 Number of characters to be replaced. | |
1156 | * @param __s C string to insert. | |
1157 | * @param __n2 Number of characters from @a __s to use. | |
872d8fea | 1158 | * @return Reference to this string. |
5b9daa7e | 1159 | * @throw std::out_of_range If @a __pos1 > size(). |
872d8fea PC |
1160 | * @throw std::length_error If new length exceeds @c max_size(). |
1161 | * | |
5b9daa7e BK |
1162 | * Removes the characters in the range [pos,pos + n1) from this |
1163 | * string. In place, the first @a __n2 characters of @a __s | |
1164 | * are inserted, or all of @a __s if @a __n2 is too large. If | |
1165 | * @a __pos is beyond end of string, out_of_range is thrown. | |
1166 | * If the length of result exceeds max_size(), length_error is | |
1167 | * thrown. The value of the string doesn't change if an error | |
1168 | * is thrown. | |
872d8fea PC |
1169 | */ |
1170 | __versa_string& | |
1171 | replace(size_type __pos, size_type __n1, const _CharT* __s, | |
cf882919 PC |
1172 | size_type __n2) |
1173 | { | |
1174 | __glibcxx_requires_string_len(__s, __n2); | |
1175 | return _M_replace(_M_check(__pos, "__versa_string::replace"), | |
1176 | _M_limit(__pos, __n1), __s, __n2); | |
1177 | } | |
872d8fea PC |
1178 | |
1179 | /** | |
1180 | * @brief Replace characters with value of a C string. | |
5b9daa7e BK |
1181 | * @param __pos Index of first character to replace. |
1182 | * @param __n1 Number of characters to be replaced. | |
1183 | * @param __s C string to insert. | |
872d8fea | 1184 | * @return Reference to this string. |
5b9daa7e | 1185 | * @throw std::out_of_range If @a __pos > size(). |
872d8fea PC |
1186 | * @throw std::length_error If new length exceeds @c max_size(). |
1187 | * | |
5b9daa7e BK |
1188 | * Removes the characters in the range [pos,pos + n1) from this |
1189 | * string. In place, the first @a __n characters of @a __s are | |
1190 | * inserted. If @a pos is beyond end of string, out_of_range | |
1191 | * is thrown. If the length of result exceeds max_size(), | |
1192 | * length_error is thrown. The value of the string doesn't | |
1193 | * change if an error is thrown. | |
872d8fea PC |
1194 | */ |
1195 | __versa_string& | |
1196 | replace(size_type __pos, size_type __n1, const _CharT* __s) | |
1197 | { | |
1198 | __glibcxx_requires_string(__s); | |
1199 | return this->replace(__pos, __n1, __s, traits_type::length(__s)); | |
1200 | } | |
1201 | ||
1202 | /** | |
1203 | * @brief Replace characters with multiple characters. | |
5b9daa7e BK |
1204 | * @param __pos Index of first character to replace. |
1205 | * @param __n1 Number of characters to be replaced. | |
1206 | * @param __n2 Number of characters to insert. | |
1207 | * @param __c Character to insert. | |
872d8fea | 1208 | * @return Reference to this string. |
5b9daa7e | 1209 | * @throw std::out_of_range If @a __pos > size(). |
872d8fea PC |
1210 | * @throw std::length_error If new length exceeds @c max_size(). |
1211 | * | |
5b9daa7e BK |
1212 | * Removes the characters in the range [pos,pos + n1) from this |
1213 | * string. In place, @a __n2 copies of @a __c are inserted. | |
1214 | * If @a __pos is beyond end of string, out_of_range is thrown. | |
1215 | * If the length of result exceeds max_size(), length_error is | |
1216 | * thrown. The value of the string doesn't change if an error | |
1217 | * is thrown. | |
872d8fea PC |
1218 | */ |
1219 | __versa_string& | |
1220 | replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c) | |
1221 | { return _M_replace_aux(_M_check(__pos, "__versa_string::replace"), | |
1222 | _M_limit(__pos, __n1), __n2, __c); } | |
1223 | ||
1224 | /** | |
1225 | * @brief Replace range of characters with string. | |
5b9daa7e BK |
1226 | * @param __i1 Iterator referencing start of range to replace. |
1227 | * @param __i2 Iterator referencing end of range to replace. | |
1228 | * @param __str String value to insert. | |
872d8fea PC |
1229 | * @return Reference to this string. |
1230 | * @throw std::length_error If new length exceeds @c max_size(). | |
1231 | * | |
5b9daa7e BK |
1232 | * Removes the characters in the range [i1,i2). In place, the |
1233 | * value of @a __str is inserted. If the length of result | |
1234 | * exceeds max_size(), length_error is thrown. The value of | |
1235 | * the string doesn't change if an error is thrown. | |
872d8fea PC |
1236 | */ |
1237 | __versa_string& | |
1238 | replace(iterator __i1, iterator __i2, const __versa_string& __str) | |
1239 | { return this->replace(__i1, __i2, __str._M_data(), __str.size()); } | |
1240 | ||
1241 | /** | |
1242 | * @brief Replace range of characters with C substring. | |
5b9daa7e BK |
1243 | * @param __i1 Iterator referencing start of range to replace. |
1244 | * @param __i2 Iterator referencing end of range to replace. | |
1245 | * @param __s C string value to insert. | |
1246 | * @param __n Number of characters from s to insert. | |
872d8fea PC |
1247 | * @return Reference to this string. |
1248 | * @throw std::length_error If new length exceeds @c max_size(). | |
1249 | * | |
5b9daa7e BK |
1250 | * Removes the characters in the range [i1,i2). In place, the |
1251 | * first @a n characters of @a __s are inserted. If the length | |
1252 | * of result exceeds max_size(), length_error is thrown. The | |
1253 | * value of the string doesn't change if an error is thrown. | |
872d8fea PC |
1254 | */ |
1255 | __versa_string& | |
1256 | replace(iterator __i1, iterator __i2, const _CharT* __s, size_type __n) | |
1257 | { | |
1258 | _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 | |
1259 | && __i2 <= _M_iend()); | |
1260 | return this->replace(__i1 - _M_ibegin(), __i2 - __i1, __s, __n); | |
1261 | } | |
1262 | ||
1263 | /** | |
1264 | * @brief Replace range of characters with C string. | |
5b9daa7e BK |
1265 | * @param __i1 Iterator referencing start of range to replace. |
1266 | * @param __i2 Iterator referencing end of range to replace. | |
1267 | * @param __s C string value to insert. | |
872d8fea PC |
1268 | * @return Reference to this string. |
1269 | * @throw std::length_error If new length exceeds @c max_size(). | |
1270 | * | |
1271 | * Removes the characters in the range [i1,i2). In place, the | |
5b9daa7e BK |
1272 | * characters of @a __s are inserted. If the length of result |
1273 | * exceeds max_size(), length_error is thrown. The value of | |
1274 | * the string doesn't change if an error is thrown. | |
872d8fea PC |
1275 | */ |
1276 | __versa_string& | |
1277 | replace(iterator __i1, iterator __i2, const _CharT* __s) | |
1278 | { | |
1279 | __glibcxx_requires_string(__s); | |
1280 | return this->replace(__i1, __i2, __s, traits_type::length(__s)); | |
1281 | } | |
1282 | ||
1283 | /** | |
1284 | * @brief Replace range of characters with multiple characters | |
5b9daa7e BK |
1285 | * @param __i1 Iterator referencing start of range to replace. |
1286 | * @param __i2 Iterator referencing end of range to replace. | |
1287 | * @param __n Number of characters to insert. | |
1288 | * @param __c Character to insert. | |
872d8fea PC |
1289 | * @return Reference to this string. |
1290 | * @throw std::length_error If new length exceeds @c max_size(). | |
1291 | * | |
5b9daa7e BK |
1292 | * Removes the characters in the range [i1,i2). In place, @a |
1293 | * __n copies of @a __c are inserted. If the length of result | |
1294 | * exceeds max_size(), length_error is thrown. The value of | |
1295 | * the string doesn't change if an error is thrown. | |
872d8fea PC |
1296 | */ |
1297 | __versa_string& | |
1298 | replace(iterator __i1, iterator __i2, size_type __n, _CharT __c) | |
1299 | { | |
1300 | _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 | |
1301 | && __i2 <= _M_iend()); | |
1302 | return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __c); | |
1303 | } | |
1304 | ||
1305 | /** | |
1306 | * @brief Replace range of characters with range. | |
5b9daa7e BK |
1307 | * @param __i1 Iterator referencing start of range to replace. |
1308 | * @param __i2 Iterator referencing end of range to replace. | |
1309 | * @param __k1 Iterator referencing start of range to insert. | |
1310 | * @param __k2 Iterator referencing end of range to insert. | |
872d8fea PC |
1311 | * @return Reference to this string. |
1312 | * @throw std::length_error If new length exceeds @c max_size(). | |
1313 | * | |
5b9daa7e BK |
1314 | * Removes the characters in the range [i1,i2). In place, |
1315 | * characters in the range [k1,k2) are inserted. If the length | |
1316 | * of result exceeds max_size(), length_error is thrown. The | |
1317 | * value of the string doesn't change if an error is thrown. | |
872d8fea PC |
1318 | */ |
1319 | template<class _InputIterator> | |
1320 | __versa_string& | |
1321 | replace(iterator __i1, iterator __i2, | |
1322 | _InputIterator __k1, _InputIterator __k2) | |
1323 | { | |
1324 | _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 | |
1325 | && __i2 <= _M_iend()); | |
1326 | __glibcxx_requires_valid_range(__k1, __k2); | |
1327 | typedef typename std::__is_integer<_InputIterator>::__type _Integral; | |
1328 | return _M_replace_dispatch(__i1, __i2, __k1, __k2, _Integral()); | |
1329 | } | |
1330 | ||
1331 | // Specializations for the common case of pointer and iterator: | |
1332 | // useful to avoid the overhead of temporary buffering in _M_replace. | |
1333 | __versa_string& | |
1334 | replace(iterator __i1, iterator __i2, _CharT* __k1, _CharT* __k2) | |
1335 | { | |
1336 | _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 | |
1337 | && __i2 <= _M_iend()); | |
1338 | __glibcxx_requires_valid_range(__k1, __k2); | |
1339 | return this->replace(__i1 - _M_ibegin(), __i2 - __i1, | |
1340 | __k1, __k2 - __k1); | |
1341 | } | |
1342 | ||
1343 | __versa_string& | |
1344 | replace(iterator __i1, iterator __i2, | |
1345 | const _CharT* __k1, const _CharT* __k2) | |
1346 | { | |
1347 | _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 | |
1348 | && __i2 <= _M_iend()); | |
1349 | __glibcxx_requires_valid_range(__k1, __k2); | |
1350 | return this->replace(__i1 - _M_ibegin(), __i2 - __i1, | |
1351 | __k1, __k2 - __k1); | |
1352 | } | |
1353 | ||
1354 | __versa_string& | |
1355 | replace(iterator __i1, iterator __i2, iterator __k1, iterator __k2) | |
1356 | { | |
1357 | _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 | |
1358 | && __i2 <= _M_iend()); | |
1359 | __glibcxx_requires_valid_range(__k1, __k2); | |
1360 | return this->replace(__i1 - _M_ibegin(), __i2 - __i1, | |
1361 | __k1.base(), __k2 - __k1); | |
1362 | } | |
1363 | ||
1364 | __versa_string& | |
1365 | replace(iterator __i1, iterator __i2, | |
1366 | const_iterator __k1, const_iterator __k2) | |
1367 | { | |
1368 | _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 | |
1369 | && __i2 <= _M_iend()); | |
1370 | __glibcxx_requires_valid_range(__k1, __k2); | |
1371 | return this->replace(__i1 - _M_ibegin(), __i2 - __i1, | |
1372 | __k1.base(), __k2 - __k1); | |
1373 | } | |
1374 | ||
988499f4 JM |
1375 | #ifdef __GXX_EXPERIMENTAL_CXX0X__ |
1376 | /** | |
1377 | * @brief Replace range of characters with initializer_list. | |
5b9daa7e BK |
1378 | * @param __i1 Iterator referencing start of range to replace. |
1379 | * @param __i2 Iterator referencing end of range to replace. | |
1380 | * @param __l The initializer_list of characters to insert. | |
988499f4 JM |
1381 | * @return Reference to this string. |
1382 | * @throw std::length_error If new length exceeds @c max_size(). | |
1383 | * | |
5b9daa7e BK |
1384 | * Removes the characters in the range [i1,i2). In place, |
1385 | * characters in the range [k1,k2) are inserted. If the length | |
1386 | * of result exceeds max_size(), length_error is thrown. The | |
1387 | * value of the string doesn't change if an error is thrown. | |
988499f4 JM |
1388 | */ |
1389 | __versa_string& replace(iterator __i1, iterator __i2, | |
1390 | std::initializer_list<_CharT> __l) | |
1391 | { return this->replace(__i1, __i2, __l.begin(), __l.end()); } | |
1392 | #endif // __GXX_EXPERIMENTAL_CXX0X__ | |
1393 | ||
872d8fea PC |
1394 | private: |
1395 | template<class _Integer> | |
1396 | __versa_string& | |
1397 | _M_replace_dispatch(iterator __i1, iterator __i2, _Integer __n, | |
78a53887 | 1398 | _Integer __val, std::__true_type) |
872d8fea PC |
1399 | { return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __val); } |
1400 | ||
1401 | template<class _InputIterator> | |
1402 | __versa_string& | |
1403 | _M_replace_dispatch(iterator __i1, iterator __i2, _InputIterator __k1, | |
78a53887 | 1404 | _InputIterator __k2, std::__false_type); |
872d8fea PC |
1405 | |
1406 | __versa_string& | |
1407 | _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2, | |
1408 | _CharT __c); | |
1409 | ||
1410 | __versa_string& | |
cf882919 PC |
1411 | _M_replace(size_type __pos, size_type __len1, const _CharT* __s, |
1412 | const size_type __len2); | |
1413 | ||
1414 | __versa_string& | |
1415 | _M_append(const _CharT* __s, size_type __n); | |
872d8fea PC |
1416 | |
1417 | public: | |
1418 | ||
1419 | /** | |
1420 | * @brief Copy substring into C string. | |
5b9daa7e BK |
1421 | * @param __s C string to copy value into. |
1422 | * @param __n Number of characters to copy. | |
1423 | * @param __pos Index of first character to copy. | |
872d8fea PC |
1424 | * @return Number of characters actually copied |
1425 | * @throw std::out_of_range If pos > size(). | |
1426 | * | |
5b9daa7e BK |
1427 | * Copies up to @a __n characters starting at @a __pos into the |
1428 | * C string @a s. If @a __pos is greater than size(), | |
1429 | * out_of_range is thrown. | |
872d8fea PC |
1430 | */ |
1431 | size_type | |
1432 | copy(_CharT* __s, size_type __n, size_type __pos = 0) const; | |
1433 | ||
1434 | /** | |
1435 | * @brief Swap contents with another string. | |
5b9daa7e | 1436 | * @param __s String to swap with. |
872d8fea | 1437 | * |
5b9daa7e BK |
1438 | * Exchanges the contents of this string with that of @a __s in |
1439 | * constant time. | |
872d8fea PC |
1440 | */ |
1441 | void | |
7697e6c6 PC |
1442 | swap(__versa_string& __s) |
1443 | { this->_M_swap(__s); } | |
872d8fea PC |
1444 | |
1445 | // String operations: | |
1446 | /** | |
1447 | * @brief Return const pointer to null-terminated contents. | |
1448 | * | |
1449 | * This is a handle to internal data. Do not modify or dire things may | |
1450 | * happen. | |
1451 | */ | |
1452 | const _CharT* | |
1453 | c_str() const | |
1454 | { return this->_M_data(); } | |
1455 | ||
1456 | /** | |
1457 | * @brief Return const pointer to contents. | |
1458 | * | |
1459 | * This is a handle to internal data. Do not modify or dire things may | |
1460 | * happen. | |
1461 | */ | |
1462 | const _CharT* | |
1463 | data() const | |
1464 | { return this->_M_data(); } | |
1465 | ||
1466 | /** | |
1467 | * @brief Return copy of allocator used to construct this string. | |
1468 | */ | |
1469 | allocator_type | |
1470 | get_allocator() const | |
f7ace77f | 1471 | { return allocator_type(this->_M_get_allocator()); } |
872d8fea PC |
1472 | |
1473 | /** | |
1474 | * @brief Find position of a C substring. | |
5b9daa7e BK |
1475 | * @param __s C string to locate. |
1476 | * @param __pos Index of character to search from. | |
1477 | * @param __n Number of characters from @a __s to search for. | |
872d8fea PC |
1478 | * @return Index of start of first occurrence. |
1479 | * | |
5b9daa7e BK |
1480 | * Starting from @a __pos, searches forward for the first @a |
1481 | * __n characters in @a __s within this string. If found, | |
1482 | * returns the index where it begins. If not found, returns | |
1483 | * npos. | |
872d8fea PC |
1484 | */ |
1485 | size_type | |
1486 | find(const _CharT* __s, size_type __pos, size_type __n) const; | |
1487 | ||
1488 | /** | |
1489 | * @brief Find position of a string. | |
5b9daa7e BK |
1490 | * @param __str String to locate. |
1491 | * @param __pos Index of character to search from (default 0). | |
872d8fea PC |
1492 | * @return Index of start of first occurrence. |
1493 | * | |
5b9daa7e BK |
1494 | * Starting from @a __pos, searches forward for value of @a |
1495 | * __str within this string. If found, returns the index where | |
1496 | * it begins. If not found, returns npos. | |
872d8fea PC |
1497 | */ |
1498 | size_type | |
1499 | find(const __versa_string& __str, size_type __pos = 0) const | |
1500 | { return this->find(__str.data(), __pos, __str.size()); } | |
1501 | ||
1502 | /** | |
1503 | * @brief Find position of a C string. | |
5b9daa7e BK |
1504 | * @param __s C string to locate. |
1505 | * @param __pos Index of character to search from (default 0). | |
872d8fea PC |
1506 | * @return Index of start of first occurrence. |
1507 | * | |
5b9daa7e BK |
1508 | * Starting from @a __pos, searches forward for the value of @a |
1509 | * __s within this string. If found, returns the index where | |
1510 | * it begins. If not found, returns npos. | |
872d8fea PC |
1511 | */ |
1512 | size_type | |
1513 | find(const _CharT* __s, size_type __pos = 0) const | |
1514 | { | |
1515 | __glibcxx_requires_string(__s); | |
1516 | return this->find(__s, __pos, traits_type::length(__s)); | |
1517 | } | |
1518 | ||
1519 | /** | |
1520 | * @brief Find position of a character. | |
5b9daa7e BK |
1521 | * @param __c Character to locate. |
1522 | * @param __pos Index of character to search from (default 0). | |
872d8fea PC |
1523 | * @return Index of first occurrence. |
1524 | * | |
5b9daa7e BK |
1525 | * Starting from @a __pos, searches forward for @a __c within |
1526 | * this string. If found, returns the index where it was | |
1527 | * found. If not found, returns npos. | |
872d8fea PC |
1528 | */ |
1529 | size_type | |
1530 | find(_CharT __c, size_type __pos = 0) const; | |
1531 | ||
1532 | /** | |
1533 | * @brief Find last position of a string. | |
5b9daa7e BK |
1534 | * @param __str String to locate. |
1535 | * @param __pos Index of character to search back from (default end). | |
872d8fea PC |
1536 | * @return Index of start of last occurrence. |
1537 | * | |
5b9daa7e BK |
1538 | * Starting from @a __pos, searches backward for value of @a |
1539 | * __str within this string. If found, returns the index where | |
1540 | * it begins. If not found, returns npos. | |
872d8fea PC |
1541 | */ |
1542 | size_type | |
1543 | rfind(const __versa_string& __str, size_type __pos = npos) const | |
1544 | { return this->rfind(__str.data(), __pos, __str.size()); } | |
1545 | ||
1546 | /** | |
1547 | * @brief Find last position of a C substring. | |
5b9daa7e BK |
1548 | * @param __s C string to locate. |
1549 | * @param __pos Index of character to search back from. | |
1550 | * @param __n Number of characters from s to search for. | |
872d8fea PC |
1551 | * @return Index of start of last occurrence. |
1552 | * | |
5b9daa7e BK |
1553 | * Starting from @a __pos, searches backward for the first @a |
1554 | * __n characters in @a __s within this string. If found, | |
1555 | * returns the index where it begins. If not found, returns | |
1556 | * npos. | |
872d8fea PC |
1557 | */ |
1558 | size_type | |
1559 | rfind(const _CharT* __s, size_type __pos, size_type __n) const; | |
1560 | ||
1561 | /** | |
1562 | * @brief Find last position of a C string. | |
5b9daa7e BK |
1563 | * @param __s C string to locate. |
1564 | * @param __pos Index of character to start search at (default end). | |
872d8fea PC |
1565 | * @return Index of start of last occurrence. |
1566 | * | |
5b9daa7e BK |
1567 | * Starting from @a __pos, searches backward for the value of |
1568 | * @a __s within this string. If found, returns the index | |
1569 | * where it begins. If not found, returns npos. | |
872d8fea PC |
1570 | */ |
1571 | size_type | |
1572 | rfind(const _CharT* __s, size_type __pos = npos) const | |
1573 | { | |
1574 | __glibcxx_requires_string(__s); | |
1575 | return this->rfind(__s, __pos, traits_type::length(__s)); | |
1576 | } | |
1577 | ||
1578 | /** | |
1579 | * @brief Find last position of a character. | |
5b9daa7e BK |
1580 | * @param __c Character to locate. |
1581 | * @param __pos Index of character to search back from (default end). | |
872d8fea PC |
1582 | * @return Index of last occurrence. |
1583 | * | |
5b9daa7e BK |
1584 | * Starting from @a __pos, searches backward for @a __c within |
1585 | * this string. If found, returns the index where it was | |
1586 | * found. If not found, returns npos. | |
872d8fea PC |
1587 | */ |
1588 | size_type | |
1589 | rfind(_CharT __c, size_type __pos = npos) const; | |
1590 | ||
1591 | /** | |
1592 | * @brief Find position of a character of string. | |
5b9daa7e BK |
1593 | * @param __str String containing characters to locate. |
1594 | * @param __pos Index of character to search from (default 0). | |
872d8fea PC |
1595 | * @return Index of first occurrence. |
1596 | * | |
5b9daa7e BK |
1597 | * Starting from @a __pos, searches forward for one of the characters of |
1598 | * @a __str within this string. If found, returns the index where it was | |
872d8fea PC |
1599 | * found. If not found, returns npos. |
1600 | */ | |
1601 | size_type | |
1602 | find_first_of(const __versa_string& __str, size_type __pos = 0) const | |
1603 | { return this->find_first_of(__str.data(), __pos, __str.size()); } | |
1604 | ||
1605 | /** | |
1606 | * @brief Find position of a character of C substring. | |
5b9daa7e BK |
1607 | * @param __s String containing characters to locate. |
1608 | * @param __pos Index of character to search from. | |
1609 | * @param __n Number of characters from s to search for. | |
872d8fea PC |
1610 | * @return Index of first occurrence. |
1611 | * | |
5b9daa7e BK |
1612 | * Starting from @a __pos, searches forward for one of the |
1613 | * first @a __n characters of @a __s within this string. If | |
1614 | * found, returns the index where it was found. If not found, | |
1615 | * returns npos. | |
872d8fea PC |
1616 | */ |
1617 | size_type | |
1618 | find_first_of(const _CharT* __s, size_type __pos, size_type __n) const; | |
1619 | ||
1620 | /** | |
1621 | * @brief Find position of a character of C string. | |
5b9daa7e BK |
1622 | * @param __s String containing characters to locate. |
1623 | * @param __pos Index of character to search from (default 0). | |
872d8fea PC |
1624 | * @return Index of first occurrence. |
1625 | * | |
5b9daa7e BK |
1626 | * Starting from @a __pos, searches forward for one of the |
1627 | * characters of @a __s within this string. If found, returns | |
1628 | * the index where it was found. If not found, returns npos. | |
872d8fea PC |
1629 | */ |
1630 | size_type | |
1631 | find_first_of(const _CharT* __s, size_type __pos = 0) const | |
1632 | { | |
1633 | __glibcxx_requires_string(__s); | |
1634 | return this->find_first_of(__s, __pos, traits_type::length(__s)); | |
1635 | } | |
1636 | ||
1637 | /** | |
1638 | * @brief Find position of a character. | |
5b9daa7e BK |
1639 | * @param __c Character to locate. |
1640 | * @param __pos Index of character to search from (default 0). | |
872d8fea PC |
1641 | * @return Index of first occurrence. |
1642 | * | |
5b9daa7e BK |
1643 | * Starting from @a __pos, searches forward for the character |
1644 | * @a __c within this string. If found, returns the index | |
1645 | * where it was found. If not found, returns npos. | |
872d8fea PC |
1646 | * |
1647 | * Note: equivalent to find(c, pos). | |
1648 | */ | |
1649 | size_type | |
1650 | find_first_of(_CharT __c, size_type __pos = 0) const | |
1651 | { return this->find(__c, __pos); } | |
1652 | ||
1653 | /** | |
1654 | * @brief Find last position of a character of string. | |
5b9daa7e BK |
1655 | * @param __str String containing characters to locate. |
1656 | * @param __pos Index of character to search back from (default end). | |
872d8fea PC |
1657 | * @return Index of last occurrence. |
1658 | * | |
5b9daa7e BK |
1659 | * Starting from @a __pos, searches backward for one of the |
1660 | * characters of @a __str within this string. If found, | |
1661 | * returns the index where it was found. If not found, returns | |
1662 | * npos. | |
872d8fea PC |
1663 | */ |
1664 | size_type | |
1665 | find_last_of(const __versa_string& __str, size_type __pos = npos) const | |
1666 | { return this->find_last_of(__str.data(), __pos, __str.size()); } | |
1667 | ||
1668 | /** | |
1669 | * @brief Find last position of a character of C substring. | |
5b9daa7e BK |
1670 | * @param __s C string containing characters to locate. |
1671 | * @param __pos Index of character to search back from. | |
1672 | * @param __n Number of characters from s to search for. | |
872d8fea PC |
1673 | * @return Index of last occurrence. |
1674 | * | |
5b9daa7e BK |
1675 | * Starting from @a __pos, searches backward for one of the |
1676 | * first @a __n characters of @a __s within this string. If | |
1677 | * found, returns the index where it was found. If not found, | |
1678 | * returns npos. | |
872d8fea PC |
1679 | */ |
1680 | size_type | |
1681 | find_last_of(const _CharT* __s, size_type __pos, size_type __n) const; | |
1682 | ||
1683 | /** | |
1684 | * @brief Find last position of a character of C string. | |
5b9daa7e BK |
1685 | * @param __s C string containing characters to locate. |
1686 | * @param __pos Index of character to search back from (default end). | |
872d8fea PC |
1687 | * @return Index of last occurrence. |
1688 | * | |
5b9daa7e BK |
1689 | * Starting from @a __pos, searches backward for one of the |
1690 | * characters of @a __s within this string. If found, returns | |
1691 | * the index where it was found. If not found, returns npos. | |
872d8fea PC |
1692 | */ |
1693 | size_type | |
1694 | find_last_of(const _CharT* __s, size_type __pos = npos) const | |
1695 | { | |
1696 | __glibcxx_requires_string(__s); | |
1697 | return this->find_last_of(__s, __pos, traits_type::length(__s)); | |
1698 | } | |
1699 | ||
1700 | /** | |
1701 | * @brief Find last position of a character. | |
5b9daa7e BK |
1702 | * @param __c Character to locate. |
1703 | * @param __pos Index of character to search back from (default end). | |
872d8fea PC |
1704 | * @return Index of last occurrence. |
1705 | * | |
5b9daa7e BK |
1706 | * Starting from @a __pos, searches backward for @a __c within |
1707 | * this string. If found, returns the index where it was | |
1708 | * found. If not found, returns npos. | |
872d8fea PC |
1709 | * |
1710 | * Note: equivalent to rfind(c, pos). | |
1711 | */ | |
1712 | size_type | |
1713 | find_last_of(_CharT __c, size_type __pos = npos) const | |
1714 | { return this->rfind(__c, __pos); } | |
1715 | ||
1716 | /** | |
1717 | * @brief Find position of a character not in string. | |
5b9daa7e BK |
1718 | * @param __str String containing characters to avoid. |
1719 | * @param __pos Index of character to search from (default 0). | |
872d8fea PC |
1720 | * @return Index of first occurrence. |
1721 | * | |
5b9daa7e BK |
1722 | * Starting from @a __pos, searches forward for a character not |
1723 | * contained in @a __str within this string. If found, returns | |
1724 | * the index where it was found. If not found, returns npos. | |
872d8fea PC |
1725 | */ |
1726 | size_type | |
1727 | find_first_not_of(const __versa_string& __str, size_type __pos = 0) const | |
1728 | { return this->find_first_not_of(__str.data(), __pos, __str.size()); } | |
1729 | ||
1730 | /** | |
1731 | * @brief Find position of a character not in C substring. | |
5b9daa7e BK |
1732 | * @param __s C string containing characters to avoid. |
1733 | * @param __pos Index of character to search from. | |
1734 | * @param __n Number of characters from s to consider. | |
872d8fea PC |
1735 | * @return Index of first occurrence. |
1736 | * | |
5b9daa7e BK |
1737 | * Starting from @a __pos, searches forward for a character not |
1738 | * contained in the first @a __n characters of @a __s within | |
1739 | * this string. If found, returns the index where it was | |
1740 | * found. If not found, returns npos. | |
872d8fea PC |
1741 | */ |
1742 | size_type | |
1743 | find_first_not_of(const _CharT* __s, size_type __pos, | |
1744 | size_type __n) const; | |
1745 | ||
1746 | /** | |
1747 | * @brief Find position of a character not in C string. | |
5b9daa7e BK |
1748 | * @param __s C string containing characters to avoid. |
1749 | * @param __pos Index of character to search from (default 0). | |
872d8fea PC |
1750 | * @return Index of first occurrence. |
1751 | * | |
5b9daa7e BK |
1752 | * Starting from @a __pos, searches forward for a character not |
1753 | * contained in @a __s within this string. If found, returns | |
1754 | * the index where it was found. If not found, returns npos. | |
872d8fea PC |
1755 | */ |
1756 | size_type | |
1757 | find_first_not_of(const _CharT* __s, size_type __pos = 0) const | |
1758 | { | |
1759 | __glibcxx_requires_string(__s); | |
1760 | return this->find_first_not_of(__s, __pos, traits_type::length(__s)); | |
1761 | } | |
1762 | ||
1763 | /** | |
1764 | * @brief Find position of a different character. | |
5b9daa7e BK |
1765 | * @param __c Character to avoid. |
1766 | * @param __pos Index of character to search from (default 0). | |
872d8fea PC |
1767 | * @return Index of first occurrence. |
1768 | * | |
5b9daa7e BK |
1769 | * Starting from @a __pos, searches forward for a character |
1770 | * other than @a __c within this string. If found, returns the | |
1771 | * index where it was found. If not found, returns npos. | |
872d8fea PC |
1772 | */ |
1773 | size_type | |
1774 | find_first_not_of(_CharT __c, size_type __pos = 0) const; | |
1775 | ||
1776 | /** | |
1777 | * @brief Find last position of a character not in string. | |
5b9daa7e BK |
1778 | * @param __str String containing characters to avoid. |
1779 | * @param __pos Index of character to search back from (default end). | |
ee5ca789 | 1780 | * @return Index of last occurrence. |
872d8fea | 1781 | * |
5b9daa7e BK |
1782 | * Starting from @a __pos, searches backward for a character |
1783 | * not contained in @a __str within this string. If found, | |
1784 | * returns the index where it was found. If not found, returns | |
1785 | * npos. | |
872d8fea PC |
1786 | */ |
1787 | size_type | |
1788 | find_last_not_of(const __versa_string& __str, | |
1789 | size_type __pos = npos) const | |
1790 | { return this->find_last_not_of(__str.data(), __pos, __str.size()); } | |
1791 | ||
1792 | /** | |
1793 | * @brief Find last position of a character not in C substring. | |
5b9daa7e BK |
1794 | * @param __s C string containing characters to avoid. |
1795 | * @param __pos Index of character to search back from. | |
1796 | * @param __n Number of characters from s to consider. | |
ee5ca789 | 1797 | * @return Index of last occurrence. |
872d8fea | 1798 | * |
5b9daa7e BK |
1799 | * Starting from @a __pos, searches backward for a character |
1800 | * not contained in the first @a __n characters of @a __s | |
1801 | * within this string. If found, returns the index where it | |
1802 | * was found. If not found, returns npos. | |
872d8fea PC |
1803 | */ |
1804 | size_type | |
1805 | find_last_not_of(const _CharT* __s, size_type __pos, | |
1806 | size_type __n) const; | |
1807 | /** | |
ee5ca789 | 1808 | * @brief Find last position of a character not in C string. |
5b9daa7e BK |
1809 | * @param __s C string containing characters to avoid. |
1810 | * @param __pos Index of character to search back from (default end). | |
ee5ca789 | 1811 | * @return Index of last occurrence. |
872d8fea | 1812 | * |
5b9daa7e BK |
1813 | * Starting from @a __pos, searches backward for a character |
1814 | * not contained in @a __s within this string. If found, | |
1815 | * returns the index where it was found. If not found, returns | |
1816 | * npos. | |
872d8fea PC |
1817 | */ |
1818 | size_type | |
1819 | find_last_not_of(const _CharT* __s, size_type __pos = npos) const | |
1820 | { | |
1821 | __glibcxx_requires_string(__s); | |
1822 | return this->find_last_not_of(__s, __pos, traits_type::length(__s)); | |
1823 | } | |
1824 | ||
1825 | /** | |
1826 | * @brief Find last position of a different character. | |
5b9daa7e BK |
1827 | * @param __c Character to avoid. |
1828 | * @param __pos Index of character to search back from (default end). | |
ee5ca789 | 1829 | * @return Index of last occurrence. |
872d8fea | 1830 | * |
5b9daa7e BK |
1831 | * Starting from @a __pos, searches backward for a character |
1832 | * other than @a __c within this string. If found, returns the | |
1833 | * index where it was found. If not found, returns npos. | |
872d8fea PC |
1834 | */ |
1835 | size_type | |
1836 | find_last_not_of(_CharT __c, size_type __pos = npos) const; | |
1837 | ||
1838 | /** | |
1839 | * @brief Get a substring. | |
5b9daa7e BK |
1840 | * @param __pos Index of first character (default 0). |
1841 | * @param __n Number of characters in substring (default remainder). | |
872d8fea PC |
1842 | * @return The new string. |
1843 | * @throw std::out_of_range If pos > size(). | |
1844 | * | |
5b9daa7e BK |
1845 | * Construct and return a new string using the @a __n |
1846 | * characters starting at @a __pos. If the string is too | |
1847 | * short, use the remainder of the characters. If @a __pos is | |
1848 | * beyond the end of the string, out_of_range is thrown. | |
872d8fea PC |
1849 | */ |
1850 | __versa_string | |
1851 | substr(size_type __pos = 0, size_type __n = npos) const | |
1852 | { | |
1853 | return __versa_string(*this, _M_check(__pos, "__versa_string::substr"), | |
1854 | __n); | |
1855 | } | |
1856 | ||
1857 | /** | |
1858 | * @brief Compare to a string. | |
5b9daa7e | 1859 | * @param __str String to compare against. |
872d8fea PC |
1860 | * @return Integer < 0, 0, or > 0. |
1861 | * | |
5b9daa7e BK |
1862 | * Returns an integer < 0 if this string is ordered before @a |
1863 | * __str, 0 if their values are equivalent, or > 0 if this | |
1864 | * string is ordered after @a __str. Determines the effective | |
1865 | * length rlen of the strings to compare as the smallest of | |
1866 | * size() and str.size(). The function then compares the two | |
1867 | * strings by calling traits::compare(data(), str.data(),rlen). | |
1868 | * If the result of the comparison is nonzero returns it, | |
1869 | * otherwise the shorter one is ordered first. | |
872d8fea PC |
1870 | */ |
1871 | int | |
1872 | compare(const __versa_string& __str) const | |
1873 | { | |
b6105bf2 PC |
1874 | if (this->_M_compare(__str)) |
1875 | return 0; | |
1876 | ||
872d8fea PC |
1877 | const size_type __size = this->size(); |
1878 | const size_type __osize = __str.size(); | |
1879 | const size_type __len = std::min(__size, __osize); | |
1880 | ||
1881 | int __r = traits_type::compare(this->_M_data(), __str.data(), __len); | |
1882 | if (!__r) | |
9521dd6b | 1883 | __r = _S_compare(__size, __osize); |
872d8fea PC |
1884 | return __r; |
1885 | } | |
1886 | ||
1887 | /** | |
1888 | * @brief Compare substring to a string. | |
5b9daa7e BK |
1889 | * @param __pos Index of first character of substring. |
1890 | * @param __n Number of characters in substring. | |
1891 | * @param __str String to compare against. | |
872d8fea PC |
1892 | * @return Integer < 0, 0, or > 0. |
1893 | * | |
5b9daa7e BK |
1894 | * Form the substring of this string from the @a __n characters |
1895 | * starting at @a __pos. Returns an integer < 0 if the | |
1896 | * substring is ordered before @a __str, 0 if their values are | |
1897 | * equivalent, or > 0 if the substring is ordered after @a | |
1898 | * __str. Determines the effective length rlen of the strings | |
1899 | * to compare as the smallest of the length of the substring | |
1900 | * and @a __str.size(). The function then compares the two | |
1901 | * strings by calling | |
1902 | * traits::compare(substring.data(),str.data(),rlen). If the | |
1903 | * result of the comparison is nonzero returns it, otherwise | |
1904 | * the shorter one is ordered first. | |
872d8fea PC |
1905 | */ |
1906 | int | |
1907 | compare(size_type __pos, size_type __n, | |
1908 | const __versa_string& __str) const; | |
1909 | ||
1910 | /** | |
1911 | * @brief Compare substring to a substring. | |
5b9daa7e BK |
1912 | * @param __pos1 Index of first character of substring. |
1913 | * @param __n1 Number of characters in substring. | |
1914 | * @param __str String to compare against. | |
1915 | * @param __pos2 Index of first character of substring of str. | |
1916 | * @param __n2 Number of characters in substring of str. | |
872d8fea PC |
1917 | * @return Integer < 0, 0, or > 0. |
1918 | * | |
5b9daa7e BK |
1919 | * Form the substring of this string from the @a __n1 |
1920 | * characters starting at @a __pos1. Form the substring of @a | |
1921 | * __str from the @a __n2 characters starting at @a __pos2. | |
1922 | * Returns an integer < 0 if this substring is ordered before | |
1923 | * the substring of @a __str, 0 if their values are equivalent, | |
1924 | * or > 0 if this substring is ordered after the substring of | |
1925 | * @a __str. Determines the effective length rlen of the | |
1926 | * strings to compare as the smallest of the lengths of the | |
1927 | * substrings. The function then compares the two strings by | |
1928 | * calling | |
872d8fea | 1929 | * traits::compare(substring.data(),str.substr(pos2,n2).data(),rlen). |
5b9daa7e BK |
1930 | * If the result of the comparison is nonzero returns it, |
1931 | * otherwise the shorter one is ordered first. | |
872d8fea PC |
1932 | */ |
1933 | int | |
1934 | compare(size_type __pos1, size_type __n1, const __versa_string& __str, | |
1935 | size_type __pos2, size_type __n2) const; | |
1936 | ||
1937 | /** | |
1938 | * @brief Compare to a C string. | |
5b9daa7e | 1939 | * @param __s C string to compare against. |
872d8fea PC |
1940 | * @return Integer < 0, 0, or > 0. |
1941 | * | |
5b9daa7e BK |
1942 | * Returns an integer < 0 if this string is ordered before @a |
1943 | * __s, 0 if their values are equivalent, or > 0 if this string | |
1944 | * is ordered after @a __s. Determines the effective length | |
1945 | * rlen of the strings to compare as the smallest of size() and | |
1946 | * the length of a string constructed from @a __s. The | |
1947 | * function then compares the two strings by calling | |
1948 | * traits::compare(data(),s,rlen). If the result of the | |
1949 | * comparison is nonzero returns it, otherwise the shorter one | |
1950 | * is ordered first. | |
872d8fea PC |
1951 | */ |
1952 | int | |
1953 | compare(const _CharT* __s) const; | |
1954 | ||
1955 | // _GLIBCXX_RESOLVE_LIB_DEFECTS | |
1956 | // 5 String::compare specification questionable | |
1957 | /** | |
1958 | * @brief Compare substring to a C string. | |
5b9daa7e BK |
1959 | * @param __pos Index of first character of substring. |
1960 | * @param __n1 Number of characters in substring. | |
1961 | * @param __s C string to compare against. | |
872d8fea PC |
1962 | * @return Integer < 0, 0, or > 0. |
1963 | * | |
5b9daa7e BK |
1964 | * Form the substring of this string from the @a __n1 |
1965 | * characters starting at @a __pos. Returns an integer < 0 if | |
1966 | * the substring is ordered before @a __s, 0 if their values | |
1967 | * are equivalent, or > 0 if the substring is ordered after @a | |
1968 | * __s. Determines the effective length rlen of the strings to | |
1969 | * compare as the smallest of the length of the substring and | |
1970 | * the length of a string constructed from @a __s. The | |
872d8fea | 1971 | * function then compares the two string by calling |
5b9daa7e BK |
1972 | * traits::compare(substring.data(),s,rlen). If the result of |
1973 | * the comparison is nonzero returns it, otherwise the shorter | |
1974 | * one is ordered first. | |
872d8fea PC |
1975 | */ |
1976 | int | |
1977 | compare(size_type __pos, size_type __n1, const _CharT* __s) const; | |
1978 | ||
1979 | /** | |
1980 | * @brief Compare substring against a character array. | |
5b9daa7e BK |
1981 | * @param __pos1 Index of first character of substring. |
1982 | * @param __n1 Number of characters in substring. | |
1983 | * @param __s character array to compare against. | |
1984 | * @param __n2 Number of characters of s. | |
872d8fea PC |
1985 | * @return Integer < 0, 0, or > 0. |
1986 | * | |
5b9daa7e BK |
1987 | * Form the substring of this string from the @a __n1 |
1988 | * characters starting at @a __pos1. Form a string from the | |
1989 | * first @a __n2 characters of @a __s. Returns an integer < 0 | |
1990 | * if this substring is ordered before the string from @a __s, | |
1991 | * 0 if their values are equivalent, or > 0 if this substring | |
1992 | * is ordered after the string from @a __s. Determines the | |
1993 | * effective length rlen of the strings to compare as the | |
1994 | * smallest of the length of the substring and @a __n2. The | |
1995 | * function then compares the two strings by calling | |
1996 | * traits::compare(substring.data(),s,rlen). If the result of | |
1997 | * the comparison is nonzero returns it, otherwise the shorter | |
872d8fea PC |
1998 | * one is ordered first. |
1999 | * | |
5df9ac4b | 2000 | * NB: s must have at least n2 characters, '\\0' has no special |
872d8fea PC |
2001 | * meaning. |
2002 | */ | |
2003 | int | |
2004 | compare(size_type __pos, size_type __n1, const _CharT* __s, | |
2005 | size_type __n2) const; | |
2006 | }; | |
2007 | ||
2008 | // operator+ | |
2009 | /** | |
2010 | * @brief Concatenate two strings. | |
5b9daa7e BK |
2011 | * @param __lhs First string. |
2012 | * @param __rhs Last string. | |
2013 | * @return New string with value of @a __lhs followed by @a __rhs. | |
872d8fea PC |
2014 | */ |
2015 | template<typename _CharT, typename _Traits, typename _Alloc, | |
2016 | template <typename, typename, typename> class _Base> | |
2017 | __versa_string<_CharT, _Traits, _Alloc, _Base> | |
2018 | operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, | |
cf882919 | 2019 | const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs); |
872d8fea PC |
2020 | |
2021 | /** | |
2022 | * @brief Concatenate C string and string. | |
5b9daa7e BK |
2023 | * @param __lhs First string. |
2024 | * @param __rhs Last string. | |
2025 | * @return New string with value of @a __lhs followed by @a __rhs. | |
872d8fea PC |
2026 | */ |
2027 | template<typename _CharT, typename _Traits, typename _Alloc, | |
2028 | template <typename, typename, typename> class _Base> | |
2029 | __versa_string<_CharT, _Traits, _Alloc, _Base> | |
2030 | operator+(const _CharT* __lhs, | |
2031 | const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs); | |
2032 | ||
2033 | /** | |
2034 | * @brief Concatenate character and string. | |
5b9daa7e BK |
2035 | * @param __lhs First string. |
2036 | * @param __rhs Last string. | |
2037 | * @return New string with @a __lhs followed by @a __rhs. | |
872d8fea PC |
2038 | */ |
2039 | template<typename _CharT, typename _Traits, typename _Alloc, | |
2040 | template <typename, typename, typename> class _Base> | |
2041 | __versa_string<_CharT, _Traits, _Alloc, _Base> | |
2042 | operator+(_CharT __lhs, | |
2043 | const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs); | |
2044 | ||
2045 | /** | |
2046 | * @brief Concatenate string and C string. | |
5b9daa7e BK |
2047 | * @param __lhs First string. |
2048 | * @param __rhs Last string. | |
2049 | * @return New string with @a __lhs followed by @a __rhs. | |
872d8fea PC |
2050 | */ |
2051 | template<typename _CharT, typename _Traits, typename _Alloc, | |
2052 | template <typename, typename, typename> class _Base> | |
cf882919 | 2053 | __versa_string<_CharT, _Traits, _Alloc, _Base> |
872d8fea | 2054 | operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, |
cf882919 | 2055 | const _CharT* __rhs); |
872d8fea PC |
2056 | |
2057 | /** | |
2058 | * @brief Concatenate string and character. | |
5b9daa7e BK |
2059 | * @param __lhs First string. |
2060 | * @param __rhs Last string. | |
2061 | * @return New string with @a __lhs followed by @a __rhs. | |
872d8fea PC |
2062 | */ |
2063 | template<typename _CharT, typename _Traits, typename _Alloc, | |
2064 | template <typename, typename, typename> class _Base> | |
cf882919 | 2065 | __versa_string<_CharT, _Traits, _Alloc, _Base> |
872d8fea | 2066 | operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, |
cf882919 | 2067 | _CharT __rhs); |
872d8fea PC |
2068 | |
2069 | // operator == | |
2070 | /** | |
2071 | * @brief Test equivalence of two strings. | |
5b9daa7e BK |
2072 | * @param __lhs First string. |
2073 | * @param __rhs Second string. | |
2074 | * @return True if @a __lhs.compare(@a __rhs) == 0. False otherwise. | |
872d8fea PC |
2075 | */ |
2076 | template<typename _CharT, typename _Traits, typename _Alloc, | |
2077 | template <typename, typename, typename> class _Base> | |
2078 | inline bool | |
2079 | operator==(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, | |
2080 | const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) | |
2081 | { return __lhs.compare(__rhs) == 0; } | |
2082 | ||
bd12160a PC |
2083 | template<typename _CharT, |
2084 | template <typename, typename, typename> class _Base> | |
2085 | inline typename __enable_if<std::__is_char<_CharT>::__value, bool>::__type | |
2086 | operator==(const __versa_string<_CharT, std::char_traits<_CharT>, | |
2087 | std::allocator<_CharT>, _Base>& __lhs, | |
2088 | const __versa_string<_CharT, std::char_traits<_CharT>, | |
2089 | std::allocator<_CharT>, _Base>& __rhs) | |
2090 | { return (__lhs.size() == __rhs.size() | |
2091 | && !std::char_traits<_CharT>::compare(__lhs.data(), __rhs.data(), | |
2092 | __lhs.size())); } | |
2093 | ||
872d8fea PC |
2094 | /** |
2095 | * @brief Test equivalence of C string and string. | |
5b9daa7e BK |
2096 | * @param __lhs C string. |
2097 | * @param __rhs String. | |
2098 | * @return True if @a __rhs.compare(@a __lhs) == 0. False otherwise. | |
872d8fea PC |
2099 | */ |
2100 | template<typename _CharT, typename _Traits, typename _Alloc, | |
2101 | template <typename, typename, typename> class _Base> | |
2102 | inline bool | |
2103 | operator==(const _CharT* __lhs, | |
2104 | const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) | |
2105 | { return __rhs.compare(__lhs) == 0; } | |
2106 | ||
2107 | /** | |
2108 | * @brief Test equivalence of string and C string. | |
5b9daa7e BK |
2109 | * @param __lhs String. |
2110 | * @param __rhs C string. | |
2111 | * @return True if @a __lhs.compare(@a __rhs) == 0. False otherwise. | |
872d8fea PC |
2112 | */ |
2113 | template<typename _CharT, typename _Traits, typename _Alloc, | |
2114 | template <typename, typename, typename> class _Base> | |
2115 | inline bool | |
2116 | operator==(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, | |
2117 | const _CharT* __rhs) | |
2118 | { return __lhs.compare(__rhs) == 0; } | |
2119 | ||
2120 | // operator != | |
2121 | /** | |
2122 | * @brief Test difference of two strings. | |
5b9daa7e BK |
2123 | * @param __lhs First string. |
2124 | * @param __rhs Second string. | |
2125 | * @return True if @a __lhs.compare(@a __rhs) != 0. False otherwise. | |
872d8fea PC |
2126 | */ |
2127 | template<typename _CharT, typename _Traits, typename _Alloc, | |
2128 | template <typename, typename, typename> class _Base> | |
2129 | inline bool | |
2130 | operator!=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, | |
2131 | const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) | |
bd12160a | 2132 | { return !(__lhs == __rhs); } |
872d8fea PC |
2133 | |
2134 | /** | |
2135 | * @brief Test difference of C string and string. | |
5b9daa7e BK |
2136 | * @param __lhs C string. |
2137 | * @param __rhs String. | |
2138 | * @return True if @a __rhs.compare(@a __lhs) != 0. False otherwise. | |
872d8fea PC |
2139 | */ |
2140 | template<typename _CharT, typename _Traits, typename _Alloc, | |
2141 | template <typename, typename, typename> class _Base> | |
2142 | inline bool | |
2143 | operator!=(const _CharT* __lhs, | |
2144 | const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) | |
bd12160a | 2145 | { return !(__lhs == __rhs); } |
872d8fea PC |
2146 | |
2147 | /** | |
2148 | * @brief Test difference of string and C string. | |
5b9daa7e BK |
2149 | * @param __lhs String. |
2150 | * @param __rhs C string. | |
2151 | * @return True if @a __lhs.compare(@a __rhs) != 0. False otherwise. | |
872d8fea PC |
2152 | */ |
2153 | template<typename _CharT, typename _Traits, typename _Alloc, | |
2154 | template <typename, typename, typename> class _Base> | |
2155 | inline bool | |
2156 | operator!=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, | |
2157 | const _CharT* __rhs) | |
bd12160a | 2158 | { return !(__lhs == __rhs); } |
872d8fea PC |
2159 | |
2160 | // operator < | |
2161 | /** | |
2162 | * @brief Test if string precedes string. | |
5b9daa7e BK |
2163 | * @param __lhs First string. |
2164 | * @param __rhs Second string. | |
2165 | * @return True if @a __lhs precedes @a __rhs. False otherwise. | |
872d8fea PC |
2166 | */ |
2167 | template<typename _CharT, typename _Traits, typename _Alloc, | |
2168 | template <typename, typename, typename> class _Base> | |
2169 | inline bool | |
2170 | operator<(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, | |
2171 | const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) | |
2172 | { return __lhs.compare(__rhs) < 0; } | |
2173 | ||
2174 | /** | |
2175 | * @brief Test if string precedes C string. | |
5b9daa7e BK |
2176 | * @param __lhs String. |
2177 | * @param __rhs C string. | |
2178 | * @return True if @a __lhs precedes @a __rhs. False otherwise. | |
872d8fea PC |
2179 | */ |
2180 | template<typename _CharT, typename _Traits, typename _Alloc, | |
2181 | template <typename, typename, typename> class _Base> | |
2182 | inline bool | |
2183 | operator<(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, | |
2184 | const _CharT* __rhs) | |
2185 | { return __lhs.compare(__rhs) < 0; } | |
2186 | ||
2187 | /** | |
2188 | * @brief Test if C string precedes string. | |
5b9daa7e BK |
2189 | * @param __lhs C string. |
2190 | * @param __rhs String. | |
2191 | * @return True if @a __lhs precedes @a __rhs. False otherwise. | |
872d8fea PC |
2192 | */ |
2193 | template<typename _CharT, typename _Traits, typename _Alloc, | |
2194 | template <typename, typename, typename> class _Base> | |
2195 | inline bool | |
2196 | operator<(const _CharT* __lhs, | |
2197 | const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) | |
2198 | { return __rhs.compare(__lhs) > 0; } | |
2199 | ||
2200 | // operator > | |
2201 | /** | |
2202 | * @brief Test if string follows string. | |
5b9daa7e BK |
2203 | * @param __lhs First string. |
2204 | * @param __rhs Second string. | |
2205 | * @return True if @a __lhs follows @a __rhs. False otherwise. | |
872d8fea PC |
2206 | */ |
2207 | template<typename _CharT, typename _Traits, typename _Alloc, | |
2208 | template <typename, typename, typename> class _Base> | |
2209 | inline bool | |
2210 | operator>(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, | |
2211 | const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) | |
2212 | { return __lhs.compare(__rhs) > 0; } | |
2213 | ||
2214 | /** | |
2215 | * @brief Test if string follows C string. | |
5b9daa7e BK |
2216 | * @param __lhs String. |
2217 | * @param __rhs C string. | |
2218 | * @return True if @a __lhs follows @a __rhs. False otherwise. | |
872d8fea PC |
2219 | */ |
2220 | template<typename _CharT, typename _Traits, typename _Alloc, | |
2221 | template <typename, typename, typename> class _Base> | |
2222 | inline bool | |
2223 | operator>(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, | |
2224 | const _CharT* __rhs) | |
2225 | { return __lhs.compare(__rhs) > 0; } | |
2226 | ||
2227 | /** | |
2228 | * @brief Test if C string follows string. | |
5b9daa7e BK |
2229 | * @param __lhs C string. |
2230 | * @param __rhs String. | |
2231 | * @return True if @a __lhs follows @a __rhs. False otherwise. | |
872d8fea PC |
2232 | */ |
2233 | template<typename _CharT, typename _Traits, typename _Alloc, | |
2234 | template <typename, typename, typename> class _Base> | |
2235 | inline bool | |
2236 | operator>(const _CharT* __lhs, | |
2237 | const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) | |
2238 | { return __rhs.compare(__lhs) < 0; } | |
2239 | ||
2240 | // operator <= | |
2241 | /** | |
2242 | * @brief Test if string doesn't follow string. | |
5b9daa7e BK |
2243 | * @param __lhs First string. |
2244 | * @param __rhs Second string. | |
2245 | * @return True if @a __lhs doesn't follow @a __rhs. False otherwise. | |
872d8fea PC |
2246 | */ |
2247 | template<typename _CharT, typename _Traits, typename _Alloc, | |
2248 | template <typename, typename, typename> class _Base> | |
2249 | inline bool | |
2250 | operator<=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, | |
2251 | const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) | |
2252 | { return __lhs.compare(__rhs) <= 0; } | |
2253 | ||
2254 | /** | |
2255 | * @brief Test if string doesn't follow C string. | |
5b9daa7e BK |
2256 | * @param __lhs String. |
2257 | * @param __rhs C string. | |
2258 | * @return True if @a __lhs doesn't follow @a __rhs. False otherwise. | |
872d8fea PC |
2259 | */ |
2260 | template<typename _CharT, typename _Traits, typename _Alloc, | |
2261 | template <typename, typename, typename> class _Base> | |
2262 | inline bool | |
2263 | operator<=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, | |
2264 | const _CharT* __rhs) | |
2265 | { return __lhs.compare(__rhs) <= 0; } | |
2266 | ||
2267 | /** | |
2268 | * @brief Test if C string doesn't follow string. | |
5b9daa7e BK |
2269 | * @param __lhs C string. |
2270 | * @param __rhs String. | |
2271 | * @return True if @a __lhs doesn't follow @a __rhs. False otherwise. | |
872d8fea PC |
2272 | */ |
2273 | template<typename _CharT, typename _Traits, typename _Alloc, | |
2274 | template <typename, typename, typename> class _Base> | |
2275 | inline bool | |
2276 | operator<=(const _CharT* __lhs, | |
2277 | const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) | |
2278 | { return __rhs.compare(__lhs) >= 0; } | |
2279 | ||
2280 | // operator >= | |
2281 | /** | |
2282 | * @brief Test if string doesn't precede string. | |
5b9daa7e BK |
2283 | * @param __lhs First string. |
2284 | * @param __rhs Second string. | |
2285 | * @return True if @a __lhs doesn't precede @a __rhs. False otherwise. | |
872d8fea PC |
2286 | */ |
2287 | template<typename _CharT, typename _Traits, typename _Alloc, | |
2288 | template <typename, typename, typename> class _Base> | |
2289 | inline bool | |
2290 | operator>=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, | |
2291 | const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) | |
2292 | { return __lhs.compare(__rhs) >= 0; } | |
2293 | ||
2294 | /** | |
2295 | * @brief Test if string doesn't precede C string. | |
5b9daa7e BK |
2296 | * @param __lhs String. |
2297 | * @param __rhs C string. | |
2298 | * @return True if @a __lhs doesn't precede @a __rhs. False otherwise. | |
872d8fea PC |
2299 | */ |
2300 | template<typename _CharT, typename _Traits, typename _Alloc, | |
2301 | template <typename, typename, typename> class _Base> | |
2302 | inline bool | |
2303 | operator>=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, | |
2304 | const _CharT* __rhs) | |
2305 | { return __lhs.compare(__rhs) >= 0; } | |
2306 | ||
2307 | /** | |
2308 | * @brief Test if C string doesn't precede string. | |
5b9daa7e BK |
2309 | * @param __lhs C string. |
2310 | * @param __rhs String. | |
2311 | * @return True if @a __lhs doesn't precede @a __rhs. False otherwise. | |
872d8fea PC |
2312 | */ |
2313 | template<typename _CharT, typename _Traits, typename _Alloc, | |
2314 | template <typename, typename, typename> class _Base> | |
2315 | inline bool | |
2316 | operator>=(const _CharT* __lhs, | |
2317 | const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) | |
2318 | { return __rhs.compare(__lhs) <= 0; } | |
2319 | ||
2320 | /** | |
2321 | * @brief Swap contents of two strings. | |
5b9daa7e BK |
2322 | * @param __lhs First string. |
2323 | * @param __rhs Second string. | |
872d8fea | 2324 | * |
5b9daa7e | 2325 | * Exchanges the contents of @a __lhs and @a __rhs in constant time. |
872d8fea PC |
2326 | */ |
2327 | template<typename _CharT, typename _Traits, typename _Alloc, | |
2328 | template <typename, typename, typename> class _Base> | |
2329 | inline void | |
2330 | swap(__versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, | |
2331 | __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) | |
2332 | { __lhs.swap(__rhs); } | |
2333 | ||
3cbc7af0 BK |
2334 | _GLIBCXX_END_NAMESPACE |
2335 | ||
2336 | _GLIBCXX_BEGIN_NAMESPACE(std) | |
872d8fea | 2337 | |
872d8fea PC |
2338 | /** |
2339 | * @brief Read stream into a string. | |
5b9daa7e BK |
2340 | * @param __is Input stream. |
2341 | * @param __str Buffer to store into. | |
872d8fea PC |
2342 | * @return Reference to the input stream. |
2343 | * | |
5b9daa7e BK |
2344 | * Stores characters from @a __is into @a __str until whitespace is |
2345 | * found, the end of the stream is encountered, or str.max_size() | |
2346 | * is reached. If is.width() is non-zero, that is the limit on the | |
2347 | * number of characters stored into @a __str. Any previous | |
2348 | * contents of @a __str are erased. | |
872d8fea PC |
2349 | */ |
2350 | template<typename _CharT, typename _Traits, typename _Alloc, | |
2351 | template <typename, typename, typename> class _Base> | |
2352 | basic_istream<_CharT, _Traits>& | |
2353 | operator>>(basic_istream<_CharT, _Traits>& __is, | |
2354 | __gnu_cxx::__versa_string<_CharT, _Traits, | |
2355 | _Alloc, _Base>& __str); | |
2356 | ||
2357 | /** | |
2358 | * @brief Write string to a stream. | |
5b9daa7e BK |
2359 | * @param __os Output stream. |
2360 | * @param __str String to write out. | |
872d8fea PC |
2361 | * @return Reference to the output stream. |
2362 | * | |
5b9daa7e | 2363 | * Output characters of @a __str into os following the same rules as for |
872d8fea PC |
2364 | * writing a C string. |
2365 | */ | |
2366 | template<typename _CharT, typename _Traits, typename _Alloc, | |
11202768 PC |
2367 | template <typename, typename, typename> class _Base> |
2368 | inline basic_ostream<_CharT, _Traits>& | |
872d8fea | 2369 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
11202768 PC |
2370 | const __gnu_cxx::__versa_string<_CharT, _Traits, _Alloc, |
2371 | _Base>& __str) | |
2372 | { | |
2373 | // _GLIBCXX_RESOLVE_LIB_DEFECTS | |
2374 | // 586. string inserter not a formatted function | |
2375 | return __ostream_insert(__os, __str.data(), __str.size()); | |
2376 | } | |
872d8fea PC |
2377 | |
2378 | /** | |
2379 | * @brief Read a line from stream into a string. | |
5b9daa7e BK |
2380 | * @param __is Input stream. |
2381 | * @param __str Buffer to store into. | |
2382 | * @param __delim Character marking end of line. | |
872d8fea PC |
2383 | * @return Reference to the input stream. |
2384 | * | |
5b9daa7e BK |
2385 | * Stores characters from @a __is into @a __str until @a __delim is |
2386 | * found, the end of the stream is encountered, or str.max_size() | |
2387 | * is reached. If is.width() is non-zero, that is the limit on the | |
2388 | * number of characters stored into @a __str. Any previous | |
2389 | * contents of @a __str are erased. If @a delim was encountered, | |
2390 | * it is extracted but not stored into @a __str. | |
872d8fea PC |
2391 | */ |
2392 | template<typename _CharT, typename _Traits, typename _Alloc, | |
2393 | template <typename, typename, typename> class _Base> | |
2394 | basic_istream<_CharT, _Traits>& | |
2395 | getline(basic_istream<_CharT, _Traits>& __is, | |
2396 | __gnu_cxx::__versa_string<_CharT, _Traits, _Alloc, _Base>& __str, | |
2397 | _CharT __delim); | |
2398 | ||
2399 | /** | |
2400 | * @brief Read a line from stream into a string. | |
5b9daa7e BK |
2401 | * @param __is Input stream. |
2402 | * @param __str Buffer to store into. | |
872d8fea PC |
2403 | * @return Reference to the input stream. |
2404 | * | |
5b9daa7e BK |
2405 | * Stores characters from is into @a __str until '\n' is found, the |
2406 | * end of the stream is encountered, or str.max_size() is reached. | |
2407 | * If is.width() is non-zero, that is the limit on the number of | |
2408 | * characters stored into @a __str. Any previous contents of @a | |
2409 | * __str are erased. If end of line was encountered, it is | |
2410 | * extracted but not stored into @a __str. | |
872d8fea PC |
2411 | */ |
2412 | template<typename _CharT, typename _Traits, typename _Alloc, | |
2413 | template <typename, typename, typename> class _Base> | |
2414 | inline basic_istream<_CharT, _Traits>& | |
2415 | getline(basic_istream<_CharT, _Traits>& __is, | |
2416 | __gnu_cxx::__versa_string<_CharT, _Traits, _Alloc, _Base>& __str) | |
2417 | { return getline(__is, __str, __is.widen('\n')); } | |
2418 | ||
3cbc7af0 | 2419 | _GLIBCXX_END_NAMESPACE |
872d8fea | 2420 | |
a5a6b586 PC |
2421 | #if (defined(__GXX_EXPERIMENTAL_CXX0X__) && defined(_GLIBCXX_USE_C99)) |
2422 | ||
2423 | #include <ext/string_conversions.h> | |
2424 | ||
2425 | _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) | |
2426 | ||
2427 | // 21.4 Numeric Conversions [string.conversions]. | |
2428 | inline int | |
2429 | stoi(const __vstring& __str, std::size_t* __idx = 0, int __base = 10) | |
2430 | { return __gnu_cxx::__stoa<long, int>(&std::strtol, "stoi", __str.c_str(), | |
2431 | __idx, __base); } | |
2432 | ||
2433 | inline long | |
2434 | stol(const __vstring& __str, std::size_t* __idx = 0, int __base = 10) | |
2435 | { return __gnu_cxx::__stoa(&std::strtol, "stol", __str.c_str(), | |
2436 | __idx, __base); } | |
2437 | ||
2438 | inline unsigned long | |
2439 | stoul(const __vstring& __str, std::size_t* __idx = 0, int __base = 10) | |
2440 | { return __gnu_cxx::__stoa(&std::strtoul, "stoul", __str.c_str(), | |
2441 | __idx, __base); } | |
2442 | ||
2443 | inline long long | |
2444 | stoll(const __vstring& __str, std::size_t* __idx = 0, int __base = 10) | |
2445 | { return __gnu_cxx::__stoa(&std::strtoll, "stoll", __str.c_str(), | |
2446 | __idx, __base); } | |
2447 | ||
2448 | inline unsigned long long | |
2449 | stoull(const __vstring& __str, std::size_t* __idx, int __base = 10) | |
2450 | { return __gnu_cxx::__stoa(&std::strtoull, "stoull", __str.c_str(), | |
2451 | __idx, __base); } | |
2452 | ||
2453 | // NB: strtof vs strtod. | |
2454 | inline float | |
2455 | stof(const __vstring& __str, std::size_t* __idx = 0) | |
2456 | { return __gnu_cxx::__stoa(&std::strtof, "stof", __str.c_str(), __idx); } | |
2457 | ||
2458 | inline double | |
2459 | stod(const __vstring& __str, std::size_t* __idx = 0) | |
2460 | { return __gnu_cxx::__stoa(&std::strtod, "stod", __str.c_str(), __idx); } | |
2461 | ||
2462 | inline long double | |
2463 | stold(const __vstring& __str, std::size_t* __idx = 0) | |
2464 | { return __gnu_cxx::__stoa(&std::strtold, "stold", __str.c_str(), __idx); } | |
2465 | ||
2466 | // NB: (v)snprintf vs sprintf. | |
2467 | inline __vstring | |
2468 | to_string(long long __val) | |
2469 | { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, | |
2470 | 4 * sizeof(long long), | |
2471 | "%lld", __val); } | |
2472 | ||
2473 | inline __vstring | |
2474 | to_string(unsigned long long __val) | |
2475 | { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, | |
2476 | 4 * sizeof(unsigned long long), | |
2477 | "%llu", __val); } | |
2478 | ||
2479 | inline __vstring | |
2480 | to_string(long double __val) | |
2481 | { | |
2482 | const int __n = __numeric_traits<long double>::__max_exponent10 + 20; | |
2483 | return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, __n, | |
2484 | "%Lf", __val); | |
2485 | } | |
2486 | ||
2487 | #ifdef _GLIBCXX_USE_WCHAR_T | |
2488 | inline int | |
2489 | stoi(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10) | |
2490 | { return __gnu_cxx::__stoa<long, int>(&std::wcstol, "stoi", __str.c_str(), | |
2491 | __idx, __base); } | |
2492 | ||
2493 | inline long | |
2494 | stol(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10) | |
2495 | { return __gnu_cxx::__stoa(&std::wcstol, "stol", __str.c_str(), | |
2496 | __idx, __base); } | |
2497 | ||
2498 | inline unsigned long | |
2499 | stoul(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10) | |
2500 | { return __gnu_cxx::__stoa(&std::wcstoul, "stoul", __str.c_str(), | |
2501 | __idx, __base); } | |
2502 | ||
2503 | inline long long | |
2504 | stoll(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10) | |
2505 | { return __gnu_cxx::__stoa(&std::wcstoll, "stoll", __str.c_str(), | |
2506 | __idx, __base); } | |
2507 | ||
2508 | inline unsigned long long | |
2509 | stoull(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10) | |
2510 | { return __gnu_cxx::__stoa(&std::wcstoull, "stoull", __str.c_str(), | |
2511 | __idx, __base); } | |
2512 | ||
2513 | // NB: wcstof vs wcstod. | |
2514 | inline float | |
2515 | stof(const __wvstring& __str, std::size_t* __idx = 0) | |
2516 | { return __gnu_cxx::__stoa(&std::wcstof, "stof", __str.c_str(), __idx); } | |
2517 | ||
2518 | inline double | |
2519 | stod(const __wvstring& __str, std::size_t* __idx = 0) | |
2520 | { return __gnu_cxx::__stoa(&std::wcstod, "stod", __str.c_str(), __idx); } | |
2521 | ||
2522 | inline long double | |
2523 | stold(const __wvstring& __str, std::size_t* __idx = 0) | |
2524 | { return __gnu_cxx::__stoa(&std::wcstold, "stold", __str.c_str(), __idx); } | |
2525 | ||
2526 | inline __wvstring | |
2527 | to_wstring(long long __val) | |
2528 | { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, | |
2529 | 4 * sizeof(long long), | |
2530 | L"%lld", __val); } | |
2531 | ||
2532 | inline __wvstring | |
2533 | to_wstring(unsigned long long __val) | |
2534 | { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, | |
2535 | 4 * sizeof(unsigned long long), | |
2536 | L"%llu", __val); } | |
2537 | ||
2538 | inline __wvstring | |
2539 | to_wstring(long double __val) | |
2540 | { | |
2541 | const int __n = __numeric_traits<long double>::__max_exponent10 + 20; | |
2542 | return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, __n, | |
2543 | L"%Lf", __val); | |
2544 | } | |
2545 | #endif | |
2546 | ||
2547 | _GLIBCXX_END_NAMESPACE | |
2548 | ||
2549 | #endif | |
2550 | ||
872d8fea PC |
2551 | #ifndef _GLIBCXX_EXPORT_TEMPLATE |
2552 | # include "vstring.tcc" | |
2553 | #endif | |
2554 | ||
2555 | #endif /* _VSTRING_H */ |