1 // Versatile string -*- C++ -*-
3 // Copyright (C) 2005-2013 Free Software Foundation, Inc.
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)
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.
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.
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/>.
25 /** @file ext/vstring.h
26 * This file is a GNU extension to the Standard C++ Library.
32 #pragma GCC system_header
34 #if __cplusplus >= 201103L
35 #include <initializer_list>
38 #include <ext/vstring_util.h>
39 #include <ext/rc_string_base.h>
40 #include <ext/sso_string_base.h>
42 namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
44 _GLIBCXX_BEGIN_NAMESPACE_VERSION
47 * @class __versa_string vstring.h
48 * @brief Template class __versa_string.
51 * Data structure managing sequences of characters and
52 * character-like objects.
54 template<typename _CharT, typename _Traits, typename _Alloc,
55 template <typename, typename, typename> class _Base>
57 : private _Base<_CharT, _Traits, _Alloc>
59 typedef _Base<_CharT, _Traits, _Alloc> __vstring_base;
60 typedef typename __vstring_base::_CharT_alloc_type _CharT_alloc_type;
64 typedef _Traits traits_type;
65 typedef typename _Traits::char_type value_type;
66 typedef _Alloc allocator_type;
67 typedef typename _CharT_alloc_type::size_type size_type;
68 typedef typename _CharT_alloc_type::difference_type difference_type;
69 typedef value_type& reference;
70 typedef const value_type& const_reference;
71 typedef typename _CharT_alloc_type::pointer pointer;
72 typedef typename _CharT_alloc_type::const_pointer const_pointer;
73 typedef __gnu_cxx::__normal_iterator<pointer, __versa_string> iterator;
74 typedef __gnu_cxx::__normal_iterator<const_pointer, __versa_string>
76 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
77 typedef std::reverse_iterator<iterator> reverse_iterator;
79 // Data Member (public):
80 /// Value returned by various member functions when they fail.
81 static const size_type npos = static_cast<size_type>(-1);
85 _M_check(size_type __pos, const char* __s) const
87 if (__pos > this->size())
88 std::__throw_out_of_range(__N(__s));
93 _M_check_length(size_type __n1, size_type __n2, const char* __s) const
95 if (this->max_size() - (this->size() - __n1) < __n2)
96 std::__throw_length_error(__N(__s));
99 // NB: _M_limit doesn't check for a bad __pos value.
101 _M_limit(size_type __pos, size_type __off) const
103 const bool __testoff = __off < this->size() - __pos;
104 return __testoff ? __off : this->size() - __pos;
107 // True if _Rep and source do not overlap.
109 _M_disjunct(const _CharT* __s) const
111 return (std::less<const _CharT*>()(__s, this->_M_data())
112 || std::less<const _CharT*>()(this->_M_data()
113 + this->size(), __s));
116 // For the internal use we have functions similar to `begin'/`end'
117 // but they do not call _M_leak.
120 { return iterator(this->_M_data()); }
124 { return iterator(this->_M_data() + this->_M_length()); }
127 // Construct/copy/destroy:
128 // NB: We overload ctors in some cases instead of using default
129 // arguments, per 17.4.4.4 para. 2 item 2.
132 * @brief Default constructor creates an empty string.
135 : __vstring_base() { }
138 * @brief Construct an empty string using allocator @a a.
141 __versa_string(const _Alloc& __a)
142 : __vstring_base(__a) { }
144 // NB: per LWG issue 42, semantics different from IS:
146 * @brief Construct string with copy of value of @a __str.
147 * @param __str Source string.
149 __versa_string(const __versa_string& __str)
150 : __vstring_base(__str) { }
152 #if __cplusplus >= 201103L
154 * @brief String move constructor.
155 * @param __str Source string.
157 * The newly-constructed %string contains the exact contents of
158 * @a __str. The contents of @a __str are a valid, but unspecified
161 __versa_string(__versa_string&& __str) noexcept
162 : __vstring_base(std::move(__str)) { }
165 * @brief Construct string from an initializer list.
166 * @param __l std::initializer_list of characters.
167 * @param __a Allocator to use (default is default allocator).
169 __versa_string(std::initializer_list<_CharT> __l,
170 const _Alloc& __a = _Alloc())
171 : __vstring_base(__l.begin(), __l.end(), __a) { }
175 * @brief Construct string as copy of a substring.
176 * @param __str Source string.
177 * @param __pos Index of first character to copy from.
178 * @param __n Number of characters to copy (default remainder).
180 __versa_string(const __versa_string& __str, size_type __pos,
181 size_type __n = npos)
182 : __vstring_base(__str._M_data()
183 + __str._M_check(__pos,
184 "__versa_string::__versa_string"),
185 __str._M_data() + __str._M_limit(__pos, __n)
186 + __pos, _Alloc()) { }
189 * @brief Construct string as copy of a substring.
190 * @param __str Source string.
191 * @param __pos Index of first character to copy from.
192 * @param __n Number of characters to copy.
193 * @param __a Allocator to use.
195 __versa_string(const __versa_string& __str, size_type __pos,
196 size_type __n, const _Alloc& __a)
197 : __vstring_base(__str._M_data()
198 + __str._M_check(__pos,
199 "__versa_string::__versa_string"),
200 __str._M_data() + __str._M_limit(__pos, __n)
204 * @brief Construct string initialized by a character array.
205 * @param __s Source character array.
206 * @param __n Number of characters to copy.
207 * @param __a Allocator to use (default is default allocator).
209 * NB: @a __s must have at least @a __n characters, '\\0' has no special
212 __versa_string(const _CharT* __s, size_type __n,
213 const _Alloc& __a = _Alloc())
214 : __vstring_base(__s, __s + __n, __a) { }
217 * @brief Construct string as copy of a C string.
218 * @param __s Source C string.
219 * @param __a Allocator to use (default is default allocator).
221 __versa_string(const _CharT* __s, const _Alloc& __a = _Alloc())
222 : __vstring_base(__s, __s ? __s + traits_type::length(__s) :
226 * @brief Construct string as multiple characters.
227 * @param __n Number of characters.
228 * @param __c Character to use.
229 * @param __a Allocator to use (default is default allocator).
231 __versa_string(size_type __n, _CharT __c, const _Alloc& __a = _Alloc())
232 : __vstring_base(__n, __c, __a) { }
235 * @brief Construct string as copy of a range.
236 * @param __beg Start of range.
237 * @param __end End of range.
238 * @param __a Allocator to use (default is default allocator).
240 #if __cplusplus >= 201103L
241 template<class _InputIterator,
242 typename = std::_RequireInputIter<_InputIterator>>
244 template<class _InputIterator>
246 __versa_string(_InputIterator __beg, _InputIterator __end,
247 const _Alloc& __a = _Alloc())
248 : __vstring_base(__beg, __end, __a) { }
251 * @brief Destroy the string instance.
253 ~__versa_string() _GLIBCXX_NOEXCEPT { }
256 * @brief Assign the value of @a str to this string.
257 * @param __str Source string.
260 operator=(const __versa_string& __str)
261 { return this->assign(__str); }
263 #if __cplusplus >= 201103L
265 * @brief String move assignment operator.
266 * @param __str Source string.
268 * The contents of @a __str are moved into this string (without
269 * copying). @a __str is a valid, but unspecified string.
272 operator=(__versa_string&& __str)
280 * @brief Set value to string constructed from initializer list.
281 * @param __l std::initializer_list.
284 operator=(std::initializer_list<_CharT> __l)
286 this->assign(__l.begin(), __l.end());
292 * @brief Copy contents of @a __s into this string.
293 * @param __s Source null-terminated string.
296 operator=(const _CharT* __s)
297 { return this->assign(__s); }
300 * @brief Set value to string of length 1.
301 * @param __c Source character.
303 * Assigning to a character makes this string length 1 and
304 * (*this)[0] == @a __c.
307 operator=(_CharT __c)
309 this->assign(1, __c);
315 * Returns a read/write iterator that points to the first character in
316 * the %string. Unshares the string.
319 begin() _GLIBCXX_NOEXCEPT
322 return iterator(this->_M_data());
326 * Returns a read-only (constant) iterator that points to the first
327 * character in the %string.
330 begin() const _GLIBCXX_NOEXCEPT
331 { return const_iterator(this->_M_data()); }
334 * Returns a read/write iterator that points one past the last
335 * character in the %string. Unshares the string.
338 end() _GLIBCXX_NOEXCEPT
341 return iterator(this->_M_data() + this->size());
345 * Returns a read-only (constant) iterator that points one past the
346 * last character in the %string.
349 end() const _GLIBCXX_NOEXCEPT
350 { return const_iterator(this->_M_data() + this->size()); }
353 * Returns a read/write reverse iterator that points to the last
354 * character in the %string. Iteration is done in reverse element
355 * order. Unshares the string.
358 rbegin() _GLIBCXX_NOEXCEPT
359 { return reverse_iterator(this->end()); }
362 * Returns a read-only (constant) reverse iterator that points
363 * to the last character in the %string. Iteration is done in
364 * reverse element order.
366 const_reverse_iterator
367 rbegin() const _GLIBCXX_NOEXCEPT
368 { return const_reverse_iterator(this->end()); }
371 * Returns a read/write reverse iterator that points to one before the
372 * first character in the %string. Iteration is done in reverse
373 * element order. Unshares the string.
376 rend() _GLIBCXX_NOEXCEPT
377 { return reverse_iterator(this->begin()); }
380 * Returns a read-only (constant) reverse iterator that points
381 * to one before the first character in the %string. Iteration
382 * is done in reverse element order.
384 const_reverse_iterator
385 rend() const _GLIBCXX_NOEXCEPT
386 { return const_reverse_iterator(this->begin()); }
388 #if __cplusplus >= 201103L
390 * Returns a read-only (constant) iterator that points to the first
391 * character in the %string.
394 cbegin() const noexcept
395 { return const_iterator(this->_M_data()); }
398 * Returns a read-only (constant) iterator that points one past the
399 * last character in the %string.
402 cend() const noexcept
403 { return const_iterator(this->_M_data() + this->size()); }
406 * Returns a read-only (constant) reverse iterator that points
407 * to the last character in the %string. Iteration is done in
408 * reverse element order.
410 const_reverse_iterator
411 crbegin() const noexcept
412 { return const_reverse_iterator(this->end()); }
415 * Returns a read-only (constant) reverse iterator that points
416 * to one before the first character in the %string. Iteration
417 * is done in reverse element order.
419 const_reverse_iterator
420 crend() const noexcept
421 { return const_reverse_iterator(this->begin()); }
426 /// Returns the number of characters in the string, not including any
427 /// null-termination.
429 size() const _GLIBCXX_NOEXCEPT
430 { return this->_M_length(); }
432 /// Returns the number of characters in the string, not including any
433 /// null-termination.
435 length() const _GLIBCXX_NOEXCEPT
436 { return this->_M_length(); }
438 /// Returns the size() of the largest possible %string.
440 max_size() const _GLIBCXX_NOEXCEPT
441 { return this->_M_max_size(); }
444 * @brief Resizes the %string to the specified number of characters.
445 * @param __n Number of characters the %string should contain.
446 * @param __c Character to fill any new elements.
448 * This function will %resize the %string to the specified
449 * number of characters. If the number is smaller than the
450 * %string's current size the %string is truncated, otherwise
451 * the %string is extended and new elements are set to @a __c.
454 resize(size_type __n, _CharT __c);
457 * @brief Resizes the %string to the specified number of characters.
458 * @param __n Number of characters the %string should contain.
460 * This function will resize the %string to the specified
461 * length. If the new size is smaller than the %string's
462 * current size the %string is truncated, otherwise the %string
463 * is extended and new characters are default-constructed. For
464 * basic types such as char, this means setting them to 0.
467 resize(size_type __n)
468 { this->resize(__n, _CharT()); }
470 #if __cplusplus >= 201103L
471 /// A non-binding request to reduce capacity() to size().
475 if (capacity() > size())
478 { this->reserve(0); }
486 * Returns the total number of characters that the %string can
487 * hold before needing to allocate more memory.
490 capacity() const _GLIBCXX_NOEXCEPT
491 { return this->_M_capacity(); }
494 * @brief Attempt to preallocate enough memory for specified number of
496 * @param __res_arg Number of characters required.
497 * @throw std::length_error If @a __res_arg exceeds @c max_size().
499 * This function attempts to reserve enough memory for the
500 * %string to hold the specified number of characters. If the
501 * number requested is more than max_size(), length_error is
504 * The advantage of this function is that if optimal code is a
505 * necessity and the user can determine the string length that
506 * will be required, the user can reserve the memory in
507 * %advance, and thus prevent a possible reallocation of memory
508 * and copying of %string data.
511 reserve(size_type __res_arg = 0)
512 { this->_M_reserve(__res_arg); }
515 * Erases the string, making it empty.
518 clear() _GLIBCXX_NOEXCEPT
519 { this->_M_clear(); }
522 * Returns true if the %string is empty. Equivalent to
523 * <code>*this == ""</code>.
526 empty() const _GLIBCXX_NOEXCEPT
527 { return this->size() == 0; }
531 * @brief Subscript access to the data contained in the %string.
532 * @param __pos The index of the character to access.
533 * @return Read-only (constant) reference to the character.
535 * This operator allows for easy, array-style, data access.
536 * Note that data access with this operator is unchecked and
537 * out_of_range lookups are not defined. (For checked lookups
541 operator[] (size_type __pos) const
543 _GLIBCXX_DEBUG_ASSERT(__pos <= this->size());
544 return this->_M_data()[__pos];
548 * @brief Subscript access to the data contained in the %string.
549 * @param __pos The index of the character to access.
550 * @return Read/write reference to the character.
552 * This operator allows for easy, array-style, data access.
553 * Note that data access with this operator is unchecked and
554 * out_of_range lookups are not defined. (For checked lookups
555 * see at().) Unshares the string.
558 operator[](size_type __pos)
560 // allow pos == size() as v3 extension:
561 _GLIBCXX_DEBUG_ASSERT(__pos <= this->size());
562 // but be strict in pedantic mode:
563 _GLIBCXX_DEBUG_PEDASSERT(__pos < this->size());
565 return this->_M_data()[__pos];
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.
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.
579 at(size_type __n) const
581 if (__n >= this->size())
582 std::__throw_out_of_range(__N("__versa_string::at"));
583 return this->_M_data()[__n];
587 * @brief Provides access to the data contained in the %string.
588 * @param __n The index of the character to access.
589 * @return Read/write reference to the character.
590 * @throw std::out_of_range If @a __n is an invalid index.
592 * This function provides for safer data access. The parameter
593 * is first checked that it is in the range of the string. The
594 * function throws out_of_range if the check fails. Success
595 * results in unsharing the string.
600 if (__n >= this->size())
601 std::__throw_out_of_range(__N("__versa_string::at"));
603 return this->_M_data()[__n];
606 #if __cplusplus >= 201103L
608 * Returns a read/write reference to the data at the first
609 * element of the %string.
613 { return operator[](0); }
616 * Returns a read-only (constant) reference to the data at the first
617 * element of the %string.
621 { return operator[](0); }
624 * Returns a read/write reference to the data at the last
625 * element of the %string.
629 { return operator[](this->size() - 1); }
632 * Returns a read-only (constant) reference to the data at the
633 * last element of the %string.
637 { return operator[](this->size() - 1); }
642 * @brief Append a string to this string.
643 * @param __str The string to append.
644 * @return Reference to this string.
647 operator+=(const __versa_string& __str)
648 { return this->append(__str); }
651 * @brief Append a C string.
652 * @param __s The C string to append.
653 * @return Reference to this string.
656 operator+=(const _CharT* __s)
657 { return this->append(__s); }
660 * @brief Append a character.
661 * @param __c The character to append.
662 * @return Reference to this string.
665 operator+=(_CharT __c)
667 this->push_back(__c);
671 #if __cplusplus >= 201103L
673 * @brief Append an initializer_list of characters.
674 * @param __l The initializer_list of characters to be appended.
675 * @return Reference to this string.
678 operator+=(std::initializer_list<_CharT> __l)
679 { return this->append(__l.begin(), __l.end()); }
683 * @brief Append a string to this string.
684 * @param __str The string to append.
685 * @return Reference to this string.
688 append(const __versa_string& __str)
689 { return _M_append(__str._M_data(), __str.size()); }
692 * @brief Append a substring.
693 * @param __str The string to append.
694 * @param __pos Index of the first character of str to append.
695 * @param __n The number of characters to append.
696 * @return Reference to this string.
697 * @throw std::out_of_range if @a pos is not a valid index.
699 * This function appends @a __n characters from @a __str
700 * starting at @a __pos to this string. If @a __n is is larger
701 * than the number of available characters in @a __str, the
702 * remainder of @a __str is appended.
705 append(const __versa_string& __str, size_type __pos, size_type __n)
706 { return _M_append(__str._M_data()
707 + __str._M_check(__pos, "__versa_string::append"),
708 __str._M_limit(__pos, __n)); }
711 * @brief Append a C substring.
712 * @param __s The C string to append.
713 * @param __n The number of characters to append.
714 * @return Reference to this string.
717 append(const _CharT* __s, size_type __n)
719 __glibcxx_requires_string_len(__s, __n);
720 _M_check_length(size_type(0), __n, "__versa_string::append");
721 return _M_append(__s, __n);
725 * @brief Append a C string.
726 * @param __s The C string to append.
727 * @return Reference to this string.
730 append(const _CharT* __s)
732 __glibcxx_requires_string(__s);
733 const size_type __n = traits_type::length(__s);
734 _M_check_length(size_type(0), __n, "__versa_string::append");
735 return _M_append(__s, __n);
739 * @brief Append multiple characters.
740 * @param __n The number of characters to append.
741 * @param __c The character to use.
742 * @return Reference to this string.
744 * Appends n copies of c to this string.
747 append(size_type __n, _CharT __c)
748 { return _M_replace_aux(this->size(), size_type(0), __n, __c); }
750 #if __cplusplus >= 201103L
752 * @brief Append an initializer_list of characters.
753 * @param __l The initializer_list of characters to append.
754 * @return Reference to this string.
757 append(std::initializer_list<_CharT> __l)
758 { return this->append(__l.begin(), __l.end()); }
762 * @brief Append a range of characters.
763 * @param __first Iterator referencing the first character to append.
764 * @param __last Iterator marking the end of the range.
765 * @return Reference to this string.
767 * Appends characters in the range [first,last) to this string.
769 #if __cplusplus >= 201103L
770 template<class _InputIterator,
771 typename = std::_RequireInputIter<_InputIterator>>
773 template<class _InputIterator>
776 append(_InputIterator __first, _InputIterator __last)
777 { return this->replace(_M_iend(), _M_iend(), __first, __last); }
780 * @brief Append a single character.
781 * @param __c Character to append.
784 push_back(_CharT __c)
786 const size_type __size = this->size();
787 if (__size + 1 > this->capacity() || this->_M_is_shared())
788 this->_M_mutate(__size, size_type(0), 0, size_type(1));
789 traits_type::assign(this->_M_data()[__size], __c);
790 this->_M_set_length(__size + 1);
794 * @brief Set value to contents of another string.
795 * @param __str Source string to use.
796 * @return Reference to this string.
799 assign(const __versa_string& __str)
801 this->_M_assign(__str);
805 #if __cplusplus >= 201103L
807 * @brief Set value to contents of another string.
808 * @param __str Source string to use.
809 * @return Reference to this string.
811 * This function sets this string to the exact contents of @a __str.
812 * @a __str is a valid, but unspecified string.
815 assign(__versa_string&& __str)
823 * @brief Set value to a substring of a string.
824 * @param __str The string to use.
825 * @param __pos Index of the first character of str.
826 * @param __n Number of characters to use.
827 * @return Reference to this string.
828 * @throw std::out_of_range if @a __pos is not a valid index.
830 * This function sets this string to the substring of @a __str
831 * consisting of @a __n characters at @a __pos. If @a __n is
832 * is larger than the number of available characters in @a
833 * __str, the remainder of @a __str is used.
836 assign(const __versa_string& __str, size_type __pos, size_type __n)
837 { return _M_replace(size_type(0), this->size(), __str._M_data()
838 + __str._M_check(__pos, "__versa_string::assign"),
839 __str._M_limit(__pos, __n)); }
842 * @brief Set value to a C substring.
843 * @param __s The C string to use.
844 * @param __n Number of characters to use.
845 * @return Reference to this string.
847 * This function sets the value of this string to the first @a
848 * __n characters of @a __s. If @a __n is is larger than the
849 * number of available characters in @a __s, the remainder of
853 assign(const _CharT* __s, size_type __n)
855 __glibcxx_requires_string_len(__s, __n);
856 return _M_replace(size_type(0), this->size(), __s, __n);
860 * @brief Set value to contents of a C string.
861 * @param __s The C string to use.
862 * @return Reference to this string.
864 * This function sets the value of this string to the value of
865 * @a __s. The data is copied, so there is no dependence on @a
866 * __s once the function returns.
869 assign(const _CharT* __s)
871 __glibcxx_requires_string(__s);
872 return _M_replace(size_type(0), this->size(), __s,
873 traits_type::length(__s));
877 * @brief Set value to multiple characters.
878 * @param __n Length of the resulting string.
879 * @param __c The character to use.
880 * @return Reference to this string.
882 * This function sets the value of this string to @a __n copies of
886 assign(size_type __n, _CharT __c)
887 { return _M_replace_aux(size_type(0), this->size(), __n, __c); }
890 * @brief Set value to a range of characters.
891 * @param __first Iterator referencing the first character to append.
892 * @param __last Iterator marking the end of the range.
893 * @return Reference to this string.
895 * Sets value of string to characters in the range
898 #if __cplusplus >= 201103L
899 template<class _InputIterator,
900 typename = std::_RequireInputIter<_InputIterator>>
902 template<class _InputIterator>
905 assign(_InputIterator __first, _InputIterator __last)
906 { return this->replace(_M_ibegin(), _M_iend(), __first, __last); }
908 #if __cplusplus >= 201103L
910 * @brief Set value to an initializer_list of characters.
911 * @param __l The initializer_list of characters to assign.
912 * @return Reference to this string.
915 assign(std::initializer_list<_CharT> __l)
916 { return this->assign(__l.begin(), __l.end()); }
920 * @brief Insert multiple characters.
921 * @param __p Iterator referencing location in string to insert at.
922 * @param __n Number of characters to insert
923 * @param __c The character to insert.
924 * @throw std::length_error If new length exceeds @c max_size().
926 * Inserts @a __n copies of character @a __c starting at the
927 * position referenced by iterator @a __p. If adding
928 * characters causes the length to exceed max_size(),
929 * length_error is thrown. The value of the string doesn't
930 * change if an error is thrown.
933 insert(iterator __p, size_type __n, _CharT __c)
934 { this->replace(__p, __p, __n, __c); }
937 * @brief Insert a range of characters.
938 * @param __p Iterator referencing location in string to insert at.
939 * @param __beg Start of range.
940 * @param __end End of range.
941 * @throw std::length_error If new length exceeds @c max_size().
943 * Inserts characters in range [beg,end). If adding characters
944 * causes the length to exceed max_size(), length_error is
945 * thrown. The value of the string doesn't change if an error
948 #if __cplusplus >= 201103L
949 template<class _InputIterator,
950 typename = std::_RequireInputIter<_InputIterator>>
952 template<class _InputIterator>
955 insert(iterator __p, _InputIterator __beg, _InputIterator __end)
956 { this->replace(__p, __p, __beg, __end); }
958 #if __cplusplus >= 201103L
960 * @brief Insert an initializer_list of characters.
961 * @param __p Iterator referencing location in string to insert at.
962 * @param __l The initializer_list of characters to insert.
963 * @throw std::length_error If new length exceeds @c max_size().
966 insert(iterator __p, std::initializer_list<_CharT> __l)
967 { this->insert(__p, __l.begin(), __l.end()); }
971 * @brief Insert value of a string.
972 * @param __pos1 Iterator referencing location in string to insert at.
973 * @param __str The string to insert.
974 * @return Reference to this string.
975 * @throw std::length_error If new length exceeds @c max_size().
977 * Inserts value of @a __str starting at @a __pos1. If adding
978 * characters causes the length to exceed max_size(),
979 * length_error is thrown. The value of the string doesn't
980 * change if an error is thrown.
983 insert(size_type __pos1, const __versa_string& __str)
984 { return this->replace(__pos1, size_type(0),
985 __str._M_data(), __str.size()); }
988 * @brief Insert a substring.
989 * @param __pos1 Iterator referencing location in string to insert at.
990 * @param __str The string to insert.
991 * @param __pos2 Start of characters in str to insert.
992 * @param __n Number of characters to insert.
993 * @return Reference to this string.
994 * @throw std::length_error If new length exceeds @c max_size().
995 * @throw std::out_of_range If @a __pos1 > size() or
996 * @a __pos2 > @a __str.size().
998 * Starting at @a __pos1, insert @a __n character of @a __str
999 * beginning with @a __pos2. If adding characters causes the
1000 * length to exceed max_size(), length_error is thrown. If @a
1001 * __pos1 is beyond the end of this string or @a __pos2 is
1002 * beyond the end of @a __str, out_of_range is thrown. The
1003 * value of the string doesn't change if an error is thrown.
1006 insert(size_type __pos1, const __versa_string& __str,
1007 size_type __pos2, size_type __n)
1008 { return this->replace(__pos1, size_type(0), __str._M_data()
1009 + __str._M_check(__pos2, "__versa_string::insert"),
1010 __str._M_limit(__pos2, __n)); }
1013 * @brief Insert a C substring.
1014 * @param __pos Iterator referencing location in string to insert at.
1015 * @param __s The C string to insert.
1016 * @param __n The number of characters to insert.
1017 * @return Reference to this string.
1018 * @throw std::length_error If new length exceeds @c max_size().
1019 * @throw std::out_of_range If @a __pos is beyond the end of this
1022 * Inserts the first @a __n characters of @a __s starting at @a
1023 * __pos. If adding characters causes the length to exceed
1024 * max_size(), length_error is thrown. If @a __pos is beyond
1025 * end(), out_of_range is thrown. The value of the string
1026 * doesn't change if an error is thrown.
1029 insert(size_type __pos, const _CharT* __s, size_type __n)
1030 { return this->replace(__pos, size_type(0), __s, __n); }
1033 * @brief Insert a C string.
1034 * @param __pos Iterator referencing location in string to insert at.
1035 * @param __s The C string to insert.
1036 * @return Reference to this string.
1037 * @throw std::length_error If new length exceeds @c max_size().
1038 * @throw std::out_of_range If @a __pos is beyond the end of this
1041 * Inserts the first @a __n characters of @a __s starting at @a
1042 * __pos. If adding characters causes the length to exceed
1043 * max_size(), length_error is thrown. If @a __pos is beyond
1044 * end(), out_of_range is thrown. The value of the string
1045 * doesn't change if an error is thrown.
1048 insert(size_type __pos, const _CharT* __s)
1050 __glibcxx_requires_string(__s);
1051 return this->replace(__pos, size_type(0), __s,
1052 traits_type::length(__s));
1056 * @brief Insert multiple characters.
1057 * @param __pos Index in string to insert at.
1058 * @param __n Number of characters to insert
1059 * @param __c The character to insert.
1060 * @return Reference to this string.
1061 * @throw std::length_error If new length exceeds @c max_size().
1062 * @throw std::out_of_range If @a __pos is beyond the end of this
1065 * Inserts @a __n copies of character @a __c starting at index
1066 * @a __pos. If adding characters causes the length to exceed
1067 * max_size(), length_error is thrown. If @a __pos > length(),
1068 * out_of_range is thrown. The value of the string doesn't
1069 * change if an error is thrown.
1072 insert(size_type __pos, size_type __n, _CharT __c)
1073 { return _M_replace_aux(_M_check(__pos, "__versa_string::insert"),
1074 size_type(0), __n, __c); }
1077 * @brief Insert one character.
1078 * @param __p Iterator referencing position in string to insert at.
1079 * @param __c The character to insert.
1080 * @return Iterator referencing newly inserted char.
1081 * @throw std::length_error If new length exceeds @c max_size().
1083 * Inserts character @a __c at position referenced by @a __p.
1084 * If adding character causes the length to exceed max_size(),
1085 * length_error is thrown. If @a __p is beyond end of string,
1086 * out_of_range is thrown. The value of the string doesn't
1087 * change if an error is thrown.
1090 insert(iterator __p, _CharT __c)
1092 _GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend());
1093 const size_type __pos = __p - _M_ibegin();
1094 _M_replace_aux(__pos, size_type(0), size_type(1), __c);
1095 this->_M_set_leaked();
1096 return iterator(this->_M_data() + __pos);
1100 * @brief Remove characters.
1101 * @param __pos Index of first character to remove (default 0).
1102 * @param __n Number of characters to remove (default remainder).
1103 * @return Reference to this string.
1104 * @throw std::out_of_range If @a __pos is beyond the end of this
1107 * Removes @a __n characters from this string starting at @a
1108 * __pos. The length of the string is reduced by @a __n. If
1109 * there are < @a __n characters to remove, the remainder of
1110 * the string is truncated. If @a __p is beyond end of string,
1111 * out_of_range is thrown. The value of the string doesn't
1112 * change if an error is thrown.
1115 erase(size_type __pos = 0, size_type __n = npos)
1117 this->_M_erase(_M_check(__pos, "__versa_string::erase"),
1118 _M_limit(__pos, __n));
1123 * @brief Remove one character.
1124 * @param __position Iterator referencing the character to remove.
1125 * @return iterator referencing same location after removal.
1127 * Removes the character at @a __position from this string. The
1128 * value of the string doesn't change if an error is thrown.
1131 erase(iterator __position)
1133 _GLIBCXX_DEBUG_PEDASSERT(__position >= _M_ibegin()
1134 && __position < _M_iend());
1135 const size_type __pos = __position - _M_ibegin();
1136 this->_M_erase(__pos, size_type(1));
1137 this->_M_set_leaked();
1138 return iterator(this->_M_data() + __pos);
1142 * @brief Remove a range of characters.
1143 * @param __first Iterator referencing the first character to remove.
1144 * @param __last Iterator referencing the end of the range.
1145 * @return Iterator referencing location of first after removal.
1147 * Removes the characters in the range [first,last) from this
1148 * string. The value of the string doesn't change if an error
1152 erase(iterator __first, iterator __last)
1154 _GLIBCXX_DEBUG_PEDASSERT(__first >= _M_ibegin() && __first <= __last
1155 && __last <= _M_iend());
1156 const size_type __pos = __first - _M_ibegin();
1157 this->_M_erase(__pos, __last - __first);
1158 this->_M_set_leaked();
1159 return iterator(this->_M_data() + __pos);
1162 #if __cplusplus >= 201103L
1164 * @brief Remove the last character.
1166 * The string must be non-empty.
1170 { this->_M_erase(size()-1, 1); }
1174 * @brief Replace characters with value from another string.
1175 * @param __pos Index of first character to replace.
1176 * @param __n Number of characters to be replaced.
1177 * @param __str String to insert.
1178 * @return Reference to this string.
1179 * @throw std::out_of_range If @a __pos is beyond the end of this
1181 * @throw std::length_error If new length exceeds @c max_size().
1183 * Removes the characters in the range [pos,pos+n) from this
1184 * string. In place, the value of @a __str is inserted. If @a
1185 * __pos is beyond end of string, out_of_range is thrown. If
1186 * the length of the result exceeds max_size(), length_error is
1187 * thrown. The value of the string doesn't change if an error
1191 replace(size_type __pos, size_type __n, const __versa_string& __str)
1192 { return this->replace(__pos, __n, __str._M_data(), __str.size()); }
1195 * @brief Replace characters with value from another string.
1196 * @param __pos1 Index of first character to replace.
1197 * @param __n1 Number of characters to be replaced.
1198 * @param __str String to insert.
1199 * @param __pos2 Index of first character of str to use.
1200 * @param __n2 Number of characters from str to use.
1201 * @return Reference to this string.
1202 * @throw std::out_of_range If @a __pos1 > size() or @a __pos2 >
1204 * @throw std::length_error If new length exceeds @c max_size().
1206 * Removes the characters in the range [pos1,pos1 + n) from
1207 * this string. In place, the value of @a __str is inserted.
1208 * If @a __pos is beyond end of string, out_of_range is thrown.
1209 * If the length of the result exceeds max_size(), length_error
1210 * is thrown. The value of the string doesn't change if an
1214 replace(size_type __pos1, size_type __n1, const __versa_string& __str,
1215 size_type __pos2, size_type __n2)
1217 return this->replace(__pos1, __n1, __str._M_data()
1218 + __str._M_check(__pos2,
1219 "__versa_string::replace"),
1220 __str._M_limit(__pos2, __n2));
1224 * @brief Replace characters with value of a C substring.
1225 * @param __pos Index of first character to replace.
1226 * @param __n1 Number of characters to be replaced.
1227 * @param __s C string to insert.
1228 * @param __n2 Number of characters from @a __s to use.
1229 * @return Reference to this string.
1230 * @throw std::out_of_range If @a __pos1 > size().
1231 * @throw std::length_error If new length exceeds @c max_size().
1233 * Removes the characters in the range [pos,pos + n1) from this
1234 * string. In place, the first @a __n2 characters of @a __s
1235 * are inserted, or all of @a __s if @a __n2 is too large. If
1236 * @a __pos is beyond end of string, out_of_range is thrown.
1237 * If the length of result exceeds max_size(), length_error is
1238 * thrown. The value of the string doesn't change if an error
1242 replace(size_type __pos, size_type __n1, const _CharT* __s,
1245 __glibcxx_requires_string_len(__s, __n2);
1246 return _M_replace(_M_check(__pos, "__versa_string::replace"),
1247 _M_limit(__pos, __n1), __s, __n2);
1251 * @brief Replace characters with value of a C string.
1252 * @param __pos Index of first character to replace.
1253 * @param __n1 Number of characters to be replaced.
1254 * @param __s C string to insert.
1255 * @return Reference to this string.
1256 * @throw std::out_of_range If @a __pos > size().
1257 * @throw std::length_error If new length exceeds @c max_size().
1259 * Removes the characters in the range [pos,pos + n1) from this
1260 * string. In place, the characters of @a __s are inserted. If
1261 * @a pos is beyond end of string, out_of_range is thrown. If
1262 * the length of result exceeds max_size(), length_error is thrown.
1263 * The value of the string doesn't change if an error is thrown.
1266 replace(size_type __pos, size_type __n1, const _CharT* __s)
1268 __glibcxx_requires_string(__s);
1269 return this->replace(__pos, __n1, __s, traits_type::length(__s));
1273 * @brief Replace characters with multiple characters.
1274 * @param __pos Index of first character to replace.
1275 * @param __n1 Number of characters to be replaced.
1276 * @param __n2 Number of characters to insert.
1277 * @param __c Character to insert.
1278 * @return Reference to this string.
1279 * @throw std::out_of_range If @a __pos > size().
1280 * @throw std::length_error If new length exceeds @c max_size().
1282 * Removes the characters in the range [pos,pos + n1) from this
1283 * string. In place, @a __n2 copies of @a __c are inserted.
1284 * If @a __pos is beyond end of string, out_of_range is thrown.
1285 * If the length of result exceeds max_size(), length_error is
1286 * thrown. The value of the string doesn't change if an error
1290 replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
1291 { return _M_replace_aux(_M_check(__pos, "__versa_string::replace"),
1292 _M_limit(__pos, __n1), __n2, __c); }
1295 * @brief Replace range of characters with string.
1296 * @param __i1 Iterator referencing start of range to replace.
1297 * @param __i2 Iterator referencing end of range to replace.
1298 * @param __str String value to insert.
1299 * @return Reference to this string.
1300 * @throw std::length_error If new length exceeds @c max_size().
1302 * Removes the characters in the range [i1,i2). In place, the
1303 * value of @a __str is inserted. If the length of result
1304 * exceeds max_size(), length_error is thrown. The value of
1305 * the string doesn't change if an error is thrown.
1308 replace(iterator __i1, iterator __i2, const __versa_string& __str)
1309 { return this->replace(__i1, __i2, __str._M_data(), __str.size()); }
1312 * @brief Replace range of characters with C substring.
1313 * @param __i1 Iterator referencing start of range to replace.
1314 * @param __i2 Iterator referencing end of range to replace.
1315 * @param __s C string value to insert.
1316 * @param __n Number of characters from s to insert.
1317 * @return Reference to this string.
1318 * @throw std::length_error If new length exceeds @c max_size().
1320 * Removes the characters in the range [i1,i2). In place, the
1321 * first @a n characters of @a __s are inserted. If the length
1322 * of result exceeds max_size(), length_error is thrown. The
1323 * value of the string doesn't change if an error is thrown.
1326 replace(iterator __i1, iterator __i2, const _CharT* __s, size_type __n)
1328 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1329 && __i2 <= _M_iend());
1330 return this->replace(__i1 - _M_ibegin(), __i2 - __i1, __s, __n);
1334 * @brief Replace range of characters with C string.
1335 * @param __i1 Iterator referencing start of range to replace.
1336 * @param __i2 Iterator referencing end of range to replace.
1337 * @param __s C string value to insert.
1338 * @return Reference to this string.
1339 * @throw std::length_error If new length exceeds @c max_size().
1341 * Removes the characters in the range [i1,i2). In place, the
1342 * characters of @a __s are inserted. If the length of result
1343 * exceeds max_size(), length_error is thrown. The value of
1344 * the string doesn't change if an error is thrown.
1347 replace(iterator __i1, iterator __i2, const _CharT* __s)
1349 __glibcxx_requires_string(__s);
1350 return this->replace(__i1, __i2, __s, traits_type::length(__s));
1354 * @brief Replace range of characters with multiple characters
1355 * @param __i1 Iterator referencing start of range to replace.
1356 * @param __i2 Iterator referencing end of range to replace.
1357 * @param __n Number of characters to insert.
1358 * @param __c Character to insert.
1359 * @return Reference to this string.
1360 * @throw std::length_error If new length exceeds @c max_size().
1362 * Removes the characters in the range [i1,i2). In place, @a
1363 * __n copies of @a __c are inserted. If the length of result
1364 * exceeds max_size(), length_error is thrown. The value of
1365 * the string doesn't change if an error is thrown.
1368 replace(iterator __i1, iterator __i2, size_type __n, _CharT __c)
1370 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1371 && __i2 <= _M_iend());
1372 return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __c);
1376 * @brief Replace range of characters with range.
1377 * @param __i1 Iterator referencing start of range to replace.
1378 * @param __i2 Iterator referencing end of range to replace.
1379 * @param __k1 Iterator referencing start of range to insert.
1380 * @param __k2 Iterator referencing end of range to insert.
1381 * @return Reference to this string.
1382 * @throw std::length_error If new length exceeds @c max_size().
1384 * Removes the characters in the range [i1,i2). In place,
1385 * characters in the range [k1,k2) are inserted. If the length
1386 * of result exceeds max_size(), length_error is thrown. The
1387 * value of the string doesn't change if an error is thrown.
1389 #if __cplusplus >= 201103L
1390 template<class _InputIterator,
1391 typename = std::_RequireInputIter<_InputIterator>>
1393 replace(iterator __i1, iterator __i2,
1394 _InputIterator __k1, _InputIterator __k2)
1396 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1397 && __i2 <= _M_iend());
1398 __glibcxx_requires_valid_range(__k1, __k2);
1399 return this->_M_replace_dispatch(__i1, __i2, __k1, __k2,
1400 std::__false_type());
1403 template<class _InputIterator>
1405 replace(iterator __i1, iterator __i2,
1406 _InputIterator __k1, _InputIterator __k2)
1408 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1409 && __i2 <= _M_iend());
1410 __glibcxx_requires_valid_range(__k1, __k2);
1411 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
1412 return this->_M_replace_dispatch(__i1, __i2, __k1, __k2, _Integral());
1416 // Specializations for the common case of pointer and iterator:
1417 // useful to avoid the overhead of temporary buffering in _M_replace.
1419 replace(iterator __i1, iterator __i2, _CharT* __k1, _CharT* __k2)
1421 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1422 && __i2 <= _M_iend());
1423 __glibcxx_requires_valid_range(__k1, __k2);
1424 return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
1429 replace(iterator __i1, iterator __i2,
1430 const _CharT* __k1, const _CharT* __k2)
1432 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1433 && __i2 <= _M_iend());
1434 __glibcxx_requires_valid_range(__k1, __k2);
1435 return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
1440 replace(iterator __i1, iterator __i2, iterator __k1, iterator __k2)
1442 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1443 && __i2 <= _M_iend());
1444 __glibcxx_requires_valid_range(__k1, __k2);
1445 return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
1446 __k1.base(), __k2 - __k1);
1450 replace(iterator __i1, iterator __i2,
1451 const_iterator __k1, const_iterator __k2)
1453 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1454 && __i2 <= _M_iend());
1455 __glibcxx_requires_valid_range(__k1, __k2);
1456 return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
1457 __k1.base(), __k2 - __k1);
1460 #if __cplusplus >= 201103L
1462 * @brief Replace range of characters with initializer_list.
1463 * @param __i1 Iterator referencing start of range to replace.
1464 * @param __i2 Iterator referencing end of range to replace.
1465 * @param __l The initializer_list of characters to insert.
1466 * @return Reference to this string.
1467 * @throw std::length_error If new length exceeds @c max_size().
1469 * Removes the characters in the range [i1,i2). In place,
1470 * characters in the range [k1,k2) are inserted. If the length
1471 * of result exceeds max_size(), length_error is thrown. The
1472 * value of the string doesn't change if an error is thrown.
1474 __versa_string& replace(iterator __i1, iterator __i2,
1475 std::initializer_list<_CharT> __l)
1476 { return this->replace(__i1, __i2, __l.begin(), __l.end()); }
1480 template<class _Integer>
1482 _M_replace_dispatch(iterator __i1, iterator __i2, _Integer __n,
1483 _Integer __val, std::__true_type)
1484 { return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __val); }
1486 template<class _InputIterator>
1488 _M_replace_dispatch(iterator __i1, iterator __i2, _InputIterator __k1,
1489 _InputIterator __k2, std::__false_type);
1492 _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2,
1496 _M_replace(size_type __pos, size_type __len1, const _CharT* __s,
1497 const size_type __len2);
1500 _M_append(const _CharT* __s, size_type __n);
1505 * @brief Copy substring into C string.
1506 * @param __s C string to copy value into.
1507 * @param __n Number of characters to copy.
1508 * @param __pos Index of first character to copy.
1509 * @return Number of characters actually copied
1510 * @throw std::out_of_range If pos > size().
1512 * Copies up to @a __n characters starting at @a __pos into the
1513 * C string @a s. If @a __pos is greater than size(),
1514 * out_of_range is thrown.
1517 copy(_CharT* __s, size_type __n, size_type __pos = 0) const;
1520 * @brief Swap contents with another string.
1521 * @param __s String to swap with.
1523 * Exchanges the contents of this string with that of @a __s in
1527 swap(__versa_string& __s)
1528 { this->_M_swap(__s); }
1530 // String operations:
1532 * @brief Return const pointer to null-terminated contents.
1534 * This is a handle to internal data. Do not modify or dire things may
1538 c_str() const _GLIBCXX_NOEXCEPT
1539 { return this->_M_data(); }
1542 * @brief Return const pointer to contents.
1544 * This is a handle to internal data. Do not modify or dire things may
1548 data() const _GLIBCXX_NOEXCEPT
1549 { return this->_M_data(); }
1552 * @brief Return copy of allocator used to construct this string.
1555 get_allocator() const _GLIBCXX_NOEXCEPT
1556 { return allocator_type(this->_M_get_allocator()); }
1559 * @brief Find position of a C substring.
1560 * @param __s C string to locate.
1561 * @param __pos Index of character to search from.
1562 * @param __n Number of characters from @a __s to search for.
1563 * @return Index of start of first occurrence.
1565 * Starting from @a __pos, searches forward for the first @a
1566 * __n characters in @a __s within this string. If found,
1567 * returns the index where it begins. If not found, returns
1571 find(const _CharT* __s, size_type __pos, size_type __n) const;
1574 * @brief Find position of a string.
1575 * @param __str String to locate.
1576 * @param __pos Index of character to search from (default 0).
1577 * @return Index of start of first occurrence.
1579 * Starting from @a __pos, searches forward for value of @a
1580 * __str within this string. If found, returns the index where
1581 * it begins. If not found, returns npos.
1584 find(const __versa_string& __str, size_type __pos = 0) const
1586 { return this->find(__str.data(), __pos, __str.size()); }
1589 * @brief Find position of a C string.
1590 * @param __s C string to locate.
1591 * @param __pos Index of character to search from (default 0).
1592 * @return Index of start of first occurrence.
1594 * Starting from @a __pos, searches forward for the value of @a
1595 * __s within this string. If found, returns the index where
1596 * it begins. If not found, returns npos.
1599 find(const _CharT* __s, size_type __pos = 0) const
1601 __glibcxx_requires_string(__s);
1602 return this->find(__s, __pos, traits_type::length(__s));
1606 * @brief Find position of a character.
1607 * @param __c Character to locate.
1608 * @param __pos Index of character to search from (default 0).
1609 * @return Index of first occurrence.
1611 * Starting from @a __pos, searches forward for @a __c within
1612 * this string. If found, returns the index where it was
1613 * found. If not found, returns npos.
1616 find(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT;
1619 * @brief Find last position of a string.
1620 * @param __str String to locate.
1621 * @param __pos Index of character to search back from (default end).
1622 * @return Index of start of last occurrence.
1624 * Starting from @a __pos, searches backward for value of @a
1625 * __str within this string. If found, returns the index where
1626 * it begins. If not found, returns npos.
1629 rfind(const __versa_string& __str, size_type __pos = npos) const
1631 { return this->rfind(__str.data(), __pos, __str.size()); }
1634 * @brief Find last position of a C substring.
1635 * @param __s C string to locate.
1636 * @param __pos Index of character to search back from.
1637 * @param __n Number of characters from s to search for.
1638 * @return Index of start of last occurrence.
1640 * Starting from @a __pos, searches backward for the first @a
1641 * __n characters in @a __s within this string. If found,
1642 * returns the index where it begins. If not found, returns
1646 rfind(const _CharT* __s, size_type __pos, size_type __n) const;
1649 * @brief Find last position of a C string.
1650 * @param __s C string to locate.
1651 * @param __pos Index of character to start search at (default end).
1652 * @return Index of start of last occurrence.
1654 * Starting from @a __pos, searches backward for the value of
1655 * @a __s within this string. If found, returns the index
1656 * where it begins. If not found, returns npos.
1659 rfind(const _CharT* __s, size_type __pos = npos) const
1661 __glibcxx_requires_string(__s);
1662 return this->rfind(__s, __pos, traits_type::length(__s));
1666 * @brief Find last position of a character.
1667 * @param __c Character to locate.
1668 * @param __pos Index of character to search back from (default end).
1669 * @return Index of last occurrence.
1671 * Starting from @a __pos, searches backward for @a __c within
1672 * this string. If found, returns the index where it was
1673 * found. If not found, returns npos.
1676 rfind(_CharT __c, size_type __pos = npos) const _GLIBCXX_NOEXCEPT;
1679 * @brief Find position of a character of string.
1680 * @param __str String containing characters to locate.
1681 * @param __pos Index of character to search from (default 0).
1682 * @return Index of first occurrence.
1684 * Starting from @a __pos, searches forward for one of the characters of
1685 * @a __str within this string. If found, returns the index where it was
1686 * found. If not found, returns npos.
1689 find_first_of(const __versa_string& __str, size_type __pos = 0) const
1691 { return this->find_first_of(__str.data(), __pos, __str.size()); }
1694 * @brief Find position of a character of C substring.
1695 * @param __s String containing characters to locate.
1696 * @param __pos Index of character to search from.
1697 * @param __n Number of characters from s to search for.
1698 * @return Index of first occurrence.
1700 * Starting from @a __pos, searches forward for one of the
1701 * first @a __n characters of @a __s within this string. If
1702 * found, returns the index where it was found. If not found,
1706 find_first_of(const _CharT* __s, size_type __pos, size_type __n) const;
1709 * @brief Find position of a character of C string.
1710 * @param __s String containing characters to locate.
1711 * @param __pos Index of character to search from (default 0).
1712 * @return Index of first occurrence.
1714 * Starting from @a __pos, searches forward for one of the
1715 * characters of @a __s within this string. If found, returns
1716 * the index where it was found. If not found, returns npos.
1719 find_first_of(const _CharT* __s, size_type __pos = 0) const
1721 __glibcxx_requires_string(__s);
1722 return this->find_first_of(__s, __pos, traits_type::length(__s));
1726 * @brief Find position of a character.
1727 * @param __c Character to locate.
1728 * @param __pos Index of character to search from (default 0).
1729 * @return Index of first occurrence.
1731 * Starting from @a __pos, searches forward for the character
1732 * @a __c within this string. If found, returns the index
1733 * where it was found. If not found, returns npos.
1735 * Note: equivalent to find(c, pos).
1738 find_first_of(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT
1739 { return this->find(__c, __pos); }
1742 * @brief Find last position of a character of string.
1743 * @param __str String containing characters to locate.
1744 * @param __pos Index of character to search back from (default end).
1745 * @return Index of last occurrence.
1747 * Starting from @a __pos, searches backward for one of the
1748 * characters of @a __str within this string. If found,
1749 * returns the index where it was found. If not found, returns
1753 find_last_of(const __versa_string& __str, size_type __pos = npos) const
1755 { return this->find_last_of(__str.data(), __pos, __str.size()); }
1758 * @brief Find last position of a character of C substring.
1759 * @param __s C string containing characters to locate.
1760 * @param __pos Index of character to search back from.
1761 * @param __n Number of characters from s to search for.
1762 * @return Index of last occurrence.
1764 * Starting from @a __pos, searches backward for one of the
1765 * first @a __n characters of @a __s within this string. If
1766 * found, returns the index where it was found. If not found,
1770 find_last_of(const _CharT* __s, size_type __pos, size_type __n) const;
1773 * @brief Find last position of a character of C string.
1774 * @param __s C string containing characters to locate.
1775 * @param __pos Index of character to search back from (default end).
1776 * @return Index of last occurrence.
1778 * Starting from @a __pos, searches backward for one of the
1779 * characters of @a __s within this string. If found, returns
1780 * the index where it was found. If not found, returns npos.
1783 find_last_of(const _CharT* __s, size_type __pos = npos) const
1785 __glibcxx_requires_string(__s);
1786 return this->find_last_of(__s, __pos, traits_type::length(__s));
1790 * @brief Find last position of a character.
1791 * @param __c Character to locate.
1792 * @param __pos Index of character to search back from (default end).
1793 * @return Index of last occurrence.
1795 * Starting from @a __pos, searches backward for @a __c within
1796 * this string. If found, returns the index where it was
1797 * found. If not found, returns npos.
1799 * Note: equivalent to rfind(c, pos).
1802 find_last_of(_CharT __c, size_type __pos = npos) const _GLIBCXX_NOEXCEPT
1803 { return this->rfind(__c, __pos); }
1806 * @brief Find position of a character not in string.
1807 * @param __str String containing characters to avoid.
1808 * @param __pos Index of character to search from (default 0).
1809 * @return Index of first occurrence.
1811 * Starting from @a __pos, searches forward for a character not
1812 * contained in @a __str within this string. If found, returns
1813 * the index where it was found. If not found, returns npos.
1816 find_first_not_of(const __versa_string& __str, size_type __pos = 0) const
1818 { return this->find_first_not_of(__str.data(), __pos, __str.size()); }
1821 * @brief Find position of a character not in C substring.
1822 * @param __s C string containing characters to avoid.
1823 * @param __pos Index of character to search from.
1824 * @param __n Number of characters from s to consider.
1825 * @return Index of first occurrence.
1827 * Starting from @a __pos, searches forward for a character not
1828 * contained in the first @a __n characters of @a __s within
1829 * this string. If found, returns the index where it was
1830 * found. If not found, returns npos.
1833 find_first_not_of(const _CharT* __s, size_type __pos,
1834 size_type __n) const;
1837 * @brief Find position of a character not in C string.
1838 * @param __s C string containing characters to avoid.
1839 * @param __pos Index of character to search from (default 0).
1840 * @return Index of first occurrence.
1842 * Starting from @a __pos, searches forward for a character not
1843 * contained in @a __s within this string. If found, returns
1844 * the index where it was found. If not found, returns npos.
1847 find_first_not_of(const _CharT* __s, size_type __pos = 0) const
1849 __glibcxx_requires_string(__s);
1850 return this->find_first_not_of(__s, __pos, traits_type::length(__s));
1854 * @brief Find position of a different character.
1855 * @param __c Character to avoid.
1856 * @param __pos Index of character to search from (default 0).
1857 * @return Index of first occurrence.
1859 * Starting from @a __pos, searches forward for a character
1860 * other than @a __c within this string. If found, returns the
1861 * index where it was found. If not found, returns npos.
1864 find_first_not_of(_CharT __c, size_type __pos = 0) const
1868 * @brief Find last position of a character not in string.
1869 * @param __str String containing characters to avoid.
1870 * @param __pos Index of character to search back from (default end).
1871 * @return Index of last occurrence.
1873 * Starting from @a __pos, searches backward for a character
1874 * not contained in @a __str within this string. If found,
1875 * returns the index where it was found. If not found, returns
1879 find_last_not_of(const __versa_string& __str,
1880 size_type __pos = npos) const _GLIBCXX_NOEXCEPT
1881 { return this->find_last_not_of(__str.data(), __pos, __str.size()); }
1884 * @brief Find last position of a character not in C substring.
1885 * @param __s C string containing characters to avoid.
1886 * @param __pos Index of character to search back from.
1887 * @param __n Number of characters from s to consider.
1888 * @return Index of last occurrence.
1890 * Starting from @a __pos, searches backward for a character
1891 * not contained in the first @a __n characters of @a __s
1892 * within this string. If found, returns the index where it
1893 * was found. If not found, returns npos.
1896 find_last_not_of(const _CharT* __s, size_type __pos,
1897 size_type __n) const;
1899 * @brief Find last position of a character not in C string.
1900 * @param __s C string containing characters to avoid.
1901 * @param __pos Index of character to search back from (default end).
1902 * @return Index of last occurrence.
1904 * Starting from @a __pos, searches backward for a character
1905 * not contained in @a __s within this string. If found,
1906 * returns the index where it was found. If not found, returns
1910 find_last_not_of(const _CharT* __s, size_type __pos = npos) const
1912 __glibcxx_requires_string(__s);
1913 return this->find_last_not_of(__s, __pos, traits_type::length(__s));
1917 * @brief Find last position of a different character.
1918 * @param __c Character to avoid.
1919 * @param __pos Index of character to search back from (default end).
1920 * @return Index of last occurrence.
1922 * Starting from @a __pos, searches backward for a character
1923 * other than @a __c within this string. If found, returns the
1924 * index where it was found. If not found, returns npos.
1927 find_last_not_of(_CharT __c, size_type __pos = npos) const
1931 * @brief Get a substring.
1932 * @param __pos Index of first character (default 0).
1933 * @param __n Number of characters in substring (default remainder).
1934 * @return The new string.
1935 * @throw std::out_of_range If pos > size().
1937 * Construct and return a new string using the @a __n
1938 * characters starting at @a __pos. If the string is too
1939 * short, use the remainder of the characters. If @a __pos is
1940 * beyond the end of the string, out_of_range is thrown.
1943 substr(size_type __pos = 0, size_type __n = npos) const
1945 return __versa_string(*this, _M_check(__pos, "__versa_string::substr"),
1950 * @brief Compare to a string.
1951 * @param __str String to compare against.
1952 * @return Integer < 0, 0, or > 0.
1954 * Returns an integer < 0 if this string is ordered before @a
1955 * __str, 0 if their values are equivalent, or > 0 if this
1956 * string is ordered after @a __str. Determines the effective
1957 * length rlen of the strings to compare as the smallest of
1958 * size() and str.size(). The function then compares the two
1959 * strings by calling traits::compare(data(), str.data(),rlen).
1960 * If the result of the comparison is nonzero returns it,
1961 * otherwise the shorter one is ordered first.
1964 compare(const __versa_string& __str) const
1966 if (this->_M_compare(__str))
1969 const size_type __size = this->size();
1970 const size_type __osize = __str.size();
1971 const size_type __len = std::min(__size, __osize);
1973 int __r = traits_type::compare(this->_M_data(), __str.data(), __len);
1975 __r = this->_S_compare(__size, __osize);
1980 * @brief Compare substring to a string.
1981 * @param __pos Index of first character of substring.
1982 * @param __n Number of characters in substring.
1983 * @param __str String to compare against.
1984 * @return Integer < 0, 0, or > 0.
1986 * Form the substring of this string from the @a __n characters
1987 * starting at @a __pos. Returns an integer < 0 if the
1988 * substring is ordered before @a __str, 0 if their values are
1989 * equivalent, or > 0 if the substring is ordered after @a
1990 * __str. Determines the effective length rlen of the strings
1991 * to compare as the smallest of the length of the substring
1992 * and @a __str.size(). The function then compares the two
1993 * strings by calling
1994 * traits::compare(substring.data(),str.data(),rlen). If the
1995 * result of the comparison is nonzero returns it, otherwise
1996 * the shorter one is ordered first.
1999 compare(size_type __pos, size_type __n,
2000 const __versa_string& __str) const;
2003 * @brief Compare substring to a substring.
2004 * @param __pos1 Index of first character of substring.
2005 * @param __n1 Number of characters in substring.
2006 * @param __str String to compare against.
2007 * @param __pos2 Index of first character of substring of str.
2008 * @param __n2 Number of characters in substring of str.
2009 * @return Integer < 0, 0, or > 0.
2011 * Form the substring of this string from the @a __n1
2012 * characters starting at @a __pos1. Form the substring of @a
2013 * __str from the @a __n2 characters starting at @a __pos2.
2014 * Returns an integer < 0 if this substring is ordered before
2015 * the substring of @a __str, 0 if their values are equivalent,
2016 * or > 0 if this substring is ordered after the substring of
2017 * @a __str. Determines the effective length rlen of the
2018 * strings to compare as the smallest of the lengths of the
2019 * substrings. The function then compares the two strings by
2021 * traits::compare(substring.data(),str.substr(pos2,n2).data(),rlen).
2022 * If the result of the comparison is nonzero returns it,
2023 * otherwise the shorter one is ordered first.
2026 compare(size_type __pos1, size_type __n1, const __versa_string& __str,
2027 size_type __pos2, size_type __n2) const;
2030 * @brief Compare to a C string.
2031 * @param __s C string to compare against.
2032 * @return Integer < 0, 0, or > 0.
2034 * Returns an integer < 0 if this string is ordered before @a
2035 * __s, 0 if their values are equivalent, or > 0 if this string
2036 * is ordered after @a __s. Determines the effective length
2037 * rlen of the strings to compare as the smallest of size() and
2038 * the length of a string constructed from @a __s. The
2039 * function then compares the two strings by calling
2040 * traits::compare(data(),s,rlen). If the result of the
2041 * comparison is nonzero returns it, otherwise the shorter one
2045 compare(const _CharT* __s) const;
2047 // _GLIBCXX_RESOLVE_LIB_DEFECTS
2048 // 5 String::compare specification questionable
2050 * @brief Compare substring to a C string.
2051 * @param __pos Index of first character of substring.
2052 * @param __n1 Number of characters in substring.
2053 * @param __s C string to compare against.
2054 * @return Integer < 0, 0, or > 0.
2056 * Form the substring of this string from the @a __n1
2057 * characters starting at @a __pos. Returns an integer < 0 if
2058 * the substring is ordered before @a __s, 0 if their values
2059 * are equivalent, or > 0 if the substring is ordered after @a
2060 * __s. Determines the effective length rlen of the strings to
2061 * compare as the smallest of the length of the substring and
2062 * the length of a string constructed from @a __s. The
2063 * function then compares the two string by calling
2064 * traits::compare(substring.data(),s,rlen). If the result of
2065 * the comparison is nonzero returns it, otherwise the shorter
2066 * one is ordered first.
2069 compare(size_type __pos, size_type __n1, const _CharT* __s) const;
2072 * @brief Compare substring against a character array.
2073 * @param __pos Index of first character of substring.
2074 * @param __n1 Number of characters in substring.
2075 * @param __s character array to compare against.
2076 * @param __n2 Number of characters of s.
2077 * @return Integer < 0, 0, or > 0.
2079 * Form the substring of this string from the @a __n1
2080 * characters starting at @a __pos. Form a string from the
2081 * first @a __n2 characters of @a __s. Returns an integer < 0
2082 * if this substring is ordered before the string from @a __s,
2083 * 0 if their values are equivalent, or > 0 if this substring
2084 * is ordered after the string from @a __s. Determines the
2085 * effective length rlen of the strings to compare as the
2086 * smallest of the length of the substring and @a __n2. The
2087 * function then compares the two strings by calling
2088 * traits::compare(substring.data(),__s,rlen). If the result of
2089 * the comparison is nonzero returns it, otherwise the shorter
2090 * one is ordered first.
2092 * NB: __s must have at least n2 characters, <em>\\0</em> has no special
2096 compare(size_type __pos, size_type __n1, const _CharT* __s,
2097 size_type __n2) const;
2102 * @brief Concatenate two strings.
2103 * @param __lhs First string.
2104 * @param __rhs Last string.
2105 * @return New string with value of @a __lhs followed by @a __rhs.
2107 template<typename _CharT, typename _Traits, typename _Alloc,
2108 template <typename, typename, typename> class _Base>
2109 __versa_string<_CharT, _Traits, _Alloc, _Base>
2110 operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2111 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs);
2114 * @brief Concatenate C string and string.
2115 * @param __lhs First string.
2116 * @param __rhs Last string.
2117 * @return New string with value of @a __lhs followed by @a __rhs.
2119 template<typename _CharT, typename _Traits, typename _Alloc,
2120 template <typename, typename, typename> class _Base>
2121 __versa_string<_CharT, _Traits, _Alloc, _Base>
2122 operator+(const _CharT* __lhs,
2123 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs);
2126 * @brief Concatenate character and string.
2127 * @param __lhs First string.
2128 * @param __rhs Last string.
2129 * @return New string with @a __lhs followed by @a __rhs.
2131 template<typename _CharT, typename _Traits, typename _Alloc,
2132 template <typename, typename, typename> class _Base>
2133 __versa_string<_CharT, _Traits, _Alloc, _Base>
2134 operator+(_CharT __lhs,
2135 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs);
2138 * @brief Concatenate string and C string.
2139 * @param __lhs First string.
2140 * @param __rhs Last string.
2141 * @return New string with @a __lhs followed by @a __rhs.
2143 template<typename _CharT, typename _Traits, typename _Alloc,
2144 template <typename, typename, typename> class _Base>
2145 __versa_string<_CharT, _Traits, _Alloc, _Base>
2146 operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2147 const _CharT* __rhs);
2150 * @brief Concatenate string and character.
2151 * @param __lhs First string.
2152 * @param __rhs Last string.
2153 * @return New string with @a __lhs followed by @a __rhs.
2155 template<typename _CharT, typename _Traits, typename _Alloc,
2156 template <typename, typename, typename> class _Base>
2157 __versa_string<_CharT, _Traits, _Alloc, _Base>
2158 operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2161 #if __cplusplus >= 201103L
2162 template<typename _CharT, typename _Traits, typename _Alloc,
2163 template <typename, typename, typename> class _Base>
2164 inline __versa_string<_CharT, _Traits, _Alloc, _Base>
2165 operator+(__versa_string<_CharT, _Traits, _Alloc, _Base>&& __lhs,
2166 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2167 { return std::move(__lhs.append(__rhs)); }
2169 template<typename _CharT, typename _Traits, typename _Alloc,
2170 template <typename, typename, typename> class _Base>
2171 inline __versa_string<_CharT, _Traits, _Alloc, _Base>
2172 operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2173 __versa_string<_CharT, _Traits, _Alloc, _Base>&& __rhs)
2174 { return std::move(__rhs.insert(0, __lhs)); }
2176 template<typename _CharT, typename _Traits, typename _Alloc,
2177 template <typename, typename, typename> class _Base>
2178 inline __versa_string<_CharT, _Traits, _Alloc, _Base>
2179 operator+(__versa_string<_CharT, _Traits, _Alloc, _Base>&& __lhs,
2180 __versa_string<_CharT, _Traits, _Alloc, _Base>&& __rhs)
2182 const auto __size = __lhs.size() + __rhs.size();
2183 const bool __cond = (__size > __lhs.capacity()
2184 && __size <= __rhs.capacity());
2185 return __cond ? std::move(__rhs.insert(0, __lhs))
2186 : std::move(__lhs.append(__rhs));
2189 template<typename _CharT, typename _Traits, typename _Alloc,
2190 template <typename, typename, typename> class _Base>
2191 inline __versa_string<_CharT, _Traits, _Alloc, _Base>
2192 operator+(const _CharT* __lhs,
2193 __versa_string<_CharT, _Traits, _Alloc, _Base>&& __rhs)
2194 { return std::move(__rhs.insert(0, __lhs)); }
2196 template<typename _CharT, typename _Traits, typename _Alloc,
2197 template <typename, typename, typename> class _Base>
2198 inline __versa_string<_CharT, _Traits, _Alloc, _Base>
2199 operator+(_CharT __lhs,
2200 __versa_string<_CharT, _Traits, _Alloc, _Base>&& __rhs)
2201 { return std::move(__rhs.insert(0, 1, __lhs)); }
2203 template<typename _CharT, typename _Traits, typename _Alloc,
2204 template <typename, typename, typename> class _Base>
2205 inline __versa_string<_CharT, _Traits, _Alloc, _Base>
2206 operator+(__versa_string<_CharT, _Traits, _Alloc, _Base>&& __lhs,
2207 const _CharT* __rhs)
2208 { return std::move(__lhs.append(__rhs)); }
2210 template<typename _CharT, typename _Traits, typename _Alloc,
2211 template <typename, typename, typename> class _Base>
2212 inline __versa_string<_CharT, _Traits, _Alloc, _Base>
2213 operator+(__versa_string<_CharT, _Traits, _Alloc, _Base>&& __lhs,
2215 { return std::move(__lhs.append(1, __rhs)); }
2220 * @brief Test equivalence of two strings.
2221 * @param __lhs First string.
2222 * @param __rhs Second string.
2223 * @return True if @a __lhs.compare(@a __rhs) == 0. False otherwise.
2225 template<typename _CharT, typename _Traits, typename _Alloc,
2226 template <typename, typename, typename> class _Base>
2228 operator==(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2229 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2230 { return __lhs.compare(__rhs) == 0; }
2232 template<typename _CharT,
2233 template <typename, typename, typename> class _Base>
2234 inline typename __enable_if<std::__is_char<_CharT>::__value, bool>::__type
2235 operator==(const __versa_string<_CharT, std::char_traits<_CharT>,
2236 std::allocator<_CharT>, _Base>& __lhs,
2237 const __versa_string<_CharT, std::char_traits<_CharT>,
2238 std::allocator<_CharT>, _Base>& __rhs)
2239 { return (__lhs.size() == __rhs.size()
2240 && !std::char_traits<_CharT>::compare(__lhs.data(), __rhs.data(),
2244 * @brief Test equivalence of C string and string.
2245 * @param __lhs C string.
2246 * @param __rhs String.
2247 * @return True if @a __rhs.compare(@a __lhs) == 0. False otherwise.
2249 template<typename _CharT, typename _Traits, typename _Alloc,
2250 template <typename, typename, typename> class _Base>
2252 operator==(const _CharT* __lhs,
2253 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2254 { return __rhs.compare(__lhs) == 0; }
2257 * @brief Test equivalence of string and C string.
2258 * @param __lhs String.
2259 * @param __rhs C string.
2260 * @return True if @a __lhs.compare(@a __rhs) == 0. False otherwise.
2262 template<typename _CharT, typename _Traits, typename _Alloc,
2263 template <typename, typename, typename> class _Base>
2265 operator==(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2266 const _CharT* __rhs)
2267 { return __lhs.compare(__rhs) == 0; }
2271 * @brief Test difference of two strings.
2272 * @param __lhs First string.
2273 * @param __rhs Second string.
2274 * @return True if @a __lhs.compare(@a __rhs) != 0. False otherwise.
2276 template<typename _CharT, typename _Traits, typename _Alloc,
2277 template <typename, typename, typename> class _Base>
2279 operator!=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2280 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2281 { return !(__lhs == __rhs); }
2284 * @brief Test difference of C string and string.
2285 * @param __lhs C string.
2286 * @param __rhs String.
2287 * @return True if @a __rhs.compare(@a __lhs) != 0. False otherwise.
2289 template<typename _CharT, typename _Traits, typename _Alloc,
2290 template <typename, typename, typename> class _Base>
2292 operator!=(const _CharT* __lhs,
2293 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2294 { return !(__lhs == __rhs); }
2297 * @brief Test difference of string and C string.
2298 * @param __lhs String.
2299 * @param __rhs C string.
2300 * @return True if @a __lhs.compare(@a __rhs) != 0. False otherwise.
2302 template<typename _CharT, typename _Traits, typename _Alloc,
2303 template <typename, typename, typename> class _Base>
2305 operator!=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2306 const _CharT* __rhs)
2307 { return !(__lhs == __rhs); }
2311 * @brief Test if string precedes string.
2312 * @param __lhs First string.
2313 * @param __rhs Second string.
2314 * @return True if @a __lhs precedes @a __rhs. False otherwise.
2316 template<typename _CharT, typename _Traits, typename _Alloc,
2317 template <typename, typename, typename> class _Base>
2319 operator<(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2320 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2321 { return __lhs.compare(__rhs) < 0; }
2324 * @brief Test if string precedes C string.
2325 * @param __lhs String.
2326 * @param __rhs C string.
2327 * @return True if @a __lhs precedes @a __rhs. False otherwise.
2329 template<typename _CharT, typename _Traits, typename _Alloc,
2330 template <typename, typename, typename> class _Base>
2332 operator<(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2333 const _CharT* __rhs)
2334 { return __lhs.compare(__rhs) < 0; }
2337 * @brief Test if C string precedes string.
2338 * @param __lhs C string.
2339 * @param __rhs String.
2340 * @return True if @a __lhs precedes @a __rhs. False otherwise.
2342 template<typename _CharT, typename _Traits, typename _Alloc,
2343 template <typename, typename, typename> class _Base>
2345 operator<(const _CharT* __lhs,
2346 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2347 { return __rhs.compare(__lhs) > 0; }
2351 * @brief Test if string follows string.
2352 * @param __lhs First string.
2353 * @param __rhs Second string.
2354 * @return True if @a __lhs follows @a __rhs. False otherwise.
2356 template<typename _CharT, typename _Traits, typename _Alloc,
2357 template <typename, typename, typename> class _Base>
2359 operator>(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2360 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2361 { return __lhs.compare(__rhs) > 0; }
2364 * @brief Test if string follows C string.
2365 * @param __lhs String.
2366 * @param __rhs C string.
2367 * @return True if @a __lhs follows @a __rhs. False otherwise.
2369 template<typename _CharT, typename _Traits, typename _Alloc,
2370 template <typename, typename, typename> class _Base>
2372 operator>(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2373 const _CharT* __rhs)
2374 { return __lhs.compare(__rhs) > 0; }
2377 * @brief Test if C string follows string.
2378 * @param __lhs C string.
2379 * @param __rhs String.
2380 * @return True if @a __lhs follows @a __rhs. False otherwise.
2382 template<typename _CharT, typename _Traits, typename _Alloc,
2383 template <typename, typename, typename> class _Base>
2385 operator>(const _CharT* __lhs,
2386 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2387 { return __rhs.compare(__lhs) < 0; }
2391 * @brief Test if string doesn't follow string.
2392 * @param __lhs First string.
2393 * @param __rhs Second string.
2394 * @return True if @a __lhs doesn't follow @a __rhs. False otherwise.
2396 template<typename _CharT, typename _Traits, typename _Alloc,
2397 template <typename, typename, typename> class _Base>
2399 operator<=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2400 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2401 { return __lhs.compare(__rhs) <= 0; }
2404 * @brief Test if string doesn't follow C string.
2405 * @param __lhs String.
2406 * @param __rhs C string.
2407 * @return True if @a __lhs doesn't follow @a __rhs. False otherwise.
2409 template<typename _CharT, typename _Traits, typename _Alloc,
2410 template <typename, typename, typename> class _Base>
2412 operator<=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2413 const _CharT* __rhs)
2414 { return __lhs.compare(__rhs) <= 0; }
2417 * @brief Test if C string doesn't follow string.
2418 * @param __lhs C string.
2419 * @param __rhs String.
2420 * @return True if @a __lhs doesn't follow @a __rhs. False otherwise.
2422 template<typename _CharT, typename _Traits, typename _Alloc,
2423 template <typename, typename, typename> class _Base>
2425 operator<=(const _CharT* __lhs,
2426 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2427 { return __rhs.compare(__lhs) >= 0; }
2431 * @brief Test if string doesn't precede string.
2432 * @param __lhs First string.
2433 * @param __rhs Second string.
2434 * @return True if @a __lhs doesn't precede @a __rhs. False otherwise.
2436 template<typename _CharT, typename _Traits, typename _Alloc,
2437 template <typename, typename, typename> class _Base>
2439 operator>=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2440 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2441 { return __lhs.compare(__rhs) >= 0; }
2444 * @brief Test if string doesn't precede C string.
2445 * @param __lhs String.
2446 * @param __rhs C string.
2447 * @return True if @a __lhs doesn't precede @a __rhs. False otherwise.
2449 template<typename _CharT, typename _Traits, typename _Alloc,
2450 template <typename, typename, typename> class _Base>
2452 operator>=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2453 const _CharT* __rhs)
2454 { return __lhs.compare(__rhs) >= 0; }
2457 * @brief Test if C string doesn't precede string.
2458 * @param __lhs C string.
2459 * @param __rhs String.
2460 * @return True if @a __lhs doesn't precede @a __rhs. False otherwise.
2462 template<typename _CharT, typename _Traits, typename _Alloc,
2463 template <typename, typename, typename> class _Base>
2465 operator>=(const _CharT* __lhs,
2466 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2467 { return __rhs.compare(__lhs) <= 0; }
2470 * @brief Swap contents of two strings.
2471 * @param __lhs First string.
2472 * @param __rhs Second string.
2474 * Exchanges the contents of @a __lhs and @a __rhs in constant time.
2476 template<typename _CharT, typename _Traits, typename _Alloc,
2477 template <typename, typename, typename> class _Base>
2479 swap(__versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2480 __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2481 { __lhs.swap(__rhs); }
2483 _GLIBCXX_END_NAMESPACE_VERSION
2486 namespace std _GLIBCXX_VISIBILITY(default)
2488 _GLIBCXX_BEGIN_NAMESPACE_VERSION
2491 * @brief Read stream into a string.
2492 * @param __is Input stream.
2493 * @param __str Buffer to store into.
2494 * @return Reference to the input stream.
2496 * Stores characters from @a __is into @a __str until whitespace is
2497 * found, the end of the stream is encountered, or str.max_size()
2498 * is reached. If is.width() is non-zero, that is the limit on the
2499 * number of characters stored into @a __str. Any previous
2500 * contents of @a __str are erased.
2502 template<typename _CharT, typename _Traits, typename _Alloc,
2503 template <typename, typename, typename> class _Base>
2504 basic_istream<_CharT, _Traits>&
2505 operator>>(basic_istream<_CharT, _Traits>& __is,
2506 __gnu_cxx::__versa_string<_CharT, _Traits,
2507 _Alloc, _Base>& __str);
2510 * @brief Write string to a stream.
2511 * @param __os Output stream.
2512 * @param __str String to write out.
2513 * @return Reference to the output stream.
2515 * Output characters of @a __str into os following the same rules as for
2516 * writing a C string.
2518 template<typename _CharT, typename _Traits, typename _Alloc,
2519 template <typename, typename, typename> class _Base>
2520 inline basic_ostream<_CharT, _Traits>&
2521 operator<<(basic_ostream<_CharT, _Traits>& __os,
2522 const __gnu_cxx::__versa_string<_CharT, _Traits, _Alloc,
2525 // _GLIBCXX_RESOLVE_LIB_DEFECTS
2526 // 586. string inserter not a formatted function
2527 return __ostream_insert(__os, __str.data(), __str.size());
2531 * @brief Read a line from stream into a string.
2532 * @param __is Input stream.
2533 * @param __str Buffer to store into.
2534 * @param __delim Character marking end of line.
2535 * @return Reference to the input stream.
2537 * Stores characters from @a __is into @a __str until @a __delim is
2538 * found, the end of the stream is encountered, or str.max_size()
2539 * is reached. If is.width() is non-zero, that is the limit on the
2540 * number of characters stored into @a __str. Any previous
2541 * contents of @a __str are erased. If @a delim was encountered,
2542 * it is extracted but not stored into @a __str.
2544 template<typename _CharT, typename _Traits, typename _Alloc,
2545 template <typename, typename, typename> class _Base>
2546 basic_istream<_CharT, _Traits>&
2547 getline(basic_istream<_CharT, _Traits>& __is,
2548 __gnu_cxx::__versa_string<_CharT, _Traits, _Alloc, _Base>& __str,
2552 * @brief Read a line from stream into a string.
2553 * @param __is Input stream.
2554 * @param __str Buffer to store into.
2555 * @return Reference to the input stream.
2557 * Stores characters from is into @a __str until '\n' is
2558 * found, the end of the stream is encountered, or str.max_size()
2559 * is reached. If is.width() is non-zero, that is the limit on the
2560 * number of characters stored into @a __str. Any previous
2561 * contents of @a __str are erased. If end of line was
2562 * encountered, it is extracted but not stored into @a __str.
2564 template<typename _CharT, typename _Traits, typename _Alloc,
2565 template <typename, typename, typename> class _Base>
2566 inline basic_istream<_CharT, _Traits>&
2567 getline(basic_istream<_CharT, _Traits>& __is,
2568 __gnu_cxx::__versa_string<_CharT, _Traits, _Alloc, _Base>& __str)
2569 { return getline(__is, __str, __is.widen('\n')); }
2571 _GLIBCXX_END_NAMESPACE_VERSION
2574 #if ((__cplusplus >= 201103L) && defined(_GLIBCXX_USE_C99))
2576 #include <ext/string_conversions.h>
2578 namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
2580 _GLIBCXX_BEGIN_NAMESPACE_VERSION
2582 // 21.4 Numeric Conversions [string.conversions].
2584 stoi(const __vstring& __str, std::size_t* __idx = 0, int __base = 10)
2585 { return __gnu_cxx::__stoa<long, int>(&std::strtol, "stoi", __str.c_str(),
2589 stol(const __vstring& __str, std::size_t* __idx = 0, int __base = 10)
2590 { return __gnu_cxx::__stoa(&std::strtol, "stol", __str.c_str(),
2593 inline unsigned long
2594 stoul(const __vstring& __str, std::size_t* __idx = 0, int __base = 10)
2595 { return __gnu_cxx::__stoa(&std::strtoul, "stoul", __str.c_str(),
2599 stoll(const __vstring& __str, std::size_t* __idx = 0, int __base = 10)
2600 { return __gnu_cxx::__stoa(&std::strtoll, "stoll", __str.c_str(),
2603 inline unsigned long long
2604 stoull(const __vstring& __str, std::size_t* __idx, int __base = 10)
2605 { return __gnu_cxx::__stoa(&std::strtoull, "stoull", __str.c_str(),
2608 // NB: strtof vs strtod.
2610 stof(const __vstring& __str, std::size_t* __idx = 0)
2611 { return __gnu_cxx::__stoa(&std::strtof, "stof", __str.c_str(), __idx); }
2614 stod(const __vstring& __str, std::size_t* __idx = 0)
2615 { return __gnu_cxx::__stoa(&std::strtod, "stod", __str.c_str(), __idx); }
2618 stold(const __vstring& __str, std::size_t* __idx = 0)
2619 { return __gnu_cxx::__stoa(&std::strtold, "stold", __str.c_str(), __idx); }
2621 // NB: (v)snprintf vs sprintf.
2625 to_string(int __val)
2626 { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, 4 * sizeof(int),
2630 to_string(unsigned __val)
2631 { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf,
2632 4 * sizeof(unsigned),
2636 to_string(long __val)
2637 { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf,
2642 to_string(unsigned long __val)
2643 { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf,
2644 4 * sizeof(unsigned long),
2649 to_string(long long __val)
2650 { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf,
2651 4 * sizeof(long long),
2655 to_string(unsigned long long __val)
2656 { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf,
2657 4 * sizeof(unsigned long long),
2661 to_string(float __val)
2663 const int __n = __numeric_traits<float>::__max_exponent10 + 20;
2664 return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, __n,
2669 to_string(double __val)
2671 const int __n = __numeric_traits<double>::__max_exponent10 + 20;
2672 return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, __n,
2677 to_string(long double __val)
2679 const int __n = __numeric_traits<long double>::__max_exponent10 + 20;
2680 return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, __n,
2684 #ifdef _GLIBCXX_USE_WCHAR_T
2686 stoi(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10)
2687 { return __gnu_cxx::__stoa<long, int>(&std::wcstol, "stoi", __str.c_str(),
2691 stol(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10)
2692 { return __gnu_cxx::__stoa(&std::wcstol, "stol", __str.c_str(),
2695 inline unsigned long
2696 stoul(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10)
2697 { return __gnu_cxx::__stoa(&std::wcstoul, "stoul", __str.c_str(),
2701 stoll(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10)
2702 { return __gnu_cxx::__stoa(&std::wcstoll, "stoll", __str.c_str(),
2705 inline unsigned long long
2706 stoull(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10)
2707 { return __gnu_cxx::__stoa(&std::wcstoull, "stoull", __str.c_str(),
2710 // NB: wcstof vs wcstod.
2712 stof(const __wvstring& __str, std::size_t* __idx = 0)
2713 { return __gnu_cxx::__stoa(&std::wcstof, "stof", __str.c_str(), __idx); }
2716 stod(const __wvstring& __str, std::size_t* __idx = 0)
2717 { return __gnu_cxx::__stoa(&std::wcstod, "stod", __str.c_str(), __idx); }
2720 stold(const __wvstring& __str, std::size_t* __idx = 0)
2721 { return __gnu_cxx::__stoa(&std::wcstold, "stold", __str.c_str(), __idx); }
2723 #ifndef _GLIBCXX_HAVE_BROKEN_VSWPRINTF
2726 to_wstring(int __val)
2727 { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
2732 to_wstring(unsigned __val)
2733 { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
2734 4 * sizeof(unsigned),
2738 to_wstring(long __val)
2739 { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
2744 to_wstring(unsigned long __val)
2745 { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
2746 4 * sizeof(unsigned long),
2750 to_wstring(long long __val)
2751 { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
2752 4 * sizeof(long long),
2756 to_wstring(unsigned long long __val)
2757 { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
2758 4 * sizeof(unsigned long long),
2762 to_wstring(float __val)
2764 const int __n = __numeric_traits<float>::__max_exponent10 + 20;
2765 return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, __n,
2770 to_wstring(double __val)
2772 const int __n = __numeric_traits<double>::__max_exponent10 + 20;
2773 return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, __n,
2778 to_wstring(long double __val)
2780 const int __n = __numeric_traits<long double>::__max_exponent10 + 20;
2781 return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, __n,
2787 _GLIBCXX_END_NAMESPACE_VERSION
2792 #if __cplusplus >= 201103L
2794 #include <bits/functional_hash.h>
2796 namespace std _GLIBCXX_VISIBILITY(default)
2798 _GLIBCXX_BEGIN_NAMESPACE_VERSION
2800 /// std::hash specialization for __vstring.
2802 struct hash<__gnu_cxx::__vstring>
2803 : public __hash_base<size_t, __gnu_cxx::__vstring>
2806 operator()(const __gnu_cxx::__vstring& __s) const noexcept
2807 { return std::_Hash_impl::hash(__s.data(), __s.length()); }
2810 #ifdef _GLIBCXX_USE_WCHAR_T
2811 /// std::hash specialization for __wvstring.
2813 struct hash<__gnu_cxx::__wvstring>
2814 : public __hash_base<size_t, __gnu_cxx::__wvstring>
2817 operator()(const __gnu_cxx::__wvstring& __s) const noexcept
2818 { return std::_Hash_impl::hash(__s.data(),
2819 __s.length() * sizeof(wchar_t)); }
2823 #ifdef _GLIBCXX_USE_C99_STDINT_TR1
2824 /// std::hash specialization for __u16vstring.
2826 struct hash<__gnu_cxx::__u16vstring>
2827 : public __hash_base<size_t, __gnu_cxx::__u16vstring>
2830 operator()(const __gnu_cxx::__u16vstring& __s) const noexcept
2831 { return std::_Hash_impl::hash(__s.data(),
2832 __s.length() * sizeof(char16_t)); }
2835 /// std::hash specialization for __u32vstring.
2837 struct hash<__gnu_cxx::__u32vstring>
2838 : public __hash_base<size_t, __gnu_cxx::__u32vstring>
2841 operator()(const __gnu_cxx::__u32vstring& __s) const noexcept
2842 { return std::_Hash_impl::hash(__s.data(),
2843 __s.length() * sizeof(char32_t)); }
2847 _GLIBCXX_END_NAMESPACE_VERSION
2852 #include "vstring.tcc"
2854 #endif /* _VSTRING_H */