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)
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() { }
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.
315 return iterator(this->_M_data());
319 * Returns a read-only (constant) iterator that points to the first
320 * character in the %string.
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.
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.
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.
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
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.
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
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.
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.
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
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
414 { return const_reverse_iterator(this->begin()); }
419 /// Returns the number of characters in the string, not including any
420 /// null-termination.
423 { return this->_M_length(); }
425 /// Returns the number of characters in the string, not including any
426 /// null-termination.
429 { return this->_M_length(); }
431 /// Returns the size() of the largest possible %string.
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().
469 { this->reserve(0); }
476 * Returns the total number of characters that the %string can
477 * hold before needing to allocate more memory.
481 { return this->_M_capacity(); }
484 * @brief Attempt to preallocate enough memory for specified number of
486 * @param __res_arg Number of characters required.
487 * @throw std::length_error If @a __res_arg exceeds @c max_size().
489 * This function attempts to reserve enough memory for the
490 * %string to hold the specified number of characters. If the
491 * number requested is more than max_size(), length_error is
494 * The advantage of this function is that if optimal code is a
495 * necessity and the user can determine the string length that
496 * will be required, the user can reserve the memory in
497 * %advance, and thus prevent a possible reallocation of memory
498 * and copying of %string data.
501 reserve(size_type __res_arg = 0)
502 { this->_M_reserve(__res_arg); }
505 * Erases the string, making it empty.
509 { this->_M_clear(); }
512 * Returns true if the %string is empty. Equivalent to
513 * <code>*this == ""</code>.
517 { return this->size() == 0; }
521 * @brief Subscript access to the data contained in the %string.
522 * @param __pos The index of the character to access.
523 * @return Read-only (constant) reference to the character.
525 * This operator allows for easy, array-style, data access.
526 * Note that data access with this operator is unchecked and
527 * out_of_range lookups are not defined. (For checked lookups
531 operator[] (size_type __pos) const
533 _GLIBCXX_DEBUG_ASSERT(__pos <= this->size());
534 return this->_M_data()[__pos];
538 * @brief Subscript access to the data contained in the %string.
539 * @param __pos The index of the character to access.
540 * @return Read/write reference to the character.
542 * This operator allows for easy, array-style, data access.
543 * Note that data access with this operator is unchecked and
544 * out_of_range lookups are not defined. (For checked lookups
545 * see at().) Unshares the string.
548 operator[](size_type __pos)
550 // allow pos == size() as v3 extension:
551 _GLIBCXX_DEBUG_ASSERT(__pos <= this->size());
552 // but be strict in pedantic mode:
553 _GLIBCXX_DEBUG_PEDASSERT(__pos < this->size());
555 return this->_M_data()[__pos];
559 * @brief Provides access to the data contained in the %string.
560 * @param __n The index of the character to access.
561 * @return Read-only (const) reference to the character.
562 * @throw std::out_of_range If @a __n is an invalid index.
564 * This function provides for safer data access. The parameter
565 * is first checked that it is in the range of the string. The
566 * function throws out_of_range if the check fails.
569 at(size_type __n) const
571 if (__n >= this->size())
572 std::__throw_out_of_range(__N("__versa_string::at"));
573 return this->_M_data()[__n];
577 * @brief Provides access to the data contained in the %string.
578 * @param __n The index of the character to access.
579 * @return Read/write reference to the character.
580 * @throw std::out_of_range If @a __n is an invalid index.
582 * This function provides for safer data access. The parameter
583 * is first checked that it is in the range of the string. The
584 * function throws out_of_range if the check fails. Success
585 * results in unsharing the string.
590 if (__n >= this->size())
591 std::__throw_out_of_range(__N("__versa_string::at"));
593 return this->_M_data()[__n];
596 #ifdef __GXX_EXPERIMENTAL_CXX0X__
598 * Returns a read/write reference to the data at the first
599 * element of the %string.
603 { return operator[](0); }
606 * Returns a read-only (constant) reference to the data at the first
607 * element of the %string.
611 { return operator[](0); }
614 * Returns a read/write reference to the data at the last
615 * element of the %string.
619 { return operator[](this->size() - 1); }
622 * Returns a read-only (constant) reference to the data at the
623 * last element of the %string.
627 { return operator[](this->size() - 1); }
632 * @brief Append a string to this string.
633 * @param __str The string to append.
634 * @return Reference to this string.
637 operator+=(const __versa_string& __str)
638 { return this->append(__str); }
641 * @brief Append a C string.
642 * @param __s The C string to append.
643 * @return Reference to this string.
646 operator+=(const _CharT* __s)
647 { return this->append(__s); }
650 * @brief Append a character.
651 * @param __c The character to append.
652 * @return Reference to this string.
655 operator+=(_CharT __c)
657 this->push_back(__c);
661 #ifdef __GXX_EXPERIMENTAL_CXX0X__
663 * @brief Append an initializer_list of characters.
664 * @param __l The initializer_list of characters to be appended.
665 * @return Reference to this string.
668 operator+=(std::initializer_list<_CharT> __l)
669 { return this->append(__l.begin(), __l.end()); }
670 #endif // __GXX_EXPERIMENTAL_CXX0X__
673 * @brief Append a string to this string.
674 * @param __str The string to append.
675 * @return Reference to this string.
678 append(const __versa_string& __str)
679 { return _M_append(__str._M_data(), __str.size()); }
682 * @brief Append a substring.
683 * @param __str The string to append.
684 * @param __pos Index of the first character of str to append.
685 * @param __n The number of characters to append.
686 * @return Reference to this string.
687 * @throw std::out_of_range if @a pos is not a valid index.
689 * This function appends @a __n characters from @a __str
690 * starting at @a __pos to this string. If @a __n is is larger
691 * than the number of available characters in @a __str, the
692 * remainder of @a __str is appended.
695 append(const __versa_string& __str, size_type __pos, size_type __n)
696 { return _M_append(__str._M_data()
697 + __str._M_check(__pos, "__versa_string::append"),
698 __str._M_limit(__pos, __n)); }
701 * @brief Append a C substring.
702 * @param __s The C string to append.
703 * @param __n The number of characters to append.
704 * @return Reference to this string.
707 append(const _CharT* __s, size_type __n)
709 __glibcxx_requires_string_len(__s, __n);
710 _M_check_length(size_type(0), __n, "__versa_string::append");
711 return _M_append(__s, __n);
715 * @brief Append a C string.
716 * @param __s The C string to append.
717 * @return Reference to this string.
720 append(const _CharT* __s)
722 __glibcxx_requires_string(__s);
723 const size_type __n = traits_type::length(__s);
724 _M_check_length(size_type(0), __n, "__versa_string::append");
725 return _M_append(__s, __n);
729 * @brief Append multiple characters.
730 * @param __n The number of characters to append.
731 * @param __c The character to use.
732 * @return Reference to this string.
734 * Appends n copies of c to this string.
737 append(size_type __n, _CharT __c)
738 { return _M_replace_aux(this->size(), size_type(0), __n, __c); }
740 #ifdef __GXX_EXPERIMENTAL_CXX0X__
742 * @brief Append an initializer_list of characters.
743 * @param __l The initializer_list of characters to append.
744 * @return Reference to this string.
747 append(std::initializer_list<_CharT> __l)
748 { return this->append(__l.begin(), __l.end()); }
749 #endif // __GXX_EXPERIMENTAL_CXX0X__
752 * @brief Append a range of characters.
753 * @param __first Iterator referencing the first character to append.
754 * @param __last Iterator marking the end of the range.
755 * @return Reference to this string.
757 * Appends characters in the range [first,last) to this string.
759 template<class _InputIterator>
761 append(_InputIterator __first, _InputIterator __last)
762 { return this->replace(_M_iend(), _M_iend(), __first, __last); }
765 * @brief Append a single character.
766 * @param __c Character to append.
769 push_back(_CharT __c)
771 const size_type __size = this->size();
772 if (__size + 1 > this->capacity() || this->_M_is_shared())
773 this->_M_mutate(__size, size_type(0), 0, size_type(1));
774 traits_type::assign(this->_M_data()[__size], __c);
775 this->_M_set_length(__size + 1);
779 * @brief Set value to contents of another string.
780 * @param __str Source string to use.
781 * @return Reference to this string.
784 assign(const __versa_string& __str)
786 this->_M_assign(__str);
790 #ifdef __GXX_EXPERIMENTAL_CXX0X__
792 * @brief Set value to contents of another string.
793 * @param __str Source string to use.
794 * @return Reference to this string.
796 * This function sets this string to the exact contents of @a __str.
797 * @a __str is a valid, but unspecified string.
800 assign(__versa_string&& __str)
805 #endif // __GXX_EXPERIMENTAL_CXX0X__
808 * @brief Set value to a substring of a string.
809 * @param __str The string to use.
810 * @param __pos Index of the first character of str.
811 * @param __n Number of characters to use.
812 * @return Reference to this string.
813 * @throw std::out_of_range if @a __pos is not a valid index.
815 * This function sets this string to the substring of @a __str
816 * consisting of @a __n characters at @a __pos. If @a __n is
817 * is larger than the number of available characters in @a
818 * __str, the remainder of @a __str is used.
821 assign(const __versa_string& __str, size_type __pos, size_type __n)
822 { return _M_replace(size_type(0), this->size(), __str._M_data()
823 + __str._M_check(__pos, "__versa_string::assign"),
824 __str._M_limit(__pos, __n)); }
827 * @brief Set value to a C substring.
828 * @param __s The C string to use.
829 * @param __n Number of characters to use.
830 * @return Reference to this string.
832 * This function sets the value of this string to the first @a
833 * __n characters of @a __s. If @a __n is is larger than the
834 * number of available characters in @a __s, the remainder of
838 assign(const _CharT* __s, size_type __n)
840 __glibcxx_requires_string_len(__s, __n);
841 return _M_replace(size_type(0), this->size(), __s, __n);
845 * @brief Set value to contents of a C string.
846 * @param __s The C string to use.
847 * @return Reference to this string.
849 * This function sets the value of this string to the value of
850 * @a __s. The data is copied, so there is no dependence on @a
851 * __s once the function returns.
854 assign(const _CharT* __s)
856 __glibcxx_requires_string(__s);
857 return _M_replace(size_type(0), this->size(), __s,
858 traits_type::length(__s));
862 * @brief Set value to multiple characters.
863 * @param __n Length of the resulting string.
864 * @param __c The character to use.
865 * @return Reference to this string.
867 * This function sets the value of this string to @a __n copies of
871 assign(size_type __n, _CharT __c)
872 { return _M_replace_aux(size_type(0), this->size(), __n, __c); }
875 * @brief Set value to a range of characters.
876 * @param __first Iterator referencing the first character to append.
877 * @param __last Iterator marking the end of the range.
878 * @return Reference to this string.
880 * Sets value of string to characters in the range
883 template<class _InputIterator>
885 assign(_InputIterator __first, _InputIterator __last)
886 { return this->replace(_M_ibegin(), _M_iend(), __first, __last); }
888 #ifdef __GXX_EXPERIMENTAL_CXX0X__
890 * @brief Set value to an initializer_list of characters.
891 * @param __l The initializer_list of characters to assign.
892 * @return Reference to this string.
895 assign(std::initializer_list<_CharT> __l)
896 { return this->assign(__l.begin(), __l.end()); }
897 #endif // __GXX_EXPERIMENTAL_CXX0X__
900 * @brief Insert multiple characters.
901 * @param __p Iterator referencing location in string to insert at.
902 * @param __n Number of characters to insert
903 * @param __c The character to insert.
904 * @throw std::length_error If new length exceeds @c max_size().
906 * Inserts @a __n copies of character @a __c starting at the
907 * position referenced by iterator @a __p. If adding
908 * characters causes the length to exceed max_size(),
909 * length_error is thrown. The value of the string doesn't
910 * change if an error is thrown.
913 insert(iterator __p, size_type __n, _CharT __c)
914 { this->replace(__p, __p, __n, __c); }
917 * @brief Insert a range of characters.
918 * @param __p Iterator referencing location in string to insert at.
919 * @param __beg Start of range.
920 * @param __end End of range.
921 * @throw std::length_error If new length exceeds @c max_size().
923 * Inserts characters in range [beg,end). If adding characters
924 * causes the length to exceed max_size(), length_error is
925 * thrown. The value of the string doesn't change if an error
928 template<class _InputIterator>
930 insert(iterator __p, _InputIterator __beg, _InputIterator __end)
931 { this->replace(__p, __p, __beg, __end); }
933 #ifdef __GXX_EXPERIMENTAL_CXX0X__
935 * @brief Insert an initializer_list of characters.
936 * @param __p Iterator referencing location in string to insert at.
937 * @param __l The initializer_list of characters to insert.
938 * @throw std::length_error If new length exceeds @c max_size().
941 insert(iterator __p, std::initializer_list<_CharT> __l)
942 { this->insert(__p, __l.begin(), __l.end()); }
943 #endif // __GXX_EXPERIMENTAL_CXX0X__
946 * @brief Insert value of a string.
947 * @param __pos1 Iterator referencing location in string to insert at.
948 * @param __str The string to insert.
949 * @return Reference to this string.
950 * @throw std::length_error If new length exceeds @c max_size().
952 * Inserts value of @a __str starting at @a __pos1. If adding
953 * characters causes the length to exceed max_size(),
954 * length_error is thrown. The value of the string doesn't
955 * change if an error is thrown.
958 insert(size_type __pos1, const __versa_string& __str)
959 { return this->replace(__pos1, size_type(0),
960 __str._M_data(), __str.size()); }
963 * @brief Insert a substring.
964 * @param __pos1 Iterator referencing location in string to insert at.
965 * @param __str The string to insert.
966 * @param __pos2 Start of characters in str to insert.
967 * @param __n Number of characters to insert.
968 * @return Reference to this string.
969 * @throw std::length_error If new length exceeds @c max_size().
970 * @throw std::out_of_range If @a __pos1 > size() or
971 * @a __pos2 > @a __str.size().
973 * Starting at @a __pos1, insert @a __n character of @a __str
974 * beginning with @a __pos2. If adding characters causes the
975 * length to exceed max_size(), length_error is thrown. If @a
976 * __pos1 is beyond the end of this string or @a __pos2 is
977 * beyond the end of @a __str, out_of_range is thrown. The
978 * value of the string doesn't change if an error is thrown.
981 insert(size_type __pos1, const __versa_string& __str,
982 size_type __pos2, size_type __n)
983 { return this->replace(__pos1, size_type(0), __str._M_data()
984 + __str._M_check(__pos2, "__versa_string::insert"),
985 __str._M_limit(__pos2, __n)); }
988 * @brief Insert a C substring.
989 * @param __pos Iterator referencing location in string to insert at.
990 * @param __s The C string to insert.
991 * @param __n The number of characters to insert.
992 * @return Reference to this string.
993 * @throw std::length_error If new length exceeds @c max_size().
994 * @throw std::out_of_range If @a __pos is beyond the end of this
997 * Inserts the first @a __n characters of @a __s starting at @a
998 * __pos. If adding characters causes the length to exceed
999 * max_size(), length_error is thrown. If @a __pos is beyond
1000 * end(), out_of_range is thrown. The value of the string
1001 * doesn't change if an error is thrown.
1004 insert(size_type __pos, const _CharT* __s, size_type __n)
1005 { return this->replace(__pos, size_type(0), __s, __n); }
1008 * @brief Insert a C string.
1009 * @param __pos Iterator referencing location in string to insert at.
1010 * @param __s The C string to insert.
1011 * @return Reference to this string.
1012 * @throw std::length_error If new length exceeds @c max_size().
1013 * @throw std::out_of_range If @a __pos is beyond the end of this
1016 * Inserts the first @a __n characters of @a __s starting at @a
1017 * __pos. If adding characters causes the length to exceed
1018 * max_size(), length_error is thrown. If @a __pos is beyond
1019 * end(), out_of_range is thrown. The value of the string
1020 * doesn't change if an error is thrown.
1023 insert(size_type __pos, const _CharT* __s)
1025 __glibcxx_requires_string(__s);
1026 return this->replace(__pos, size_type(0), __s,
1027 traits_type::length(__s));
1031 * @brief Insert multiple characters.
1032 * @param __pos Index in string to insert at.
1033 * @param __n Number of characters to insert
1034 * @param __c The character to insert.
1035 * @return Reference to this string.
1036 * @throw std::length_error If new length exceeds @c max_size().
1037 * @throw std::out_of_range If @a __pos is beyond the end of this
1040 * Inserts @a __n copies of character @a __c starting at index
1041 * @a __pos. If adding characters causes the length to exceed
1042 * max_size(), length_error is thrown. If @a __pos > length(),
1043 * out_of_range is thrown. The value of the string doesn't
1044 * change if an error is thrown.
1047 insert(size_type __pos, size_type __n, _CharT __c)
1048 { return _M_replace_aux(_M_check(__pos, "__versa_string::insert"),
1049 size_type(0), __n, __c); }
1052 * @brief Insert one character.
1053 * @param __p Iterator referencing position in string to insert at.
1054 * @param __c The character to insert.
1055 * @return Iterator referencing newly inserted char.
1056 * @throw std::length_error If new length exceeds @c max_size().
1058 * Inserts character @a __c at position referenced by @a __p.
1059 * If adding character causes the length to exceed max_size(),
1060 * length_error is thrown. If @a __p is beyond end of string,
1061 * out_of_range is thrown. The value of the string doesn't
1062 * change if an error is thrown.
1065 insert(iterator __p, _CharT __c)
1067 _GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend());
1068 const size_type __pos = __p - _M_ibegin();
1069 _M_replace_aux(__pos, size_type(0), size_type(1), __c);
1070 this->_M_set_leaked();
1071 return iterator(this->_M_data() + __pos);
1075 * @brief Remove characters.
1076 * @param __pos Index of first character to remove (default 0).
1077 * @param __n Number of characters to remove (default remainder).
1078 * @return Reference to this string.
1079 * @throw std::out_of_range If @a __pos is beyond the end of this
1082 * Removes @a __n characters from this string starting at @a
1083 * __pos. The length of the string is reduced by @a __n. If
1084 * there are < @a __n characters to remove, the remainder of
1085 * the string is truncated. If @a __p is beyond end of string,
1086 * out_of_range is thrown. The value of the string doesn't
1087 * change if an error is thrown.
1090 erase(size_type __pos = 0, size_type __n = npos)
1092 this->_M_erase(_M_check(__pos, "__versa_string::erase"),
1093 _M_limit(__pos, __n));
1098 * @brief Remove one character.
1099 * @param __position Iterator referencing the character to remove.
1100 * @return iterator referencing same location after removal.
1102 * Removes the character at @a __position from this string. The
1103 * value of the string doesn't change if an error is thrown.
1106 erase(iterator __position)
1108 _GLIBCXX_DEBUG_PEDASSERT(__position >= _M_ibegin()
1109 && __position < _M_iend());
1110 const size_type __pos = __position - _M_ibegin();
1111 this->_M_erase(__pos, size_type(1));
1112 this->_M_set_leaked();
1113 return iterator(this->_M_data() + __pos);
1117 * @brief Remove a range of characters.
1118 * @param __first Iterator referencing the first character to remove.
1119 * @param __last Iterator referencing the end of the range.
1120 * @return Iterator referencing location of first after removal.
1122 * Removes the characters in the range [first,last) from this
1123 * string. The value of the string doesn't change if an error
1127 erase(iterator __first, iterator __last)
1129 _GLIBCXX_DEBUG_PEDASSERT(__first >= _M_ibegin() && __first <= __last
1130 && __last <= _M_iend());
1131 const size_type __pos = __first - _M_ibegin();
1132 this->_M_erase(__pos, __last - __first);
1133 this->_M_set_leaked();
1134 return iterator(this->_M_data() + __pos);
1138 * @brief Replace characters with value from another string.
1139 * @param __pos Index of first character to replace.
1140 * @param __n Number of characters to be replaced.
1141 * @param __str String to insert.
1142 * @return Reference to this string.
1143 * @throw std::out_of_range If @a __pos is beyond the end of this
1145 * @throw std::length_error If new length exceeds @c max_size().
1147 * Removes the characters in the range [pos,pos+n) from this
1148 * string. In place, the value of @a __str is inserted. If @a
1149 * __pos is beyond end of string, out_of_range is thrown. If
1150 * the length of the result exceeds max_size(), length_error is
1151 * thrown. The value of the string doesn't change if an error
1155 replace(size_type __pos, size_type __n, const __versa_string& __str)
1156 { return this->replace(__pos, __n, __str._M_data(), __str.size()); }
1159 * @brief Replace characters with value from another string.
1160 * @param __pos1 Index of first character to replace.
1161 * @param __n1 Number of characters to be replaced.
1162 * @param __str String to insert.
1163 * @param __pos2 Index of first character of str to use.
1164 * @param __n2 Number of characters from str to use.
1165 * @return Reference to this string.
1166 * @throw std::out_of_range If @a __pos1 > size() or @a __pos2 >
1168 * @throw std::length_error If new length exceeds @c max_size().
1170 * Removes the characters in the range [pos1,pos1 + n) from
1171 * this string. In place, the value of @a __str is inserted.
1172 * If @a __pos is beyond end of string, out_of_range is thrown.
1173 * If the length of the result exceeds max_size(), length_error
1174 * is thrown. The value of the string doesn't change if an
1178 replace(size_type __pos1, size_type __n1, const __versa_string& __str,
1179 size_type __pos2, size_type __n2)
1181 return this->replace(__pos1, __n1, __str._M_data()
1182 + __str._M_check(__pos2,
1183 "__versa_string::replace"),
1184 __str._M_limit(__pos2, __n2));
1188 * @brief Replace characters with value of a C substring.
1189 * @param __pos Index of first character to replace.
1190 * @param __n1 Number of characters to be replaced.
1191 * @param __s C string to insert.
1192 * @param __n2 Number of characters from @a __s to use.
1193 * @return Reference to this string.
1194 * @throw std::out_of_range If @a __pos1 > size().
1195 * @throw std::length_error If new length exceeds @c max_size().
1197 * Removes the characters in the range [pos,pos + n1) from this
1198 * string. In place, the first @a __n2 characters of @a __s
1199 * are inserted, or all of @a __s if @a __n2 is too large. If
1200 * @a __pos is beyond end of string, out_of_range is thrown.
1201 * If the length of result exceeds max_size(), length_error is
1202 * thrown. The value of the string doesn't change if an error
1206 replace(size_type __pos, size_type __n1, const _CharT* __s,
1209 __glibcxx_requires_string_len(__s, __n2);
1210 return _M_replace(_M_check(__pos, "__versa_string::replace"),
1211 _M_limit(__pos, __n1), __s, __n2);
1215 * @brief Replace characters with value of a C string.
1216 * @param __pos Index of first character to replace.
1217 * @param __n1 Number of characters to be replaced.
1218 * @param __s C string to insert.
1219 * @return Reference to this string.
1220 * @throw std::out_of_range If @a __pos > size().
1221 * @throw std::length_error If new length exceeds @c max_size().
1223 * Removes the characters in the range [pos,pos + n1) from this
1224 * string. In place, the characters of @a __s are inserted. If
1225 * @a pos is beyond end of string, out_of_range is thrown. If
1226 * the length of result exceeds max_size(), length_error is thrown.
1227 * The value of the string doesn't change if an error is thrown.
1230 replace(size_type __pos, size_type __n1, const _CharT* __s)
1232 __glibcxx_requires_string(__s);
1233 return this->replace(__pos, __n1, __s, traits_type::length(__s));
1237 * @brief Replace characters with multiple characters.
1238 * @param __pos Index of first character to replace.
1239 * @param __n1 Number of characters to be replaced.
1240 * @param __n2 Number of characters to insert.
1241 * @param __c Character to insert.
1242 * @return Reference to this string.
1243 * @throw std::out_of_range If @a __pos > size().
1244 * @throw std::length_error If new length exceeds @c max_size().
1246 * Removes the characters in the range [pos,pos + n1) from this
1247 * string. In place, @a __n2 copies of @a __c are inserted.
1248 * If @a __pos is beyond end of string, out_of_range is thrown.
1249 * If the length of result exceeds max_size(), length_error is
1250 * thrown. The value of the string doesn't change if an error
1254 replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
1255 { return _M_replace_aux(_M_check(__pos, "__versa_string::replace"),
1256 _M_limit(__pos, __n1), __n2, __c); }
1259 * @brief Replace range of characters with string.
1260 * @param __i1 Iterator referencing start of range to replace.
1261 * @param __i2 Iterator referencing end of range to replace.
1262 * @param __str String value to insert.
1263 * @return Reference to this string.
1264 * @throw std::length_error If new length exceeds @c max_size().
1266 * Removes the characters in the range [i1,i2). In place, the
1267 * value of @a __str is inserted. If the length of result
1268 * exceeds max_size(), length_error is thrown. The value of
1269 * the string doesn't change if an error is thrown.
1272 replace(iterator __i1, iterator __i2, const __versa_string& __str)
1273 { return this->replace(__i1, __i2, __str._M_data(), __str.size()); }
1276 * @brief Replace range of characters with C substring.
1277 * @param __i1 Iterator referencing start of range to replace.
1278 * @param __i2 Iterator referencing end of range to replace.
1279 * @param __s C string value to insert.
1280 * @param __n Number of characters from s to insert.
1281 * @return Reference to this string.
1282 * @throw std::length_error If new length exceeds @c max_size().
1284 * Removes the characters in the range [i1,i2). In place, the
1285 * first @a n characters of @a __s are inserted. If the length
1286 * of result exceeds max_size(), length_error is thrown. The
1287 * value of the string doesn't change if an error is thrown.
1290 replace(iterator __i1, iterator __i2, const _CharT* __s, size_type __n)
1292 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1293 && __i2 <= _M_iend());
1294 return this->replace(__i1 - _M_ibegin(), __i2 - __i1, __s, __n);
1298 * @brief Replace range of characters with C string.
1299 * @param __i1 Iterator referencing start of range to replace.
1300 * @param __i2 Iterator referencing end of range to replace.
1301 * @param __s C string value to insert.
1302 * @return Reference to this string.
1303 * @throw std::length_error If new length exceeds @c max_size().
1305 * Removes the characters in the range [i1,i2). In place, the
1306 * characters of @a __s are inserted. If the length of result
1307 * exceeds max_size(), length_error is thrown. The value of
1308 * the string doesn't change if an error is thrown.
1311 replace(iterator __i1, iterator __i2, const _CharT* __s)
1313 __glibcxx_requires_string(__s);
1314 return this->replace(__i1, __i2, __s, traits_type::length(__s));
1318 * @brief Replace range of characters with multiple characters
1319 * @param __i1 Iterator referencing start of range to replace.
1320 * @param __i2 Iterator referencing end of range to replace.
1321 * @param __n Number of characters to insert.
1322 * @param __c Character to insert.
1323 * @return Reference to this string.
1324 * @throw std::length_error If new length exceeds @c max_size().
1326 * Removes the characters in the range [i1,i2). In place, @a
1327 * __n copies of @a __c are inserted. If the length of result
1328 * exceeds max_size(), length_error is thrown. The value of
1329 * the string doesn't change if an error is thrown.
1332 replace(iterator __i1, iterator __i2, size_type __n, _CharT __c)
1334 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1335 && __i2 <= _M_iend());
1336 return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __c);
1340 * @brief Replace range of characters with range.
1341 * @param __i1 Iterator referencing start of range to replace.
1342 * @param __i2 Iterator referencing end of range to replace.
1343 * @param __k1 Iterator referencing start of range to insert.
1344 * @param __k2 Iterator referencing end of range to insert.
1345 * @return Reference to this string.
1346 * @throw std::length_error If new length exceeds @c max_size().
1348 * Removes the characters in the range [i1,i2). In place,
1349 * characters in the range [k1,k2) are inserted. If the length
1350 * of result exceeds max_size(), length_error is thrown. The
1351 * value of the string doesn't change if an error is thrown.
1353 template<class _InputIterator>
1355 replace(iterator __i1, iterator __i2,
1356 _InputIterator __k1, _InputIterator __k2)
1358 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1359 && __i2 <= _M_iend());
1360 __glibcxx_requires_valid_range(__k1, __k2);
1361 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
1362 return this->_M_replace_dispatch(__i1, __i2, __k1, __k2, _Integral());
1365 // Specializations for the common case of pointer and iterator:
1366 // useful to avoid the overhead of temporary buffering in _M_replace.
1368 replace(iterator __i1, iterator __i2, _CharT* __k1, _CharT* __k2)
1370 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1371 && __i2 <= _M_iend());
1372 __glibcxx_requires_valid_range(__k1, __k2);
1373 return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
1378 replace(iterator __i1, iterator __i2,
1379 const _CharT* __k1, const _CharT* __k2)
1381 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1382 && __i2 <= _M_iend());
1383 __glibcxx_requires_valid_range(__k1, __k2);
1384 return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
1389 replace(iterator __i1, iterator __i2, iterator __k1, iterator __k2)
1391 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1392 && __i2 <= _M_iend());
1393 __glibcxx_requires_valid_range(__k1, __k2);
1394 return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
1395 __k1.base(), __k2 - __k1);
1399 replace(iterator __i1, iterator __i2,
1400 const_iterator __k1, const_iterator __k2)
1402 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1403 && __i2 <= _M_iend());
1404 __glibcxx_requires_valid_range(__k1, __k2);
1405 return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
1406 __k1.base(), __k2 - __k1);
1409 #ifdef __GXX_EXPERIMENTAL_CXX0X__
1411 * @brief Replace range of characters with initializer_list.
1412 * @param __i1 Iterator referencing start of range to replace.
1413 * @param __i2 Iterator referencing end of range to replace.
1414 * @param __l The initializer_list of characters to insert.
1415 * @return Reference to this string.
1416 * @throw std::length_error If new length exceeds @c max_size().
1418 * Removes the characters in the range [i1,i2). In place,
1419 * characters in the range [k1,k2) are inserted. If the length
1420 * of result exceeds max_size(), length_error is thrown. The
1421 * value of the string doesn't change if an error is thrown.
1423 __versa_string& replace(iterator __i1, iterator __i2,
1424 std::initializer_list<_CharT> __l)
1425 { return this->replace(__i1, __i2, __l.begin(), __l.end()); }
1426 #endif // __GXX_EXPERIMENTAL_CXX0X__
1429 template<class _Integer>
1431 _M_replace_dispatch(iterator __i1, iterator __i2, _Integer __n,
1432 _Integer __val, std::__true_type)
1433 { return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __val); }
1435 template<class _InputIterator>
1437 _M_replace_dispatch(iterator __i1, iterator __i2, _InputIterator __k1,
1438 _InputIterator __k2, std::__false_type);
1441 _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2,
1445 _M_replace(size_type __pos, size_type __len1, const _CharT* __s,
1446 const size_type __len2);
1449 _M_append(const _CharT* __s, size_type __n);
1454 * @brief Copy substring into C string.
1455 * @param __s C string to copy value into.
1456 * @param __n Number of characters to copy.
1457 * @param __pos Index of first character to copy.
1458 * @return Number of characters actually copied
1459 * @throw std::out_of_range If pos > size().
1461 * Copies up to @a __n characters starting at @a __pos into the
1462 * C string @a s. If @a __pos is greater than size(),
1463 * out_of_range is thrown.
1466 copy(_CharT* __s, size_type __n, size_type __pos = 0) const;
1469 * @brief Swap contents with another string.
1470 * @param __s String to swap with.
1472 * Exchanges the contents of this string with that of @a __s in
1476 swap(__versa_string& __s)
1477 { this->_M_swap(__s); }
1479 // String operations:
1481 * @brief Return const pointer to null-terminated contents.
1483 * This is a handle to internal data. Do not modify or dire things may
1488 { return this->_M_data(); }
1491 * @brief Return const pointer to contents.
1493 * This is a handle to internal data. Do not modify or dire things may
1498 { return this->_M_data(); }
1501 * @brief Return copy of allocator used to construct this string.
1504 get_allocator() const
1505 { return allocator_type(this->_M_get_allocator()); }
1508 * @brief Find position of a C substring.
1509 * @param __s C string to locate.
1510 * @param __pos Index of character to search from.
1511 * @param __n Number of characters from @a __s to search for.
1512 * @return Index of start of first occurrence.
1514 * Starting from @a __pos, searches forward for the first @a
1515 * __n characters in @a __s within this string. If found,
1516 * returns the index where it begins. If not found, returns
1520 find(const _CharT* __s, size_type __pos, size_type __n) const;
1523 * @brief Find position of a string.
1524 * @param __str String to locate.
1525 * @param __pos Index of character to search from (default 0).
1526 * @return Index of start of first occurrence.
1528 * Starting from @a __pos, searches forward for value of @a
1529 * __str within this string. If found, returns the index where
1530 * it begins. If not found, returns npos.
1533 find(const __versa_string& __str, size_type __pos = 0) const
1534 { return this->find(__str.data(), __pos, __str.size()); }
1537 * @brief Find position of a C string.
1538 * @param __s C string to locate.
1539 * @param __pos Index of character to search from (default 0).
1540 * @return Index of start of first occurrence.
1542 * Starting from @a __pos, searches forward for the value of @a
1543 * __s within this string. If found, returns the index where
1544 * it begins. If not found, returns npos.
1547 find(const _CharT* __s, size_type __pos = 0) const
1549 __glibcxx_requires_string(__s);
1550 return this->find(__s, __pos, traits_type::length(__s));
1554 * @brief Find position of a character.
1555 * @param __c Character to locate.
1556 * @param __pos Index of character to search from (default 0).
1557 * @return Index of first occurrence.
1559 * Starting from @a __pos, searches forward for @a __c within
1560 * this string. If found, returns the index where it was
1561 * found. If not found, returns npos.
1564 find(_CharT __c, size_type __pos = 0) const;
1567 * @brief Find last position of a string.
1568 * @param __str String to locate.
1569 * @param __pos Index of character to search back from (default end).
1570 * @return Index of start of last occurrence.
1572 * Starting from @a __pos, searches backward for value of @a
1573 * __str within this string. If found, returns the index where
1574 * it begins. If not found, returns npos.
1577 rfind(const __versa_string& __str, size_type __pos = npos) const
1578 { return this->rfind(__str.data(), __pos, __str.size()); }
1581 * @brief Find last position of a C substring.
1582 * @param __s C string to locate.
1583 * @param __pos Index of character to search back from.
1584 * @param __n Number of characters from s to search for.
1585 * @return Index of start of last occurrence.
1587 * Starting from @a __pos, searches backward for the first @a
1588 * __n characters in @a __s within this string. If found,
1589 * returns the index where it begins. If not found, returns
1593 rfind(const _CharT* __s, size_type __pos, size_type __n) const;
1596 * @brief Find last position of a C string.
1597 * @param __s C string to locate.
1598 * @param __pos Index of character to start search at (default end).
1599 * @return Index of start of last occurrence.
1601 * Starting from @a __pos, searches backward for the value of
1602 * @a __s within this string. If found, returns the index
1603 * where it begins. If not found, returns npos.
1606 rfind(const _CharT* __s, size_type __pos = npos) const
1608 __glibcxx_requires_string(__s);
1609 return this->rfind(__s, __pos, traits_type::length(__s));
1613 * @brief Find last position of a character.
1614 * @param __c Character to locate.
1615 * @param __pos Index of character to search back from (default end).
1616 * @return Index of last occurrence.
1618 * Starting from @a __pos, searches backward for @a __c within
1619 * this string. If found, returns the index where it was
1620 * found. If not found, returns npos.
1623 rfind(_CharT __c, size_type __pos = npos) const;
1626 * @brief Find position of a character of string.
1627 * @param __str String containing characters to locate.
1628 * @param __pos Index of character to search from (default 0).
1629 * @return Index of first occurrence.
1631 * Starting from @a __pos, searches forward for one of the characters of
1632 * @a __str within this string. If found, returns the index where it was
1633 * found. If not found, returns npos.
1636 find_first_of(const __versa_string& __str, size_type __pos = 0) const
1637 { return this->find_first_of(__str.data(), __pos, __str.size()); }
1640 * @brief Find position of a character of C substring.
1641 * @param __s String containing characters to locate.
1642 * @param __pos Index of character to search from.
1643 * @param __n Number of characters from s to search for.
1644 * @return Index of first occurrence.
1646 * Starting from @a __pos, searches forward for one of the
1647 * first @a __n characters of @a __s within this string. If
1648 * found, returns the index where it was found. If not found,
1652 find_first_of(const _CharT* __s, size_type __pos, size_type __n) const;
1655 * @brief Find position of a character of C string.
1656 * @param __s String containing characters to locate.
1657 * @param __pos Index of character to search from (default 0).
1658 * @return Index of first occurrence.
1660 * Starting from @a __pos, searches forward for one of the
1661 * characters of @a __s within this string. If found, returns
1662 * the index where it was found. If not found, returns npos.
1665 find_first_of(const _CharT* __s, size_type __pos = 0) const
1667 __glibcxx_requires_string(__s);
1668 return this->find_first_of(__s, __pos, traits_type::length(__s));
1672 * @brief Find position of a character.
1673 * @param __c Character to locate.
1674 * @param __pos Index of character to search from (default 0).
1675 * @return Index of first occurrence.
1677 * Starting from @a __pos, searches forward for the character
1678 * @a __c within this string. If found, returns the index
1679 * where it was found. If not found, returns npos.
1681 * Note: equivalent to find(c, pos).
1684 find_first_of(_CharT __c, size_type __pos = 0) const
1685 { return this->find(__c, __pos); }
1688 * @brief Find last position of a character of string.
1689 * @param __str String containing characters to locate.
1690 * @param __pos Index of character to search back from (default end).
1691 * @return Index of last occurrence.
1693 * Starting from @a __pos, searches backward for one of the
1694 * characters of @a __str within this string. If found,
1695 * returns the index where it was found. If not found, returns
1699 find_last_of(const __versa_string& __str, size_type __pos = npos) const
1700 { return this->find_last_of(__str.data(), __pos, __str.size()); }
1703 * @brief Find last position of a character of C substring.
1704 * @param __s C string containing characters to locate.
1705 * @param __pos Index of character to search back from.
1706 * @param __n Number of characters from s to search for.
1707 * @return Index of last occurrence.
1709 * Starting from @a __pos, searches backward for one of the
1710 * first @a __n characters of @a __s within this string. If
1711 * found, returns the index where it was found. If not found,
1715 find_last_of(const _CharT* __s, size_type __pos, size_type __n) const;
1718 * @brief Find last position of a character of C string.
1719 * @param __s C string containing characters to locate.
1720 * @param __pos Index of character to search back from (default end).
1721 * @return Index of last occurrence.
1723 * Starting from @a __pos, searches backward for one of the
1724 * characters of @a __s within this string. If found, returns
1725 * the index where it was found. If not found, returns npos.
1728 find_last_of(const _CharT* __s, size_type __pos = npos) const
1730 __glibcxx_requires_string(__s);
1731 return this->find_last_of(__s, __pos, traits_type::length(__s));
1735 * @brief Find last position of a character.
1736 * @param __c Character to locate.
1737 * @param __pos Index of character to search back from (default end).
1738 * @return Index of last occurrence.
1740 * Starting from @a __pos, searches backward for @a __c within
1741 * this string. If found, returns the index where it was
1742 * found. If not found, returns npos.
1744 * Note: equivalent to rfind(c, pos).
1747 find_last_of(_CharT __c, size_type __pos = npos) const
1748 { return this->rfind(__c, __pos); }
1751 * @brief Find position of a character not in string.
1752 * @param __str String containing characters to avoid.
1753 * @param __pos Index of character to search from (default 0).
1754 * @return Index of first occurrence.
1756 * Starting from @a __pos, searches forward for a character not
1757 * contained in @a __str within this string. If found, returns
1758 * the index where it was found. If not found, returns npos.
1761 find_first_not_of(const __versa_string& __str, size_type __pos = 0) const
1762 { return this->find_first_not_of(__str.data(), __pos, __str.size()); }
1765 * @brief Find position of a character not in C substring.
1766 * @param __s C string containing characters to avoid.
1767 * @param __pos Index of character to search from.
1768 * @param __n Number of characters from s to consider.
1769 * @return Index of first occurrence.
1771 * Starting from @a __pos, searches forward for a character not
1772 * contained in the first @a __n characters of @a __s within
1773 * this string. If found, returns the index where it was
1774 * found. If not found, returns npos.
1777 find_first_not_of(const _CharT* __s, size_type __pos,
1778 size_type __n) const;
1781 * @brief Find position of a character not in C string.
1782 * @param __s C string containing characters to avoid.
1783 * @param __pos Index of character to search from (default 0).
1784 * @return Index of first occurrence.
1786 * Starting from @a __pos, searches forward for a character not
1787 * contained in @a __s within this string. If found, returns
1788 * the index where it was found. If not found, returns npos.
1791 find_first_not_of(const _CharT* __s, size_type __pos = 0) const
1793 __glibcxx_requires_string(__s);
1794 return this->find_first_not_of(__s, __pos, traits_type::length(__s));
1798 * @brief Find position of a different character.
1799 * @param __c Character to avoid.
1800 * @param __pos Index of character to search from (default 0).
1801 * @return Index of first occurrence.
1803 * Starting from @a __pos, searches forward for a character
1804 * other than @a __c within this string. If found, returns the
1805 * index where it was found. If not found, returns npos.
1808 find_first_not_of(_CharT __c, size_type __pos = 0) const;
1811 * @brief Find last position of a character not in string.
1812 * @param __str String containing characters to avoid.
1813 * @param __pos Index of character to search back from (default end).
1814 * @return Index of last occurrence.
1816 * Starting from @a __pos, searches backward for a character
1817 * not contained in @a __str within this string. If found,
1818 * returns the index where it was found. If not found, returns
1822 find_last_not_of(const __versa_string& __str,
1823 size_type __pos = npos) const
1824 { return this->find_last_not_of(__str.data(), __pos, __str.size()); }
1827 * @brief Find last position of a character not in C substring.
1828 * @param __s C string containing characters to avoid.
1829 * @param __pos Index of character to search back from.
1830 * @param __n Number of characters from s to consider.
1831 * @return Index of last occurrence.
1833 * Starting from @a __pos, searches backward for a character
1834 * not contained in the first @a __n characters of @a __s
1835 * within this string. If found, returns the index where it
1836 * was found. If not found, returns npos.
1839 find_last_not_of(const _CharT* __s, size_type __pos,
1840 size_type __n) const;
1842 * @brief Find last position of a character not in C string.
1843 * @param __s C string containing characters to avoid.
1844 * @param __pos Index of character to search back from (default end).
1845 * @return Index of last occurrence.
1847 * Starting from @a __pos, searches backward for a character
1848 * not contained in @a __s within this string. If found,
1849 * returns the index where it was found. If not found, returns
1853 find_last_not_of(const _CharT* __s, size_type __pos = npos) const
1855 __glibcxx_requires_string(__s);
1856 return this->find_last_not_of(__s, __pos, traits_type::length(__s));
1860 * @brief Find last position of a different character.
1861 * @param __c Character to avoid.
1862 * @param __pos Index of character to search back from (default end).
1863 * @return Index of last occurrence.
1865 * Starting from @a __pos, searches backward for a character
1866 * other than @a __c within this string. If found, returns the
1867 * index where it was found. If not found, returns npos.
1870 find_last_not_of(_CharT __c, size_type __pos = npos) const;
1873 * @brief Get a substring.
1874 * @param __pos Index of first character (default 0).
1875 * @param __n Number of characters in substring (default remainder).
1876 * @return The new string.
1877 * @throw std::out_of_range If pos > size().
1879 * Construct and return a new string using the @a __n
1880 * characters starting at @a __pos. If the string is too
1881 * short, use the remainder of the characters. If @a __pos is
1882 * beyond the end of the string, out_of_range is thrown.
1885 substr(size_type __pos = 0, size_type __n = npos) const
1887 return __versa_string(*this, _M_check(__pos, "__versa_string::substr"),
1892 * @brief Compare to a string.
1893 * @param __str String to compare against.
1894 * @return Integer < 0, 0, or > 0.
1896 * Returns an integer < 0 if this string is ordered before @a
1897 * __str, 0 if their values are equivalent, or > 0 if this
1898 * string is ordered after @a __str. Determines the effective
1899 * length rlen of the strings to compare as the smallest of
1900 * size() and str.size(). The function then compares the two
1901 * strings by calling traits::compare(data(), str.data(),rlen).
1902 * If the result of the comparison is nonzero returns it,
1903 * otherwise the shorter one is ordered first.
1906 compare(const __versa_string& __str) const
1908 if (this->_M_compare(__str))
1911 const size_type __size = this->size();
1912 const size_type __osize = __str.size();
1913 const size_type __len = std::min(__size, __osize);
1915 int __r = traits_type::compare(this->_M_data(), __str.data(), __len);
1917 __r = this->_S_compare(__size, __osize);
1922 * @brief Compare substring to a string.
1923 * @param __pos Index of first character of substring.
1924 * @param __n Number of characters in substring.
1925 * @param __str String to compare against.
1926 * @return Integer < 0, 0, or > 0.
1928 * Form the substring of this string from the @a __n characters
1929 * starting at @a __pos. Returns an integer < 0 if the
1930 * substring is ordered before @a __str, 0 if their values are
1931 * equivalent, or > 0 if the substring is ordered after @a
1932 * __str. Determines the effective length rlen of the strings
1933 * to compare as the smallest of the length of the substring
1934 * and @a __str.size(). The function then compares the two
1935 * strings by calling
1936 * traits::compare(substring.data(),str.data(),rlen). If the
1937 * result of the comparison is nonzero returns it, otherwise
1938 * the shorter one is ordered first.
1941 compare(size_type __pos, size_type __n,
1942 const __versa_string& __str) const;
1945 * @brief Compare substring to a substring.
1946 * @param __pos1 Index of first character of substring.
1947 * @param __n1 Number of characters in substring.
1948 * @param __str String to compare against.
1949 * @param __pos2 Index of first character of substring of str.
1950 * @param __n2 Number of characters in substring of str.
1951 * @return Integer < 0, 0, or > 0.
1953 * Form the substring of this string from the @a __n1
1954 * characters starting at @a __pos1. Form the substring of @a
1955 * __str from the @a __n2 characters starting at @a __pos2.
1956 * Returns an integer < 0 if this substring is ordered before
1957 * the substring of @a __str, 0 if their values are equivalent,
1958 * or > 0 if this substring is ordered after the substring of
1959 * @a __str. Determines the effective length rlen of the
1960 * strings to compare as the smallest of the lengths of the
1961 * substrings. The function then compares the two strings by
1963 * traits::compare(substring.data(),str.substr(pos2,n2).data(),rlen).
1964 * If the result of the comparison is nonzero returns it,
1965 * otherwise the shorter one is ordered first.
1968 compare(size_type __pos1, size_type __n1, const __versa_string& __str,
1969 size_type __pos2, size_type __n2) const;
1972 * @brief Compare to a C string.
1973 * @param __s C string to compare against.
1974 * @return Integer < 0, 0, or > 0.
1976 * Returns an integer < 0 if this string is ordered before @a
1977 * __s, 0 if their values are equivalent, or > 0 if this string
1978 * is ordered after @a __s. Determines the effective length
1979 * rlen of the strings to compare as the smallest of size() and
1980 * the length of a string constructed from @a __s. The
1981 * function then compares the two strings by calling
1982 * traits::compare(data(),s,rlen). If the result of the
1983 * comparison is nonzero returns it, otherwise the shorter one
1987 compare(const _CharT* __s) const;
1989 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1990 // 5 String::compare specification questionable
1992 * @brief Compare substring to a C string.
1993 * @param __pos Index of first character of substring.
1994 * @param __n1 Number of characters in substring.
1995 * @param __s C string to compare against.
1996 * @return Integer < 0, 0, or > 0.
1998 * Form the substring of this string from the @a __n1
1999 * characters starting at @a __pos. Returns an integer < 0 if
2000 * the substring is ordered before @a __s, 0 if their values
2001 * are equivalent, or > 0 if the substring is ordered after @a
2002 * __s. Determines the effective length rlen of the strings to
2003 * compare as the smallest of the length of the substring and
2004 * the length of a string constructed from @a __s. The
2005 * function then compares the two string by calling
2006 * traits::compare(substring.data(),s,rlen). If the result of
2007 * the comparison is nonzero returns it, otherwise the shorter
2008 * one is ordered first.
2011 compare(size_type __pos, size_type __n1, const _CharT* __s) const;
2014 * @brief Compare substring against a character array.
2015 * @param __pos1 Index of first character of substring.
2016 * @param __n1 Number of characters in substring.
2017 * @param __s character array to compare against.
2018 * @param __n2 Number of characters of s.
2019 * @return Integer < 0, 0, or > 0.
2021 * Form the substring of this string from the @a __n1
2022 * characters starting at @a __pos1. Form a string from the
2023 * first @a __n2 characters of @a __s. Returns an integer < 0
2024 * if this substring is ordered before the string from @a __s,
2025 * 0 if their values are equivalent, or > 0 if this substring
2026 * is ordered after the string from @a __s. Determines the
2027 * effective length rlen of the strings to compare as the
2028 * smallest of the length of the substring and @a __n2. The
2029 * function then compares the two strings 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.
2034 * NB: s must have at least n2 characters, <em>\\0</em> has no special
2038 compare(size_type __pos, size_type __n1, const _CharT* __s,
2039 size_type __n2) const;
2044 * @brief Concatenate two strings.
2045 * @param __lhs First string.
2046 * @param __rhs Last string.
2047 * @return New string with value of @a __lhs followed by @a __rhs.
2049 template<typename _CharT, typename _Traits, typename _Alloc,
2050 template <typename, typename, typename> class _Base>
2051 __versa_string<_CharT, _Traits, _Alloc, _Base>
2052 operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2053 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs);
2056 * @brief Concatenate C string and string.
2057 * @param __lhs First string.
2058 * @param __rhs Last string.
2059 * @return New string with value of @a __lhs followed by @a __rhs.
2061 template<typename _CharT, typename _Traits, typename _Alloc,
2062 template <typename, typename, typename> class _Base>
2063 __versa_string<_CharT, _Traits, _Alloc, _Base>
2064 operator+(const _CharT* __lhs,
2065 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs);
2068 * @brief Concatenate character and string.
2069 * @param __lhs First string.
2070 * @param __rhs Last string.
2071 * @return New string with @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+(_CharT __lhs,
2077 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs);
2080 * @brief Concatenate string and C string.
2081 * @param __lhs First string.
2082 * @param __rhs Last string.
2083 * @return New string with @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 __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2089 const _CharT* __rhs);
2092 * @brief Concatenate string and character.
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+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2103 #ifdef __GXX_EXPERIMENTAL_CXX0X__
2104 template<typename _CharT, typename _Traits, typename _Alloc,
2105 template <typename, typename, typename> class _Base>
2106 inline __versa_string<_CharT, _Traits, _Alloc, _Base>
2107 operator+(__versa_string<_CharT, _Traits, _Alloc, _Base>&& __lhs,
2108 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2109 { return std::move(__lhs.append(__rhs)); }
2111 template<typename _CharT, typename _Traits, typename _Alloc,
2112 template <typename, typename, typename> class _Base>
2113 inline __versa_string<_CharT, _Traits, _Alloc, _Base>
2114 operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2115 __versa_string<_CharT, _Traits, _Alloc, _Base>&& __rhs)
2116 { return std::move(__rhs.insert(0, __lhs)); }
2118 template<typename _CharT, typename _Traits, typename _Alloc,
2119 template <typename, typename, typename> class _Base>
2120 inline __versa_string<_CharT, _Traits, _Alloc, _Base>
2121 operator+(__versa_string<_CharT, _Traits, _Alloc, _Base>&& __lhs,
2122 __versa_string<_CharT, _Traits, _Alloc, _Base>&& __rhs)
2124 const auto __size = __lhs.size() + __rhs.size();
2125 const bool __cond = (__size > __lhs.capacity()
2126 && __size <= __rhs.capacity());
2127 return __cond ? std::move(__rhs.insert(0, __lhs))
2128 : std::move(__lhs.append(__rhs));
2131 template<typename _CharT, typename _Traits, typename _Alloc,
2132 template <typename, typename, typename> class _Base>
2133 inline __versa_string<_CharT, _Traits, _Alloc, _Base>
2134 operator+(const _CharT* __lhs,
2135 __versa_string<_CharT, _Traits, _Alloc, _Base>&& __rhs)
2136 { return std::move(__rhs.insert(0, __lhs)); }
2138 template<typename _CharT, typename _Traits, typename _Alloc,
2139 template <typename, typename, typename> class _Base>
2140 inline __versa_string<_CharT, _Traits, _Alloc, _Base>
2141 operator+(_CharT __lhs,
2142 __versa_string<_CharT, _Traits, _Alloc, _Base>&& __rhs)
2143 { return std::move(__rhs.insert(0, 1, __lhs)); }
2145 template<typename _CharT, typename _Traits, typename _Alloc,
2146 template <typename, typename, typename> class _Base>
2147 inline __versa_string<_CharT, _Traits, _Alloc, _Base>
2148 operator+(__versa_string<_CharT, _Traits, _Alloc, _Base>&& __lhs,
2149 const _CharT* __rhs)
2150 { return std::move(__lhs.append(__rhs)); }
2152 template<typename _CharT, typename _Traits, typename _Alloc,
2153 template <typename, typename, typename> class _Base>
2154 inline __versa_string<_CharT, _Traits, _Alloc, _Base>
2155 operator+(__versa_string<_CharT, _Traits, _Alloc, _Base>&& __lhs,
2157 { return std::move(__lhs.append(1, __rhs)); }
2162 * @brief Test equivalence of two strings.
2163 * @param __lhs First string.
2164 * @param __rhs Second string.
2165 * @return True if @a __lhs.compare(@a __rhs) == 0. False otherwise.
2167 template<typename _CharT, typename _Traits, typename _Alloc,
2168 template <typename, typename, typename> class _Base>
2170 operator==(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2171 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2172 { return __lhs.compare(__rhs) == 0; }
2174 template<typename _CharT,
2175 template <typename, typename, typename> class _Base>
2176 inline typename __enable_if<std::__is_char<_CharT>::__value, bool>::__type
2177 operator==(const __versa_string<_CharT, std::char_traits<_CharT>,
2178 std::allocator<_CharT>, _Base>& __lhs,
2179 const __versa_string<_CharT, std::char_traits<_CharT>,
2180 std::allocator<_CharT>, _Base>& __rhs)
2181 { return (__lhs.size() == __rhs.size()
2182 && !std::char_traits<_CharT>::compare(__lhs.data(), __rhs.data(),
2186 * @brief Test equivalence of C string and string.
2187 * @param __lhs C string.
2188 * @param __rhs String.
2189 * @return True if @a __rhs.compare(@a __lhs) == 0. False otherwise.
2191 template<typename _CharT, typename _Traits, typename _Alloc,
2192 template <typename, typename, typename> class _Base>
2194 operator==(const _CharT* __lhs,
2195 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2196 { return __rhs.compare(__lhs) == 0; }
2199 * @brief Test equivalence of string and C string.
2200 * @param __lhs String.
2201 * @param __rhs C string.
2202 * @return True if @a __lhs.compare(@a __rhs) == 0. False otherwise.
2204 template<typename _CharT, typename _Traits, typename _Alloc,
2205 template <typename, typename, typename> class _Base>
2207 operator==(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2208 const _CharT* __rhs)
2209 { return __lhs.compare(__rhs) == 0; }
2213 * @brief Test difference of two strings.
2214 * @param __lhs First string.
2215 * @param __rhs Second string.
2216 * @return True if @a __lhs.compare(@a __rhs) != 0. False otherwise.
2218 template<typename _CharT, typename _Traits, typename _Alloc,
2219 template <typename, typename, typename> class _Base>
2221 operator!=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2222 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2223 { return !(__lhs == __rhs); }
2226 * @brief Test difference of C string and string.
2227 * @param __lhs C string.
2228 * @param __rhs String.
2229 * @return True if @a __rhs.compare(@a __lhs) != 0. False otherwise.
2231 template<typename _CharT, typename _Traits, typename _Alloc,
2232 template <typename, typename, typename> class _Base>
2234 operator!=(const _CharT* __lhs,
2235 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2236 { return !(__lhs == __rhs); }
2239 * @brief Test difference of string and C string.
2240 * @param __lhs String.
2241 * @param __rhs C string.
2242 * @return True if @a __lhs.compare(@a __rhs) != 0. False otherwise.
2244 template<typename _CharT, typename _Traits, typename _Alloc,
2245 template <typename, typename, typename> class _Base>
2247 operator!=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2248 const _CharT* __rhs)
2249 { return !(__lhs == __rhs); }
2253 * @brief Test if string precedes string.
2254 * @param __lhs First string.
2255 * @param __rhs Second string.
2256 * @return True if @a __lhs precedes @a __rhs. False otherwise.
2258 template<typename _CharT, typename _Traits, typename _Alloc,
2259 template <typename, typename, typename> class _Base>
2261 operator<(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2262 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2263 { return __lhs.compare(__rhs) < 0; }
2266 * @brief Test if string precedes C string.
2267 * @param __lhs String.
2268 * @param __rhs C string.
2269 * @return True if @a __lhs precedes @a __rhs. False otherwise.
2271 template<typename _CharT, typename _Traits, typename _Alloc,
2272 template <typename, typename, typename> class _Base>
2274 operator<(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2275 const _CharT* __rhs)
2276 { return __lhs.compare(__rhs) < 0; }
2279 * @brief Test if C string precedes string.
2280 * @param __lhs C string.
2281 * @param __rhs String.
2282 * @return True if @a __lhs precedes @a __rhs. False otherwise.
2284 template<typename _CharT, typename _Traits, typename _Alloc,
2285 template <typename, typename, typename> class _Base>
2287 operator<(const _CharT* __lhs,
2288 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2289 { return __rhs.compare(__lhs) > 0; }
2293 * @brief Test if string follows string.
2294 * @param __lhs First string.
2295 * @param __rhs Second string.
2296 * @return True if @a __lhs follows @a __rhs. False otherwise.
2298 template<typename _CharT, typename _Traits, typename _Alloc,
2299 template <typename, typename, typename> class _Base>
2301 operator>(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2302 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2303 { return __lhs.compare(__rhs) > 0; }
2306 * @brief Test if string follows C string.
2307 * @param __lhs String.
2308 * @param __rhs C string.
2309 * @return True if @a __lhs follows @a __rhs. False otherwise.
2311 template<typename _CharT, typename _Traits, typename _Alloc,
2312 template <typename, typename, typename> class _Base>
2314 operator>(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2315 const _CharT* __rhs)
2316 { return __lhs.compare(__rhs) > 0; }
2319 * @brief Test if C string follows string.
2320 * @param __lhs C string.
2321 * @param __rhs String.
2322 * @return True if @a __lhs follows @a __rhs. False otherwise.
2324 template<typename _CharT, typename _Traits, typename _Alloc,
2325 template <typename, typename, typename> class _Base>
2327 operator>(const _CharT* __lhs,
2328 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2329 { return __rhs.compare(__lhs) < 0; }
2333 * @brief Test if string doesn't follow string.
2334 * @param __lhs First string.
2335 * @param __rhs Second string.
2336 * @return True if @a __lhs doesn't follow @a __rhs. False otherwise.
2338 template<typename _CharT, typename _Traits, typename _Alloc,
2339 template <typename, typename, typename> class _Base>
2341 operator<=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2342 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2343 { return __lhs.compare(__rhs) <= 0; }
2346 * @brief Test if string doesn't follow C string.
2347 * @param __lhs String.
2348 * @param __rhs C string.
2349 * @return True if @a __lhs doesn't follow @a __rhs. False otherwise.
2351 template<typename _CharT, typename _Traits, typename _Alloc,
2352 template <typename, typename, typename> class _Base>
2354 operator<=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2355 const _CharT* __rhs)
2356 { return __lhs.compare(__rhs) <= 0; }
2359 * @brief Test if C string doesn't follow string.
2360 * @param __lhs C string.
2361 * @param __rhs String.
2362 * @return True if @a __lhs doesn't follow @a __rhs. False otherwise.
2364 template<typename _CharT, typename _Traits, typename _Alloc,
2365 template <typename, typename, typename> class _Base>
2367 operator<=(const _CharT* __lhs,
2368 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2369 { return __rhs.compare(__lhs) >= 0; }
2373 * @brief Test if string doesn't precede string.
2374 * @param __lhs First string.
2375 * @param __rhs Second string.
2376 * @return True if @a __lhs doesn't precede @a __rhs. False otherwise.
2378 template<typename _CharT, typename _Traits, typename _Alloc,
2379 template <typename, typename, typename> class _Base>
2381 operator>=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2382 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2383 { return __lhs.compare(__rhs) >= 0; }
2386 * @brief Test if string doesn't precede C string.
2387 * @param __lhs String.
2388 * @param __rhs C string.
2389 * @return True if @a __lhs doesn't precede @a __rhs. False otherwise.
2391 template<typename _CharT, typename _Traits, typename _Alloc,
2392 template <typename, typename, typename> class _Base>
2394 operator>=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2395 const _CharT* __rhs)
2396 { return __lhs.compare(__rhs) >= 0; }
2399 * @brief Test if C string doesn't precede string.
2400 * @param __lhs C string.
2401 * @param __rhs String.
2402 * @return True if @a __lhs doesn't precede @a __rhs. False otherwise.
2404 template<typename _CharT, typename _Traits, typename _Alloc,
2405 template <typename, typename, typename> class _Base>
2407 operator>=(const _CharT* __lhs,
2408 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2409 { return __rhs.compare(__lhs) <= 0; }
2412 * @brief Swap contents of two strings.
2413 * @param __lhs First string.
2414 * @param __rhs Second string.
2416 * Exchanges the contents of @a __lhs and @a __rhs in constant time.
2418 template<typename _CharT, typename _Traits, typename _Alloc,
2419 template <typename, typename, typename> class _Base>
2421 swap(__versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2422 __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2423 { __lhs.swap(__rhs); }
2425 _GLIBCXX_END_NAMESPACE_VERSION
2428 namespace std _GLIBCXX_VISIBILITY(default)
2430 _GLIBCXX_BEGIN_NAMESPACE_VERSION
2433 * @brief Read stream into a string.
2434 * @param __is Input stream.
2435 * @param __str Buffer to store into.
2436 * @return Reference to the input stream.
2438 * Stores characters from @a __is into @a __str until whitespace is
2439 * found, the end of the stream is encountered, or str.max_size()
2440 * is reached. If is.width() is non-zero, that is the limit on the
2441 * number of characters stored into @a __str. Any previous
2442 * contents of @a __str are erased.
2444 template<typename _CharT, typename _Traits, typename _Alloc,
2445 template <typename, typename, typename> class _Base>
2446 basic_istream<_CharT, _Traits>&
2447 operator>>(basic_istream<_CharT, _Traits>& __is,
2448 __gnu_cxx::__versa_string<_CharT, _Traits,
2449 _Alloc, _Base>& __str);
2452 * @brief Write string to a stream.
2453 * @param __os Output stream.
2454 * @param __str String to write out.
2455 * @return Reference to the output stream.
2457 * Output characters of @a __str into os following the same rules as for
2458 * writing a C string.
2460 template<typename _CharT, typename _Traits, typename _Alloc,
2461 template <typename, typename, typename> class _Base>
2462 inline basic_ostream<_CharT, _Traits>&
2463 operator<<(basic_ostream<_CharT, _Traits>& __os,
2464 const __gnu_cxx::__versa_string<_CharT, _Traits, _Alloc,
2467 // _GLIBCXX_RESOLVE_LIB_DEFECTS
2468 // 586. string inserter not a formatted function
2469 return __ostream_insert(__os, __str.data(), __str.size());
2473 * @brief Read a line from stream into a string.
2474 * @param __is Input stream.
2475 * @param __str Buffer to store into.
2476 * @param __delim Character marking end of line.
2477 * @return Reference to the input stream.
2479 * Stores characters from @a __is into @a __str until @a __delim is
2480 * found, the end of the stream is encountered, or str.max_size()
2481 * is reached. If is.width() is non-zero, that is the limit on the
2482 * number of characters stored into @a __str. Any previous
2483 * contents of @a __str are erased. If @a delim was encountered,
2484 * it is extracted but not stored into @a __str.
2486 template<typename _CharT, typename _Traits, typename _Alloc,
2487 template <typename, typename, typename> class _Base>
2488 basic_istream<_CharT, _Traits>&
2489 getline(basic_istream<_CharT, _Traits>& __is,
2490 __gnu_cxx::__versa_string<_CharT, _Traits, _Alloc, _Base>& __str,
2494 * @brief Read a line from stream into a string.
2495 * @param __is Input stream.
2496 * @param __str Buffer to store into.
2497 * @return Reference to the input stream.
2499 * Stores characters from is into @a __str until '\n' is
2500 * found, the end of the stream is encountered, or str.max_size()
2501 * is reached. If is.width() is non-zero, that is the limit on the
2502 * number of characters stored into @a __str. Any previous
2503 * contents of @a __str are erased. If end of line was
2504 * encountered, it is extracted but not stored into @a __str.
2506 template<typename _CharT, typename _Traits, typename _Alloc,
2507 template <typename, typename, typename> class _Base>
2508 inline basic_istream<_CharT, _Traits>&
2509 getline(basic_istream<_CharT, _Traits>& __is,
2510 __gnu_cxx::__versa_string<_CharT, _Traits, _Alloc, _Base>& __str)
2511 { return getline(__is, __str, __is.widen('\n')); }
2513 _GLIBCXX_END_NAMESPACE_VERSION
2516 #if (defined(__GXX_EXPERIMENTAL_CXX0X__) && defined(_GLIBCXX_USE_C99))
2518 #include <ext/string_conversions.h>
2520 namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
2522 _GLIBCXX_BEGIN_NAMESPACE_VERSION
2524 // 21.4 Numeric Conversions [string.conversions].
2526 stoi(const __vstring& __str, std::size_t* __idx = 0, int __base = 10)
2527 { return __gnu_cxx::__stoa<long, int>(&std::strtol, "stoi", __str.c_str(),
2531 stol(const __vstring& __str, std::size_t* __idx = 0, int __base = 10)
2532 { return __gnu_cxx::__stoa(&std::strtol, "stol", __str.c_str(),
2535 inline unsigned long
2536 stoul(const __vstring& __str, std::size_t* __idx = 0, int __base = 10)
2537 { return __gnu_cxx::__stoa(&std::strtoul, "stoul", __str.c_str(),
2541 stoll(const __vstring& __str, std::size_t* __idx = 0, int __base = 10)
2542 { return __gnu_cxx::__stoa(&std::strtoll, "stoll", __str.c_str(),
2545 inline unsigned long long
2546 stoull(const __vstring& __str, std::size_t* __idx, int __base = 10)
2547 { return __gnu_cxx::__stoa(&std::strtoull, "stoull", __str.c_str(),
2550 // NB: strtof vs strtod.
2552 stof(const __vstring& __str, std::size_t* __idx = 0)
2553 { return __gnu_cxx::__stoa(&std::strtof, "stof", __str.c_str(), __idx); }
2556 stod(const __vstring& __str, std::size_t* __idx = 0)
2557 { return __gnu_cxx::__stoa(&std::strtod, "stod", __str.c_str(), __idx); }
2560 stold(const __vstring& __str, std::size_t* __idx = 0)
2561 { return __gnu_cxx::__stoa(&std::strtold, "stold", __str.c_str(), __idx); }
2563 // NB: (v)snprintf vs sprintf.
2567 to_string(int __val)
2568 { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, 4 * sizeof(int),
2572 to_string(unsigned __val)
2573 { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf,
2574 4 * sizeof(unsigned),
2578 to_string(long __val)
2579 { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf,
2584 to_string(unsigned long __val)
2585 { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf,
2586 4 * sizeof(unsigned long),
2591 to_string(long long __val)
2592 { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf,
2593 4 * sizeof(long long),
2597 to_string(unsigned long long __val)
2598 { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf,
2599 4 * sizeof(unsigned long long),
2603 to_string(float __val)
2605 const int __n = __numeric_traits<float>::__max_exponent10 + 20;
2606 return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, __n,
2611 to_string(double __val)
2613 const int __n = __numeric_traits<double>::__max_exponent10 + 20;
2614 return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, __n,
2619 to_string(long double __val)
2621 const int __n = __numeric_traits<long double>::__max_exponent10 + 20;
2622 return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, __n,
2626 #ifdef _GLIBCXX_USE_WCHAR_T
2628 stoi(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10)
2629 { return __gnu_cxx::__stoa<long, int>(&std::wcstol, "stoi", __str.c_str(),
2633 stol(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10)
2634 { return __gnu_cxx::__stoa(&std::wcstol, "stol", __str.c_str(),
2637 inline unsigned long
2638 stoul(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10)
2639 { return __gnu_cxx::__stoa(&std::wcstoul, "stoul", __str.c_str(),
2643 stoll(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10)
2644 { return __gnu_cxx::__stoa(&std::wcstoll, "stoll", __str.c_str(),
2647 inline unsigned long long
2648 stoull(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10)
2649 { return __gnu_cxx::__stoa(&std::wcstoull, "stoull", __str.c_str(),
2652 // NB: wcstof vs wcstod.
2654 stof(const __wvstring& __str, std::size_t* __idx = 0)
2655 { return __gnu_cxx::__stoa(&std::wcstof, "stof", __str.c_str(), __idx); }
2658 stod(const __wvstring& __str, std::size_t* __idx = 0)
2659 { return __gnu_cxx::__stoa(&std::wcstod, "stod", __str.c_str(), __idx); }
2662 stold(const __wvstring& __str, std::size_t* __idx = 0)
2663 { return __gnu_cxx::__stoa(&std::wcstold, "stold", __str.c_str(), __idx); }
2665 #ifndef _GLIBCXX_HAVE_BROKEN_VSWPRINTF
2668 to_wstring(int __val)
2669 { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
2674 to_wstring(unsigned __val)
2675 { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
2676 4 * sizeof(unsigned),
2680 to_wstring(long __val)
2681 { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
2686 to_wstring(unsigned long __val)
2687 { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
2688 4 * sizeof(unsigned long),
2692 to_wstring(long long __val)
2693 { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
2694 4 * sizeof(long long),
2698 to_wstring(unsigned long long __val)
2699 { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
2700 4 * sizeof(unsigned long long),
2704 to_wstring(float __val)
2706 const int __n = __numeric_traits<float>::__max_exponent10 + 20;
2707 return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, __n,
2712 to_wstring(double __val)
2714 const int __n = __numeric_traits<double>::__max_exponent10 + 20;
2715 return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, __n,
2720 to_wstring(long double __val)
2722 const int __n = __numeric_traits<long double>::__max_exponent10 + 20;
2723 return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, __n,
2729 _GLIBCXX_END_NAMESPACE_VERSION
2734 #ifdef __GXX_EXPERIMENTAL_CXX0X__
2736 #include <bits/functional_hash.h>
2738 namespace std _GLIBCXX_VISIBILITY(default)
2740 _GLIBCXX_BEGIN_NAMESPACE_VERSION
2742 /// std::hash specialization for __vstring.
2744 struct hash<__gnu_cxx::__vstring>
2745 : public __hash_base<size_t, __gnu_cxx::__vstring>
2748 operator()(const __gnu_cxx::__vstring& __s) const
2749 { return std::_Hash_impl::hash(__s.data(), __s.length()); }
2752 #ifdef _GLIBCXX_USE_WCHAR_T
2753 /// std::hash specialization for __wvstring.
2755 struct hash<__gnu_cxx::__wvstring>
2756 : public __hash_base<size_t, __gnu_cxx::__wvstring>
2759 operator()(const __gnu_cxx::__wvstring& __s) const
2760 { return std::_Hash_impl::hash(__s.data(),
2761 __s.length() * sizeof(wchar_t)); }
2765 #ifdef _GLIBCXX_USE_C99_STDINT_TR1
2766 /// std::hash specialization for __u16vstring.
2768 struct hash<__gnu_cxx::__u16vstring>
2769 : public __hash_base<size_t, __gnu_cxx::__u16vstring>
2772 operator()(const __gnu_cxx::__u16vstring& __s) const
2773 { return std::_Hash_impl::hash(__s.data(),
2774 __s.length() * sizeof(char16_t)); }
2777 /// std::hash specialization for __u32vstring.
2779 struct hash<__gnu_cxx::__u32vstring>
2780 : public __hash_base<size_t, __gnu_cxx::__u32vstring>
2783 operator()(const __gnu_cxx::__u32vstring& __s) const
2784 { return std::_Hash_impl::hash(__s.data(),
2785 __s.length() * sizeof(char32_t)); }
2789 _GLIBCXX_END_NAMESPACE_VERSION
2792 #endif /* __GXX_EXPERIMENTAL_CXX0X__ */
2794 #include "vstring.tcc"
2796 #endif /* _VSTRING_H */