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)
271 * @brief Set value to string constructed from initializer list.
272 * @param __l std::initializer_list.
275 operator=(std::initializer_list<_CharT> __l)
277 this->assign(__l.begin(), __l.end());
283 * @brief Copy contents of @a __s into this string.
284 * @param __s Source null-terminated string.
287 operator=(const _CharT* __s)
288 { return this->assign(__s); }
291 * @brief Set value to string of length 1.
292 * @param __c Source character.
294 * Assigning to a character makes this string length 1 and
295 * (*this)[0] == @a __c.
298 operator=(_CharT __c)
300 this->assign(1, __c);
306 * Returns a read/write iterator that points to the first character in
307 * the %string. Unshares the string.
313 return iterator(this->_M_data());
317 * Returns a read-only (constant) iterator that points to the first
318 * character in the %string.
322 { return const_iterator(this->_M_data()); }
325 * Returns a read/write iterator that points one past the last
326 * character in the %string. Unshares the string.
332 return iterator(this->_M_data() + this->size());
336 * Returns a read-only (constant) iterator that points one past the
337 * last character in the %string.
341 { return const_iterator(this->_M_data() + this->size()); }
344 * Returns a read/write reverse iterator that points to the last
345 * character in the %string. Iteration is done in reverse element
346 * order. Unshares the string.
350 { return reverse_iterator(this->end()); }
353 * Returns a read-only (constant) reverse iterator that points
354 * to the last character in the %string. Iteration is done in
355 * reverse element order.
357 const_reverse_iterator
359 { return const_reverse_iterator(this->end()); }
362 * Returns a read/write reverse iterator that points to one before the
363 * first character in the %string. Iteration is done in reverse
364 * element order. Unshares the string.
368 { return reverse_iterator(this->begin()); }
371 * Returns a read-only (constant) reverse iterator that points
372 * to one before the first character in the %string. Iteration
373 * is done in reverse element order.
375 const_reverse_iterator
377 { return const_reverse_iterator(this->begin()); }
379 #ifdef __GXX_EXPERIMENTAL_CXX0X__
381 * Returns a read-only (constant) iterator that points to the first
382 * character in the %string.
386 { return const_iterator(this->_M_data()); }
389 * Returns a read-only (constant) iterator that points one past the
390 * last character in the %string.
394 { return const_iterator(this->_M_data() + this->size()); }
397 * Returns a read-only (constant) reverse iterator that points
398 * to the last character in the %string. Iteration is done in
399 * reverse element order.
401 const_reverse_iterator
403 { return const_reverse_iterator(this->end()); }
406 * Returns a read-only (constant) reverse iterator that points
407 * to one before the first character in the %string. Iteration
408 * is done in reverse element order.
410 const_reverse_iterator
412 { return const_reverse_iterator(this->begin()); }
417 /// Returns the number of characters in the string, not including any
418 /// null-termination.
421 { return this->_M_length(); }
423 /// Returns the number of characters in the string, not including any
424 /// null-termination.
427 { return this->_M_length(); }
429 /// Returns the size() of the largest possible %string.
432 { return this->_M_max_size(); }
435 * @brief Resizes the %string to the specified number of characters.
436 * @param __n Number of characters the %string should contain.
437 * @param __c Character to fill any new elements.
439 * This function will %resize the %string to the specified
440 * number of characters. If the number is smaller than the
441 * %string's current size the %string is truncated, otherwise
442 * the %string is extended and new elements are set to @a __c.
445 resize(size_type __n, _CharT __c);
448 * @brief Resizes the %string to the specified number of characters.
449 * @param __n Number of characters the %string should contain.
451 * This function will resize the %string to the specified
452 * length. If the new size is smaller than the %string's
453 * current size the %string is truncated, otherwise the %string
454 * is extended and new characters are default-constructed. For
455 * basic types such as char, this means setting them to 0.
458 resize(size_type __n)
459 { this->resize(__n, _CharT()); }
461 #ifdef __GXX_EXPERIMENTAL_CXX0X__
462 /// A non-binding request to reduce capacity() to size().
467 { this->reserve(0); }
474 * Returns the total number of characters that the %string can
475 * hold before needing to allocate more memory.
479 { return this->_M_capacity(); }
482 * @brief Attempt to preallocate enough memory for specified number of
484 * @param __res_arg Number of characters required.
485 * @throw std::length_error If @a __res_arg exceeds @c max_size().
487 * This function attempts to reserve enough memory for the
488 * %string to hold the specified number of characters. If the
489 * number requested is more than max_size(), length_error is
492 * The advantage of this function is that if optimal code is a
493 * necessity and the user can determine the string length that
494 * will be required, the user can reserve the memory in
495 * %advance, and thus prevent a possible reallocation of memory
496 * and copying of %string data.
499 reserve(size_type __res_arg = 0)
500 { this->_M_reserve(__res_arg); }
503 * Erases the string, making it empty.
507 { this->_M_clear(); }
510 * Returns true if the %string is empty. Equivalent to *this == "".
514 { return this->size() == 0; }
518 * @brief Subscript access to the data contained in the %string.
519 * @param __pos The index of the character to access.
520 * @return Read-only (constant) reference to the character.
522 * This operator allows for easy, array-style, data access.
523 * Note that data access with this operator is unchecked and
524 * out_of_range lookups are not defined. (For checked lookups
528 operator[] (size_type __pos) const
530 _GLIBCXX_DEBUG_ASSERT(__pos <= this->size());
531 return this->_M_data()[__pos];
535 * @brief Subscript access to the data contained in the %string.
536 * @param __pos The index of the character to access.
537 * @return Read/write reference to the character.
539 * This operator allows for easy, array-style, data access.
540 * Note that data access with this operator is unchecked and
541 * out_of_range lookups are not defined. (For checked lookups
542 * see at().) Unshares the string.
545 operator[](size_type __pos)
547 // allow pos == size() as v3 extension:
548 _GLIBCXX_DEBUG_ASSERT(__pos <= this->size());
549 // but be strict in pedantic mode:
550 _GLIBCXX_DEBUG_PEDASSERT(__pos < this->size());
552 return this->_M_data()[__pos];
556 * @brief Provides access to the data contained in the %string.
557 * @param __n The index of the character to access.
558 * @return Read-only (const) reference to the character.
559 * @throw std::out_of_range If @a __n is an invalid index.
561 * This function provides for safer data access. The parameter
562 * is first checked that it is in the range of the string. The
563 * function throws out_of_range if the check fails.
566 at(size_type __n) const
568 if (__n >= this->size())
569 std::__throw_out_of_range(__N("__versa_string::at"));
570 return this->_M_data()[__n];
574 * @brief Provides access to the data contained in the %string.
575 * @param __n The index of the character to access.
576 * @return Read/write reference to the character.
577 * @throw std::out_of_range If @a __n is an invalid index.
579 * This function provides for safer data access. The parameter
580 * is first checked that it is in the range of the string. The
581 * function throws out_of_range if the check fails. Success
582 * results in unsharing the string.
587 if (__n >= this->size())
588 std::__throw_out_of_range(__N("__versa_string::at"));
590 return this->_M_data()[__n];
593 #ifdef __GXX_EXPERIMENTAL_CXX0X__
595 * Returns a read/write reference to the data at the first
596 * element of the %string.
603 * Returns a read-only (constant) reference to the data at the first
604 * element of the %string.
611 * Returns a read/write reference to the data at the last
612 * element of the %string.
616 { return *(end() - 1); }
619 * Returns a read-only (constant) reference to the data at the
620 * last element of the %string.
624 { return *(end() - 1); }
629 * @brief Append a string to this string.
630 * @param __str The string to append.
631 * @return Reference to this string.
634 operator+=(const __versa_string& __str)
635 { return this->append(__str); }
638 * @brief Append a C string.
639 * @param __s The C string to append.
640 * @return Reference to this string.
643 operator+=(const _CharT* __s)
644 { return this->append(__s); }
647 * @brief Append a character.
648 * @param __c The character to append.
649 * @return Reference to this string.
652 operator+=(_CharT __c)
654 this->push_back(__c);
658 #ifdef __GXX_EXPERIMENTAL_CXX0X__
660 * @brief Append an initializer_list of characters.
661 * @param __l The initializer_list of characters to be appended.
662 * @return Reference to this string.
665 operator+=(std::initializer_list<_CharT> __l)
666 { return this->append(__l.begin(), __l.end()); }
667 #endif // __GXX_EXPERIMENTAL_CXX0X__
670 * @brief Append a string to this string.
671 * @param __str The string to append.
672 * @return Reference to this string.
675 append(const __versa_string& __str)
676 { return _M_append(__str._M_data(), __str.size()); }
679 * @brief Append a substring.
680 * @param __str The string to append.
681 * @param __pos Index of the first character of str to append.
682 * @param __n The number of characters to append.
683 * @return Reference to this string.
684 * @throw std::out_of_range if @a pos is not a valid index.
686 * This function appends @a __n characters from @a __str
687 * starting at @a __pos to this string. If @a __n is is larger
688 * than the number of available characters in @a __str, the
689 * remainder of @a __str is appended.
692 append(const __versa_string& __str, size_type __pos, size_type __n)
693 { return _M_append(__str._M_data()
694 + __str._M_check(__pos, "__versa_string::append"),
695 __str._M_limit(__pos, __n)); }
698 * @brief Append a C substring.
699 * @param __s The C string to append.
700 * @param __n The number of characters to append.
701 * @return Reference to this string.
704 append(const _CharT* __s, size_type __n)
706 __glibcxx_requires_string_len(__s, __n);
707 _M_check_length(size_type(0), __n, "__versa_string::append");
708 return _M_append(__s, __n);
712 * @brief Append a C string.
713 * @param __s The C string to append.
714 * @return Reference to this string.
717 append(const _CharT* __s)
719 __glibcxx_requires_string(__s);
720 const size_type __n = traits_type::length(__s);
721 _M_check_length(size_type(0), __n, "__versa_string::append");
722 return _M_append(__s, __n);
726 * @brief Append multiple characters.
727 * @param __n The number of characters to append.
728 * @param __c The character to use.
729 * @return Reference to this string.
731 * Appends n copies of c to this string.
734 append(size_type __n, _CharT __c)
735 { return _M_replace_aux(this->size(), size_type(0), __n, __c); }
737 #ifdef __GXX_EXPERIMENTAL_CXX0X__
739 * @brief Append an initializer_list of characters.
740 * @param __l The initializer_list of characters to append.
741 * @return Reference to this string.
744 append(std::initializer_list<_CharT> __l)
745 { return this->append(__l.begin(), __l.end()); }
746 #endif // __GXX_EXPERIMENTAL_CXX0X__
749 * @brief Append a range of characters.
750 * @param __first Iterator referencing the first character to append.
751 * @param __last Iterator marking the end of the range.
752 * @return Reference to this string.
754 * Appends characters in the range [first,last) to this string.
756 template<class _InputIterator>
758 append(_InputIterator __first, _InputIterator __last)
759 { return this->replace(_M_iend(), _M_iend(), __first, __last); }
762 * @brief Append a single character.
763 * @param __c Character to append.
766 push_back(_CharT __c)
768 const size_type __size = this->size();
769 if (__size + 1 > this->capacity() || this->_M_is_shared())
770 this->_M_mutate(__size, size_type(0), 0, size_type(1));
771 traits_type::assign(this->_M_data()[__size], __c);
772 this->_M_set_length(__size + 1);
776 * @brief Set value to contents of another string.
777 * @param __str Source string to use.
778 * @return Reference to this string.
781 assign(const __versa_string& __str)
783 this->_M_assign(__str);
788 * @brief Set value to a substring of a string.
789 * @param __str The string to use.
790 * @param __pos Index of the first character of str.
791 * @param __n Number of characters to use.
792 * @return Reference to this string.
793 * @throw std::out_of_range if @a __pos is not a valid index.
795 * This function sets this string to the substring of @a __str
796 * consisting of @a __n characters at @a __pos. If @a __n is
797 * is larger than the number of available characters in @a
798 * __str, the remainder of @a __str is used.
801 assign(const __versa_string& __str, size_type __pos, size_type __n)
802 { return _M_replace(size_type(0), this->size(), __str._M_data()
803 + __str._M_check(__pos, "__versa_string::assign"),
804 __str._M_limit(__pos, __n)); }
807 * @brief Set value to a C substring.
808 * @param __s The C string to use.
809 * @param __n Number of characters to use.
810 * @return Reference to this string.
812 * This function sets the value of this string to the first @a
813 * __n characters of @a __s. If @a __n is is larger than the
814 * number of available characters in @a __s, the remainder of
818 assign(const _CharT* __s, size_type __n)
820 __glibcxx_requires_string_len(__s, __n);
821 return _M_replace(size_type(0), this->size(), __s, __n);
825 * @brief Set value to contents of a C string.
826 * @param __s The C string to use.
827 * @return Reference to this string.
829 * This function sets the value of this string to the value of
830 * @a __s. The data is copied, so there is no dependence on @a
831 * __s once the function returns.
834 assign(const _CharT* __s)
836 __glibcxx_requires_string(__s);
837 return _M_replace(size_type(0), this->size(), __s,
838 traits_type::length(__s));
842 * @brief Set value to multiple characters.
843 * @param __n Length of the resulting string.
844 * @param __c The character to use.
845 * @return Reference to this string.
847 * This function sets the value of this string to @a __n copies of
851 assign(size_type __n, _CharT __c)
852 { return _M_replace_aux(size_type(0), this->size(), __n, __c); }
855 * @brief Set value to a range of characters.
856 * @param __first Iterator referencing the first character to append.
857 * @param __last Iterator marking the end of the range.
858 * @return Reference to this string.
860 * Sets value of string to characters in the range
863 template<class _InputIterator>
865 assign(_InputIterator __first, _InputIterator __last)
866 { return this->replace(_M_ibegin(), _M_iend(), __first, __last); }
868 #ifdef __GXX_EXPERIMENTAL_CXX0X__
870 * @brief Set value to an initializer_list of characters.
871 * @param __l The initializer_list of characters to assign.
872 * @return Reference to this string.
875 assign(std::initializer_list<_CharT> __l)
876 { return this->assign(__l.begin(), __l.end()); }
877 #endif // __GXX_EXPERIMENTAL_CXX0X__
880 * @brief Insert multiple characters.
881 * @param __p Iterator referencing location in string to insert at.
882 * @param __n Number of characters to insert
883 * @param __c The character to insert.
884 * @throw std::length_error If new length exceeds @c max_size().
886 * Inserts @a __n copies of character @a __c starting at the
887 * position referenced by iterator @a __p. If adding
888 * characters causes the length to exceed max_size(),
889 * length_error is thrown. The value of the string doesn't
890 * change if an error is thrown.
893 insert(iterator __p, size_type __n, _CharT __c)
894 { this->replace(__p, __p, __n, __c); }
897 * @brief Insert a range of characters.
898 * @param __p Iterator referencing location in string to insert at.
899 * @param __beg Start of range.
900 * @param __end End of range.
901 * @throw std::length_error If new length exceeds @c max_size().
903 * Inserts characters in range [beg,end). If adding characters
904 * causes the length to exceed max_size(), length_error is
905 * thrown. The value of the string doesn't change if an error
908 template<class _InputIterator>
910 insert(iterator __p, _InputIterator __beg, _InputIterator __end)
911 { this->replace(__p, __p, __beg, __end); }
913 #ifdef __GXX_EXPERIMENTAL_CXX0X__
915 * @brief Insert an initializer_list of characters.
916 * @param __p Iterator referencing location in string to insert at.
917 * @param __l The initializer_list of characters to insert.
918 * @throw std::length_error If new length exceeds @c max_size().
921 insert(iterator __p, std::initializer_list<_CharT> __l)
922 { this->insert(__p, __l.begin(), __l.end()); }
923 #endif // __GXX_EXPERIMENTAL_CXX0X__
926 * @brief Insert value of a string.
927 * @param __pos1 Iterator referencing location in string to insert at.
928 * @param __str The string to insert.
929 * @return Reference to this string.
930 * @throw std::length_error If new length exceeds @c max_size().
932 * Inserts value of @a __str starting at @a __pos1. If adding
933 * characters causes the length to exceed max_size(),
934 * length_error is thrown. The value of the string doesn't
935 * change if an error is thrown.
938 insert(size_type __pos1, const __versa_string& __str)
939 { return this->replace(__pos1, size_type(0),
940 __str._M_data(), __str.size()); }
943 * @brief Insert a substring.
944 * @param __pos1 Iterator referencing location in string to insert at.
945 * @param __str The string to insert.
946 * @param __pos2 Start of characters in str to insert.
947 * @param __n Number of characters to insert.
948 * @return Reference to this string.
949 * @throw std::length_error If new length exceeds @c max_size().
950 * @throw std::out_of_range If @a __pos1 > size() or
951 * @a __pos2 > @a __str.size().
953 * Starting at @a __pos1, insert @a __n character of @a __str
954 * beginning with @a __pos2. If adding characters causes the
955 * length to exceed max_size(), length_error is thrown. If @a
956 * __pos1 is beyond the end of this string or @a __pos2 is
957 * beyond the end of @a __str, out_of_range is thrown. The
958 * value of the string doesn't change if an error is thrown.
961 insert(size_type __pos1, const __versa_string& __str,
962 size_type __pos2, size_type __n)
963 { return this->replace(__pos1, size_type(0), __str._M_data()
964 + __str._M_check(__pos2, "__versa_string::insert"),
965 __str._M_limit(__pos2, __n)); }
968 * @brief Insert a C substring.
969 * @param __pos Iterator referencing location in string to insert at.
970 * @param __s The C string to insert.
971 * @param __n The number of characters to insert.
972 * @return Reference to this string.
973 * @throw std::length_error If new length exceeds @c max_size().
974 * @throw std::out_of_range If @a __pos is beyond the end of this
977 * Inserts the first @a __n characters of @a __s starting at @a
978 * __pos. If adding characters causes the length to exceed
979 * max_size(), length_error is thrown. If @a __pos is beyond
980 * end(), out_of_range is thrown. The value of the string
981 * doesn't change if an error is thrown.
984 insert(size_type __pos, const _CharT* __s, size_type __n)
985 { return this->replace(__pos, size_type(0), __s, __n); }
988 * @brief Insert a C string.
989 * @param __pos Iterator referencing location in string to insert at.
990 * @param __s The C string to insert.
991 * @return Reference to this string.
992 * @throw std::length_error If new length exceeds @c max_size().
993 * @throw std::out_of_range If @a __pos is beyond the end of this
996 * Inserts the first @a __n characters of @a __s starting at @a
997 * __pos. If adding characters causes the length to exceed
998 * max_size(), length_error is thrown. If @a __pos is beyond
999 * end(), out_of_range is thrown. The value of the string
1000 * doesn't change if an error is thrown.
1003 insert(size_type __pos, const _CharT* __s)
1005 __glibcxx_requires_string(__s);
1006 return this->replace(__pos, size_type(0), __s,
1007 traits_type::length(__s));
1011 * @brief Insert multiple characters.
1012 * @param __pos Index in string to insert at.
1013 * @param __n Number of characters to insert
1014 * @param __c The character to insert.
1015 * @return Reference to this string.
1016 * @throw std::length_error If new length exceeds @c max_size().
1017 * @throw std::out_of_range If @a __pos is beyond the end of this
1020 * Inserts @a __n copies of character @a __c starting at index
1021 * @a __pos. If adding characters causes the length to exceed
1022 * max_size(), length_error is thrown. If @a __pos > length(),
1023 * out_of_range is thrown. The value of the string doesn't
1024 * change if an error is thrown.
1027 insert(size_type __pos, size_type __n, _CharT __c)
1028 { return _M_replace_aux(_M_check(__pos, "__versa_string::insert"),
1029 size_type(0), __n, __c); }
1032 * @brief Insert one character.
1033 * @param __p Iterator referencing position in string to insert at.
1034 * @param __c The character to insert.
1035 * @return Iterator referencing newly inserted char.
1036 * @throw std::length_error If new length exceeds @c max_size().
1038 * Inserts character @a __c at position referenced by @a __p.
1039 * If adding character causes the length to exceed max_size(),
1040 * length_error is thrown. If @a __p is beyond end of string,
1041 * out_of_range is thrown. The value of the string doesn't
1042 * change if an error is thrown.
1045 insert(iterator __p, _CharT __c)
1047 _GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend());
1048 const size_type __pos = __p - _M_ibegin();
1049 _M_replace_aux(__pos, size_type(0), size_type(1), __c);
1050 this->_M_set_leaked();
1051 return iterator(this->_M_data() + __pos);
1055 * @brief Remove characters.
1056 * @param __pos Index of first character to remove (default 0).
1057 * @param __n Number of characters to remove (default remainder).
1058 * @return Reference to this string.
1059 * @throw std::out_of_range If @a __pos is beyond the end of this
1062 * Removes @a __n characters from this string starting at @a
1063 * __pos. The length of the string is reduced by @a __n. If
1064 * there are < @a __n characters to remove, the remainder of
1065 * the string is truncated. If @a __p is beyond end of string,
1066 * out_of_range is thrown. The value of the string doesn't
1067 * change if an error is thrown.
1070 erase(size_type __pos = 0, size_type __n = npos)
1072 this->_M_erase(_M_check(__pos, "__versa_string::erase"),
1073 _M_limit(__pos, __n));
1078 * @brief Remove one character.
1079 * @param __position Iterator referencing the character to remove.
1080 * @return iterator referencing same location after removal.
1082 * Removes the character at @a __position from this string. The
1083 * value of the string doesn't change if an error is thrown.
1086 erase(iterator __position)
1088 _GLIBCXX_DEBUG_PEDASSERT(__position >= _M_ibegin()
1089 && __position < _M_iend());
1090 const size_type __pos = __position - _M_ibegin();
1091 this->_M_erase(__pos, size_type(1));
1092 this->_M_set_leaked();
1093 return iterator(this->_M_data() + __pos);
1097 * @brief Remove a range of characters.
1098 * @param __first Iterator referencing the first character to remove.
1099 * @param __last Iterator referencing the end of the range.
1100 * @return Iterator referencing location of first after removal.
1102 * Removes the characters in the range [first,last) from this
1103 * string. The value of the string doesn't change if an error
1107 erase(iterator __first, iterator __last)
1109 _GLIBCXX_DEBUG_PEDASSERT(__first >= _M_ibegin() && __first <= __last
1110 && __last <= _M_iend());
1111 const size_type __pos = __first - _M_ibegin();
1112 this->_M_erase(__pos, __last - __first);
1113 this->_M_set_leaked();
1114 return iterator(this->_M_data() + __pos);
1118 * @brief Replace characters with value from another string.
1119 * @param __pos Index of first character to replace.
1120 * @param __n Number of characters to be replaced.
1121 * @param __str String to insert.
1122 * @return Reference to this string.
1123 * @throw std::out_of_range If @a __pos is beyond the end of this
1125 * @throw std::length_error If new length exceeds @c max_size().
1127 * Removes the characters in the range [pos,pos+n) from this
1128 * string. In place, the value of @a __str is inserted. If @a
1129 * __pos is beyond end of string, out_of_range is thrown. If
1130 * the length of the result exceeds max_size(), length_error is
1131 * thrown. The value of the string doesn't change if an error
1135 replace(size_type __pos, size_type __n, const __versa_string& __str)
1136 { return this->replace(__pos, __n, __str._M_data(), __str.size()); }
1139 * @brief Replace characters with value from another string.
1140 * @param __pos1 Index of first character to replace.
1141 * @param __n1 Number of characters to be replaced.
1142 * @param __str String to insert.
1143 * @param __pos2 Index of first character of str to use.
1144 * @param __n2 Number of characters from str to use.
1145 * @return Reference to this string.
1146 * @throw std::out_of_range If @a __pos1 > size() or @a __pos2 >
1148 * @throw std::length_error If new length exceeds @c max_size().
1150 * Removes the characters in the range [pos1,pos1 + n) from
1151 * this string. In place, the value of @a __str is inserted.
1152 * If @a __pos is beyond end of string, out_of_range is thrown.
1153 * If the length of the result exceeds max_size(), length_error
1154 * is thrown. The value of the string doesn't change if an
1158 replace(size_type __pos1, size_type __n1, const __versa_string& __str,
1159 size_type __pos2, size_type __n2)
1161 return this->replace(__pos1, __n1, __str._M_data()
1162 + __str._M_check(__pos2,
1163 "__versa_string::replace"),
1164 __str._M_limit(__pos2, __n2));
1168 * @brief Replace characters with value of a C substring.
1169 * @param __pos Index of first character to replace.
1170 * @param __n1 Number of characters to be replaced.
1171 * @param __s C string to insert.
1172 * @param __n2 Number of characters from @a __s to use.
1173 * @return Reference to this string.
1174 * @throw std::out_of_range If @a __pos1 > size().
1175 * @throw std::length_error If new length exceeds @c max_size().
1177 * Removes the characters in the range [pos,pos + n1) from this
1178 * string. In place, the first @a __n2 characters of @a __s
1179 * are inserted, or all of @a __s if @a __n2 is too large. If
1180 * @a __pos is beyond end of string, out_of_range is thrown.
1181 * If the length of result exceeds max_size(), length_error is
1182 * thrown. The value of the string doesn't change if an error
1186 replace(size_type __pos, size_type __n1, const _CharT* __s,
1189 __glibcxx_requires_string_len(__s, __n2);
1190 return _M_replace(_M_check(__pos, "__versa_string::replace"),
1191 _M_limit(__pos, __n1), __s, __n2);
1195 * @brief Replace characters with value of a C string.
1196 * @param __pos Index of first character to replace.
1197 * @param __n1 Number of characters to be replaced.
1198 * @param __s C string to insert.
1199 * @return Reference to this string.
1200 * @throw std::out_of_range If @a __pos > size().
1201 * @throw std::length_error If new length exceeds @c max_size().
1203 * Removes the characters in the range [pos,pos + n1) from this
1204 * string. In place, the first @a __n characters of @a __s are
1205 * inserted. If @a pos is beyond end of string, out_of_range
1206 * is thrown. If the length of result exceeds max_size(),
1207 * length_error is thrown. The value of the string doesn't
1208 * change if an error is thrown.
1211 replace(size_type __pos, size_type __n1, const _CharT* __s)
1213 __glibcxx_requires_string(__s);
1214 return this->replace(__pos, __n1, __s, traits_type::length(__s));
1218 * @brief Replace characters with multiple characters.
1219 * @param __pos Index of first character to replace.
1220 * @param __n1 Number of characters to be replaced.
1221 * @param __n2 Number of characters to insert.
1222 * @param __c Character to insert.
1223 * @return Reference to this string.
1224 * @throw std::out_of_range If @a __pos > size().
1225 * @throw std::length_error If new length exceeds @c max_size().
1227 * Removes the characters in the range [pos,pos + n1) from this
1228 * string. In place, @a __n2 copies of @a __c are inserted.
1229 * If @a __pos is beyond end of string, out_of_range is thrown.
1230 * If the length of result exceeds max_size(), length_error is
1231 * thrown. The value of the string doesn't change if an error
1235 replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
1236 { return _M_replace_aux(_M_check(__pos, "__versa_string::replace"),
1237 _M_limit(__pos, __n1), __n2, __c); }
1240 * @brief Replace range of characters with string.
1241 * @param __i1 Iterator referencing start of range to replace.
1242 * @param __i2 Iterator referencing end of range to replace.
1243 * @param __str String value to insert.
1244 * @return Reference to this string.
1245 * @throw std::length_error If new length exceeds @c max_size().
1247 * Removes the characters in the range [i1,i2). In place, the
1248 * value of @a __str is inserted. If the length of result
1249 * exceeds max_size(), length_error is thrown. The value of
1250 * the string doesn't change if an error is thrown.
1253 replace(iterator __i1, iterator __i2, const __versa_string& __str)
1254 { return this->replace(__i1, __i2, __str._M_data(), __str.size()); }
1257 * @brief Replace range of characters with C substring.
1258 * @param __i1 Iterator referencing start of range to replace.
1259 * @param __i2 Iterator referencing end of range to replace.
1260 * @param __s C string value to insert.
1261 * @param __n Number of characters from s to insert.
1262 * @return Reference to this string.
1263 * @throw std::length_error If new length exceeds @c max_size().
1265 * Removes the characters in the range [i1,i2). In place, the
1266 * first @a n characters of @a __s are inserted. If the length
1267 * of result exceeds max_size(), length_error is thrown. The
1268 * value of the string doesn't change if an error is thrown.
1271 replace(iterator __i1, iterator __i2, const _CharT* __s, size_type __n)
1273 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1274 && __i2 <= _M_iend());
1275 return this->replace(__i1 - _M_ibegin(), __i2 - __i1, __s, __n);
1279 * @brief Replace range of characters with C string.
1280 * @param __i1 Iterator referencing start of range to replace.
1281 * @param __i2 Iterator referencing end of range to replace.
1282 * @param __s C string value to insert.
1283 * @return Reference to this string.
1284 * @throw std::length_error If new length exceeds @c max_size().
1286 * Removes the characters in the range [i1,i2). In place, the
1287 * characters of @a __s are inserted. If the length of result
1288 * exceeds max_size(), length_error is thrown. The value of
1289 * the string doesn't change if an error is thrown.
1292 replace(iterator __i1, iterator __i2, const _CharT* __s)
1294 __glibcxx_requires_string(__s);
1295 return this->replace(__i1, __i2, __s, traits_type::length(__s));
1299 * @brief Replace range of characters with multiple characters
1300 * @param __i1 Iterator referencing start of range to replace.
1301 * @param __i2 Iterator referencing end of range to replace.
1302 * @param __n Number of characters to insert.
1303 * @param __c Character to insert.
1304 * @return Reference to this string.
1305 * @throw std::length_error If new length exceeds @c max_size().
1307 * Removes the characters in the range [i1,i2). In place, @a
1308 * __n copies of @a __c are inserted. If the length of result
1309 * exceeds max_size(), length_error is thrown. The value of
1310 * the string doesn't change if an error is thrown.
1313 replace(iterator __i1, iterator __i2, size_type __n, _CharT __c)
1315 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1316 && __i2 <= _M_iend());
1317 return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __c);
1321 * @brief Replace range of characters with range.
1322 * @param __i1 Iterator referencing start of range to replace.
1323 * @param __i2 Iterator referencing end of range to replace.
1324 * @param __k1 Iterator referencing start of range to insert.
1325 * @param __k2 Iterator referencing end of range to insert.
1326 * @return Reference to this string.
1327 * @throw std::length_error If new length exceeds @c max_size().
1329 * Removes the characters in the range [i1,i2). In place,
1330 * characters in the range [k1,k2) are inserted. If the length
1331 * of result exceeds max_size(), length_error is thrown. The
1332 * value of the string doesn't change if an error is thrown.
1334 template<class _InputIterator>
1336 replace(iterator __i1, iterator __i2,
1337 _InputIterator __k1, _InputIterator __k2)
1339 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1340 && __i2 <= _M_iend());
1341 __glibcxx_requires_valid_range(__k1, __k2);
1342 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
1343 return _M_replace_dispatch(__i1, __i2, __k1, __k2, _Integral());
1346 // Specializations for the common case of pointer and iterator:
1347 // useful to avoid the overhead of temporary buffering in _M_replace.
1349 replace(iterator __i1, iterator __i2, _CharT* __k1, _CharT* __k2)
1351 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1352 && __i2 <= _M_iend());
1353 __glibcxx_requires_valid_range(__k1, __k2);
1354 return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
1359 replace(iterator __i1, iterator __i2,
1360 const _CharT* __k1, const _CharT* __k2)
1362 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1363 && __i2 <= _M_iend());
1364 __glibcxx_requires_valid_range(__k1, __k2);
1365 return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
1370 replace(iterator __i1, iterator __i2, iterator __k1, iterator __k2)
1372 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1373 && __i2 <= _M_iend());
1374 __glibcxx_requires_valid_range(__k1, __k2);
1375 return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
1376 __k1.base(), __k2 - __k1);
1380 replace(iterator __i1, iterator __i2,
1381 const_iterator __k1, const_iterator __k2)
1383 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1384 && __i2 <= _M_iend());
1385 __glibcxx_requires_valid_range(__k1, __k2);
1386 return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
1387 __k1.base(), __k2 - __k1);
1390 #ifdef __GXX_EXPERIMENTAL_CXX0X__
1392 * @brief Replace range of characters with initializer_list.
1393 * @param __i1 Iterator referencing start of range to replace.
1394 * @param __i2 Iterator referencing end of range to replace.
1395 * @param __l The initializer_list of characters to insert.
1396 * @return Reference to this string.
1397 * @throw std::length_error If new length exceeds @c max_size().
1399 * Removes the characters in the range [i1,i2). In place,
1400 * characters in the range [k1,k2) are inserted. If the length
1401 * of result exceeds max_size(), length_error is thrown. The
1402 * value of the string doesn't change if an error is thrown.
1404 __versa_string& replace(iterator __i1, iterator __i2,
1405 std::initializer_list<_CharT> __l)
1406 { return this->replace(__i1, __i2, __l.begin(), __l.end()); }
1407 #endif // __GXX_EXPERIMENTAL_CXX0X__
1410 template<class _Integer>
1412 _M_replace_dispatch(iterator __i1, iterator __i2, _Integer __n,
1413 _Integer __val, std::__true_type)
1414 { return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __val); }
1416 template<class _InputIterator>
1418 _M_replace_dispatch(iterator __i1, iterator __i2, _InputIterator __k1,
1419 _InputIterator __k2, std::__false_type);
1422 _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2,
1426 _M_replace(size_type __pos, size_type __len1, const _CharT* __s,
1427 const size_type __len2);
1430 _M_append(const _CharT* __s, size_type __n);
1435 * @brief Copy substring into C string.
1436 * @param __s C string to copy value into.
1437 * @param __n Number of characters to copy.
1438 * @param __pos Index of first character to copy.
1439 * @return Number of characters actually copied
1440 * @throw std::out_of_range If pos > size().
1442 * Copies up to @a __n characters starting at @a __pos into the
1443 * C string @a s. If @a __pos is greater than size(),
1444 * out_of_range is thrown.
1447 copy(_CharT* __s, size_type __n, size_type __pos = 0) const;
1450 * @brief Swap contents with another string.
1451 * @param __s String to swap with.
1453 * Exchanges the contents of this string with that of @a __s in
1457 swap(__versa_string& __s)
1458 { this->_M_swap(__s); }
1460 // String operations:
1462 * @brief Return const pointer to null-terminated contents.
1464 * This is a handle to internal data. Do not modify or dire things may
1469 { return this->_M_data(); }
1472 * @brief Return const pointer to contents.
1474 * This is a handle to internal data. Do not modify or dire things may
1479 { return this->_M_data(); }
1482 * @brief Return copy of allocator used to construct this string.
1485 get_allocator() const
1486 { return allocator_type(this->_M_get_allocator()); }
1489 * @brief Find position of a C substring.
1490 * @param __s C string to locate.
1491 * @param __pos Index of character to search from.
1492 * @param __n Number of characters from @a __s to search for.
1493 * @return Index of start of first occurrence.
1495 * Starting from @a __pos, searches forward for the first @a
1496 * __n characters in @a __s within this string. If found,
1497 * returns the index where it begins. If not found, returns
1501 find(const _CharT* __s, size_type __pos, size_type __n) const;
1504 * @brief Find position of a string.
1505 * @param __str String to locate.
1506 * @param __pos Index of character to search from (default 0).
1507 * @return Index of start of first occurrence.
1509 * Starting from @a __pos, searches forward for value of @a
1510 * __str within this string. If found, returns the index where
1511 * it begins. If not found, returns npos.
1514 find(const __versa_string& __str, size_type __pos = 0) const
1515 { return this->find(__str.data(), __pos, __str.size()); }
1518 * @brief Find position of a C string.
1519 * @param __s C string to locate.
1520 * @param __pos Index of character to search from (default 0).
1521 * @return Index of start of first occurrence.
1523 * Starting from @a __pos, searches forward for the value of @a
1524 * __s within this string. If found, returns the index where
1525 * it begins. If not found, returns npos.
1528 find(const _CharT* __s, size_type __pos = 0) const
1530 __glibcxx_requires_string(__s);
1531 return this->find(__s, __pos, traits_type::length(__s));
1535 * @brief Find position of a character.
1536 * @param __c Character to locate.
1537 * @param __pos Index of character to search from (default 0).
1538 * @return Index of first occurrence.
1540 * Starting from @a __pos, searches forward for @a __c within
1541 * this string. If found, returns the index where it was
1542 * found. If not found, returns npos.
1545 find(_CharT __c, size_type __pos = 0) const;
1548 * @brief Find last position of a string.
1549 * @param __str String to locate.
1550 * @param __pos Index of character to search back from (default end).
1551 * @return Index of start of last occurrence.
1553 * Starting from @a __pos, searches backward for value of @a
1554 * __str within this string. If found, returns the index where
1555 * it begins. If not found, returns npos.
1558 rfind(const __versa_string& __str, size_type __pos = npos) const
1559 { return this->rfind(__str.data(), __pos, __str.size()); }
1562 * @brief Find last position of a C substring.
1563 * @param __s C string to locate.
1564 * @param __pos Index of character to search back from.
1565 * @param __n Number of characters from s to search for.
1566 * @return Index of start of last occurrence.
1568 * Starting from @a __pos, searches backward for the first @a
1569 * __n characters in @a __s within this string. If found,
1570 * returns the index where it begins. If not found, returns
1574 rfind(const _CharT* __s, size_type __pos, size_type __n) const;
1577 * @brief Find last position of a C string.
1578 * @param __s C string to locate.
1579 * @param __pos Index of character to start search at (default end).
1580 * @return Index of start of last occurrence.
1582 * Starting from @a __pos, searches backward for the value of
1583 * @a __s within this string. If found, returns the index
1584 * where it begins. If not found, returns npos.
1587 rfind(const _CharT* __s, size_type __pos = npos) const
1589 __glibcxx_requires_string(__s);
1590 return this->rfind(__s, __pos, traits_type::length(__s));
1594 * @brief Find last position of a character.
1595 * @param __c Character to locate.
1596 * @param __pos Index of character to search back from (default end).
1597 * @return Index of last occurrence.
1599 * Starting from @a __pos, searches backward for @a __c within
1600 * this string. If found, returns the index where it was
1601 * found. If not found, returns npos.
1604 rfind(_CharT __c, size_type __pos = npos) const;
1607 * @brief Find position of a character of string.
1608 * @param __str String containing characters to locate.
1609 * @param __pos Index of character to search from (default 0).
1610 * @return Index of first occurrence.
1612 * Starting from @a __pos, searches forward for one of the characters of
1613 * @a __str within this string. If found, returns the index where it was
1614 * found. If not found, returns npos.
1617 find_first_of(const __versa_string& __str, size_type __pos = 0) const
1618 { return this->find_first_of(__str.data(), __pos, __str.size()); }
1621 * @brief Find position of a character of C substring.
1622 * @param __s String containing characters to locate.
1623 * @param __pos Index of character to search from.
1624 * @param __n Number of characters from s to search for.
1625 * @return Index of first occurrence.
1627 * Starting from @a __pos, searches forward for one of the
1628 * first @a __n characters of @a __s within this string. If
1629 * found, returns the index where it was found. If not found,
1633 find_first_of(const _CharT* __s, size_type __pos, size_type __n) const;
1636 * @brief Find position of a character of C string.
1637 * @param __s String containing characters to locate.
1638 * @param __pos Index of character to search from (default 0).
1639 * @return Index of first occurrence.
1641 * Starting from @a __pos, searches forward for one of the
1642 * characters of @a __s within this string. If found, returns
1643 * the index where it was found. If not found, returns npos.
1646 find_first_of(const _CharT* __s, size_type __pos = 0) const
1648 __glibcxx_requires_string(__s);
1649 return this->find_first_of(__s, __pos, traits_type::length(__s));
1653 * @brief Find position of a character.
1654 * @param __c Character to locate.
1655 * @param __pos Index of character to search from (default 0).
1656 * @return Index of first occurrence.
1658 * Starting from @a __pos, searches forward for the character
1659 * @a __c within this string. If found, returns the index
1660 * where it was found. If not found, returns npos.
1662 * Note: equivalent to find(c, pos).
1665 find_first_of(_CharT __c, size_type __pos = 0) const
1666 { return this->find(__c, __pos); }
1669 * @brief Find last position of a character of string.
1670 * @param __str String containing characters to locate.
1671 * @param __pos Index of character to search back from (default end).
1672 * @return Index of last occurrence.
1674 * Starting from @a __pos, searches backward for one of the
1675 * characters of @a __str within this string. If found,
1676 * returns the index where it was found. If not found, returns
1680 find_last_of(const __versa_string& __str, size_type __pos = npos) const
1681 { return this->find_last_of(__str.data(), __pos, __str.size()); }
1684 * @brief Find last position of a character of C substring.
1685 * @param __s C string containing characters to locate.
1686 * @param __pos Index of character to search back from.
1687 * @param __n Number of characters from s to search for.
1688 * @return Index of last occurrence.
1690 * Starting from @a __pos, searches backward for one of the
1691 * first @a __n characters of @a __s within this string. If
1692 * found, returns the index where it was found. If not found,
1696 find_last_of(const _CharT* __s, size_type __pos, size_type __n) const;
1699 * @brief Find last position of a character of C string.
1700 * @param __s C string containing characters to locate.
1701 * @param __pos Index of character to search back from (default end).
1702 * @return Index of last occurrence.
1704 * Starting from @a __pos, searches backward for one of the
1705 * characters of @a __s within this string. If found, returns
1706 * the index where it was found. If not found, returns npos.
1709 find_last_of(const _CharT* __s, size_type __pos = npos) const
1711 __glibcxx_requires_string(__s);
1712 return this->find_last_of(__s, __pos, traits_type::length(__s));
1716 * @brief Find last position of a character.
1717 * @param __c Character to locate.
1718 * @param __pos Index of character to search back from (default end).
1719 * @return Index of last occurrence.
1721 * Starting from @a __pos, searches backward for @a __c within
1722 * this string. If found, returns the index where it was
1723 * found. If not found, returns npos.
1725 * Note: equivalent to rfind(c, pos).
1728 find_last_of(_CharT __c, size_type __pos = npos) const
1729 { return this->rfind(__c, __pos); }
1732 * @brief Find position of a character not in string.
1733 * @param __str String containing characters to avoid.
1734 * @param __pos Index of character to search from (default 0).
1735 * @return Index of first occurrence.
1737 * Starting from @a __pos, searches forward for a character not
1738 * contained in @a __str within this string. If found, returns
1739 * the index where it was found. If not found, returns npos.
1742 find_first_not_of(const __versa_string& __str, size_type __pos = 0) const
1743 { return this->find_first_not_of(__str.data(), __pos, __str.size()); }
1746 * @brief Find position of a character not in C substring.
1747 * @param __s C string containing characters to avoid.
1748 * @param __pos Index of character to search from.
1749 * @param __n Number of characters from s to consider.
1750 * @return Index of first occurrence.
1752 * Starting from @a __pos, searches forward for a character not
1753 * contained in the first @a __n characters of @a __s within
1754 * this string. If found, returns the index where it was
1755 * found. If not found, returns npos.
1758 find_first_not_of(const _CharT* __s, size_type __pos,
1759 size_type __n) const;
1762 * @brief Find position of a character not in C string.
1763 * @param __s C string containing characters to avoid.
1764 * @param __pos Index of character to search from (default 0).
1765 * @return Index of first occurrence.
1767 * Starting from @a __pos, searches forward for a character not
1768 * contained in @a __s within this string. If found, returns
1769 * the index where it was found. If not found, returns npos.
1772 find_first_not_of(const _CharT* __s, size_type __pos = 0) const
1774 __glibcxx_requires_string(__s);
1775 return this->find_first_not_of(__s, __pos, traits_type::length(__s));
1779 * @brief Find position of a different character.
1780 * @param __c Character to avoid.
1781 * @param __pos Index of character to search from (default 0).
1782 * @return Index of first occurrence.
1784 * Starting from @a __pos, searches forward for a character
1785 * other than @a __c within this string. If found, returns the
1786 * index where it was found. If not found, returns npos.
1789 find_first_not_of(_CharT __c, size_type __pos = 0) const;
1792 * @brief Find last position of a character not in string.
1793 * @param __str String containing characters to avoid.
1794 * @param __pos Index of character to search back from (default end).
1795 * @return Index of last occurrence.
1797 * Starting from @a __pos, searches backward for a character
1798 * not contained in @a __str within this string. If found,
1799 * returns the index where it was found. If not found, returns
1803 find_last_not_of(const __versa_string& __str,
1804 size_type __pos = npos) const
1805 { return this->find_last_not_of(__str.data(), __pos, __str.size()); }
1808 * @brief Find last position of a character not in C substring.
1809 * @param __s C string containing characters to avoid.
1810 * @param __pos Index of character to search back from.
1811 * @param __n Number of characters from s to consider.
1812 * @return Index of last occurrence.
1814 * Starting from @a __pos, searches backward for a character
1815 * not contained in the first @a __n characters of @a __s
1816 * within this string. If found, returns the index where it
1817 * was found. If not found, returns npos.
1820 find_last_not_of(const _CharT* __s, size_type __pos,
1821 size_type __n) const;
1823 * @brief Find last position of a character not in C string.
1824 * @param __s C string containing characters to avoid.
1825 * @param __pos Index of character to search back from (default end).
1826 * @return Index of last occurrence.
1828 * Starting from @a __pos, searches backward for a character
1829 * not contained in @a __s within this string. If found,
1830 * returns the index where it was found. If not found, returns
1834 find_last_not_of(const _CharT* __s, size_type __pos = npos) const
1836 __glibcxx_requires_string(__s);
1837 return this->find_last_not_of(__s, __pos, traits_type::length(__s));
1841 * @brief Find last position of a different character.
1842 * @param __c Character to avoid.
1843 * @param __pos Index of character to search back from (default end).
1844 * @return Index of last occurrence.
1846 * Starting from @a __pos, searches backward for a character
1847 * other than @a __c within this string. If found, returns the
1848 * index where it was found. If not found, returns npos.
1851 find_last_not_of(_CharT __c, size_type __pos = npos) const;
1854 * @brief Get a substring.
1855 * @param __pos Index of first character (default 0).
1856 * @param __n Number of characters in substring (default remainder).
1857 * @return The new string.
1858 * @throw std::out_of_range If pos > size().
1860 * Construct and return a new string using the @a __n
1861 * characters starting at @a __pos. If the string is too
1862 * short, use the remainder of the characters. If @a __pos is
1863 * beyond the end of the string, out_of_range is thrown.
1866 substr(size_type __pos = 0, size_type __n = npos) const
1868 return __versa_string(*this, _M_check(__pos, "__versa_string::substr"),
1873 * @brief Compare to a string.
1874 * @param __str String to compare against.
1875 * @return Integer < 0, 0, or > 0.
1877 * Returns an integer < 0 if this string is ordered before @a
1878 * __str, 0 if their values are equivalent, or > 0 if this
1879 * string is ordered after @a __str. Determines the effective
1880 * length rlen of the strings to compare as the smallest of
1881 * size() and str.size(). The function then compares the two
1882 * strings by calling traits::compare(data(), str.data(),rlen).
1883 * If the result of the comparison is nonzero returns it,
1884 * otherwise the shorter one is ordered first.
1887 compare(const __versa_string& __str) const
1889 if (this->_M_compare(__str))
1892 const size_type __size = this->size();
1893 const size_type __osize = __str.size();
1894 const size_type __len = std::min(__size, __osize);
1896 int __r = traits_type::compare(this->_M_data(), __str.data(), __len);
1898 __r = _S_compare(__size, __osize);
1903 * @brief Compare substring to a string.
1904 * @param __pos Index of first character of substring.
1905 * @param __n Number of characters in substring.
1906 * @param __str String to compare against.
1907 * @return Integer < 0, 0, or > 0.
1909 * Form the substring of this string from the @a __n characters
1910 * starting at @a __pos. Returns an integer < 0 if the
1911 * substring is ordered before @a __str, 0 if their values are
1912 * equivalent, or > 0 if the substring is ordered after @a
1913 * __str. Determines the effective length rlen of the strings
1914 * to compare as the smallest of the length of the substring
1915 * and @a __str.size(). The function then compares the two
1916 * strings by calling
1917 * traits::compare(substring.data(),str.data(),rlen). If the
1918 * result of the comparison is nonzero returns it, otherwise
1919 * the shorter one is ordered first.
1922 compare(size_type __pos, size_type __n,
1923 const __versa_string& __str) const;
1926 * @brief Compare substring to a substring.
1927 * @param __pos1 Index of first character of substring.
1928 * @param __n1 Number of characters in substring.
1929 * @param __str String to compare against.
1930 * @param __pos2 Index of first character of substring of str.
1931 * @param __n2 Number of characters in substring of str.
1932 * @return Integer < 0, 0, or > 0.
1934 * Form the substring of this string from the @a __n1
1935 * characters starting at @a __pos1. Form the substring of @a
1936 * __str from the @a __n2 characters starting at @a __pos2.
1937 * Returns an integer < 0 if this substring is ordered before
1938 * the substring of @a __str, 0 if their values are equivalent,
1939 * or > 0 if this substring is ordered after the substring of
1940 * @a __str. Determines the effective length rlen of the
1941 * strings to compare as the smallest of the lengths of the
1942 * substrings. The function then compares the two strings by
1944 * traits::compare(substring.data(),str.substr(pos2,n2).data(),rlen).
1945 * If the result of the comparison is nonzero returns it,
1946 * otherwise the shorter one is ordered first.
1949 compare(size_type __pos1, size_type __n1, const __versa_string& __str,
1950 size_type __pos2, size_type __n2) const;
1953 * @brief Compare to a C string.
1954 * @param __s C string to compare against.
1955 * @return Integer < 0, 0, or > 0.
1957 * Returns an integer < 0 if this string is ordered before @a
1958 * __s, 0 if their values are equivalent, or > 0 if this string
1959 * is ordered after @a __s. Determines the effective length
1960 * rlen of the strings to compare as the smallest of size() and
1961 * the length of a string constructed from @a __s. The
1962 * function then compares the two strings by calling
1963 * traits::compare(data(),s,rlen). If the result of the
1964 * comparison is nonzero returns it, otherwise the shorter one
1968 compare(const _CharT* __s) const;
1970 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1971 // 5 String::compare specification questionable
1973 * @brief Compare substring to a C string.
1974 * @param __pos Index of first character of substring.
1975 * @param __n1 Number of characters in substring.
1976 * @param __s C string to compare against.
1977 * @return Integer < 0, 0, or > 0.
1979 * Form the substring of this string from the @a __n1
1980 * characters starting at @a __pos. Returns an integer < 0 if
1981 * the substring is ordered before @a __s, 0 if their values
1982 * are equivalent, or > 0 if the substring is ordered after @a
1983 * __s. Determines the effective length rlen of the strings to
1984 * compare as the smallest of the length of the substring and
1985 * the length of a string constructed from @a __s. The
1986 * function then compares the two string by calling
1987 * traits::compare(substring.data(),s,rlen). If the result of
1988 * the comparison is nonzero returns it, otherwise the shorter
1989 * one is ordered first.
1992 compare(size_type __pos, size_type __n1, const _CharT* __s) const;
1995 * @brief Compare substring against a character array.
1996 * @param __pos1 Index of first character of substring.
1997 * @param __n1 Number of characters in substring.
1998 * @param __s character array to compare against.
1999 * @param __n2 Number of characters of s.
2000 * @return Integer < 0, 0, or > 0.
2002 * Form the substring of this string from the @a __n1
2003 * characters starting at @a __pos1. Form a string from the
2004 * first @a __n2 characters of @a __s. Returns an integer < 0
2005 * if this substring is ordered before the string from @a __s,
2006 * 0 if their values are equivalent, or > 0 if this substring
2007 * is ordered after the string from @a __s. Determines the
2008 * effective length rlen of the strings to compare as the
2009 * smallest of the length of the substring and @a __n2. The
2010 * function then compares the two strings by calling
2011 * traits::compare(substring.data(),s,rlen). If the result of
2012 * the comparison is nonzero returns it, otherwise the shorter
2013 * one is ordered first.
2015 * NB: s must have at least n2 characters, '\\0' has no special
2019 compare(size_type __pos, size_type __n1, const _CharT* __s,
2020 size_type __n2) const;
2025 * @brief Concatenate two strings.
2026 * @param __lhs First string.
2027 * @param __rhs Last string.
2028 * @return New string with value of @a __lhs followed by @a __rhs.
2030 template<typename _CharT, typename _Traits, typename _Alloc,
2031 template <typename, typename, typename> class _Base>
2032 __versa_string<_CharT, _Traits, _Alloc, _Base>
2033 operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2034 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs);
2037 * @brief Concatenate C string and string.
2038 * @param __lhs First string.
2039 * @param __rhs Last string.
2040 * @return New string with value of @a __lhs followed by @a __rhs.
2042 template<typename _CharT, typename _Traits, typename _Alloc,
2043 template <typename, typename, typename> class _Base>
2044 __versa_string<_CharT, _Traits, _Alloc, _Base>
2045 operator+(const _CharT* __lhs,
2046 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs);
2049 * @brief Concatenate character and string.
2050 * @param __lhs First string.
2051 * @param __rhs Last string.
2052 * @return New string with @a __lhs followed by @a __rhs.
2054 template<typename _CharT, typename _Traits, typename _Alloc,
2055 template <typename, typename, typename> class _Base>
2056 __versa_string<_CharT, _Traits, _Alloc, _Base>
2057 operator+(_CharT __lhs,
2058 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs);
2061 * @brief Concatenate string and C string.
2062 * @param __lhs First string.
2063 * @param __rhs Last string.
2064 * @return New string with @a __lhs followed by @a __rhs.
2066 template<typename _CharT, typename _Traits, typename _Alloc,
2067 template <typename, typename, typename> class _Base>
2068 __versa_string<_CharT, _Traits, _Alloc, _Base>
2069 operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2070 const _CharT* __rhs);
2073 * @brief Concatenate string and character.
2074 * @param __lhs First string.
2075 * @param __rhs Last string.
2076 * @return New string with @a __lhs followed by @a __rhs.
2078 template<typename _CharT, typename _Traits, typename _Alloc,
2079 template <typename, typename, typename> class _Base>
2080 __versa_string<_CharT, _Traits, _Alloc, _Base>
2081 operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2086 * @brief Test equivalence of two strings.
2087 * @param __lhs First string.
2088 * @param __rhs Second string.
2089 * @return True if @a __lhs.compare(@a __rhs) == 0. False otherwise.
2091 template<typename _CharT, typename _Traits, typename _Alloc,
2092 template <typename, typename, typename> class _Base>
2094 operator==(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2095 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2096 { return __lhs.compare(__rhs) == 0; }
2098 template<typename _CharT,
2099 template <typename, typename, typename> class _Base>
2100 inline typename __enable_if<std::__is_char<_CharT>::__value, bool>::__type
2101 operator==(const __versa_string<_CharT, std::char_traits<_CharT>,
2102 std::allocator<_CharT>, _Base>& __lhs,
2103 const __versa_string<_CharT, std::char_traits<_CharT>,
2104 std::allocator<_CharT>, _Base>& __rhs)
2105 { return (__lhs.size() == __rhs.size()
2106 && !std::char_traits<_CharT>::compare(__lhs.data(), __rhs.data(),
2110 * @brief Test equivalence of C string and string.
2111 * @param __lhs C string.
2112 * @param __rhs String.
2113 * @return True if @a __rhs.compare(@a __lhs) == 0. False otherwise.
2115 template<typename _CharT, typename _Traits, typename _Alloc,
2116 template <typename, typename, typename> class _Base>
2118 operator==(const _CharT* __lhs,
2119 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2120 { return __rhs.compare(__lhs) == 0; }
2123 * @brief Test equivalence of string and C string.
2124 * @param __lhs String.
2125 * @param __rhs C string.
2126 * @return True if @a __lhs.compare(@a __rhs) == 0. False otherwise.
2128 template<typename _CharT, typename _Traits, typename _Alloc,
2129 template <typename, typename, typename> class _Base>
2131 operator==(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2132 const _CharT* __rhs)
2133 { return __lhs.compare(__rhs) == 0; }
2137 * @brief Test difference of two strings.
2138 * @param __lhs First string.
2139 * @param __rhs Second string.
2140 * @return True if @a __lhs.compare(@a __rhs) != 0. False otherwise.
2142 template<typename _CharT, typename _Traits, typename _Alloc,
2143 template <typename, typename, typename> class _Base>
2145 operator!=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2146 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2147 { return !(__lhs == __rhs); }
2150 * @brief Test difference of C string and string.
2151 * @param __lhs C string.
2152 * @param __rhs String.
2153 * @return True if @a __rhs.compare(@a __lhs) != 0. False otherwise.
2155 template<typename _CharT, typename _Traits, typename _Alloc,
2156 template <typename, typename, typename> class _Base>
2158 operator!=(const _CharT* __lhs,
2159 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2160 { return !(__lhs == __rhs); }
2163 * @brief Test difference of string and C string.
2164 * @param __lhs String.
2165 * @param __rhs C string.
2166 * @return True if @a __lhs.compare(@a __rhs) != 0. False otherwise.
2168 template<typename _CharT, typename _Traits, typename _Alloc,
2169 template <typename, typename, typename> class _Base>
2171 operator!=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2172 const _CharT* __rhs)
2173 { return !(__lhs == __rhs); }
2177 * @brief Test if string precedes string.
2178 * @param __lhs First string.
2179 * @param __rhs Second string.
2180 * @return True if @a __lhs precedes @a __rhs. False otherwise.
2182 template<typename _CharT, typename _Traits, typename _Alloc,
2183 template <typename, typename, typename> class _Base>
2185 operator<(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2186 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2187 { return __lhs.compare(__rhs) < 0; }
2190 * @brief Test if string precedes C string.
2191 * @param __lhs String.
2192 * @param __rhs C string.
2193 * @return True if @a __lhs precedes @a __rhs. False otherwise.
2195 template<typename _CharT, typename _Traits, typename _Alloc,
2196 template <typename, typename, typename> class _Base>
2198 operator<(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2199 const _CharT* __rhs)
2200 { return __lhs.compare(__rhs) < 0; }
2203 * @brief Test if C string precedes string.
2204 * @param __lhs C string.
2205 * @param __rhs String.
2206 * @return True if @a __lhs precedes @a __rhs. False otherwise.
2208 template<typename _CharT, typename _Traits, typename _Alloc,
2209 template <typename, typename, typename> class _Base>
2211 operator<(const _CharT* __lhs,
2212 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2213 { return __rhs.compare(__lhs) > 0; }
2217 * @brief Test if string follows string.
2218 * @param __lhs First string.
2219 * @param __rhs Second string.
2220 * @return True if @a __lhs follows @a __rhs. False otherwise.
2222 template<typename _CharT, typename _Traits, typename _Alloc,
2223 template <typename, typename, typename> class _Base>
2225 operator>(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2226 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2227 { return __lhs.compare(__rhs) > 0; }
2230 * @brief Test if string follows C string.
2231 * @param __lhs String.
2232 * @param __rhs C string.
2233 * @return True if @a __lhs follows @a __rhs. False otherwise.
2235 template<typename _CharT, typename _Traits, typename _Alloc,
2236 template <typename, typename, typename> class _Base>
2238 operator>(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2239 const _CharT* __rhs)
2240 { return __lhs.compare(__rhs) > 0; }
2243 * @brief Test if C string follows string.
2244 * @param __lhs C string.
2245 * @param __rhs String.
2246 * @return True if @a __lhs follows @a __rhs. False otherwise.
2248 template<typename _CharT, typename _Traits, typename _Alloc,
2249 template <typename, typename, typename> class _Base>
2251 operator>(const _CharT* __lhs,
2252 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2253 { return __rhs.compare(__lhs) < 0; }
2257 * @brief Test if string doesn't follow string.
2258 * @param __lhs First string.
2259 * @param __rhs Second string.
2260 * @return True if @a __lhs doesn't follow @a __rhs. False otherwise.
2262 template<typename _CharT, typename _Traits, typename _Alloc,
2263 template <typename, typename, typename> class _Base>
2265 operator<=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2266 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2267 { return __lhs.compare(__rhs) <= 0; }
2270 * @brief Test if string doesn't follow C string.
2271 * @param __lhs String.
2272 * @param __rhs C string.
2273 * @return True if @a __lhs doesn't follow @a __rhs. False otherwise.
2275 template<typename _CharT, typename _Traits, typename _Alloc,
2276 template <typename, typename, typename> class _Base>
2278 operator<=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2279 const _CharT* __rhs)
2280 { return __lhs.compare(__rhs) <= 0; }
2283 * @brief Test if C string doesn't follow string.
2284 * @param __lhs C string.
2285 * @param __rhs String.
2286 * @return True if @a __lhs doesn't follow @a __rhs. False otherwise.
2288 template<typename _CharT, typename _Traits, typename _Alloc,
2289 template <typename, typename, typename> class _Base>
2291 operator<=(const _CharT* __lhs,
2292 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2293 { return __rhs.compare(__lhs) >= 0; }
2297 * @brief Test if string doesn't precede string.
2298 * @param __lhs First string.
2299 * @param __rhs Second string.
2300 * @return True if @a __lhs doesn't precede @a __rhs. False otherwise.
2302 template<typename _CharT, typename _Traits, typename _Alloc,
2303 template <typename, typename, typename> class _Base>
2305 operator>=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2306 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2307 { return __lhs.compare(__rhs) >= 0; }
2310 * @brief Test if string doesn't precede C string.
2311 * @param __lhs String.
2312 * @param __rhs C string.
2313 * @return True if @a __lhs doesn't precede @a __rhs. False otherwise.
2315 template<typename _CharT, typename _Traits, typename _Alloc,
2316 template <typename, typename, typename> class _Base>
2318 operator>=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2319 const _CharT* __rhs)
2320 { return __lhs.compare(__rhs) >= 0; }
2323 * @brief Test if C string doesn't precede string.
2324 * @param __lhs C string.
2325 * @param __rhs String.
2326 * @return True if @a __lhs doesn't precede @a __rhs. False otherwise.
2328 template<typename _CharT, typename _Traits, typename _Alloc,
2329 template <typename, typename, typename> class _Base>
2331 operator>=(const _CharT* __lhs,
2332 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2333 { return __rhs.compare(__lhs) <= 0; }
2336 * @brief Swap contents of two strings.
2337 * @param __lhs First string.
2338 * @param __rhs Second string.
2340 * Exchanges the contents of @a __lhs and @a __rhs in constant time.
2342 template<typename _CharT, typename _Traits, typename _Alloc,
2343 template <typename, typename, typename> class _Base>
2345 swap(__versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2346 __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2347 { __lhs.swap(__rhs); }
2349 _GLIBCXX_END_NAMESPACE
2351 _GLIBCXX_BEGIN_NAMESPACE(std)
2354 * @brief Read stream into a string.
2355 * @param __is Input stream.
2356 * @param __str Buffer to store into.
2357 * @return Reference to the input stream.
2359 * Stores characters from @a __is into @a __str until whitespace is
2360 * found, the end of the stream is encountered, or str.max_size()
2361 * is reached. If is.width() is non-zero, that is the limit on the
2362 * number of characters stored into @a __str. Any previous
2363 * contents of @a __str are erased.
2365 template<typename _CharT, typename _Traits, typename _Alloc,
2366 template <typename, typename, typename> class _Base>
2367 basic_istream<_CharT, _Traits>&
2368 operator>>(basic_istream<_CharT, _Traits>& __is,
2369 __gnu_cxx::__versa_string<_CharT, _Traits,
2370 _Alloc, _Base>& __str);
2373 * @brief Write string to a stream.
2374 * @param __os Output stream.
2375 * @param __str String to write out.
2376 * @return Reference to the output stream.
2378 * Output characters of @a __str into os following the same rules as for
2379 * writing a C string.
2381 template<typename _CharT, typename _Traits, typename _Alloc,
2382 template <typename, typename, typename> class _Base>
2383 inline basic_ostream<_CharT, _Traits>&
2384 operator<<(basic_ostream<_CharT, _Traits>& __os,
2385 const __gnu_cxx::__versa_string<_CharT, _Traits, _Alloc,
2388 // _GLIBCXX_RESOLVE_LIB_DEFECTS
2389 // 586. string inserter not a formatted function
2390 return __ostream_insert(__os, __str.data(), __str.size());
2394 * @brief Read a line from stream into a string.
2395 * @param __is Input stream.
2396 * @param __str Buffer to store into.
2397 * @param __delim Character marking end of line.
2398 * @return Reference to the input stream.
2400 * Stores characters from @a __is into @a __str until @a __delim is
2401 * found, the end of the stream is encountered, or str.max_size()
2402 * is reached. If is.width() is non-zero, that is the limit on the
2403 * number of characters stored into @a __str. Any previous
2404 * contents of @a __str are erased. If @a delim was encountered,
2405 * it is extracted but not stored into @a __str.
2407 template<typename _CharT, typename _Traits, typename _Alloc,
2408 template <typename, typename, typename> class _Base>
2409 basic_istream<_CharT, _Traits>&
2410 getline(basic_istream<_CharT, _Traits>& __is,
2411 __gnu_cxx::__versa_string<_CharT, _Traits, _Alloc, _Base>& __str,
2415 * @brief Read a line from stream into a string.
2416 * @param __is Input stream.
2417 * @param __str Buffer to store into.
2418 * @return Reference to the input stream.
2420 * Stores characters from is into @a __str until '\n' is found, the
2421 * end of the stream is encountered, or str.max_size() is reached.
2422 * If is.width() is non-zero, that is the limit on the number of
2423 * characters stored into @a __str. Any previous contents of @a
2424 * __str are erased. If end of line was encountered, it is
2425 * extracted but not stored into @a __str.
2427 template<typename _CharT, typename _Traits, typename _Alloc,
2428 template <typename, typename, typename> class _Base>
2429 inline basic_istream<_CharT, _Traits>&
2430 getline(basic_istream<_CharT, _Traits>& __is,
2431 __gnu_cxx::__versa_string<_CharT, _Traits, _Alloc, _Base>& __str)
2432 { return getline(__is, __str, __is.widen('\n')); }
2434 _GLIBCXX_END_NAMESPACE
2436 #if (defined(__GXX_EXPERIMENTAL_CXX0X__) && defined(_GLIBCXX_USE_C99))
2438 #include <ext/string_conversions.h>
2440 _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
2442 // 21.4 Numeric Conversions [string.conversions].
2444 stoi(const __vstring& __str, std::size_t* __idx = 0, int __base = 10)
2445 { return __gnu_cxx::__stoa<long, int>(&std::strtol, "stoi", __str.c_str(),
2449 stol(const __vstring& __str, std::size_t* __idx = 0, int __base = 10)
2450 { return __gnu_cxx::__stoa(&std::strtol, "stol", __str.c_str(),
2453 inline unsigned long
2454 stoul(const __vstring& __str, std::size_t* __idx = 0, int __base = 10)
2455 { return __gnu_cxx::__stoa(&std::strtoul, "stoul", __str.c_str(),
2459 stoll(const __vstring& __str, std::size_t* __idx = 0, int __base = 10)
2460 { return __gnu_cxx::__stoa(&std::strtoll, "stoll", __str.c_str(),
2463 inline unsigned long long
2464 stoull(const __vstring& __str, std::size_t* __idx, int __base = 10)
2465 { return __gnu_cxx::__stoa(&std::strtoull, "stoull", __str.c_str(),
2468 // NB: strtof vs strtod.
2470 stof(const __vstring& __str, std::size_t* __idx = 0)
2471 { return __gnu_cxx::__stoa(&std::strtof, "stof", __str.c_str(), __idx); }
2474 stod(const __vstring& __str, std::size_t* __idx = 0)
2475 { return __gnu_cxx::__stoa(&std::strtod, "stod", __str.c_str(), __idx); }
2478 stold(const __vstring& __str, std::size_t* __idx = 0)
2479 { return __gnu_cxx::__stoa(&std::strtold, "stold", __str.c_str(), __idx); }
2481 // NB: (v)snprintf vs sprintf.
2485 to_string(int __val)
2486 { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, 4 * sizeof(int),
2490 to_string(unsigned __val)
2491 { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf,
2492 4 * sizeof(unsigned),
2496 to_string(long __val)
2497 { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf,
2502 to_string(unsigned long __val)
2503 { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf,
2504 4 * sizeof(unsigned long),
2509 to_string(long long __val)
2510 { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf,
2511 4 * sizeof(long long),
2515 to_string(unsigned long long __val)
2516 { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf,
2517 4 * sizeof(unsigned long long),
2521 to_string(float __val)
2523 const int __n = __numeric_traits<float>::__max_exponent10 + 20;
2524 return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, __n,
2529 to_string(double __val)
2531 const int __n = __numeric_traits<double>::__max_exponent10 + 20;
2532 return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, __n,
2537 to_string(long double __val)
2539 const int __n = __numeric_traits<long double>::__max_exponent10 + 20;
2540 return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, __n,
2544 #ifdef _GLIBCXX_USE_WCHAR_T
2546 stoi(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10)
2547 { return __gnu_cxx::__stoa<long, int>(&std::wcstol, "stoi", __str.c_str(),
2551 stol(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10)
2552 { return __gnu_cxx::__stoa(&std::wcstol, "stol", __str.c_str(),
2555 inline unsigned long
2556 stoul(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10)
2557 { return __gnu_cxx::__stoa(&std::wcstoul, "stoul", __str.c_str(),
2561 stoll(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10)
2562 { return __gnu_cxx::__stoa(&std::wcstoll, "stoll", __str.c_str(),
2565 inline unsigned long long
2566 stoull(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10)
2567 { return __gnu_cxx::__stoa(&std::wcstoull, "stoull", __str.c_str(),
2570 // NB: wcstof vs wcstod.
2572 stof(const __wvstring& __str, std::size_t* __idx = 0)
2573 { return __gnu_cxx::__stoa(&std::wcstof, "stof", __str.c_str(), __idx); }
2576 stod(const __wvstring& __str, std::size_t* __idx = 0)
2577 { return __gnu_cxx::__stoa(&std::wcstod, "stod", __str.c_str(), __idx); }
2580 stold(const __wvstring& __str, std::size_t* __idx = 0)
2581 { return __gnu_cxx::__stoa(&std::wcstold, "stold", __str.c_str(), __idx); }
2583 #ifndef _GLIBCXX_HAVE_BROKEN_VSWPRINTF
2586 to_wstring(int __val)
2587 { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
2592 to_wstring(unsigned __val)
2593 { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
2594 4 * sizeof(unsigned),
2598 to_wstring(long __val)
2599 { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
2604 to_wstring(unsigned long __val)
2605 { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
2606 4 * sizeof(unsigned long),
2610 to_wstring(long long __val)
2611 { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
2612 4 * sizeof(long long),
2616 to_wstring(unsigned long long __val)
2617 { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
2618 4 * sizeof(unsigned long long),
2622 to_wstring(float __val)
2624 const int __n = __numeric_traits<float>::__max_exponent10 + 20;
2625 return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, __n,
2630 to_wstring(double __val)
2632 const int __n = __numeric_traits<double>::__max_exponent10 + 20;
2633 return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, __n,
2638 to_wstring(long double __val)
2640 const int __n = __numeric_traits<long double>::__max_exponent10 + 20;
2641 return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, __n,
2647 _GLIBCXX_END_NAMESPACE
2651 #ifndef _GLIBCXX_EXPORT_TEMPLATE
2652 # include "vstring.tcc"
2655 #endif /* _VSTRING_H */