1169691Skan// Versatile string -*- C++ -*-
2169691Skan
3169691Skan// Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc.
4169691Skan//
5169691Skan// This file is part of the GNU ISO C++ Library.  This library is free
6169691Skan// software; you can redistribute it and/or modify it under the
7169691Skan// terms of the GNU General Public License as published by the
8169691Skan// Free Software Foundation; either version 2, or (at your option)
9169691Skan// any later version.
10169691Skan
11169691Skan// This library is distributed in the hope that it will be useful,
12169691Skan// but WITHOUT ANY WARRANTY; without even the implied warranty of
13169691Skan// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14169691Skan// GNU General Public License for more details.
15169691Skan
16169691Skan// You should have received a copy of the GNU General Public License along
17169691Skan// with this library; see the file COPYING.  If not, write to the Free
18169691Skan// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19169691Skan// USA.
20169691Skan
21169691Skan// As a special exception, you may use this file as part of a free software
22169691Skan// library without restriction.  Specifically, if other files instantiate
23169691Skan// templates or use macros or inline functions from this file, or you compile
24169691Skan// this file and link it with other files to produce an executable, this
25169691Skan// file does not by itself cause the resulting executable to be covered by
26169691Skan// the GNU General Public License.  This exception does not however
27169691Skan// invalidate any other reasons why the executable file might be covered by
28169691Skan// the GNU General Public License.
29169691Skan
30169691Skan/** @file ext/vstring.h
31169691Skan *  This file is a GNU extension to the Standard C++ Library.
32169691Skan */
33169691Skan
34169691Skan#ifndef _VSTRING_H
35169691Skan#define _VSTRING_H 1
36169691Skan
37169691Skan#pragma GCC system_header
38169691Skan
39169691Skan#include <ext/vstring_util.h>
40169691Skan#include <ext/rc_string_base.h>
41169691Skan#include <ext/sso_string_base.h>
42169691Skan
43169691Skan_GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
44169691Skan
45169691Skan  /**
46169691Skan   *  @class __versa_string vstring.h
47169691Skan   *  @brief  Managing sequences of characters and character-like objects.
48169691Skan   */
49169691Skan
50169691Skan  // Template class __versa_string
51169691Skan  template<typename _CharT, typename _Traits, typename _Alloc,
52169691Skan	   template <typename, typename, typename> class _Base>
53169691Skan    class __versa_string
54169691Skan    : private _Base<_CharT, _Traits, _Alloc>
55169691Skan    {
56169691Skan      typedef _Base<_CharT, _Traits, _Alloc>                __vstring_base;
57169691Skan      typedef typename __vstring_base::_CharT_alloc_type    _CharT_alloc_type;
58169691Skan
59169691Skan      // Types:
60169691Skan    public:
61169691Skan      typedef _Traits					    traits_type;
62169691Skan      typedef typename _Traits::char_type		    value_type;
63169691Skan      typedef _Alloc					    allocator_type;
64169691Skan      typedef typename _CharT_alloc_type::size_type	    size_type;
65169691Skan      typedef typename _CharT_alloc_type::difference_type   difference_type;
66169691Skan      typedef typename _CharT_alloc_type::reference	    reference;
67169691Skan      typedef typename _CharT_alloc_type::const_reference   const_reference;
68169691Skan      typedef typename _CharT_alloc_type::pointer	    pointer;
69169691Skan      typedef typename _CharT_alloc_type::const_pointer	    const_pointer;
70169691Skan      typedef __gnu_cxx::__normal_iterator<pointer, __versa_string>  iterator;
71169691Skan      typedef __gnu_cxx::__normal_iterator<const_pointer, __versa_string>
72169691Skan                                                            const_iterator;
73169691Skan      typedef std::reverse_iterator<const_iterator>	const_reverse_iterator;
74169691Skan      typedef std::reverse_iterator<iterator>		    reverse_iterator;
75169691Skan
76169691Skan      // Data Member (public):
77169691Skan      ///  Value returned by various member functions when they fail.
78169691Skan      static const size_type	npos = static_cast<size_type>(-1);
79169691Skan
80169691Skan    private:
81169691Skan      size_type
82169691Skan      _M_check(size_type __pos, const char* __s) const
83169691Skan      {
84169691Skan	if (__pos > this->size())
85169691Skan	  std::__throw_out_of_range(__N(__s));
86169691Skan	return __pos;
87169691Skan      }
88169691Skan
89169691Skan      void
90169691Skan      _M_check_length(size_type __n1, size_type __n2, const char* __s) const
91169691Skan      {
92169691Skan	if (this->max_size() - (this->size() - __n1) < __n2)
93169691Skan	  std::__throw_length_error(__N(__s));
94169691Skan      }
95169691Skan
96169691Skan      // NB: _M_limit doesn't check for a bad __pos value.
97169691Skan      size_type
98169691Skan      _M_limit(size_type __pos, size_type __off) const
99169691Skan      {
100169691Skan	const bool __testoff =  __off < this->size() - __pos;
101169691Skan	return __testoff ? __off : this->size() - __pos;
102169691Skan      }
103169691Skan
104169691Skan      // True if _Rep and source do not overlap.
105169691Skan      bool
106169691Skan      _M_disjunct(const _CharT* __s) const
107169691Skan      {
108169691Skan	return (std::less<const _CharT*>()(__s, this->_M_data())
109169691Skan		|| std::less<const _CharT*>()(this->_M_data()
110169691Skan					      + this->size(), __s));
111169691Skan      }
112169691Skan
113169691Skan      // For the internal use we have functions similar to `begin'/`end'
114169691Skan      // but they do not call _M_leak.
115169691Skan      iterator
116169691Skan      _M_ibegin() const
117169691Skan      { return iterator(this->_M_data()); }
118169691Skan
119169691Skan      iterator
120169691Skan      _M_iend() const
121169691Skan      { return iterator(this->_M_data() + this->_M_length()); }
122169691Skan
123169691Skan    public:
124169691Skan      // Construct/copy/destroy:
125169691Skan      // NB: We overload ctors in some cases instead of using default
126169691Skan      // arguments, per 17.4.4.4 para. 2 item 2.
127169691Skan
128169691Skan      /**
129169691Skan       *  @brief  Default constructor creates an empty string.
130169691Skan       */
131169691Skan      __versa_string()
132169691Skan      : __vstring_base() { }
133169691Skan
134169691Skan      /**
135169691Skan       *  @brief  Construct an empty string using allocator @a a.
136169691Skan       */
137169691Skan      explicit
138169691Skan      __versa_string(const _Alloc& __a)
139169691Skan      : __vstring_base(__a) { }
140169691Skan
141169691Skan      // NB: per LWG issue 42, semantics different from IS:
142169691Skan      /**
143169691Skan       *  @brief  Construct string with copy of value of @a str.
144169691Skan       *  @param  str  Source string.
145169691Skan       */
146169691Skan      __versa_string(const __versa_string& __str)
147169691Skan      : __vstring_base(__str) { }
148169691Skan
149169691Skan      /**
150169691Skan       *  @brief  Construct string as copy of a substring.
151169691Skan       *  @param  str  Source string.
152169691Skan       *  @param  pos  Index of first character to copy from.
153169691Skan       *  @param  n  Number of characters to copy (default remainder).
154169691Skan       */
155169691Skan      __versa_string(const __versa_string& __str, size_type __pos,
156169691Skan		     size_type __n = npos)
157169691Skan      : __vstring_base(__str._M_data()
158169691Skan		       + __str._M_check(__pos,
159169691Skan					"__versa_string::__versa_string"),
160169691Skan		       __str._M_data() + __str._M_limit(__pos, __n)
161169691Skan		       + __pos, _Alloc()) { }
162169691Skan
163169691Skan      /**
164169691Skan       *  @brief  Construct string as copy of a substring.
165169691Skan       *  @param  str  Source string.
166169691Skan       *  @param  pos  Index of first character to copy from.
167169691Skan       *  @param  n  Number of characters to copy.
168169691Skan       *  @param  a  Allocator to use.
169169691Skan       */
170169691Skan      __versa_string(const __versa_string& __str, size_type __pos,
171169691Skan		     size_type __n, const _Alloc& __a)
172169691Skan      : __vstring_base(__str._M_data()
173169691Skan		       + __str._M_check(__pos,
174169691Skan					"__versa_string::__versa_string"),
175169691Skan		       __str._M_data() + __str._M_limit(__pos, __n)
176169691Skan		       + __pos, __a) { }
177169691Skan
178169691Skan      /**
179169691Skan       *  @brief  Construct string initialized by a character array.
180169691Skan       *  @param  s  Source character array.
181169691Skan       *  @param  n  Number of characters to copy.
182169691Skan       *  @param  a  Allocator to use (default is default allocator).
183169691Skan       *
184169691Skan       *  NB: @a s must have at least @a n characters, '\0' has no special
185169691Skan       *  meaning.
186169691Skan       */
187169691Skan      __versa_string(const _CharT* __s, size_type __n,
188169691Skan		     const _Alloc& __a = _Alloc())
189169691Skan      : __vstring_base(__s, __s + __n, __a) { }
190169691Skan
191169691Skan      /**
192169691Skan       *  @brief  Construct string as copy of a C string.
193169691Skan       *  @param  s  Source C string.
194169691Skan       *  @param  a  Allocator to use (default is default allocator).
195169691Skan       */
196169691Skan      __versa_string(const _CharT* __s, const _Alloc& __a = _Alloc())
197169691Skan      : __vstring_base(__s, __s ? __s + traits_type::length(__s) :
198169691Skan		       __s + npos, __a) { }
199169691Skan
200169691Skan      /**
201169691Skan       *  @brief  Construct string as multiple characters.
202169691Skan       *  @param  n  Number of characters.
203169691Skan       *  @param  c  Character to use.
204169691Skan       *  @param  a  Allocator to use (default is default allocator).
205169691Skan       */
206169691Skan      __versa_string(size_type __n, _CharT __c, const _Alloc& __a = _Alloc())
207169691Skan      : __vstring_base(__n, __c, __a) { }
208169691Skan
209169691Skan      /**
210169691Skan       *  @brief  Construct string as copy of a range.
211169691Skan       *  @param  beg  Start of range.
212169691Skan       *  @param  end  End of range.
213169691Skan       *  @param  a  Allocator to use (default is default allocator).
214169691Skan       */
215169691Skan      template<class _InputIterator>
216169691Skan        __versa_string(_InputIterator __beg, _InputIterator __end,
217169691Skan		       const _Alloc& __a = _Alloc())
218169691Skan	: __vstring_base(__beg, __end, __a) { }
219169691Skan
220169691Skan      /**
221169691Skan       *  @brief  Destroy the string instance.
222169691Skan       */
223169691Skan      ~__versa_string() { }
224169691Skan
225169691Skan      /**
226169691Skan       *  @brief  Assign the value of @a str to this string.
227169691Skan       *  @param  str  Source string.
228169691Skan       */
229169691Skan      __versa_string&
230169691Skan      operator=(const __versa_string& __str)
231169691Skan      { return this->assign(__str); }
232169691Skan
233169691Skan      /**
234169691Skan       *  @brief  Copy contents of @a s into this string.
235169691Skan       *  @param  s  Source null-terminated string.
236169691Skan       */
237169691Skan      __versa_string&
238169691Skan      operator=(const _CharT* __s)
239169691Skan      { return this->assign(__s); }
240169691Skan
241169691Skan      /**
242169691Skan       *  @brief  Set value to string of length 1.
243169691Skan       *  @param  c  Source character.
244169691Skan       *
245169691Skan       *  Assigning to a character makes this string length 1 and
246169691Skan       *  (*this)[0] == @a c.
247169691Skan       */
248169691Skan      __versa_string&
249169691Skan      operator=(_CharT __c)
250169691Skan      {
251169691Skan	this->assign(1, __c);
252169691Skan	return *this;
253169691Skan      }
254169691Skan
255169691Skan      // Iterators:
256169691Skan      /**
257169691Skan       *  Returns a read/write iterator that points to the first character in
258169691Skan       *  the %string.  Unshares the string.
259169691Skan       */
260169691Skan      iterator
261169691Skan      begin()
262169691Skan      {
263169691Skan	this->_M_leak();
264169691Skan	return iterator(this->_M_data());
265169691Skan      }
266169691Skan
267169691Skan      /**
268169691Skan       *  Returns a read-only (constant) iterator that points to the first
269169691Skan       *  character in the %string.
270169691Skan       */
271169691Skan      const_iterator
272169691Skan      begin() const
273169691Skan      { return const_iterator(this->_M_data()); }
274169691Skan
275169691Skan      /**
276169691Skan       *  Returns a read/write iterator that points one past the last
277169691Skan       *  character in the %string.  Unshares the string.
278169691Skan       */
279169691Skan      iterator
280169691Skan      end()
281169691Skan      {
282169691Skan	this->_M_leak();
283169691Skan	return iterator(this->_M_data() + this->size());
284169691Skan      }
285169691Skan
286169691Skan      /**
287169691Skan       *  Returns a read-only (constant) iterator that points one past the
288169691Skan       *  last character in the %string.
289169691Skan       */
290169691Skan      const_iterator
291169691Skan      end() const
292169691Skan      { return const_iterator(this->_M_data() + this->size()); }
293169691Skan
294169691Skan      /**
295169691Skan       *  Returns a read/write reverse iterator that points to the last
296169691Skan       *  character in the %string.  Iteration is done in reverse element
297169691Skan       *  order.  Unshares the string.
298169691Skan       */
299169691Skan      reverse_iterator
300169691Skan      rbegin()
301169691Skan      { return reverse_iterator(this->end()); }
302169691Skan
303169691Skan      /**
304169691Skan       *  Returns a read-only (constant) reverse iterator that points
305169691Skan       *  to the last character in the %string.  Iteration is done in
306169691Skan       *  reverse element order.
307169691Skan       */
308169691Skan      const_reverse_iterator
309169691Skan      rbegin() const
310169691Skan      { return const_reverse_iterator(this->end()); }
311169691Skan
312169691Skan      /**
313169691Skan       *  Returns a read/write reverse iterator that points to one before the
314169691Skan       *  first character in the %string.  Iteration is done in reverse
315169691Skan       *  element order.  Unshares the string.
316169691Skan       */
317169691Skan      reverse_iterator
318169691Skan      rend()
319169691Skan      { return reverse_iterator(this->begin()); }
320169691Skan
321169691Skan      /**
322169691Skan       *  Returns a read-only (constant) reverse iterator that points
323169691Skan       *  to one before the first character in the %string.  Iteration
324169691Skan       *  is done in reverse element order.
325169691Skan       */
326169691Skan      const_reverse_iterator
327169691Skan      rend() const
328169691Skan      { return const_reverse_iterator(this->begin()); }
329169691Skan
330169691Skan    public:
331169691Skan      // Capacity:
332169691Skan      ///  Returns the number of characters in the string, not including any
333169691Skan      ///  null-termination.
334169691Skan      size_type
335169691Skan      size() const
336169691Skan      { return this->_M_length(); }
337169691Skan
338169691Skan      ///  Returns the number of characters in the string, not including any
339169691Skan      ///  null-termination.
340169691Skan      size_type
341169691Skan      length() const
342169691Skan      { return this->_M_length(); }
343169691Skan
344169691Skan      /// Returns the size() of the largest possible %string.
345169691Skan      size_type
346169691Skan      max_size() const
347169691Skan      { return this->_M_max_size(); }
348169691Skan
349169691Skan      /**
350169691Skan       *  @brief  Resizes the %string to the specified number of characters.
351169691Skan       *  @param  n  Number of characters the %string should contain.
352169691Skan       *  @param  c  Character to fill any new elements.
353169691Skan       *
354169691Skan       *  This function will %resize the %string to the specified
355169691Skan       *  number of characters.  If the number is smaller than the
356169691Skan       *  %string's current size the %string is truncated, otherwise
357169691Skan       *  the %string is extended and new elements are set to @a c.
358169691Skan       */
359169691Skan      void
360169691Skan      resize(size_type __n, _CharT __c);
361169691Skan
362169691Skan      /**
363169691Skan       *  @brief  Resizes the %string to the specified number of characters.
364169691Skan       *  @param  n  Number of characters the %string should contain.
365169691Skan       *
366169691Skan       *  This function will resize the %string to the specified length.  If
367169691Skan       *  the new size is smaller than the %string's current size the %string
368169691Skan       *  is truncated, otherwise the %string is extended and new characters
369169691Skan       *  are default-constructed.  For basic types such as char, this means
370169691Skan       *  setting them to 0.
371169691Skan       */
372169691Skan      void
373169691Skan      resize(size_type __n)
374169691Skan      { this->resize(__n, _CharT()); }
375169691Skan
376169691Skan      /**
377169691Skan       *  Returns the total number of characters that the %string can hold
378169691Skan       *  before needing to allocate more memory.
379169691Skan       */
380169691Skan      size_type
381169691Skan      capacity() const
382169691Skan      { return this->_M_capacity(); }
383169691Skan
384169691Skan      /**
385169691Skan       *  @brief  Attempt to preallocate enough memory for specified number of
386169691Skan       *          characters.
387169691Skan       *  @param  res_arg  Number of characters required.
388169691Skan       *  @throw  std::length_error  If @a res_arg exceeds @c max_size().
389169691Skan       *
390169691Skan       *  This function attempts to reserve enough memory for the
391169691Skan       *  %string to hold the specified number of characters.  If the
392169691Skan       *  number requested is more than max_size(), length_error is
393169691Skan       *  thrown.
394169691Skan       *
395169691Skan       *  The advantage of this function is that if optimal code is a
396169691Skan       *  necessity and the user can determine the string length that will be
397169691Skan       *  required, the user can reserve the memory in %advance, and thus
398169691Skan       *  prevent a possible reallocation of memory and copying of %string
399169691Skan       *  data.
400169691Skan       */
401169691Skan      void
402169691Skan      reserve(size_type __res_arg = 0)
403169691Skan      { this->_M_reserve(__res_arg); }
404169691Skan
405169691Skan      /**
406169691Skan       *  Erases the string, making it empty.
407169691Skan       */
408169691Skan      void
409169691Skan      clear()
410169691Skan      { this->_M_clear(); }
411169691Skan
412169691Skan      /**
413169691Skan       *  Returns true if the %string is empty.  Equivalent to *this == "".
414169691Skan       */
415169691Skan      bool
416169691Skan      empty() const
417169691Skan      { return this->size() == 0; }
418169691Skan
419169691Skan      // Element access:
420169691Skan      /**
421169691Skan       *  @brief  Subscript access to the data contained in the %string.
422169691Skan       *  @param  pos  The index of the character to access.
423169691Skan       *  @return  Read-only (constant) reference to the character.
424169691Skan       *
425169691Skan       *  This operator allows for easy, array-style, data access.
426169691Skan       *  Note that data access with this operator is unchecked and
427169691Skan       *  out_of_range lookups are not defined. (For checked lookups
428169691Skan       *  see at().)
429169691Skan       */
430169691Skan      const_reference
431169691Skan      operator[] (size_type __pos) const
432169691Skan      {
433169691Skan	_GLIBCXX_DEBUG_ASSERT(__pos <= this->size());
434169691Skan	return this->_M_data()[__pos];
435169691Skan      }
436169691Skan
437169691Skan      /**
438169691Skan       *  @brief  Subscript access to the data contained in the %string.
439169691Skan       *  @param  pos  The index of the character to access.
440169691Skan       *  @return  Read/write reference to the character.
441169691Skan       *
442169691Skan       *  This operator allows for easy, array-style, data access.
443169691Skan       *  Note that data access with this operator is unchecked and
444169691Skan       *  out_of_range lookups are not defined. (For checked lookups
445169691Skan       *  see at().)  Unshares the string.
446169691Skan       */
447169691Skan      reference
448169691Skan      operator[](size_type __pos)
449169691Skan      {
450169691Skan        // allow pos == size() as v3 extension:
451169691Skan	_GLIBCXX_DEBUG_ASSERT(__pos <= this->size());
452169691Skan        // but be strict in pedantic mode:
453169691Skan	_GLIBCXX_DEBUG_PEDASSERT(__pos < this->size());
454169691Skan	this->_M_leak();
455169691Skan	return this->_M_data()[__pos];
456169691Skan      }
457169691Skan
458169691Skan      /**
459169691Skan       *  @brief  Provides access to the data contained in the %string.
460169691Skan       *  @param n The index of the character to access.
461169691Skan       *  @return  Read-only (const) reference to the character.
462169691Skan       *  @throw  std::out_of_range  If @a n is an invalid index.
463169691Skan       *
464169691Skan       *  This function provides for safer data access.  The parameter is
465169691Skan       *  first checked that it is in the range of the string.  The function
466169691Skan       *  throws out_of_range if the check fails.
467169691Skan       */
468169691Skan      const_reference
469169691Skan      at(size_type __n) const
470169691Skan      {
471169691Skan	if (__n >= this->size())
472169691Skan	  std::__throw_out_of_range(__N("__versa_string::at"));
473169691Skan	return this->_M_data()[__n];
474169691Skan      }
475169691Skan
476169691Skan      /**
477169691Skan       *  @brief  Provides access to the data contained in the %string.
478169691Skan       *  @param n The index of the character to access.
479169691Skan       *  @return  Read/write reference to the character.
480169691Skan       *  @throw  std::out_of_range  If @a n is an invalid index.
481169691Skan       *
482169691Skan       *  This function provides for safer data access.  The parameter is
483169691Skan       *  first checked that it is in the range of the string.  The function
484169691Skan       *  throws out_of_range if the check fails.  Success results in
485169691Skan       *  unsharing the string.
486169691Skan       */
487169691Skan      reference
488169691Skan      at(size_type __n)
489169691Skan      {
490169691Skan	if (__n >= this->size())
491169691Skan	  std::__throw_out_of_range(__N("__versa_string::at"));
492169691Skan	this->_M_leak();
493169691Skan	return this->_M_data()[__n];
494169691Skan      }
495169691Skan
496169691Skan      // Modifiers:
497169691Skan      /**
498169691Skan       *  @brief  Append a string to this string.
499169691Skan       *  @param str  The string to append.
500169691Skan       *  @return  Reference to this string.
501169691Skan       */
502169691Skan      __versa_string&
503169691Skan      operator+=(const __versa_string& __str)
504169691Skan      { return this->append(__str); }
505169691Skan
506169691Skan      /**
507169691Skan       *  @brief  Append a C string.
508169691Skan       *  @param s  The C string to append.
509169691Skan       *  @return  Reference to this string.
510169691Skan       */
511169691Skan      __versa_string&
512169691Skan      operator+=(const _CharT* __s)
513169691Skan      { return this->append(__s); }
514169691Skan
515169691Skan      /**
516169691Skan       *  @brief  Append a character.
517169691Skan       *  @param c  The character to append.
518169691Skan       *  @return  Reference to this string.
519169691Skan       */
520169691Skan      __versa_string&
521169691Skan      operator+=(_CharT __c)
522169691Skan      {
523169691Skan	this->push_back(__c);
524169691Skan	return *this;
525169691Skan      }
526169691Skan
527169691Skan      /**
528169691Skan       *  @brief  Append a string to this string.
529169691Skan       *  @param str  The string to append.
530169691Skan       *  @return  Reference to this string.
531169691Skan       */
532169691Skan      __versa_string&
533169691Skan      append(const __versa_string& __str)
534169691Skan      { return _M_append(__str._M_data(), __str.size()); }
535169691Skan
536169691Skan      /**
537169691Skan       *  @brief  Append a substring.
538169691Skan       *  @param str  The string to append.
539169691Skan       *  @param pos  Index of the first character of str to append.
540169691Skan       *  @param n  The number of characters to append.
541169691Skan       *  @return  Reference to this string.
542169691Skan       *  @throw  std::out_of_range if @a pos is not a valid index.
543169691Skan       *
544169691Skan       *  This function appends @a n characters from @a str starting at @a pos
545169691Skan       *  to this string.  If @a n is is larger than the number of available
546169691Skan       *  characters in @a str, the remainder of @a str is appended.
547169691Skan       */
548169691Skan      __versa_string&
549169691Skan      append(const __versa_string& __str, size_type __pos, size_type __n)
550169691Skan      { return _M_append(__str._M_data()
551169691Skan			 + __str._M_check(__pos, "__versa_string::append"),
552169691Skan			 __str._M_limit(__pos, __n)); }
553169691Skan
554169691Skan      /**
555169691Skan       *  @brief  Append a C substring.
556169691Skan       *  @param s  The C string to append.
557169691Skan       *  @param n  The number of characters to append.
558169691Skan       *  @return  Reference to this string.
559169691Skan       */
560169691Skan      __versa_string&
561169691Skan      append(const _CharT* __s, size_type __n)
562169691Skan      {
563169691Skan	__glibcxx_requires_string_len(__s, __n);
564169691Skan	_M_check_length(size_type(0), __n, "__versa_string::append");
565169691Skan	return _M_append(__s, __n);
566169691Skan      }
567169691Skan
568169691Skan      /**
569169691Skan       *  @brief  Append a C string.
570169691Skan       *  @param s  The C string to append.
571169691Skan       *  @return  Reference to this string.
572169691Skan       */
573169691Skan      __versa_string&
574169691Skan      append(const _CharT* __s)
575169691Skan      {
576169691Skan	__glibcxx_requires_string(__s);
577169691Skan	const size_type __n = traits_type::length(__s);
578169691Skan	_M_check_length(size_type(0), __n, "__versa_string::append");
579169691Skan	return _M_append(__s, __n);
580169691Skan      }
581169691Skan
582169691Skan      /**
583169691Skan       *  @brief  Append multiple characters.
584169691Skan       *  @param n  The number of characters to append.
585169691Skan       *  @param c  The character to use.
586169691Skan       *  @return  Reference to this string.
587169691Skan       *
588169691Skan       *  Appends n copies of c to this string.
589169691Skan       */
590169691Skan      __versa_string&
591169691Skan      append(size_type __n, _CharT __c)
592169691Skan      { return _M_replace_aux(this->size(), size_type(0), __n, __c); }
593169691Skan
594169691Skan      /**
595169691Skan       *  @brief  Append a range of characters.
596169691Skan       *  @param first  Iterator referencing the first character to append.
597169691Skan       *  @param last  Iterator marking the end of the range.
598169691Skan       *  @return  Reference to this string.
599169691Skan       *
600169691Skan       *  Appends characters in the range [first,last) to this string.
601169691Skan       */
602169691Skan      template<class _InputIterator>
603169691Skan        __versa_string&
604169691Skan        append(_InputIterator __first, _InputIterator __last)
605169691Skan        { return this->replace(_M_iend(), _M_iend(), __first, __last); }
606169691Skan
607169691Skan      /**
608169691Skan       *  @brief  Append a single character.
609169691Skan       *  @param c  Character to append.
610169691Skan       */
611169691Skan      void
612169691Skan      push_back(_CharT __c)
613169691Skan      {
614169691Skan	const size_type __size = this->size();
615169691Skan	if (__size + 1 > this->capacity() || this->_M_is_shared())
616169691Skan	  this->_M_mutate(__size, size_type(0), 0, size_type(1));
617169691Skan	traits_type::assign(this->_M_data()[__size], __c);
618169691Skan	this->_M_set_length(__size + 1);
619169691Skan      }
620169691Skan
621169691Skan      /**
622169691Skan       *  @brief  Set value to contents of another string.
623169691Skan       *  @param  str  Source string to use.
624169691Skan       *  @return  Reference to this string.
625169691Skan       */
626169691Skan      __versa_string&
627169691Skan      assign(const __versa_string& __str)
628169691Skan      {
629169691Skan	this->_M_assign(__str);
630169691Skan	return *this;
631169691Skan      }
632169691Skan
633169691Skan      /**
634169691Skan       *  @brief  Set value to a substring of a string.
635169691Skan       *  @param str  The string to use.
636169691Skan       *  @param pos  Index of the first character of str.
637169691Skan       *  @param n  Number of characters to use.
638169691Skan       *  @return  Reference to this string.
639169691Skan       *  @throw  std::out_of_range if @a pos is not a valid index.
640169691Skan       *
641169691Skan       *  This function sets this string to the substring of @a str consisting
642169691Skan       *  of @a n characters at @a pos.  If @a n is is larger than the number
643169691Skan       *  of available characters in @a str, the remainder of @a str is used.
644169691Skan       */
645169691Skan      __versa_string&
646169691Skan      assign(const __versa_string& __str, size_type __pos, size_type __n)
647169691Skan      { return _M_replace(size_type(0), this->size(), __str._M_data()
648169691Skan			  + __str._M_check(__pos, "__versa_string::assign"),
649169691Skan			  __str._M_limit(__pos, __n)); }
650169691Skan
651169691Skan      /**
652169691Skan       *  @brief  Set value to a C substring.
653169691Skan       *  @param s  The C string to use.
654169691Skan       *  @param n  Number of characters to use.
655169691Skan       *  @return  Reference to this string.
656169691Skan       *
657169691Skan       *  This function sets the value of this string to the first @a n
658169691Skan       *  characters of @a s.  If @a n is is larger than the number of
659169691Skan       *  available characters in @a s, the remainder of @a s is used.
660169691Skan       */
661169691Skan      __versa_string&
662169691Skan      assign(const _CharT* __s, size_type __n)
663169691Skan      {
664169691Skan	__glibcxx_requires_string_len(__s, __n);
665169691Skan	return _M_replace(size_type(0), this->size(), __s, __n);
666169691Skan      }
667169691Skan
668169691Skan      /**
669169691Skan       *  @brief  Set value to contents of a C string.
670169691Skan       *  @param s  The C string to use.
671169691Skan       *  @return  Reference to this string.
672169691Skan       *
673169691Skan       *  This function sets the value of this string to the value of @a s.
674169691Skan       *  The data is copied, so there is no dependence on @a s once the
675169691Skan       *  function returns.
676169691Skan       */
677169691Skan      __versa_string&
678169691Skan      assign(const _CharT* __s)
679169691Skan      {
680169691Skan	__glibcxx_requires_string(__s);
681169691Skan	return _M_replace(size_type(0), this->size(), __s,
682169691Skan			  traits_type::length(__s));
683169691Skan      }
684169691Skan
685169691Skan      /**
686169691Skan       *  @brief  Set value to multiple characters.
687169691Skan       *  @param n  Length of the resulting string.
688169691Skan       *  @param c  The character to use.
689169691Skan       *  @return  Reference to this string.
690169691Skan       *
691169691Skan       *  This function sets the value of this string to @a n copies of
692169691Skan       *  character @a c.
693169691Skan       */
694169691Skan      __versa_string&
695169691Skan      assign(size_type __n, _CharT __c)
696169691Skan      { return _M_replace_aux(size_type(0), this->size(), __n, __c); }
697169691Skan
698169691Skan      /**
699169691Skan       *  @brief  Set value to a range of characters.
700169691Skan       *  @param first  Iterator referencing the first character to append.
701169691Skan       *  @param last  Iterator marking the end of the range.
702169691Skan       *  @return  Reference to this string.
703169691Skan       *
704169691Skan       *  Sets value of string to characters in the range [first,last).
705169691Skan      */
706169691Skan      template<class _InputIterator>
707169691Skan        __versa_string&
708169691Skan        assign(_InputIterator __first, _InputIterator __last)
709169691Skan        { return this->replace(_M_ibegin(), _M_iend(), __first, __last); }
710169691Skan
711169691Skan      /**
712169691Skan       *  @brief  Insert multiple characters.
713169691Skan       *  @param p  Iterator referencing location in string to insert at.
714169691Skan       *  @param n  Number of characters to insert
715169691Skan       *  @param c  The character to insert.
716169691Skan       *  @throw  std::length_error  If new length exceeds @c max_size().
717169691Skan       *
718169691Skan       *  Inserts @a n copies of character @a c starting at the position
719169691Skan       *  referenced by iterator @a p.  If adding characters causes the length
720169691Skan       *  to exceed max_size(), length_error is thrown.  The value of the
721169691Skan       *  string doesn't change if an error is thrown.
722169691Skan      */
723169691Skan      void
724169691Skan      insert(iterator __p, size_type __n, _CharT __c)
725169691Skan      {	this->replace(__p, __p, __n, __c);  }
726169691Skan
727169691Skan      /**
728169691Skan       *  @brief  Insert a range of characters.
729169691Skan       *  @param p  Iterator referencing location in string to insert at.
730169691Skan       *  @param beg  Start of range.
731169691Skan       *  @param end  End of range.
732169691Skan       *  @throw  std::length_error  If new length exceeds @c max_size().
733169691Skan       *
734169691Skan       *  Inserts characters in range [beg,end).  If adding characters causes
735169691Skan       *  the length to exceed max_size(), length_error is thrown.  The value
736169691Skan       *  of the string doesn't change if an error is thrown.
737169691Skan      */
738169691Skan      template<class _InputIterator>
739169691Skan        void
740169691Skan        insert(iterator __p, _InputIterator __beg, _InputIterator __end)
741169691Skan        { this->replace(__p, __p, __beg, __end); }
742169691Skan
743169691Skan      /**
744169691Skan       *  @brief  Insert value of a string.
745169691Skan       *  @param pos1  Iterator referencing location in string to insert at.
746169691Skan       *  @param str  The string to insert.
747169691Skan       *  @return  Reference to this string.
748169691Skan       *  @throw  std::length_error  If new length exceeds @c max_size().
749169691Skan       *
750169691Skan       *  Inserts value of @a str starting at @a pos1.  If adding characters
751169691Skan       *  causes the length to exceed max_size(), length_error is thrown.  The
752169691Skan       *  value of the string doesn't change if an error is thrown.
753169691Skan      */
754169691Skan      __versa_string&
755169691Skan      insert(size_type __pos1, const __versa_string& __str)
756169691Skan      { return this->replace(__pos1, size_type(0),
757169691Skan			     __str._M_data(), __str.size()); }
758169691Skan
759169691Skan      /**
760169691Skan       *  @brief  Insert a substring.
761169691Skan       *  @param pos1  Iterator referencing location in string to insert at.
762169691Skan       *  @param str  The string to insert.
763169691Skan       *  @param pos2  Start of characters in str to insert.
764169691Skan       *  @param n  Number of characters to insert.
765169691Skan       *  @return  Reference to this string.
766169691Skan       *  @throw  std::length_error  If new length exceeds @c max_size().
767169691Skan       *  @throw  std::out_of_range  If @a pos1 > size() or
768169691Skan       *  @a pos2 > @a str.size().
769169691Skan       *
770169691Skan       *  Starting at @a pos1, insert @a n character of @a str beginning with
771169691Skan       *  @a pos2.  If adding characters causes the length to exceed
772169691Skan       *  max_size(), length_error is thrown.  If @a pos1 is beyond the end of
773169691Skan       *  this string or @a pos2 is beyond the end of @a str, out_of_range is
774169691Skan       *  thrown.  The value of the string doesn't change if an error is
775169691Skan       *  thrown.
776169691Skan      */
777169691Skan      __versa_string&
778169691Skan      insert(size_type __pos1, const __versa_string& __str,
779169691Skan	     size_type __pos2, size_type __n)
780169691Skan      { return this->replace(__pos1, size_type(0), __str._M_data()
781169691Skan			     + __str._M_check(__pos2, "__versa_string::insert"),
782169691Skan			     __str._M_limit(__pos2, __n)); }
783169691Skan
784169691Skan      /**
785169691Skan       *  @brief  Insert a C substring.
786169691Skan       *  @param pos  Iterator referencing location in string to insert at.
787169691Skan       *  @param s  The C string to insert.
788169691Skan       *  @param n  The number of characters to insert.
789169691Skan       *  @return  Reference to this string.
790169691Skan       *  @throw  std::length_error  If new length exceeds @c max_size().
791169691Skan       *  @throw  std::out_of_range  If @a pos is beyond the end of this
792169691Skan       *  string.
793169691Skan       *
794169691Skan       *  Inserts the first @a n characters of @a s starting at @a pos.  If
795169691Skan       *  adding characters causes the length to exceed max_size(),
796169691Skan       *  length_error is thrown.  If @a pos is beyond end(), out_of_range is
797169691Skan       *  thrown.  The value of the string doesn't change if an error is
798169691Skan       *  thrown.
799169691Skan      */
800169691Skan      __versa_string&
801169691Skan      insert(size_type __pos, const _CharT* __s, size_type __n)
802169691Skan      { return this->replace(__pos, size_type(0), __s, __n); }
803169691Skan
804169691Skan      /**
805169691Skan       *  @brief  Insert a C string.
806169691Skan       *  @param pos  Iterator referencing location in string to insert at.
807169691Skan       *  @param s  The C string to insert.
808169691Skan       *  @return  Reference to this string.
809169691Skan       *  @throw  std::length_error  If new length exceeds @c max_size().
810169691Skan       *  @throw  std::out_of_range  If @a pos is beyond the end of this
811169691Skan       *  string.
812169691Skan       *
813169691Skan       *  Inserts the first @a n characters of @a s starting at @a pos.  If
814169691Skan       *  adding characters causes the length to exceed max_size(),
815169691Skan       *  length_error is thrown.  If @a pos is beyond end(), out_of_range is
816169691Skan       *  thrown.  The value of the string doesn't change if an error is
817169691Skan       *  thrown.
818169691Skan      */
819169691Skan      __versa_string&
820169691Skan      insert(size_type __pos, const _CharT* __s)
821169691Skan      {
822169691Skan	__glibcxx_requires_string(__s);
823169691Skan	return this->replace(__pos, size_type(0), __s,
824169691Skan			     traits_type::length(__s));
825169691Skan      }
826169691Skan
827169691Skan      /**
828169691Skan       *  @brief  Insert multiple characters.
829169691Skan       *  @param pos  Index in string to insert at.
830169691Skan       *  @param n  Number of characters to insert
831169691Skan       *  @param c  The character to insert.
832169691Skan       *  @return  Reference to this string.
833169691Skan       *  @throw  std::length_error  If new length exceeds @c max_size().
834169691Skan       *  @throw  std::out_of_range  If @a pos is beyond the end of this
835169691Skan       *  string.
836169691Skan       *
837169691Skan       *  Inserts @a n copies of character @a c starting at index @a pos.  If
838169691Skan       *  adding characters causes the length to exceed max_size(),
839169691Skan       *  length_error is thrown.  If @a pos > length(), out_of_range is
840169691Skan       *  thrown.  The value of the string doesn't change if an error is
841169691Skan       *  thrown.
842169691Skan      */
843169691Skan      __versa_string&
844169691Skan      insert(size_type __pos, size_type __n, _CharT __c)
845169691Skan      { return _M_replace_aux(_M_check(__pos, "__versa_string::insert"),
846169691Skan			      size_type(0), __n, __c); }
847169691Skan
848169691Skan      /**
849169691Skan       *  @brief  Insert one character.
850169691Skan       *  @param p  Iterator referencing position in string to insert at.
851169691Skan       *  @param c  The character to insert.
852169691Skan       *  @return  Iterator referencing newly inserted char.
853169691Skan       *  @throw  std::length_error  If new length exceeds @c max_size().
854169691Skan       *
855169691Skan       *  Inserts character @a c at position referenced by @a p.  If adding
856169691Skan       *  character causes the length to exceed max_size(), length_error is
857169691Skan       *  thrown.  If @a p is beyond end of string, out_of_range is thrown.
858169691Skan       *  The value of the string doesn't change if an error is thrown.
859169691Skan      */
860169691Skan      iterator
861169691Skan      insert(iterator __p, _CharT __c)
862169691Skan      {
863169691Skan	_GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend());
864169691Skan	const size_type __pos = __p - _M_ibegin();
865169691Skan	_M_replace_aux(__pos, size_type(0), size_type(1), __c);
866169691Skan	this->_M_set_leaked();
867169691Skan	return iterator(this->_M_data() + __pos);
868169691Skan      }
869169691Skan
870169691Skan      /**
871169691Skan       *  @brief  Remove characters.
872169691Skan       *  @param pos  Index of first character to remove (default 0).
873169691Skan       *  @param n  Number of characters to remove (default remainder).
874169691Skan       *  @return  Reference to this string.
875169691Skan       *  @throw  std::out_of_range  If @a pos is beyond the end of this
876169691Skan       *  string.
877169691Skan       *
878169691Skan       *  Removes @a n characters from this string starting at @a pos.  The
879169691Skan       *  length of the string is reduced by @a n.  If there are < @a n
880169691Skan       *  characters to remove, the remainder of the string is truncated.  If
881169691Skan       *  @a p is beyond end of string, out_of_range is thrown.  The value of
882169691Skan       *  the string doesn't change if an error is thrown.
883169691Skan      */
884169691Skan      __versa_string&
885169691Skan      erase(size_type __pos = 0, size_type __n = npos)
886169691Skan      {
887169691Skan	this->_M_erase(_M_check(__pos, "__versa_string::erase"),
888169691Skan		       _M_limit(__pos, __n));
889169691Skan	return *this;
890169691Skan      }
891169691Skan
892169691Skan      /**
893169691Skan       *  @brief  Remove one character.
894169691Skan       *  @param position  Iterator referencing the character to remove.
895169691Skan       *  @return  iterator referencing same location after removal.
896169691Skan       *
897169691Skan       *  Removes the character at @a position from this string. The value
898169691Skan       *  of the string doesn't change if an error is thrown.
899169691Skan      */
900169691Skan      iterator
901169691Skan      erase(iterator __position)
902169691Skan      {
903169691Skan	_GLIBCXX_DEBUG_PEDASSERT(__position >= _M_ibegin()
904169691Skan				 && __position < _M_iend());
905169691Skan	const size_type __pos = __position - _M_ibegin();
906169691Skan	this->_M_erase(__pos, size_type(1));
907169691Skan	this->_M_set_leaked();
908169691Skan	return iterator(this->_M_data() + __pos);
909169691Skan      }
910169691Skan
911169691Skan      /**
912169691Skan       *  @brief  Remove a range of characters.
913169691Skan       *  @param first  Iterator referencing the first character to remove.
914169691Skan       *  @param last  Iterator referencing the end of the range.
915169691Skan       *  @return  Iterator referencing location of first after removal.
916169691Skan       *
917169691Skan       *  Removes the characters in the range [first,last) from this string.
918169691Skan       *  The value of the string doesn't change if an error is thrown.
919169691Skan      */
920169691Skan      iterator
921169691Skan      erase(iterator __first, iterator __last)
922169691Skan      {
923169691Skan	_GLIBCXX_DEBUG_PEDASSERT(__first >= _M_ibegin() && __first <= __last
924169691Skan				 && __last <= _M_iend());
925169691Skan        const size_type __pos = __first - _M_ibegin();
926169691Skan	this->_M_erase(__pos, __last - __first);
927169691Skan	this->_M_set_leaked();
928169691Skan	return iterator(this->_M_data() + __pos);
929169691Skan      }
930169691Skan
931169691Skan      /**
932169691Skan       *  @brief  Replace characters with value from another string.
933169691Skan       *  @param pos  Index of first character to replace.
934169691Skan       *  @param n  Number of characters to be replaced.
935169691Skan       *  @param str  String to insert.
936169691Skan       *  @return  Reference to this string.
937169691Skan       *  @throw  std::out_of_range  If @a pos is beyond the end of this
938169691Skan       *  string.
939169691Skan       *  @throw  std::length_error  If new length exceeds @c max_size().
940169691Skan       *
941169691Skan       *  Removes the characters in the range [pos,pos+n) from this string.
942169691Skan       *  In place, the value of @a str is inserted.  If @a pos is beyond end
943169691Skan       *  of string, out_of_range is thrown.  If the length of the result
944169691Skan       *  exceeds max_size(), length_error is thrown.  The value of the string
945169691Skan       *  doesn't change if an error is thrown.
946169691Skan      */
947169691Skan      __versa_string&
948169691Skan      replace(size_type __pos, size_type __n, const __versa_string& __str)
949169691Skan      { return this->replace(__pos, __n, __str._M_data(), __str.size()); }
950169691Skan
951169691Skan      /**
952169691Skan       *  @brief  Replace characters with value from another string.
953169691Skan       *  @param pos1  Index of first character to replace.
954169691Skan       *  @param n1  Number of characters to be replaced.
955169691Skan       *  @param str  String to insert.
956169691Skan       *  @param pos2  Index of first character of str to use.
957169691Skan       *  @param n2  Number of characters from str to use.
958169691Skan       *  @return  Reference to this string.
959169691Skan       *  @throw  std::out_of_range  If @a pos1 > size() or @a pos2 >
960169691Skan       *  str.size().
961169691Skan       *  @throw  std::length_error  If new length exceeds @c max_size().
962169691Skan       *
963169691Skan       *  Removes the characters in the range [pos1,pos1 + n) from this
964169691Skan       *  string.  In place, the value of @a str is inserted.  If @a pos is
965169691Skan       *  beyond end of string, out_of_range is thrown.  If the length of the
966169691Skan       *  result exceeds max_size(), length_error is thrown.  The value of the
967169691Skan       *  string doesn't change if an error is thrown.
968169691Skan      */
969169691Skan      __versa_string&
970169691Skan      replace(size_type __pos1, size_type __n1, const __versa_string& __str,
971169691Skan	      size_type __pos2, size_type __n2)
972169691Skan      {
973169691Skan	return this->replace(__pos1, __n1, __str._M_data()
974169691Skan			     + __str._M_check(__pos2,
975169691Skan					      "__versa_string::replace"),
976169691Skan			     __str._M_limit(__pos2, __n2));
977169691Skan      }
978169691Skan
979169691Skan      /**
980169691Skan       *  @brief  Replace characters with value of a C substring.
981169691Skan       *  @param pos  Index of first character to replace.
982169691Skan       *  @param n1  Number of characters to be replaced.
983169691Skan       *  @param s  C string to insert.
984169691Skan       *  @param n2  Number of characters from @a s to use.
985169691Skan       *  @return  Reference to this string.
986169691Skan       *  @throw  std::out_of_range  If @a pos1 > size().
987169691Skan       *  @throw  std::length_error  If new length exceeds @c max_size().
988169691Skan       *
989169691Skan       *  Removes the characters in the range [pos,pos + n1) from this string.
990169691Skan       *  In place, the first @a n2 characters of @a s are inserted, or all
991169691Skan       *  of @a s if @a n2 is too large.  If @a pos is beyond end of string,
992169691Skan       *  out_of_range is thrown.  If the length of result exceeds max_size(),
993169691Skan       *  length_error is thrown.  The value of the string doesn't change if
994169691Skan       *  an error is thrown.
995169691Skan      */
996169691Skan      __versa_string&
997169691Skan      replace(size_type __pos, size_type __n1, const _CharT* __s,
998169691Skan	      size_type __n2)
999169691Skan      {
1000169691Skan	__glibcxx_requires_string_len(__s, __n2);
1001169691Skan	return _M_replace(_M_check(__pos, "__versa_string::replace"),
1002169691Skan			  _M_limit(__pos, __n1), __s, __n2);
1003169691Skan      }
1004169691Skan
1005169691Skan      /**
1006169691Skan       *  @brief  Replace characters with value of a C string.
1007169691Skan       *  @param pos  Index of first character to replace.
1008169691Skan       *  @param n1  Number of characters to be replaced.
1009169691Skan       *  @param s  C string to insert.
1010169691Skan       *  @return  Reference to this string.
1011169691Skan       *  @throw  std::out_of_range  If @a pos > size().
1012169691Skan       *  @throw  std::length_error  If new length exceeds @c max_size().
1013169691Skan       *
1014169691Skan       *  Removes the characters in the range [pos,pos + n1) from this string.
1015169691Skan       *  In place, the first @a n characters of @a s are inserted.  If @a
1016169691Skan       *  pos is beyond end of string, out_of_range is thrown.  If the length
1017169691Skan       *  of result exceeds max_size(), length_error is thrown.  The value of
1018169691Skan       *  the string doesn't change if an error is thrown.
1019169691Skan      */
1020169691Skan      __versa_string&
1021169691Skan      replace(size_type __pos, size_type __n1, const _CharT* __s)
1022169691Skan      {
1023169691Skan	__glibcxx_requires_string(__s);
1024169691Skan	return this->replace(__pos, __n1, __s, traits_type::length(__s));
1025169691Skan      }
1026169691Skan
1027169691Skan      /**
1028169691Skan       *  @brief  Replace characters with multiple characters.
1029169691Skan       *  @param pos  Index of first character to replace.
1030169691Skan       *  @param n1  Number of characters to be replaced.
1031169691Skan       *  @param n2  Number of characters to insert.
1032169691Skan       *  @param c  Character to insert.
1033169691Skan       *  @return  Reference to this string.
1034169691Skan       *  @throw  std::out_of_range  If @a pos > size().
1035169691Skan       *  @throw  std::length_error  If new length exceeds @c max_size().
1036169691Skan       *
1037169691Skan       *  Removes the characters in the range [pos,pos + n1) from this string.
1038169691Skan       *  In place, @a n2 copies of @a c are inserted.  If @a pos is beyond
1039169691Skan       *  end of string, out_of_range is thrown.  If the length of result
1040169691Skan       *  exceeds max_size(), length_error is thrown.  The value of the string
1041169691Skan       *  doesn't change if an error is thrown.
1042169691Skan      */
1043169691Skan      __versa_string&
1044169691Skan      replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
1045169691Skan      { return _M_replace_aux(_M_check(__pos, "__versa_string::replace"),
1046169691Skan			      _M_limit(__pos, __n1), __n2, __c); }
1047169691Skan
1048169691Skan      /**
1049169691Skan       *  @brief  Replace range of characters with string.
1050169691Skan       *  @param i1  Iterator referencing start of range to replace.
1051169691Skan       *  @param i2  Iterator referencing end of range to replace.
1052169691Skan       *  @param str  String value to insert.
1053169691Skan       *  @return  Reference to this string.
1054169691Skan       *  @throw  std::length_error  If new length exceeds @c max_size().
1055169691Skan       *
1056169691Skan       *  Removes the characters in the range [i1,i2).  In place, the value of
1057169691Skan       *  @a str is inserted.  If the length of result exceeds max_size(),
1058169691Skan       *  length_error is thrown.  The value of the string doesn't change if
1059169691Skan       *  an error is thrown.
1060169691Skan      */
1061169691Skan      __versa_string&
1062169691Skan      replace(iterator __i1, iterator __i2, const __versa_string& __str)
1063169691Skan      { return this->replace(__i1, __i2, __str._M_data(), __str.size()); }
1064169691Skan
1065169691Skan      /**
1066169691Skan       *  @brief  Replace range of characters with C substring.
1067169691Skan       *  @param i1  Iterator referencing start of range to replace.
1068169691Skan       *  @param i2  Iterator referencing end of range to replace.
1069169691Skan       *  @param s  C string value to insert.
1070169691Skan       *  @param n  Number of characters from s to insert.
1071169691Skan       *  @return  Reference to this string.
1072169691Skan       *  @throw  std::length_error  If new length exceeds @c max_size().
1073169691Skan       *
1074169691Skan       *  Removes the characters in the range [i1,i2).  In place, the first @a
1075169691Skan       *  n characters of @a s are inserted.  If the length of result exceeds
1076169691Skan       *  max_size(), length_error is thrown.  The value of the string doesn't
1077169691Skan       *  change if an error is thrown.
1078169691Skan      */
1079169691Skan      __versa_string&
1080169691Skan      replace(iterator __i1, iterator __i2, const _CharT* __s, size_type __n)
1081169691Skan      {
1082169691Skan	_GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1083169691Skan				 && __i2 <= _M_iend());
1084169691Skan	return this->replace(__i1 - _M_ibegin(), __i2 - __i1, __s, __n);
1085169691Skan      }
1086169691Skan
1087169691Skan      /**
1088169691Skan       *  @brief  Replace range of characters with C string.
1089169691Skan       *  @param i1  Iterator referencing start of range to replace.
1090169691Skan       *  @param i2  Iterator referencing end of range to replace.
1091169691Skan       *  @param s  C string value to insert.
1092169691Skan       *  @return  Reference to this string.
1093169691Skan       *  @throw  std::length_error  If new length exceeds @c max_size().
1094169691Skan       *
1095169691Skan       *  Removes the characters in the range [i1,i2).  In place, the
1096169691Skan       *  characters of @a s are inserted.  If the length of result exceeds
1097169691Skan       *  max_size(), length_error is thrown.  The value of the string doesn't
1098169691Skan       *  change if an error is thrown.
1099169691Skan      */
1100169691Skan      __versa_string&
1101169691Skan      replace(iterator __i1, iterator __i2, const _CharT* __s)
1102169691Skan      {
1103169691Skan	__glibcxx_requires_string(__s);
1104169691Skan	return this->replace(__i1, __i2, __s, traits_type::length(__s));
1105169691Skan      }
1106169691Skan
1107169691Skan      /**
1108169691Skan       *  @brief  Replace range of characters with multiple characters
1109169691Skan       *  @param i1  Iterator referencing start of range to replace.
1110169691Skan       *  @param i2  Iterator referencing end of range to replace.
1111169691Skan       *  @param n  Number of characters to insert.
1112169691Skan       *  @param c  Character to insert.
1113169691Skan       *  @return  Reference to this string.
1114169691Skan       *  @throw  std::length_error  If new length exceeds @c max_size().
1115169691Skan       *
1116169691Skan       *  Removes the characters in the range [i1,i2).  In place, @a n copies
1117169691Skan       *  of @a c are inserted.  If the length of result exceeds max_size(),
1118169691Skan       *  length_error is thrown.  The value of the string doesn't change if
1119169691Skan       *  an error is thrown.
1120169691Skan      */
1121169691Skan      __versa_string&
1122169691Skan      replace(iterator __i1, iterator __i2, size_type __n, _CharT __c)
1123169691Skan      {
1124169691Skan	_GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1125169691Skan				 && __i2 <= _M_iend());
1126169691Skan	return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __c);
1127169691Skan      }
1128169691Skan
1129169691Skan      /**
1130169691Skan       *  @brief  Replace range of characters with range.
1131169691Skan       *  @param i1  Iterator referencing start of range to replace.
1132169691Skan       *  @param i2  Iterator referencing end of range to replace.
1133169691Skan       *  @param k1  Iterator referencing start of range to insert.
1134169691Skan       *  @param k2  Iterator referencing end of range to insert.
1135169691Skan       *  @return  Reference to this string.
1136169691Skan       *  @throw  std::length_error  If new length exceeds @c max_size().
1137169691Skan       *
1138169691Skan       *  Removes the characters in the range [i1,i2).  In place, characters
1139169691Skan       *  in the range [k1,k2) are inserted.  If the length of result exceeds
1140169691Skan       *  max_size(), length_error is thrown.  The value of the string doesn't
1141169691Skan       *  change if an error is thrown.
1142169691Skan      */
1143169691Skan      template<class _InputIterator>
1144169691Skan        __versa_string&
1145169691Skan        replace(iterator __i1, iterator __i2,
1146169691Skan		_InputIterator __k1, _InputIterator __k2)
1147169691Skan        {
1148169691Skan	  _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1149169691Skan				   && __i2 <= _M_iend());
1150169691Skan	  __glibcxx_requires_valid_range(__k1, __k2);
1151169691Skan	  typedef typename std::__is_integer<_InputIterator>::__type _Integral;
1152169691Skan	  return _M_replace_dispatch(__i1, __i2, __k1, __k2, _Integral());
1153169691Skan	}
1154169691Skan
1155169691Skan      // Specializations for the common case of pointer and iterator:
1156169691Skan      // useful to avoid the overhead of temporary buffering in _M_replace.
1157169691Skan      __versa_string&
1158169691Skan      replace(iterator __i1, iterator __i2, _CharT* __k1, _CharT* __k2)
1159169691Skan      {
1160169691Skan	_GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1161169691Skan				 && __i2 <= _M_iend());
1162169691Skan	__glibcxx_requires_valid_range(__k1, __k2);
1163169691Skan	return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
1164169691Skan			     __k1, __k2 - __k1);
1165169691Skan      }
1166169691Skan
1167169691Skan      __versa_string&
1168169691Skan      replace(iterator __i1, iterator __i2,
1169169691Skan	      const _CharT* __k1, const _CharT* __k2)
1170169691Skan      {
1171169691Skan	_GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1172169691Skan				 && __i2 <= _M_iend());
1173169691Skan	__glibcxx_requires_valid_range(__k1, __k2);
1174169691Skan	return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
1175169691Skan			     __k1, __k2 - __k1);
1176169691Skan      }
1177169691Skan
1178169691Skan      __versa_string&
1179169691Skan      replace(iterator __i1, iterator __i2, iterator __k1, iterator __k2)
1180169691Skan      {
1181169691Skan	_GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1182169691Skan				 && __i2 <= _M_iend());
1183169691Skan	__glibcxx_requires_valid_range(__k1, __k2);
1184169691Skan	return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
1185169691Skan			     __k1.base(), __k2 - __k1);
1186169691Skan      }
1187169691Skan
1188169691Skan      __versa_string&
1189169691Skan      replace(iterator __i1, iterator __i2,
1190169691Skan	      const_iterator __k1, const_iterator __k2)
1191169691Skan      {
1192169691Skan	_GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1193169691Skan				 && __i2 <= _M_iend());
1194169691Skan	__glibcxx_requires_valid_range(__k1, __k2);
1195169691Skan	return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
1196169691Skan			     __k1.base(), __k2 - __k1);
1197169691Skan      }
1198169691Skan
1199169691Skan    private:
1200169691Skan      template<class _Integer>
1201169691Skan	__versa_string&
1202169691Skan	_M_replace_dispatch(iterator __i1, iterator __i2, _Integer __n,
1203169691Skan			    _Integer __val, std::__true_type)
1204169691Skan        { return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __val); }
1205169691Skan
1206169691Skan      template<class _InputIterator>
1207169691Skan	__versa_string&
1208169691Skan	_M_replace_dispatch(iterator __i1, iterator __i2, _InputIterator __k1,
1209169691Skan			    _InputIterator __k2, std::__false_type);
1210169691Skan
1211169691Skan      __versa_string&
1212169691Skan      _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2,
1213169691Skan		     _CharT __c);
1214169691Skan
1215169691Skan      __versa_string&
1216169691Skan      _M_replace(size_type __pos, size_type __len1, const _CharT* __s,
1217169691Skan		 const size_type __len2);
1218169691Skan
1219169691Skan      __versa_string&
1220169691Skan      _M_append(const _CharT* __s, size_type __n);
1221169691Skan
1222169691Skan    public:
1223169691Skan
1224169691Skan      /**
1225169691Skan       *  @brief  Copy substring into C string.
1226169691Skan       *  @param s  C string to copy value into.
1227169691Skan       *  @param n  Number of characters to copy.
1228169691Skan       *  @param pos  Index of first character to copy.
1229169691Skan       *  @return  Number of characters actually copied
1230169691Skan       *  @throw  std::out_of_range  If pos > size().
1231169691Skan       *
1232169691Skan       *  Copies up to @a n characters starting at @a pos into the C string @a
1233169691Skan       *  s.  If @a pos is greater than size(), out_of_range is thrown.
1234169691Skan      */
1235169691Skan      size_type
1236169691Skan      copy(_CharT* __s, size_type __n, size_type __pos = 0) const;
1237169691Skan
1238169691Skan      /**
1239169691Skan       *  @brief  Swap contents with another string.
1240169691Skan       *  @param s  String to swap with.
1241169691Skan       *
1242169691Skan       *  Exchanges the contents of this string with that of @a s in constant
1243169691Skan       *  time.
1244169691Skan      */
1245169691Skan      void
1246169691Skan      swap(__versa_string& __s)
1247169691Skan      { this->_M_swap(__s); }
1248169691Skan
1249169691Skan      // String operations:
1250169691Skan      /**
1251169691Skan       *  @brief  Return const pointer to null-terminated contents.
1252169691Skan       *
1253169691Skan       *  This is a handle to internal data.  Do not modify or dire things may
1254169691Skan       *  happen.
1255169691Skan      */
1256169691Skan      const _CharT*
1257169691Skan      c_str() const
1258169691Skan      { return this->_M_data(); }
1259169691Skan
1260169691Skan      /**
1261169691Skan       *  @brief  Return const pointer to contents.
1262169691Skan       *
1263169691Skan       *  This is a handle to internal data.  Do not modify or dire things may
1264169691Skan       *  happen.
1265169691Skan      */
1266169691Skan      const _CharT*
1267169691Skan      data() const
1268169691Skan      { return this->_M_data(); }
1269169691Skan
1270169691Skan      /**
1271169691Skan       *  @brief  Return copy of allocator used to construct this string.
1272169691Skan      */
1273169691Skan      allocator_type
1274169691Skan      get_allocator() const
1275169691Skan      { return allocator_type(this->_M_get_allocator()); }
1276169691Skan
1277169691Skan      /**
1278169691Skan       *  @brief  Find position of a C substring.
1279169691Skan       *  @param s  C string to locate.
1280169691Skan       *  @param pos  Index of character to search from.
1281169691Skan       *  @param n  Number of characters from @a s to search for.
1282169691Skan       *  @return  Index of start of first occurrence.
1283169691Skan       *
1284169691Skan       *  Starting from @a pos, searches forward for the first @a n characters
1285169691Skan       *  in @a s within this string.  If found, returns the index where it
1286169691Skan       *  begins.  If not found, returns npos.
1287169691Skan      */
1288169691Skan      size_type
1289169691Skan      find(const _CharT* __s, size_type __pos, size_type __n) const;
1290169691Skan
1291169691Skan      /**
1292169691Skan       *  @brief  Find position of a string.
1293169691Skan       *  @param str  String to locate.
1294169691Skan       *  @param pos  Index of character to search from (default 0).
1295169691Skan       *  @return  Index of start of first occurrence.
1296169691Skan       *
1297169691Skan       *  Starting from @a pos, searches forward for value of @a str within
1298169691Skan       *  this string.  If found, returns the index where it begins.  If not
1299169691Skan       *  found, returns npos.
1300169691Skan      */
1301169691Skan      size_type
1302169691Skan      find(const __versa_string& __str, size_type __pos = 0) const
1303169691Skan      { return this->find(__str.data(), __pos, __str.size()); }
1304169691Skan
1305169691Skan      /**
1306169691Skan       *  @brief  Find position of a C string.
1307169691Skan       *  @param s  C string to locate.
1308169691Skan       *  @param pos  Index of character to search from (default 0).
1309169691Skan       *  @return  Index of start of first occurrence.
1310169691Skan       *
1311169691Skan       *  Starting from @a pos, searches forward for the value of @a s within
1312169691Skan       *  this string.  If found, returns the index where it begins.  If not
1313169691Skan       *  found, returns npos.
1314169691Skan      */
1315169691Skan      size_type
1316169691Skan      find(const _CharT* __s, size_type __pos = 0) const
1317169691Skan      {
1318169691Skan	__glibcxx_requires_string(__s);
1319169691Skan	return this->find(__s, __pos, traits_type::length(__s));
1320169691Skan      }
1321169691Skan
1322169691Skan      /**
1323169691Skan       *  @brief  Find position of a character.
1324169691Skan       *  @param c  Character to locate.
1325169691Skan       *  @param pos  Index of character to search from (default 0).
1326169691Skan       *  @return  Index of first occurrence.
1327169691Skan       *
1328169691Skan       *  Starting from @a pos, searches forward for @a c within this string.
1329169691Skan       *  If found, returns the index where it was found.  If not found,
1330169691Skan       *  returns npos.
1331169691Skan      */
1332169691Skan      size_type
1333169691Skan      find(_CharT __c, size_type __pos = 0) const;
1334169691Skan
1335169691Skan      /**
1336169691Skan       *  @brief  Find last position of a string.
1337169691Skan       *  @param str  String to locate.
1338169691Skan       *  @param pos  Index of character to search back from (default end).
1339169691Skan       *  @return  Index of start of last occurrence.
1340169691Skan       *
1341169691Skan       *  Starting from @a pos, searches backward for value of @a str within
1342169691Skan       *  this string.  If found, returns the index where it begins.  If not
1343169691Skan       *  found, returns npos.
1344169691Skan      */
1345169691Skan      size_type
1346169691Skan      rfind(const __versa_string& __str, size_type __pos = npos) const
1347169691Skan      { return this->rfind(__str.data(), __pos, __str.size()); }
1348169691Skan
1349169691Skan      /**
1350169691Skan       *  @brief  Find last position of a C substring.
1351169691Skan       *  @param s  C string to locate.
1352169691Skan       *  @param pos  Index of character to search back from.
1353169691Skan       *  @param n  Number of characters from s to search for.
1354169691Skan       *  @return  Index of start of last occurrence.
1355169691Skan       *
1356169691Skan       *  Starting from @a pos, searches backward for the first @a n
1357169691Skan       *  characters in @a s within this string.  If found, returns the index
1358169691Skan       *  where it begins.  If not found, returns npos.
1359169691Skan      */
1360169691Skan      size_type
1361169691Skan      rfind(const _CharT* __s, size_type __pos, size_type __n) const;
1362169691Skan
1363169691Skan      /**
1364169691Skan       *  @brief  Find last position of a C string.
1365169691Skan       *  @param s  C string to locate.
1366169691Skan       *  @param pos  Index of character to start search at (default end).
1367169691Skan       *  @return  Index of start of  last occurrence.
1368169691Skan       *
1369169691Skan       *  Starting from @a pos, searches backward for the value of @a s within
1370169691Skan       *  this string.  If found, returns the index where it begins.  If not
1371169691Skan       *  found, returns npos.
1372169691Skan      */
1373169691Skan      size_type
1374169691Skan      rfind(const _CharT* __s, size_type __pos = npos) const
1375169691Skan      {
1376169691Skan	__glibcxx_requires_string(__s);
1377169691Skan	return this->rfind(__s, __pos, traits_type::length(__s));
1378169691Skan      }
1379169691Skan
1380169691Skan      /**
1381169691Skan       *  @brief  Find last position of a character.
1382169691Skan       *  @param c  Character to locate.
1383169691Skan       *  @param pos  Index of character to search back from (default end).
1384169691Skan       *  @return  Index of last occurrence.
1385169691Skan       *
1386169691Skan       *  Starting from @a pos, searches backward for @a c within this string.
1387169691Skan       *  If found, returns the index where it was found.  If not found,
1388169691Skan       *  returns npos.
1389169691Skan      */
1390169691Skan      size_type
1391169691Skan      rfind(_CharT __c, size_type __pos = npos) const;
1392169691Skan
1393169691Skan      /**
1394169691Skan       *  @brief  Find position of a character of string.
1395169691Skan       *  @param str  String containing characters to locate.
1396169691Skan       *  @param pos  Index of character to search from (default 0).
1397169691Skan       *  @return  Index of first occurrence.
1398169691Skan       *
1399169691Skan       *  Starting from @a pos, searches forward for one of the characters of
1400169691Skan       *  @a str within this string.  If found, returns the index where it was
1401169691Skan       *  found.  If not found, returns npos.
1402169691Skan      */
1403169691Skan      size_type
1404169691Skan      find_first_of(const __versa_string& __str, size_type __pos = 0) const
1405169691Skan      { return this->find_first_of(__str.data(), __pos, __str.size()); }
1406169691Skan
1407169691Skan      /**
1408169691Skan       *  @brief  Find position of a character of C substring.
1409169691Skan       *  @param s  String containing characters to locate.
1410228780Spfg       *  @param pos  Index of character to search from.
1411169691Skan       *  @param n  Number of characters from s to search for.
1412169691Skan       *  @return  Index of first occurrence.
1413169691Skan       *
1414169691Skan       *  Starting from @a pos, searches forward for one of the first @a n
1415169691Skan       *  characters of @a s within this string.  If found, returns the index
1416169691Skan       *  where it was found.  If not found, returns npos.
1417169691Skan      */
1418169691Skan      size_type
1419169691Skan      find_first_of(const _CharT* __s, size_type __pos, size_type __n) const;
1420169691Skan
1421169691Skan      /**
1422169691Skan       *  @brief  Find position of a character of C string.
1423169691Skan       *  @param s  String containing characters to locate.
1424169691Skan       *  @param pos  Index of character to search from (default 0).
1425169691Skan       *  @return  Index of first occurrence.
1426169691Skan       *
1427169691Skan       *  Starting from @a pos, searches forward for one of the characters of
1428169691Skan       *  @a s within this string.  If found, returns the index where it was
1429169691Skan       *  found.  If not found, returns npos.
1430169691Skan      */
1431169691Skan      size_type
1432169691Skan      find_first_of(const _CharT* __s, size_type __pos = 0) const
1433169691Skan      {
1434169691Skan	__glibcxx_requires_string(__s);
1435169691Skan	return this->find_first_of(__s, __pos, traits_type::length(__s));
1436169691Skan      }
1437169691Skan
1438169691Skan      /**
1439169691Skan       *  @brief  Find position of a character.
1440169691Skan       *  @param c  Character to locate.
1441169691Skan       *  @param pos  Index of character to search from (default 0).
1442169691Skan       *  @return  Index of first occurrence.
1443169691Skan       *
1444169691Skan       *  Starting from @a pos, searches forward for the character @a c within
1445169691Skan       *  this string.  If found, returns the index where it was found.  If
1446169691Skan       *  not found, returns npos.
1447169691Skan       *
1448169691Skan       *  Note: equivalent to find(c, pos).
1449169691Skan      */
1450169691Skan      size_type
1451169691Skan      find_first_of(_CharT __c, size_type __pos = 0) const
1452169691Skan      { return this->find(__c, __pos); }
1453169691Skan
1454169691Skan      /**
1455169691Skan       *  @brief  Find last position of a character of string.
1456169691Skan       *  @param str  String containing characters to locate.
1457169691Skan       *  @param pos  Index of character to search back from (default end).
1458169691Skan       *  @return  Index of last occurrence.
1459169691Skan       *
1460169691Skan       *  Starting from @a pos, searches backward for one of the characters of
1461169691Skan       *  @a str within this string.  If found, returns the index where it was
1462169691Skan       *  found.  If not found, returns npos.
1463169691Skan      */
1464169691Skan      size_type
1465169691Skan      find_last_of(const __versa_string& __str, size_type __pos = npos) const
1466169691Skan      { return this->find_last_of(__str.data(), __pos, __str.size()); }
1467169691Skan
1468169691Skan      /**
1469169691Skan       *  @brief  Find last position of a character of C substring.
1470169691Skan       *  @param s  C string containing characters to locate.
1471228780Spfg       *  @param pos  Index of character to search back from.
1472169691Skan       *  @param n  Number of characters from s to search for.
1473169691Skan       *  @return  Index of last occurrence.
1474169691Skan       *
1475169691Skan       *  Starting from @a pos, searches backward for one of the first @a n
1476169691Skan       *  characters of @a s within this string.  If found, returns the index
1477169691Skan       *  where it was found.  If not found, returns npos.
1478169691Skan      */
1479169691Skan      size_type
1480169691Skan      find_last_of(const _CharT* __s, size_type __pos, size_type __n) const;
1481169691Skan
1482169691Skan      /**
1483169691Skan       *  @brief  Find last position of a character of C string.
1484169691Skan       *  @param s  C string containing characters to locate.
1485169691Skan       *  @param pos  Index of character to search back from (default end).
1486169691Skan       *  @return  Index of last occurrence.
1487169691Skan       *
1488169691Skan       *  Starting from @a pos, searches backward for one of the characters of
1489169691Skan       *  @a s within this string.  If found, returns the index where it was
1490169691Skan       *  found.  If not found, returns npos.
1491169691Skan      */
1492169691Skan      size_type
1493169691Skan      find_last_of(const _CharT* __s, size_type __pos = npos) const
1494169691Skan      {
1495169691Skan	__glibcxx_requires_string(__s);
1496169691Skan	return this->find_last_of(__s, __pos, traits_type::length(__s));
1497169691Skan      }
1498169691Skan
1499169691Skan      /**
1500169691Skan       *  @brief  Find last position of a character.
1501169691Skan       *  @param c  Character to locate.
1502228780Spfg       *  @param pos  Index of character to search back from (default end).
1503169691Skan       *  @return  Index of last occurrence.
1504169691Skan       *
1505169691Skan       *  Starting from @a pos, searches backward for @a c within this string.
1506169691Skan       *  If found, returns the index where it was found.  If not found,
1507169691Skan       *  returns npos.
1508169691Skan       *
1509169691Skan       *  Note: equivalent to rfind(c, pos).
1510169691Skan      */
1511169691Skan      size_type
1512169691Skan      find_last_of(_CharT __c, size_type __pos = npos) const
1513169691Skan      { return this->rfind(__c, __pos); }
1514169691Skan
1515169691Skan      /**
1516169691Skan       *  @brief  Find position of a character not in string.
1517169691Skan       *  @param str  String containing characters to avoid.
1518169691Skan       *  @param pos  Index of character to search from (default 0).
1519169691Skan       *  @return  Index of first occurrence.
1520169691Skan       *
1521169691Skan       *  Starting from @a pos, searches forward for a character not contained
1522169691Skan       *  in @a str within this string.  If found, returns the index where it
1523169691Skan       *  was found.  If not found, returns npos.
1524169691Skan      */
1525169691Skan      size_type
1526169691Skan      find_first_not_of(const __versa_string& __str, size_type __pos = 0) const
1527169691Skan      { return this->find_first_not_of(__str.data(), __pos, __str.size()); }
1528169691Skan
1529169691Skan      /**
1530169691Skan       *  @brief  Find position of a character not in C substring.
1531169691Skan       *  @param s  C string containing characters to avoid.
1532228780Spfg       *  @param pos  Index of character to search from.
1533169691Skan       *  @param n  Number of characters from s to consider.
1534169691Skan       *  @return  Index of first occurrence.
1535169691Skan       *
1536169691Skan       *  Starting from @a pos, searches forward for a character not contained
1537169691Skan       *  in the first @a n characters of @a s within this string.  If found,
1538169691Skan       *  returns the index where it was found.  If not found, returns npos.
1539169691Skan      */
1540169691Skan      size_type
1541169691Skan      find_first_not_of(const _CharT* __s, size_type __pos,
1542169691Skan			size_type __n) const;
1543169691Skan
1544169691Skan      /**
1545169691Skan       *  @brief  Find position of a character not in C string.
1546169691Skan       *  @param s  C string containing characters to avoid.
1547169691Skan       *  @param pos  Index of character to search from (default 0).
1548169691Skan       *  @return  Index of first occurrence.
1549169691Skan       *
1550169691Skan       *  Starting from @a pos, searches forward for a character not contained
1551169691Skan       *  in @a s within this string.  If found, returns the index where it
1552169691Skan       *  was found.  If not found, returns npos.
1553169691Skan      */
1554169691Skan      size_type
1555169691Skan      find_first_not_of(const _CharT* __s, size_type __pos = 0) const
1556169691Skan      {
1557169691Skan	__glibcxx_requires_string(__s);
1558169691Skan	return this->find_first_not_of(__s, __pos, traits_type::length(__s));
1559169691Skan      }
1560169691Skan
1561169691Skan      /**
1562169691Skan       *  @brief  Find position of a different character.
1563169691Skan       *  @param c  Character to avoid.
1564169691Skan       *  @param pos  Index of character to search from (default 0).
1565169691Skan       *  @return  Index of first occurrence.
1566169691Skan       *
1567169691Skan       *  Starting from @a pos, searches forward for a character other than @a c
1568169691Skan       *  within this string.  If found, returns the index where it was found.
1569169691Skan       *  If not found, returns npos.
1570169691Skan      */
1571169691Skan      size_type
1572169691Skan      find_first_not_of(_CharT __c, size_type __pos = 0) const;
1573169691Skan
1574169691Skan      /**
1575169691Skan       *  @brief  Find last position of a character not in string.
1576169691Skan       *  @param str  String containing characters to avoid.
1577228780Spfg       *  @param pos  Index of character to search back from (default end).
1578228780Spfg       *  @return  Index of last occurrence.
1579169691Skan       *
1580169691Skan       *  Starting from @a pos, searches backward for a character not
1581169691Skan       *  contained in @a str within this string.  If found, returns the index
1582169691Skan       *  where it was found.  If not found, returns npos.
1583169691Skan      */
1584169691Skan      size_type
1585169691Skan      find_last_not_of(const __versa_string& __str,
1586169691Skan		       size_type __pos = npos) const
1587169691Skan      { return this->find_last_not_of(__str.data(), __pos, __str.size()); }
1588169691Skan
1589169691Skan      /**
1590169691Skan       *  @brief  Find last position of a character not in C substring.
1591169691Skan       *  @param s  C string containing characters to avoid.
1592228780Spfg       *  @param pos  Index of character to search back from.
1593169691Skan       *  @param n  Number of characters from s to consider.
1594228780Spfg       *  @return  Index of last occurrence.
1595169691Skan       *
1596169691Skan       *  Starting from @a pos, searches backward for a character not
1597169691Skan       *  contained in the first @a n characters of @a s within this string.
1598169691Skan       *  If found, returns the index where it was found.  If not found,
1599169691Skan       *  returns npos.
1600169691Skan      */
1601169691Skan      size_type
1602169691Skan      find_last_not_of(const _CharT* __s, size_type __pos,
1603169691Skan		       size_type __n) const;
1604169691Skan      /**
1605228780Spfg       *  @brief  Find last position of a character not in C string.
1606169691Skan       *  @param s  C string containing characters to avoid.
1607228780Spfg       *  @param pos  Index of character to search back from (default end).
1608228780Spfg       *  @return  Index of last occurrence.
1609169691Skan       *
1610169691Skan       *  Starting from @a pos, searches backward for a character not
1611169691Skan       *  contained in @a s within this string.  If found, returns the index
1612169691Skan       *  where it was found.  If not found, returns npos.
1613169691Skan      */
1614169691Skan      size_type
1615169691Skan      find_last_not_of(const _CharT* __s, size_type __pos = npos) const
1616169691Skan      {
1617169691Skan	__glibcxx_requires_string(__s);
1618169691Skan	return this->find_last_not_of(__s, __pos, traits_type::length(__s));
1619169691Skan      }
1620169691Skan
1621169691Skan      /**
1622169691Skan       *  @brief  Find last position of a different character.
1623169691Skan       *  @param c  Character to avoid.
1624228780Spfg       *  @param pos  Index of character to search back from (default end).
1625228780Spfg       *  @return  Index of last occurrence.
1626169691Skan       *
1627169691Skan       *  Starting from @a pos, searches backward for a character other than
1628169691Skan       *  @a c within this string.  If found, returns the index where it was
1629169691Skan       *  found.  If not found, returns npos.
1630169691Skan      */
1631169691Skan      size_type
1632169691Skan      find_last_not_of(_CharT __c, size_type __pos = npos) const;
1633169691Skan
1634169691Skan      /**
1635169691Skan       *  @brief  Get a substring.
1636169691Skan       *  @param pos  Index of first character (default 0).
1637169691Skan       *  @param n  Number of characters in substring (default remainder).
1638169691Skan       *  @return  The new string.
1639169691Skan       *  @throw  std::out_of_range  If pos > size().
1640169691Skan       *
1641169691Skan       *  Construct and return a new string using the @a n characters starting
1642169691Skan       *  at @a pos.  If the string is too short, use the remainder of the
1643169691Skan       *  characters.  If @a pos is beyond the end of the string, out_of_range
1644169691Skan       *  is thrown.
1645169691Skan      */
1646169691Skan      __versa_string
1647169691Skan      substr(size_type __pos = 0, size_type __n = npos) const
1648169691Skan      {
1649169691Skan	return __versa_string(*this, _M_check(__pos, "__versa_string::substr"),
1650169691Skan			      __n);
1651169691Skan      }
1652169691Skan
1653169691Skan      /**
1654169691Skan       *  @brief  Compare to a string.
1655169691Skan       *  @param str  String to compare against.
1656169691Skan       *  @return  Integer < 0, 0, or > 0.
1657169691Skan       *
1658169691Skan       *  Returns an integer < 0 if this string is ordered before @a str, 0 if
1659169691Skan       *  their values are equivalent, or > 0 if this string is ordered after
1660169691Skan       *  @a str.  Determines the effective length rlen of the strings to
1661169691Skan       *  compare as the smallest of size() and str.size().  The function
1662169691Skan       *  then compares the two strings by calling traits::compare(data(),
1663169691Skan       *  str.data(),rlen).  If the result of the comparison is nonzero returns
1664169691Skan       *  it, otherwise the shorter one is ordered first.
1665169691Skan      */
1666169691Skan      int
1667169691Skan      compare(const __versa_string& __str) const
1668169691Skan      {
1669169691Skan	if (this->_M_compare(__str))
1670169691Skan	  return 0;
1671169691Skan
1672169691Skan	const size_type __size = this->size();
1673169691Skan	const size_type __osize = __str.size();
1674169691Skan	const size_type __len = std::min(__size, __osize);
1675169691Skan
1676169691Skan	int __r = traits_type::compare(this->_M_data(), __str.data(), __len);
1677169691Skan	if (!__r)
1678169691Skan	  __r =  __size - __osize;
1679169691Skan	return __r;
1680169691Skan      }
1681169691Skan
1682169691Skan      /**
1683169691Skan       *  @brief  Compare substring to a string.
1684169691Skan       *  @param pos  Index of first character of substring.
1685169691Skan       *  @param n  Number of characters in substring.
1686169691Skan       *  @param str  String to compare against.
1687169691Skan       *  @return  Integer < 0, 0, or > 0.
1688169691Skan       *
1689169691Skan       *  Form the substring of this string from the @a n characters starting
1690169691Skan       *  at @a pos.  Returns an integer < 0 if the substring is ordered
1691169691Skan       *  before @a str, 0 if their values are equivalent, or > 0 if the
1692169691Skan       *  substring is ordered after @a str.  Determines the effective length
1693169691Skan       *  rlen of the strings to compare as the smallest of the length of the
1694169691Skan       *  substring and @a str.size().  The function then compares the two
1695169691Skan       *  strings by calling traits::compare(substring.data(),str.data(),rlen).
1696169691Skan       *  If the result of the comparison is nonzero returns it, otherwise the
1697169691Skan       *  shorter one is ordered first.
1698169691Skan      */
1699169691Skan      int
1700169691Skan      compare(size_type __pos, size_type __n,
1701169691Skan	      const __versa_string& __str) const;
1702169691Skan
1703169691Skan      /**
1704169691Skan       *  @brief  Compare substring to a substring.
1705169691Skan       *  @param pos1  Index of first character of substring.
1706169691Skan       *  @param n1  Number of characters in substring.
1707169691Skan       *  @param str  String to compare against.
1708169691Skan       *  @param pos2  Index of first character of substring of str.
1709169691Skan       *  @param n2  Number of characters in substring of str.
1710169691Skan       *  @return  Integer < 0, 0, or > 0.
1711169691Skan       *
1712169691Skan       *  Form the substring of this string from the @a n1 characters starting
1713169691Skan       *  at @a pos1.  Form the substring of @a str from the @a n2 characters
1714169691Skan       *  starting at @a pos2.  Returns an integer < 0 if this substring is
1715169691Skan       *  ordered before the substring of @a str, 0 if their values are
1716169691Skan       *  equivalent, or > 0 if this substring is ordered after the substring
1717169691Skan       *  of @a str.  Determines the effective length rlen of the strings
1718169691Skan       *  to compare as the smallest of the lengths of the substrings.  The
1719169691Skan       *  function then compares the two strings by calling
1720169691Skan       *  traits::compare(substring.data(),str.substr(pos2,n2).data(),rlen).
1721169691Skan       *  If the result of the comparison is nonzero returns it, otherwise the
1722169691Skan       *  shorter one is ordered first.
1723169691Skan      */
1724169691Skan      int
1725169691Skan      compare(size_type __pos1, size_type __n1, const __versa_string& __str,
1726169691Skan	      size_type __pos2, size_type __n2) const;
1727169691Skan
1728169691Skan      /**
1729169691Skan       *  @brief  Compare to a C string.
1730169691Skan       *  @param s  C string to compare against.
1731169691Skan       *  @return  Integer < 0, 0, or > 0.
1732169691Skan       *
1733169691Skan       *  Returns an integer < 0 if this string is ordered before @a s, 0 if
1734169691Skan       *  their values are equivalent, or > 0 if this string is ordered after
1735169691Skan       *  @a s.  Determines the effective length rlen of the strings to
1736169691Skan       *  compare as the smallest of size() and the length of a string
1737169691Skan       *  constructed from @a s.  The function then compares the two strings
1738169691Skan       *  by calling traits::compare(data(),s,rlen).  If the result of the
1739169691Skan       *  comparison is nonzero returns it, otherwise the shorter one is
1740169691Skan       *  ordered first.
1741169691Skan      */
1742169691Skan      int
1743169691Skan      compare(const _CharT* __s) const;
1744169691Skan
1745169691Skan      // _GLIBCXX_RESOLVE_LIB_DEFECTS
1746169691Skan      // 5 String::compare specification questionable
1747169691Skan      /**
1748169691Skan       *  @brief  Compare substring to a C string.
1749169691Skan       *  @param pos  Index of first character of substring.
1750169691Skan       *  @param n1  Number of characters in substring.
1751169691Skan       *  @param s  C string to compare against.
1752169691Skan       *  @return  Integer < 0, 0, or > 0.
1753169691Skan       *
1754169691Skan       *  Form the substring of this string from the @a n1 characters starting
1755169691Skan       *  at @a pos.  Returns an integer < 0 if the substring is ordered
1756169691Skan       *  before @a s, 0 if their values are equivalent, or > 0 if the
1757169691Skan       *  substring is ordered after @a s.  Determines the effective length
1758169691Skan       *  rlen of the strings to compare as the smallest of the length of the
1759169691Skan       *  substring and the length of a string constructed from @a s.  The
1760169691Skan       *  function then compares the two string by calling
1761169691Skan       *  traits::compare(substring.data(),s,rlen).  If the result of the
1762169691Skan       *  comparison is nonzero returns it, otherwise the shorter one is
1763169691Skan       *  ordered first.
1764169691Skan      */
1765169691Skan      int
1766169691Skan      compare(size_type __pos, size_type __n1, const _CharT* __s) const;
1767169691Skan
1768169691Skan      /**
1769169691Skan       *  @brief  Compare substring against a character array.
1770169691Skan       *  @param pos1  Index of first character of substring.
1771169691Skan       *  @param n1  Number of characters in substring.
1772169691Skan       *  @param s  character array to compare against.
1773169691Skan       *  @param n2  Number of characters of s.
1774169691Skan       *  @return  Integer < 0, 0, or > 0.
1775169691Skan       *
1776169691Skan       *  Form the substring of this string from the @a n1 characters starting
1777169691Skan       *  at @a pos1.  Form a string from the first @a n2 characters of @a s.
1778169691Skan       *  Returns an integer < 0 if this substring is ordered before the string
1779169691Skan       *  from @a s, 0 if their values are equivalent, or > 0 if this substring
1780169691Skan       *  is ordered after the string from @a s.   Determines the effective
1781169691Skan       *  length rlen of the strings to compare as the smallest of the length
1782169691Skan       *  of the substring and @a n2.  The function then compares the two
1783169691Skan       *  strings by calling traits::compare(substring.data(),s,rlen).  If the
1784169691Skan       *  result of the comparison is nonzero returns it, otherwise the shorter
1785169691Skan       *  one is ordered first.
1786169691Skan       *
1787169691Skan       *  NB: s must have at least n2 characters, '\0' has no special
1788169691Skan       *  meaning.
1789169691Skan      */
1790169691Skan      int
1791169691Skan      compare(size_type __pos, size_type __n1, const _CharT* __s,
1792169691Skan	      size_type __n2) const;
1793169691Skan    };
1794169691Skan
1795169691Skan  // operator+
1796169691Skan  /**
1797169691Skan   *  @brief  Concatenate two strings.
1798169691Skan   *  @param lhs  First string.
1799169691Skan   *  @param rhs  Last string.
1800169691Skan   *  @return  New string with value of @a lhs followed by @a rhs.
1801169691Skan   */
1802169691Skan  template<typename _CharT, typename _Traits, typename _Alloc,
1803169691Skan	   template <typename, typename, typename> class _Base>
1804169691Skan    __versa_string<_CharT, _Traits, _Alloc, _Base>
1805169691Skan    operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
1806169691Skan	      const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs);
1807169691Skan
1808169691Skan  /**
1809169691Skan   *  @brief  Concatenate C string and string.
1810169691Skan   *  @param lhs  First string.
1811169691Skan   *  @param rhs  Last string.
1812169691Skan   *  @return  New string with value of @a lhs followed by @a rhs.
1813169691Skan   */
1814169691Skan  template<typename _CharT, typename _Traits, typename _Alloc,
1815169691Skan	   template <typename, typename, typename> class _Base>
1816169691Skan    __versa_string<_CharT, _Traits, _Alloc, _Base>
1817169691Skan    operator+(const _CharT* __lhs,
1818169691Skan	      const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs);
1819169691Skan
1820169691Skan  /**
1821169691Skan   *  @brief  Concatenate character and string.
1822169691Skan   *  @param lhs  First string.
1823169691Skan   *  @param rhs  Last string.
1824169691Skan   *  @return  New string with @a lhs followed by @a rhs.
1825169691Skan   */
1826169691Skan  template<typename _CharT, typename _Traits, typename _Alloc,
1827169691Skan	   template <typename, typename, typename> class _Base>
1828169691Skan    __versa_string<_CharT, _Traits, _Alloc, _Base>
1829169691Skan    operator+(_CharT __lhs,
1830169691Skan	      const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs);
1831169691Skan
1832169691Skan  /**
1833169691Skan   *  @brief  Concatenate string and C string.
1834169691Skan   *  @param lhs  First string.
1835169691Skan   *  @param rhs  Last string.
1836169691Skan   *  @return  New string with @a lhs followed by @a rhs.
1837169691Skan   */
1838169691Skan  template<typename _CharT, typename _Traits, typename _Alloc,
1839169691Skan	   template <typename, typename, typename> class _Base>
1840169691Skan    __versa_string<_CharT, _Traits, _Alloc, _Base>
1841169691Skan    operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
1842169691Skan	      const _CharT* __rhs);
1843169691Skan
1844169691Skan  /**
1845169691Skan   *  @brief  Concatenate string and character.
1846169691Skan   *  @param lhs  First string.
1847169691Skan   *  @param rhs  Last string.
1848169691Skan   *  @return  New string with @a lhs followed by @a rhs.
1849169691Skan   */
1850169691Skan  template<typename _CharT, typename _Traits, typename _Alloc,
1851169691Skan	   template <typename, typename, typename> class _Base>
1852169691Skan    __versa_string<_CharT, _Traits, _Alloc, _Base>
1853169691Skan    operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
1854169691Skan	      _CharT __rhs);
1855169691Skan
1856169691Skan  // operator ==
1857169691Skan  /**
1858169691Skan   *  @brief  Test equivalence of two strings.
1859169691Skan   *  @param lhs  First string.
1860169691Skan   *  @param rhs  Second string.
1861169691Skan   *  @return  True if @a lhs.compare(@a rhs) == 0.  False otherwise.
1862169691Skan   */
1863169691Skan  template<typename _CharT, typename _Traits, typename _Alloc,
1864169691Skan	   template <typename, typename, typename> class _Base>
1865169691Skan    inline bool
1866169691Skan    operator==(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
1867169691Skan	       const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
1868169691Skan    { return __lhs.compare(__rhs) == 0; }
1869169691Skan
1870169691Skan  /**
1871169691Skan   *  @brief  Test equivalence of C string and string.
1872169691Skan   *  @param lhs  C string.
1873169691Skan   *  @param rhs  String.
1874169691Skan   *  @return  True if @a rhs.compare(@a lhs) == 0.  False otherwise.
1875169691Skan   */
1876169691Skan  template<typename _CharT, typename _Traits, typename _Alloc,
1877169691Skan	   template <typename, typename, typename> class _Base>
1878169691Skan    inline bool
1879169691Skan    operator==(const _CharT* __lhs,
1880169691Skan	       const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
1881169691Skan    { return __rhs.compare(__lhs) == 0; }
1882169691Skan
1883169691Skan  /**
1884169691Skan   *  @brief  Test equivalence of string and C string.
1885169691Skan   *  @param lhs  String.
1886169691Skan   *  @param rhs  C string.
1887169691Skan   *  @return  True if @a lhs.compare(@a rhs) == 0.  False otherwise.
1888169691Skan   */
1889169691Skan  template<typename _CharT, typename _Traits, typename _Alloc,
1890169691Skan	   template <typename, typename, typename> class _Base>
1891169691Skan    inline bool
1892169691Skan    operator==(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
1893169691Skan	       const _CharT* __rhs)
1894169691Skan    { return __lhs.compare(__rhs) == 0; }
1895169691Skan
1896169691Skan  // operator !=
1897169691Skan  /**
1898169691Skan   *  @brief  Test difference of two strings.
1899169691Skan   *  @param lhs  First string.
1900169691Skan   *  @param rhs  Second string.
1901169691Skan   *  @return  True if @a lhs.compare(@a rhs) != 0.  False otherwise.
1902169691Skan   */
1903169691Skan  template<typename _CharT, typename _Traits, typename _Alloc,
1904169691Skan	   template <typename, typename, typename> class _Base>
1905169691Skan    inline bool
1906169691Skan    operator!=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
1907169691Skan	       const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
1908169691Skan    { return __rhs.compare(__lhs) != 0; }
1909169691Skan
1910169691Skan  /**
1911169691Skan   *  @brief  Test difference of C string and string.
1912169691Skan   *  @param lhs  C string.
1913169691Skan   *  @param rhs  String.
1914169691Skan   *  @return  True if @a rhs.compare(@a lhs) != 0.  False otherwise.
1915169691Skan   */
1916169691Skan  template<typename _CharT, typename _Traits, typename _Alloc,
1917169691Skan	   template <typename, typename, typename> class _Base>
1918169691Skan    inline bool
1919169691Skan    operator!=(const _CharT* __lhs,
1920169691Skan	       const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
1921169691Skan    { return __rhs.compare(__lhs) != 0; }
1922169691Skan
1923169691Skan  /**
1924169691Skan   *  @brief  Test difference of string and C string.
1925169691Skan   *  @param lhs  String.
1926169691Skan   *  @param rhs  C string.
1927169691Skan   *  @return  True if @a lhs.compare(@a rhs) != 0.  False otherwise.
1928169691Skan   */
1929169691Skan  template<typename _CharT, typename _Traits, typename _Alloc,
1930169691Skan	   template <typename, typename, typename> class _Base>
1931169691Skan    inline bool
1932169691Skan    operator!=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
1933169691Skan	       const _CharT* __rhs)
1934169691Skan    { return __lhs.compare(__rhs) != 0; }
1935169691Skan
1936169691Skan  // operator <
1937169691Skan  /**
1938169691Skan   *  @brief  Test if string precedes string.
1939169691Skan   *  @param lhs  First string.
1940169691Skan   *  @param rhs  Second string.
1941169691Skan   *  @return  True if @a lhs precedes @a rhs.  False otherwise.
1942169691Skan   */
1943169691Skan  template<typename _CharT, typename _Traits, typename _Alloc,
1944169691Skan	   template <typename, typename, typename> class _Base>
1945169691Skan    inline bool
1946169691Skan    operator<(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
1947169691Skan	      const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
1948169691Skan    { return __lhs.compare(__rhs) < 0; }
1949169691Skan
1950169691Skan  /**
1951169691Skan   *  @brief  Test if string precedes C string.
1952169691Skan   *  @param lhs  String.
1953169691Skan   *  @param rhs  C string.
1954169691Skan   *  @return  True if @a lhs precedes @a rhs.  False otherwise.
1955169691Skan   */
1956169691Skan  template<typename _CharT, typename _Traits, typename _Alloc,
1957169691Skan	   template <typename, typename, typename> class _Base>
1958169691Skan    inline bool
1959169691Skan    operator<(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
1960169691Skan	      const _CharT* __rhs)
1961169691Skan    { return __lhs.compare(__rhs) < 0; }
1962169691Skan
1963169691Skan  /**
1964169691Skan   *  @brief  Test if C string precedes string.
1965169691Skan   *  @param lhs  C string.
1966169691Skan   *  @param rhs  String.
1967169691Skan   *  @return  True if @a lhs precedes @a rhs.  False otherwise.
1968169691Skan   */
1969169691Skan  template<typename _CharT, typename _Traits, typename _Alloc,
1970169691Skan	   template <typename, typename, typename> class _Base>
1971169691Skan    inline bool
1972169691Skan    operator<(const _CharT* __lhs,
1973169691Skan	      const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
1974169691Skan    { return __rhs.compare(__lhs) > 0; }
1975169691Skan
1976169691Skan  // operator >
1977169691Skan  /**
1978169691Skan   *  @brief  Test if string follows string.
1979169691Skan   *  @param lhs  First string.
1980169691Skan   *  @param rhs  Second string.
1981169691Skan   *  @return  True if @a lhs follows @a rhs.  False otherwise.
1982169691Skan   */
1983169691Skan  template<typename _CharT, typename _Traits, typename _Alloc,
1984169691Skan	   template <typename, typename, typename> class _Base>
1985169691Skan    inline bool
1986169691Skan    operator>(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
1987169691Skan	      const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
1988169691Skan    { return __lhs.compare(__rhs) > 0; }
1989169691Skan
1990169691Skan  /**
1991169691Skan   *  @brief  Test if string follows C string.
1992169691Skan   *  @param lhs  String.
1993169691Skan   *  @param rhs  C string.
1994169691Skan   *  @return  True if @a lhs follows @a rhs.  False otherwise.
1995169691Skan   */
1996169691Skan  template<typename _CharT, typename _Traits, typename _Alloc,
1997169691Skan	   template <typename, typename, typename> class _Base>
1998169691Skan    inline bool
1999169691Skan    operator>(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2000169691Skan	      const _CharT* __rhs)
2001169691Skan    { return __lhs.compare(__rhs) > 0; }
2002169691Skan
2003169691Skan  /**
2004169691Skan   *  @brief  Test if C string follows string.
2005169691Skan   *  @param lhs  C string.
2006169691Skan   *  @param rhs  String.
2007169691Skan   *  @return  True if @a lhs follows @a rhs.  False otherwise.
2008169691Skan   */
2009169691Skan  template<typename _CharT, typename _Traits, typename _Alloc,
2010169691Skan	   template <typename, typename, typename> class _Base>
2011169691Skan    inline bool
2012169691Skan    operator>(const _CharT* __lhs,
2013169691Skan	      const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2014169691Skan    { return __rhs.compare(__lhs) < 0; }
2015169691Skan
2016169691Skan  // operator <=
2017169691Skan  /**
2018169691Skan   *  @brief  Test if string doesn't follow string.
2019169691Skan   *  @param lhs  First string.
2020169691Skan   *  @param rhs  Second string.
2021169691Skan   *  @return  True if @a lhs doesn't follow @a rhs.  False otherwise.
2022169691Skan   */
2023169691Skan  template<typename _CharT, typename _Traits, typename _Alloc,
2024169691Skan	   template <typename, typename, typename> class _Base>
2025169691Skan    inline bool
2026169691Skan    operator<=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2027169691Skan	       const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2028169691Skan    { return __lhs.compare(__rhs) <= 0; }
2029169691Skan
2030169691Skan  /**
2031169691Skan   *  @brief  Test if string doesn't follow C string.
2032169691Skan   *  @param lhs  String.
2033169691Skan   *  @param rhs  C string.
2034169691Skan   *  @return  True if @a lhs doesn't follow @a rhs.  False otherwise.
2035169691Skan   */
2036169691Skan  template<typename _CharT, typename _Traits, typename _Alloc,
2037169691Skan	   template <typename, typename, typename> class _Base>
2038169691Skan    inline bool
2039169691Skan    operator<=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2040169691Skan	       const _CharT* __rhs)
2041169691Skan    { return __lhs.compare(__rhs) <= 0; }
2042169691Skan
2043169691Skan  /**
2044169691Skan   *  @brief  Test if C string doesn't follow string.
2045169691Skan   *  @param lhs  C string.
2046169691Skan   *  @param rhs  String.
2047169691Skan   *  @return  True if @a lhs doesn't follow @a rhs.  False otherwise.
2048169691Skan   */
2049169691Skan  template<typename _CharT, typename _Traits, typename _Alloc,
2050169691Skan	   template <typename, typename, typename> class _Base>
2051169691Skan    inline bool
2052169691Skan    operator<=(const _CharT* __lhs,
2053169691Skan	       const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2054169691Skan    { return __rhs.compare(__lhs) >= 0; }
2055169691Skan
2056169691Skan  // operator >=
2057169691Skan  /**
2058169691Skan   *  @brief  Test if string doesn't precede string.
2059169691Skan   *  @param lhs  First string.
2060169691Skan   *  @param rhs  Second string.
2061169691Skan   *  @return  True if @a lhs doesn't precede @a rhs.  False otherwise.
2062169691Skan   */
2063169691Skan  template<typename _CharT, typename _Traits, typename _Alloc,
2064169691Skan	   template <typename, typename, typename> class _Base>
2065169691Skan    inline bool
2066169691Skan    operator>=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2067169691Skan	       const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2068169691Skan    { return __lhs.compare(__rhs) >= 0; }
2069169691Skan
2070169691Skan  /**
2071169691Skan   *  @brief  Test if string doesn't precede C string.
2072169691Skan   *  @param lhs  String.
2073169691Skan   *  @param rhs  C string.
2074169691Skan   *  @return  True if @a lhs doesn't precede @a rhs.  False otherwise.
2075169691Skan   */
2076169691Skan  template<typename _CharT, typename _Traits, typename _Alloc,
2077169691Skan	   template <typename, typename, typename> class _Base>
2078169691Skan    inline bool
2079169691Skan    operator>=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2080169691Skan	       const _CharT* __rhs)
2081169691Skan    { return __lhs.compare(__rhs) >= 0; }
2082169691Skan
2083169691Skan  /**
2084169691Skan   *  @brief  Test if C string doesn't precede string.
2085169691Skan   *  @param lhs  C string.
2086169691Skan   *  @param rhs  String.
2087169691Skan   *  @return  True if @a lhs doesn't precede @a rhs.  False otherwise.
2088169691Skan   */
2089169691Skan  template<typename _CharT, typename _Traits, typename _Alloc,
2090169691Skan	   template <typename, typename, typename> class _Base>
2091169691Skan    inline bool
2092169691Skan    operator>=(const _CharT* __lhs,
2093169691Skan	       const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2094169691Skan    { return __rhs.compare(__lhs) <= 0; }
2095169691Skan
2096169691Skan  /**
2097169691Skan   *  @brief  Swap contents of two strings.
2098169691Skan   *  @param lhs  First string.
2099169691Skan   *  @param rhs  Second string.
2100169691Skan   *
2101169691Skan   *  Exchanges the contents of @a lhs and @a rhs in constant time.
2102169691Skan   */
2103169691Skan  template<typename _CharT, typename _Traits, typename _Alloc,
2104169691Skan	   template <typename, typename, typename> class _Base>
2105169691Skan    inline void
2106169691Skan    swap(__versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2107169691Skan	 __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2108169691Skan    { __lhs.swap(__rhs); }
2109169691Skan
2110169691Skan_GLIBCXX_END_NAMESPACE
2111169691Skan
2112169691Skan_GLIBCXX_BEGIN_NAMESPACE(std)
2113169691Skan
2114169691Skan  /**
2115169691Skan   *  @brief  Read stream into a string.
2116169691Skan   *  @param is  Input stream.
2117169691Skan   *  @param str  Buffer to store into.
2118169691Skan   *  @return  Reference to the input stream.
2119169691Skan   *
2120169691Skan   *  Stores characters from @a is into @a str until whitespace is found, the
2121169691Skan   *  end of the stream is encountered, or str.max_size() is reached.  If
2122169691Skan   *  is.width() is non-zero, that is the limit on the number of characters
2123169691Skan   *  stored into @a str.  Any previous contents of @a str are erased.
2124169691Skan   */
2125169691Skan  template<typename _CharT, typename _Traits, typename _Alloc,
2126169691Skan           template <typename, typename, typename> class _Base>
2127169691Skan    basic_istream<_CharT, _Traits>&
2128169691Skan    operator>>(basic_istream<_CharT, _Traits>& __is,
2129169691Skan	       __gnu_cxx::__versa_string<_CharT, _Traits,
2130169691Skan	                                 _Alloc, _Base>& __str);
2131169691Skan
2132169691Skan  /**
2133169691Skan   *  @brief  Write string to a stream.
2134169691Skan   *  @param os  Output stream.
2135169691Skan   *  @param str  String to write out.
2136169691Skan   *  @return  Reference to the output stream.
2137169691Skan   *
2138169691Skan   *  Output characters of @a str into os following the same rules as for
2139169691Skan   *  writing a C string.
2140169691Skan   */
2141169691Skan  template<typename _CharT, typename _Traits, typename _Alloc,
2142169691Skan           template <typename, typename, typename> class _Base>
2143169691Skan    inline basic_ostream<_CharT, _Traits>&
2144169691Skan    operator<<(basic_ostream<_CharT, _Traits>& __os,
2145169691Skan	       const __gnu_cxx::__versa_string<_CharT, _Traits,
2146169691Skan	                                       _Alloc, _Base>& __str)
2147169691Skan    {
2148169691Skan      // _GLIBCXX_RESOLVE_LIB_DEFECTS
2149169691Skan      // 586. string inserter not a formatted function
2150169691Skan      return __ostream_insert(__os, __str.data(), __str.size());
2151169691Skan    }
2152169691Skan
2153169691Skan  /**
2154169691Skan   *  @brief  Read a line from stream into a string.
2155169691Skan   *  @param is  Input stream.
2156169691Skan   *  @param str  Buffer to store into.
2157169691Skan   *  @param delim  Character marking end of line.
2158169691Skan   *  @return  Reference to the input stream.
2159169691Skan   *
2160169691Skan   *  Stores characters from @a is into @a str until @a delim is found, the
2161169691Skan   *  end of the stream is encountered, or str.max_size() is reached.  If
2162169691Skan   *  is.width() is non-zero, that is the limit on the number of characters
2163169691Skan   *  stored into @a str.  Any previous contents of @a str are erased.  If @a
2164169691Skan   *  delim was encountered, it is extracted but not stored into @a str.
2165169691Skan   */
2166169691Skan  template<typename _CharT, typename _Traits, typename _Alloc,
2167169691Skan           template <typename, typename, typename> class _Base>
2168169691Skan    basic_istream<_CharT, _Traits>&
2169169691Skan    getline(basic_istream<_CharT, _Traits>& __is,
2170169691Skan	    __gnu_cxx::__versa_string<_CharT, _Traits, _Alloc, _Base>& __str,
2171169691Skan	    _CharT __delim);
2172169691Skan
2173169691Skan  /**
2174169691Skan   *  @brief  Read a line from stream into a string.
2175169691Skan   *  @param is  Input stream.
2176169691Skan   *  @param str  Buffer to store into.
2177169691Skan   *  @return  Reference to the input stream.
2178169691Skan   *
2179169691Skan   *  Stores characters from is into @a str until '\n' is found, the end of
2180169691Skan   *  the stream is encountered, or str.max_size() is reached.  If is.width()
2181169691Skan   *  is non-zero, that is the limit on the number of characters stored into
2182169691Skan   *  @a str.  Any previous contents of @a str are erased.  If end of line was
2183169691Skan   *  encountered, it is extracted but not stored into @a str.
2184169691Skan   */
2185169691Skan  template<typename _CharT, typename _Traits, typename _Alloc,
2186169691Skan           template <typename, typename, typename> class _Base>
2187169691Skan    inline basic_istream<_CharT, _Traits>&
2188169691Skan    getline(basic_istream<_CharT, _Traits>& __is,
2189169691Skan	    __gnu_cxx::__versa_string<_CharT, _Traits, _Alloc, _Base>& __str)
2190169691Skan    { return getline(__is, __str, __is.widen('\n')); }
2191169691Skan
2192169691Skan_GLIBCXX_END_NAMESPACE
2193169691Skan
2194169691Skan#ifndef _GLIBCXX_EXPORT_TEMPLATE
2195169691Skan# include "vstring.tcc"
2196169691Skan#endif
2197169691Skan
2198169691Skan#endif /* _VSTRING_H */
2199