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