1 // Versatile string -*- C++ -*-
3 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010
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 _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
43 * @class __versa_string vstring.h
44 * @brief Managing sequences of characters and character-like objects.
47 // Template class __versa_string
48 template<typename _CharT, typename _Traits, typename _Alloc,
49 template <typename, typename, typename> class _Base>
51 : private _Base<_CharT, _Traits, _Alloc>
53 typedef _Base<_CharT, _Traits, _Alloc> __vstring_base;
54 typedef typename __vstring_base::_CharT_alloc_type _CharT_alloc_type;
58 typedef _Traits traits_type;
59 typedef typename _Traits::char_type value_type;
60 typedef _Alloc allocator_type;
61 typedef typename _CharT_alloc_type::size_type size_type;
62 typedef typename _CharT_alloc_type::difference_type difference_type;
63 typedef typename _CharT_alloc_type::reference reference;
64 typedef typename _CharT_alloc_type::const_reference const_reference;
65 typedef typename _CharT_alloc_type::pointer pointer;
66 typedef typename _CharT_alloc_type::const_pointer const_pointer;
67 typedef __gnu_cxx::__normal_iterator<pointer, __versa_string> iterator;
68 typedef __gnu_cxx::__normal_iterator<const_pointer, __versa_string>
70 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
71 typedef std::reverse_iterator<iterator> reverse_iterator;
73 // Data Member (public):
74 /// Value returned by various member functions when they fail.
75 static const size_type npos = static_cast<size_type>(-1);
79 _M_check(size_type __pos, const char* __s) const
81 if (__pos > this->size())
82 std::__throw_out_of_range(__N(__s));
87 _M_check_length(size_type __n1, size_type __n2, const char* __s) const
89 if (this->max_size() - (this->size() - __n1) < __n2)
90 std::__throw_length_error(__N(__s));
93 // NB: _M_limit doesn't check for a bad __pos value.
95 _M_limit(size_type __pos, size_type __off) const
97 const bool __testoff = __off < this->size() - __pos;
98 return __testoff ? __off : this->size() - __pos;
101 // True if _Rep and source do not overlap.
103 _M_disjunct(const _CharT* __s) const
105 return (std::less<const _CharT*>()(__s, this->_M_data())
106 || std::less<const _CharT*>()(this->_M_data()
107 + this->size(), __s));
110 // For the internal use we have functions similar to `begin'/`end'
111 // but they do not call _M_leak.
114 { return iterator(this->_M_data()); }
118 { return iterator(this->_M_data() + this->_M_length()); }
121 // Construct/copy/destroy:
122 // NB: We overload ctors in some cases instead of using default
123 // arguments, per 17.4.4.4 para. 2 item 2.
126 * @brief Default constructor creates an empty string.
129 : __vstring_base() { }
132 * @brief Construct an empty string using allocator @a a.
135 __versa_string(const _Alloc& __a)
136 : __vstring_base(__a) { }
138 // NB: per LWG issue 42, semantics different from IS:
140 * @brief Construct string with copy of value of @a str.
141 * @param __str Source string.
143 __versa_string(const __versa_string& __str)
144 : __vstring_base(__str) { }
146 #ifdef __GXX_EXPERIMENTAL_CXX0X__
148 * @brief String move constructor.
149 * @param __str Source string.
151 * The newly-constructed %string contains the exact contents of
152 * @a str. The contents of @a str are a valid, but unspecified
155 __versa_string(__versa_string&& __str)
156 : __vstring_base(std::forward<__vstring_base>(__str)) { }
159 * @brief Construct string from an initializer list.
160 * @param __l std::initializer_list of characters.
161 * @param __a Allocator to use (default is default allocator).
163 __versa_string(std::initializer_list<_CharT> __l,
164 const _Alloc& __a = _Alloc())
165 : __vstring_base(__l.begin(), __l.end(), __a) { }
169 * @brief Construct string as copy of a substring.
170 * @param __str Source string.
171 * @param __pos Index of first character to copy from.
172 * @param __n Number of characters to copy (default remainder).
174 __versa_string(const __versa_string& __str, size_type __pos,
175 size_type __n = npos)
176 : __vstring_base(__str._M_data()
177 + __str._M_check(__pos,
178 "__versa_string::__versa_string"),
179 __str._M_data() + __str._M_limit(__pos, __n)
180 + __pos, _Alloc()) { }
183 * @brief Construct string as copy of a substring.
184 * @param __str Source string.
185 * @param __pos Index of first character to copy from.
186 * @param __n Number of characters to copy.
187 * @param __a Allocator to use.
189 __versa_string(const __versa_string& __str, size_type __pos,
190 size_type __n, const _Alloc& __a)
191 : __vstring_base(__str._M_data()
192 + __str._M_check(__pos,
193 "__versa_string::__versa_string"),
194 __str._M_data() + __str._M_limit(__pos, __n)
198 * @brief Construct string initialized by a character array.
199 * @param __s Source character array.
200 * @param __n Number of characters to copy.
201 * @param __a Allocator to use (default is default allocator).
203 * NB: @a __s must have at least @a __n characters, '\\0' has no special
206 __versa_string(const _CharT* __s, size_type __n,
207 const _Alloc& __a = _Alloc())
208 : __vstring_base(__s, __s + __n, __a) { }
211 * @brief Construct string as copy of a C string.
212 * @param __s Source C string.
213 * @param __a Allocator to use (default is default allocator).
215 __versa_string(const _CharT* __s, const _Alloc& __a = _Alloc())
216 : __vstring_base(__s, __s ? __s + traits_type::length(__s) :
220 * @brief Construct string as multiple characters.
221 * @param __n Number of characters.
222 * @param __c Character to use.
223 * @param __a Allocator to use (default is default allocator).
225 __versa_string(size_type __n, _CharT __c, const _Alloc& __a = _Alloc())
226 : __vstring_base(__n, __c, __a) { }
229 * @brief Construct string as copy of a range.
230 * @param __beg Start of range.
231 * @param __end End of range.
232 * @param __a Allocator to use (default is default allocator).
234 template<class _InputIterator>
235 __versa_string(_InputIterator __beg, _InputIterator __end,
236 const _Alloc& __a = _Alloc())
237 : __vstring_base(__beg, __end, __a) { }
240 * @brief Destroy the string instance.
242 ~__versa_string() { }
245 * @brief Assign the value of @a str to this string.
246 * @param __str Source string.
249 operator=(const __versa_string& __str)
250 { return this->assign(__str); }
252 #ifdef __GXX_EXPERIMENTAL_CXX0X__
254 * @brief String move assignment operator.
255 * @param __str Source string.
257 * The contents of @a __str are moved into this string (without
258 * copying). @a __str is a valid, but unspecified string.
261 operator=(__versa_string&& __str)
272 * @brief Set value to string constructed from initializer list.
273 * @param __l std::initializer_list.
276 operator=(std::initializer_list<_CharT> __l)
278 this->assign(__l.begin(), __l.end());
284 * @brief Copy contents of @a __s into this string.
285 * @param __s Source null-terminated string.
288 operator=(const _CharT* __s)
289 { return this->assign(__s); }
292 * @brief Set value to string of length 1.
293 * @param __c Source character.
295 * Assigning to a character makes this string length 1 and
296 * (*this)[0] == @a __c.
299 operator=(_CharT __c)
301 this->assign(1, __c);
307 * Returns a read/write iterator that points to the first character in
308 * the %string. Unshares the string.
314 return iterator(this->_M_data());
318 * Returns a read-only (constant) iterator that points to the first
319 * character in the %string.
323 { return const_iterator(this->_M_data()); }
326 * Returns a read/write iterator that points one past the last
327 * character in the %string. Unshares the string.
333 return iterator(this->_M_data() + this->size());
337 * Returns a read-only (constant) iterator that points one past the
338 * last character in the %string.
342 { return const_iterator(this->_M_data() + this->size()); }
345 * Returns a read/write reverse iterator that points to the last
346 * character in the %string. Iteration is done in reverse element
347 * order. Unshares the string.
351 { return reverse_iterator(this->end()); }
354 * Returns a read-only (constant) reverse iterator that points
355 * to the last character in the %string. Iteration is done in
356 * reverse element order.
358 const_reverse_iterator
360 { return const_reverse_iterator(this->end()); }
363 * Returns a read/write reverse iterator that points to one before the
364 * first character in the %string. Iteration is done in reverse
365 * element order. Unshares the string.
369 { return reverse_iterator(this->begin()); }
372 * Returns a read-only (constant) reverse iterator that points
373 * to one before the first character in the %string. Iteration
374 * is done in reverse element order.
376 const_reverse_iterator
378 { return const_reverse_iterator(this->begin()); }
380 #ifdef __GXX_EXPERIMENTAL_CXX0X__
382 * Returns a read-only (constant) iterator that points to the first
383 * character in the %string.
387 { return const_iterator(this->_M_data()); }
390 * Returns a read-only (constant) iterator that points one past the
391 * last character in the %string.
395 { return const_iterator(this->_M_data() + this->size()); }
398 * Returns a read-only (constant) reverse iterator that points
399 * to the last character in the %string. Iteration is done in
400 * reverse element order.
402 const_reverse_iterator
404 { return const_reverse_iterator(this->end()); }
407 * Returns a read-only (constant) reverse iterator that points
408 * to one before the first character in the %string. Iteration
409 * is done in reverse element order.
411 const_reverse_iterator
413 { return const_reverse_iterator(this->begin()); }
418 /// Returns the number of characters in the string, not including any
419 /// null-termination.
422 { return this->_M_length(); }
424 /// Returns the number of characters in the string, not including any
425 /// null-termination.
428 { return this->_M_length(); }
430 /// Returns the size() of the largest possible %string.
433 { return this->_M_max_size(); }
436 * @brief Resizes the %string to the specified number of characters.
437 * @param __n Number of characters the %string should contain.
438 * @param __c Character to fill any new elements.
440 * This function will %resize the %string to the specified
441 * number of characters. If the number is smaller than the
442 * %string's current size the %string is truncated, otherwise
443 * the %string is extended and new elements are set to @a __c.
446 resize(size_type __n, _CharT __c);
449 * @brief Resizes the %string to the specified number of characters.
450 * @param __n Number of characters the %string should contain.
452 * This function will resize the %string to the specified
453 * length. If the new size is smaller than the %string's
454 * current size the %string is truncated, otherwise the %string
455 * is extended and new characters are default-constructed. For
456 * basic types such as char, this means setting them to 0.
459 resize(size_type __n)
460 { this->resize(__n, _CharT()); }
462 #ifdef __GXX_EXPERIMENTAL_CXX0X__
463 /// A non-binding request to reduce capacity() to size().
468 { this->reserve(0); }
475 * Returns the total number of characters that the %string can
476 * hold before needing to allocate more memory.
480 { return this->_M_capacity(); }
483 * @brief Attempt to preallocate enough memory for specified number of
485 * @param __res_arg Number of characters required.
486 * @throw std::length_error If @a __res_arg exceeds @c max_size().
488 * This function attempts to reserve enough memory for the
489 * %string to hold the specified number of characters. If the
490 * number requested is more than max_size(), length_error is
493 * The advantage of this function is that if optimal code is a
494 * necessity and the user can determine the string length that
495 * will be required, the user can reserve the memory in
496 * %advance, and thus prevent a possible reallocation of memory
497 * and copying of %string data.
500 reserve(size_type __res_arg = 0)
501 { this->_M_reserve(__res_arg); }
504 * Erases the string, making it empty.
508 { this->_M_clear(); }
511 * Returns true if the %string is empty. Equivalent to *this == "".
515 { return this->size() == 0; }
519 * @brief Subscript access to the data contained in the %string.
520 * @param __pos The index of the character to access.
521 * @return Read-only (constant) reference to the character.
523 * This operator allows for easy, array-style, data access.
524 * Note that data access with this operator is unchecked and
525 * out_of_range lookups are not defined. (For checked lookups
529 operator[] (size_type __pos) const
531 _GLIBCXX_DEBUG_ASSERT(__pos <= this->size());
532 return this->_M_data()[__pos];
536 * @brief Subscript access to the data contained in the %string.
537 * @param __pos The index of the character to access.
538 * @return Read/write reference to the character.
540 * This operator allows for easy, array-style, data access.
541 * Note that data access with this operator is unchecked and
542 * out_of_range lookups are not defined. (For checked lookups
543 * see at().) Unshares the string.
546 operator[](size_type __pos)
548 // allow pos == size() as v3 extension:
549 _GLIBCXX_DEBUG_ASSERT(__pos <= this->size());
550 // but be strict in pedantic mode:
551 _GLIBCXX_DEBUG_PEDASSERT(__pos < this->size());
553 return this->_M_data()[__pos];
557 * @brief Provides access to the data contained in the %string.
558 * @param __n The index of the character to access.
559 * @return Read-only (const) reference to the character.
560 * @throw std::out_of_range If @a __n is an invalid index.
562 * This function provides for safer data access. The parameter
563 * is first checked that it is in the range of the string. The
564 * function throws out_of_range if the check fails.
567 at(size_type __n) const
569 if (__n >= this->size())
570 std::__throw_out_of_range(__N("__versa_string::at"));
571 return this->_M_data()[__n];
575 * @brief Provides access to the data contained in the %string.
576 * @param __n The index of the character to access.
577 * @return Read/write reference to the character.
578 * @throw std::out_of_range If @a __n is an invalid index.
580 * This function provides for safer data access. The parameter
581 * is first checked that it is in the range of the string. The
582 * function throws out_of_range if the check fails. Success
583 * results in unsharing the string.
588 if (__n >= this->size())
589 std::__throw_out_of_range(__N("__versa_string::at"));
591 return this->_M_data()[__n];
594 #ifdef __GXX_EXPERIMENTAL_CXX0X__
596 * Returns a read/write reference to the data at the first
597 * element of the %string.
604 * Returns a read-only (constant) reference to the data at the first
605 * element of the %string.
612 * Returns a read/write reference to the data at the last
613 * element of the %string.
617 { return *(end() - 1); }
620 * Returns a read-only (constant) reference to the data at the
621 * last element of the %string.
625 { return *(end() - 1); }
630 * @brief Append a string to this string.
631 * @param __str The string to append.
632 * @return Reference to this string.
635 operator+=(const __versa_string& __str)
636 { return this->append(__str); }
639 * @brief Append a C string.
640 * @param __s The C string to append.
641 * @return Reference to this string.
644 operator+=(const _CharT* __s)
645 { return this->append(__s); }
648 * @brief Append a character.
649 * @param __c The character to append.
650 * @return Reference to this string.
653 operator+=(_CharT __c)
655 this->push_back(__c);
659 #ifdef __GXX_EXPERIMENTAL_CXX0X__
661 * @brief Append an initializer_list of characters.
662 * @param __l The initializer_list of characters to be appended.
663 * @return Reference to this string.
666 operator+=(std::initializer_list<_CharT> __l)
667 { return this->append(__l.begin(), __l.end()); }
668 #endif // __GXX_EXPERIMENTAL_CXX0X__
671 * @brief Append a string to this string.
672 * @param __str The string to append.
673 * @return Reference to this string.
676 append(const __versa_string& __str)
677 { return _M_append(__str._M_data(), __str.size()); }
680 * @brief Append a substring.
681 * @param __str The string to append.
682 * @param __pos Index of the first character of str to append.
683 * @param __n The number of characters to append.
684 * @return Reference to this string.
685 * @throw std::out_of_range if @a pos is not a valid index.
687 * This function appends @a __n characters from @a __str
688 * starting at @a __pos to this string. If @a __n is is larger
689 * than the number of available characters in @a __str, the
690 * remainder of @a __str is appended.
693 append(const __versa_string& __str, size_type __pos, size_type __n)
694 { return _M_append(__str._M_data()
695 + __str._M_check(__pos, "__versa_string::append"),
696 __str._M_limit(__pos, __n)); }
699 * @brief Append a C substring.
700 * @param __s The C string to append.
701 * @param __n The number of characters to append.
702 * @return Reference to this string.
705 append(const _CharT* __s, size_type __n)
707 __glibcxx_requires_string_len(__s, __n);
708 _M_check_length(size_type(0), __n, "__versa_string::append");
709 return _M_append(__s, __n);
713 * @brief Append a C string.
714 * @param __s The C string to append.
715 * @return Reference to this string.
718 append(const _CharT* __s)
720 __glibcxx_requires_string(__s);
721 const size_type __n = traits_type::length(__s);
722 _M_check_length(size_type(0), __n, "__versa_string::append");
723 return _M_append(__s, __n);
727 * @brief Append multiple characters.
728 * @param __n The number of characters to append.
729 * @param __c The character to use.
730 * @return Reference to this string.
732 * Appends n copies of c to this string.
735 append(size_type __n, _CharT __c)
736 { return _M_replace_aux(this->size(), size_type(0), __n, __c); }
738 #ifdef __GXX_EXPERIMENTAL_CXX0X__
740 * @brief Append an initializer_list of characters.
741 * @param __l The initializer_list of characters to append.
742 * @return Reference to this string.
745 append(std::initializer_list<_CharT> __l)
746 { return this->append(__l.begin(), __l.end()); }
747 #endif // __GXX_EXPERIMENTAL_CXX0X__
750 * @brief Append a range of characters.
751 * @param __first Iterator referencing the first character to append.
752 * @param __last Iterator marking the end of the range.
753 * @return Reference to this string.
755 * Appends characters in the range [first,last) to this string.
757 template<class _InputIterator>
759 append(_InputIterator __first, _InputIterator __last)
760 { return this->replace(_M_iend(), _M_iend(), __first, __last); }
763 * @brief Append a single character.
764 * @param __c Character to append.
767 push_back(_CharT __c)
769 const size_type __size = this->size();
770 if (__size + 1 > this->capacity() || this->_M_is_shared())
771 this->_M_mutate(__size, size_type(0), 0, size_type(1));
772 traits_type::assign(this->_M_data()[__size], __c);
773 this->_M_set_length(__size + 1);
777 * @brief Set value to contents of another string.
778 * @param __str Source string to use.
779 * @return Reference to this string.
782 assign(const __versa_string& __str)
784 this->_M_assign(__str);
789 * @brief Set value to a substring of a string.
790 * @param __str The string to use.
791 * @param __pos Index of the first character of str.
792 * @param __n Number of characters to use.
793 * @return Reference to this string.
794 * @throw std::out_of_range if @a __pos is not a valid index.
796 * This function sets this string to the substring of @a __str
797 * consisting of @a __n characters at @a __pos. If @a __n is
798 * is larger than the number of available characters in @a
799 * __str, the remainder of @a __str is used.
802 assign(const __versa_string& __str, size_type __pos, size_type __n)
803 { return _M_replace(size_type(0), this->size(), __str._M_data()
804 + __str._M_check(__pos, "__versa_string::assign"),
805 __str._M_limit(__pos, __n)); }
808 * @brief Set value to a C substring.
809 * @param __s The C string to use.
810 * @param __n Number of characters to use.
811 * @return Reference to this string.
813 * This function sets the value of this string to the first @a
814 * __n characters of @a __s. If @a __n is is larger than the
815 * number of available characters in @a __s, the remainder of
819 assign(const _CharT* __s, size_type __n)
821 __glibcxx_requires_string_len(__s, __n);
822 return _M_replace(size_type(0), this->size(), __s, __n);
826 * @brief Set value to contents of a C string.
827 * @param __s The C string to use.
828 * @return Reference to this string.
830 * This function sets the value of this string to the value of
831 * @a __s. The data is copied, so there is no dependence on @a
832 * __s once the function returns.
835 assign(const _CharT* __s)
837 __glibcxx_requires_string(__s);
838 return _M_replace(size_type(0), this->size(), __s,
839 traits_type::length(__s));
843 * @brief Set value to multiple characters.
844 * @param __n Length of the resulting string.
845 * @param __c The character to use.
846 * @return Reference to this string.
848 * This function sets the value of this string to @a __n copies of
852 assign(size_type __n, _CharT __c)
853 { return _M_replace_aux(size_type(0), this->size(), __n, __c); }
856 * @brief Set value to a range of characters.
857 * @param __first Iterator referencing the first character to append.
858 * @param __last Iterator marking the end of the range.
859 * @return Reference to this string.
861 * Sets value of string to characters in the range
864 template<class _InputIterator>
866 assign(_InputIterator __first, _InputIterator __last)
867 { return this->replace(_M_ibegin(), _M_iend(), __first, __last); }
869 #ifdef __GXX_EXPERIMENTAL_CXX0X__
871 * @brief Set value to an initializer_list of characters.
872 * @param __l The initializer_list of characters to assign.
873 * @return Reference to this string.
876 assign(std::initializer_list<_CharT> __l)
877 { return this->assign(__l.begin(), __l.end()); }
878 #endif // __GXX_EXPERIMENTAL_CXX0X__
881 * @brief Insert multiple characters.
882 * @param __p Iterator referencing location in string to insert at.
883 * @param __n Number of characters to insert
884 * @param __c The character to insert.
885 * @throw std::length_error If new length exceeds @c max_size().
887 * Inserts @a __n copies of character @a __c starting at the
888 * position referenced by iterator @a __p. If adding
889 * characters causes the length to exceed max_size(),
890 * length_error is thrown. The value of the string doesn't
891 * change if an error is thrown.
894 insert(iterator __p, size_type __n, _CharT __c)
895 { this->replace(__p, __p, __n, __c); }
898 * @brief Insert a range of characters.
899 * @param __p Iterator referencing location in string to insert at.
900 * @param __beg Start of range.
901 * @param __end End of range.
902 * @throw std::length_error If new length exceeds @c max_size().
904 * Inserts characters in range [beg,end). If adding characters
905 * causes the length to exceed max_size(), length_error is
906 * thrown. The value of the string doesn't change if an error
909 template<class _InputIterator>
911 insert(iterator __p, _InputIterator __beg, _InputIterator __end)
912 { this->replace(__p, __p, __beg, __end); }
914 #ifdef __GXX_EXPERIMENTAL_CXX0X__
916 * @brief Insert an initializer_list of characters.
917 * @param __p Iterator referencing location in string to insert at.
918 * @param __l The initializer_list of characters to insert.
919 * @throw std::length_error If new length exceeds @c max_size().
922 insert(iterator __p, std::initializer_list<_CharT> __l)
923 { this->insert(__p, __l.begin(), __l.end()); }
924 #endif // __GXX_EXPERIMENTAL_CXX0X__
927 * @brief Insert value of a string.
928 * @param __pos1 Iterator referencing location in string to insert at.
929 * @param __str The string to insert.
930 * @return Reference to this string.
931 * @throw std::length_error If new length exceeds @c max_size().
933 * Inserts value of @a __str starting at @a __pos1. If adding
934 * characters causes the length to exceed max_size(),
935 * length_error is thrown. The value of the string doesn't
936 * change if an error is thrown.
939 insert(size_type __pos1, const __versa_string& __str)
940 { return this->replace(__pos1, size_type(0),
941 __str._M_data(), __str.size()); }
944 * @brief Insert a substring.
945 * @param __pos1 Iterator referencing location in string to insert at.
946 * @param __str The string to insert.
947 * @param __pos2 Start of characters in str to insert.
948 * @param __n Number of characters to insert.
949 * @return Reference to this string.
950 * @throw std::length_error If new length exceeds @c max_size().
951 * @throw std::out_of_range If @a __pos1 > size() or
952 * @a __pos2 > @a __str.size().
954 * Starting at @a __pos1, insert @a __n character of @a __str
955 * beginning with @a __pos2. If adding characters causes the
956 * length to exceed max_size(), length_error is thrown. If @a
957 * __pos1 is beyond the end of this string or @a __pos2 is
958 * beyond the end of @a __str, out_of_range is thrown. The
959 * value of the string doesn't change if an error is thrown.
962 insert(size_type __pos1, const __versa_string& __str,
963 size_type __pos2, size_type __n)
964 { return this->replace(__pos1, size_type(0), __str._M_data()
965 + __str._M_check(__pos2, "__versa_string::insert"),
966 __str._M_limit(__pos2, __n)); }
969 * @brief Insert a C substring.
970 * @param __pos Iterator referencing location in string to insert at.
971 * @param __s The C string to insert.
972 * @param __n The number of characters to insert.
973 * @return Reference to this string.
974 * @throw std::length_error If new length exceeds @c max_size().
975 * @throw std::out_of_range If @a __pos is beyond the end of this
978 * Inserts the first @a __n characters of @a __s starting at @a
979 * __pos. If adding characters causes the length to exceed
980 * max_size(), length_error is thrown. If @a __pos is beyond
981 * end(), out_of_range is thrown. The value of the string
982 * doesn't change if an error is thrown.
985 insert(size_type __pos, const _CharT* __s, size_type __n)
986 { return this->replace(__pos, size_type(0), __s, __n); }
989 * @brief Insert a C string.
990 * @param __pos Iterator referencing location in string to insert at.
991 * @param __s The C string 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)
1006 __glibcxx_requires_string(__s);
1007 return this->replace(__pos, size_type(0), __s,
1008 traits_type::length(__s));
1012 * @brief Insert multiple characters.
1013 * @param __pos Index in string to insert at.
1014 * @param __n Number of characters to insert
1015 * @param __c The character to insert.
1016 * @return Reference to this string.
1017 * @throw std::length_error If new length exceeds @c max_size().
1018 * @throw std::out_of_range If @a __pos is beyond the end of this
1021 * Inserts @a __n copies of character @a __c starting at index
1022 * @a __pos. If adding characters causes the length to exceed
1023 * max_size(), length_error is thrown. If @a __pos > length(),
1024 * out_of_range is thrown. The value of the string doesn't
1025 * change if an error is thrown.
1028 insert(size_type __pos, size_type __n, _CharT __c)
1029 { return _M_replace_aux(_M_check(__pos, "__versa_string::insert"),
1030 size_type(0), __n, __c); }
1033 * @brief Insert one character.
1034 * @param __p Iterator referencing position in string to insert at.
1035 * @param __c The character to insert.
1036 * @return Iterator referencing newly inserted char.
1037 * @throw std::length_error If new length exceeds @c max_size().
1039 * Inserts character @a __c at position referenced by @a __p.
1040 * If adding character causes the length to exceed max_size(),
1041 * length_error is thrown. If @a __p is beyond end of string,
1042 * out_of_range is thrown. The value of the string doesn't
1043 * change if an error is thrown.
1046 insert(iterator __p, _CharT __c)
1048 _GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend());
1049 const size_type __pos = __p - _M_ibegin();
1050 _M_replace_aux(__pos, size_type(0), size_type(1), __c);
1051 this->_M_set_leaked();
1052 return iterator(this->_M_data() + __pos);
1056 * @brief Remove characters.
1057 * @param __pos Index of first character to remove (default 0).
1058 * @param __n Number of characters to remove (default remainder).
1059 * @return Reference to this string.
1060 * @throw std::out_of_range If @a __pos is beyond the end of this
1063 * Removes @a __n characters from this string starting at @a
1064 * __pos. The length of the string is reduced by @a __n. If
1065 * there are < @a __n characters to remove, the remainder of
1066 * the string is truncated. If @a __p is beyond end of string,
1067 * out_of_range is thrown. The value of the string doesn't
1068 * change if an error is thrown.
1071 erase(size_type __pos = 0, size_type __n = npos)
1073 this->_M_erase(_M_check(__pos, "__versa_string::erase"),
1074 _M_limit(__pos, __n));
1079 * @brief Remove one character.
1080 * @param __position Iterator referencing the character to remove.
1081 * @return iterator referencing same location after removal.
1083 * Removes the character at @a __position from this string. The
1084 * value of the string doesn't change if an error is thrown.
1087 erase(iterator __position)
1089 _GLIBCXX_DEBUG_PEDASSERT(__position >= _M_ibegin()
1090 && __position < _M_iend());
1091 const size_type __pos = __position - _M_ibegin();
1092 this->_M_erase(__pos, size_type(1));
1093 this->_M_set_leaked();
1094 return iterator(this->_M_data() + __pos);
1098 * @brief Remove a range of characters.
1099 * @param __first Iterator referencing the first character to remove.
1100 * @param __last Iterator referencing the end of the range.
1101 * @return Iterator referencing location of first after removal.
1103 * Removes the characters in the range [first,last) from this
1104 * string. The value of the string doesn't change if an error
1108 erase(iterator __first, iterator __last)
1110 _GLIBCXX_DEBUG_PEDASSERT(__first >= _M_ibegin() && __first <= __last
1111 && __last <= _M_iend());
1112 const size_type __pos = __first - _M_ibegin();
1113 this->_M_erase(__pos, __last - __first);
1114 this->_M_set_leaked();
1115 return iterator(this->_M_data() + __pos);
1119 * @brief Replace characters with value from another string.
1120 * @param __pos Index of first character to replace.
1121 * @param __n Number of characters to be replaced.
1122 * @param __str String to insert.
1123 * @return Reference to this string.
1124 * @throw std::out_of_range If @a __pos is beyond the end of this
1126 * @throw std::length_error If new length exceeds @c max_size().
1128 * Removes the characters in the range [pos,pos+n) from this
1129 * string. In place, the value of @a __str is inserted. If @a
1130 * __pos is beyond end of string, out_of_range is thrown. If
1131 * the length of the result exceeds max_size(), length_error is
1132 * thrown. The value of the string doesn't change if an error
1136 replace(size_type __pos, size_type __n, const __versa_string& __str)
1137 { return this->replace(__pos, __n, __str._M_data(), __str.size()); }
1140 * @brief Replace characters with value from another string.
1141 * @param __pos1 Index of first character to replace.
1142 * @param __n1 Number of characters to be replaced.
1143 * @param __str String to insert.
1144 * @param __pos2 Index of first character of str to use.
1145 * @param __n2 Number of characters from str to use.
1146 * @return Reference to this string.
1147 * @throw std::out_of_range If @a __pos1 > size() or @a __pos2 >
1149 * @throw std::length_error If new length exceeds @c max_size().
1151 * Removes the characters in the range [pos1,pos1 + n) from
1152 * this string. In place, the value of @a __str is inserted.
1153 * If @a __pos is beyond end of string, out_of_range is thrown.
1154 * If the length of the result exceeds max_size(), length_error
1155 * is thrown. The value of the string doesn't change if an
1159 replace(size_type __pos1, size_type __n1, const __versa_string& __str,
1160 size_type __pos2, size_type __n2)
1162 return this->replace(__pos1, __n1, __str._M_data()
1163 + __str._M_check(__pos2,
1164 "__versa_string::replace"),
1165 __str._M_limit(__pos2, __n2));
1169 * @brief Replace characters with value of a C substring.
1170 * @param __pos Index of first character to replace.
1171 * @param __n1 Number of characters to be replaced.
1172 * @param __s C string to insert.
1173 * @param __n2 Number of characters from @a __s to use.
1174 * @return Reference to this string.
1175 * @throw std::out_of_range If @a __pos1 > size().
1176 * @throw std::length_error If new length exceeds @c max_size().
1178 * Removes the characters in the range [pos,pos + n1) from this
1179 * string. In place, the first @a __n2 characters of @a __s
1180 * are inserted, or all of @a __s if @a __n2 is too large. If
1181 * @a __pos is beyond end of string, out_of_range is thrown.
1182 * If the length of result exceeds max_size(), length_error is
1183 * thrown. The value of the string doesn't change if an error
1187 replace(size_type __pos, size_type __n1, const _CharT* __s,
1190 __glibcxx_requires_string_len(__s, __n2);
1191 return _M_replace(_M_check(__pos, "__versa_string::replace"),
1192 _M_limit(__pos, __n1), __s, __n2);
1196 * @brief Replace characters with value of a C string.
1197 * @param __pos Index of first character to replace.
1198 * @param __n1 Number of characters to be replaced.
1199 * @param __s C string to insert.
1200 * @return Reference to this string.
1201 * @throw std::out_of_range If @a __pos > size().
1202 * @throw std::length_error If new length exceeds @c max_size().
1204 * Removes the characters in the range [pos,pos + n1) from this
1205 * string. In place, the first @a __n characters of @a __s are
1206 * inserted. If @a pos is beyond end of string, out_of_range
1207 * is thrown. If the length of result exceeds max_size(),
1208 * length_error is thrown. The value of the string doesn't
1209 * change if an error is thrown.
1212 replace(size_type __pos, size_type __n1, const _CharT* __s)
1214 __glibcxx_requires_string(__s);
1215 return this->replace(__pos, __n1, __s, traits_type::length(__s));
1219 * @brief Replace characters with multiple characters.
1220 * @param __pos Index of first character to replace.
1221 * @param __n1 Number of characters to be replaced.
1222 * @param __n2 Number of characters to insert.
1223 * @param __c Character to insert.
1224 * @return Reference to this string.
1225 * @throw std::out_of_range If @a __pos > size().
1226 * @throw std::length_error If new length exceeds @c max_size().
1228 * Removes the characters in the range [pos,pos + n1) from this
1229 * string. In place, @a __n2 copies of @a __c are inserted.
1230 * If @a __pos is beyond end of string, out_of_range is thrown.
1231 * If the length of result exceeds max_size(), length_error is
1232 * thrown. The value of the string doesn't change if an error
1236 replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
1237 { return _M_replace_aux(_M_check(__pos, "__versa_string::replace"),
1238 _M_limit(__pos, __n1), __n2, __c); }
1241 * @brief Replace range of characters with string.
1242 * @param __i1 Iterator referencing start of range to replace.
1243 * @param __i2 Iterator referencing end of range to replace.
1244 * @param __str String value to insert.
1245 * @return Reference to this string.
1246 * @throw std::length_error If new length exceeds @c max_size().
1248 * Removes the characters in the range [i1,i2). In place, the
1249 * value of @a __str is inserted. If the length of result
1250 * exceeds max_size(), length_error is thrown. The value of
1251 * the string doesn't change if an error is thrown.
1254 replace(iterator __i1, iterator __i2, const __versa_string& __str)
1255 { return this->replace(__i1, __i2, __str._M_data(), __str.size()); }
1258 * @brief Replace range of characters with C substring.
1259 * @param __i1 Iterator referencing start of range to replace.
1260 * @param __i2 Iterator referencing end of range to replace.
1261 * @param __s C string value to insert.
1262 * @param __n Number of characters from s 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 * first @a n characters of @a __s are inserted. If the length
1268 * of result exceeds max_size(), length_error is thrown. The
1269 * value of the string doesn't change if an error is thrown.
1272 replace(iterator __i1, iterator __i2, const _CharT* __s, size_type __n)
1274 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1275 && __i2 <= _M_iend());
1276 return this->replace(__i1 - _M_ibegin(), __i2 - __i1, __s, __n);
1280 * @brief Replace range of characters with C string.
1281 * @param __i1 Iterator referencing start of range to replace.
1282 * @param __i2 Iterator referencing end of range to replace.
1283 * @param __s C string value 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 * characters of @a __s are inserted. If the length of result
1289 * exceeds max_size(), length_error is thrown. The value of
1290 * the string doesn't change if an error is thrown.
1293 replace(iterator __i1, iterator __i2, const _CharT* __s)
1295 __glibcxx_requires_string(__s);
1296 return this->replace(__i1, __i2, __s, traits_type::length(__s));
1300 * @brief Replace range of characters with multiple characters
1301 * @param __i1 Iterator referencing start of range to replace.
1302 * @param __i2 Iterator referencing end of range to replace.
1303 * @param __n Number of characters to insert.
1304 * @param __c Character 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, @a
1309 * __n copies of @a __c 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, size_type __n, _CharT __c)
1316 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1317 && __i2 <= _M_iend());
1318 return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __c);
1322 * @brief Replace range of characters with range.
1323 * @param __i1 Iterator referencing start of range to replace.
1324 * @param __i2 Iterator referencing end of range to replace.
1325 * @param __k1 Iterator referencing start of range to insert.
1326 * @param __k2 Iterator referencing end of range to insert.
1327 * @return Reference to this string.
1328 * @throw std::length_error If new length exceeds @c max_size().
1330 * Removes the characters in the range [i1,i2). In place,
1331 * characters in the range [k1,k2) are inserted. If the length
1332 * of result exceeds max_size(), length_error is thrown. The
1333 * value of the string doesn't change if an error is thrown.
1335 template<class _InputIterator>
1337 replace(iterator __i1, iterator __i2,
1338 _InputIterator __k1, _InputIterator __k2)
1340 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1341 && __i2 <= _M_iend());
1342 __glibcxx_requires_valid_range(__k1, __k2);
1343 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
1344 return _M_replace_dispatch(__i1, __i2, __k1, __k2, _Integral());
1347 // Specializations for the common case of pointer and iterator:
1348 // useful to avoid the overhead of temporary buffering in _M_replace.
1350 replace(iterator __i1, iterator __i2, _CharT* __k1, _CharT* __k2)
1352 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1353 && __i2 <= _M_iend());
1354 __glibcxx_requires_valid_range(__k1, __k2);
1355 return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
1360 replace(iterator __i1, iterator __i2,
1361 const _CharT* __k1, const _CharT* __k2)
1363 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1364 && __i2 <= _M_iend());
1365 __glibcxx_requires_valid_range(__k1, __k2);
1366 return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
1371 replace(iterator __i1, iterator __i2, iterator __k1, iterator __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,
1377 __k1.base(), __k2 - __k1);
1381 replace(iterator __i1, iterator __i2,
1382 const_iterator __k1, const_iterator __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,
1388 __k1.base(), __k2 - __k1);
1391 #ifdef __GXX_EXPERIMENTAL_CXX0X__
1393 * @brief Replace range of characters with initializer_list.
1394 * @param __i1 Iterator referencing start of range to replace.
1395 * @param __i2 Iterator referencing end of range to replace.
1396 * @param __l The initializer_list of characters to insert.
1397 * @return Reference to this string.
1398 * @throw std::length_error If new length exceeds @c max_size().
1400 * Removes the characters in the range [i1,i2). In place,
1401 * characters in the range [k1,k2) are inserted. If the length
1402 * of result exceeds max_size(), length_error is thrown. The
1403 * value of the string doesn't change if an error is thrown.
1405 __versa_string& replace(iterator __i1, iterator __i2,
1406 std::initializer_list<_CharT> __l)
1407 { return this->replace(__i1, __i2, __l.begin(), __l.end()); }
1408 #endif // __GXX_EXPERIMENTAL_CXX0X__
1411 template<class _Integer>
1413 _M_replace_dispatch(iterator __i1, iterator __i2, _Integer __n,
1414 _Integer __val, std::__true_type)
1415 { return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __val); }
1417 template<class _InputIterator>
1419 _M_replace_dispatch(iterator __i1, iterator __i2, _InputIterator __k1,
1420 _InputIterator __k2, std::__false_type);
1423 _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2,
1427 _M_replace(size_type __pos, size_type __len1, const _CharT* __s,
1428 const size_type __len2);
1431 _M_append(const _CharT* __s, size_type __n);
1436 * @brief Copy substring into C string.
1437 * @param __s C string to copy value into.
1438 * @param __n Number of characters to copy.
1439 * @param __pos Index of first character to copy.
1440 * @return Number of characters actually copied
1441 * @throw std::out_of_range If pos > size().
1443 * Copies up to @a __n characters starting at @a __pos into the
1444 * C string @a s. If @a __pos is greater than size(),
1445 * out_of_range is thrown.
1448 copy(_CharT* __s, size_type __n, size_type __pos = 0) const;
1451 * @brief Swap contents with another string.
1452 * @param __s String to swap with.
1454 * Exchanges the contents of this string with that of @a __s in
1458 swap(__versa_string& __s)
1459 { this->_M_swap(__s); }
1461 // String operations:
1463 * @brief Return const pointer to null-terminated contents.
1465 * This is a handle to internal data. Do not modify or dire things may
1470 { return this->_M_data(); }
1473 * @brief Return const pointer to contents.
1475 * This is a handle to internal data. Do not modify or dire things may
1480 { return this->_M_data(); }
1483 * @brief Return copy of allocator used to construct this string.
1486 get_allocator() const
1487 { return allocator_type(this->_M_get_allocator()); }
1490 * @brief Find position of a C substring.
1491 * @param __s C string to locate.
1492 * @param __pos Index of character to search from.
1493 * @param __n Number of characters from @a __s to search for.
1494 * @return Index of start of first occurrence.
1496 * Starting from @a __pos, searches forward for the first @a
1497 * __n characters in @a __s within this string. If found,
1498 * returns the index where it begins. If not found, returns
1502 find(const _CharT* __s, size_type __pos, size_type __n) const;
1505 * @brief Find position of a string.
1506 * @param __str String to locate.
1507 * @param __pos Index of character to search from (default 0).
1508 * @return Index of start of first occurrence.
1510 * Starting from @a __pos, searches forward for value of @a
1511 * __str within this string. If found, returns the index where
1512 * it begins. If not found, returns npos.
1515 find(const __versa_string& __str, size_type __pos = 0) const
1516 { return this->find(__str.data(), __pos, __str.size()); }
1519 * @brief Find position of a C string.
1520 * @param __s C string to locate.
1521 * @param __pos Index of character to search from (default 0).
1522 * @return Index of start of first occurrence.
1524 * Starting from @a __pos, searches forward for the value of @a
1525 * __s within this string. If found, returns the index where
1526 * it begins. If not found, returns npos.
1529 find(const _CharT* __s, size_type __pos = 0) const
1531 __glibcxx_requires_string(__s);
1532 return this->find(__s, __pos, traits_type::length(__s));
1536 * @brief Find position of a character.
1537 * @param __c Character to locate.
1538 * @param __pos Index of character to search from (default 0).
1539 * @return Index of first occurrence.
1541 * Starting from @a __pos, searches forward for @a __c within
1542 * this string. If found, returns the index where it was
1543 * found. If not found, returns npos.
1546 find(_CharT __c, size_type __pos = 0) const;
1549 * @brief Find last position of a string.
1550 * @param __str String to locate.
1551 * @param __pos Index of character to search back from (default end).
1552 * @return Index of start of last occurrence.
1554 * Starting from @a __pos, searches backward for value of @a
1555 * __str within this string. If found, returns the index where
1556 * it begins. If not found, returns npos.
1559 rfind(const __versa_string& __str, size_type __pos = npos) const
1560 { return this->rfind(__str.data(), __pos, __str.size()); }
1563 * @brief Find last position of a C substring.
1564 * @param __s C string to locate.
1565 * @param __pos Index of character to search back from.
1566 * @param __n Number of characters from s to search for.
1567 * @return Index of start of last occurrence.
1569 * Starting from @a __pos, searches backward for the first @a
1570 * __n characters in @a __s within this string. If found,
1571 * returns the index where it begins. If not found, returns
1575 rfind(const _CharT* __s, size_type __pos, size_type __n) const;
1578 * @brief Find last position of a C string.
1579 * @param __s C string to locate.
1580 * @param __pos Index of character to start search at (default end).
1581 * @return Index of start of last occurrence.
1583 * Starting from @a __pos, searches backward for the value of
1584 * @a __s within this string. If found, returns the index
1585 * where it begins. If not found, returns npos.
1588 rfind(const _CharT* __s, size_type __pos = npos) const
1590 __glibcxx_requires_string(__s);
1591 return this->rfind(__s, __pos, traits_type::length(__s));
1595 * @brief Find last position of a character.
1596 * @param __c Character to locate.
1597 * @param __pos Index of character to search back from (default end).
1598 * @return Index of last occurrence.
1600 * Starting from @a __pos, searches backward for @a __c within
1601 * this string. If found, returns the index where it was
1602 * found. If not found, returns npos.
1605 rfind(_CharT __c, size_type __pos = npos) const;
1608 * @brief Find position of a character of string.
1609 * @param __str String containing characters to locate.
1610 * @param __pos Index of character to search from (default 0).
1611 * @return Index of first occurrence.
1613 * Starting from @a __pos, searches forward for one of the characters of
1614 * @a __str within this string. If found, returns the index where it was
1615 * found. If not found, returns npos.
1618 find_first_of(const __versa_string& __str, size_type __pos = 0) const
1619 { return this->find_first_of(__str.data(), __pos, __str.size()); }
1622 * @brief Find position of a character of C substring.
1623 * @param __s String containing characters to locate.
1624 * @param __pos Index of character to search from.
1625 * @param __n Number of characters from s to search for.
1626 * @return Index of first occurrence.
1628 * Starting from @a __pos, searches forward for one of the
1629 * first @a __n characters of @a __s within this string. If
1630 * found, returns the index where it was found. If not found,
1634 find_first_of(const _CharT* __s, size_type __pos, size_type __n) const;
1637 * @brief Find position of a character of C string.
1638 * @param __s String containing characters to locate.
1639 * @param __pos Index of character to search from (default 0).
1640 * @return Index of first occurrence.
1642 * Starting from @a __pos, searches forward for one of the
1643 * characters of @a __s within this string. If found, returns
1644 * the index where it was found. If not found, returns npos.
1647 find_first_of(const _CharT* __s, size_type __pos = 0) const
1649 __glibcxx_requires_string(__s);
1650 return this->find_first_of(__s, __pos, traits_type::length(__s));
1654 * @brief Find position of a character.
1655 * @param __c Character to locate.
1656 * @param __pos Index of character to search from (default 0).
1657 * @return Index of first occurrence.
1659 * Starting from @a __pos, searches forward for the character
1660 * @a __c within this string. If found, returns the index
1661 * where it was found. If not found, returns npos.
1663 * Note: equivalent to find(c, pos).
1666 find_first_of(_CharT __c, size_type __pos = 0) const
1667 { return this->find(__c, __pos); }
1670 * @brief Find last position of a character of string.
1671 * @param __str String containing characters to locate.
1672 * @param __pos Index of character to search back from (default end).
1673 * @return Index of last occurrence.
1675 * Starting from @a __pos, searches backward for one of the
1676 * characters of @a __str within this string. If found,
1677 * returns the index where it was found. If not found, returns
1681 find_last_of(const __versa_string& __str, size_type __pos = npos) const
1682 { return this->find_last_of(__str.data(), __pos, __str.size()); }
1685 * @brief Find last position of a character of C substring.
1686 * @param __s C string containing characters to locate.
1687 * @param __pos Index of character to search back from.
1688 * @param __n Number of characters from s to search for.
1689 * @return Index of last occurrence.
1691 * Starting from @a __pos, searches backward for one of the
1692 * first @a __n characters of @a __s within this string. If
1693 * found, returns the index where it was found. If not found,
1697 find_last_of(const _CharT* __s, size_type __pos, size_type __n) const;
1700 * @brief Find last position of a character of C string.
1701 * @param __s C string containing characters to locate.
1702 * @param __pos Index of character to search back from (default end).
1703 * @return Index of last occurrence.
1705 * Starting from @a __pos, searches backward for one of the
1706 * characters of @a __s within this string. If found, returns
1707 * the index where it was found. If not found, returns npos.
1710 find_last_of(const _CharT* __s, size_type __pos = npos) const
1712 __glibcxx_requires_string(__s);
1713 return this->find_last_of(__s, __pos, traits_type::length(__s));
1717 * @brief Find last position of a character.
1718 * @param __c Character to locate.
1719 * @param __pos Index of character to search back from (default end).
1720 * @return Index of last occurrence.
1722 * Starting from @a __pos, searches backward for @a __c within
1723 * this string. If found, returns the index where it was
1724 * found. If not found, returns npos.
1726 * Note: equivalent to rfind(c, pos).
1729 find_last_of(_CharT __c, size_type __pos = npos) const
1730 { return this->rfind(__c, __pos); }
1733 * @brief Find position of a character not in string.
1734 * @param __str String containing characters to avoid.
1735 * @param __pos Index of character to search from (default 0).
1736 * @return Index of first occurrence.
1738 * Starting from @a __pos, searches forward for a character not
1739 * contained in @a __str within this string. If found, returns
1740 * the index where it was found. If not found, returns npos.
1743 find_first_not_of(const __versa_string& __str, size_type __pos = 0) const
1744 { return this->find_first_not_of(__str.data(), __pos, __str.size()); }
1747 * @brief Find position of a character not in C substring.
1748 * @param __s C string containing characters to avoid.
1749 * @param __pos Index of character to search from.
1750 * @param __n Number of characters from s to consider.
1751 * @return Index of first occurrence.
1753 * Starting from @a __pos, searches forward for a character not
1754 * contained in the first @a __n characters of @a __s within
1755 * this string. If found, returns the index where it was
1756 * found. If not found, returns npos.
1759 find_first_not_of(const _CharT* __s, size_type __pos,
1760 size_type __n) const;
1763 * @brief Find position of a character not in C string.
1764 * @param __s C string containing characters to avoid.
1765 * @param __pos Index of character to search from (default 0).
1766 * @return Index of first occurrence.
1768 * Starting from @a __pos, searches forward for a character not
1769 * contained in @a __s within this string. If found, returns
1770 * the index where it was found. If not found, returns npos.
1773 find_first_not_of(const _CharT* __s, size_type __pos = 0) const
1775 __glibcxx_requires_string(__s);
1776 return this->find_first_not_of(__s, __pos, traits_type::length(__s));
1780 * @brief Find position of a different character.
1781 * @param __c Character to avoid.
1782 * @param __pos Index of character to search from (default 0).
1783 * @return Index of first occurrence.
1785 * Starting from @a __pos, searches forward for a character
1786 * other than @a __c within this string. If found, returns the
1787 * index where it was found. If not found, returns npos.
1790 find_first_not_of(_CharT __c, size_type __pos = 0) const;
1793 * @brief Find last position of a character not in string.
1794 * @param __str String containing characters to avoid.
1795 * @param __pos Index of character to search back from (default end).
1796 * @return Index of last occurrence.
1798 * Starting from @a __pos, searches backward for a character
1799 * not contained in @a __str within this string. If found,
1800 * returns the index where it was found. If not found, returns
1804 find_last_not_of(const __versa_string& __str,
1805 size_type __pos = npos) const
1806 { return this->find_last_not_of(__str.data(), __pos, __str.size()); }
1809 * @brief Find last position of a character not in C substring.
1810 * @param __s C string containing characters to avoid.
1811 * @param __pos Index of character to search back from.
1812 * @param __n Number of characters from s to consider.
1813 * @return Index of last occurrence.
1815 * Starting from @a __pos, searches backward for a character
1816 * not contained in the first @a __n characters of @a __s
1817 * within this string. If found, returns the index where it
1818 * was found. If not found, returns npos.
1821 find_last_not_of(const _CharT* __s, size_type __pos,
1822 size_type __n) const;
1824 * @brief Find last position of a character not in C string.
1825 * @param __s C string containing characters to avoid.
1826 * @param __pos Index of character to search back from (default end).
1827 * @return Index of last occurrence.
1829 * Starting from @a __pos, searches backward for a character
1830 * not contained in @a __s within this string. If found,
1831 * returns the index where it was found. If not found, returns
1835 find_last_not_of(const _CharT* __s, size_type __pos = npos) const
1837 __glibcxx_requires_string(__s);
1838 return this->find_last_not_of(__s, __pos, traits_type::length(__s));
1842 * @brief Find last position of a different character.
1843 * @param __c Character 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 * other than @a __c within this string. If found, returns the
1849 * index where it was found. If not found, returns npos.
1852 find_last_not_of(_CharT __c, size_type __pos = npos) const;
1855 * @brief Get a substring.
1856 * @param __pos Index of first character (default 0).
1857 * @param __n Number of characters in substring (default remainder).
1858 * @return The new string.
1859 * @throw std::out_of_range If pos > size().
1861 * Construct and return a new string using the @a __n
1862 * characters starting at @a __pos. If the string is too
1863 * short, use the remainder of the characters. If @a __pos is
1864 * beyond the end of the string, out_of_range is thrown.
1867 substr(size_type __pos = 0, size_type __n = npos) const
1869 return __versa_string(*this, _M_check(__pos, "__versa_string::substr"),
1874 * @brief Compare to a string.
1875 * @param __str String to compare against.
1876 * @return Integer < 0, 0, or > 0.
1878 * Returns an integer < 0 if this string is ordered before @a
1879 * __str, 0 if their values are equivalent, or > 0 if this
1880 * string is ordered after @a __str. Determines the effective
1881 * length rlen of the strings to compare as the smallest of
1882 * size() and str.size(). The function then compares the two
1883 * strings by calling traits::compare(data(), str.data(),rlen).
1884 * If the result of the comparison is nonzero returns it,
1885 * otherwise the shorter one is ordered first.
1888 compare(const __versa_string& __str) const
1890 if (this->_M_compare(__str))
1893 const size_type __size = this->size();
1894 const size_type __osize = __str.size();
1895 const size_type __len = std::min(__size, __osize);
1897 int __r = traits_type::compare(this->_M_data(), __str.data(), __len);
1899 __r = _S_compare(__size, __osize);
1904 * @brief Compare substring to a string.
1905 * @param __pos Index of first character of substring.
1906 * @param __n Number of characters in substring.
1907 * @param __str String to compare against.
1908 * @return Integer < 0, 0, or > 0.
1910 * Form the substring of this string from the @a __n characters
1911 * starting at @a __pos. Returns an integer < 0 if the
1912 * substring is ordered before @a __str, 0 if their values are
1913 * equivalent, or > 0 if the substring is ordered after @a
1914 * __str. Determines the effective length rlen of the strings
1915 * to compare as the smallest of the length of the substring
1916 * and @a __str.size(). The function then compares the two
1917 * strings by calling
1918 * traits::compare(substring.data(),str.data(),rlen). If the
1919 * result of the comparison is nonzero returns it, otherwise
1920 * the shorter one is ordered first.
1923 compare(size_type __pos, size_type __n,
1924 const __versa_string& __str) const;
1927 * @brief Compare substring to a substring.
1928 * @param __pos1 Index of first character of substring.
1929 * @param __n1 Number of characters in substring.
1930 * @param __str String to compare against.
1931 * @param __pos2 Index of first character of substring of str.
1932 * @param __n2 Number of characters in substring of str.
1933 * @return Integer < 0, 0, or > 0.
1935 * Form the substring of this string from the @a __n1
1936 * characters starting at @a __pos1. Form the substring of @a
1937 * __str from the @a __n2 characters starting at @a __pos2.
1938 * Returns an integer < 0 if this substring is ordered before
1939 * the substring of @a __str, 0 if their values are equivalent,
1940 * or > 0 if this substring is ordered after the substring of
1941 * @a __str. Determines the effective length rlen of the
1942 * strings to compare as the smallest of the lengths of the
1943 * substrings. The function then compares the two strings by
1945 * traits::compare(substring.data(),str.substr(pos2,n2).data(),rlen).
1946 * If the result of the comparison is nonzero returns it,
1947 * otherwise the shorter one is ordered first.
1950 compare(size_type __pos1, size_type __n1, const __versa_string& __str,
1951 size_type __pos2, size_type __n2) const;
1954 * @brief Compare to a C string.
1955 * @param __s C string to compare against.
1956 * @return Integer < 0, 0, or > 0.
1958 * Returns an integer < 0 if this string is ordered before @a
1959 * __s, 0 if their values are equivalent, or > 0 if this string
1960 * is ordered after @a __s. Determines the effective length
1961 * rlen of the strings to compare as the smallest of size() and
1962 * the length of a string constructed from @a __s. The
1963 * function then compares the two strings by calling
1964 * traits::compare(data(),s,rlen). If the result of the
1965 * comparison is nonzero returns it, otherwise the shorter one
1969 compare(const _CharT* __s) const;
1971 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1972 // 5 String::compare specification questionable
1974 * @brief Compare substring to a C string.
1975 * @param __pos Index of first character of substring.
1976 * @param __n1 Number of characters in substring.
1977 * @param __s C string to compare against.
1978 * @return Integer < 0, 0, or > 0.
1980 * Form the substring of this string from the @a __n1
1981 * characters starting at @a __pos. Returns an integer < 0 if
1982 * the substring is ordered before @a __s, 0 if their values
1983 * are equivalent, or > 0 if the substring is ordered after @a
1984 * __s. Determines the effective length rlen of the strings to
1985 * compare as the smallest of the length of the substring and
1986 * the length of a string constructed from @a __s. The
1987 * function then compares the two string by calling
1988 * traits::compare(substring.data(),s,rlen). If the result of
1989 * the comparison is nonzero returns it, otherwise the shorter
1990 * one is ordered first.
1993 compare(size_type __pos, size_type __n1, const _CharT* __s) const;
1996 * @brief Compare substring against a character array.
1997 * @param __pos1 Index of first character of substring.
1998 * @param __n1 Number of characters in substring.
1999 * @param __s character array to compare against.
2000 * @param __n2 Number of characters of s.
2001 * @return Integer < 0, 0, or > 0.
2003 * Form the substring of this string from the @a __n1
2004 * characters starting at @a __pos1. Form a string from the
2005 * first @a __n2 characters of @a __s. Returns an integer < 0
2006 * if this substring is ordered before the string from @a __s,
2007 * 0 if their values are equivalent, or > 0 if this substring
2008 * is ordered after the string from @a __s. Determines the
2009 * effective length rlen of the strings to compare as the
2010 * smallest of the length of the substring and @a __n2. The
2011 * function then compares the two strings by calling
2012 * traits::compare(substring.data(),s,rlen). If the result of
2013 * the comparison is nonzero returns it, otherwise the shorter
2014 * one is ordered first.
2016 * NB: s must have at least n2 characters, '\\0' has no special
2020 compare(size_type __pos, size_type __n1, const _CharT* __s,
2021 size_type __n2) const;
2026 * @brief Concatenate two strings.
2027 * @param __lhs First string.
2028 * @param __rhs Last string.
2029 * @return New string with value of @a __lhs followed by @a __rhs.
2031 template<typename _CharT, typename _Traits, typename _Alloc,
2032 template <typename, typename, typename> class _Base>
2033 __versa_string<_CharT, _Traits, _Alloc, _Base>
2034 operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2035 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs);
2038 * @brief Concatenate C string and string.
2039 * @param __lhs First string.
2040 * @param __rhs Last string.
2041 * @return New string with value of @a __lhs followed by @a __rhs.
2043 template<typename _CharT, typename _Traits, typename _Alloc,
2044 template <typename, typename, typename> class _Base>
2045 __versa_string<_CharT, _Traits, _Alloc, _Base>
2046 operator+(const _CharT* __lhs,
2047 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs);
2050 * @brief Concatenate character and string.
2051 * @param __lhs First string.
2052 * @param __rhs Last string.
2053 * @return New string with @a __lhs followed by @a __rhs.
2055 template<typename _CharT, typename _Traits, typename _Alloc,
2056 template <typename, typename, typename> class _Base>
2057 __versa_string<_CharT, _Traits, _Alloc, _Base>
2058 operator+(_CharT __lhs,
2059 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs);
2062 * @brief Concatenate string and C string.
2063 * @param __lhs First string.
2064 * @param __rhs Last string.
2065 * @return New string with @a __lhs followed by @a __rhs.
2067 template<typename _CharT, typename _Traits, typename _Alloc,
2068 template <typename, typename, typename> class _Base>
2069 __versa_string<_CharT, _Traits, _Alloc, _Base>
2070 operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2071 const _CharT* __rhs);
2074 * @brief Concatenate string and character.
2075 * @param __lhs First string.
2076 * @param __rhs Last string.
2077 * @return New string with @a __lhs followed by @a __rhs.
2079 template<typename _CharT, typename _Traits, typename _Alloc,
2080 template <typename, typename, typename> class _Base>
2081 __versa_string<_CharT, _Traits, _Alloc, _Base>
2082 operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2087 * @brief Test equivalence of two strings.
2088 * @param __lhs First string.
2089 * @param __rhs Second string.
2090 * @return True if @a __lhs.compare(@a __rhs) == 0. False otherwise.
2092 template<typename _CharT, typename _Traits, typename _Alloc,
2093 template <typename, typename, typename> class _Base>
2095 operator==(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2096 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2097 { return __lhs.compare(__rhs) == 0; }
2099 template<typename _CharT,
2100 template <typename, typename, typename> class _Base>
2101 inline typename __enable_if<std::__is_char<_CharT>::__value, bool>::__type
2102 operator==(const __versa_string<_CharT, std::char_traits<_CharT>,
2103 std::allocator<_CharT>, _Base>& __lhs,
2104 const __versa_string<_CharT, std::char_traits<_CharT>,
2105 std::allocator<_CharT>, _Base>& __rhs)
2106 { return (__lhs.size() == __rhs.size()
2107 && !std::char_traits<_CharT>::compare(__lhs.data(), __rhs.data(),
2111 * @brief Test equivalence of C string and string.
2112 * @param __lhs C string.
2113 * @param __rhs String.
2114 * @return True if @a __rhs.compare(@a __lhs) == 0. False otherwise.
2116 template<typename _CharT, typename _Traits, typename _Alloc,
2117 template <typename, typename, typename> class _Base>
2119 operator==(const _CharT* __lhs,
2120 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2121 { return __rhs.compare(__lhs) == 0; }
2124 * @brief Test equivalence of string and C string.
2125 * @param __lhs String.
2126 * @param __rhs C string.
2127 * @return True if @a __lhs.compare(@a __rhs) == 0. False otherwise.
2129 template<typename _CharT, typename _Traits, typename _Alloc,
2130 template <typename, typename, typename> class _Base>
2132 operator==(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2133 const _CharT* __rhs)
2134 { return __lhs.compare(__rhs) == 0; }
2138 * @brief Test difference of two strings.
2139 * @param __lhs First string.
2140 * @param __rhs Second string.
2141 * @return True if @a __lhs.compare(@a __rhs) != 0. False otherwise.
2143 template<typename _CharT, typename _Traits, typename _Alloc,
2144 template <typename, typename, typename> class _Base>
2146 operator!=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2147 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2148 { return !(__lhs == __rhs); }
2151 * @brief Test difference of C string and string.
2152 * @param __lhs C string.
2153 * @param __rhs String.
2154 * @return True if @a __rhs.compare(@a __lhs) != 0. False otherwise.
2156 template<typename _CharT, typename _Traits, typename _Alloc,
2157 template <typename, typename, typename> class _Base>
2159 operator!=(const _CharT* __lhs,
2160 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2161 { return !(__lhs == __rhs); }
2164 * @brief Test difference of string and C string.
2165 * @param __lhs String.
2166 * @param __rhs C string.
2167 * @return True if @a __lhs.compare(@a __rhs) != 0. False otherwise.
2169 template<typename _CharT, typename _Traits, typename _Alloc,
2170 template <typename, typename, typename> class _Base>
2172 operator!=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2173 const _CharT* __rhs)
2174 { return !(__lhs == __rhs); }
2178 * @brief Test if string precedes string.
2179 * @param __lhs First string.
2180 * @param __rhs Second string.
2181 * @return True if @a __lhs precedes @a __rhs. False otherwise.
2183 template<typename _CharT, typename _Traits, typename _Alloc,
2184 template <typename, typename, typename> class _Base>
2186 operator<(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2187 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2188 { return __lhs.compare(__rhs) < 0; }
2191 * @brief Test if string precedes C string.
2192 * @param __lhs String.
2193 * @param __rhs C string.
2194 * @return True if @a __lhs precedes @a __rhs. False otherwise.
2196 template<typename _CharT, typename _Traits, typename _Alloc,
2197 template <typename, typename, typename> class _Base>
2199 operator<(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2200 const _CharT* __rhs)
2201 { return __lhs.compare(__rhs) < 0; }
2204 * @brief Test if C string precedes string.
2205 * @param __lhs C string.
2206 * @param __rhs String.
2207 * @return True if @a __lhs precedes @a __rhs. False otherwise.
2209 template<typename _CharT, typename _Traits, typename _Alloc,
2210 template <typename, typename, typename> class _Base>
2212 operator<(const _CharT* __lhs,
2213 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2214 { return __rhs.compare(__lhs) > 0; }
2218 * @brief Test if string follows string.
2219 * @param __lhs First string.
2220 * @param __rhs Second string.
2221 * @return True if @a __lhs follows @a __rhs. False otherwise.
2223 template<typename _CharT, typename _Traits, typename _Alloc,
2224 template <typename, typename, typename> class _Base>
2226 operator>(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2227 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2228 { return __lhs.compare(__rhs) > 0; }
2231 * @brief Test if string follows C string.
2232 * @param __lhs String.
2233 * @param __rhs C string.
2234 * @return True if @a __lhs follows @a __rhs. False otherwise.
2236 template<typename _CharT, typename _Traits, typename _Alloc,
2237 template <typename, typename, typename> class _Base>
2239 operator>(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2240 const _CharT* __rhs)
2241 { return __lhs.compare(__rhs) > 0; }
2244 * @brief Test if C string follows string.
2245 * @param __lhs C string.
2246 * @param __rhs String.
2247 * @return True if @a __lhs follows @a __rhs. False otherwise.
2249 template<typename _CharT, typename _Traits, typename _Alloc,
2250 template <typename, typename, typename> class _Base>
2252 operator>(const _CharT* __lhs,
2253 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2254 { return __rhs.compare(__lhs) < 0; }
2258 * @brief Test if string doesn't follow string.
2259 * @param __lhs First string.
2260 * @param __rhs Second string.
2261 * @return True if @a __lhs doesn't follow @a __rhs. False otherwise.
2263 template<typename _CharT, typename _Traits, typename _Alloc,
2264 template <typename, typename, typename> class _Base>
2266 operator<=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2267 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2268 { return __lhs.compare(__rhs) <= 0; }
2271 * @brief Test if string doesn't follow C string.
2272 * @param __lhs String.
2273 * @param __rhs C string.
2274 * @return True if @a __lhs doesn't follow @a __rhs. False otherwise.
2276 template<typename _CharT, typename _Traits, typename _Alloc,
2277 template <typename, typename, typename> class _Base>
2279 operator<=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2280 const _CharT* __rhs)
2281 { return __lhs.compare(__rhs) <= 0; }
2284 * @brief Test if C string doesn't follow string.
2285 * @param __lhs C string.
2286 * @param __rhs String.
2287 * @return True if @a __lhs doesn't follow @a __rhs. False otherwise.
2289 template<typename _CharT, typename _Traits, typename _Alloc,
2290 template <typename, typename, typename> class _Base>
2292 operator<=(const _CharT* __lhs,
2293 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2294 { return __rhs.compare(__lhs) >= 0; }
2298 * @brief Test if string doesn't precede string.
2299 * @param __lhs First string.
2300 * @param __rhs Second string.
2301 * @return True if @a __lhs doesn't precede @a __rhs. False otherwise.
2303 template<typename _CharT, typename _Traits, typename _Alloc,
2304 template <typename, typename, typename> class _Base>
2306 operator>=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2307 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2308 { return __lhs.compare(__rhs) >= 0; }
2311 * @brief Test if string doesn't precede C string.
2312 * @param __lhs String.
2313 * @param __rhs C string.
2314 * @return True if @a __lhs doesn't precede @a __rhs. False otherwise.
2316 template<typename _CharT, typename _Traits, typename _Alloc,
2317 template <typename, typename, typename> class _Base>
2319 operator>=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2320 const _CharT* __rhs)
2321 { return __lhs.compare(__rhs) >= 0; }
2324 * @brief Test if C string doesn't precede string.
2325 * @param __lhs C string.
2326 * @param __rhs String.
2327 * @return True if @a __lhs doesn't precede @a __rhs. False otherwise.
2329 template<typename _CharT, typename _Traits, typename _Alloc,
2330 template <typename, typename, typename> class _Base>
2332 operator>=(const _CharT* __lhs,
2333 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2334 { return __rhs.compare(__lhs) <= 0; }
2337 * @brief Swap contents of two strings.
2338 * @param __lhs First string.
2339 * @param __rhs Second string.
2341 * Exchanges the contents of @a __lhs and @a __rhs in constant time.
2343 template<typename _CharT, typename _Traits, typename _Alloc,
2344 template <typename, typename, typename> class _Base>
2346 swap(__versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2347 __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2348 { __lhs.swap(__rhs); }
2350 _GLIBCXX_END_NAMESPACE
2352 _GLIBCXX_BEGIN_NAMESPACE(std)
2355 * @brief Read stream into a string.
2356 * @param __is Input stream.
2357 * @param __str Buffer to store into.
2358 * @return Reference to the input stream.
2360 * Stores characters from @a __is into @a __str until whitespace is
2361 * found, the end of the stream is encountered, or str.max_size()
2362 * is reached. If is.width() is non-zero, that is the limit on the
2363 * number of characters stored into @a __str. Any previous
2364 * contents of @a __str are erased.
2366 template<typename _CharT, typename _Traits, typename _Alloc,
2367 template <typename, typename, typename> class _Base>
2368 basic_istream<_CharT, _Traits>&
2369 operator>>(basic_istream<_CharT, _Traits>& __is,
2370 __gnu_cxx::__versa_string<_CharT, _Traits,
2371 _Alloc, _Base>& __str);
2374 * @brief Write string to a stream.
2375 * @param __os Output stream.
2376 * @param __str String to write out.
2377 * @return Reference to the output stream.
2379 * Output characters of @a __str into os following the same rules as for
2380 * writing a C string.
2382 template<typename _CharT, typename _Traits, typename _Alloc,
2383 template <typename, typename, typename> class _Base>
2384 inline basic_ostream<_CharT, _Traits>&
2385 operator<<(basic_ostream<_CharT, _Traits>& __os,
2386 const __gnu_cxx::__versa_string<_CharT, _Traits, _Alloc,
2389 // _GLIBCXX_RESOLVE_LIB_DEFECTS
2390 // 586. string inserter not a formatted function
2391 return __ostream_insert(__os, __str.data(), __str.size());
2395 * @brief Read a line from stream into a string.
2396 * @param __is Input stream.
2397 * @param __str Buffer to store into.
2398 * @param __delim Character marking end of line.
2399 * @return Reference to the input stream.
2401 * Stores characters from @a __is into @a __str until @a __delim is
2402 * found, the end of the stream is encountered, or str.max_size()
2403 * is reached. If is.width() is non-zero, that is the limit on the
2404 * number of characters stored into @a __str. Any previous
2405 * contents of @a __str are erased. If @a delim was encountered,
2406 * it is extracted but not stored into @a __str.
2408 template<typename _CharT, typename _Traits, typename _Alloc,
2409 template <typename, typename, typename> class _Base>
2410 basic_istream<_CharT, _Traits>&
2411 getline(basic_istream<_CharT, _Traits>& __is,
2412 __gnu_cxx::__versa_string<_CharT, _Traits, _Alloc, _Base>& __str,
2416 * @brief Read a line from stream into a string.
2417 * @param __is Input stream.
2418 * @param __str Buffer to store into.
2419 * @return Reference to the input stream.
2421 * Stores characters from is into @a __str until '\n' is found, the
2422 * end of the stream is encountered, or str.max_size() is reached.
2423 * If is.width() is non-zero, that is the limit on the number of
2424 * characters stored into @a __str. Any previous contents of @a
2425 * __str are erased. If end of line was encountered, it is
2426 * extracted but not stored into @a __str.
2428 template<typename _CharT, typename _Traits, typename _Alloc,
2429 template <typename, typename, typename> class _Base>
2430 inline basic_istream<_CharT, _Traits>&
2431 getline(basic_istream<_CharT, _Traits>& __is,
2432 __gnu_cxx::__versa_string<_CharT, _Traits, _Alloc, _Base>& __str)
2433 { return getline(__is, __str, __is.widen('\n')); }
2435 _GLIBCXX_END_NAMESPACE
2437 #if (defined(__GXX_EXPERIMENTAL_CXX0X__) && defined(_GLIBCXX_USE_C99))
2439 #include <ext/string_conversions.h>
2441 _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
2443 // 21.4 Numeric Conversions [string.conversions].
2445 stoi(const __vstring& __str, std::size_t* __idx = 0, int __base = 10)
2446 { return __gnu_cxx::__stoa<long, int>(&std::strtol, "stoi", __str.c_str(),
2450 stol(const __vstring& __str, std::size_t* __idx = 0, int __base = 10)
2451 { return __gnu_cxx::__stoa(&std::strtol, "stol", __str.c_str(),
2454 inline unsigned long
2455 stoul(const __vstring& __str, std::size_t* __idx = 0, int __base = 10)
2456 { return __gnu_cxx::__stoa(&std::strtoul, "stoul", __str.c_str(),
2460 stoll(const __vstring& __str, std::size_t* __idx = 0, int __base = 10)
2461 { return __gnu_cxx::__stoa(&std::strtoll, "stoll", __str.c_str(),
2464 inline unsigned long long
2465 stoull(const __vstring& __str, std::size_t* __idx, int __base = 10)
2466 { return __gnu_cxx::__stoa(&std::strtoull, "stoull", __str.c_str(),
2469 // NB: strtof vs strtod.
2471 stof(const __vstring& __str, std::size_t* __idx = 0)
2472 { return __gnu_cxx::__stoa(&std::strtof, "stof", __str.c_str(), __idx); }
2475 stod(const __vstring& __str, std::size_t* __idx = 0)
2476 { return __gnu_cxx::__stoa(&std::strtod, "stod", __str.c_str(), __idx); }
2479 stold(const __vstring& __str, std::size_t* __idx = 0)
2480 { return __gnu_cxx::__stoa(&std::strtold, "stold", __str.c_str(), __idx); }
2482 // NB: (v)snprintf vs sprintf.
2486 to_string(int __val)
2487 { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, 4 * sizeof(int),
2491 to_string(unsigned __val)
2492 { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf,
2493 4 * sizeof(unsigned),
2497 to_string(long __val)
2498 { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf,
2503 to_string(unsigned long __val)
2504 { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf,
2505 4 * sizeof(unsigned long),
2510 to_string(long long __val)
2511 { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf,
2512 4 * sizeof(long long),
2516 to_string(unsigned long long __val)
2517 { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf,
2518 4 * sizeof(unsigned long long),
2522 to_string(float __val)
2524 const int __n = __numeric_traits<float>::__max_exponent10 + 20;
2525 return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, __n,
2530 to_string(double __val)
2532 const int __n = __numeric_traits<double>::__max_exponent10 + 20;
2533 return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, __n,
2538 to_string(long double __val)
2540 const int __n = __numeric_traits<long double>::__max_exponent10 + 20;
2541 return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, __n,
2545 #ifdef _GLIBCXX_USE_WCHAR_T
2547 stoi(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10)
2548 { return __gnu_cxx::__stoa<long, int>(&std::wcstol, "stoi", __str.c_str(),
2552 stol(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10)
2553 { return __gnu_cxx::__stoa(&std::wcstol, "stol", __str.c_str(),
2556 inline unsigned long
2557 stoul(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10)
2558 { return __gnu_cxx::__stoa(&std::wcstoul, "stoul", __str.c_str(),
2562 stoll(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10)
2563 { return __gnu_cxx::__stoa(&std::wcstoll, "stoll", __str.c_str(),
2566 inline unsigned long long
2567 stoull(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10)
2568 { return __gnu_cxx::__stoa(&std::wcstoull, "stoull", __str.c_str(),
2571 // NB: wcstof vs wcstod.
2573 stof(const __wvstring& __str, std::size_t* __idx = 0)
2574 { return __gnu_cxx::__stoa(&std::wcstof, "stof", __str.c_str(), __idx); }
2577 stod(const __wvstring& __str, std::size_t* __idx = 0)
2578 { return __gnu_cxx::__stoa(&std::wcstod, "stod", __str.c_str(), __idx); }
2581 stold(const __wvstring& __str, std::size_t* __idx = 0)
2582 { return __gnu_cxx::__stoa(&std::wcstold, "stold", __str.c_str(), __idx); }
2584 #ifndef _GLIBCXX_HAVE_BROKEN_VSWPRINTF
2587 to_wstring(int __val)
2588 { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
2593 to_wstring(unsigned __val)
2594 { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
2595 4 * sizeof(unsigned),
2599 to_wstring(long __val)
2600 { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
2605 to_wstring(unsigned long __val)
2606 { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
2607 4 * sizeof(unsigned long),
2611 to_wstring(long long __val)
2612 { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
2613 4 * sizeof(long long),
2617 to_wstring(unsigned long long __val)
2618 { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
2619 4 * sizeof(unsigned long long),
2623 to_wstring(float __val)
2625 const int __n = __numeric_traits<float>::__max_exponent10 + 20;
2626 return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, __n,
2631 to_wstring(double __val)
2633 const int __n = __numeric_traits<double>::__max_exponent10 + 20;
2634 return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, __n,
2639 to_wstring(long double __val)
2641 const int __n = __numeric_traits<long double>::__max_exponent10 + 20;
2642 return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, __n,
2648 _GLIBCXX_END_NAMESPACE
2652 #ifndef _GLIBCXX_EXPORT_TEMPLATE
2653 # include "vstring.tcc"
2656 #endif /* _VSTRING_H */