1 // Versatile string -*- C++ -*-
3 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011
4 // Free Software Foundation, Inc.
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 3, or (at your option)
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // Under Section 7 of GPL version 3, you are granted additional
18 // permissions described in the GCC Runtime Library Exception, version
19 // 3.1, as published by the Free Software Foundation.
21 // You should have received a copy of the GNU General Public License and
22 // a copy of the GCC Runtime Library Exception along with this program;
23 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 // <http://www.gnu.org/licenses/>.
26 /** @file ext/vstring.h
27 * This file is a GNU extension to the Standard C++ Library.
33 #pragma GCC system_header
35 #ifdef __GXX_EXPERIMENTAL_CXX0X__
36 #include <initializer_list>
39 #include <ext/vstring_util.h>
40 #include <ext/rc_string_base.h>
41 #include <ext/sso_string_base.h>
43 namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
45 _GLIBCXX_BEGIN_NAMESPACE_VERSION
48 * @class __versa_string vstring.h
49 * @brief Template class __versa_string.
52 * Data structure managing sequences of characters and
53 * character-like objects.
55 template<typename _CharT, typename _Traits, typename _Alloc,
56 template <typename, typename, typename> class _Base>
58 : private _Base<_CharT, _Traits, _Alloc>
60 typedef _Base<_CharT, _Traits, _Alloc> __vstring_base;
61 typedef typename __vstring_base::_CharT_alloc_type _CharT_alloc_type;
65 typedef _Traits traits_type;
66 typedef typename _Traits::char_type value_type;
67 typedef _Alloc allocator_type;
68 typedef typename _CharT_alloc_type::size_type size_type;
69 typedef typename _CharT_alloc_type::difference_type difference_type;
70 typedef value_type& reference;
71 typedef const value_type& const_reference;
72 typedef typename _CharT_alloc_type::pointer pointer;
73 typedef typename _CharT_alloc_type::const_pointer const_pointer;
74 typedef __gnu_cxx::__normal_iterator<pointer, __versa_string> iterator;
75 typedef __gnu_cxx::__normal_iterator<const_pointer, __versa_string>
77 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
78 typedef std::reverse_iterator<iterator> reverse_iterator;
80 // Data Member (public):
81 /// Value returned by various member functions when they fail.
82 static const size_type npos = static_cast<size_type>(-1);
86 _M_check(size_type __pos, const char* __s) const
88 if (__pos > this->size())
89 std::__throw_out_of_range(__N(__s));
94 _M_check_length(size_type __n1, size_type __n2, const char* __s) const
96 if (this->max_size() - (this->size() - __n1) < __n2)
97 std::__throw_length_error(__N(__s));
100 // NB: _M_limit doesn't check for a bad __pos value.
102 _M_limit(size_type __pos, size_type __off) const
104 const bool __testoff = __off < this->size() - __pos;
105 return __testoff ? __off : this->size() - __pos;
108 // True if _Rep and source do not overlap.
110 _M_disjunct(const _CharT* __s) const
112 return (std::less<const _CharT*>()(__s, this->_M_data())
113 || std::less<const _CharT*>()(this->_M_data()
114 + this->size(), __s));
117 // For the internal use we have functions similar to `begin'/`end'
118 // but they do not call _M_leak.
121 { return iterator(this->_M_data()); }
125 { return iterator(this->_M_data() + this->_M_length()); }
128 // Construct/copy/destroy:
129 // NB: We overload ctors in some cases instead of using default
130 // arguments, per 17.4.4.4 para. 2 item 2.
133 * @brief Default constructor creates an empty string.
136 : __vstring_base() { }
139 * @brief Construct an empty string using allocator @a a.
142 __versa_string(const _Alloc& __a)
143 : __vstring_base(__a) { }
145 // NB: per LWG issue 42, semantics different from IS:
147 * @brief Construct string with copy of value of @a __str.
148 * @param __str Source string.
150 __versa_string(const __versa_string& __str)
151 : __vstring_base(__str) { }
153 #ifdef __GXX_EXPERIMENTAL_CXX0X__
155 * @brief String move constructor.
156 * @param __str Source string.
158 * The newly-constructed %string contains the exact contents of
159 * @a __str. The contents of @a __str are a valid, but unspecified
162 __versa_string(__versa_string&& __str) noexcept
163 : __vstring_base(std::move(__str)) { }
166 * @brief Construct string from an initializer list.
167 * @param __l std::initializer_list of characters.
168 * @param __a Allocator to use (default is default allocator).
170 __versa_string(std::initializer_list<_CharT> __l,
171 const _Alloc& __a = _Alloc())
172 : __vstring_base(__l.begin(), __l.end(), __a) { }
176 * @brief Construct string as copy of a substring.
177 * @param __str Source string.
178 * @param __pos Index of first character to copy from.
179 * @param __n Number of characters to copy (default remainder).
181 __versa_string(const __versa_string& __str, size_type __pos,
182 size_type __n = npos)
183 : __vstring_base(__str._M_data()
184 + __str._M_check(__pos,
185 "__versa_string::__versa_string"),
186 __str._M_data() + __str._M_limit(__pos, __n)
187 + __pos, _Alloc()) { }
190 * @brief Construct string as copy of a substring.
191 * @param __str Source string.
192 * @param __pos Index of first character to copy from.
193 * @param __n Number of characters to copy.
194 * @param __a Allocator to use.
196 __versa_string(const __versa_string& __str, size_type __pos,
197 size_type __n, const _Alloc& __a)
198 : __vstring_base(__str._M_data()
199 + __str._M_check(__pos,
200 "__versa_string::__versa_string"),
201 __str._M_data() + __str._M_limit(__pos, __n)
205 * @brief Construct string initialized by a character array.
206 * @param __s Source character array.
207 * @param __n Number of characters to copy.
208 * @param __a Allocator to use (default is default allocator).
210 * NB: @a __s must have at least @a __n characters, '\\0' has no special
213 __versa_string(const _CharT* __s, size_type __n,
214 const _Alloc& __a = _Alloc())
215 : __vstring_base(__s, __s + __n, __a) { }
218 * @brief Construct string as copy of a C string.
219 * @param __s Source C string.
220 * @param __a Allocator to use (default is default allocator).
222 __versa_string(const _CharT* __s, const _Alloc& __a = _Alloc())
223 : __vstring_base(__s, __s ? __s + traits_type::length(__s) :
227 * @brief Construct string as multiple characters.
228 * @param __n Number of characters.
229 * @param __c Character to use.
230 * @param __a Allocator to use (default is default allocator).
232 __versa_string(size_type __n, _CharT __c, const _Alloc& __a = _Alloc())
233 : __vstring_base(__n, __c, __a) { }
236 * @brief Construct string as copy of a range.
237 * @param __beg Start of range.
238 * @param __end End of range.
239 * @param __a Allocator to use (default is default allocator).
241 template<class _InputIterator>
242 __versa_string(_InputIterator __beg, _InputIterator __end,
243 const _Alloc& __a = _Alloc())
244 : __vstring_base(__beg, __end, __a) { }
247 * @brief Destroy the string instance.
249 ~__versa_string() _GLIBCXX_NOEXCEPT { }
252 * @brief Assign the value of @a str to this string.
253 * @param __str Source string.
256 operator=(const __versa_string& __str)
257 { return this->assign(__str); }
259 #ifdef __GXX_EXPERIMENTAL_CXX0X__
261 * @brief String move assignment operator.
262 * @param __str Source string.
264 * The contents of @a __str are moved into this string (without
265 * copying). @a __str is a valid, but unspecified string.
268 operator=(__versa_string&& __str)
276 * @brief Set value to string constructed from initializer list.
277 * @param __l std::initializer_list.
280 operator=(std::initializer_list<_CharT> __l)
282 this->assign(__l.begin(), __l.end());
288 * @brief Copy contents of @a __s into this string.
289 * @param __s Source null-terminated string.
292 operator=(const _CharT* __s)
293 { return this->assign(__s); }
296 * @brief Set value to string of length 1.
297 * @param __c Source character.
299 * Assigning to a character makes this string length 1 and
300 * (*this)[0] == @a __c.
303 operator=(_CharT __c)
305 this->assign(1, __c);
311 * Returns a read/write iterator that points to the first character in
312 * the %string. Unshares the string.
315 begin() _GLIBCXX_NOEXCEPT
318 return iterator(this->_M_data());
322 * Returns a read-only (constant) iterator that points to the first
323 * character in the %string.
326 begin() const _GLIBCXX_NOEXCEPT
327 { return const_iterator(this->_M_data()); }
330 * Returns a read/write iterator that points one past the last
331 * character in the %string. Unshares the string.
334 end() _GLIBCXX_NOEXCEPT
337 return iterator(this->_M_data() + this->size());
341 * Returns a read-only (constant) iterator that points one past the
342 * last character in the %string.
345 end() const _GLIBCXX_NOEXCEPT
346 { return const_iterator(this->_M_data() + this->size()); }
349 * Returns a read/write reverse iterator that points to the last
350 * character in the %string. Iteration is done in reverse element
351 * order. Unshares the string.
354 rbegin() _GLIBCXX_NOEXCEPT
355 { return reverse_iterator(this->end()); }
358 * Returns a read-only (constant) reverse iterator that points
359 * to the last character in the %string. Iteration is done in
360 * reverse element order.
362 const_reverse_iterator
363 rbegin() const _GLIBCXX_NOEXCEPT
364 { return const_reverse_iterator(this->end()); }
367 * Returns a read/write reverse iterator that points to one before the
368 * first character in the %string. Iteration is done in reverse
369 * element order. Unshares the string.
372 rend() _GLIBCXX_NOEXCEPT
373 { return reverse_iterator(this->begin()); }
376 * Returns a read-only (constant) reverse iterator that points
377 * to one before the first character in the %string. Iteration
378 * is done in reverse element order.
380 const_reverse_iterator
381 rend() const _GLIBCXX_NOEXCEPT
382 { return const_reverse_iterator(this->begin()); }
384 #ifdef __GXX_EXPERIMENTAL_CXX0X__
386 * Returns a read-only (constant) iterator that points to the first
387 * character in the %string.
390 cbegin() const noexcept
391 { return const_iterator(this->_M_data()); }
394 * Returns a read-only (constant) iterator that points one past the
395 * last character in the %string.
398 cend() const noexcept
399 { return const_iterator(this->_M_data() + this->size()); }
402 * Returns a read-only (constant) reverse iterator that points
403 * to the last character in the %string. Iteration is done in
404 * reverse element order.
406 const_reverse_iterator
407 crbegin() const noexcept
408 { return const_reverse_iterator(this->end()); }
411 * Returns a read-only (constant) reverse iterator that points
412 * to one before the first character in the %string. Iteration
413 * is done in reverse element order.
415 const_reverse_iterator
416 crend() const noexcept
417 { return const_reverse_iterator(this->begin()); }
422 /// Returns the number of characters in the string, not including any
423 /// null-termination.
425 size() const _GLIBCXX_NOEXCEPT
426 { return this->_M_length(); }
428 /// Returns the number of characters in the string, not including any
429 /// null-termination.
431 length() const _GLIBCXX_NOEXCEPT
432 { return this->_M_length(); }
434 /// Returns the size() of the largest possible %string.
436 max_size() const _GLIBCXX_NOEXCEPT
437 { return this->_M_max_size(); }
440 * @brief Resizes the %string to the specified number of characters.
441 * @param __n Number of characters the %string should contain.
442 * @param __c Character to fill any new elements.
444 * This function will %resize the %string to the specified
445 * number of characters. If the number is smaller than the
446 * %string's current size the %string is truncated, otherwise
447 * the %string is extended and new elements are set to @a __c.
450 resize(size_type __n, _CharT __c);
453 * @brief Resizes the %string to the specified number of characters.
454 * @param __n Number of characters the %string should contain.
456 * This function will resize the %string to the specified
457 * length. If the new size is smaller than the %string's
458 * current size the %string is truncated, otherwise the %string
459 * is extended and new characters are default-constructed. For
460 * basic types such as char, this means setting them to 0.
463 resize(size_type __n)
464 { this->resize(__n, _CharT()); }
466 #ifdef __GXX_EXPERIMENTAL_CXX0X__
467 /// A non-binding request to reduce capacity() to size().
471 if (capacity() > size())
474 { this->reserve(0); }
482 * Returns the total number of characters that the %string can
483 * hold before needing to allocate more memory.
486 capacity() const _GLIBCXX_NOEXCEPT
487 { return this->_M_capacity(); }
490 * @brief Attempt to preallocate enough memory for specified number of
492 * @param __res_arg Number of characters required.
493 * @throw std::length_error If @a __res_arg exceeds @c max_size().
495 * This function attempts to reserve enough memory for the
496 * %string to hold the specified number of characters. If the
497 * number requested is more than max_size(), length_error is
500 * The advantage of this function is that if optimal code is a
501 * necessity and the user can determine the string length that
502 * will be required, the user can reserve the memory in
503 * %advance, and thus prevent a possible reallocation of memory
504 * and copying of %string data.
507 reserve(size_type __res_arg = 0)
508 { this->_M_reserve(__res_arg); }
511 * Erases the string, making it empty.
514 clear() _GLIBCXX_NOEXCEPT
515 { this->_M_clear(); }
518 * Returns true if the %string is empty. Equivalent to
519 * <code>*this == ""</code>.
522 empty() const _GLIBCXX_NOEXCEPT
523 { return this->size() == 0; }
527 * @brief Subscript access to the data contained in the %string.
528 * @param __pos The index of the character to access.
529 * @return Read-only (constant) reference to the character.
531 * This operator allows for easy, array-style, data access.
532 * Note that data access with this operator is unchecked and
533 * out_of_range lookups are not defined. (For checked lookups
537 operator[] (size_type __pos) const
539 _GLIBCXX_DEBUG_ASSERT(__pos <= this->size());
540 return this->_M_data()[__pos];
544 * @brief Subscript access to the data contained in the %string.
545 * @param __pos The index of the character to access.
546 * @return Read/write reference to the character.
548 * This operator allows for easy, array-style, data access.
549 * Note that data access with this operator is unchecked and
550 * out_of_range lookups are not defined. (For checked lookups
551 * see at().) Unshares the string.
554 operator[](size_type __pos)
556 // allow pos == size() as v3 extension:
557 _GLIBCXX_DEBUG_ASSERT(__pos <= this->size());
558 // but be strict in pedantic mode:
559 _GLIBCXX_DEBUG_PEDASSERT(__pos < this->size());
561 return this->_M_data()[__pos];
565 * @brief Provides access to the data contained in the %string.
566 * @param __n The index of the character to access.
567 * @return Read-only (const) reference to the character.
568 * @throw std::out_of_range If @a __n is an invalid index.
570 * This function provides for safer data access. The parameter
571 * is first checked that it is in the range of the string. The
572 * function throws out_of_range if the check fails.
575 at(size_type __n) const
577 if (__n >= this->size())
578 std::__throw_out_of_range(__N("__versa_string::at"));
579 return this->_M_data()[__n];
583 * @brief Provides access to the data contained in the %string.
584 * @param __n The index of the character to access.
585 * @return Read/write reference to the character.
586 * @throw std::out_of_range If @a __n is an invalid index.
588 * This function provides for safer data access. The parameter
589 * is first checked that it is in the range of the string. The
590 * function throws out_of_range if the check fails. Success
591 * results in unsharing the string.
596 if (__n >= this->size())
597 std::__throw_out_of_range(__N("__versa_string::at"));
599 return this->_M_data()[__n];
602 #ifdef __GXX_EXPERIMENTAL_CXX0X__
604 * Returns a read/write reference to the data at the first
605 * element of the %string.
609 { return operator[](0); }
612 * Returns a read-only (constant) reference to the data at the first
613 * element of the %string.
617 { return operator[](0); }
620 * Returns a read/write reference to the data at the last
621 * element of the %string.
625 { return operator[](this->size() - 1); }
628 * Returns a read-only (constant) reference to the data at the
629 * last element of the %string.
633 { return operator[](this->size() - 1); }
638 * @brief Append a string to this string.
639 * @param __str The string to append.
640 * @return Reference to this string.
643 operator+=(const __versa_string& __str)
644 { return this->append(__str); }
647 * @brief Append a C string.
648 * @param __s The C string to append.
649 * @return Reference to this string.
652 operator+=(const _CharT* __s)
653 { return this->append(__s); }
656 * @brief Append a character.
657 * @param __c The character to append.
658 * @return Reference to this string.
661 operator+=(_CharT __c)
663 this->push_back(__c);
667 #ifdef __GXX_EXPERIMENTAL_CXX0X__
669 * @brief Append an initializer_list of characters.
670 * @param __l The initializer_list of characters to be appended.
671 * @return Reference to this string.
674 operator+=(std::initializer_list<_CharT> __l)
675 { return this->append(__l.begin(), __l.end()); }
676 #endif // __GXX_EXPERIMENTAL_CXX0X__
679 * @brief Append a string to this string.
680 * @param __str The string to append.
681 * @return Reference to this string.
684 append(const __versa_string& __str)
685 { return _M_append(__str._M_data(), __str.size()); }
688 * @brief Append a substring.
689 * @param __str The string to append.
690 * @param __pos Index of the first character of str to append.
691 * @param __n The number of characters to append.
692 * @return Reference to this string.
693 * @throw std::out_of_range if @a pos is not a valid index.
695 * This function appends @a __n characters from @a __str
696 * starting at @a __pos to this string. If @a __n is is larger
697 * than the number of available characters in @a __str, the
698 * remainder of @a __str is appended.
701 append(const __versa_string& __str, size_type __pos, size_type __n)
702 { return _M_append(__str._M_data()
703 + __str._M_check(__pos, "__versa_string::append"),
704 __str._M_limit(__pos, __n)); }
707 * @brief Append a C substring.
708 * @param __s The C string to append.
709 * @param __n The number of characters to append.
710 * @return Reference to this string.
713 append(const _CharT* __s, size_type __n)
715 __glibcxx_requires_string_len(__s, __n);
716 _M_check_length(size_type(0), __n, "__versa_string::append");
717 return _M_append(__s, __n);
721 * @brief Append a C string.
722 * @param __s The C string to append.
723 * @return Reference to this string.
726 append(const _CharT* __s)
728 __glibcxx_requires_string(__s);
729 const size_type __n = traits_type::length(__s);
730 _M_check_length(size_type(0), __n, "__versa_string::append");
731 return _M_append(__s, __n);
735 * @brief Append multiple characters.
736 * @param __n The number of characters to append.
737 * @param __c The character to use.
738 * @return Reference to this string.
740 * Appends n copies of c to this string.
743 append(size_type __n, _CharT __c)
744 { return _M_replace_aux(this->size(), size_type(0), __n, __c); }
746 #ifdef __GXX_EXPERIMENTAL_CXX0X__
748 * @brief Append an initializer_list of characters.
749 * @param __l The initializer_list of characters to append.
750 * @return Reference to this string.
753 append(std::initializer_list<_CharT> __l)
754 { return this->append(__l.begin(), __l.end()); }
755 #endif // __GXX_EXPERIMENTAL_CXX0X__
758 * @brief Append a range of characters.
759 * @param __first Iterator referencing the first character to append.
760 * @param __last Iterator marking the end of the range.
761 * @return Reference to this string.
763 * Appends characters in the range [first,last) to this string.
765 template<class _InputIterator>
767 append(_InputIterator __first, _InputIterator __last)
768 { return this->replace(_M_iend(), _M_iend(), __first, __last); }
771 * @brief Append a single character.
772 * @param __c Character to append.
775 push_back(_CharT __c)
777 const size_type __size = this->size();
778 if (__size + 1 > this->capacity() || this->_M_is_shared())
779 this->_M_mutate(__size, size_type(0), 0, size_type(1));
780 traits_type::assign(this->_M_data()[__size], __c);
781 this->_M_set_length(__size + 1);
785 * @brief Set value to contents of another string.
786 * @param __str Source string to use.
787 * @return Reference to this string.
790 assign(const __versa_string& __str)
792 this->_M_assign(__str);
796 #ifdef __GXX_EXPERIMENTAL_CXX0X__
798 * @brief Set value to contents of another string.
799 * @param __str Source string to use.
800 * @return Reference to this string.
802 * This function sets this string to the exact contents of @a __str.
803 * @a __str is a valid, but unspecified string.
806 assign(__versa_string&& __str)
811 #endif // __GXX_EXPERIMENTAL_CXX0X__
814 * @brief Set value to a substring of a string.
815 * @param __str The string to use.
816 * @param __pos Index of the first character of str.
817 * @param __n Number of characters to use.
818 * @return Reference to this string.
819 * @throw std::out_of_range if @a __pos is not a valid index.
821 * This function sets this string to the substring of @a __str
822 * consisting of @a __n characters at @a __pos. If @a __n is
823 * is larger than the number of available characters in @a
824 * __str, the remainder of @a __str is used.
827 assign(const __versa_string& __str, size_type __pos, size_type __n)
828 { return _M_replace(size_type(0), this->size(), __str._M_data()
829 + __str._M_check(__pos, "__versa_string::assign"),
830 __str._M_limit(__pos, __n)); }
833 * @brief Set value to a C substring.
834 * @param __s The C string to use.
835 * @param __n Number of characters to use.
836 * @return Reference to this string.
838 * This function sets the value of this string to the first @a
839 * __n characters of @a __s. If @a __n is is larger than the
840 * number of available characters in @a __s, the remainder of
844 assign(const _CharT* __s, size_type __n)
846 __glibcxx_requires_string_len(__s, __n);
847 return _M_replace(size_type(0), this->size(), __s, __n);
851 * @brief Set value to contents of a C string.
852 * @param __s The C string to use.
853 * @return Reference to this string.
855 * This function sets the value of this string to the value of
856 * @a __s. The data is copied, so there is no dependence on @a
857 * __s once the function returns.
860 assign(const _CharT* __s)
862 __glibcxx_requires_string(__s);
863 return _M_replace(size_type(0), this->size(), __s,
864 traits_type::length(__s));
868 * @brief Set value to multiple characters.
869 * @param __n Length of the resulting string.
870 * @param __c The character to use.
871 * @return Reference to this string.
873 * This function sets the value of this string to @a __n copies of
877 assign(size_type __n, _CharT __c)
878 { return _M_replace_aux(size_type(0), this->size(), __n, __c); }
881 * @brief Set value to a range of characters.
882 * @param __first Iterator referencing the first character to append.
883 * @param __last Iterator marking the end of the range.
884 * @return Reference to this string.
886 * Sets value of string to characters in the range
889 template<class _InputIterator>
891 assign(_InputIterator __first, _InputIterator __last)
892 { return this->replace(_M_ibegin(), _M_iend(), __first, __last); }
894 #ifdef __GXX_EXPERIMENTAL_CXX0X__
896 * @brief Set value to an initializer_list of characters.
897 * @param __l The initializer_list of characters to assign.
898 * @return Reference to this string.
901 assign(std::initializer_list<_CharT> __l)
902 { return this->assign(__l.begin(), __l.end()); }
903 #endif // __GXX_EXPERIMENTAL_CXX0X__
906 * @brief Insert multiple characters.
907 * @param __p Iterator referencing location in string to insert at.
908 * @param __n Number of characters to insert
909 * @param __c The character to insert.
910 * @throw std::length_error If new length exceeds @c max_size().
912 * Inserts @a __n copies of character @a __c starting at the
913 * position referenced by iterator @a __p. If adding
914 * characters causes the length to exceed max_size(),
915 * length_error is thrown. The value of the string doesn't
916 * change if an error is thrown.
919 insert(iterator __p, size_type __n, _CharT __c)
920 { this->replace(__p, __p, __n, __c); }
923 * @brief Insert a range of characters.
924 * @param __p Iterator referencing location in string to insert at.
925 * @param __beg Start of range.
926 * @param __end End of range.
927 * @throw std::length_error If new length exceeds @c max_size().
929 * Inserts characters in range [beg,end). If adding characters
930 * causes the length to exceed max_size(), length_error is
931 * thrown. The value of the string doesn't change if an error
934 template<class _InputIterator>
936 insert(iterator __p, _InputIterator __beg, _InputIterator __end)
937 { this->replace(__p, __p, __beg, __end); }
939 #ifdef __GXX_EXPERIMENTAL_CXX0X__
941 * @brief Insert an initializer_list of characters.
942 * @param __p Iterator referencing location in string to insert at.
943 * @param __l The initializer_list of characters to insert.
944 * @throw std::length_error If new length exceeds @c max_size().
947 insert(iterator __p, std::initializer_list<_CharT> __l)
948 { this->insert(__p, __l.begin(), __l.end()); }
949 #endif // __GXX_EXPERIMENTAL_CXX0X__
952 * @brief Insert value of a string.
953 * @param __pos1 Iterator referencing location in string to insert at.
954 * @param __str The string to insert.
955 * @return Reference to this string.
956 * @throw std::length_error If new length exceeds @c max_size().
958 * Inserts value of @a __str starting at @a __pos1. 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.
964 insert(size_type __pos1, const __versa_string& __str)
965 { return this->replace(__pos1, size_type(0),
966 __str._M_data(), __str.size()); }
969 * @brief Insert a substring.
970 * @param __pos1 Iterator referencing location in string to insert at.
971 * @param __str The string to insert.
972 * @param __pos2 Start of characters in str to insert.
973 * @param __n Number of characters to insert.
974 * @return Reference to this string.
975 * @throw std::length_error If new length exceeds @c max_size().
976 * @throw std::out_of_range If @a __pos1 > size() or
977 * @a __pos2 > @a __str.size().
979 * Starting at @a __pos1, insert @a __n character of @a __str
980 * beginning with @a __pos2. If adding characters causes the
981 * length to exceed max_size(), length_error is thrown. If @a
982 * __pos1 is beyond the end of this string or @a __pos2 is
983 * beyond the end of @a __str, out_of_range is thrown. The
984 * value of the string doesn't change if an error is thrown.
987 insert(size_type __pos1, const __versa_string& __str,
988 size_type __pos2, size_type __n)
989 { return this->replace(__pos1, size_type(0), __str._M_data()
990 + __str._M_check(__pos2, "__versa_string::insert"),
991 __str._M_limit(__pos2, __n)); }
994 * @brief Insert a C substring.
995 * @param __pos Iterator referencing location in string to insert at.
996 * @param __s The C string to insert.
997 * @param __n The number of characters to insert.
998 * @return Reference to this string.
999 * @throw std::length_error If new length exceeds @c max_size().
1000 * @throw std::out_of_range If @a __pos is beyond the end of this
1003 * Inserts the first @a __n characters of @a __s starting at @a
1004 * __pos. If adding characters causes the length to exceed
1005 * max_size(), length_error is thrown. If @a __pos is beyond
1006 * end(), out_of_range is thrown. The value of the string
1007 * doesn't change if an error is thrown.
1010 insert(size_type __pos, const _CharT* __s, size_type __n)
1011 { return this->replace(__pos, size_type(0), __s, __n); }
1014 * @brief Insert a C string.
1015 * @param __pos Iterator referencing location in string to insert at.
1016 * @param __s The C string 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)
1031 __glibcxx_requires_string(__s);
1032 return this->replace(__pos, size_type(0), __s,
1033 traits_type::length(__s));
1037 * @brief Insert multiple characters.
1038 * @param __pos Index in string to insert at.
1039 * @param __n Number of characters to insert
1040 * @param __c The character to insert.
1041 * @return Reference to this string.
1042 * @throw std::length_error If new length exceeds @c max_size().
1043 * @throw std::out_of_range If @a __pos is beyond the end of this
1046 * Inserts @a __n copies of character @a __c starting at index
1047 * @a __pos. If adding characters causes the length to exceed
1048 * max_size(), length_error is thrown. If @a __pos > length(),
1049 * out_of_range is thrown. The value of the string doesn't
1050 * change if an error is thrown.
1053 insert(size_type __pos, size_type __n, _CharT __c)
1054 { return _M_replace_aux(_M_check(__pos, "__versa_string::insert"),
1055 size_type(0), __n, __c); }
1058 * @brief Insert one character.
1059 * @param __p Iterator referencing position in string to insert at.
1060 * @param __c The character to insert.
1061 * @return Iterator referencing newly inserted char.
1062 * @throw std::length_error If new length exceeds @c max_size().
1064 * Inserts character @a __c at position referenced by @a __p.
1065 * If adding character causes the length to exceed max_size(),
1066 * length_error is thrown. If @a __p is beyond end of string,
1067 * out_of_range is thrown. The value of the string doesn't
1068 * change if an error is thrown.
1071 insert(iterator __p, _CharT __c)
1073 _GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend());
1074 const size_type __pos = __p - _M_ibegin();
1075 _M_replace_aux(__pos, size_type(0), size_type(1), __c);
1076 this->_M_set_leaked();
1077 return iterator(this->_M_data() + __pos);
1081 * @brief Remove characters.
1082 * @param __pos Index of first character to remove (default 0).
1083 * @param __n Number of characters to remove (default remainder).
1084 * @return Reference to this string.
1085 * @throw std::out_of_range If @a __pos is beyond the end of this
1088 * Removes @a __n characters from this string starting at @a
1089 * __pos. The length of the string is reduced by @a __n. If
1090 * there are < @a __n characters to remove, the remainder of
1091 * the string is truncated. If @a __p is beyond end of string,
1092 * out_of_range is thrown. The value of the string doesn't
1093 * change if an error is thrown.
1096 erase(size_type __pos = 0, size_type __n = npos)
1098 this->_M_erase(_M_check(__pos, "__versa_string::erase"),
1099 _M_limit(__pos, __n));
1104 * @brief Remove one character.
1105 * @param __position Iterator referencing the character to remove.
1106 * @return iterator referencing same location after removal.
1108 * Removes the character at @a __position from this string. The
1109 * value of the string doesn't change if an error is thrown.
1112 erase(iterator __position)
1114 _GLIBCXX_DEBUG_PEDASSERT(__position >= _M_ibegin()
1115 && __position < _M_iend());
1116 const size_type __pos = __position - _M_ibegin();
1117 this->_M_erase(__pos, size_type(1));
1118 this->_M_set_leaked();
1119 return iterator(this->_M_data() + __pos);
1123 * @brief Remove a range of characters.
1124 * @param __first Iterator referencing the first character to remove.
1125 * @param __last Iterator referencing the end of the range.
1126 * @return Iterator referencing location of first after removal.
1128 * Removes the characters in the range [first,last) from this
1129 * string. The value of the string doesn't change if an error
1133 erase(iterator __first, iterator __last)
1135 _GLIBCXX_DEBUG_PEDASSERT(__first >= _M_ibegin() && __first <= __last
1136 && __last <= _M_iend());
1137 const size_type __pos = __first - _M_ibegin();
1138 this->_M_erase(__pos, __last - __first);
1139 this->_M_set_leaked();
1140 return iterator(this->_M_data() + __pos);
1143 #ifdef __GXX_EXPERIMENTAL_CXX0X__
1145 * @brief Remove the last character.
1147 * The string must be non-empty.
1151 { this->_M_erase(size()-1, 1); }
1152 #endif // __GXX_EXPERIMENTAL_CXX0X__
1155 * @brief Replace characters with value from another string.
1156 * @param __pos Index of first character to replace.
1157 * @param __n Number of characters to be replaced.
1158 * @param __str String to insert.
1159 * @return Reference to this string.
1160 * @throw std::out_of_range If @a __pos is beyond the end of this
1162 * @throw std::length_error If new length exceeds @c max_size().
1164 * Removes the characters in the range [pos,pos+n) from this
1165 * string. In place, the value of @a __str is inserted. If @a
1166 * __pos is beyond end of string, out_of_range is thrown. If
1167 * the length of the result exceeds max_size(), length_error is
1168 * thrown. The value of the string doesn't change if an error
1172 replace(size_type __pos, size_type __n, const __versa_string& __str)
1173 { return this->replace(__pos, __n, __str._M_data(), __str.size()); }
1176 * @brief Replace characters with value from another string.
1177 * @param __pos1 Index of first character to replace.
1178 * @param __n1 Number of characters to be replaced.
1179 * @param __str String to insert.
1180 * @param __pos2 Index of first character of str to use.
1181 * @param __n2 Number of characters from str to use.
1182 * @return Reference to this string.
1183 * @throw std::out_of_range If @a __pos1 > size() or @a __pos2 >
1185 * @throw std::length_error If new length exceeds @c max_size().
1187 * Removes the characters in the range [pos1,pos1 + n) from
1188 * this string. In place, the value of @a __str is inserted.
1189 * If @a __pos is beyond end of string, out_of_range is thrown.
1190 * If the length of the result exceeds max_size(), length_error
1191 * is thrown. The value of the string doesn't change if an
1195 replace(size_type __pos1, size_type __n1, const __versa_string& __str,
1196 size_type __pos2, size_type __n2)
1198 return this->replace(__pos1, __n1, __str._M_data()
1199 + __str._M_check(__pos2,
1200 "__versa_string::replace"),
1201 __str._M_limit(__pos2, __n2));
1205 * @brief Replace characters with value of a C substring.
1206 * @param __pos Index of first character to replace.
1207 * @param __n1 Number of characters to be replaced.
1208 * @param __s C string to insert.
1209 * @param __n2 Number of characters from @a __s to use.
1210 * @return Reference to this string.
1211 * @throw std::out_of_range If @a __pos1 > size().
1212 * @throw std::length_error If new length exceeds @c max_size().
1214 * Removes the characters in the range [pos,pos + n1) from this
1215 * string. In place, the first @a __n2 characters of @a __s
1216 * are inserted, or all of @a __s if @a __n2 is too large. If
1217 * @a __pos is beyond end of string, out_of_range is thrown.
1218 * If the length of result exceeds max_size(), length_error is
1219 * thrown. The value of the string doesn't change if an error
1223 replace(size_type __pos, size_type __n1, const _CharT* __s,
1226 __glibcxx_requires_string_len(__s, __n2);
1227 return _M_replace(_M_check(__pos, "__versa_string::replace"),
1228 _M_limit(__pos, __n1), __s, __n2);
1232 * @brief Replace characters with value of a C string.
1233 * @param __pos Index of first character to replace.
1234 * @param __n1 Number of characters to be replaced.
1235 * @param __s C string to insert.
1236 * @return Reference to this string.
1237 * @throw std::out_of_range If @a __pos > size().
1238 * @throw std::length_error If new length exceeds @c max_size().
1240 * Removes the characters in the range [pos,pos + n1) from this
1241 * string. In place, the characters of @a __s are inserted. If
1242 * @a pos is beyond end of string, out_of_range is thrown. If
1243 * the length of result exceeds max_size(), length_error is thrown.
1244 * The value of the string doesn't change if an error is thrown.
1247 replace(size_type __pos, size_type __n1, const _CharT* __s)
1249 __glibcxx_requires_string(__s);
1250 return this->replace(__pos, __n1, __s, traits_type::length(__s));
1254 * @brief Replace characters with multiple characters.
1255 * @param __pos Index of first character to replace.
1256 * @param __n1 Number of characters to be replaced.
1257 * @param __n2 Number of characters to insert.
1258 * @param __c Character to insert.
1259 * @return Reference to this string.
1260 * @throw std::out_of_range If @a __pos > size().
1261 * @throw std::length_error If new length exceeds @c max_size().
1263 * Removes the characters in the range [pos,pos + n1) from this
1264 * string. In place, @a __n2 copies of @a __c are inserted.
1265 * If @a __pos is beyond end of string, out_of_range is thrown.
1266 * If the length of result exceeds max_size(), length_error is
1267 * thrown. The value of the string doesn't change if an error
1271 replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
1272 { return _M_replace_aux(_M_check(__pos, "__versa_string::replace"),
1273 _M_limit(__pos, __n1), __n2, __c); }
1276 * @brief Replace range of characters with string.
1277 * @param __i1 Iterator referencing start of range to replace.
1278 * @param __i2 Iterator referencing end of range to replace.
1279 * @param __str String value to insert.
1280 * @return Reference to this string.
1281 * @throw std::length_error If new length exceeds @c max_size().
1283 * Removes the characters in the range [i1,i2). In place, the
1284 * value of @a __str is inserted. If the length of result
1285 * exceeds max_size(), length_error is thrown. The value of
1286 * the string doesn't change if an error is thrown.
1289 replace(iterator __i1, iterator __i2, const __versa_string& __str)
1290 { return this->replace(__i1, __i2, __str._M_data(), __str.size()); }
1293 * @brief Replace range of characters with C substring.
1294 * @param __i1 Iterator referencing start of range to replace.
1295 * @param __i2 Iterator referencing end of range to replace.
1296 * @param __s C string value to insert.
1297 * @param __n Number of characters from s to insert.
1298 * @return Reference to this string.
1299 * @throw std::length_error If new length exceeds @c max_size().
1301 * Removes the characters in the range [i1,i2). In place, the
1302 * first @a n characters of @a __s are inserted. If the length
1303 * of result exceeds max_size(), length_error is thrown. The
1304 * value of the string doesn't change if an error is thrown.
1307 replace(iterator __i1, iterator __i2, const _CharT* __s, size_type __n)
1309 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1310 && __i2 <= _M_iend());
1311 return this->replace(__i1 - _M_ibegin(), __i2 - __i1, __s, __n);
1315 * @brief Replace range of characters with C string.
1316 * @param __i1 Iterator referencing start of range to replace.
1317 * @param __i2 Iterator referencing end of range to replace.
1318 * @param __s C string value to insert.
1319 * @return Reference to this string.
1320 * @throw std::length_error If new length exceeds @c max_size().
1322 * Removes the characters in the range [i1,i2). In place, the
1323 * characters of @a __s are inserted. If the length of result
1324 * exceeds max_size(), length_error is thrown. The value of
1325 * the string doesn't change if an error is thrown.
1328 replace(iterator __i1, iterator __i2, const _CharT* __s)
1330 __glibcxx_requires_string(__s);
1331 return this->replace(__i1, __i2, __s, traits_type::length(__s));
1335 * @brief Replace range of characters with multiple characters
1336 * @param __i1 Iterator referencing start of range to replace.
1337 * @param __i2 Iterator referencing end of range to replace.
1338 * @param __n Number of characters to insert.
1339 * @param __c Character to insert.
1340 * @return Reference to this string.
1341 * @throw std::length_error If new length exceeds @c max_size().
1343 * Removes the characters in the range [i1,i2). In place, @a
1344 * __n copies of @a __c are inserted. If the length of result
1345 * exceeds max_size(), length_error is thrown. The value of
1346 * the string doesn't change if an error is thrown.
1349 replace(iterator __i1, iterator __i2, size_type __n, _CharT __c)
1351 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1352 && __i2 <= _M_iend());
1353 return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __c);
1357 * @brief Replace range of characters with range.
1358 * @param __i1 Iterator referencing start of range to replace.
1359 * @param __i2 Iterator referencing end of range to replace.
1360 * @param __k1 Iterator referencing start of range to insert.
1361 * @param __k2 Iterator referencing end of range to insert.
1362 * @return Reference to this string.
1363 * @throw std::length_error If new length exceeds @c max_size().
1365 * Removes the characters in the range [i1,i2). In place,
1366 * characters in the range [k1,k2) are inserted. If the length
1367 * of result exceeds max_size(), length_error is thrown. The
1368 * value of the string doesn't change if an error is thrown.
1370 template<class _InputIterator>
1372 replace(iterator __i1, iterator __i2,
1373 _InputIterator __k1, _InputIterator __k2)
1375 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1376 && __i2 <= _M_iend());
1377 __glibcxx_requires_valid_range(__k1, __k2);
1378 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
1379 return this->_M_replace_dispatch(__i1, __i2, __k1, __k2, _Integral());
1382 // Specializations for the common case of pointer and iterator:
1383 // useful to avoid the overhead of temporary buffering in _M_replace.
1385 replace(iterator __i1, iterator __i2, _CharT* __k1, _CharT* __k2)
1387 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1388 && __i2 <= _M_iend());
1389 __glibcxx_requires_valid_range(__k1, __k2);
1390 return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
1395 replace(iterator __i1, iterator __i2,
1396 const _CharT* __k1, const _CharT* __k2)
1398 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1399 && __i2 <= _M_iend());
1400 __glibcxx_requires_valid_range(__k1, __k2);
1401 return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
1406 replace(iterator __i1, iterator __i2, iterator __k1, iterator __k2)
1408 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1409 && __i2 <= _M_iend());
1410 __glibcxx_requires_valid_range(__k1, __k2);
1411 return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
1412 __k1.base(), __k2 - __k1);
1416 replace(iterator __i1, iterator __i2,
1417 const_iterator __k1, const_iterator __k2)
1419 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1420 && __i2 <= _M_iend());
1421 __glibcxx_requires_valid_range(__k1, __k2);
1422 return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
1423 __k1.base(), __k2 - __k1);
1426 #ifdef __GXX_EXPERIMENTAL_CXX0X__
1428 * @brief Replace range of characters with initializer_list.
1429 * @param __i1 Iterator referencing start of range to replace.
1430 * @param __i2 Iterator referencing end of range to replace.
1431 * @param __l The initializer_list of characters to insert.
1432 * @return Reference to this string.
1433 * @throw std::length_error If new length exceeds @c max_size().
1435 * Removes the characters in the range [i1,i2). In place,
1436 * characters in the range [k1,k2) are inserted. If the length
1437 * of result exceeds max_size(), length_error is thrown. The
1438 * value of the string doesn't change if an error is thrown.
1440 __versa_string& replace(iterator __i1, iterator __i2,
1441 std::initializer_list<_CharT> __l)
1442 { return this->replace(__i1, __i2, __l.begin(), __l.end()); }
1443 #endif // __GXX_EXPERIMENTAL_CXX0X__
1446 template<class _Integer>
1448 _M_replace_dispatch(iterator __i1, iterator __i2, _Integer __n,
1449 _Integer __val, std::__true_type)
1450 { return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __val); }
1452 template<class _InputIterator>
1454 _M_replace_dispatch(iterator __i1, iterator __i2, _InputIterator __k1,
1455 _InputIterator __k2, std::__false_type);
1458 _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2,
1462 _M_replace(size_type __pos, size_type __len1, const _CharT* __s,
1463 const size_type __len2);
1466 _M_append(const _CharT* __s, size_type __n);
1471 * @brief Copy substring into C string.
1472 * @param __s C string to copy value into.
1473 * @param __n Number of characters to copy.
1474 * @param __pos Index of first character to copy.
1475 * @return Number of characters actually copied
1476 * @throw std::out_of_range If pos > size().
1478 * Copies up to @a __n characters starting at @a __pos into the
1479 * C string @a s. If @a __pos is greater than size(),
1480 * out_of_range is thrown.
1483 copy(_CharT* __s, size_type __n, size_type __pos = 0) const;
1486 * @brief Swap contents with another string.
1487 * @param __s String to swap with.
1489 * Exchanges the contents of this string with that of @a __s in
1493 swap(__versa_string& __s)
1494 { this->_M_swap(__s); }
1496 // String operations:
1498 * @brief Return const pointer to null-terminated contents.
1500 * This is a handle to internal data. Do not modify or dire things may
1504 c_str() const _GLIBCXX_NOEXCEPT
1505 { return this->_M_data(); }
1508 * @brief Return const pointer to contents.
1510 * This is a handle to internal data. Do not modify or dire things may
1514 data() const _GLIBCXX_NOEXCEPT
1515 { return this->_M_data(); }
1518 * @brief Return copy of allocator used to construct this string.
1521 get_allocator() const _GLIBCXX_NOEXCEPT
1522 { return allocator_type(this->_M_get_allocator()); }
1525 * @brief Find position of a C substring.
1526 * @param __s C string to locate.
1527 * @param __pos Index of character to search from.
1528 * @param __n Number of characters from @a __s to search for.
1529 * @return Index of start of first occurrence.
1531 * Starting from @a __pos, searches forward for the first @a
1532 * __n characters in @a __s within this string. If found,
1533 * returns the index where it begins. If not found, returns
1537 find(const _CharT* __s, size_type __pos, size_type __n) const;
1540 * @brief Find position of a string.
1541 * @param __str String to locate.
1542 * @param __pos Index of character to search from (default 0).
1543 * @return Index of start of first occurrence.
1545 * Starting from @a __pos, searches forward for value of @a
1546 * __str within this string. If found, returns the index where
1547 * it begins. If not found, returns npos.
1550 find(const __versa_string& __str, size_type __pos = 0) const
1552 { return this->find(__str.data(), __pos, __str.size()); }
1555 * @brief Find position of a C string.
1556 * @param __s C string to locate.
1557 * @param __pos Index of character to search from (default 0).
1558 * @return Index of start of first occurrence.
1560 * Starting from @a __pos, searches forward for the value of @a
1561 * __s within this string. If found, returns the index where
1562 * it begins. If not found, returns npos.
1565 find(const _CharT* __s, size_type __pos = 0) const
1567 __glibcxx_requires_string(__s);
1568 return this->find(__s, __pos, traits_type::length(__s));
1572 * @brief Find position of a character.
1573 * @param __c Character to locate.
1574 * @param __pos Index of character to search from (default 0).
1575 * @return Index of first occurrence.
1577 * Starting from @a __pos, searches forward for @a __c within
1578 * this string. If found, returns the index where it was
1579 * found. If not found, returns npos.
1582 find(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT;
1585 * @brief Find last position of a string.
1586 * @param __str String to locate.
1587 * @param __pos Index of character to search back from (default end).
1588 * @return Index of start of last occurrence.
1590 * Starting from @a __pos, searches backward for value of @a
1591 * __str within this string. If found, returns the index where
1592 * it begins. If not found, returns npos.
1595 rfind(const __versa_string& __str, size_type __pos = npos) const
1597 { return this->rfind(__str.data(), __pos, __str.size()); }
1600 * @brief Find last position of a C substring.
1601 * @param __s C string to locate.
1602 * @param __pos Index of character to search back from.
1603 * @param __n Number of characters from s to search for.
1604 * @return Index of start of last occurrence.
1606 * Starting from @a __pos, searches backward for the first @a
1607 * __n characters in @a __s within this string. If found,
1608 * returns the index where it begins. If not found, returns
1612 rfind(const _CharT* __s, size_type __pos, size_type __n) const;
1615 * @brief Find last position of a C string.
1616 * @param __s C string to locate.
1617 * @param __pos Index of character to start search at (default end).
1618 * @return Index of start of last occurrence.
1620 * Starting from @a __pos, searches backward for the value of
1621 * @a __s within this string. If found, returns the index
1622 * where it begins. If not found, returns npos.
1625 rfind(const _CharT* __s, size_type __pos = npos) const
1627 __glibcxx_requires_string(__s);
1628 return this->rfind(__s, __pos, traits_type::length(__s));
1632 * @brief Find last position of a character.
1633 * @param __c Character to locate.
1634 * @param __pos Index of character to search back from (default end).
1635 * @return Index of last occurrence.
1637 * Starting from @a __pos, searches backward for @a __c within
1638 * this string. If found, returns the index where it was
1639 * found. If not found, returns npos.
1642 rfind(_CharT __c, size_type __pos = npos) const _GLIBCXX_NOEXCEPT;
1645 * @brief Find position of a character of string.
1646 * @param __str String containing characters to locate.
1647 * @param __pos Index of character to search from (default 0).
1648 * @return Index of first occurrence.
1650 * Starting from @a __pos, searches forward for one of the characters of
1651 * @a __str within this string. If found, returns the index where it was
1652 * found. If not found, returns npos.
1655 find_first_of(const __versa_string& __str, size_type __pos = 0) const
1657 { return this->find_first_of(__str.data(), __pos, __str.size()); }
1660 * @brief Find position of a character of C substring.
1661 * @param __s String containing characters to locate.
1662 * @param __pos Index of character to search from.
1663 * @param __n Number of characters from s to search for.
1664 * @return Index of first occurrence.
1666 * Starting from @a __pos, searches forward for one of the
1667 * first @a __n characters of @a __s within this string. If
1668 * found, returns the index where it was found. If not found,
1672 find_first_of(const _CharT* __s, size_type __pos, size_type __n) const;
1675 * @brief Find position of a character of C string.
1676 * @param __s String containing characters to locate.
1677 * @param __pos Index of character to search from (default 0).
1678 * @return Index of first occurrence.
1680 * Starting from @a __pos, searches forward for one of the
1681 * characters of @a __s within this string. If found, returns
1682 * the index where it was found. If not found, returns npos.
1685 find_first_of(const _CharT* __s, size_type __pos = 0) const
1687 __glibcxx_requires_string(__s);
1688 return this->find_first_of(__s, __pos, traits_type::length(__s));
1692 * @brief Find position of a character.
1693 * @param __c Character to locate.
1694 * @param __pos Index of character to search from (default 0).
1695 * @return Index of first occurrence.
1697 * Starting from @a __pos, searches forward for the character
1698 * @a __c within this string. If found, returns the index
1699 * where it was found. If not found, returns npos.
1701 * Note: equivalent to find(c, pos).
1704 find_first_of(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT
1705 { return this->find(__c, __pos); }
1708 * @brief Find last position of a character of string.
1709 * @param __str String containing characters to locate.
1710 * @param __pos Index of character to search back from (default end).
1711 * @return Index of last occurrence.
1713 * Starting from @a __pos, searches backward for one of the
1714 * characters of @a __str within this string. If found,
1715 * returns the index where it was found. If not found, returns
1719 find_last_of(const __versa_string& __str, size_type __pos = npos) const
1721 { return this->find_last_of(__str.data(), __pos, __str.size()); }
1724 * @brief Find last position of a character of C substring.
1725 * @param __s C string containing characters to locate.
1726 * @param __pos Index of character to search back from.
1727 * @param __n Number of characters from s to search for.
1728 * @return Index of last occurrence.
1730 * Starting from @a __pos, searches backward for one of the
1731 * first @a __n characters of @a __s within this string. If
1732 * found, returns the index where it was found. If not found,
1736 find_last_of(const _CharT* __s, size_type __pos, size_type __n) const;
1739 * @brief Find last position of a character of C string.
1740 * @param __s C string containing characters to locate.
1741 * @param __pos Index of character to search back from (default end).
1742 * @return Index of last occurrence.
1744 * Starting from @a __pos, searches backward for one of the
1745 * characters of @a __s within this string. If found, returns
1746 * the index where it was found. If not found, returns npos.
1749 find_last_of(const _CharT* __s, size_type __pos = npos) const
1751 __glibcxx_requires_string(__s);
1752 return this->find_last_of(__s, __pos, traits_type::length(__s));
1756 * @brief Find last position of a character.
1757 * @param __c Character to locate.
1758 * @param __pos Index of character to search back from (default end).
1759 * @return Index of last occurrence.
1761 * Starting from @a __pos, searches backward for @a __c within
1762 * this string. If found, returns the index where it was
1763 * found. If not found, returns npos.
1765 * Note: equivalent to rfind(c, pos).
1768 find_last_of(_CharT __c, size_type __pos = npos) const _GLIBCXX_NOEXCEPT
1769 { return this->rfind(__c, __pos); }
1772 * @brief Find position of a character not in string.
1773 * @param __str String containing characters to avoid.
1774 * @param __pos Index of character to search from (default 0).
1775 * @return Index of first occurrence.
1777 * Starting from @a __pos, searches forward for a character not
1778 * contained in @a __str within this string. If found, returns
1779 * the index where it was found. If not found, returns npos.
1782 find_first_not_of(const __versa_string& __str, size_type __pos = 0) const
1784 { return this->find_first_not_of(__str.data(), __pos, __str.size()); }
1787 * @brief Find position of a character not in C substring.
1788 * @param __s C string containing characters to avoid.
1789 * @param __pos Index of character to search from.
1790 * @param __n Number of characters from s to consider.
1791 * @return Index of first occurrence.
1793 * Starting from @a __pos, searches forward for a character not
1794 * contained in the first @a __n characters of @a __s within
1795 * this string. If found, returns the index where it was
1796 * found. If not found, returns npos.
1799 find_first_not_of(const _CharT* __s, size_type __pos,
1800 size_type __n) const;
1803 * @brief Find position of a character not in C string.
1804 * @param __s C string containing characters to avoid.
1805 * @param __pos Index of character to search from (default 0).
1806 * @return Index of first occurrence.
1808 * Starting from @a __pos, searches forward for a character not
1809 * contained in @a __s within this string. If found, returns
1810 * the index where it was found. If not found, returns npos.
1813 find_first_not_of(const _CharT* __s, size_type __pos = 0) const
1815 __glibcxx_requires_string(__s);
1816 return this->find_first_not_of(__s, __pos, traits_type::length(__s));
1820 * @brief Find position of a different character.
1821 * @param __c Character to avoid.
1822 * @param __pos Index of character to search from (default 0).
1823 * @return Index of first occurrence.
1825 * Starting from @a __pos, searches forward for a character
1826 * other than @a __c within this string. If found, returns the
1827 * index where it was found. If not found, returns npos.
1830 find_first_not_of(_CharT __c, size_type __pos = 0) const
1834 * @brief Find last position of a character not in string.
1835 * @param __str String containing characters to avoid.
1836 * @param __pos Index of character to search back from (default end).
1837 * @return Index of last occurrence.
1839 * Starting from @a __pos, searches backward for a character
1840 * not contained in @a __str within this string. If found,
1841 * returns the index where it was found. If not found, returns
1845 find_last_not_of(const __versa_string& __str,
1846 size_type __pos = npos) const _GLIBCXX_NOEXCEPT
1847 { return this->find_last_not_of(__str.data(), __pos, __str.size()); }
1850 * @brief Find last position of a character not in C substring.
1851 * @param __s C string containing characters to avoid.
1852 * @param __pos Index of character to search back from.
1853 * @param __n Number of characters from s to consider.
1854 * @return Index of last occurrence.
1856 * Starting from @a __pos, searches backward for a character
1857 * not contained in the first @a __n characters of @a __s
1858 * within this string. If found, returns the index where it
1859 * was found. If not found, returns npos.
1862 find_last_not_of(const _CharT* __s, size_type __pos,
1863 size_type __n) const;
1865 * @brief Find last position of a character not in C string.
1866 * @param __s C string containing characters to avoid.
1867 * @param __pos Index of character to search back from (default end).
1868 * @return Index of last occurrence.
1870 * Starting from @a __pos, searches backward for a character
1871 * not contained in @a __s within this string. If found,
1872 * returns the index where it was found. If not found, returns
1876 find_last_not_of(const _CharT* __s, size_type __pos = npos) const
1878 __glibcxx_requires_string(__s);
1879 return this->find_last_not_of(__s, __pos, traits_type::length(__s));
1883 * @brief Find last position of a different character.
1884 * @param __c Character to avoid.
1885 * @param __pos Index of character to search back from (default end).
1886 * @return Index of last occurrence.
1888 * Starting from @a __pos, searches backward for a character
1889 * other than @a __c within this string. If found, returns the
1890 * index where it was found. If not found, returns npos.
1893 find_last_not_of(_CharT __c, size_type __pos = npos) const
1897 * @brief Get a substring.
1898 * @param __pos Index of first character (default 0).
1899 * @param __n Number of characters in substring (default remainder).
1900 * @return The new string.
1901 * @throw std::out_of_range If pos > size().
1903 * Construct and return a new string using the @a __n
1904 * characters starting at @a __pos. If the string is too
1905 * short, use the remainder of the characters. If @a __pos is
1906 * beyond the end of the string, out_of_range is thrown.
1909 substr(size_type __pos = 0, size_type __n = npos) const
1911 return __versa_string(*this, _M_check(__pos, "__versa_string::substr"),
1916 * @brief Compare to a string.
1917 * @param __str String to compare against.
1918 * @return Integer < 0, 0, or > 0.
1920 * Returns an integer < 0 if this string is ordered before @a
1921 * __str, 0 if their values are equivalent, or > 0 if this
1922 * string is ordered after @a __str. Determines the effective
1923 * length rlen of the strings to compare as the smallest of
1924 * size() and str.size(). The function then compares the two
1925 * strings by calling traits::compare(data(), str.data(),rlen).
1926 * If the result of the comparison is nonzero returns it,
1927 * otherwise the shorter one is ordered first.
1930 compare(const __versa_string& __str) const
1932 if (this->_M_compare(__str))
1935 const size_type __size = this->size();
1936 const size_type __osize = __str.size();
1937 const size_type __len = std::min(__size, __osize);
1939 int __r = traits_type::compare(this->_M_data(), __str.data(), __len);
1941 __r = this->_S_compare(__size, __osize);
1946 * @brief Compare substring to a string.
1947 * @param __pos Index of first character of substring.
1948 * @param __n Number of characters in substring.
1949 * @param __str String to compare against.
1950 * @return Integer < 0, 0, or > 0.
1952 * Form the substring of this string from the @a __n characters
1953 * starting at @a __pos. Returns an integer < 0 if the
1954 * substring is ordered before @a __str, 0 if their values are
1955 * equivalent, or > 0 if the substring is ordered after @a
1956 * __str. Determines the effective length rlen of the strings
1957 * to compare as the smallest of the length of the substring
1958 * and @a __str.size(). The function then compares the two
1959 * strings by calling
1960 * traits::compare(substring.data(),str.data(),rlen). If the
1961 * result of the comparison is nonzero returns it, otherwise
1962 * the shorter one is ordered first.
1965 compare(size_type __pos, size_type __n,
1966 const __versa_string& __str) const;
1969 * @brief Compare substring to a substring.
1970 * @param __pos1 Index of first character of substring.
1971 * @param __n1 Number of characters in substring.
1972 * @param __str String to compare against.
1973 * @param __pos2 Index of first character of substring of str.
1974 * @param __n2 Number of characters in substring of str.
1975 * @return Integer < 0, 0, or > 0.
1977 * Form the substring of this string from the @a __n1
1978 * characters starting at @a __pos1. Form the substring of @a
1979 * __str from the @a __n2 characters starting at @a __pos2.
1980 * Returns an integer < 0 if this substring is ordered before
1981 * the substring of @a __str, 0 if their values are equivalent,
1982 * or > 0 if this substring is ordered after the substring of
1983 * @a __str. Determines the effective length rlen of the
1984 * strings to compare as the smallest of the lengths of the
1985 * substrings. The function then compares the two strings by
1987 * traits::compare(substring.data(),str.substr(pos2,n2).data(),rlen).
1988 * If the result of the comparison is nonzero returns it,
1989 * otherwise the shorter one is ordered first.
1992 compare(size_type __pos1, size_type __n1, const __versa_string& __str,
1993 size_type __pos2, size_type __n2) const;
1996 * @brief Compare to a C string.
1997 * @param __s C string to compare against.
1998 * @return Integer < 0, 0, or > 0.
2000 * Returns an integer < 0 if this string is ordered before @a
2001 * __s, 0 if their values are equivalent, or > 0 if this string
2002 * is ordered after @a __s. Determines the effective length
2003 * rlen of the strings to compare as the smallest of size() and
2004 * the length of a string constructed from @a __s. The
2005 * function then compares the two strings by calling
2006 * traits::compare(data(),s,rlen). If the result of the
2007 * comparison is nonzero returns it, otherwise the shorter one
2011 compare(const _CharT* __s) const;
2013 // _GLIBCXX_RESOLVE_LIB_DEFECTS
2014 // 5 String::compare specification questionable
2016 * @brief Compare substring to a C string.
2017 * @param __pos Index of first character of substring.
2018 * @param __n1 Number of characters in substring.
2019 * @param __s C string to compare against.
2020 * @return Integer < 0, 0, or > 0.
2022 * Form the substring of this string from the @a __n1
2023 * characters starting at @a __pos. Returns an integer < 0 if
2024 * the substring is ordered before @a __s, 0 if their values
2025 * are equivalent, or > 0 if the substring is ordered after @a
2026 * __s. Determines the effective length rlen of the strings to
2027 * compare as the smallest of the length of the substring and
2028 * the length of a string constructed from @a __s. The
2029 * function then compares the two string by calling
2030 * traits::compare(substring.data(),s,rlen). If the result of
2031 * the comparison is nonzero returns it, otherwise the shorter
2032 * one is ordered first.
2035 compare(size_type __pos, size_type __n1, const _CharT* __s) const;
2038 * @brief Compare substring against a character array.
2039 * @param __pos Index of first character of substring.
2040 * @param __n1 Number of characters in substring.
2041 * @param __s character array to compare against.
2042 * @param __n2 Number of characters of s.
2043 * @return Integer < 0, 0, or > 0.
2045 * Form the substring of this string from the @a __n1
2046 * characters starting at @a __pos. Form a string from the
2047 * first @a __n2 characters of @a __s. Returns an integer < 0
2048 * if this substring is ordered before the string from @a __s,
2049 * 0 if their values are equivalent, or > 0 if this substring
2050 * is ordered after the string from @a __s. Determines the
2051 * effective length rlen of the strings to compare as the
2052 * smallest of the length of the substring and @a __n2. The
2053 * function then compares the two strings by calling
2054 * traits::compare(substring.data(),__s,rlen). If the result of
2055 * the comparison is nonzero returns it, otherwise the shorter
2056 * one is ordered first.
2058 * NB: __s must have at least n2 characters, <em>\\0</em> has no special
2062 compare(size_type __pos, size_type __n1, const _CharT* __s,
2063 size_type __n2) const;
2068 * @brief Concatenate two strings.
2069 * @param __lhs First string.
2070 * @param __rhs Last string.
2071 * @return New string with value of @a __lhs followed by @a __rhs.
2073 template<typename _CharT, typename _Traits, typename _Alloc,
2074 template <typename, typename, typename> class _Base>
2075 __versa_string<_CharT, _Traits, _Alloc, _Base>
2076 operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2077 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs);
2080 * @brief Concatenate C string and string.
2081 * @param __lhs First string.
2082 * @param __rhs Last string.
2083 * @return New string with value of @a __lhs followed by @a __rhs.
2085 template<typename _CharT, typename _Traits, typename _Alloc,
2086 template <typename, typename, typename> class _Base>
2087 __versa_string<_CharT, _Traits, _Alloc, _Base>
2088 operator+(const _CharT* __lhs,
2089 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs);
2092 * @brief Concatenate character and string.
2093 * @param __lhs First string.
2094 * @param __rhs Last string.
2095 * @return New string with @a __lhs followed by @a __rhs.
2097 template<typename _CharT, typename _Traits, typename _Alloc,
2098 template <typename, typename, typename> class _Base>
2099 __versa_string<_CharT, _Traits, _Alloc, _Base>
2100 operator+(_CharT __lhs,
2101 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs);
2104 * @brief Concatenate string and C string.
2105 * @param __lhs First string.
2106 * @param __rhs Last string.
2107 * @return New string with @a __lhs followed by @a __rhs.
2109 template<typename _CharT, typename _Traits, typename _Alloc,
2110 template <typename, typename, typename> class _Base>
2111 __versa_string<_CharT, _Traits, _Alloc, _Base>
2112 operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2113 const _CharT* __rhs);
2116 * @brief Concatenate string and character.
2117 * @param __lhs First string.
2118 * @param __rhs Last string.
2119 * @return New string with @a __lhs followed by @a __rhs.
2121 template<typename _CharT, typename _Traits, typename _Alloc,
2122 template <typename, typename, typename> class _Base>
2123 __versa_string<_CharT, _Traits, _Alloc, _Base>
2124 operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2127 #ifdef __GXX_EXPERIMENTAL_CXX0X__
2128 template<typename _CharT, typename _Traits, typename _Alloc,
2129 template <typename, typename, typename> class _Base>
2130 inline __versa_string<_CharT, _Traits, _Alloc, _Base>
2131 operator+(__versa_string<_CharT, _Traits, _Alloc, _Base>&& __lhs,
2132 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2133 { return std::move(__lhs.append(__rhs)); }
2135 template<typename _CharT, typename _Traits, typename _Alloc,
2136 template <typename, typename, typename> class _Base>
2137 inline __versa_string<_CharT, _Traits, _Alloc, _Base>
2138 operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2139 __versa_string<_CharT, _Traits, _Alloc, _Base>&& __rhs)
2140 { return std::move(__rhs.insert(0, __lhs)); }
2142 template<typename _CharT, typename _Traits, typename _Alloc,
2143 template <typename, typename, typename> class _Base>
2144 inline __versa_string<_CharT, _Traits, _Alloc, _Base>
2145 operator+(__versa_string<_CharT, _Traits, _Alloc, _Base>&& __lhs,
2146 __versa_string<_CharT, _Traits, _Alloc, _Base>&& __rhs)
2148 const auto __size = __lhs.size() + __rhs.size();
2149 const bool __cond = (__size > __lhs.capacity()
2150 && __size <= __rhs.capacity());
2151 return __cond ? std::move(__rhs.insert(0, __lhs))
2152 : std::move(__lhs.append(__rhs));
2155 template<typename _CharT, typename _Traits, typename _Alloc,
2156 template <typename, typename, typename> class _Base>
2157 inline __versa_string<_CharT, _Traits, _Alloc, _Base>
2158 operator+(const _CharT* __lhs,
2159 __versa_string<_CharT, _Traits, _Alloc, _Base>&& __rhs)
2160 { return std::move(__rhs.insert(0, __lhs)); }
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+(_CharT __lhs,
2166 __versa_string<_CharT, _Traits, _Alloc, _Base>&& __rhs)
2167 { return std::move(__rhs.insert(0, 1, __lhs)); }
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+(__versa_string<_CharT, _Traits, _Alloc, _Base>&& __lhs,
2173 const _CharT* __rhs)
2174 { return std::move(__lhs.append(__rhs)); }
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,
2181 { return std::move(__lhs.append(1, __rhs)); }
2186 * @brief Test equivalence of two strings.
2187 * @param __lhs First string.
2188 * @param __rhs Second string.
2189 * @return True if @a __lhs.compare(@a __rhs) == 0. False otherwise.
2191 template<typename _CharT, typename _Traits, typename _Alloc,
2192 template <typename, typename, typename> class _Base>
2194 operator==(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2195 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2196 { return __lhs.compare(__rhs) == 0; }
2198 template<typename _CharT,
2199 template <typename, typename, typename> class _Base>
2200 inline typename __enable_if<std::__is_char<_CharT>::__value, bool>::__type
2201 operator==(const __versa_string<_CharT, std::char_traits<_CharT>,
2202 std::allocator<_CharT>, _Base>& __lhs,
2203 const __versa_string<_CharT, std::char_traits<_CharT>,
2204 std::allocator<_CharT>, _Base>& __rhs)
2205 { return (__lhs.size() == __rhs.size()
2206 && !std::char_traits<_CharT>::compare(__lhs.data(), __rhs.data(),
2210 * @brief Test equivalence of C string and string.
2211 * @param __lhs C string.
2212 * @param __rhs String.
2213 * @return True if @a __rhs.compare(@a __lhs) == 0. False otherwise.
2215 template<typename _CharT, typename _Traits, typename _Alloc,
2216 template <typename, typename, typename> class _Base>
2218 operator==(const _CharT* __lhs,
2219 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2220 { return __rhs.compare(__lhs) == 0; }
2223 * @brief Test equivalence of string and C string.
2224 * @param __lhs String.
2225 * @param __rhs C string.
2226 * @return True if @a __lhs.compare(@a __rhs) == 0. False otherwise.
2228 template<typename _CharT, typename _Traits, typename _Alloc,
2229 template <typename, typename, typename> class _Base>
2231 operator==(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2232 const _CharT* __rhs)
2233 { return __lhs.compare(__rhs) == 0; }
2237 * @brief Test difference of two strings.
2238 * @param __lhs First string.
2239 * @param __rhs Second string.
2240 * @return True if @a __lhs.compare(@a __rhs) != 0. False otherwise.
2242 template<typename _CharT, typename _Traits, typename _Alloc,
2243 template <typename, typename, typename> class _Base>
2245 operator!=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2246 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2247 { return !(__lhs == __rhs); }
2250 * @brief Test difference of C string and string.
2251 * @param __lhs C string.
2252 * @param __rhs String.
2253 * @return True if @a __rhs.compare(@a __lhs) != 0. False otherwise.
2255 template<typename _CharT, typename _Traits, typename _Alloc,
2256 template <typename, typename, typename> class _Base>
2258 operator!=(const _CharT* __lhs,
2259 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2260 { return !(__lhs == __rhs); }
2263 * @brief Test difference of string and C string.
2264 * @param __lhs String.
2265 * @param __rhs C string.
2266 * @return True if @a __lhs.compare(@a __rhs) != 0. False otherwise.
2268 template<typename _CharT, typename _Traits, typename _Alloc,
2269 template <typename, typename, typename> class _Base>
2271 operator!=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2272 const _CharT* __rhs)
2273 { return !(__lhs == __rhs); }
2277 * @brief Test if string precedes string.
2278 * @param __lhs First string.
2279 * @param __rhs Second string.
2280 * @return True if @a __lhs precedes @a __rhs. False otherwise.
2282 template<typename _CharT, typename _Traits, typename _Alloc,
2283 template <typename, typename, typename> class _Base>
2285 operator<(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2286 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2287 { return __lhs.compare(__rhs) < 0; }
2290 * @brief Test if string precedes C string.
2291 * @param __lhs String.
2292 * @param __rhs C string.
2293 * @return True if @a __lhs precedes @a __rhs. False otherwise.
2295 template<typename _CharT, typename _Traits, typename _Alloc,
2296 template <typename, typename, typename> class _Base>
2298 operator<(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2299 const _CharT* __rhs)
2300 { return __lhs.compare(__rhs) < 0; }
2303 * @brief Test if C string precedes string.
2304 * @param __lhs C string.
2305 * @param __rhs String.
2306 * @return True if @a __lhs precedes @a __rhs. False otherwise.
2308 template<typename _CharT, typename _Traits, typename _Alloc,
2309 template <typename, typename, typename> class _Base>
2311 operator<(const _CharT* __lhs,
2312 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2313 { return __rhs.compare(__lhs) > 0; }
2317 * @brief Test if string follows string.
2318 * @param __lhs First string.
2319 * @param __rhs Second string.
2320 * @return True if @a __lhs follows @a __rhs. False otherwise.
2322 template<typename _CharT, typename _Traits, typename _Alloc,
2323 template <typename, typename, typename> class _Base>
2325 operator>(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2326 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2327 { return __lhs.compare(__rhs) > 0; }
2330 * @brief Test if string follows C string.
2331 * @param __lhs String.
2332 * @param __rhs C string.
2333 * @return True if @a __lhs follows @a __rhs. False otherwise.
2335 template<typename _CharT, typename _Traits, typename _Alloc,
2336 template <typename, typename, typename> class _Base>
2338 operator>(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2339 const _CharT* __rhs)
2340 { return __lhs.compare(__rhs) > 0; }
2343 * @brief Test if C string follows string.
2344 * @param __lhs C string.
2345 * @param __rhs String.
2346 * @return True if @a __lhs follows @a __rhs. False otherwise.
2348 template<typename _CharT, typename _Traits, typename _Alloc,
2349 template <typename, typename, typename> class _Base>
2351 operator>(const _CharT* __lhs,
2352 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2353 { return __rhs.compare(__lhs) < 0; }
2357 * @brief Test if string doesn't follow string.
2358 * @param __lhs First string.
2359 * @param __rhs Second string.
2360 * @return True if @a __lhs doesn't follow @a __rhs. False otherwise.
2362 template<typename _CharT, typename _Traits, typename _Alloc,
2363 template <typename, typename, typename> class _Base>
2365 operator<=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2366 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2367 { return __lhs.compare(__rhs) <= 0; }
2370 * @brief Test if string doesn't follow C string.
2371 * @param __lhs String.
2372 * @param __rhs C string.
2373 * @return True if @a __lhs doesn't follow @a __rhs. False otherwise.
2375 template<typename _CharT, typename _Traits, typename _Alloc,
2376 template <typename, typename, typename> class _Base>
2378 operator<=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2379 const _CharT* __rhs)
2380 { return __lhs.compare(__rhs) <= 0; }
2383 * @brief Test if C string doesn't follow string.
2384 * @param __lhs C string.
2385 * @param __rhs String.
2386 * @return True if @a __lhs doesn't follow @a __rhs. False otherwise.
2388 template<typename _CharT, typename _Traits, typename _Alloc,
2389 template <typename, typename, typename> class _Base>
2391 operator<=(const _CharT* __lhs,
2392 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2393 { return __rhs.compare(__lhs) >= 0; }
2397 * @brief Test if string doesn't precede string.
2398 * @param __lhs First string.
2399 * @param __rhs Second string.
2400 * @return True if @a __lhs doesn't precede @a __rhs. False otherwise.
2402 template<typename _CharT, typename _Traits, typename _Alloc,
2403 template <typename, typename, typename> class _Base>
2405 operator>=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2406 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2407 { return __lhs.compare(__rhs) >= 0; }
2410 * @brief Test if string doesn't precede C string.
2411 * @param __lhs String.
2412 * @param __rhs C string.
2413 * @return True if @a __lhs doesn't precede @a __rhs. False otherwise.
2415 template<typename _CharT, typename _Traits, typename _Alloc,
2416 template <typename, typename, typename> class _Base>
2418 operator>=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2419 const _CharT* __rhs)
2420 { return __lhs.compare(__rhs) >= 0; }
2423 * @brief Test if C string doesn't precede string.
2424 * @param __lhs C string.
2425 * @param __rhs String.
2426 * @return True if @a __lhs doesn't precede @a __rhs. False otherwise.
2428 template<typename _CharT, typename _Traits, typename _Alloc,
2429 template <typename, typename, typename> class _Base>
2431 operator>=(const _CharT* __lhs,
2432 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2433 { return __rhs.compare(__lhs) <= 0; }
2436 * @brief Swap contents of two strings.
2437 * @param __lhs First string.
2438 * @param __rhs Second string.
2440 * Exchanges the contents of @a __lhs and @a __rhs in constant time.
2442 template<typename _CharT, typename _Traits, typename _Alloc,
2443 template <typename, typename, typename> class _Base>
2445 swap(__versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2446 __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2447 { __lhs.swap(__rhs); }
2449 _GLIBCXX_END_NAMESPACE_VERSION
2452 namespace std _GLIBCXX_VISIBILITY(default)
2454 _GLIBCXX_BEGIN_NAMESPACE_VERSION
2457 * @brief Read stream into a string.
2458 * @param __is Input stream.
2459 * @param __str Buffer to store into.
2460 * @return Reference to the input stream.
2462 * Stores characters from @a __is into @a __str until whitespace is
2463 * found, the end of the stream is encountered, or str.max_size()
2464 * is reached. If is.width() is non-zero, that is the limit on the
2465 * number of characters stored into @a __str. Any previous
2466 * contents of @a __str are erased.
2468 template<typename _CharT, typename _Traits, typename _Alloc,
2469 template <typename, typename, typename> class _Base>
2470 basic_istream<_CharT, _Traits>&
2471 operator>>(basic_istream<_CharT, _Traits>& __is,
2472 __gnu_cxx::__versa_string<_CharT, _Traits,
2473 _Alloc, _Base>& __str);
2476 * @brief Write string to a stream.
2477 * @param __os Output stream.
2478 * @param __str String to write out.
2479 * @return Reference to the output stream.
2481 * Output characters of @a __str into os following the same rules as for
2482 * writing a C string.
2484 template<typename _CharT, typename _Traits, typename _Alloc,
2485 template <typename, typename, typename> class _Base>
2486 inline basic_ostream<_CharT, _Traits>&
2487 operator<<(basic_ostream<_CharT, _Traits>& __os,
2488 const __gnu_cxx::__versa_string<_CharT, _Traits, _Alloc,
2491 // _GLIBCXX_RESOLVE_LIB_DEFECTS
2492 // 586. string inserter not a formatted function
2493 return __ostream_insert(__os, __str.data(), __str.size());
2497 * @brief Read a line from stream into a string.
2498 * @param __is Input stream.
2499 * @param __str Buffer to store into.
2500 * @param __delim Character marking end of line.
2501 * @return Reference to the input stream.
2503 * Stores characters from @a __is into @a __str until @a __delim is
2504 * found, the end of the stream is encountered, or str.max_size()
2505 * is reached. If is.width() is non-zero, that is the limit on the
2506 * number of characters stored into @a __str. Any previous
2507 * contents of @a __str are erased. If @a delim was encountered,
2508 * it is extracted but not stored into @a __str.
2510 template<typename _CharT, typename _Traits, typename _Alloc,
2511 template <typename, typename, typename> class _Base>
2512 basic_istream<_CharT, _Traits>&
2513 getline(basic_istream<_CharT, _Traits>& __is,
2514 __gnu_cxx::__versa_string<_CharT, _Traits, _Alloc, _Base>& __str,
2518 * @brief Read a line from stream into a string.
2519 * @param __is Input stream.
2520 * @param __str Buffer to store into.
2521 * @return Reference to the input stream.
2523 * Stores characters from is into @a __str until '\n' is
2524 * found, the end of the stream is encountered, or str.max_size()
2525 * is reached. If is.width() is non-zero, that is the limit on the
2526 * number of characters stored into @a __str. Any previous
2527 * contents of @a __str are erased. If end of line was
2528 * encountered, it is extracted but not stored into @a __str.
2530 template<typename _CharT, typename _Traits, typename _Alloc,
2531 template <typename, typename, typename> class _Base>
2532 inline basic_istream<_CharT, _Traits>&
2533 getline(basic_istream<_CharT, _Traits>& __is,
2534 __gnu_cxx::__versa_string<_CharT, _Traits, _Alloc, _Base>& __str)
2535 { return getline(__is, __str, __is.widen('\n')); }
2537 _GLIBCXX_END_NAMESPACE_VERSION
2540 #if (defined(__GXX_EXPERIMENTAL_CXX0X__) && defined(_GLIBCXX_USE_C99))
2542 #include <ext/string_conversions.h>
2544 namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
2546 _GLIBCXX_BEGIN_NAMESPACE_VERSION
2548 // 21.4 Numeric Conversions [string.conversions].
2550 stoi(const __vstring& __str, std::size_t* __idx = 0, int __base = 10)
2551 { return __gnu_cxx::__stoa<long, int>(&std::strtol, "stoi", __str.c_str(),
2555 stol(const __vstring& __str, std::size_t* __idx = 0, int __base = 10)
2556 { return __gnu_cxx::__stoa(&std::strtol, "stol", __str.c_str(),
2559 inline unsigned long
2560 stoul(const __vstring& __str, std::size_t* __idx = 0, int __base = 10)
2561 { return __gnu_cxx::__stoa(&std::strtoul, "stoul", __str.c_str(),
2565 stoll(const __vstring& __str, std::size_t* __idx = 0, int __base = 10)
2566 { return __gnu_cxx::__stoa(&std::strtoll, "stoll", __str.c_str(),
2569 inline unsigned long long
2570 stoull(const __vstring& __str, std::size_t* __idx, int __base = 10)
2571 { return __gnu_cxx::__stoa(&std::strtoull, "stoull", __str.c_str(),
2574 // NB: strtof vs strtod.
2576 stof(const __vstring& __str, std::size_t* __idx = 0)
2577 { return __gnu_cxx::__stoa(&std::strtof, "stof", __str.c_str(), __idx); }
2580 stod(const __vstring& __str, std::size_t* __idx = 0)
2581 { return __gnu_cxx::__stoa(&std::strtod, "stod", __str.c_str(), __idx); }
2584 stold(const __vstring& __str, std::size_t* __idx = 0)
2585 { return __gnu_cxx::__stoa(&std::strtold, "stold", __str.c_str(), __idx); }
2587 // NB: (v)snprintf vs sprintf.
2591 to_string(int __val)
2592 { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, 4 * sizeof(int),
2596 to_string(unsigned __val)
2597 { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf,
2598 4 * sizeof(unsigned),
2602 to_string(long __val)
2603 { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf,
2608 to_string(unsigned long __val)
2609 { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf,
2610 4 * sizeof(unsigned long),
2615 to_string(long long __val)
2616 { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf,
2617 4 * sizeof(long long),
2621 to_string(unsigned long long __val)
2622 { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf,
2623 4 * sizeof(unsigned long long),
2627 to_string(float __val)
2629 const int __n = __numeric_traits<float>::__max_exponent10 + 20;
2630 return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, __n,
2635 to_string(double __val)
2637 const int __n = __numeric_traits<double>::__max_exponent10 + 20;
2638 return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, __n,
2643 to_string(long double __val)
2645 const int __n = __numeric_traits<long double>::__max_exponent10 + 20;
2646 return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, __n,
2650 #ifdef _GLIBCXX_USE_WCHAR_T
2652 stoi(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10)
2653 { return __gnu_cxx::__stoa<long, int>(&std::wcstol, "stoi", __str.c_str(),
2657 stol(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10)
2658 { return __gnu_cxx::__stoa(&std::wcstol, "stol", __str.c_str(),
2661 inline unsigned long
2662 stoul(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10)
2663 { return __gnu_cxx::__stoa(&std::wcstoul, "stoul", __str.c_str(),
2667 stoll(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10)
2668 { return __gnu_cxx::__stoa(&std::wcstoll, "stoll", __str.c_str(),
2671 inline unsigned long long
2672 stoull(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10)
2673 { return __gnu_cxx::__stoa(&std::wcstoull, "stoull", __str.c_str(),
2676 // NB: wcstof vs wcstod.
2678 stof(const __wvstring& __str, std::size_t* __idx = 0)
2679 { return __gnu_cxx::__stoa(&std::wcstof, "stof", __str.c_str(), __idx); }
2682 stod(const __wvstring& __str, std::size_t* __idx = 0)
2683 { return __gnu_cxx::__stoa(&std::wcstod, "stod", __str.c_str(), __idx); }
2686 stold(const __wvstring& __str, std::size_t* __idx = 0)
2687 { return __gnu_cxx::__stoa(&std::wcstold, "stold", __str.c_str(), __idx); }
2689 #ifndef _GLIBCXX_HAVE_BROKEN_VSWPRINTF
2692 to_wstring(int __val)
2693 { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
2698 to_wstring(unsigned __val)
2699 { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
2700 4 * sizeof(unsigned),
2704 to_wstring(long __val)
2705 { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
2710 to_wstring(unsigned long __val)
2711 { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
2712 4 * sizeof(unsigned long),
2716 to_wstring(long long __val)
2717 { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
2718 4 * sizeof(long long),
2722 to_wstring(unsigned long long __val)
2723 { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
2724 4 * sizeof(unsigned long long),
2728 to_wstring(float __val)
2730 const int __n = __numeric_traits<float>::__max_exponent10 + 20;
2731 return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, __n,
2736 to_wstring(double __val)
2738 const int __n = __numeric_traits<double>::__max_exponent10 + 20;
2739 return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, __n,
2744 to_wstring(long double __val)
2746 const int __n = __numeric_traits<long double>::__max_exponent10 + 20;
2747 return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, __n,
2753 _GLIBCXX_END_NAMESPACE_VERSION
2758 #ifdef __GXX_EXPERIMENTAL_CXX0X__
2760 #include <bits/functional_hash.h>
2762 namespace std _GLIBCXX_VISIBILITY(default)
2764 _GLIBCXX_BEGIN_NAMESPACE_VERSION
2766 /// std::hash specialization for __vstring.
2768 struct hash<__gnu_cxx::__vstring>
2769 : public __hash_base<size_t, __gnu_cxx::__vstring>
2772 operator()(const __gnu_cxx::__vstring& __s) const noexcept
2773 { return std::_Hash_impl::hash(__s.data(), __s.length()); }
2776 #ifdef _GLIBCXX_USE_WCHAR_T
2777 /// std::hash specialization for __wvstring.
2779 struct hash<__gnu_cxx::__wvstring>
2780 : public __hash_base<size_t, __gnu_cxx::__wvstring>
2783 operator()(const __gnu_cxx::__wvstring& __s) const noexcept
2784 { return std::_Hash_impl::hash(__s.data(),
2785 __s.length() * sizeof(wchar_t)); }
2789 #ifdef _GLIBCXX_USE_C99_STDINT_TR1
2790 /// std::hash specialization for __u16vstring.
2792 struct hash<__gnu_cxx::__u16vstring>
2793 : public __hash_base<size_t, __gnu_cxx::__u16vstring>
2796 operator()(const __gnu_cxx::__u16vstring& __s) const noexcept
2797 { return std::_Hash_impl::hash(__s.data(),
2798 __s.length() * sizeof(char16_t)); }
2801 /// std::hash specialization for __u32vstring.
2803 struct hash<__gnu_cxx::__u32vstring>
2804 : public __hash_base<size_t, __gnu_cxx::__u32vstring>
2807 operator()(const __gnu_cxx::__u32vstring& __s) const noexcept
2808 { return std::_Hash_impl::hash(__s.data(),
2809 __s.length() * sizeof(char32_t)); }
2813 _GLIBCXX_END_NAMESPACE_VERSION
2816 #endif /* __GXX_EXPERIMENTAL_CXX0X__ */
2818 #include "vstring.tcc"
2820 #endif /* _VSTRING_H */