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 #include <initializer_list>
36 #include <ext/vstring_util.h>
37 #include <ext/rc_string_base.h>
38 #include <ext/sso_string_base.h>
40 namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
42 _GLIBCXX_BEGIN_NAMESPACE_VERSION
45 * @class __versa_string vstring.h
46 * @brief Template class __versa_string.
49 * Data structure managing sequences of characters and
50 * character-like objects.
52 template<typename _CharT, typename _Traits, typename _Alloc,
53 template <typename, typename, typename> class _Base>
55 : private _Base<_CharT, _Traits, _Alloc>
57 typedef _Base<_CharT, _Traits, _Alloc> __vstring_base;
58 typedef typename __vstring_base::_CharT_alloc_type _CharT_alloc_type;
62 typedef _Traits traits_type;
63 typedef typename _Traits::char_type value_type;
64 typedef _Alloc allocator_type;
65 typedef typename _CharT_alloc_type::size_type size_type;
66 typedef typename _CharT_alloc_type::difference_type difference_type;
67 typedef value_type& reference;
68 typedef const value_type& const_reference;
69 typedef typename _CharT_alloc_type::pointer pointer;
70 typedef typename _CharT_alloc_type::const_pointer const_pointer;
71 typedef __gnu_cxx::__normal_iterator<pointer, __versa_string> iterator;
72 typedef __gnu_cxx::__normal_iterator<const_pointer, __versa_string>
74 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
75 typedef std::reverse_iterator<iterator> reverse_iterator;
77 // Data Member (public):
78 /// Value returned by various member functions when they fail.
79 static const size_type npos = static_cast<size_type>(-1);
83 _M_check(size_type __pos, const char* __s) const
85 if (__pos > this->size())
86 std::__throw_out_of_range(__N(__s));
91 _M_check_length(size_type __n1, size_type __n2, const char* __s) const
93 if (this->max_size() - (this->size() - __n1) < __n2)
94 std::__throw_length_error(__N(__s));
97 // NB: _M_limit doesn't check for a bad __pos value.
99 _M_limit(size_type __pos, size_type __off) const
101 const bool __testoff = __off < this->size() - __pos;
102 return __testoff ? __off : this->size() - __pos;
105 // True if _Rep and source do not overlap.
107 _M_disjunct(const _CharT* __s) const
109 return (std::less<const _CharT*>()(__s, this->_M_data())
110 || std::less<const _CharT*>()(this->_M_data()
111 + this->size(), __s));
114 // For the internal use we have functions similar to `begin'/`end'
115 // but they do not call _M_leak.
118 { return iterator(this->_M_data()); }
122 { return iterator(this->_M_data() + this->_M_length()); }
125 // Construct/copy/destroy:
126 // NB: We overload ctors in some cases instead of using default
127 // arguments, per 17.4.4.4 para. 2 item 2.
130 * @brief Default constructor creates an empty string.
133 : __vstring_base() { }
136 * @brief Construct an empty string using allocator @a a.
139 __versa_string(const _Alloc& __a)
140 : __vstring_base(__a) { }
142 // NB: per LWG issue 42, semantics different from IS:
144 * @brief Construct string with copy of value of @a __str.
145 * @param __str Source string.
147 __versa_string(const __versa_string& __str)
148 : __vstring_base(__str) { }
150 #ifdef __GXX_EXPERIMENTAL_CXX0X__
152 * @brief String move constructor.
153 * @param __str Source string.
155 * The newly-constructed %string contains the exact contents of
156 * @a __str. The contents of @a __str are a valid, but unspecified
159 __versa_string(__versa_string&& __str) noexcept
160 : __vstring_base(std::move(__str)) { }
163 * @brief Construct string from an initializer list.
164 * @param __l std::initializer_list of characters.
165 * @param __a Allocator to use (default is default allocator).
167 __versa_string(std::initializer_list<_CharT> __l,
168 const _Alloc& __a = _Alloc())
169 : __vstring_base(__l.begin(), __l.end(), __a) { }
173 * @brief Construct string as copy of a substring.
174 * @param __str Source string.
175 * @param __pos Index of first character to copy from.
176 * @param __n Number of characters to copy (default remainder).
178 __versa_string(const __versa_string& __str, size_type __pos,
179 size_type __n = npos)
180 : __vstring_base(__str._M_data()
181 + __str._M_check(__pos,
182 "__versa_string::__versa_string"),
183 __str._M_data() + __str._M_limit(__pos, __n)
184 + __pos, _Alloc()) { }
187 * @brief Construct string as copy of a substring.
188 * @param __str Source string.
189 * @param __pos Index of first character to copy from.
190 * @param __n Number of characters to copy.
191 * @param __a Allocator to use.
193 __versa_string(const __versa_string& __str, size_type __pos,
194 size_type __n, const _Alloc& __a)
195 : __vstring_base(__str._M_data()
196 + __str._M_check(__pos,
197 "__versa_string::__versa_string"),
198 __str._M_data() + __str._M_limit(__pos, __n)
202 * @brief Construct string initialized by a character array.
203 * @param __s Source character array.
204 * @param __n Number of characters to copy.
205 * @param __a Allocator to use (default is default allocator).
207 * NB: @a __s must have at least @a __n characters, '\\0' has no special
210 __versa_string(const _CharT* __s, size_type __n,
211 const _Alloc& __a = _Alloc())
212 : __vstring_base(__s, __s + __n, __a) { }
215 * @brief Construct string as copy of a C string.
216 * @param __s Source C string.
217 * @param __a Allocator to use (default is default allocator).
219 __versa_string(const _CharT* __s, const _Alloc& __a = _Alloc())
220 : __vstring_base(__s, __s ? __s + traits_type::length(__s) :
224 * @brief Construct string as multiple characters.
225 * @param __n Number of characters.
226 * @param __c Character to use.
227 * @param __a Allocator to use (default is default allocator).
229 __versa_string(size_type __n, _CharT __c, const _Alloc& __a = _Alloc())
230 : __vstring_base(__n, __c, __a) { }
233 * @brief Construct string as copy of a range.
234 * @param __beg Start of range.
235 * @param __end End of range.
236 * @param __a Allocator to use (default is default allocator).
238 template<class _InputIterator>
239 __versa_string(_InputIterator __beg, _InputIterator __end,
240 const _Alloc& __a = _Alloc())
241 : __vstring_base(__beg, __end, __a) { }
244 * @brief Destroy the string instance.
246 ~__versa_string() _GLIBCXX_NOEXCEPT { }
249 * @brief Assign the value of @a str to this string.
250 * @param __str Source string.
253 operator=(const __versa_string& __str)
254 { return this->assign(__str); }
256 #ifdef __GXX_EXPERIMENTAL_CXX0X__
258 * @brief String move assignment operator.
259 * @param __str Source string.
261 * The contents of @a __str are moved into this string (without
262 * copying). @a __str is a valid, but unspecified string.
265 operator=(__versa_string&& __str)
273 * @brief Set value to string constructed from initializer list.
274 * @param __l std::initializer_list.
277 operator=(std::initializer_list<_CharT> __l)
279 this->assign(__l.begin(), __l.end());
285 * @brief Copy contents of @a __s into this string.
286 * @param __s Source null-terminated string.
289 operator=(const _CharT* __s)
290 { return this->assign(__s); }
293 * @brief Set value to string of length 1.
294 * @param __c Source character.
296 * Assigning to a character makes this string length 1 and
297 * (*this)[0] == @a __c.
300 operator=(_CharT __c)
302 this->assign(1, __c);
308 * Returns a read/write iterator that points to the first character in
309 * the %string. Unshares the string.
312 begin() _GLIBCXX_NOEXCEPT
315 return iterator(this->_M_data());
319 * Returns a read-only (constant) iterator that points to the first
320 * character in the %string.
323 begin() const _GLIBCXX_NOEXCEPT
324 { return const_iterator(this->_M_data()); }
327 * Returns a read/write iterator that points one past the last
328 * character in the %string. Unshares the string.
331 end() _GLIBCXX_NOEXCEPT
334 return iterator(this->_M_data() + this->size());
338 * Returns a read-only (constant) iterator that points one past the
339 * last character in the %string.
342 end() const _GLIBCXX_NOEXCEPT
343 { return const_iterator(this->_M_data() + this->size()); }
346 * Returns a read/write reverse iterator that points to the last
347 * character in the %string. Iteration is done in reverse element
348 * order. Unshares the string.
351 rbegin() _GLIBCXX_NOEXCEPT
352 { return reverse_iterator(this->end()); }
355 * Returns a read-only (constant) reverse iterator that points
356 * to the last character in the %string. Iteration is done in
357 * reverse element order.
359 const_reverse_iterator
360 rbegin() const _GLIBCXX_NOEXCEPT
361 { return const_reverse_iterator(this->end()); }
364 * Returns a read/write reverse iterator that points to one before the
365 * first character in the %string. Iteration is done in reverse
366 * element order. Unshares the string.
369 rend() _GLIBCXX_NOEXCEPT
370 { return reverse_iterator(this->begin()); }
373 * Returns a read-only (constant) reverse iterator that points
374 * to one before the first character in the %string. Iteration
375 * is done in reverse element order.
377 const_reverse_iterator
378 rend() const _GLIBCXX_NOEXCEPT
379 { return const_reverse_iterator(this->begin()); }
381 #ifdef __GXX_EXPERIMENTAL_CXX0X__
383 * Returns a read-only (constant) iterator that points to the first
384 * character in the %string.
387 cbegin() const noexcept
388 { return const_iterator(this->_M_data()); }
391 * Returns a read-only (constant) iterator that points one past the
392 * last character in the %string.
395 cend() const noexcept
396 { return const_iterator(this->_M_data() + this->size()); }
399 * Returns a read-only (constant) reverse iterator that points
400 * to the last character in the %string. Iteration is done in
401 * reverse element order.
403 const_reverse_iterator
404 crbegin() const noexcept
405 { return const_reverse_iterator(this->end()); }
408 * Returns a read-only (constant) reverse iterator that points
409 * to one before the first character in the %string. Iteration
410 * is done in reverse element order.
412 const_reverse_iterator
413 crend() const noexcept
414 { return const_reverse_iterator(this->begin()); }
419 /// Returns the number of characters in the string, not including any
420 /// null-termination.
422 size() const _GLIBCXX_NOEXCEPT
423 { return this->_M_length(); }
425 /// Returns the number of characters in the string, not including any
426 /// null-termination.
428 length() const _GLIBCXX_NOEXCEPT
429 { return this->_M_length(); }
431 /// Returns the size() of the largest possible %string.
433 max_size() const _GLIBCXX_NOEXCEPT
434 { return this->_M_max_size(); }
437 * @brief Resizes the %string to the specified number of characters.
438 * @param __n Number of characters the %string should contain.
439 * @param __c Character to fill any new elements.
441 * This function will %resize the %string to the specified
442 * number of characters. If the number is smaller than the
443 * %string's current size the %string is truncated, otherwise
444 * the %string is extended and new elements are set to @a __c.
447 resize(size_type __n, _CharT __c);
450 * @brief Resizes the %string to the specified number of characters.
451 * @param __n Number of characters the %string should contain.
453 * This function will resize the %string to the specified
454 * length. If the new size is smaller than the %string's
455 * current size the %string is truncated, otherwise the %string
456 * is extended and new characters are default-constructed. For
457 * basic types such as char, this means setting them to 0.
460 resize(size_type __n)
461 { this->resize(__n, _CharT()); }
463 #ifdef __GXX_EXPERIMENTAL_CXX0X__
464 /// A non-binding request to reduce capacity() to size().
468 if (capacity() > size())
471 { this->reserve(0); }
479 * Returns the total number of characters that the %string can
480 * hold before needing to allocate more memory.
483 capacity() const _GLIBCXX_NOEXCEPT
484 { return this->_M_capacity(); }
487 * @brief Attempt to preallocate enough memory for specified number of
489 * @param __res_arg Number of characters required.
490 * @throw std::length_error If @a __res_arg exceeds @c max_size().
492 * This function attempts to reserve enough memory for the
493 * %string to hold the specified number of characters. If the
494 * number requested is more than max_size(), length_error is
497 * The advantage of this function is that if optimal code is a
498 * necessity and the user can determine the string length that
499 * will be required, the user can reserve the memory in
500 * %advance, and thus prevent a possible reallocation of memory
501 * and copying of %string data.
504 reserve(size_type __res_arg = 0)
505 { this->_M_reserve(__res_arg); }
508 * Erases the string, making it empty.
511 clear() _GLIBCXX_NOEXCEPT
512 { this->_M_clear(); }
515 * Returns true if the %string is empty. Equivalent to
516 * <code>*this == ""</code>.
519 empty() const _GLIBCXX_NOEXCEPT
520 { return this->size() == 0; }
524 * @brief Subscript access to the data contained in the %string.
525 * @param __pos The index of the character to access.
526 * @return Read-only (constant) reference to the character.
528 * This operator allows for easy, array-style, data access.
529 * Note that data access with this operator is unchecked and
530 * out_of_range lookups are not defined. (For checked lookups
534 operator[] (size_type __pos) const
536 _GLIBCXX_DEBUG_ASSERT(__pos <= this->size());
537 return this->_M_data()[__pos];
541 * @brief Subscript access to the data contained in the %string.
542 * @param __pos The index of the character to access.
543 * @return Read/write reference to the character.
545 * This operator allows for easy, array-style, data access.
546 * Note that data access with this operator is unchecked and
547 * out_of_range lookups are not defined. (For checked lookups
548 * see at().) Unshares the string.
551 operator[](size_type __pos)
553 // allow pos == size() as v3 extension:
554 _GLIBCXX_DEBUG_ASSERT(__pos <= this->size());
555 // but be strict in pedantic mode:
556 _GLIBCXX_DEBUG_PEDASSERT(__pos < this->size());
558 return this->_M_data()[__pos];
562 * @brief Provides access to the data contained in the %string.
563 * @param __n The index of the character to access.
564 * @return Read-only (const) reference to the character.
565 * @throw std::out_of_range If @a __n is an invalid index.
567 * This function provides for safer data access. The parameter
568 * is first checked that it is in the range of the string. The
569 * function throws out_of_range if the check fails.
572 at(size_type __n) const
574 if (__n >= this->size())
575 std::__throw_out_of_range(__N("__versa_string::at"));
576 return this->_M_data()[__n];
580 * @brief Provides access to the data contained in the %string.
581 * @param __n The index of the character to access.
582 * @return Read/write reference to the character.
583 * @throw std::out_of_range If @a __n is an invalid index.
585 * This function provides for safer data access. The parameter
586 * is first checked that it is in the range of the string. The
587 * function throws out_of_range if the check fails. Success
588 * results in unsharing the string.
593 if (__n >= this->size())
594 std::__throw_out_of_range(__N("__versa_string::at"));
596 return this->_M_data()[__n];
599 #ifdef __GXX_EXPERIMENTAL_CXX0X__
601 * Returns a read/write reference to the data at the first
602 * element of the %string.
606 { return operator[](0); }
609 * Returns a read-only (constant) reference to the data at the first
610 * element of the %string.
614 { return operator[](0); }
617 * Returns a read/write reference to the data at the last
618 * element of the %string.
622 { return operator[](this->size() - 1); }
625 * Returns a read-only (constant) reference to the data at the
626 * last element of the %string.
630 { return operator[](this->size() - 1); }
635 * @brief Append a string to this string.
636 * @param __str The string to append.
637 * @return Reference to this string.
640 operator+=(const __versa_string& __str)
641 { return this->append(__str); }
644 * @brief Append a C string.
645 * @param __s The C string to append.
646 * @return Reference to this string.
649 operator+=(const _CharT* __s)
650 { return this->append(__s); }
653 * @brief Append a character.
654 * @param __c The character to append.
655 * @return Reference to this string.
658 operator+=(_CharT __c)
660 this->push_back(__c);
664 #ifdef __GXX_EXPERIMENTAL_CXX0X__
666 * @brief Append an initializer_list of characters.
667 * @param __l The initializer_list of characters to be appended.
668 * @return Reference to this string.
671 operator+=(std::initializer_list<_CharT> __l)
672 { return this->append(__l.begin(), __l.end()); }
673 #endif // __GXX_EXPERIMENTAL_CXX0X__
676 * @brief Append a string to this string.
677 * @param __str The string to append.
678 * @return Reference to this string.
681 append(const __versa_string& __str)
682 { return _M_append(__str._M_data(), __str.size()); }
685 * @brief Append a substring.
686 * @param __str The string to append.
687 * @param __pos Index of the first character of str to append.
688 * @param __n The number of characters to append.
689 * @return Reference to this string.
690 * @throw std::out_of_range if @a pos is not a valid index.
692 * This function appends @a __n characters from @a __str
693 * starting at @a __pos to this string. If @a __n is is larger
694 * than the number of available characters in @a __str, the
695 * remainder of @a __str is appended.
698 append(const __versa_string& __str, size_type __pos, size_type __n)
699 { return _M_append(__str._M_data()
700 + __str._M_check(__pos, "__versa_string::append"),
701 __str._M_limit(__pos, __n)); }
704 * @brief Append a C substring.
705 * @param __s The C string to append.
706 * @param __n The number of characters to append.
707 * @return Reference to this string.
710 append(const _CharT* __s, size_type __n)
712 __glibcxx_requires_string_len(__s, __n);
713 _M_check_length(size_type(0), __n, "__versa_string::append");
714 return _M_append(__s, __n);
718 * @brief Append a C string.
719 * @param __s The C string to append.
720 * @return Reference to this string.
723 append(const _CharT* __s)
725 __glibcxx_requires_string(__s);
726 const size_type __n = traits_type::length(__s);
727 _M_check_length(size_type(0), __n, "__versa_string::append");
728 return _M_append(__s, __n);
732 * @brief Append multiple characters.
733 * @param __n The number of characters to append.
734 * @param __c The character to use.
735 * @return Reference to this string.
737 * Appends n copies of c to this string.
740 append(size_type __n, _CharT __c)
741 { return _M_replace_aux(this->size(), size_type(0), __n, __c); }
743 #ifdef __GXX_EXPERIMENTAL_CXX0X__
745 * @brief Append an initializer_list of characters.
746 * @param __l The initializer_list of characters to append.
747 * @return Reference to this string.
750 append(std::initializer_list<_CharT> __l)
751 { return this->append(__l.begin(), __l.end()); }
752 #endif // __GXX_EXPERIMENTAL_CXX0X__
755 * @brief Append a range of characters.
756 * @param __first Iterator referencing the first character to append.
757 * @param __last Iterator marking the end of the range.
758 * @return Reference to this string.
760 * Appends characters in the range [first,last) to this string.
762 template<class _InputIterator>
764 append(_InputIterator __first, _InputIterator __last)
765 { return this->replace(_M_iend(), _M_iend(), __first, __last); }
768 * @brief Append a single character.
769 * @param __c Character to append.
772 push_back(_CharT __c)
774 const size_type __size = this->size();
775 if (__size + 1 > this->capacity() || this->_M_is_shared())
776 this->_M_mutate(__size, size_type(0), 0, size_type(1));
777 traits_type::assign(this->_M_data()[__size], __c);
778 this->_M_set_length(__size + 1);
782 * @brief Set value to contents of another string.
783 * @param __str Source string to use.
784 * @return Reference to this string.
787 assign(const __versa_string& __str)
789 this->_M_assign(__str);
793 #ifdef __GXX_EXPERIMENTAL_CXX0X__
795 * @brief Set value to contents of another string.
796 * @param __str Source string to use.
797 * @return Reference to this string.
799 * This function sets this string to the exact contents of @a __str.
800 * @a __str is a valid, but unspecified string.
803 assign(__versa_string&& __str)
808 #endif // __GXX_EXPERIMENTAL_CXX0X__
811 * @brief Set value to a substring of a string.
812 * @param __str The string to use.
813 * @param __pos Index of the first character of str.
814 * @param __n Number of characters to use.
815 * @return Reference to this string.
816 * @throw std::out_of_range if @a __pos is not a valid index.
818 * This function sets this string to the substring of @a __str
819 * consisting of @a __n characters at @a __pos. If @a __n is
820 * is larger than the number of available characters in @a
821 * __str, the remainder of @a __str is used.
824 assign(const __versa_string& __str, size_type __pos, size_type __n)
825 { return _M_replace(size_type(0), this->size(), __str._M_data()
826 + __str._M_check(__pos, "__versa_string::assign"),
827 __str._M_limit(__pos, __n)); }
830 * @brief Set value to a C substring.
831 * @param __s The C string to use.
832 * @param __n Number of characters to use.
833 * @return Reference to this string.
835 * This function sets the value of this string to the first @a
836 * __n characters of @a __s. If @a __n is is larger than the
837 * number of available characters in @a __s, the remainder of
841 assign(const _CharT* __s, size_type __n)
843 __glibcxx_requires_string_len(__s, __n);
844 return _M_replace(size_type(0), this->size(), __s, __n);
848 * @brief Set value to contents of a C string.
849 * @param __s The C string to use.
850 * @return Reference to this string.
852 * This function sets the value of this string to the value of
853 * @a __s. The data is copied, so there is no dependence on @a
854 * __s once the function returns.
857 assign(const _CharT* __s)
859 __glibcxx_requires_string(__s);
860 return _M_replace(size_type(0), this->size(), __s,
861 traits_type::length(__s));
865 * @brief Set value to multiple characters.
866 * @param __n Length of the resulting string.
867 * @param __c The character to use.
868 * @return Reference to this string.
870 * This function sets the value of this string to @a __n copies of
874 assign(size_type __n, _CharT __c)
875 { return _M_replace_aux(size_type(0), this->size(), __n, __c); }
878 * @brief Set value to a range of characters.
879 * @param __first Iterator referencing the first character to append.
880 * @param __last Iterator marking the end of the range.
881 * @return Reference to this string.
883 * Sets value of string to characters in the range
886 template<class _InputIterator>
888 assign(_InputIterator __first, _InputIterator __last)
889 { return this->replace(_M_ibegin(), _M_iend(), __first, __last); }
891 #ifdef __GXX_EXPERIMENTAL_CXX0X__
893 * @brief Set value to an initializer_list of characters.
894 * @param __l The initializer_list of characters to assign.
895 * @return Reference to this string.
898 assign(std::initializer_list<_CharT> __l)
899 { return this->assign(__l.begin(), __l.end()); }
900 #endif // __GXX_EXPERIMENTAL_CXX0X__
903 * @brief Insert multiple characters.
904 * @param __p Iterator referencing location in string to insert at.
905 * @param __n Number of characters to insert
906 * @param __c The character to insert.
907 * @throw std::length_error If new length exceeds @c max_size().
909 * Inserts @a __n copies of character @a __c starting at the
910 * position referenced by iterator @a __p. If adding
911 * characters causes the length to exceed max_size(),
912 * length_error is thrown. The value of the string doesn't
913 * change if an error is thrown.
916 insert(iterator __p, size_type __n, _CharT __c)
917 { this->replace(__p, __p, __n, __c); }
920 * @brief Insert a range of characters.
921 * @param __p Iterator referencing location in string to insert at.
922 * @param __beg Start of range.
923 * @param __end End of range.
924 * @throw std::length_error If new length exceeds @c max_size().
926 * Inserts characters in range [beg,end). If adding characters
927 * causes the length to exceed max_size(), length_error is
928 * thrown. The value of the string doesn't change if an error
931 template<class _InputIterator>
933 insert(iterator __p, _InputIterator __beg, _InputIterator __end)
934 { this->replace(__p, __p, __beg, __end); }
936 #ifdef __GXX_EXPERIMENTAL_CXX0X__
938 * @brief Insert an initializer_list of characters.
939 * @param __p Iterator referencing location in string to insert at.
940 * @param __l The initializer_list of characters to insert.
941 * @throw std::length_error If new length exceeds @c max_size().
944 insert(iterator __p, std::initializer_list<_CharT> __l)
945 { this->insert(__p, __l.begin(), __l.end()); }
946 #endif // __GXX_EXPERIMENTAL_CXX0X__
949 * @brief Insert value of a string.
950 * @param __pos1 Iterator referencing location in string to insert at.
951 * @param __str The string to insert.
952 * @return Reference to this string.
953 * @throw std::length_error If new length exceeds @c max_size().
955 * Inserts value of @a __str starting at @a __pos1. If adding
956 * characters causes the length to exceed max_size(),
957 * length_error is thrown. The value of the string doesn't
958 * change if an error is thrown.
961 insert(size_type __pos1, const __versa_string& __str)
962 { return this->replace(__pos1, size_type(0),
963 __str._M_data(), __str.size()); }
966 * @brief Insert a substring.
967 * @param __pos1 Iterator referencing location in string to insert at.
968 * @param __str The string to insert.
969 * @param __pos2 Start of characters in str to insert.
970 * @param __n Number of characters to insert.
971 * @return Reference to this string.
972 * @throw std::length_error If new length exceeds @c max_size().
973 * @throw std::out_of_range If @a __pos1 > size() or
974 * @a __pos2 > @a __str.size().
976 * Starting at @a __pos1, insert @a __n character of @a __str
977 * beginning with @a __pos2. If adding characters causes the
978 * length to exceed max_size(), length_error is thrown. If @a
979 * __pos1 is beyond the end of this string or @a __pos2 is
980 * beyond the end of @a __str, out_of_range is thrown. The
981 * value of the string doesn't change if an error is thrown.
984 insert(size_type __pos1, const __versa_string& __str,
985 size_type __pos2, size_type __n)
986 { return this->replace(__pos1, size_type(0), __str._M_data()
987 + __str._M_check(__pos2, "__versa_string::insert"),
988 __str._M_limit(__pos2, __n)); }
991 * @brief Insert a C substring.
992 * @param __pos Iterator referencing location in string to insert at.
993 * @param __s The C string to insert.
994 * @param __n The number of characters to insert.
995 * @return Reference to this string.
996 * @throw std::length_error If new length exceeds @c max_size().
997 * @throw std::out_of_range If @a __pos is beyond the end of this
1000 * Inserts the first @a __n characters of @a __s starting at @a
1001 * __pos. If adding characters causes the length to exceed
1002 * max_size(), length_error is thrown. If @a __pos is beyond
1003 * end(), out_of_range is thrown. The value of the string
1004 * doesn't change if an error is thrown.
1007 insert(size_type __pos, const _CharT* __s, size_type __n)
1008 { return this->replace(__pos, size_type(0), __s, __n); }
1011 * @brief Insert a C string.
1012 * @param __pos Iterator referencing location in string to insert at.
1013 * @param __s The C string to insert.
1014 * @return Reference to this string.
1015 * @throw std::length_error If new length exceeds @c max_size().
1016 * @throw std::out_of_range If @a __pos is beyond the end of this
1019 * Inserts the first @a __n characters of @a __s starting at @a
1020 * __pos. If adding characters causes the length to exceed
1021 * max_size(), length_error is thrown. If @a __pos is beyond
1022 * end(), out_of_range is thrown. The value of the string
1023 * doesn't change if an error is thrown.
1026 insert(size_type __pos, const _CharT* __s)
1028 __glibcxx_requires_string(__s);
1029 return this->replace(__pos, size_type(0), __s,
1030 traits_type::length(__s));
1034 * @brief Insert multiple characters.
1035 * @param __pos Index in string to insert at.
1036 * @param __n Number of characters to insert
1037 * @param __c The character to insert.
1038 * @return Reference to this string.
1039 * @throw std::length_error If new length exceeds @c max_size().
1040 * @throw std::out_of_range If @a __pos is beyond the end of this
1043 * Inserts @a __n copies of character @a __c starting at index
1044 * @a __pos. If adding characters causes the length to exceed
1045 * max_size(), length_error is thrown. If @a __pos > length(),
1046 * out_of_range is thrown. The value of the string doesn't
1047 * change if an error is thrown.
1050 insert(size_type __pos, size_type __n, _CharT __c)
1051 { return _M_replace_aux(_M_check(__pos, "__versa_string::insert"),
1052 size_type(0), __n, __c); }
1055 * @brief Insert one character.
1056 * @param __p Iterator referencing position in string to insert at.
1057 * @param __c The character to insert.
1058 * @return Iterator referencing newly inserted char.
1059 * @throw std::length_error If new length exceeds @c max_size().
1061 * Inserts character @a __c at position referenced by @a __p.
1062 * If adding character causes the length to exceed max_size(),
1063 * length_error is thrown. If @a __p is beyond end of string,
1064 * out_of_range is thrown. The value of the string doesn't
1065 * change if an error is thrown.
1068 insert(iterator __p, _CharT __c)
1070 _GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend());
1071 const size_type __pos = __p - _M_ibegin();
1072 _M_replace_aux(__pos, size_type(0), size_type(1), __c);
1073 this->_M_set_leaked();
1074 return iterator(this->_M_data() + __pos);
1078 * @brief Remove characters.
1079 * @param __pos Index of first character to remove (default 0).
1080 * @param __n Number of characters to remove (default remainder).
1081 * @return Reference to this string.
1082 * @throw std::out_of_range If @a __pos is beyond the end of this
1085 * Removes @a __n characters from this string starting at @a
1086 * __pos. The length of the string is reduced by @a __n. If
1087 * there are < @a __n characters to remove, the remainder of
1088 * the string is truncated. If @a __p is beyond end of string,
1089 * out_of_range is thrown. The value of the string doesn't
1090 * change if an error is thrown.
1093 erase(size_type __pos = 0, size_type __n = npos)
1095 this->_M_erase(_M_check(__pos, "__versa_string::erase"),
1096 _M_limit(__pos, __n));
1101 * @brief Remove one character.
1102 * @param __position Iterator referencing the character to remove.
1103 * @return iterator referencing same location after removal.
1105 * Removes the character at @a __position from this string. The
1106 * value of the string doesn't change if an error is thrown.
1109 erase(iterator __position)
1111 _GLIBCXX_DEBUG_PEDASSERT(__position >= _M_ibegin()
1112 && __position < _M_iend());
1113 const size_type __pos = __position - _M_ibegin();
1114 this->_M_erase(__pos, size_type(1));
1115 this->_M_set_leaked();
1116 return iterator(this->_M_data() + __pos);
1120 * @brief Remove a range of characters.
1121 * @param __first Iterator referencing the first character to remove.
1122 * @param __last Iterator referencing the end of the range.
1123 * @return Iterator referencing location of first after removal.
1125 * Removes the characters in the range [first,last) from this
1126 * string. The value of the string doesn't change if an error
1130 erase(iterator __first, iterator __last)
1132 _GLIBCXX_DEBUG_PEDASSERT(__first >= _M_ibegin() && __first <= __last
1133 && __last <= _M_iend());
1134 const size_type __pos = __first - _M_ibegin();
1135 this->_M_erase(__pos, __last - __first);
1136 this->_M_set_leaked();
1137 return iterator(this->_M_data() + __pos);
1141 * @brief Replace characters with value from another string.
1142 * @param __pos Index of first character to replace.
1143 * @param __n Number of characters to be replaced.
1144 * @param __str String to insert.
1145 * @return Reference to this string.
1146 * @throw std::out_of_range If @a __pos is beyond the end of this
1148 * @throw std::length_error If new length exceeds @c max_size().
1150 * Removes the characters in the range [pos,pos+n) from this
1151 * string. In place, the value of @a __str is inserted. If @a
1152 * __pos is beyond end of string, out_of_range is thrown. If
1153 * the length of the result exceeds max_size(), length_error is
1154 * thrown. The value of the string doesn't change if an error
1158 replace(size_type __pos, size_type __n, const __versa_string& __str)
1159 { return this->replace(__pos, __n, __str._M_data(), __str.size()); }
1162 * @brief Replace characters with value from another string.
1163 * @param __pos1 Index of first character to replace.
1164 * @param __n1 Number of characters to be replaced.
1165 * @param __str String to insert.
1166 * @param __pos2 Index of first character of str to use.
1167 * @param __n2 Number of characters from str to use.
1168 * @return Reference to this string.
1169 * @throw std::out_of_range If @a __pos1 > size() or @a __pos2 >
1171 * @throw std::length_error If new length exceeds @c max_size().
1173 * Removes the characters in the range [pos1,pos1 + n) from
1174 * this string. In place, the value of @a __str is inserted.
1175 * If @a __pos is beyond end of string, out_of_range is thrown.
1176 * If the length of the result exceeds max_size(), length_error
1177 * is thrown. The value of the string doesn't change if an
1181 replace(size_type __pos1, size_type __n1, const __versa_string& __str,
1182 size_type __pos2, size_type __n2)
1184 return this->replace(__pos1, __n1, __str._M_data()
1185 + __str._M_check(__pos2,
1186 "__versa_string::replace"),
1187 __str._M_limit(__pos2, __n2));
1191 * @brief Replace characters with value of a C substring.
1192 * @param __pos Index of first character to replace.
1193 * @param __n1 Number of characters to be replaced.
1194 * @param __s C string to insert.
1195 * @param __n2 Number of characters from @a __s to use.
1196 * @return Reference to this string.
1197 * @throw std::out_of_range If @a __pos1 > size().
1198 * @throw std::length_error If new length exceeds @c max_size().
1200 * Removes the characters in the range [pos,pos + n1) from this
1201 * string. In place, the first @a __n2 characters of @a __s
1202 * are inserted, or all of @a __s if @a __n2 is too large. If
1203 * @a __pos is beyond end of string, out_of_range is thrown.
1204 * If the length of result exceeds max_size(), length_error is
1205 * thrown. The value of the string doesn't change if an error
1209 replace(size_type __pos, size_type __n1, const _CharT* __s,
1212 __glibcxx_requires_string_len(__s, __n2);
1213 return _M_replace(_M_check(__pos, "__versa_string::replace"),
1214 _M_limit(__pos, __n1), __s, __n2);
1218 * @brief Replace characters with value of a C string.
1219 * @param __pos Index of first character to replace.
1220 * @param __n1 Number of characters to be replaced.
1221 * @param __s C string to insert.
1222 * @return Reference to this string.
1223 * @throw std::out_of_range If @a __pos > size().
1224 * @throw std::length_error If new length exceeds @c max_size().
1226 * Removes the characters in the range [pos,pos + n1) from this
1227 * string. In place, the characters of @a __s are inserted. If
1228 * @a pos is beyond end of string, out_of_range is thrown. If
1229 * the length of result exceeds max_size(), length_error is thrown.
1230 * The value of the string doesn't change if an error is thrown.
1233 replace(size_type __pos, size_type __n1, const _CharT* __s)
1235 __glibcxx_requires_string(__s);
1236 return this->replace(__pos, __n1, __s, traits_type::length(__s));
1240 * @brief Replace characters with multiple characters.
1241 * @param __pos Index of first character to replace.
1242 * @param __n1 Number of characters to be replaced.
1243 * @param __n2 Number of characters to insert.
1244 * @param __c Character to insert.
1245 * @return Reference to this string.
1246 * @throw std::out_of_range If @a __pos > size().
1247 * @throw std::length_error If new length exceeds @c max_size().
1249 * Removes the characters in the range [pos,pos + n1) from this
1250 * string. In place, @a __n2 copies of @a __c are inserted.
1251 * If @a __pos is beyond end of string, out_of_range is thrown.
1252 * If the length of result exceeds max_size(), length_error is
1253 * thrown. The value of the string doesn't change if an error
1257 replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
1258 { return _M_replace_aux(_M_check(__pos, "__versa_string::replace"),
1259 _M_limit(__pos, __n1), __n2, __c); }
1262 * @brief Replace range of characters with string.
1263 * @param __i1 Iterator referencing start of range to replace.
1264 * @param __i2 Iterator referencing end of range to replace.
1265 * @param __str String value to insert.
1266 * @return Reference to this string.
1267 * @throw std::length_error If new length exceeds @c max_size().
1269 * Removes the characters in the range [i1,i2). In place, the
1270 * value of @a __str is inserted. If the length of result
1271 * exceeds max_size(), length_error is thrown. The value of
1272 * the string doesn't change if an error is thrown.
1275 replace(iterator __i1, iterator __i2, const __versa_string& __str)
1276 { return this->replace(__i1, __i2, __str._M_data(), __str.size()); }
1279 * @brief Replace range of characters with C substring.
1280 * @param __i1 Iterator referencing start of range to replace.
1281 * @param __i2 Iterator referencing end of range to replace.
1282 * @param __s C string value to insert.
1283 * @param __n Number of characters from s to insert.
1284 * @return Reference to this string.
1285 * @throw std::length_error If new length exceeds @c max_size().
1287 * Removes the characters in the range [i1,i2). In place, the
1288 * first @a n characters of @a __s are inserted. If the length
1289 * of result exceeds max_size(), length_error is thrown. The
1290 * value of the string doesn't change if an error is thrown.
1293 replace(iterator __i1, iterator __i2, const _CharT* __s, size_type __n)
1295 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1296 && __i2 <= _M_iend());
1297 return this->replace(__i1 - _M_ibegin(), __i2 - __i1, __s, __n);
1301 * @brief Replace range of characters with C string.
1302 * @param __i1 Iterator referencing start of range to replace.
1303 * @param __i2 Iterator referencing end of range to replace.
1304 * @param __s C string value to insert.
1305 * @return Reference to this string.
1306 * @throw std::length_error If new length exceeds @c max_size().
1308 * Removes the characters in the range [i1,i2). In place, the
1309 * characters of @a __s are inserted. If the length of result
1310 * exceeds max_size(), length_error is thrown. The value of
1311 * the string doesn't change if an error is thrown.
1314 replace(iterator __i1, iterator __i2, const _CharT* __s)
1316 __glibcxx_requires_string(__s);
1317 return this->replace(__i1, __i2, __s, traits_type::length(__s));
1321 * @brief Replace range of characters with multiple characters
1322 * @param __i1 Iterator referencing start of range to replace.
1323 * @param __i2 Iterator referencing end of range to replace.
1324 * @param __n Number of characters to insert.
1325 * @param __c Character to insert.
1326 * @return Reference to this string.
1327 * @throw std::length_error If new length exceeds @c max_size().
1329 * Removes the characters in the range [i1,i2). In place, @a
1330 * __n copies of @a __c are inserted. If the length of result
1331 * exceeds max_size(), length_error is thrown. The value of
1332 * the string doesn't change if an error is thrown.
1335 replace(iterator __i1, iterator __i2, size_type __n, _CharT __c)
1337 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1338 && __i2 <= _M_iend());
1339 return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __c);
1343 * @brief Replace range of characters with range.
1344 * @param __i1 Iterator referencing start of range to replace.
1345 * @param __i2 Iterator referencing end of range to replace.
1346 * @param __k1 Iterator referencing start of range to insert.
1347 * @param __k2 Iterator referencing end of range to insert.
1348 * @return Reference to this string.
1349 * @throw std::length_error If new length exceeds @c max_size().
1351 * Removes the characters in the range [i1,i2). In place,
1352 * characters in the range [k1,k2) are inserted. If the length
1353 * of result exceeds max_size(), length_error is thrown. The
1354 * value of the string doesn't change if an error is thrown.
1356 template<class _InputIterator>
1358 replace(iterator __i1, iterator __i2,
1359 _InputIterator __k1, _InputIterator __k2)
1361 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1362 && __i2 <= _M_iend());
1363 __glibcxx_requires_valid_range(__k1, __k2);
1364 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
1365 return this->_M_replace_dispatch(__i1, __i2, __k1, __k2, _Integral());
1368 // Specializations for the common case of pointer and iterator:
1369 // useful to avoid the overhead of temporary buffering in _M_replace.
1371 replace(iterator __i1, iterator __i2, _CharT* __k1, _CharT* __k2)
1373 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1374 && __i2 <= _M_iend());
1375 __glibcxx_requires_valid_range(__k1, __k2);
1376 return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
1381 replace(iterator __i1, iterator __i2,
1382 const _CharT* __k1, const _CharT* __k2)
1384 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1385 && __i2 <= _M_iend());
1386 __glibcxx_requires_valid_range(__k1, __k2);
1387 return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
1392 replace(iterator __i1, iterator __i2, iterator __k1, iterator __k2)
1394 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1395 && __i2 <= _M_iend());
1396 __glibcxx_requires_valid_range(__k1, __k2);
1397 return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
1398 __k1.base(), __k2 - __k1);
1402 replace(iterator __i1, iterator __i2,
1403 const_iterator __k1, const_iterator __k2)
1405 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1406 && __i2 <= _M_iend());
1407 __glibcxx_requires_valid_range(__k1, __k2);
1408 return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
1409 __k1.base(), __k2 - __k1);
1412 #ifdef __GXX_EXPERIMENTAL_CXX0X__
1414 * @brief Replace range of characters with initializer_list.
1415 * @param __i1 Iterator referencing start of range to replace.
1416 * @param __i2 Iterator referencing end of range to replace.
1417 * @param __l The initializer_list of characters to insert.
1418 * @return Reference to this string.
1419 * @throw std::length_error If new length exceeds @c max_size().
1421 * Removes the characters in the range [i1,i2). In place,
1422 * characters in the range [k1,k2) are inserted. If the length
1423 * of result exceeds max_size(), length_error is thrown. The
1424 * value of the string doesn't change if an error is thrown.
1426 __versa_string& replace(iterator __i1, iterator __i2,
1427 std::initializer_list<_CharT> __l)
1428 { return this->replace(__i1, __i2, __l.begin(), __l.end()); }
1429 #endif // __GXX_EXPERIMENTAL_CXX0X__
1432 template<class _Integer>
1434 _M_replace_dispatch(iterator __i1, iterator __i2, _Integer __n,
1435 _Integer __val, std::__true_type)
1436 { return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __val); }
1438 template<class _InputIterator>
1440 _M_replace_dispatch(iterator __i1, iterator __i2, _InputIterator __k1,
1441 _InputIterator __k2, std::__false_type);
1444 _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2,
1448 _M_replace(size_type __pos, size_type __len1, const _CharT* __s,
1449 const size_type __len2);
1452 _M_append(const _CharT* __s, size_type __n);
1457 * @brief Copy substring into C string.
1458 * @param __s C string to copy value into.
1459 * @param __n Number of characters to copy.
1460 * @param __pos Index of first character to copy.
1461 * @return Number of characters actually copied
1462 * @throw std::out_of_range If pos > size().
1464 * Copies up to @a __n characters starting at @a __pos into the
1465 * C string @a s. If @a __pos is greater than size(),
1466 * out_of_range is thrown.
1469 copy(_CharT* __s, size_type __n, size_type __pos = 0) const;
1472 * @brief Swap contents with another string.
1473 * @param __s String to swap with.
1475 * Exchanges the contents of this string with that of @a __s in
1479 swap(__versa_string& __s)
1480 { this->_M_swap(__s); }
1482 // String operations:
1484 * @brief Return const pointer to null-terminated contents.
1486 * This is a handle to internal data. Do not modify or dire things may
1490 c_str() const _GLIBCXX_NOEXCEPT
1491 { return this->_M_data(); }
1494 * @brief Return const pointer to contents.
1496 * This is a handle to internal data. Do not modify or dire things may
1500 data() const _GLIBCXX_NOEXCEPT
1501 { return this->_M_data(); }
1504 * @brief Return copy of allocator used to construct this string.
1507 get_allocator() const _GLIBCXX_NOEXCEPT
1508 { return allocator_type(this->_M_get_allocator()); }
1511 * @brief Find position of a C substring.
1512 * @param __s C string to locate.
1513 * @param __pos Index of character to search from.
1514 * @param __n Number of characters from @a __s to search for.
1515 * @return Index of start of first occurrence.
1517 * Starting from @a __pos, searches forward for the first @a
1518 * __n characters in @a __s within this string. If found,
1519 * returns the index where it begins. If not found, returns
1523 find(const _CharT* __s, size_type __pos, size_type __n) const;
1526 * @brief Find position of a string.
1527 * @param __str String to locate.
1528 * @param __pos Index of character to search from (default 0).
1529 * @return Index of start of first occurrence.
1531 * Starting from @a __pos, searches forward for value of @a
1532 * __str within this string. If found, returns the index where
1533 * it begins. If not found, returns npos.
1536 find(const __versa_string& __str, size_type __pos = 0) const
1538 { return this->find(__str.data(), __pos, __str.size()); }
1541 * @brief Find position of a C string.
1542 * @param __s C string to locate.
1543 * @param __pos Index of character to search from (default 0).
1544 * @return Index of start of first occurrence.
1546 * Starting from @a __pos, searches forward for the value of @a
1547 * __s within this string. If found, returns the index where
1548 * it begins. If not found, returns npos.
1551 find(const _CharT* __s, size_type __pos = 0) const
1553 __glibcxx_requires_string(__s);
1554 return this->find(__s, __pos, traits_type::length(__s));
1558 * @brief Find position of a character.
1559 * @param __c Character to locate.
1560 * @param __pos Index of character to search from (default 0).
1561 * @return Index of first occurrence.
1563 * Starting from @a __pos, searches forward for @a __c within
1564 * this string. If found, returns the index where it was
1565 * found. If not found, returns npos.
1568 find(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT;
1571 * @brief Find last position of a string.
1572 * @param __str String to locate.
1573 * @param __pos Index of character to search back from (default end).
1574 * @return Index of start of last occurrence.
1576 * Starting from @a __pos, searches backward for value of @a
1577 * __str within this string. If found, returns the index where
1578 * it begins. If not found, returns npos.
1581 rfind(const __versa_string& __str, size_type __pos = npos) const
1583 { return this->rfind(__str.data(), __pos, __str.size()); }
1586 * @brief Find last position of a C substring.
1587 * @param __s C string to locate.
1588 * @param __pos Index of character to search back from.
1589 * @param __n Number of characters from s to search for.
1590 * @return Index of start of last occurrence.
1592 * Starting from @a __pos, searches backward for the first @a
1593 * __n characters in @a __s within this string. If found,
1594 * returns the index where it begins. If not found, returns
1598 rfind(const _CharT* __s, size_type __pos, size_type __n) const;
1601 * @brief Find last position of a C string.
1602 * @param __s C string to locate.
1603 * @param __pos Index of character to start search at (default end).
1604 * @return Index of start of last occurrence.
1606 * Starting from @a __pos, searches backward for the value of
1607 * @a __s within this string. If found, returns the index
1608 * where it begins. If not found, returns npos.
1611 rfind(const _CharT* __s, size_type __pos = npos) const
1613 __glibcxx_requires_string(__s);
1614 return this->rfind(__s, __pos, traits_type::length(__s));
1618 * @brief Find last position of a character.
1619 * @param __c Character to locate.
1620 * @param __pos Index of character to search back from (default end).
1621 * @return Index of last occurrence.
1623 * Starting from @a __pos, searches backward for @a __c within
1624 * this string. If found, returns the index where it was
1625 * found. If not found, returns npos.
1628 rfind(_CharT __c, size_type __pos = npos) const _GLIBCXX_NOEXCEPT;
1631 * @brief Find position of a character of string.
1632 * @param __str String containing characters to locate.
1633 * @param __pos Index of character to search from (default 0).
1634 * @return Index of first occurrence.
1636 * Starting from @a __pos, searches forward for one of the characters of
1637 * @a __str within this string. If found, returns the index where it was
1638 * found. If not found, returns npos.
1641 find_first_of(const __versa_string& __str, size_type __pos = 0) const
1643 { return this->find_first_of(__str.data(), __pos, __str.size()); }
1646 * @brief Find position of a character of C substring.
1647 * @param __s String containing characters to locate.
1648 * @param __pos Index of character to search from.
1649 * @param __n Number of characters from s to search for.
1650 * @return Index of first occurrence.
1652 * Starting from @a __pos, searches forward for one of the
1653 * first @a __n characters of @a __s within this string. If
1654 * found, returns the index where it was found. If not found,
1658 find_first_of(const _CharT* __s, size_type __pos, size_type __n) const;
1661 * @brief Find position of a character of C string.
1662 * @param __s String containing characters to locate.
1663 * @param __pos Index of character to search from (default 0).
1664 * @return Index of first occurrence.
1666 * Starting from @a __pos, searches forward for one of the
1667 * characters of @a __s within this string. If found, returns
1668 * the index where it was found. If not found, returns npos.
1671 find_first_of(const _CharT* __s, size_type __pos = 0) const
1673 __glibcxx_requires_string(__s);
1674 return this->find_first_of(__s, __pos, traits_type::length(__s));
1678 * @brief Find position of a character.
1679 * @param __c Character to locate.
1680 * @param __pos Index of character to search from (default 0).
1681 * @return Index of first occurrence.
1683 * Starting from @a __pos, searches forward for the character
1684 * @a __c within this string. If found, returns the index
1685 * where it was found. If not found, returns npos.
1687 * Note: equivalent to find(c, pos).
1690 find_first_of(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT
1691 { return this->find(__c, __pos); }
1694 * @brief Find last position of a character of string.
1695 * @param __str String containing characters to locate.
1696 * @param __pos Index of character to search back from (default end).
1697 * @return Index of last occurrence.
1699 * Starting from @a __pos, searches backward for one of the
1700 * characters of @a __str within this string. If found,
1701 * returns the index where it was found. If not found, returns
1705 find_last_of(const __versa_string& __str, size_type __pos = npos) const
1707 { return this->find_last_of(__str.data(), __pos, __str.size()); }
1710 * @brief Find last position of a character of C substring.
1711 * @param __s C string containing characters to locate.
1712 * @param __pos Index of character to search back from.
1713 * @param __n Number of characters from s to search for.
1714 * @return Index of last occurrence.
1716 * Starting from @a __pos, searches backward for one of the
1717 * first @a __n characters of @a __s within this string. If
1718 * found, returns the index where it was found. If not found,
1722 find_last_of(const _CharT* __s, size_type __pos, size_type __n) const;
1725 * @brief Find last position of a character of C string.
1726 * @param __s C string containing characters to locate.
1727 * @param __pos Index of character to search back from (default end).
1728 * @return Index of last occurrence.
1730 * Starting from @a __pos, searches backward for one of the
1731 * characters of @a __s within this string. If found, returns
1732 * the index where it was found. If not found, returns npos.
1735 find_last_of(const _CharT* __s, size_type __pos = npos) const
1737 __glibcxx_requires_string(__s);
1738 return this->find_last_of(__s, __pos, traits_type::length(__s));
1742 * @brief Find last position of a character.
1743 * @param __c Character 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 @a __c within
1748 * this string. If found, returns the index where it was
1749 * found. If not found, returns npos.
1751 * Note: equivalent to rfind(c, pos).
1754 find_last_of(_CharT __c, size_type __pos = npos) const _GLIBCXX_NOEXCEPT
1755 { return this->rfind(__c, __pos); }
1758 * @brief Find position of a character not in string.
1759 * @param __str String containing characters to avoid.
1760 * @param __pos Index of character to search from (default 0).
1761 * @return Index of first occurrence.
1763 * Starting from @a __pos, searches forward for a character not
1764 * contained in @a __str within this string. If found, returns
1765 * the index where it was found. If not found, returns npos.
1768 find_first_not_of(const __versa_string& __str, size_type __pos = 0) const
1770 { return this->find_first_not_of(__str.data(), __pos, __str.size()); }
1773 * @brief Find position of a character not in C substring.
1774 * @param __s C string containing characters to avoid.
1775 * @param __pos Index of character to search from.
1776 * @param __n Number of characters from s to consider.
1777 * @return Index of first occurrence.
1779 * Starting from @a __pos, searches forward for a character not
1780 * contained in the first @a __n characters of @a __s within
1781 * this string. If found, returns the index where it was
1782 * found. If not found, returns npos.
1785 find_first_not_of(const _CharT* __s, size_type __pos,
1786 size_type __n) const;
1789 * @brief Find position of a character not in C string.
1790 * @param __s C string containing characters to avoid.
1791 * @param __pos Index of character to search from (default 0).
1792 * @return Index of first occurrence.
1794 * Starting from @a __pos, searches forward for a character not
1795 * contained in @a __s within this string. If found, returns
1796 * the index where it was found. If not found, returns npos.
1799 find_first_not_of(const _CharT* __s, size_type __pos = 0) const
1801 __glibcxx_requires_string(__s);
1802 return this->find_first_not_of(__s, __pos, traits_type::length(__s));
1806 * @brief Find position of a different character.
1807 * @param __c Character 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
1812 * other than @a __c within this string. If found, returns the
1813 * index where it was found. If not found, returns npos.
1816 find_first_not_of(_CharT __c, size_type __pos = 0) const
1820 * @brief Find last position of a character not in string.
1821 * @param __str String containing characters to avoid.
1822 * @param __pos Index of character to search back from (default end).
1823 * @return Index of last occurrence.
1825 * Starting from @a __pos, searches backward for a character
1826 * not contained in @a __str within this string. If found,
1827 * returns the index where it was found. If not found, returns
1831 find_last_not_of(const __versa_string& __str,
1832 size_type __pos = npos) const _GLIBCXX_NOEXCEPT
1833 { return this->find_last_not_of(__str.data(), __pos, __str.size()); }
1836 * @brief Find last position of a character not in C substring.
1837 * @param __s C string containing characters to avoid.
1838 * @param __pos Index of character to search back from.
1839 * @param __n Number of characters from s to consider.
1840 * @return Index of last occurrence.
1842 * Starting from @a __pos, searches backward for a character
1843 * not contained in the first @a __n characters of @a __s
1844 * within this string. If found, returns the index where it
1845 * was found. If not found, returns npos.
1848 find_last_not_of(const _CharT* __s, size_type __pos,
1849 size_type __n) const;
1851 * @brief Find last position of a character not in C string.
1852 * @param __s C string containing characters to avoid.
1853 * @param __pos Index of character to search back from (default end).
1854 * @return Index of last occurrence.
1856 * Starting from @a __pos, searches backward for a character
1857 * not contained in @a __s within this string. If found,
1858 * returns the index where it was found. If not found, returns
1862 find_last_not_of(const _CharT* __s, size_type __pos = npos) const
1864 __glibcxx_requires_string(__s);
1865 return this->find_last_not_of(__s, __pos, traits_type::length(__s));
1869 * @brief Find last position of a different character.
1870 * @param __c Character to avoid.
1871 * @param __pos Index of character to search back from (default end).
1872 * @return Index of last occurrence.
1874 * Starting from @a __pos, searches backward for a character
1875 * other than @a __c within this string. If found, returns the
1876 * index where it was found. If not found, returns npos.
1879 find_last_not_of(_CharT __c, size_type __pos = npos) const
1883 * @brief Get a substring.
1884 * @param __pos Index of first character (default 0).
1885 * @param __n Number of characters in substring (default remainder).
1886 * @return The new string.
1887 * @throw std::out_of_range If pos > size().
1889 * Construct and return a new string using the @a __n
1890 * characters starting at @a __pos. If the string is too
1891 * short, use the remainder of the characters. If @a __pos is
1892 * beyond the end of the string, out_of_range is thrown.
1895 substr(size_type __pos = 0, size_type __n = npos) const
1897 return __versa_string(*this, _M_check(__pos, "__versa_string::substr"),
1902 * @brief Compare to a string.
1903 * @param __str String to compare against.
1904 * @return Integer < 0, 0, or > 0.
1906 * Returns an integer < 0 if this string is ordered before @a
1907 * __str, 0 if their values are equivalent, or > 0 if this
1908 * string is ordered after @a __str. Determines the effective
1909 * length rlen of the strings to compare as the smallest of
1910 * size() and str.size(). The function then compares the two
1911 * strings by calling traits::compare(data(), str.data(),rlen).
1912 * If the result of the comparison is nonzero returns it,
1913 * otherwise the shorter one is ordered first.
1916 compare(const __versa_string& __str) const
1918 if (this->_M_compare(__str))
1921 const size_type __size = this->size();
1922 const size_type __osize = __str.size();
1923 const size_type __len = std::min(__size, __osize);
1925 int __r = traits_type::compare(this->_M_data(), __str.data(), __len);
1927 __r = this->_S_compare(__size, __osize);
1932 * @brief Compare substring to a string.
1933 * @param __pos Index of first character of substring.
1934 * @param __n Number of characters in substring.
1935 * @param __str String to compare against.
1936 * @return Integer < 0, 0, or > 0.
1938 * Form the substring of this string from the @a __n characters
1939 * starting at @a __pos. Returns an integer < 0 if the
1940 * substring is ordered before @a __str, 0 if their values are
1941 * equivalent, or > 0 if the substring is ordered after @a
1942 * __str. Determines the effective length rlen of the strings
1943 * to compare as the smallest of the length of the substring
1944 * and @a __str.size(). The function then compares the two
1945 * strings by calling
1946 * traits::compare(substring.data(),str.data(),rlen). If the
1947 * result of the comparison is nonzero returns it, otherwise
1948 * the shorter one is ordered first.
1951 compare(size_type __pos, size_type __n,
1952 const __versa_string& __str) const;
1955 * @brief Compare substring to a substring.
1956 * @param __pos1 Index of first character of substring.
1957 * @param __n1 Number of characters in substring.
1958 * @param __str String to compare against.
1959 * @param __pos2 Index of first character of substring of str.
1960 * @param __n2 Number of characters in substring of str.
1961 * @return Integer < 0, 0, or > 0.
1963 * Form the substring of this string from the @a __n1
1964 * characters starting at @a __pos1. Form the substring of @a
1965 * __str from the @a __n2 characters starting at @a __pos2.
1966 * Returns an integer < 0 if this substring is ordered before
1967 * the substring of @a __str, 0 if their values are equivalent,
1968 * or > 0 if this substring is ordered after the substring of
1969 * @a __str. Determines the effective length rlen of the
1970 * strings to compare as the smallest of the lengths of the
1971 * substrings. The function then compares the two strings by
1973 * traits::compare(substring.data(),str.substr(pos2,n2).data(),rlen).
1974 * If the result of the comparison is nonzero returns it,
1975 * otherwise the shorter one is ordered first.
1978 compare(size_type __pos1, size_type __n1, const __versa_string& __str,
1979 size_type __pos2, size_type __n2) const;
1982 * @brief Compare to a C string.
1983 * @param __s C string to compare against.
1984 * @return Integer < 0, 0, or > 0.
1986 * Returns an integer < 0 if this string is ordered before @a
1987 * __s, 0 if their values are equivalent, or > 0 if this string
1988 * is ordered after @a __s. Determines the effective length
1989 * rlen of the strings to compare as the smallest of size() and
1990 * the length of a string constructed from @a __s. The
1991 * function then compares the two strings by calling
1992 * traits::compare(data(),s,rlen). If the result of the
1993 * comparison is nonzero returns it, otherwise the shorter one
1997 compare(const _CharT* __s) const;
1999 // _GLIBCXX_RESOLVE_LIB_DEFECTS
2000 // 5 String::compare specification questionable
2002 * @brief Compare substring to a C string.
2003 * @param __pos Index of first character of substring.
2004 * @param __n1 Number of characters in substring.
2005 * @param __s C string to compare against.
2006 * @return Integer < 0, 0, or > 0.
2008 * Form the substring of this string from the @a __n1
2009 * characters starting at @a __pos. Returns an integer < 0 if
2010 * the substring is ordered before @a __s, 0 if their values
2011 * are equivalent, or > 0 if the substring is ordered after @a
2012 * __s. Determines the effective length rlen of the strings to
2013 * compare as the smallest of the length of the substring and
2014 * the length of a string constructed from @a __s. The
2015 * function then compares the two string by calling
2016 * traits::compare(substring.data(),s,rlen). If the result of
2017 * the comparison is nonzero returns it, otherwise the shorter
2018 * one is ordered first.
2021 compare(size_type __pos, size_type __n1, const _CharT* __s) const;
2024 * @brief Compare substring against a character array.
2025 * @param __pos Index of first character of substring.
2026 * @param __n1 Number of characters in substring.
2027 * @param __s character array to compare against.
2028 * @param __n2 Number of characters of s.
2029 * @return Integer < 0, 0, or > 0.
2031 * Form the substring of this string from the @a __n1
2032 * characters starting at @a __pos. Form a string from the
2033 * first @a __n2 characters of @a __s. Returns an integer < 0
2034 * if this substring is ordered before the string from @a __s,
2035 * 0 if their values are equivalent, or > 0 if this substring
2036 * is ordered after the string from @a __s. Determines the
2037 * effective length rlen of the strings to compare as the
2038 * smallest of the length of the substring and @a __n2. The
2039 * function then compares the two strings by calling
2040 * traits::compare(substring.data(),__s,rlen). If the result of
2041 * the comparison is nonzero returns it, otherwise the shorter
2042 * one is ordered first.
2044 * NB: __s must have at least n2 characters, <em>\\0</em> has no special
2048 compare(size_type __pos, size_type __n1, const _CharT* __s,
2049 size_type __n2) const;
2054 * @brief Concatenate two strings.
2055 * @param __lhs First string.
2056 * @param __rhs Last string.
2057 * @return New string with value of @a __lhs followed by @a __rhs.
2059 template<typename _CharT, typename _Traits, typename _Alloc,
2060 template <typename, typename, typename> class _Base>
2061 __versa_string<_CharT, _Traits, _Alloc, _Base>
2062 operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2063 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs);
2066 * @brief Concatenate C string and string.
2067 * @param __lhs First string.
2068 * @param __rhs Last string.
2069 * @return New string with value of @a __lhs followed by @a __rhs.
2071 template<typename _CharT, typename _Traits, typename _Alloc,
2072 template <typename, typename, typename> class _Base>
2073 __versa_string<_CharT, _Traits, _Alloc, _Base>
2074 operator+(const _CharT* __lhs,
2075 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs);
2078 * @brief Concatenate character and string.
2079 * @param __lhs First string.
2080 * @param __rhs Last string.
2081 * @return New string with @a __lhs followed by @a __rhs.
2083 template<typename _CharT, typename _Traits, typename _Alloc,
2084 template <typename, typename, typename> class _Base>
2085 __versa_string<_CharT, _Traits, _Alloc, _Base>
2086 operator+(_CharT __lhs,
2087 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs);
2090 * @brief Concatenate string and C string.
2091 * @param __lhs First string.
2092 * @param __rhs Last string.
2093 * @return New string with @a __lhs followed by @a __rhs.
2095 template<typename _CharT, typename _Traits, typename _Alloc,
2096 template <typename, typename, typename> class _Base>
2097 __versa_string<_CharT, _Traits, _Alloc, _Base>
2098 operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2099 const _CharT* __rhs);
2102 * @brief Concatenate string and character.
2103 * @param __lhs First string.
2104 * @param __rhs Last string.
2105 * @return New string with @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,
2113 #ifdef __GXX_EXPERIMENTAL_CXX0X__
2114 template<typename _CharT, typename _Traits, typename _Alloc,
2115 template <typename, typename, typename> class _Base>
2116 inline __versa_string<_CharT, _Traits, _Alloc, _Base>
2117 operator+(__versa_string<_CharT, _Traits, _Alloc, _Base>&& __lhs,
2118 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2119 { return std::move(__lhs.append(__rhs)); }
2121 template<typename _CharT, typename _Traits, typename _Alloc,
2122 template <typename, typename, typename> class _Base>
2123 inline __versa_string<_CharT, _Traits, _Alloc, _Base>
2124 operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2125 __versa_string<_CharT, _Traits, _Alloc, _Base>&& __rhs)
2126 { return std::move(__rhs.insert(0, __lhs)); }
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 __versa_string<_CharT, _Traits, _Alloc, _Base>&& __rhs)
2134 const auto __size = __lhs.size() + __rhs.size();
2135 const bool __cond = (__size > __lhs.capacity()
2136 && __size <= __rhs.capacity());
2137 return __cond ? std::move(__rhs.insert(0, __lhs))
2138 : std::move(__lhs.append(__rhs));
2141 template<typename _CharT, typename _Traits, typename _Alloc,
2142 template <typename, typename, typename> class _Base>
2143 inline __versa_string<_CharT, _Traits, _Alloc, _Base>
2144 operator+(const _CharT* __lhs,
2145 __versa_string<_CharT, _Traits, _Alloc, _Base>&& __rhs)
2146 { return std::move(__rhs.insert(0, __lhs)); }
2148 template<typename _CharT, typename _Traits, typename _Alloc,
2149 template <typename, typename, typename> class _Base>
2150 inline __versa_string<_CharT, _Traits, _Alloc, _Base>
2151 operator+(_CharT __lhs,
2152 __versa_string<_CharT, _Traits, _Alloc, _Base>&& __rhs)
2153 { return std::move(__rhs.insert(0, 1, __lhs)); }
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+(__versa_string<_CharT, _Traits, _Alloc, _Base>&& __lhs,
2159 const _CharT* __rhs)
2160 { return std::move(__lhs.append(__rhs)); }
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,
2167 { return std::move(__lhs.append(1, __rhs)); }
2172 * @brief Test equivalence of two strings.
2173 * @param __lhs First string.
2174 * @param __rhs Second string.
2175 * @return True if @a __lhs.compare(@a __rhs) == 0. False otherwise.
2177 template<typename _CharT, typename _Traits, typename _Alloc,
2178 template <typename, typename, typename> class _Base>
2180 operator==(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2181 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2182 { return __lhs.compare(__rhs) == 0; }
2184 template<typename _CharT,
2185 template <typename, typename, typename> class _Base>
2186 inline typename __enable_if<std::__is_char<_CharT>::__value, bool>::__type
2187 operator==(const __versa_string<_CharT, std::char_traits<_CharT>,
2188 std::allocator<_CharT>, _Base>& __lhs,
2189 const __versa_string<_CharT, std::char_traits<_CharT>,
2190 std::allocator<_CharT>, _Base>& __rhs)
2191 { return (__lhs.size() == __rhs.size()
2192 && !std::char_traits<_CharT>::compare(__lhs.data(), __rhs.data(),
2196 * @brief Test equivalence of C string and string.
2197 * @param __lhs C string.
2198 * @param __rhs String.
2199 * @return True if @a __rhs.compare(@a __lhs) == 0. False otherwise.
2201 template<typename _CharT, typename _Traits, typename _Alloc,
2202 template <typename, typename, typename> class _Base>
2204 operator==(const _CharT* __lhs,
2205 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2206 { return __rhs.compare(__lhs) == 0; }
2209 * @brief Test equivalence of string and C string.
2210 * @param __lhs String.
2211 * @param __rhs C string.
2212 * @return True if @a __lhs.compare(@a __rhs) == 0. False otherwise.
2214 template<typename _CharT, typename _Traits, typename _Alloc,
2215 template <typename, typename, typename> class _Base>
2217 operator==(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2218 const _CharT* __rhs)
2219 { return __lhs.compare(__rhs) == 0; }
2223 * @brief Test difference of two strings.
2224 * @param __lhs First string.
2225 * @param __rhs Second 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 __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2233 { return !(__lhs == __rhs); }
2236 * @brief Test difference of C string and string.
2237 * @param __lhs C string.
2238 * @param __rhs String.
2239 * @return True if @a __rhs.compare(@a __lhs) != 0. False otherwise.
2241 template<typename _CharT, typename _Traits, typename _Alloc,
2242 template <typename, typename, typename> class _Base>
2244 operator!=(const _CharT* __lhs,
2245 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2246 { return !(__lhs == __rhs); }
2249 * @brief Test difference of string and C string.
2250 * @param __lhs String.
2251 * @param __rhs C string.
2252 * @return True if @a __lhs.compare(@a __rhs) != 0. False otherwise.
2254 template<typename _CharT, typename _Traits, typename _Alloc,
2255 template <typename, typename, typename> class _Base>
2257 operator!=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2258 const _CharT* __rhs)
2259 { return !(__lhs == __rhs); }
2263 * @brief Test if string precedes string.
2264 * @param __lhs First string.
2265 * @param __rhs Second string.
2266 * @return True if @a __lhs precedes @a __rhs. 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 __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2273 { return __lhs.compare(__rhs) < 0; }
2276 * @brief Test if string precedes C string.
2277 * @param __lhs String.
2278 * @param __rhs C string.
2279 * @return True if @a __lhs precedes @a __rhs. False otherwise.
2281 template<typename _CharT, typename _Traits, typename _Alloc,
2282 template <typename, typename, typename> class _Base>
2284 operator<(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2285 const _CharT* __rhs)
2286 { return __lhs.compare(__rhs) < 0; }
2289 * @brief Test if C string precedes string.
2290 * @param __lhs C string.
2291 * @param __rhs String.
2292 * @return True if @a __lhs precedes @a __rhs. False otherwise.
2294 template<typename _CharT, typename _Traits, typename _Alloc,
2295 template <typename, typename, typename> class _Base>
2297 operator<(const _CharT* __lhs,
2298 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2299 { return __rhs.compare(__lhs) > 0; }
2303 * @brief Test if string follows string.
2304 * @param __lhs First string.
2305 * @param __rhs Second string.
2306 * @return True if @a __lhs follows @a __rhs. False otherwise.
2308 template<typename _CharT, typename _Traits, typename _Alloc,
2309 template <typename, typename, typename> class _Base>
2311 operator>(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2312 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2313 { return __lhs.compare(__rhs) > 0; }
2316 * @brief Test if string follows C string.
2317 * @param __lhs String.
2318 * @param __rhs C string.
2319 * @return True if @a __lhs follows @a __rhs. False otherwise.
2321 template<typename _CharT, typename _Traits, typename _Alloc,
2322 template <typename, typename, typename> class _Base>
2324 operator>(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2325 const _CharT* __rhs)
2326 { return __lhs.compare(__rhs) > 0; }
2329 * @brief Test if C string follows string.
2330 * @param __lhs C string.
2331 * @param __rhs String.
2332 * @return True if @a __lhs follows @a __rhs. False otherwise.
2334 template<typename _CharT, typename _Traits, typename _Alloc,
2335 template <typename, typename, typename> class _Base>
2337 operator>(const _CharT* __lhs,
2338 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2339 { return __rhs.compare(__lhs) < 0; }
2343 * @brief Test if string doesn't follow string.
2344 * @param __lhs First string.
2345 * @param __rhs Second string.
2346 * @return True if @a __lhs doesn't follow @a __rhs. False otherwise.
2348 template<typename _CharT, typename _Traits, typename _Alloc,
2349 template <typename, typename, typename> class _Base>
2351 operator<=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2352 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2353 { return __lhs.compare(__rhs) <= 0; }
2356 * @brief Test if string doesn't follow C string.
2357 * @param __lhs String.
2358 * @param __rhs C string.
2359 * @return True if @a __lhs doesn't follow @a __rhs. False otherwise.
2361 template<typename _CharT, typename _Traits, typename _Alloc,
2362 template <typename, typename, typename> class _Base>
2364 operator<=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2365 const _CharT* __rhs)
2366 { return __lhs.compare(__rhs) <= 0; }
2369 * @brief Test if C string doesn't follow string.
2370 * @param __lhs C string.
2371 * @param __rhs String.
2372 * @return True if @a __lhs doesn't follow @a __rhs. False otherwise.
2374 template<typename _CharT, typename _Traits, typename _Alloc,
2375 template <typename, typename, typename> class _Base>
2377 operator<=(const _CharT* __lhs,
2378 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2379 { return __rhs.compare(__lhs) >= 0; }
2383 * @brief Test if string doesn't precede string.
2384 * @param __lhs First string.
2385 * @param __rhs Second string.
2386 * @return True if @a __lhs doesn't precede @a __rhs. False otherwise.
2388 template<typename _CharT, typename _Traits, typename _Alloc,
2389 template <typename, typename, typename> class _Base>
2391 operator>=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2392 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2393 { return __lhs.compare(__rhs) >= 0; }
2396 * @brief Test if string doesn't precede C string.
2397 * @param __lhs String.
2398 * @param __rhs C string.
2399 * @return True if @a __lhs doesn't precede @a __rhs. False otherwise.
2401 template<typename _CharT, typename _Traits, typename _Alloc,
2402 template <typename, typename, typename> class _Base>
2404 operator>=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2405 const _CharT* __rhs)
2406 { return __lhs.compare(__rhs) >= 0; }
2409 * @brief Test if C string doesn't precede string.
2410 * @param __lhs C string.
2411 * @param __rhs String.
2412 * @return True if @a __lhs doesn't precede @a __rhs. False otherwise.
2414 template<typename _CharT, typename _Traits, typename _Alloc,
2415 template <typename, typename, typename> class _Base>
2417 operator>=(const _CharT* __lhs,
2418 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2419 { return __rhs.compare(__lhs) <= 0; }
2422 * @brief Swap contents of two strings.
2423 * @param __lhs First string.
2424 * @param __rhs Second string.
2426 * Exchanges the contents of @a __lhs and @a __rhs in constant time.
2428 template<typename _CharT, typename _Traits, typename _Alloc,
2429 template <typename, typename, typename> class _Base>
2431 swap(__versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2432 __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2433 { __lhs.swap(__rhs); }
2435 _GLIBCXX_END_NAMESPACE_VERSION
2438 namespace std _GLIBCXX_VISIBILITY(default)
2440 _GLIBCXX_BEGIN_NAMESPACE_VERSION
2443 * @brief Read stream into a string.
2444 * @param __is Input stream.
2445 * @param __str Buffer to store into.
2446 * @return Reference to the input stream.
2448 * Stores characters from @a __is into @a __str until whitespace is
2449 * found, the end of the stream is encountered, or str.max_size()
2450 * is reached. If is.width() is non-zero, that is the limit on the
2451 * number of characters stored into @a __str. Any previous
2452 * contents of @a __str are erased.
2454 template<typename _CharT, typename _Traits, typename _Alloc,
2455 template <typename, typename, typename> class _Base>
2456 basic_istream<_CharT, _Traits>&
2457 operator>>(basic_istream<_CharT, _Traits>& __is,
2458 __gnu_cxx::__versa_string<_CharT, _Traits,
2459 _Alloc, _Base>& __str);
2462 * @brief Write string to a stream.
2463 * @param __os Output stream.
2464 * @param __str String to write out.
2465 * @return Reference to the output stream.
2467 * Output characters of @a __str into os following the same rules as for
2468 * writing a C string.
2470 template<typename _CharT, typename _Traits, typename _Alloc,
2471 template <typename, typename, typename> class _Base>
2472 inline basic_ostream<_CharT, _Traits>&
2473 operator<<(basic_ostream<_CharT, _Traits>& __os,
2474 const __gnu_cxx::__versa_string<_CharT, _Traits, _Alloc,
2477 // _GLIBCXX_RESOLVE_LIB_DEFECTS
2478 // 586. string inserter not a formatted function
2479 return __ostream_insert(__os, __str.data(), __str.size());
2483 * @brief Read a line from stream into a string.
2484 * @param __is Input stream.
2485 * @param __str Buffer to store into.
2486 * @param __delim Character marking end of line.
2487 * @return Reference to the input stream.
2489 * Stores characters from @a __is into @a __str until @a __delim is
2490 * found, the end of the stream is encountered, or str.max_size()
2491 * is reached. If is.width() is non-zero, that is the limit on the
2492 * number of characters stored into @a __str. Any previous
2493 * contents of @a __str are erased. If @a delim was encountered,
2494 * it is extracted but not stored into @a __str.
2496 template<typename _CharT, typename _Traits, typename _Alloc,
2497 template <typename, typename, typename> class _Base>
2498 basic_istream<_CharT, _Traits>&
2499 getline(basic_istream<_CharT, _Traits>& __is,
2500 __gnu_cxx::__versa_string<_CharT, _Traits, _Alloc, _Base>& __str,
2504 * @brief Read a line from stream into a string.
2505 * @param __is Input stream.
2506 * @param __str Buffer to store into.
2507 * @return Reference to the input stream.
2509 * Stores characters from is into @a __str until '\n' is
2510 * found, the end of the stream is encountered, or str.max_size()
2511 * is reached. If is.width() is non-zero, that is the limit on the
2512 * number of characters stored into @a __str. Any previous
2513 * contents of @a __str are erased. If end of line was
2514 * encountered, it is extracted but not stored into @a __str.
2516 template<typename _CharT, typename _Traits, typename _Alloc,
2517 template <typename, typename, typename> class _Base>
2518 inline basic_istream<_CharT, _Traits>&
2519 getline(basic_istream<_CharT, _Traits>& __is,
2520 __gnu_cxx::__versa_string<_CharT, _Traits, _Alloc, _Base>& __str)
2521 { return getline(__is, __str, __is.widen('\n')); }
2523 _GLIBCXX_END_NAMESPACE_VERSION
2526 #if (defined(__GXX_EXPERIMENTAL_CXX0X__) && defined(_GLIBCXX_USE_C99))
2528 #include <ext/string_conversions.h>
2530 namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
2532 _GLIBCXX_BEGIN_NAMESPACE_VERSION
2534 // 21.4 Numeric Conversions [string.conversions].
2536 stoi(const __vstring& __str, std::size_t* __idx = 0, int __base = 10)
2537 { return __gnu_cxx::__stoa<long, int>(&std::strtol, "stoi", __str.c_str(),
2541 stol(const __vstring& __str, std::size_t* __idx = 0, int __base = 10)
2542 { return __gnu_cxx::__stoa(&std::strtol, "stol", __str.c_str(),
2545 inline unsigned long
2546 stoul(const __vstring& __str, std::size_t* __idx = 0, int __base = 10)
2547 { return __gnu_cxx::__stoa(&std::strtoul, "stoul", __str.c_str(),
2551 stoll(const __vstring& __str, std::size_t* __idx = 0, int __base = 10)
2552 { return __gnu_cxx::__stoa(&std::strtoll, "stoll", __str.c_str(),
2555 inline unsigned long long
2556 stoull(const __vstring& __str, std::size_t* __idx, int __base = 10)
2557 { return __gnu_cxx::__stoa(&std::strtoull, "stoull", __str.c_str(),
2560 // NB: strtof vs strtod.
2562 stof(const __vstring& __str, std::size_t* __idx = 0)
2563 { return __gnu_cxx::__stoa(&std::strtof, "stof", __str.c_str(), __idx); }
2566 stod(const __vstring& __str, std::size_t* __idx = 0)
2567 { return __gnu_cxx::__stoa(&std::strtod, "stod", __str.c_str(), __idx); }
2570 stold(const __vstring& __str, std::size_t* __idx = 0)
2571 { return __gnu_cxx::__stoa(&std::strtold, "stold", __str.c_str(), __idx); }
2573 // NB: (v)snprintf vs sprintf.
2577 to_string(int __val)
2578 { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, 4 * sizeof(int),
2582 to_string(unsigned __val)
2583 { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf,
2584 4 * sizeof(unsigned),
2588 to_string(long __val)
2589 { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf,
2594 to_string(unsigned long __val)
2595 { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf,
2596 4 * sizeof(unsigned long),
2601 to_string(long long __val)
2602 { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf,
2603 4 * sizeof(long long),
2607 to_string(unsigned long long __val)
2608 { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf,
2609 4 * sizeof(unsigned long long),
2613 to_string(float __val)
2615 const int __n = __numeric_traits<float>::__max_exponent10 + 20;
2616 return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, __n,
2621 to_string(double __val)
2623 const int __n = __numeric_traits<double>::__max_exponent10 + 20;
2624 return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, __n,
2629 to_string(long double __val)
2631 const int __n = __numeric_traits<long double>::__max_exponent10 + 20;
2632 return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, __n,
2636 #ifdef _GLIBCXX_USE_WCHAR_T
2638 stoi(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10)
2639 { return __gnu_cxx::__stoa<long, int>(&std::wcstol, "stoi", __str.c_str(),
2643 stol(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10)
2644 { return __gnu_cxx::__stoa(&std::wcstol, "stol", __str.c_str(),
2647 inline unsigned long
2648 stoul(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10)
2649 { return __gnu_cxx::__stoa(&std::wcstoul, "stoul", __str.c_str(),
2653 stoll(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10)
2654 { return __gnu_cxx::__stoa(&std::wcstoll, "stoll", __str.c_str(),
2657 inline unsigned long long
2658 stoull(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10)
2659 { return __gnu_cxx::__stoa(&std::wcstoull, "stoull", __str.c_str(),
2662 // NB: wcstof vs wcstod.
2664 stof(const __wvstring& __str, std::size_t* __idx = 0)
2665 { return __gnu_cxx::__stoa(&std::wcstof, "stof", __str.c_str(), __idx); }
2668 stod(const __wvstring& __str, std::size_t* __idx = 0)
2669 { return __gnu_cxx::__stoa(&std::wcstod, "stod", __str.c_str(), __idx); }
2672 stold(const __wvstring& __str, std::size_t* __idx = 0)
2673 { return __gnu_cxx::__stoa(&std::wcstold, "stold", __str.c_str(), __idx); }
2675 #ifndef _GLIBCXX_HAVE_BROKEN_VSWPRINTF
2678 to_wstring(int __val)
2679 { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
2684 to_wstring(unsigned __val)
2685 { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
2686 4 * sizeof(unsigned),
2690 to_wstring(long __val)
2691 { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
2696 to_wstring(unsigned long __val)
2697 { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
2698 4 * sizeof(unsigned long),
2702 to_wstring(long long __val)
2703 { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
2704 4 * sizeof(long long),
2708 to_wstring(unsigned long long __val)
2709 { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
2710 4 * sizeof(unsigned long long),
2714 to_wstring(float __val)
2716 const int __n = __numeric_traits<float>::__max_exponent10 + 20;
2717 return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, __n,
2722 to_wstring(double __val)
2724 const int __n = __numeric_traits<double>::__max_exponent10 + 20;
2725 return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, __n,
2730 to_wstring(long double __val)
2732 const int __n = __numeric_traits<long double>::__max_exponent10 + 20;
2733 return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, __n,
2739 _GLIBCXX_END_NAMESPACE_VERSION
2744 #ifdef __GXX_EXPERIMENTAL_CXX0X__
2746 #include <bits/functional_hash.h>
2748 namespace std _GLIBCXX_VISIBILITY(default)
2750 _GLIBCXX_BEGIN_NAMESPACE_VERSION
2752 /// std::hash specialization for __vstring.
2754 struct hash<__gnu_cxx::__vstring>
2755 : public __hash_base<size_t, __gnu_cxx::__vstring>
2758 operator()(const __gnu_cxx::__vstring& __s) const
2759 { return std::_Hash_impl::hash(__s.data(), __s.length()); }
2762 #ifdef _GLIBCXX_USE_WCHAR_T
2763 /// std::hash specialization for __wvstring.
2765 struct hash<__gnu_cxx::__wvstring>
2766 : public __hash_base<size_t, __gnu_cxx::__wvstring>
2769 operator()(const __gnu_cxx::__wvstring& __s) const
2770 { return std::_Hash_impl::hash(__s.data(),
2771 __s.length() * sizeof(wchar_t)); }
2775 #ifdef _GLIBCXX_USE_C99_STDINT_TR1
2776 /// std::hash specialization for __u16vstring.
2778 struct hash<__gnu_cxx::__u16vstring>
2779 : public __hash_base<size_t, __gnu_cxx::__u16vstring>
2782 operator()(const __gnu_cxx::__u16vstring& __s) const
2783 { return std::_Hash_impl::hash(__s.data(),
2784 __s.length() * sizeof(char16_t)); }
2787 /// std::hash specialization for __u32vstring.
2789 struct hash<__gnu_cxx::__u32vstring>
2790 : public __hash_base<size_t, __gnu_cxx::__u32vstring>
2793 operator()(const __gnu_cxx::__u32vstring& __s) const
2794 { return std::_Hash_impl::hash(__s.data(),
2795 __s.length() * sizeof(char32_t)); }
2799 _GLIBCXX_END_NAMESPACE_VERSION
2802 #endif /* __GXX_EXPERIMENTAL_CXX0X__ */
2804 #include "vstring.tcc"
2806 #endif /* _VSTRING_H */