1*e4b17023SJohn Marino // Versatile string -*- C++ -*-
2*e4b17023SJohn Marino
3*e4b17023SJohn Marino // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011
4*e4b17023SJohn Marino // Free Software Foundation, Inc.
5*e4b17023SJohn Marino //
6*e4b17023SJohn Marino // This file is part of the GNU ISO C++ Library. This library is free
7*e4b17023SJohn Marino // software; you can redistribute it and/or modify it under the
8*e4b17023SJohn Marino // terms of the GNU General Public License as published by the
9*e4b17023SJohn Marino // Free Software Foundation; either version 3, or (at your option)
10*e4b17023SJohn Marino // any later version.
11*e4b17023SJohn Marino
12*e4b17023SJohn Marino // This library is distributed in the hope that it will be useful,
13*e4b17023SJohn Marino // but WITHOUT ANY WARRANTY; without even the implied warranty of
14*e4b17023SJohn Marino // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15*e4b17023SJohn Marino // GNU General Public License for more details.
16*e4b17023SJohn Marino
17*e4b17023SJohn Marino // Under Section 7 of GPL version 3, you are granted additional
18*e4b17023SJohn Marino // permissions described in the GCC Runtime Library Exception, version
19*e4b17023SJohn Marino // 3.1, as published by the Free Software Foundation.
20*e4b17023SJohn Marino
21*e4b17023SJohn Marino // You should have received a copy of the GNU General Public License and
22*e4b17023SJohn Marino // a copy of the GCC Runtime Library Exception along with this program;
23*e4b17023SJohn Marino // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24*e4b17023SJohn Marino // <http://www.gnu.org/licenses/>.
25*e4b17023SJohn Marino
26*e4b17023SJohn Marino /** @file ext/vstring.h
27*e4b17023SJohn Marino * This file is a GNU extension to the Standard C++ Library.
28*e4b17023SJohn Marino */
29*e4b17023SJohn Marino
30*e4b17023SJohn Marino #ifndef _VSTRING_H
31*e4b17023SJohn Marino #define _VSTRING_H 1
32*e4b17023SJohn Marino
33*e4b17023SJohn Marino #pragma GCC system_header
34*e4b17023SJohn Marino
35*e4b17023SJohn Marino #ifdef __GXX_EXPERIMENTAL_CXX0X__
36*e4b17023SJohn Marino #include <initializer_list>
37*e4b17023SJohn Marino #endif
38*e4b17023SJohn Marino
39*e4b17023SJohn Marino #include <ext/vstring_util.h>
40*e4b17023SJohn Marino #include <ext/rc_string_base.h>
41*e4b17023SJohn Marino #include <ext/sso_string_base.h>
42*e4b17023SJohn Marino
_GLIBCXX_VISIBILITY(default)43*e4b17023SJohn Marino namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
44*e4b17023SJohn Marino {
45*e4b17023SJohn Marino _GLIBCXX_BEGIN_NAMESPACE_VERSION
46*e4b17023SJohn Marino
47*e4b17023SJohn Marino /**
48*e4b17023SJohn Marino * @class __versa_string vstring.h
49*e4b17023SJohn Marino * @brief Template class __versa_string.
50*e4b17023SJohn Marino * @ingroup extensions
51*e4b17023SJohn Marino *
52*e4b17023SJohn Marino * Data structure managing sequences of characters and
53*e4b17023SJohn Marino * character-like objects.
54*e4b17023SJohn Marino */
55*e4b17023SJohn Marino template<typename _CharT, typename _Traits, typename _Alloc,
56*e4b17023SJohn Marino template <typename, typename, typename> class _Base>
57*e4b17023SJohn Marino class __versa_string
58*e4b17023SJohn Marino : private _Base<_CharT, _Traits, _Alloc>
59*e4b17023SJohn Marino {
60*e4b17023SJohn Marino typedef _Base<_CharT, _Traits, _Alloc> __vstring_base;
61*e4b17023SJohn Marino typedef typename __vstring_base::_CharT_alloc_type _CharT_alloc_type;
62*e4b17023SJohn Marino
63*e4b17023SJohn Marino // Types:
64*e4b17023SJohn Marino public:
65*e4b17023SJohn Marino typedef _Traits traits_type;
66*e4b17023SJohn Marino typedef typename _Traits::char_type value_type;
67*e4b17023SJohn Marino typedef _Alloc allocator_type;
68*e4b17023SJohn Marino typedef typename _CharT_alloc_type::size_type size_type;
69*e4b17023SJohn Marino typedef typename _CharT_alloc_type::difference_type difference_type;
70*e4b17023SJohn Marino typedef value_type& reference;
71*e4b17023SJohn Marino typedef const value_type& const_reference;
72*e4b17023SJohn Marino typedef typename _CharT_alloc_type::pointer pointer;
73*e4b17023SJohn Marino typedef typename _CharT_alloc_type::const_pointer const_pointer;
74*e4b17023SJohn Marino typedef __gnu_cxx::__normal_iterator<pointer, __versa_string> iterator;
75*e4b17023SJohn Marino typedef __gnu_cxx::__normal_iterator<const_pointer, __versa_string>
76*e4b17023SJohn Marino const_iterator;
77*e4b17023SJohn Marino typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
78*e4b17023SJohn Marino typedef std::reverse_iterator<iterator> reverse_iterator;
79*e4b17023SJohn Marino
80*e4b17023SJohn Marino // Data Member (public):
81*e4b17023SJohn Marino /// Value returned by various member functions when they fail.
82*e4b17023SJohn Marino static const size_type npos = static_cast<size_type>(-1);
83*e4b17023SJohn Marino
84*e4b17023SJohn Marino private:
85*e4b17023SJohn Marino size_type
86*e4b17023SJohn Marino _M_check(size_type __pos, const char* __s) const
87*e4b17023SJohn Marino {
88*e4b17023SJohn Marino if (__pos > this->size())
89*e4b17023SJohn Marino std::__throw_out_of_range(__N(__s));
90*e4b17023SJohn Marino return __pos;
91*e4b17023SJohn Marino }
92*e4b17023SJohn Marino
93*e4b17023SJohn Marino void
94*e4b17023SJohn Marino _M_check_length(size_type __n1, size_type __n2, const char* __s) const
95*e4b17023SJohn Marino {
96*e4b17023SJohn Marino if (this->max_size() - (this->size() - __n1) < __n2)
97*e4b17023SJohn Marino std::__throw_length_error(__N(__s));
98*e4b17023SJohn Marino }
99*e4b17023SJohn Marino
100*e4b17023SJohn Marino // NB: _M_limit doesn't check for a bad __pos value.
101*e4b17023SJohn Marino size_type
102*e4b17023SJohn Marino _M_limit(size_type __pos, size_type __off) const
103*e4b17023SJohn Marino {
104*e4b17023SJohn Marino const bool __testoff = __off < this->size() - __pos;
105*e4b17023SJohn Marino return __testoff ? __off : this->size() - __pos;
106*e4b17023SJohn Marino }
107*e4b17023SJohn Marino
108*e4b17023SJohn Marino // True if _Rep and source do not overlap.
109*e4b17023SJohn Marino bool
110*e4b17023SJohn Marino _M_disjunct(const _CharT* __s) const
111*e4b17023SJohn Marino {
112*e4b17023SJohn Marino return (std::less<const _CharT*>()(__s, this->_M_data())
113*e4b17023SJohn Marino || std::less<const _CharT*>()(this->_M_data()
114*e4b17023SJohn Marino + this->size(), __s));
115*e4b17023SJohn Marino }
116*e4b17023SJohn Marino
117*e4b17023SJohn Marino // For the internal use we have functions similar to `begin'/`end'
118*e4b17023SJohn Marino // but they do not call _M_leak.
119*e4b17023SJohn Marino iterator
120*e4b17023SJohn Marino _M_ibegin() const
121*e4b17023SJohn Marino { return iterator(this->_M_data()); }
122*e4b17023SJohn Marino
123*e4b17023SJohn Marino iterator
124*e4b17023SJohn Marino _M_iend() const
125*e4b17023SJohn Marino { return iterator(this->_M_data() + this->_M_length()); }
126*e4b17023SJohn Marino
127*e4b17023SJohn Marino public:
128*e4b17023SJohn Marino // Construct/copy/destroy:
129*e4b17023SJohn Marino // NB: We overload ctors in some cases instead of using default
130*e4b17023SJohn Marino // arguments, per 17.4.4.4 para. 2 item 2.
131*e4b17023SJohn Marino
132*e4b17023SJohn Marino /**
133*e4b17023SJohn Marino * @brief Default constructor creates an empty string.
134*e4b17023SJohn Marino */
135*e4b17023SJohn Marino __versa_string()
136*e4b17023SJohn Marino : __vstring_base() { }
137*e4b17023SJohn Marino
138*e4b17023SJohn Marino /**
139*e4b17023SJohn Marino * @brief Construct an empty string using allocator @a a.
140*e4b17023SJohn Marino */
141*e4b17023SJohn Marino explicit
142*e4b17023SJohn Marino __versa_string(const _Alloc& __a)
143*e4b17023SJohn Marino : __vstring_base(__a) { }
144*e4b17023SJohn Marino
145*e4b17023SJohn Marino // NB: per LWG issue 42, semantics different from IS:
146*e4b17023SJohn Marino /**
147*e4b17023SJohn Marino * @brief Construct string with copy of value of @a __str.
148*e4b17023SJohn Marino * @param __str Source string.
149*e4b17023SJohn Marino */
150*e4b17023SJohn Marino __versa_string(const __versa_string& __str)
151*e4b17023SJohn Marino : __vstring_base(__str) { }
152*e4b17023SJohn Marino
153*e4b17023SJohn Marino #ifdef __GXX_EXPERIMENTAL_CXX0X__
154*e4b17023SJohn Marino /**
155*e4b17023SJohn Marino * @brief String move constructor.
156*e4b17023SJohn Marino * @param __str Source string.
157*e4b17023SJohn Marino *
158*e4b17023SJohn Marino * The newly-constructed %string contains the exact contents of
159*e4b17023SJohn Marino * @a __str. The contents of @a __str are a valid, but unspecified
160*e4b17023SJohn Marino * string.
161*e4b17023SJohn Marino */
162*e4b17023SJohn Marino __versa_string(__versa_string&& __str) noexcept
163*e4b17023SJohn Marino : __vstring_base(std::move(__str)) { }
164*e4b17023SJohn Marino
165*e4b17023SJohn Marino /**
166*e4b17023SJohn Marino * @brief Construct string from an initializer list.
167*e4b17023SJohn Marino * @param __l std::initializer_list of characters.
168*e4b17023SJohn Marino * @param __a Allocator to use (default is default allocator).
169*e4b17023SJohn Marino */
170*e4b17023SJohn Marino __versa_string(std::initializer_list<_CharT> __l,
171*e4b17023SJohn Marino const _Alloc& __a = _Alloc())
172*e4b17023SJohn Marino : __vstring_base(__l.begin(), __l.end(), __a) { }
173*e4b17023SJohn Marino #endif
174*e4b17023SJohn Marino
175*e4b17023SJohn Marino /**
176*e4b17023SJohn Marino * @brief Construct string as copy of a substring.
177*e4b17023SJohn Marino * @param __str Source string.
178*e4b17023SJohn Marino * @param __pos Index of first character to copy from.
179*e4b17023SJohn Marino * @param __n Number of characters to copy (default remainder).
180*e4b17023SJohn Marino */
181*e4b17023SJohn Marino __versa_string(const __versa_string& __str, size_type __pos,
182*e4b17023SJohn Marino size_type __n = npos)
183*e4b17023SJohn Marino : __vstring_base(__str._M_data()
184*e4b17023SJohn Marino + __str._M_check(__pos,
185*e4b17023SJohn Marino "__versa_string::__versa_string"),
186*e4b17023SJohn Marino __str._M_data() + __str._M_limit(__pos, __n)
187*e4b17023SJohn Marino + __pos, _Alloc()) { }
188*e4b17023SJohn Marino
189*e4b17023SJohn Marino /**
190*e4b17023SJohn Marino * @brief Construct string as copy of a substring.
191*e4b17023SJohn Marino * @param __str Source string.
192*e4b17023SJohn Marino * @param __pos Index of first character to copy from.
193*e4b17023SJohn Marino * @param __n Number of characters to copy.
194*e4b17023SJohn Marino * @param __a Allocator to use.
195*e4b17023SJohn Marino */
196*e4b17023SJohn Marino __versa_string(const __versa_string& __str, size_type __pos,
197*e4b17023SJohn Marino size_type __n, const _Alloc& __a)
198*e4b17023SJohn Marino : __vstring_base(__str._M_data()
199*e4b17023SJohn Marino + __str._M_check(__pos,
200*e4b17023SJohn Marino "__versa_string::__versa_string"),
201*e4b17023SJohn Marino __str._M_data() + __str._M_limit(__pos, __n)
202*e4b17023SJohn Marino + __pos, __a) { }
203*e4b17023SJohn Marino
204*e4b17023SJohn Marino /**
205*e4b17023SJohn Marino * @brief Construct string initialized by a character array.
206*e4b17023SJohn Marino * @param __s Source character array.
207*e4b17023SJohn Marino * @param __n Number of characters to copy.
208*e4b17023SJohn Marino * @param __a Allocator to use (default is default allocator).
209*e4b17023SJohn Marino *
210*e4b17023SJohn Marino * NB: @a __s must have at least @a __n characters, '\\0' has no special
211*e4b17023SJohn Marino * meaning.
212*e4b17023SJohn Marino */
213*e4b17023SJohn Marino __versa_string(const _CharT* __s, size_type __n,
214*e4b17023SJohn Marino const _Alloc& __a = _Alloc())
215*e4b17023SJohn Marino : __vstring_base(__s, __s + __n, __a) { }
216*e4b17023SJohn Marino
217*e4b17023SJohn Marino /**
218*e4b17023SJohn Marino * @brief Construct string as copy of a C string.
219*e4b17023SJohn Marino * @param __s Source C string.
220*e4b17023SJohn Marino * @param __a Allocator to use (default is default allocator).
221*e4b17023SJohn Marino */
222*e4b17023SJohn Marino __versa_string(const _CharT* __s, const _Alloc& __a = _Alloc())
223*e4b17023SJohn Marino : __vstring_base(__s, __s ? __s + traits_type::length(__s) :
224*e4b17023SJohn Marino __s + npos, __a) { }
225*e4b17023SJohn Marino
226*e4b17023SJohn Marino /**
227*e4b17023SJohn Marino * @brief Construct string as multiple characters.
228*e4b17023SJohn Marino * @param __n Number of characters.
229*e4b17023SJohn Marino * @param __c Character to use.
230*e4b17023SJohn Marino * @param __a Allocator to use (default is default allocator).
231*e4b17023SJohn Marino */
232*e4b17023SJohn Marino __versa_string(size_type __n, _CharT __c, const _Alloc& __a = _Alloc())
233*e4b17023SJohn Marino : __vstring_base(__n, __c, __a) { }
234*e4b17023SJohn Marino
235*e4b17023SJohn Marino /**
236*e4b17023SJohn Marino * @brief Construct string as copy of a range.
237*e4b17023SJohn Marino * @param __beg Start of range.
238*e4b17023SJohn Marino * @param __end End of range.
239*e4b17023SJohn Marino * @param __a Allocator to use (default is default allocator).
240*e4b17023SJohn Marino */
241*e4b17023SJohn Marino template<class _InputIterator>
242*e4b17023SJohn Marino __versa_string(_InputIterator __beg, _InputIterator __end,
243*e4b17023SJohn Marino const _Alloc& __a = _Alloc())
244*e4b17023SJohn Marino : __vstring_base(__beg, __end, __a) { }
245*e4b17023SJohn Marino
246*e4b17023SJohn Marino /**
247*e4b17023SJohn Marino * @brief Destroy the string instance.
248*e4b17023SJohn Marino */
249*e4b17023SJohn Marino ~__versa_string() _GLIBCXX_NOEXCEPT { }
250*e4b17023SJohn Marino
251*e4b17023SJohn Marino /**
252*e4b17023SJohn Marino * @brief Assign the value of @a str to this string.
253*e4b17023SJohn Marino * @param __str Source string.
254*e4b17023SJohn Marino */
255*e4b17023SJohn Marino __versa_string&
256*e4b17023SJohn Marino operator=(const __versa_string& __str)
257*e4b17023SJohn Marino { return this->assign(__str); }
258*e4b17023SJohn Marino
259*e4b17023SJohn Marino #ifdef __GXX_EXPERIMENTAL_CXX0X__
260*e4b17023SJohn Marino /**
261*e4b17023SJohn Marino * @brief String move assignment operator.
262*e4b17023SJohn Marino * @param __str Source string.
263*e4b17023SJohn Marino *
264*e4b17023SJohn Marino * The contents of @a __str are moved into this string (without
265*e4b17023SJohn Marino * copying). @a __str is a valid, but unspecified string.
266*e4b17023SJohn Marino */
267*e4b17023SJohn Marino __versa_string&
268*e4b17023SJohn Marino operator=(__versa_string&& __str)
269*e4b17023SJohn Marino {
270*e4b17023SJohn Marino // NB: DR 1204.
271*e4b17023SJohn Marino this->swap(__str);
272*e4b17023SJohn Marino return *this;
273*e4b17023SJohn Marino }
274*e4b17023SJohn Marino
275*e4b17023SJohn Marino /**
276*e4b17023SJohn Marino * @brief Set value to string constructed from initializer list.
277*e4b17023SJohn Marino * @param __l std::initializer_list.
278*e4b17023SJohn Marino */
279*e4b17023SJohn Marino __versa_string&
280*e4b17023SJohn Marino operator=(std::initializer_list<_CharT> __l)
281*e4b17023SJohn Marino {
282*e4b17023SJohn Marino this->assign(__l.begin(), __l.end());
283*e4b17023SJohn Marino return *this;
284*e4b17023SJohn Marino }
285*e4b17023SJohn Marino #endif
286*e4b17023SJohn Marino
287*e4b17023SJohn Marino /**
288*e4b17023SJohn Marino * @brief Copy contents of @a __s into this string.
289*e4b17023SJohn Marino * @param __s Source null-terminated string.
290*e4b17023SJohn Marino */
291*e4b17023SJohn Marino __versa_string&
292*e4b17023SJohn Marino operator=(const _CharT* __s)
293*e4b17023SJohn Marino { return this->assign(__s); }
294*e4b17023SJohn Marino
295*e4b17023SJohn Marino /**
296*e4b17023SJohn Marino * @brief Set value to string of length 1.
297*e4b17023SJohn Marino * @param __c Source character.
298*e4b17023SJohn Marino *
299*e4b17023SJohn Marino * Assigning to a character makes this string length 1 and
300*e4b17023SJohn Marino * (*this)[0] == @a __c.
301*e4b17023SJohn Marino */
302*e4b17023SJohn Marino __versa_string&
303*e4b17023SJohn Marino operator=(_CharT __c)
304*e4b17023SJohn Marino {
305*e4b17023SJohn Marino this->assign(1, __c);
306*e4b17023SJohn Marino return *this;
307*e4b17023SJohn Marino }
308*e4b17023SJohn Marino
309*e4b17023SJohn Marino // Iterators:
310*e4b17023SJohn Marino /**
311*e4b17023SJohn Marino * Returns a read/write iterator that points to the first character in
312*e4b17023SJohn Marino * the %string. Unshares the string.
313*e4b17023SJohn Marino */
314*e4b17023SJohn Marino iterator
315*e4b17023SJohn Marino begin() _GLIBCXX_NOEXCEPT
316*e4b17023SJohn Marino {
317*e4b17023SJohn Marino this->_M_leak();
318*e4b17023SJohn Marino return iterator(this->_M_data());
319*e4b17023SJohn Marino }
320*e4b17023SJohn Marino
321*e4b17023SJohn Marino /**
322*e4b17023SJohn Marino * Returns a read-only (constant) iterator that points to the first
323*e4b17023SJohn Marino * character in the %string.
324*e4b17023SJohn Marino */
325*e4b17023SJohn Marino const_iterator
326*e4b17023SJohn Marino begin() const _GLIBCXX_NOEXCEPT
327*e4b17023SJohn Marino { return const_iterator(this->_M_data()); }
328*e4b17023SJohn Marino
329*e4b17023SJohn Marino /**
330*e4b17023SJohn Marino * Returns a read/write iterator that points one past the last
331*e4b17023SJohn Marino * character in the %string. Unshares the string.
332*e4b17023SJohn Marino */
333*e4b17023SJohn Marino iterator
334*e4b17023SJohn Marino end() _GLIBCXX_NOEXCEPT
335*e4b17023SJohn Marino {
336*e4b17023SJohn Marino this->_M_leak();
337*e4b17023SJohn Marino return iterator(this->_M_data() + this->size());
338*e4b17023SJohn Marino }
339*e4b17023SJohn Marino
340*e4b17023SJohn Marino /**
341*e4b17023SJohn Marino * Returns a read-only (constant) iterator that points one past the
342*e4b17023SJohn Marino * last character in the %string.
343*e4b17023SJohn Marino */
344*e4b17023SJohn Marino const_iterator
345*e4b17023SJohn Marino end() const _GLIBCXX_NOEXCEPT
346*e4b17023SJohn Marino { return const_iterator(this->_M_data() + this->size()); }
347*e4b17023SJohn Marino
348*e4b17023SJohn Marino /**
349*e4b17023SJohn Marino * Returns a read/write reverse iterator that points to the last
350*e4b17023SJohn Marino * character in the %string. Iteration is done in reverse element
351*e4b17023SJohn Marino * order. Unshares the string.
352*e4b17023SJohn Marino */
353*e4b17023SJohn Marino reverse_iterator
354*e4b17023SJohn Marino rbegin() _GLIBCXX_NOEXCEPT
355*e4b17023SJohn Marino { return reverse_iterator(this->end()); }
356*e4b17023SJohn Marino
357*e4b17023SJohn Marino /**
358*e4b17023SJohn Marino * Returns a read-only (constant) reverse iterator that points
359*e4b17023SJohn Marino * to the last character in the %string. Iteration is done in
360*e4b17023SJohn Marino * reverse element order.
361*e4b17023SJohn Marino */
362*e4b17023SJohn Marino const_reverse_iterator
363*e4b17023SJohn Marino rbegin() const _GLIBCXX_NOEXCEPT
364*e4b17023SJohn Marino { return const_reverse_iterator(this->end()); }
365*e4b17023SJohn Marino
366*e4b17023SJohn Marino /**
367*e4b17023SJohn Marino * Returns a read/write reverse iterator that points to one before the
368*e4b17023SJohn Marino * first character in the %string. Iteration is done in reverse
369*e4b17023SJohn Marino * element order. Unshares the string.
370*e4b17023SJohn Marino */
371*e4b17023SJohn Marino reverse_iterator
372*e4b17023SJohn Marino rend() _GLIBCXX_NOEXCEPT
373*e4b17023SJohn Marino { return reverse_iterator(this->begin()); }
374*e4b17023SJohn Marino
375*e4b17023SJohn Marino /**
376*e4b17023SJohn Marino * Returns a read-only (constant) reverse iterator that points
377*e4b17023SJohn Marino * to one before the first character in the %string. Iteration
378*e4b17023SJohn Marino * is done in reverse element order.
379*e4b17023SJohn Marino */
380*e4b17023SJohn Marino const_reverse_iterator
381*e4b17023SJohn Marino rend() const _GLIBCXX_NOEXCEPT
382*e4b17023SJohn Marino { return const_reverse_iterator(this->begin()); }
383*e4b17023SJohn Marino
384*e4b17023SJohn Marino #ifdef __GXX_EXPERIMENTAL_CXX0X__
385*e4b17023SJohn Marino /**
386*e4b17023SJohn Marino * Returns a read-only (constant) iterator that points to the first
387*e4b17023SJohn Marino * character in the %string.
388*e4b17023SJohn Marino */
389*e4b17023SJohn Marino const_iterator
390*e4b17023SJohn Marino cbegin() const noexcept
391*e4b17023SJohn Marino { return const_iterator(this->_M_data()); }
392*e4b17023SJohn Marino
393*e4b17023SJohn Marino /**
394*e4b17023SJohn Marino * Returns a read-only (constant) iterator that points one past the
395*e4b17023SJohn Marino * last character in the %string.
396*e4b17023SJohn Marino */
397*e4b17023SJohn Marino const_iterator
398*e4b17023SJohn Marino cend() const noexcept
399*e4b17023SJohn Marino { return const_iterator(this->_M_data() + this->size()); }
400*e4b17023SJohn Marino
401*e4b17023SJohn Marino /**
402*e4b17023SJohn Marino * Returns a read-only (constant) reverse iterator that points
403*e4b17023SJohn Marino * to the last character in the %string. Iteration is done in
404*e4b17023SJohn Marino * reverse element order.
405*e4b17023SJohn Marino */
406*e4b17023SJohn Marino const_reverse_iterator
407*e4b17023SJohn Marino crbegin() const noexcept
408*e4b17023SJohn Marino { return const_reverse_iterator(this->end()); }
409*e4b17023SJohn Marino
410*e4b17023SJohn Marino /**
411*e4b17023SJohn Marino * Returns a read-only (constant) reverse iterator that points
412*e4b17023SJohn Marino * to one before the first character in the %string. Iteration
413*e4b17023SJohn Marino * is done in reverse element order.
414*e4b17023SJohn Marino */
415*e4b17023SJohn Marino const_reverse_iterator
416*e4b17023SJohn Marino crend() const noexcept
417*e4b17023SJohn Marino { return const_reverse_iterator(this->begin()); }
418*e4b17023SJohn Marino #endif
419*e4b17023SJohn Marino
420*e4b17023SJohn Marino public:
421*e4b17023SJohn Marino // Capacity:
422*e4b17023SJohn Marino /// Returns the number of characters in the string, not including any
423*e4b17023SJohn Marino /// null-termination.
424*e4b17023SJohn Marino size_type
425*e4b17023SJohn Marino size() const _GLIBCXX_NOEXCEPT
426*e4b17023SJohn Marino { return this->_M_length(); }
427*e4b17023SJohn Marino
428*e4b17023SJohn Marino /// Returns the number of characters in the string, not including any
429*e4b17023SJohn Marino /// null-termination.
430*e4b17023SJohn Marino size_type
431*e4b17023SJohn Marino length() const _GLIBCXX_NOEXCEPT
432*e4b17023SJohn Marino { return this->_M_length(); }
433*e4b17023SJohn Marino
434*e4b17023SJohn Marino /// Returns the size() of the largest possible %string.
435*e4b17023SJohn Marino size_type
436*e4b17023SJohn Marino max_size() const _GLIBCXX_NOEXCEPT
437*e4b17023SJohn Marino { return this->_M_max_size(); }
438*e4b17023SJohn Marino
439*e4b17023SJohn Marino /**
440*e4b17023SJohn Marino * @brief Resizes the %string to the specified number of characters.
441*e4b17023SJohn Marino * @param __n Number of characters the %string should contain.
442*e4b17023SJohn Marino * @param __c Character to fill any new elements.
443*e4b17023SJohn Marino *
444*e4b17023SJohn Marino * This function will %resize the %string to the specified
445*e4b17023SJohn Marino * number of characters. If the number is smaller than the
446*e4b17023SJohn Marino * %string's current size the %string is truncated, otherwise
447*e4b17023SJohn Marino * the %string is extended and new elements are set to @a __c.
448*e4b17023SJohn Marino */
449*e4b17023SJohn Marino void
450*e4b17023SJohn Marino resize(size_type __n, _CharT __c);
451*e4b17023SJohn Marino
452*e4b17023SJohn Marino /**
453*e4b17023SJohn Marino * @brief Resizes the %string to the specified number of characters.
454*e4b17023SJohn Marino * @param __n Number of characters the %string should contain.
455*e4b17023SJohn Marino *
456*e4b17023SJohn Marino * This function will resize the %string to the specified
457*e4b17023SJohn Marino * length. If the new size is smaller than the %string's
458*e4b17023SJohn Marino * current size the %string is truncated, otherwise the %string
459*e4b17023SJohn Marino * is extended and new characters are default-constructed. For
460*e4b17023SJohn Marino * basic types such as char, this means setting them to 0.
461*e4b17023SJohn Marino */
462*e4b17023SJohn Marino void
463*e4b17023SJohn Marino resize(size_type __n)
464*e4b17023SJohn Marino { this->resize(__n, _CharT()); }
465*e4b17023SJohn Marino
466*e4b17023SJohn Marino #ifdef __GXX_EXPERIMENTAL_CXX0X__
467*e4b17023SJohn Marino /// A non-binding request to reduce capacity() to size().
468*e4b17023SJohn Marino void
469*e4b17023SJohn Marino shrink_to_fit()
470*e4b17023SJohn Marino {
471*e4b17023SJohn Marino if (capacity() > size())
472*e4b17023SJohn Marino {
473*e4b17023SJohn Marino __try
474*e4b17023SJohn Marino { this->reserve(0); }
475*e4b17023SJohn Marino __catch(...)
476*e4b17023SJohn Marino { }
477*e4b17023SJohn Marino }
478*e4b17023SJohn Marino }
479*e4b17023SJohn Marino #endif
480*e4b17023SJohn Marino
481*e4b17023SJohn Marino /**
482*e4b17023SJohn Marino * Returns the total number of characters that the %string can
483*e4b17023SJohn Marino * hold before needing to allocate more memory.
484*e4b17023SJohn Marino */
485*e4b17023SJohn Marino size_type
486*e4b17023SJohn Marino capacity() const _GLIBCXX_NOEXCEPT
487*e4b17023SJohn Marino { return this->_M_capacity(); }
488*e4b17023SJohn Marino
489*e4b17023SJohn Marino /**
490*e4b17023SJohn Marino * @brief Attempt to preallocate enough memory for specified number of
491*e4b17023SJohn Marino * characters.
492*e4b17023SJohn Marino * @param __res_arg Number of characters required.
493*e4b17023SJohn Marino * @throw std::length_error If @a __res_arg exceeds @c max_size().
494*e4b17023SJohn Marino *
495*e4b17023SJohn Marino * This function attempts to reserve enough memory for the
496*e4b17023SJohn Marino * %string to hold the specified number of characters. If the
497*e4b17023SJohn Marino * number requested is more than max_size(), length_error is
498*e4b17023SJohn Marino * thrown.
499*e4b17023SJohn Marino *
500*e4b17023SJohn Marino * The advantage of this function is that if optimal code is a
501*e4b17023SJohn Marino * necessity and the user can determine the string length that
502*e4b17023SJohn Marino * will be required, the user can reserve the memory in
503*e4b17023SJohn Marino * %advance, and thus prevent a possible reallocation of memory
504*e4b17023SJohn Marino * and copying of %string data.
505*e4b17023SJohn Marino */
506*e4b17023SJohn Marino void
507*e4b17023SJohn Marino reserve(size_type __res_arg = 0)
508*e4b17023SJohn Marino { this->_M_reserve(__res_arg); }
509*e4b17023SJohn Marino
510*e4b17023SJohn Marino /**
511*e4b17023SJohn Marino * Erases the string, making it empty.
512*e4b17023SJohn Marino */
513*e4b17023SJohn Marino void
514*e4b17023SJohn Marino clear() _GLIBCXX_NOEXCEPT
515*e4b17023SJohn Marino { this->_M_clear(); }
516*e4b17023SJohn Marino
517*e4b17023SJohn Marino /**
518*e4b17023SJohn Marino * Returns true if the %string is empty. Equivalent to
519*e4b17023SJohn Marino * <code>*this == ""</code>.
520*e4b17023SJohn Marino */
521*e4b17023SJohn Marino bool
522*e4b17023SJohn Marino empty() const _GLIBCXX_NOEXCEPT
523*e4b17023SJohn Marino { return this->size() == 0; }
524*e4b17023SJohn Marino
525*e4b17023SJohn Marino // Element access:
526*e4b17023SJohn Marino /**
527*e4b17023SJohn Marino * @brief Subscript access to the data contained in the %string.
528*e4b17023SJohn Marino * @param __pos The index of the character to access.
529*e4b17023SJohn Marino * @return Read-only (constant) reference to the character.
530*e4b17023SJohn Marino *
531*e4b17023SJohn Marino * This operator allows for easy, array-style, data access.
532*e4b17023SJohn Marino * Note that data access with this operator is unchecked and
533*e4b17023SJohn Marino * out_of_range lookups are not defined. (For checked lookups
534*e4b17023SJohn Marino * see at().)
535*e4b17023SJohn Marino */
536*e4b17023SJohn Marino const_reference
537*e4b17023SJohn Marino operator[] (size_type __pos) const
538*e4b17023SJohn Marino {
539*e4b17023SJohn Marino _GLIBCXX_DEBUG_ASSERT(__pos <= this->size());
540*e4b17023SJohn Marino return this->_M_data()[__pos];
541*e4b17023SJohn Marino }
542*e4b17023SJohn Marino
543*e4b17023SJohn Marino /**
544*e4b17023SJohn Marino * @brief Subscript access to the data contained in the %string.
545*e4b17023SJohn Marino * @param __pos The index of the character to access.
546*e4b17023SJohn Marino * @return Read/write reference to the character.
547*e4b17023SJohn Marino *
548*e4b17023SJohn Marino * This operator allows for easy, array-style, data access.
549*e4b17023SJohn Marino * Note that data access with this operator is unchecked and
550*e4b17023SJohn Marino * out_of_range lookups are not defined. (For checked lookups
551*e4b17023SJohn Marino * see at().) Unshares the string.
552*e4b17023SJohn Marino */
553*e4b17023SJohn Marino reference
554*e4b17023SJohn Marino operator[](size_type __pos)
555*e4b17023SJohn Marino {
556*e4b17023SJohn Marino // allow pos == size() as v3 extension:
557*e4b17023SJohn Marino _GLIBCXX_DEBUG_ASSERT(__pos <= this->size());
558*e4b17023SJohn Marino // but be strict in pedantic mode:
559*e4b17023SJohn Marino _GLIBCXX_DEBUG_PEDASSERT(__pos < this->size());
560*e4b17023SJohn Marino this->_M_leak();
561*e4b17023SJohn Marino return this->_M_data()[__pos];
562*e4b17023SJohn Marino }
563*e4b17023SJohn Marino
564*e4b17023SJohn Marino /**
565*e4b17023SJohn Marino * @brief Provides access to the data contained in the %string.
566*e4b17023SJohn Marino * @param __n The index of the character to access.
567*e4b17023SJohn Marino * @return Read-only (const) reference to the character.
568*e4b17023SJohn Marino * @throw std::out_of_range If @a __n is an invalid index.
569*e4b17023SJohn Marino *
570*e4b17023SJohn Marino * This function provides for safer data access. The parameter
571*e4b17023SJohn Marino * is first checked that it is in the range of the string. The
572*e4b17023SJohn Marino * function throws out_of_range if the check fails.
573*e4b17023SJohn Marino */
574*e4b17023SJohn Marino const_reference
575*e4b17023SJohn Marino at(size_type __n) const
576*e4b17023SJohn Marino {
577*e4b17023SJohn Marino if (__n >= this->size())
578*e4b17023SJohn Marino std::__throw_out_of_range(__N("__versa_string::at"));
579*e4b17023SJohn Marino return this->_M_data()[__n];
580*e4b17023SJohn Marino }
581*e4b17023SJohn Marino
582*e4b17023SJohn Marino /**
583*e4b17023SJohn Marino * @brief Provides access to the data contained in the %string.
584*e4b17023SJohn Marino * @param __n The index of the character to access.
585*e4b17023SJohn Marino * @return Read/write reference to the character.
586*e4b17023SJohn Marino * @throw std::out_of_range If @a __n is an invalid index.
587*e4b17023SJohn Marino *
588*e4b17023SJohn Marino * This function provides for safer data access. The parameter
589*e4b17023SJohn Marino * is first checked that it is in the range of the string. The
590*e4b17023SJohn Marino * function throws out_of_range if the check fails. Success
591*e4b17023SJohn Marino * results in unsharing the string.
592*e4b17023SJohn Marino */
593*e4b17023SJohn Marino reference
594*e4b17023SJohn Marino at(size_type __n)
595*e4b17023SJohn Marino {
596*e4b17023SJohn Marino if (__n >= this->size())
597*e4b17023SJohn Marino std::__throw_out_of_range(__N("__versa_string::at"));
598*e4b17023SJohn Marino this->_M_leak();
599*e4b17023SJohn Marino return this->_M_data()[__n];
600*e4b17023SJohn Marino }
601*e4b17023SJohn Marino
602*e4b17023SJohn Marino #ifdef __GXX_EXPERIMENTAL_CXX0X__
603*e4b17023SJohn Marino /**
604*e4b17023SJohn Marino * Returns a read/write reference to the data at the first
605*e4b17023SJohn Marino * element of the %string.
606*e4b17023SJohn Marino */
607*e4b17023SJohn Marino reference
608*e4b17023SJohn Marino front()
609*e4b17023SJohn Marino { return operator[](0); }
610*e4b17023SJohn Marino
611*e4b17023SJohn Marino /**
612*e4b17023SJohn Marino * Returns a read-only (constant) reference to the data at the first
613*e4b17023SJohn Marino * element of the %string.
614*e4b17023SJohn Marino */
615*e4b17023SJohn Marino const_reference
616*e4b17023SJohn Marino front() const
617*e4b17023SJohn Marino { return operator[](0); }
618*e4b17023SJohn Marino
619*e4b17023SJohn Marino /**
620*e4b17023SJohn Marino * Returns a read/write reference to the data at the last
621*e4b17023SJohn Marino * element of the %string.
622*e4b17023SJohn Marino */
623*e4b17023SJohn Marino reference
624*e4b17023SJohn Marino back()
625*e4b17023SJohn Marino { return operator[](this->size() - 1); }
626*e4b17023SJohn Marino
627*e4b17023SJohn Marino /**
628*e4b17023SJohn Marino * Returns a read-only (constant) reference to the data at the
629*e4b17023SJohn Marino * last element of the %string.
630*e4b17023SJohn Marino */
631*e4b17023SJohn Marino const_reference
632*e4b17023SJohn Marino back() const
633*e4b17023SJohn Marino { return operator[](this->size() - 1); }
634*e4b17023SJohn Marino #endif
635*e4b17023SJohn Marino
636*e4b17023SJohn Marino // Modifiers:
637*e4b17023SJohn Marino /**
638*e4b17023SJohn Marino * @brief Append a string to this string.
639*e4b17023SJohn Marino * @param __str The string to append.
640*e4b17023SJohn Marino * @return Reference to this string.
641*e4b17023SJohn Marino */
642*e4b17023SJohn Marino __versa_string&
643*e4b17023SJohn Marino operator+=(const __versa_string& __str)
644*e4b17023SJohn Marino { return this->append(__str); }
645*e4b17023SJohn Marino
646*e4b17023SJohn Marino /**
647*e4b17023SJohn Marino * @brief Append a C string.
648*e4b17023SJohn Marino * @param __s The C string to append.
649*e4b17023SJohn Marino * @return Reference to this string.
650*e4b17023SJohn Marino */
651*e4b17023SJohn Marino __versa_string&
652*e4b17023SJohn Marino operator+=(const _CharT* __s)
653*e4b17023SJohn Marino { return this->append(__s); }
654*e4b17023SJohn Marino
655*e4b17023SJohn Marino /**
656*e4b17023SJohn Marino * @brief Append a character.
657*e4b17023SJohn Marino * @param __c The character to append.
658*e4b17023SJohn Marino * @return Reference to this string.
659*e4b17023SJohn Marino */
660*e4b17023SJohn Marino __versa_string&
661*e4b17023SJohn Marino operator+=(_CharT __c)
662*e4b17023SJohn Marino {
663*e4b17023SJohn Marino this->push_back(__c);
664*e4b17023SJohn Marino return *this;
665*e4b17023SJohn Marino }
666*e4b17023SJohn Marino
667*e4b17023SJohn Marino #ifdef __GXX_EXPERIMENTAL_CXX0X__
668*e4b17023SJohn Marino /**
669*e4b17023SJohn Marino * @brief Append an initializer_list of characters.
670*e4b17023SJohn Marino * @param __l The initializer_list of characters to be appended.
671*e4b17023SJohn Marino * @return Reference to this string.
672*e4b17023SJohn Marino */
673*e4b17023SJohn Marino __versa_string&
674*e4b17023SJohn Marino operator+=(std::initializer_list<_CharT> __l)
675*e4b17023SJohn Marino { return this->append(__l.begin(), __l.end()); }
676*e4b17023SJohn Marino #endif // __GXX_EXPERIMENTAL_CXX0X__
677*e4b17023SJohn Marino
678*e4b17023SJohn Marino /**
679*e4b17023SJohn Marino * @brief Append a string to this string.
680*e4b17023SJohn Marino * @param __str The string to append.
681*e4b17023SJohn Marino * @return Reference to this string.
682*e4b17023SJohn Marino */
683*e4b17023SJohn Marino __versa_string&
684*e4b17023SJohn Marino append(const __versa_string& __str)
685*e4b17023SJohn Marino { return _M_append(__str._M_data(), __str.size()); }
686*e4b17023SJohn Marino
687*e4b17023SJohn Marino /**
688*e4b17023SJohn Marino * @brief Append a substring.
689*e4b17023SJohn Marino * @param __str The string to append.
690*e4b17023SJohn Marino * @param __pos Index of the first character of str to append.
691*e4b17023SJohn Marino * @param __n The number of characters to append.
692*e4b17023SJohn Marino * @return Reference to this string.
693*e4b17023SJohn Marino * @throw std::out_of_range if @a pos is not a valid index.
694*e4b17023SJohn Marino *
695*e4b17023SJohn Marino * This function appends @a __n characters from @a __str
696*e4b17023SJohn Marino * starting at @a __pos to this string. If @a __n is is larger
697*e4b17023SJohn Marino * than the number of available characters in @a __str, the
698*e4b17023SJohn Marino * remainder of @a __str is appended.
699*e4b17023SJohn Marino */
700*e4b17023SJohn Marino __versa_string&
701*e4b17023SJohn Marino append(const __versa_string& __str, size_type __pos, size_type __n)
702*e4b17023SJohn Marino { return _M_append(__str._M_data()
703*e4b17023SJohn Marino + __str._M_check(__pos, "__versa_string::append"),
704*e4b17023SJohn Marino __str._M_limit(__pos, __n)); }
705*e4b17023SJohn Marino
706*e4b17023SJohn Marino /**
707*e4b17023SJohn Marino * @brief Append a C substring.
708*e4b17023SJohn Marino * @param __s The C string to append.
709*e4b17023SJohn Marino * @param __n The number of characters to append.
710*e4b17023SJohn Marino * @return Reference to this string.
711*e4b17023SJohn Marino */
712*e4b17023SJohn Marino __versa_string&
713*e4b17023SJohn Marino append(const _CharT* __s, size_type __n)
714*e4b17023SJohn Marino {
715*e4b17023SJohn Marino __glibcxx_requires_string_len(__s, __n);
716*e4b17023SJohn Marino _M_check_length(size_type(0), __n, "__versa_string::append");
717*e4b17023SJohn Marino return _M_append(__s, __n);
718*e4b17023SJohn Marino }
719*e4b17023SJohn Marino
720*e4b17023SJohn Marino /**
721*e4b17023SJohn Marino * @brief Append a C string.
722*e4b17023SJohn Marino * @param __s The C string to append.
723*e4b17023SJohn Marino * @return Reference to this string.
724*e4b17023SJohn Marino */
725*e4b17023SJohn Marino __versa_string&
726*e4b17023SJohn Marino append(const _CharT* __s)
727*e4b17023SJohn Marino {
728*e4b17023SJohn Marino __glibcxx_requires_string(__s);
729*e4b17023SJohn Marino const size_type __n = traits_type::length(__s);
730*e4b17023SJohn Marino _M_check_length(size_type(0), __n, "__versa_string::append");
731*e4b17023SJohn Marino return _M_append(__s, __n);
732*e4b17023SJohn Marino }
733*e4b17023SJohn Marino
734*e4b17023SJohn Marino /**
735*e4b17023SJohn Marino * @brief Append multiple characters.
736*e4b17023SJohn Marino * @param __n The number of characters to append.
737*e4b17023SJohn Marino * @param __c The character to use.
738*e4b17023SJohn Marino * @return Reference to this string.
739*e4b17023SJohn Marino *
740*e4b17023SJohn Marino * Appends n copies of c to this string.
741*e4b17023SJohn Marino */
742*e4b17023SJohn Marino __versa_string&
743*e4b17023SJohn Marino append(size_type __n, _CharT __c)
744*e4b17023SJohn Marino { return _M_replace_aux(this->size(), size_type(0), __n, __c); }
745*e4b17023SJohn Marino
746*e4b17023SJohn Marino #ifdef __GXX_EXPERIMENTAL_CXX0X__
747*e4b17023SJohn Marino /**
748*e4b17023SJohn Marino * @brief Append an initializer_list of characters.
749*e4b17023SJohn Marino * @param __l The initializer_list of characters to append.
750*e4b17023SJohn Marino * @return Reference to this string.
751*e4b17023SJohn Marino */
752*e4b17023SJohn Marino __versa_string&
753*e4b17023SJohn Marino append(std::initializer_list<_CharT> __l)
754*e4b17023SJohn Marino { return this->append(__l.begin(), __l.end()); }
755*e4b17023SJohn Marino #endif // __GXX_EXPERIMENTAL_CXX0X__
756*e4b17023SJohn Marino
757*e4b17023SJohn Marino /**
758*e4b17023SJohn Marino * @brief Append a range of characters.
759*e4b17023SJohn Marino * @param __first Iterator referencing the first character to append.
760*e4b17023SJohn Marino * @param __last Iterator marking the end of the range.
761*e4b17023SJohn Marino * @return Reference to this string.
762*e4b17023SJohn Marino *
763*e4b17023SJohn Marino * Appends characters in the range [first,last) to this string.
764*e4b17023SJohn Marino */
765*e4b17023SJohn Marino template<class _InputIterator>
766*e4b17023SJohn Marino __versa_string&
767*e4b17023SJohn Marino append(_InputIterator __first, _InputIterator __last)
768*e4b17023SJohn Marino { return this->replace(_M_iend(), _M_iend(), __first, __last); }
769*e4b17023SJohn Marino
770*e4b17023SJohn Marino /**
771*e4b17023SJohn Marino * @brief Append a single character.
772*e4b17023SJohn Marino * @param __c Character to append.
773*e4b17023SJohn Marino */
774*e4b17023SJohn Marino void
775*e4b17023SJohn Marino push_back(_CharT __c)
776*e4b17023SJohn Marino {
777*e4b17023SJohn Marino const size_type __size = this->size();
778*e4b17023SJohn Marino if (__size + 1 > this->capacity() || this->_M_is_shared())
779*e4b17023SJohn Marino this->_M_mutate(__size, size_type(0), 0, size_type(1));
780*e4b17023SJohn Marino traits_type::assign(this->_M_data()[__size], __c);
781*e4b17023SJohn Marino this->_M_set_length(__size + 1);
782*e4b17023SJohn Marino }
783*e4b17023SJohn Marino
784*e4b17023SJohn Marino /**
785*e4b17023SJohn Marino * @brief Set value to contents of another string.
786*e4b17023SJohn Marino * @param __str Source string to use.
787*e4b17023SJohn Marino * @return Reference to this string.
788*e4b17023SJohn Marino */
789*e4b17023SJohn Marino __versa_string&
790*e4b17023SJohn Marino assign(const __versa_string& __str)
791*e4b17023SJohn Marino {
792*e4b17023SJohn Marino this->_M_assign(__str);
793*e4b17023SJohn Marino return *this;
794*e4b17023SJohn Marino }
795*e4b17023SJohn Marino
796*e4b17023SJohn Marino #ifdef __GXX_EXPERIMENTAL_CXX0X__
797*e4b17023SJohn Marino /**
798*e4b17023SJohn Marino * @brief Set value to contents of another string.
799*e4b17023SJohn Marino * @param __str Source string to use.
800*e4b17023SJohn Marino * @return Reference to this string.
801*e4b17023SJohn Marino *
802*e4b17023SJohn Marino * This function sets this string to the exact contents of @a __str.
803*e4b17023SJohn Marino * @a __str is a valid, but unspecified string.
804*e4b17023SJohn Marino */
805*e4b17023SJohn Marino __versa_string&
806*e4b17023SJohn Marino assign(__versa_string&& __str)
807*e4b17023SJohn Marino {
808*e4b17023SJohn Marino this->swap(__str);
809*e4b17023SJohn Marino return *this;
810*e4b17023SJohn Marino }
811*e4b17023SJohn Marino #endif // __GXX_EXPERIMENTAL_CXX0X__
812*e4b17023SJohn Marino
813*e4b17023SJohn Marino /**
814*e4b17023SJohn Marino * @brief Set value to a substring of a string.
815*e4b17023SJohn Marino * @param __str The string to use.
816*e4b17023SJohn Marino * @param __pos Index of the first character of str.
817*e4b17023SJohn Marino * @param __n Number of characters to use.
818*e4b17023SJohn Marino * @return Reference to this string.
819*e4b17023SJohn Marino * @throw std::out_of_range if @a __pos is not a valid index.
820*e4b17023SJohn Marino *
821*e4b17023SJohn Marino * This function sets this string to the substring of @a __str
822*e4b17023SJohn Marino * consisting of @a __n characters at @a __pos. If @a __n is
823*e4b17023SJohn Marino * is larger than the number of available characters in @a
824*e4b17023SJohn Marino * __str, the remainder of @a __str is used.
825*e4b17023SJohn Marino */
826*e4b17023SJohn Marino __versa_string&
827*e4b17023SJohn Marino assign(const __versa_string& __str, size_type __pos, size_type __n)
828*e4b17023SJohn Marino { return _M_replace(size_type(0), this->size(), __str._M_data()
829*e4b17023SJohn Marino + __str._M_check(__pos, "__versa_string::assign"),
830*e4b17023SJohn Marino __str._M_limit(__pos, __n)); }
831*e4b17023SJohn Marino
832*e4b17023SJohn Marino /**
833*e4b17023SJohn Marino * @brief Set value to a C substring.
834*e4b17023SJohn Marino * @param __s The C string to use.
835*e4b17023SJohn Marino * @param __n Number of characters to use.
836*e4b17023SJohn Marino * @return Reference to this string.
837*e4b17023SJohn Marino *
838*e4b17023SJohn Marino * This function sets the value of this string to the first @a
839*e4b17023SJohn Marino * __n characters of @a __s. If @a __n is is larger than the
840*e4b17023SJohn Marino * number of available characters in @a __s, the remainder of
841*e4b17023SJohn Marino * @a __s is used.
842*e4b17023SJohn Marino */
843*e4b17023SJohn Marino __versa_string&
844*e4b17023SJohn Marino assign(const _CharT* __s, size_type __n)
845*e4b17023SJohn Marino {
846*e4b17023SJohn Marino __glibcxx_requires_string_len(__s, __n);
847*e4b17023SJohn Marino return _M_replace(size_type(0), this->size(), __s, __n);
848*e4b17023SJohn Marino }
849*e4b17023SJohn Marino
850*e4b17023SJohn Marino /**
851*e4b17023SJohn Marino * @brief Set value to contents of a C string.
852*e4b17023SJohn Marino * @param __s The C string to use.
853*e4b17023SJohn Marino * @return Reference to this string.
854*e4b17023SJohn Marino *
855*e4b17023SJohn Marino * This function sets the value of this string to the value of
856*e4b17023SJohn Marino * @a __s. The data is copied, so there is no dependence on @a
857*e4b17023SJohn Marino * __s once the function returns.
858*e4b17023SJohn Marino */
859*e4b17023SJohn Marino __versa_string&
860*e4b17023SJohn Marino assign(const _CharT* __s)
861*e4b17023SJohn Marino {
862*e4b17023SJohn Marino __glibcxx_requires_string(__s);
863*e4b17023SJohn Marino return _M_replace(size_type(0), this->size(), __s,
864*e4b17023SJohn Marino traits_type::length(__s));
865*e4b17023SJohn Marino }
866*e4b17023SJohn Marino
867*e4b17023SJohn Marino /**
868*e4b17023SJohn Marino * @brief Set value to multiple characters.
869*e4b17023SJohn Marino * @param __n Length of the resulting string.
870*e4b17023SJohn Marino * @param __c The character to use.
871*e4b17023SJohn Marino * @return Reference to this string.
872*e4b17023SJohn Marino *
873*e4b17023SJohn Marino * This function sets the value of this string to @a __n copies of
874*e4b17023SJohn Marino * character @a __c.
875*e4b17023SJohn Marino */
876*e4b17023SJohn Marino __versa_string&
877*e4b17023SJohn Marino assign(size_type __n, _CharT __c)
878*e4b17023SJohn Marino { return _M_replace_aux(size_type(0), this->size(), __n, __c); }
879*e4b17023SJohn Marino
880*e4b17023SJohn Marino /**
881*e4b17023SJohn Marino * @brief Set value to a range of characters.
882*e4b17023SJohn Marino * @param __first Iterator referencing the first character to append.
883*e4b17023SJohn Marino * @param __last Iterator marking the end of the range.
884*e4b17023SJohn Marino * @return Reference to this string.
885*e4b17023SJohn Marino *
886*e4b17023SJohn Marino * Sets value of string to characters in the range
887*e4b17023SJohn Marino * [first,last).
888*e4b17023SJohn Marino */
889*e4b17023SJohn Marino template<class _InputIterator>
890*e4b17023SJohn Marino __versa_string&
891*e4b17023SJohn Marino assign(_InputIterator __first, _InputIterator __last)
892*e4b17023SJohn Marino { return this->replace(_M_ibegin(), _M_iend(), __first, __last); }
893*e4b17023SJohn Marino
894*e4b17023SJohn Marino #ifdef __GXX_EXPERIMENTAL_CXX0X__
895*e4b17023SJohn Marino /**
896*e4b17023SJohn Marino * @brief Set value to an initializer_list of characters.
897*e4b17023SJohn Marino * @param __l The initializer_list of characters to assign.
898*e4b17023SJohn Marino * @return Reference to this string.
899*e4b17023SJohn Marino */
900*e4b17023SJohn Marino __versa_string&
901*e4b17023SJohn Marino assign(std::initializer_list<_CharT> __l)
902*e4b17023SJohn Marino { return this->assign(__l.begin(), __l.end()); }
903*e4b17023SJohn Marino #endif // __GXX_EXPERIMENTAL_CXX0X__
904*e4b17023SJohn Marino
905*e4b17023SJohn Marino /**
906*e4b17023SJohn Marino * @brief Insert multiple characters.
907*e4b17023SJohn Marino * @param __p Iterator referencing location in string to insert at.
908*e4b17023SJohn Marino * @param __n Number of characters to insert
909*e4b17023SJohn Marino * @param __c The character to insert.
910*e4b17023SJohn Marino * @throw std::length_error If new length exceeds @c max_size().
911*e4b17023SJohn Marino *
912*e4b17023SJohn Marino * Inserts @a __n copies of character @a __c starting at the
913*e4b17023SJohn Marino * position referenced by iterator @a __p. If adding
914*e4b17023SJohn Marino * characters causes the length to exceed max_size(),
915*e4b17023SJohn Marino * length_error is thrown. The value of the string doesn't
916*e4b17023SJohn Marino * change if an error is thrown.
917*e4b17023SJohn Marino */
918*e4b17023SJohn Marino void
919*e4b17023SJohn Marino insert(iterator __p, size_type __n, _CharT __c)
920*e4b17023SJohn Marino { this->replace(__p, __p, __n, __c); }
921*e4b17023SJohn Marino
922*e4b17023SJohn Marino /**
923*e4b17023SJohn Marino * @brief Insert a range of characters.
924*e4b17023SJohn Marino * @param __p Iterator referencing location in string to insert at.
925*e4b17023SJohn Marino * @param __beg Start of range.
926*e4b17023SJohn Marino * @param __end End of range.
927*e4b17023SJohn Marino * @throw std::length_error If new length exceeds @c max_size().
928*e4b17023SJohn Marino *
929*e4b17023SJohn Marino * Inserts characters in range [beg,end). If adding characters
930*e4b17023SJohn Marino * causes the length to exceed max_size(), length_error is
931*e4b17023SJohn Marino * thrown. The value of the string doesn't change if an error
932*e4b17023SJohn Marino * is thrown.
933*e4b17023SJohn Marino */
934*e4b17023SJohn Marino template<class _InputIterator>
935*e4b17023SJohn Marino void
936*e4b17023SJohn Marino insert(iterator __p, _InputIterator __beg, _InputIterator __end)
937*e4b17023SJohn Marino { this->replace(__p, __p, __beg, __end); }
938*e4b17023SJohn Marino
939*e4b17023SJohn Marino #ifdef __GXX_EXPERIMENTAL_CXX0X__
940*e4b17023SJohn Marino /**
941*e4b17023SJohn Marino * @brief Insert an initializer_list of characters.
942*e4b17023SJohn Marino * @param __p Iterator referencing location in string to insert at.
943*e4b17023SJohn Marino * @param __l The initializer_list of characters to insert.
944*e4b17023SJohn Marino * @throw std::length_error If new length exceeds @c max_size().
945*e4b17023SJohn Marino */
946*e4b17023SJohn Marino void
947*e4b17023SJohn Marino insert(iterator __p, std::initializer_list<_CharT> __l)
948*e4b17023SJohn Marino { this->insert(__p, __l.begin(), __l.end()); }
949*e4b17023SJohn Marino #endif // __GXX_EXPERIMENTAL_CXX0X__
950*e4b17023SJohn Marino
951*e4b17023SJohn Marino /**
952*e4b17023SJohn Marino * @brief Insert value of a string.
953*e4b17023SJohn Marino * @param __pos1 Iterator referencing location in string to insert at.
954*e4b17023SJohn Marino * @param __str The string to insert.
955*e4b17023SJohn Marino * @return Reference to this string.
956*e4b17023SJohn Marino * @throw std::length_error If new length exceeds @c max_size().
957*e4b17023SJohn Marino *
958*e4b17023SJohn Marino * Inserts value of @a __str starting at @a __pos1. If adding
959*e4b17023SJohn Marino * characters causes the length to exceed max_size(),
960*e4b17023SJohn Marino * length_error is thrown. The value of the string doesn't
961*e4b17023SJohn Marino * change if an error is thrown.
962*e4b17023SJohn Marino */
963*e4b17023SJohn Marino __versa_string&
964*e4b17023SJohn Marino insert(size_type __pos1, const __versa_string& __str)
965*e4b17023SJohn Marino { return this->replace(__pos1, size_type(0),
966*e4b17023SJohn Marino __str._M_data(), __str.size()); }
967*e4b17023SJohn Marino
968*e4b17023SJohn Marino /**
969*e4b17023SJohn Marino * @brief Insert a substring.
970*e4b17023SJohn Marino * @param __pos1 Iterator referencing location in string to insert at.
971*e4b17023SJohn Marino * @param __str The string to insert.
972*e4b17023SJohn Marino * @param __pos2 Start of characters in str to insert.
973*e4b17023SJohn Marino * @param __n Number of characters to insert.
974*e4b17023SJohn Marino * @return Reference to this string.
975*e4b17023SJohn Marino * @throw std::length_error If new length exceeds @c max_size().
976*e4b17023SJohn Marino * @throw std::out_of_range If @a __pos1 > size() or
977*e4b17023SJohn Marino * @a __pos2 > @a __str.size().
978*e4b17023SJohn Marino *
979*e4b17023SJohn Marino * Starting at @a __pos1, insert @a __n character of @a __str
980*e4b17023SJohn Marino * beginning with @a __pos2. If adding characters causes the
981*e4b17023SJohn Marino * length to exceed max_size(), length_error is thrown. If @a
982*e4b17023SJohn Marino * __pos1 is beyond the end of this string or @a __pos2 is
983*e4b17023SJohn Marino * beyond the end of @a __str, out_of_range is thrown. The
984*e4b17023SJohn Marino * value of the string doesn't change if an error is thrown.
985*e4b17023SJohn Marino */
986*e4b17023SJohn Marino __versa_string&
987*e4b17023SJohn Marino insert(size_type __pos1, const __versa_string& __str,
988*e4b17023SJohn Marino size_type __pos2, size_type __n)
989*e4b17023SJohn Marino { return this->replace(__pos1, size_type(0), __str._M_data()
990*e4b17023SJohn Marino + __str._M_check(__pos2, "__versa_string::insert"),
991*e4b17023SJohn Marino __str._M_limit(__pos2, __n)); }
992*e4b17023SJohn Marino
993*e4b17023SJohn Marino /**
994*e4b17023SJohn Marino * @brief Insert a C substring.
995*e4b17023SJohn Marino * @param __pos Iterator referencing location in string to insert at.
996*e4b17023SJohn Marino * @param __s The C string to insert.
997*e4b17023SJohn Marino * @param __n The number of characters to insert.
998*e4b17023SJohn Marino * @return Reference to this string.
999*e4b17023SJohn Marino * @throw std::length_error If new length exceeds @c max_size().
1000*e4b17023SJohn Marino * @throw std::out_of_range If @a __pos is beyond the end of this
1001*e4b17023SJohn Marino * string.
1002*e4b17023SJohn Marino *
1003*e4b17023SJohn Marino * Inserts the first @a __n characters of @a __s starting at @a
1004*e4b17023SJohn Marino * __pos. If adding characters causes the length to exceed
1005*e4b17023SJohn Marino * max_size(), length_error is thrown. If @a __pos is beyond
1006*e4b17023SJohn Marino * end(), out_of_range is thrown. The value of the string
1007*e4b17023SJohn Marino * doesn't change if an error is thrown.
1008*e4b17023SJohn Marino */
1009*e4b17023SJohn Marino __versa_string&
1010*e4b17023SJohn Marino insert(size_type __pos, const _CharT* __s, size_type __n)
1011*e4b17023SJohn Marino { return this->replace(__pos, size_type(0), __s, __n); }
1012*e4b17023SJohn Marino
1013*e4b17023SJohn Marino /**
1014*e4b17023SJohn Marino * @brief Insert a C string.
1015*e4b17023SJohn Marino * @param __pos Iterator referencing location in string to insert at.
1016*e4b17023SJohn Marino * @param __s The C string to insert.
1017*e4b17023SJohn Marino * @return Reference to this string.
1018*e4b17023SJohn Marino * @throw std::length_error If new length exceeds @c max_size().
1019*e4b17023SJohn Marino * @throw std::out_of_range If @a __pos is beyond the end of this
1020*e4b17023SJohn Marino * string.
1021*e4b17023SJohn Marino *
1022*e4b17023SJohn Marino * Inserts the first @a __n characters of @a __s starting at @a
1023*e4b17023SJohn Marino * __pos. If adding characters causes the length to exceed
1024*e4b17023SJohn Marino * max_size(), length_error is thrown. If @a __pos is beyond
1025*e4b17023SJohn Marino * end(), out_of_range is thrown. The value of the string
1026*e4b17023SJohn Marino * doesn't change if an error is thrown.
1027*e4b17023SJohn Marino */
1028*e4b17023SJohn Marino __versa_string&
1029*e4b17023SJohn Marino insert(size_type __pos, const _CharT* __s)
1030*e4b17023SJohn Marino {
1031*e4b17023SJohn Marino __glibcxx_requires_string(__s);
1032*e4b17023SJohn Marino return this->replace(__pos, size_type(0), __s,
1033*e4b17023SJohn Marino traits_type::length(__s));
1034*e4b17023SJohn Marino }
1035*e4b17023SJohn Marino
1036*e4b17023SJohn Marino /**
1037*e4b17023SJohn Marino * @brief Insert multiple characters.
1038*e4b17023SJohn Marino * @param __pos Index in string to insert at.
1039*e4b17023SJohn Marino * @param __n Number of characters to insert
1040*e4b17023SJohn Marino * @param __c The character to insert.
1041*e4b17023SJohn Marino * @return Reference to this string.
1042*e4b17023SJohn Marino * @throw std::length_error If new length exceeds @c max_size().
1043*e4b17023SJohn Marino * @throw std::out_of_range If @a __pos is beyond the end of this
1044*e4b17023SJohn Marino * string.
1045*e4b17023SJohn Marino *
1046*e4b17023SJohn Marino * Inserts @a __n copies of character @a __c starting at index
1047*e4b17023SJohn Marino * @a __pos. If adding characters causes the length to exceed
1048*e4b17023SJohn Marino * max_size(), length_error is thrown. If @a __pos > length(),
1049*e4b17023SJohn Marino * out_of_range is thrown. The value of the string doesn't
1050*e4b17023SJohn Marino * change if an error is thrown.
1051*e4b17023SJohn Marino */
1052*e4b17023SJohn Marino __versa_string&
1053*e4b17023SJohn Marino insert(size_type __pos, size_type __n, _CharT __c)
1054*e4b17023SJohn Marino { return _M_replace_aux(_M_check(__pos, "__versa_string::insert"),
1055*e4b17023SJohn Marino size_type(0), __n, __c); }
1056*e4b17023SJohn Marino
1057*e4b17023SJohn Marino /**
1058*e4b17023SJohn Marino * @brief Insert one character.
1059*e4b17023SJohn Marino * @param __p Iterator referencing position in string to insert at.
1060*e4b17023SJohn Marino * @param __c The character to insert.
1061*e4b17023SJohn Marino * @return Iterator referencing newly inserted char.
1062*e4b17023SJohn Marino * @throw std::length_error If new length exceeds @c max_size().
1063*e4b17023SJohn Marino *
1064*e4b17023SJohn Marino * Inserts character @a __c at position referenced by @a __p.
1065*e4b17023SJohn Marino * If adding character causes the length to exceed max_size(),
1066*e4b17023SJohn Marino * length_error is thrown. If @a __p is beyond end of string,
1067*e4b17023SJohn Marino * out_of_range is thrown. The value of the string doesn't
1068*e4b17023SJohn Marino * change if an error is thrown.
1069*e4b17023SJohn Marino */
1070*e4b17023SJohn Marino iterator
1071*e4b17023SJohn Marino insert(iterator __p, _CharT __c)
1072*e4b17023SJohn Marino {
1073*e4b17023SJohn Marino _GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend());
1074*e4b17023SJohn Marino const size_type __pos = __p - _M_ibegin();
1075*e4b17023SJohn Marino _M_replace_aux(__pos, size_type(0), size_type(1), __c);
1076*e4b17023SJohn Marino this->_M_set_leaked();
1077*e4b17023SJohn Marino return iterator(this->_M_data() + __pos);
1078*e4b17023SJohn Marino }
1079*e4b17023SJohn Marino
1080*e4b17023SJohn Marino /**
1081*e4b17023SJohn Marino * @brief Remove characters.
1082*e4b17023SJohn Marino * @param __pos Index of first character to remove (default 0).
1083*e4b17023SJohn Marino * @param __n Number of characters to remove (default remainder).
1084*e4b17023SJohn Marino * @return Reference to this string.
1085*e4b17023SJohn Marino * @throw std::out_of_range If @a __pos is beyond the end of this
1086*e4b17023SJohn Marino * string.
1087*e4b17023SJohn Marino *
1088*e4b17023SJohn Marino * Removes @a __n characters from this string starting at @a
1089*e4b17023SJohn Marino * __pos. The length of the string is reduced by @a __n. If
1090*e4b17023SJohn Marino * there are < @a __n characters to remove, the remainder of
1091*e4b17023SJohn Marino * the string is truncated. If @a __p is beyond end of string,
1092*e4b17023SJohn Marino * out_of_range is thrown. The value of the string doesn't
1093*e4b17023SJohn Marino * change if an error is thrown.
1094*e4b17023SJohn Marino */
1095*e4b17023SJohn Marino __versa_string&
1096*e4b17023SJohn Marino erase(size_type __pos = 0, size_type __n = npos)
1097*e4b17023SJohn Marino {
1098*e4b17023SJohn Marino this->_M_erase(_M_check(__pos, "__versa_string::erase"),
1099*e4b17023SJohn Marino _M_limit(__pos, __n));
1100*e4b17023SJohn Marino return *this;
1101*e4b17023SJohn Marino }
1102*e4b17023SJohn Marino
1103*e4b17023SJohn Marino /**
1104*e4b17023SJohn Marino * @brief Remove one character.
1105*e4b17023SJohn Marino * @param __position Iterator referencing the character to remove.
1106*e4b17023SJohn Marino * @return iterator referencing same location after removal.
1107*e4b17023SJohn Marino *
1108*e4b17023SJohn Marino * Removes the character at @a __position from this string. The
1109*e4b17023SJohn Marino * value of the string doesn't change if an error is thrown.
1110*e4b17023SJohn Marino */
1111*e4b17023SJohn Marino iterator
1112*e4b17023SJohn Marino erase(iterator __position)
1113*e4b17023SJohn Marino {
1114*e4b17023SJohn Marino _GLIBCXX_DEBUG_PEDASSERT(__position >= _M_ibegin()
1115*e4b17023SJohn Marino && __position < _M_iend());
1116*e4b17023SJohn Marino const size_type __pos = __position - _M_ibegin();
1117*e4b17023SJohn Marino this->_M_erase(__pos, size_type(1));
1118*e4b17023SJohn Marino this->_M_set_leaked();
1119*e4b17023SJohn Marino return iterator(this->_M_data() + __pos);
1120*e4b17023SJohn Marino }
1121*e4b17023SJohn Marino
1122*e4b17023SJohn Marino /**
1123*e4b17023SJohn Marino * @brief Remove a range of characters.
1124*e4b17023SJohn Marino * @param __first Iterator referencing the first character to remove.
1125*e4b17023SJohn Marino * @param __last Iterator referencing the end of the range.
1126*e4b17023SJohn Marino * @return Iterator referencing location of first after removal.
1127*e4b17023SJohn Marino *
1128*e4b17023SJohn Marino * Removes the characters in the range [first,last) from this
1129*e4b17023SJohn Marino * string. The value of the string doesn't change if an error
1130*e4b17023SJohn Marino * is thrown.
1131*e4b17023SJohn Marino */
1132*e4b17023SJohn Marino iterator
1133*e4b17023SJohn Marino erase(iterator __first, iterator __last)
1134*e4b17023SJohn Marino {
1135*e4b17023SJohn Marino _GLIBCXX_DEBUG_PEDASSERT(__first >= _M_ibegin() && __first <= __last
1136*e4b17023SJohn Marino && __last <= _M_iend());
1137*e4b17023SJohn Marino const size_type __pos = __first - _M_ibegin();
1138*e4b17023SJohn Marino this->_M_erase(__pos, __last - __first);
1139*e4b17023SJohn Marino this->_M_set_leaked();
1140*e4b17023SJohn Marino return iterator(this->_M_data() + __pos);
1141*e4b17023SJohn Marino }
1142*e4b17023SJohn Marino
1143*e4b17023SJohn Marino #ifdef __GXX_EXPERIMENTAL_CXX0X__
1144*e4b17023SJohn Marino /**
1145*e4b17023SJohn Marino * @brief Remove the last character.
1146*e4b17023SJohn Marino *
1147*e4b17023SJohn Marino * The string must be non-empty.
1148*e4b17023SJohn Marino */
1149*e4b17023SJohn Marino void
1150*e4b17023SJohn Marino pop_back()
1151*e4b17023SJohn Marino { this->_M_erase(size()-1, 1); }
1152*e4b17023SJohn Marino #endif // __GXX_EXPERIMENTAL_CXX0X__
1153*e4b17023SJohn Marino
1154*e4b17023SJohn Marino /**
1155*e4b17023SJohn Marino * @brief Replace characters with value from another string.
1156*e4b17023SJohn Marino * @param __pos Index of first character to replace.
1157*e4b17023SJohn Marino * @param __n Number of characters to be replaced.
1158*e4b17023SJohn Marino * @param __str String to insert.
1159*e4b17023SJohn Marino * @return Reference to this string.
1160*e4b17023SJohn Marino * @throw std::out_of_range If @a __pos is beyond the end of this
1161*e4b17023SJohn Marino * string.
1162*e4b17023SJohn Marino * @throw std::length_error If new length exceeds @c max_size().
1163*e4b17023SJohn Marino *
1164*e4b17023SJohn Marino * Removes the characters in the range [pos,pos+n) from this
1165*e4b17023SJohn Marino * string. In place, the value of @a __str is inserted. If @a
1166*e4b17023SJohn Marino * __pos is beyond end of string, out_of_range is thrown. If
1167*e4b17023SJohn Marino * the length of the result exceeds max_size(), length_error is
1168*e4b17023SJohn Marino * thrown. The value of the string doesn't change if an error
1169*e4b17023SJohn Marino * is thrown.
1170*e4b17023SJohn Marino */
1171*e4b17023SJohn Marino __versa_string&
1172*e4b17023SJohn Marino replace(size_type __pos, size_type __n, const __versa_string& __str)
1173*e4b17023SJohn Marino { return this->replace(__pos, __n, __str._M_data(), __str.size()); }
1174*e4b17023SJohn Marino
1175*e4b17023SJohn Marino /**
1176*e4b17023SJohn Marino * @brief Replace characters with value from another string.
1177*e4b17023SJohn Marino * @param __pos1 Index of first character to replace.
1178*e4b17023SJohn Marino * @param __n1 Number of characters to be replaced.
1179*e4b17023SJohn Marino * @param __str String to insert.
1180*e4b17023SJohn Marino * @param __pos2 Index of first character of str to use.
1181*e4b17023SJohn Marino * @param __n2 Number of characters from str to use.
1182*e4b17023SJohn Marino * @return Reference to this string.
1183*e4b17023SJohn Marino * @throw std::out_of_range If @a __pos1 > size() or @a __pos2 >
1184*e4b17023SJohn Marino * str.size().
1185*e4b17023SJohn Marino * @throw std::length_error If new length exceeds @c max_size().
1186*e4b17023SJohn Marino *
1187*e4b17023SJohn Marino * Removes the characters in the range [pos1,pos1 + n) from
1188*e4b17023SJohn Marino * this string. In place, the value of @a __str is inserted.
1189*e4b17023SJohn Marino * If @a __pos is beyond end of string, out_of_range is thrown.
1190*e4b17023SJohn Marino * If the length of the result exceeds max_size(), length_error
1191*e4b17023SJohn Marino * is thrown. The value of the string doesn't change if an
1192*e4b17023SJohn Marino * error is thrown.
1193*e4b17023SJohn Marino */
1194*e4b17023SJohn Marino __versa_string&
1195*e4b17023SJohn Marino replace(size_type __pos1, size_type __n1, const __versa_string& __str,
1196*e4b17023SJohn Marino size_type __pos2, size_type __n2)
1197*e4b17023SJohn Marino {
1198*e4b17023SJohn Marino return this->replace(__pos1, __n1, __str._M_data()
1199*e4b17023SJohn Marino + __str._M_check(__pos2,
1200*e4b17023SJohn Marino "__versa_string::replace"),
1201*e4b17023SJohn Marino __str._M_limit(__pos2, __n2));
1202*e4b17023SJohn Marino }
1203*e4b17023SJohn Marino
1204*e4b17023SJohn Marino /**
1205*e4b17023SJohn Marino * @brief Replace characters with value of a C substring.
1206*e4b17023SJohn Marino * @param __pos Index of first character to replace.
1207*e4b17023SJohn Marino * @param __n1 Number of characters to be replaced.
1208*e4b17023SJohn Marino * @param __s C string to insert.
1209*e4b17023SJohn Marino * @param __n2 Number of characters from @a __s to use.
1210*e4b17023SJohn Marino * @return Reference to this string.
1211*e4b17023SJohn Marino * @throw std::out_of_range If @a __pos1 > size().
1212*e4b17023SJohn Marino * @throw std::length_error If new length exceeds @c max_size().
1213*e4b17023SJohn Marino *
1214*e4b17023SJohn Marino * Removes the characters in the range [pos,pos + n1) from this
1215*e4b17023SJohn Marino * string. In place, the first @a __n2 characters of @a __s
1216*e4b17023SJohn Marino * are inserted, or all of @a __s if @a __n2 is too large. If
1217*e4b17023SJohn Marino * @a __pos is beyond end of string, out_of_range is thrown.
1218*e4b17023SJohn Marino * If the length of result exceeds max_size(), length_error is
1219*e4b17023SJohn Marino * thrown. The value of the string doesn't change if an error
1220*e4b17023SJohn Marino * is thrown.
1221*e4b17023SJohn Marino */
1222*e4b17023SJohn Marino __versa_string&
1223*e4b17023SJohn Marino replace(size_type __pos, size_type __n1, const _CharT* __s,
1224*e4b17023SJohn Marino size_type __n2)
1225*e4b17023SJohn Marino {
1226*e4b17023SJohn Marino __glibcxx_requires_string_len(__s, __n2);
1227*e4b17023SJohn Marino return _M_replace(_M_check(__pos, "__versa_string::replace"),
1228*e4b17023SJohn Marino _M_limit(__pos, __n1), __s, __n2);
1229*e4b17023SJohn Marino }
1230*e4b17023SJohn Marino
1231*e4b17023SJohn Marino /**
1232*e4b17023SJohn Marino * @brief Replace characters with value of a C string.
1233*e4b17023SJohn Marino * @param __pos Index of first character to replace.
1234*e4b17023SJohn Marino * @param __n1 Number of characters to be replaced.
1235*e4b17023SJohn Marino * @param __s C string to insert.
1236*e4b17023SJohn Marino * @return Reference to this string.
1237*e4b17023SJohn Marino * @throw std::out_of_range If @a __pos > size().
1238*e4b17023SJohn Marino * @throw std::length_error If new length exceeds @c max_size().
1239*e4b17023SJohn Marino *
1240*e4b17023SJohn Marino * Removes the characters in the range [pos,pos + n1) from this
1241*e4b17023SJohn Marino * string. In place, the characters of @a __s are inserted. If
1242*e4b17023SJohn Marino * @a pos is beyond end of string, out_of_range is thrown. If
1243*e4b17023SJohn Marino * the length of result exceeds max_size(), length_error is thrown.
1244*e4b17023SJohn Marino * The value of the string doesn't change if an error is thrown.
1245*e4b17023SJohn Marino */
1246*e4b17023SJohn Marino __versa_string&
1247*e4b17023SJohn Marino replace(size_type __pos, size_type __n1, const _CharT* __s)
1248*e4b17023SJohn Marino {
1249*e4b17023SJohn Marino __glibcxx_requires_string(__s);
1250*e4b17023SJohn Marino return this->replace(__pos, __n1, __s, traits_type::length(__s));
1251*e4b17023SJohn Marino }
1252*e4b17023SJohn Marino
1253*e4b17023SJohn Marino /**
1254*e4b17023SJohn Marino * @brief Replace characters with multiple characters.
1255*e4b17023SJohn Marino * @param __pos Index of first character to replace.
1256*e4b17023SJohn Marino * @param __n1 Number of characters to be replaced.
1257*e4b17023SJohn Marino * @param __n2 Number of characters to insert.
1258*e4b17023SJohn Marino * @param __c Character to insert.
1259*e4b17023SJohn Marino * @return Reference to this string.
1260*e4b17023SJohn Marino * @throw std::out_of_range If @a __pos > size().
1261*e4b17023SJohn Marino * @throw std::length_error If new length exceeds @c max_size().
1262*e4b17023SJohn Marino *
1263*e4b17023SJohn Marino * Removes the characters in the range [pos,pos + n1) from this
1264*e4b17023SJohn Marino * string. In place, @a __n2 copies of @a __c are inserted.
1265*e4b17023SJohn Marino * If @a __pos is beyond end of string, out_of_range is thrown.
1266*e4b17023SJohn Marino * If the length of result exceeds max_size(), length_error is
1267*e4b17023SJohn Marino * thrown. The value of the string doesn't change if an error
1268*e4b17023SJohn Marino * is thrown.
1269*e4b17023SJohn Marino */
1270*e4b17023SJohn Marino __versa_string&
1271*e4b17023SJohn Marino replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
1272*e4b17023SJohn Marino { return _M_replace_aux(_M_check(__pos, "__versa_string::replace"),
1273*e4b17023SJohn Marino _M_limit(__pos, __n1), __n2, __c); }
1274*e4b17023SJohn Marino
1275*e4b17023SJohn Marino /**
1276*e4b17023SJohn Marino * @brief Replace range of characters with string.
1277*e4b17023SJohn Marino * @param __i1 Iterator referencing start of range to replace.
1278*e4b17023SJohn Marino * @param __i2 Iterator referencing end of range to replace.
1279*e4b17023SJohn Marino * @param __str String value to insert.
1280*e4b17023SJohn Marino * @return Reference to this string.
1281*e4b17023SJohn Marino * @throw std::length_error If new length exceeds @c max_size().
1282*e4b17023SJohn Marino *
1283*e4b17023SJohn Marino * Removes the characters in the range [i1,i2). In place, the
1284*e4b17023SJohn Marino * value of @a __str is inserted. If the length of result
1285*e4b17023SJohn Marino * exceeds max_size(), length_error is thrown. The value of
1286*e4b17023SJohn Marino * the string doesn't change if an error is thrown.
1287*e4b17023SJohn Marino */
1288*e4b17023SJohn Marino __versa_string&
1289*e4b17023SJohn Marino replace(iterator __i1, iterator __i2, const __versa_string& __str)
1290*e4b17023SJohn Marino { return this->replace(__i1, __i2, __str._M_data(), __str.size()); }
1291*e4b17023SJohn Marino
1292*e4b17023SJohn Marino /**
1293*e4b17023SJohn Marino * @brief Replace range of characters with C substring.
1294*e4b17023SJohn Marino * @param __i1 Iterator referencing start of range to replace.
1295*e4b17023SJohn Marino * @param __i2 Iterator referencing end of range to replace.
1296*e4b17023SJohn Marino * @param __s C string value to insert.
1297*e4b17023SJohn Marino * @param __n Number of characters from s to insert.
1298*e4b17023SJohn Marino * @return Reference to this string.
1299*e4b17023SJohn Marino * @throw std::length_error If new length exceeds @c max_size().
1300*e4b17023SJohn Marino *
1301*e4b17023SJohn Marino * Removes the characters in the range [i1,i2). In place, the
1302*e4b17023SJohn Marino * first @a n characters of @a __s are inserted. If the length
1303*e4b17023SJohn Marino * of result exceeds max_size(), length_error is thrown. The
1304*e4b17023SJohn Marino * value of the string doesn't change if an error is thrown.
1305*e4b17023SJohn Marino */
1306*e4b17023SJohn Marino __versa_string&
1307*e4b17023SJohn Marino replace(iterator __i1, iterator __i2, const _CharT* __s, size_type __n)
1308*e4b17023SJohn Marino {
1309*e4b17023SJohn Marino _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1310*e4b17023SJohn Marino && __i2 <= _M_iend());
1311*e4b17023SJohn Marino return this->replace(__i1 - _M_ibegin(), __i2 - __i1, __s, __n);
1312*e4b17023SJohn Marino }
1313*e4b17023SJohn Marino
1314*e4b17023SJohn Marino /**
1315*e4b17023SJohn Marino * @brief Replace range of characters with C string.
1316*e4b17023SJohn Marino * @param __i1 Iterator referencing start of range to replace.
1317*e4b17023SJohn Marino * @param __i2 Iterator referencing end of range to replace.
1318*e4b17023SJohn Marino * @param __s C string value to insert.
1319*e4b17023SJohn Marino * @return Reference to this string.
1320*e4b17023SJohn Marino * @throw std::length_error If new length exceeds @c max_size().
1321*e4b17023SJohn Marino *
1322*e4b17023SJohn Marino * Removes the characters in the range [i1,i2). In place, the
1323*e4b17023SJohn Marino * characters of @a __s are inserted. If the length of result
1324*e4b17023SJohn Marino * exceeds max_size(), length_error is thrown. The value of
1325*e4b17023SJohn Marino * the string doesn't change if an error is thrown.
1326*e4b17023SJohn Marino */
1327*e4b17023SJohn Marino __versa_string&
1328*e4b17023SJohn Marino replace(iterator __i1, iterator __i2, const _CharT* __s)
1329*e4b17023SJohn Marino {
1330*e4b17023SJohn Marino __glibcxx_requires_string(__s);
1331*e4b17023SJohn Marino return this->replace(__i1, __i2, __s, traits_type::length(__s));
1332*e4b17023SJohn Marino }
1333*e4b17023SJohn Marino
1334*e4b17023SJohn Marino /**
1335*e4b17023SJohn Marino * @brief Replace range of characters with multiple characters
1336*e4b17023SJohn Marino * @param __i1 Iterator referencing start of range to replace.
1337*e4b17023SJohn Marino * @param __i2 Iterator referencing end of range to replace.
1338*e4b17023SJohn Marino * @param __n Number of characters to insert.
1339*e4b17023SJohn Marino * @param __c Character to insert.
1340*e4b17023SJohn Marino * @return Reference to this string.
1341*e4b17023SJohn Marino * @throw std::length_error If new length exceeds @c max_size().
1342*e4b17023SJohn Marino *
1343*e4b17023SJohn Marino * Removes the characters in the range [i1,i2). In place, @a
1344*e4b17023SJohn Marino * __n copies of @a __c are inserted. If the length of result
1345*e4b17023SJohn Marino * exceeds max_size(), length_error is thrown. The value of
1346*e4b17023SJohn Marino * the string doesn't change if an error is thrown.
1347*e4b17023SJohn Marino */
1348*e4b17023SJohn Marino __versa_string&
1349*e4b17023SJohn Marino replace(iterator __i1, iterator __i2, size_type __n, _CharT __c)
1350*e4b17023SJohn Marino {
1351*e4b17023SJohn Marino _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1352*e4b17023SJohn Marino && __i2 <= _M_iend());
1353*e4b17023SJohn Marino return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __c);
1354*e4b17023SJohn Marino }
1355*e4b17023SJohn Marino
1356*e4b17023SJohn Marino /**
1357*e4b17023SJohn Marino * @brief Replace range of characters with range.
1358*e4b17023SJohn Marino * @param __i1 Iterator referencing start of range to replace.
1359*e4b17023SJohn Marino * @param __i2 Iterator referencing end of range to replace.
1360*e4b17023SJohn Marino * @param __k1 Iterator referencing start of range to insert.
1361*e4b17023SJohn Marino * @param __k2 Iterator referencing end of range to insert.
1362*e4b17023SJohn Marino * @return Reference to this string.
1363*e4b17023SJohn Marino * @throw std::length_error If new length exceeds @c max_size().
1364*e4b17023SJohn Marino *
1365*e4b17023SJohn Marino * Removes the characters in the range [i1,i2). In place,
1366*e4b17023SJohn Marino * characters in the range [k1,k2) are inserted. If the length
1367*e4b17023SJohn Marino * of result exceeds max_size(), length_error is thrown. The
1368*e4b17023SJohn Marino * value of the string doesn't change if an error is thrown.
1369*e4b17023SJohn Marino */
1370*e4b17023SJohn Marino template<class _InputIterator>
1371*e4b17023SJohn Marino __versa_string&
1372*e4b17023SJohn Marino replace(iterator __i1, iterator __i2,
1373*e4b17023SJohn Marino _InputIterator __k1, _InputIterator __k2)
1374*e4b17023SJohn Marino {
1375*e4b17023SJohn Marino _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1376*e4b17023SJohn Marino && __i2 <= _M_iend());
1377*e4b17023SJohn Marino __glibcxx_requires_valid_range(__k1, __k2);
1378*e4b17023SJohn Marino typedef typename std::__is_integer<_InputIterator>::__type _Integral;
1379*e4b17023SJohn Marino return this->_M_replace_dispatch(__i1, __i2, __k1, __k2, _Integral());
1380*e4b17023SJohn Marino }
1381*e4b17023SJohn Marino
1382*e4b17023SJohn Marino // Specializations for the common case of pointer and iterator:
1383*e4b17023SJohn Marino // useful to avoid the overhead of temporary buffering in _M_replace.
1384*e4b17023SJohn Marino __versa_string&
1385*e4b17023SJohn Marino replace(iterator __i1, iterator __i2, _CharT* __k1, _CharT* __k2)
1386*e4b17023SJohn Marino {
1387*e4b17023SJohn Marino _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1388*e4b17023SJohn Marino && __i2 <= _M_iend());
1389*e4b17023SJohn Marino __glibcxx_requires_valid_range(__k1, __k2);
1390*e4b17023SJohn Marino return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
1391*e4b17023SJohn Marino __k1, __k2 - __k1);
1392*e4b17023SJohn Marino }
1393*e4b17023SJohn Marino
1394*e4b17023SJohn Marino __versa_string&
1395*e4b17023SJohn Marino replace(iterator __i1, iterator __i2,
1396*e4b17023SJohn Marino const _CharT* __k1, const _CharT* __k2)
1397*e4b17023SJohn Marino {
1398*e4b17023SJohn Marino _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1399*e4b17023SJohn Marino && __i2 <= _M_iend());
1400*e4b17023SJohn Marino __glibcxx_requires_valid_range(__k1, __k2);
1401*e4b17023SJohn Marino return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
1402*e4b17023SJohn Marino __k1, __k2 - __k1);
1403*e4b17023SJohn Marino }
1404*e4b17023SJohn Marino
1405*e4b17023SJohn Marino __versa_string&
1406*e4b17023SJohn Marino replace(iterator __i1, iterator __i2, iterator __k1, iterator __k2)
1407*e4b17023SJohn Marino {
1408*e4b17023SJohn Marino _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1409*e4b17023SJohn Marino && __i2 <= _M_iend());
1410*e4b17023SJohn Marino __glibcxx_requires_valid_range(__k1, __k2);
1411*e4b17023SJohn Marino return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
1412*e4b17023SJohn Marino __k1.base(), __k2 - __k1);
1413*e4b17023SJohn Marino }
1414*e4b17023SJohn Marino
1415*e4b17023SJohn Marino __versa_string&
1416*e4b17023SJohn Marino replace(iterator __i1, iterator __i2,
1417*e4b17023SJohn Marino const_iterator __k1, const_iterator __k2)
1418*e4b17023SJohn Marino {
1419*e4b17023SJohn Marino _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1420*e4b17023SJohn Marino && __i2 <= _M_iend());
1421*e4b17023SJohn Marino __glibcxx_requires_valid_range(__k1, __k2);
1422*e4b17023SJohn Marino return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
1423*e4b17023SJohn Marino __k1.base(), __k2 - __k1);
1424*e4b17023SJohn Marino }
1425*e4b17023SJohn Marino
1426*e4b17023SJohn Marino #ifdef __GXX_EXPERIMENTAL_CXX0X__
1427*e4b17023SJohn Marino /**
1428*e4b17023SJohn Marino * @brief Replace range of characters with initializer_list.
1429*e4b17023SJohn Marino * @param __i1 Iterator referencing start of range to replace.
1430*e4b17023SJohn Marino * @param __i2 Iterator referencing end of range to replace.
1431*e4b17023SJohn Marino * @param __l The initializer_list of characters to insert.
1432*e4b17023SJohn Marino * @return Reference to this string.
1433*e4b17023SJohn Marino * @throw std::length_error If new length exceeds @c max_size().
1434*e4b17023SJohn Marino *
1435*e4b17023SJohn Marino * Removes the characters in the range [i1,i2). In place,
1436*e4b17023SJohn Marino * characters in the range [k1,k2) are inserted. If the length
1437*e4b17023SJohn Marino * of result exceeds max_size(), length_error is thrown. The
1438*e4b17023SJohn Marino * value of the string doesn't change if an error is thrown.
1439*e4b17023SJohn Marino */
1440*e4b17023SJohn Marino __versa_string& replace(iterator __i1, iterator __i2,
1441*e4b17023SJohn Marino std::initializer_list<_CharT> __l)
1442*e4b17023SJohn Marino { return this->replace(__i1, __i2, __l.begin(), __l.end()); }
1443*e4b17023SJohn Marino #endif // __GXX_EXPERIMENTAL_CXX0X__
1444*e4b17023SJohn Marino
1445*e4b17023SJohn Marino private:
1446*e4b17023SJohn Marino template<class _Integer>
1447*e4b17023SJohn Marino __versa_string&
1448*e4b17023SJohn Marino _M_replace_dispatch(iterator __i1, iterator __i2, _Integer __n,
1449*e4b17023SJohn Marino _Integer __val, std::__true_type)
1450*e4b17023SJohn Marino { return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __val); }
1451*e4b17023SJohn Marino
1452*e4b17023SJohn Marino template<class _InputIterator>
1453*e4b17023SJohn Marino __versa_string&
1454*e4b17023SJohn Marino _M_replace_dispatch(iterator __i1, iterator __i2, _InputIterator __k1,
1455*e4b17023SJohn Marino _InputIterator __k2, std::__false_type);
1456*e4b17023SJohn Marino
1457*e4b17023SJohn Marino __versa_string&
1458*e4b17023SJohn Marino _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2,
1459*e4b17023SJohn Marino _CharT __c);
1460*e4b17023SJohn Marino
1461*e4b17023SJohn Marino __versa_string&
1462*e4b17023SJohn Marino _M_replace(size_type __pos, size_type __len1, const _CharT* __s,
1463*e4b17023SJohn Marino const size_type __len2);
1464*e4b17023SJohn Marino
1465*e4b17023SJohn Marino __versa_string&
1466*e4b17023SJohn Marino _M_append(const _CharT* __s, size_type __n);
1467*e4b17023SJohn Marino
1468*e4b17023SJohn Marino public:
1469*e4b17023SJohn Marino
1470*e4b17023SJohn Marino /**
1471*e4b17023SJohn Marino * @brief Copy substring into C string.
1472*e4b17023SJohn Marino * @param __s C string to copy value into.
1473*e4b17023SJohn Marino * @param __n Number of characters to copy.
1474*e4b17023SJohn Marino * @param __pos Index of first character to copy.
1475*e4b17023SJohn Marino * @return Number of characters actually copied
1476*e4b17023SJohn Marino * @throw std::out_of_range If pos > size().
1477*e4b17023SJohn Marino *
1478*e4b17023SJohn Marino * Copies up to @a __n characters starting at @a __pos into the
1479*e4b17023SJohn Marino * C string @a s. If @a __pos is greater than size(),
1480*e4b17023SJohn Marino * out_of_range is thrown.
1481*e4b17023SJohn Marino */
1482*e4b17023SJohn Marino size_type
1483*e4b17023SJohn Marino copy(_CharT* __s, size_type __n, size_type __pos = 0) const;
1484*e4b17023SJohn Marino
1485*e4b17023SJohn Marino /**
1486*e4b17023SJohn Marino * @brief Swap contents with another string.
1487*e4b17023SJohn Marino * @param __s String to swap with.
1488*e4b17023SJohn Marino *
1489*e4b17023SJohn Marino * Exchanges the contents of this string with that of @a __s in
1490*e4b17023SJohn Marino * constant time.
1491*e4b17023SJohn Marino */
1492*e4b17023SJohn Marino void
1493*e4b17023SJohn Marino swap(__versa_string& __s)
1494*e4b17023SJohn Marino { this->_M_swap(__s); }
1495*e4b17023SJohn Marino
1496*e4b17023SJohn Marino // String operations:
1497*e4b17023SJohn Marino /**
1498*e4b17023SJohn Marino * @brief Return const pointer to null-terminated contents.
1499*e4b17023SJohn Marino *
1500*e4b17023SJohn Marino * This is a handle to internal data. Do not modify or dire things may
1501*e4b17023SJohn Marino * happen.
1502*e4b17023SJohn Marino */
1503*e4b17023SJohn Marino const _CharT*
1504*e4b17023SJohn Marino c_str() const _GLIBCXX_NOEXCEPT
1505*e4b17023SJohn Marino { return this->_M_data(); }
1506*e4b17023SJohn Marino
1507*e4b17023SJohn Marino /**
1508*e4b17023SJohn Marino * @brief Return const pointer to contents.
1509*e4b17023SJohn Marino *
1510*e4b17023SJohn Marino * This is a handle to internal data. Do not modify or dire things may
1511*e4b17023SJohn Marino * happen.
1512*e4b17023SJohn Marino */
1513*e4b17023SJohn Marino const _CharT*
1514*e4b17023SJohn Marino data() const _GLIBCXX_NOEXCEPT
1515*e4b17023SJohn Marino { return this->_M_data(); }
1516*e4b17023SJohn Marino
1517*e4b17023SJohn Marino /**
1518*e4b17023SJohn Marino * @brief Return copy of allocator used to construct this string.
1519*e4b17023SJohn Marino */
1520*e4b17023SJohn Marino allocator_type
1521*e4b17023SJohn Marino get_allocator() const _GLIBCXX_NOEXCEPT
1522*e4b17023SJohn Marino { return allocator_type(this->_M_get_allocator()); }
1523*e4b17023SJohn Marino
1524*e4b17023SJohn Marino /**
1525*e4b17023SJohn Marino * @brief Find position of a C substring.
1526*e4b17023SJohn Marino * @param __s C string to locate.
1527*e4b17023SJohn Marino * @param __pos Index of character to search from.
1528*e4b17023SJohn Marino * @param __n Number of characters from @a __s to search for.
1529*e4b17023SJohn Marino * @return Index of start of first occurrence.
1530*e4b17023SJohn Marino *
1531*e4b17023SJohn Marino * Starting from @a __pos, searches forward for the first @a
1532*e4b17023SJohn Marino * __n characters in @a __s within this string. If found,
1533*e4b17023SJohn Marino * returns the index where it begins. If not found, returns
1534*e4b17023SJohn Marino * npos.
1535*e4b17023SJohn Marino */
1536*e4b17023SJohn Marino size_type
1537*e4b17023SJohn Marino find(const _CharT* __s, size_type __pos, size_type __n) const;
1538*e4b17023SJohn Marino
1539*e4b17023SJohn Marino /**
1540*e4b17023SJohn Marino * @brief Find position of a string.
1541*e4b17023SJohn Marino * @param __str String to locate.
1542*e4b17023SJohn Marino * @param __pos Index of character to search from (default 0).
1543*e4b17023SJohn Marino * @return Index of start of first occurrence.
1544*e4b17023SJohn Marino *
1545*e4b17023SJohn Marino * Starting from @a __pos, searches forward for value of @a
1546*e4b17023SJohn Marino * __str within this string. If found, returns the index where
1547*e4b17023SJohn Marino * it begins. If not found, returns npos.
1548*e4b17023SJohn Marino */
1549*e4b17023SJohn Marino size_type
1550*e4b17023SJohn Marino find(const __versa_string& __str, size_type __pos = 0) const
1551*e4b17023SJohn Marino _GLIBCXX_NOEXCEPT
1552*e4b17023SJohn Marino { return this->find(__str.data(), __pos, __str.size()); }
1553*e4b17023SJohn Marino
1554*e4b17023SJohn Marino /**
1555*e4b17023SJohn Marino * @brief Find position of a C string.
1556*e4b17023SJohn Marino * @param __s C string to locate.
1557*e4b17023SJohn Marino * @param __pos Index of character to search from (default 0).
1558*e4b17023SJohn Marino * @return Index of start of first occurrence.
1559*e4b17023SJohn Marino *
1560*e4b17023SJohn Marino * Starting from @a __pos, searches forward for the value of @a
1561*e4b17023SJohn Marino * __s within this string. If found, returns the index where
1562*e4b17023SJohn Marino * it begins. If not found, returns npos.
1563*e4b17023SJohn Marino */
1564*e4b17023SJohn Marino size_type
1565*e4b17023SJohn Marino find(const _CharT* __s, size_type __pos = 0) const
1566*e4b17023SJohn Marino {
1567*e4b17023SJohn Marino __glibcxx_requires_string(__s);
1568*e4b17023SJohn Marino return this->find(__s, __pos, traits_type::length(__s));
1569*e4b17023SJohn Marino }
1570*e4b17023SJohn Marino
1571*e4b17023SJohn Marino /**
1572*e4b17023SJohn Marino * @brief Find position of a character.
1573*e4b17023SJohn Marino * @param __c Character to locate.
1574*e4b17023SJohn Marino * @param __pos Index of character to search from (default 0).
1575*e4b17023SJohn Marino * @return Index of first occurrence.
1576*e4b17023SJohn Marino *
1577*e4b17023SJohn Marino * Starting from @a __pos, searches forward for @a __c within
1578*e4b17023SJohn Marino * this string. If found, returns the index where it was
1579*e4b17023SJohn Marino * found. If not found, returns npos.
1580*e4b17023SJohn Marino */
1581*e4b17023SJohn Marino size_type
1582*e4b17023SJohn Marino find(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT;
1583*e4b17023SJohn Marino
1584*e4b17023SJohn Marino /**
1585*e4b17023SJohn Marino * @brief Find last position of a string.
1586*e4b17023SJohn Marino * @param __str String to locate.
1587*e4b17023SJohn Marino * @param __pos Index of character to search back from (default end).
1588*e4b17023SJohn Marino * @return Index of start of last occurrence.
1589*e4b17023SJohn Marino *
1590*e4b17023SJohn Marino * Starting from @a __pos, searches backward for value of @a
1591*e4b17023SJohn Marino * __str within this string. If found, returns the index where
1592*e4b17023SJohn Marino * it begins. If not found, returns npos.
1593*e4b17023SJohn Marino */
1594*e4b17023SJohn Marino size_type
1595*e4b17023SJohn Marino rfind(const __versa_string& __str, size_type __pos = npos) const
1596*e4b17023SJohn Marino _GLIBCXX_NOEXCEPT
1597*e4b17023SJohn Marino { return this->rfind(__str.data(), __pos, __str.size()); }
1598*e4b17023SJohn Marino
1599*e4b17023SJohn Marino /**
1600*e4b17023SJohn Marino * @brief Find last position of a C substring.
1601*e4b17023SJohn Marino * @param __s C string to locate.
1602*e4b17023SJohn Marino * @param __pos Index of character to search back from.
1603*e4b17023SJohn Marino * @param __n Number of characters from s to search for.
1604*e4b17023SJohn Marino * @return Index of start of last occurrence.
1605*e4b17023SJohn Marino *
1606*e4b17023SJohn Marino * Starting from @a __pos, searches backward for the first @a
1607*e4b17023SJohn Marino * __n characters in @a __s within this string. If found,
1608*e4b17023SJohn Marino * returns the index where it begins. If not found, returns
1609*e4b17023SJohn Marino * npos.
1610*e4b17023SJohn Marino */
1611*e4b17023SJohn Marino size_type
1612*e4b17023SJohn Marino rfind(const _CharT* __s, size_type __pos, size_type __n) const;
1613*e4b17023SJohn Marino
1614*e4b17023SJohn Marino /**
1615*e4b17023SJohn Marino * @brief Find last position of a C string.
1616*e4b17023SJohn Marino * @param __s C string to locate.
1617*e4b17023SJohn Marino * @param __pos Index of character to start search at (default end).
1618*e4b17023SJohn Marino * @return Index of start of last occurrence.
1619*e4b17023SJohn Marino *
1620*e4b17023SJohn Marino * Starting from @a __pos, searches backward for the value of
1621*e4b17023SJohn Marino * @a __s within this string. If found, returns the index
1622*e4b17023SJohn Marino * where it begins. If not found, returns npos.
1623*e4b17023SJohn Marino */
1624*e4b17023SJohn Marino size_type
1625*e4b17023SJohn Marino rfind(const _CharT* __s, size_type __pos = npos) const
1626*e4b17023SJohn Marino {
1627*e4b17023SJohn Marino __glibcxx_requires_string(__s);
1628*e4b17023SJohn Marino return this->rfind(__s, __pos, traits_type::length(__s));
1629*e4b17023SJohn Marino }
1630*e4b17023SJohn Marino
1631*e4b17023SJohn Marino /**
1632*e4b17023SJohn Marino * @brief Find last position of a character.
1633*e4b17023SJohn Marino * @param __c Character to locate.
1634*e4b17023SJohn Marino * @param __pos Index of character to search back from (default end).
1635*e4b17023SJohn Marino * @return Index of last occurrence.
1636*e4b17023SJohn Marino *
1637*e4b17023SJohn Marino * Starting from @a __pos, searches backward for @a __c within
1638*e4b17023SJohn Marino * this string. If found, returns the index where it was
1639*e4b17023SJohn Marino * found. If not found, returns npos.
1640*e4b17023SJohn Marino */
1641*e4b17023SJohn Marino size_type
1642*e4b17023SJohn Marino rfind(_CharT __c, size_type __pos = npos) const _GLIBCXX_NOEXCEPT;
1643*e4b17023SJohn Marino
1644*e4b17023SJohn Marino /**
1645*e4b17023SJohn Marino * @brief Find position of a character of string.
1646*e4b17023SJohn Marino * @param __str String containing characters to locate.
1647*e4b17023SJohn Marino * @param __pos Index of character to search from (default 0).
1648*e4b17023SJohn Marino * @return Index of first occurrence.
1649*e4b17023SJohn Marino *
1650*e4b17023SJohn Marino * Starting from @a __pos, searches forward for one of the characters of
1651*e4b17023SJohn Marino * @a __str within this string. If found, returns the index where it was
1652*e4b17023SJohn Marino * found. If not found, returns npos.
1653*e4b17023SJohn Marino */
1654*e4b17023SJohn Marino size_type
1655*e4b17023SJohn Marino find_first_of(const __versa_string& __str, size_type __pos = 0) const
1656*e4b17023SJohn Marino _GLIBCXX_NOEXCEPT
1657*e4b17023SJohn Marino { return this->find_first_of(__str.data(), __pos, __str.size()); }
1658*e4b17023SJohn Marino
1659*e4b17023SJohn Marino /**
1660*e4b17023SJohn Marino * @brief Find position of a character of C substring.
1661*e4b17023SJohn Marino * @param __s String containing characters to locate.
1662*e4b17023SJohn Marino * @param __pos Index of character to search from.
1663*e4b17023SJohn Marino * @param __n Number of characters from s to search for.
1664*e4b17023SJohn Marino * @return Index of first occurrence.
1665*e4b17023SJohn Marino *
1666*e4b17023SJohn Marino * Starting from @a __pos, searches forward for one of the
1667*e4b17023SJohn Marino * first @a __n characters of @a __s within this string. If
1668*e4b17023SJohn Marino * found, returns the index where it was found. If not found,
1669*e4b17023SJohn Marino * returns npos.
1670*e4b17023SJohn Marino */
1671*e4b17023SJohn Marino size_type
1672*e4b17023SJohn Marino find_first_of(const _CharT* __s, size_type __pos, size_type __n) const;
1673*e4b17023SJohn Marino
1674*e4b17023SJohn Marino /**
1675*e4b17023SJohn Marino * @brief Find position of a character of C string.
1676*e4b17023SJohn Marino * @param __s String containing characters to locate.
1677*e4b17023SJohn Marino * @param __pos Index of character to search from (default 0).
1678*e4b17023SJohn Marino * @return Index of first occurrence.
1679*e4b17023SJohn Marino *
1680*e4b17023SJohn Marino * Starting from @a __pos, searches forward for one of the
1681*e4b17023SJohn Marino * characters of @a __s within this string. If found, returns
1682*e4b17023SJohn Marino * the index where it was found. If not found, returns npos.
1683*e4b17023SJohn Marino */
1684*e4b17023SJohn Marino size_type
1685*e4b17023SJohn Marino find_first_of(const _CharT* __s, size_type __pos = 0) const
1686*e4b17023SJohn Marino {
1687*e4b17023SJohn Marino __glibcxx_requires_string(__s);
1688*e4b17023SJohn Marino return this->find_first_of(__s, __pos, traits_type::length(__s));
1689*e4b17023SJohn Marino }
1690*e4b17023SJohn Marino
1691*e4b17023SJohn Marino /**
1692*e4b17023SJohn Marino * @brief Find position of a character.
1693*e4b17023SJohn Marino * @param __c Character to locate.
1694*e4b17023SJohn Marino * @param __pos Index of character to search from (default 0).
1695*e4b17023SJohn Marino * @return Index of first occurrence.
1696*e4b17023SJohn Marino *
1697*e4b17023SJohn Marino * Starting from @a __pos, searches forward for the character
1698*e4b17023SJohn Marino * @a __c within this string. If found, returns the index
1699*e4b17023SJohn Marino * where it was found. If not found, returns npos.
1700*e4b17023SJohn Marino *
1701*e4b17023SJohn Marino * Note: equivalent to find(c, pos).
1702*e4b17023SJohn Marino */
1703*e4b17023SJohn Marino size_type
1704*e4b17023SJohn Marino find_first_of(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT
1705*e4b17023SJohn Marino { return this->find(__c, __pos); }
1706*e4b17023SJohn Marino
1707*e4b17023SJohn Marino /**
1708*e4b17023SJohn Marino * @brief Find last position of a character of string.
1709*e4b17023SJohn Marino * @param __str String containing characters to locate.
1710*e4b17023SJohn Marino * @param __pos Index of character to search back from (default end).
1711*e4b17023SJohn Marino * @return Index of last occurrence.
1712*e4b17023SJohn Marino *
1713*e4b17023SJohn Marino * Starting from @a __pos, searches backward for one of the
1714*e4b17023SJohn Marino * characters of @a __str within this string. If found,
1715*e4b17023SJohn Marino * returns the index where it was found. If not found, returns
1716*e4b17023SJohn Marino * npos.
1717*e4b17023SJohn Marino */
1718*e4b17023SJohn Marino size_type
1719*e4b17023SJohn Marino find_last_of(const __versa_string& __str, size_type __pos = npos) const
1720*e4b17023SJohn Marino _GLIBCXX_NOEXCEPT
1721*e4b17023SJohn Marino { return this->find_last_of(__str.data(), __pos, __str.size()); }
1722*e4b17023SJohn Marino
1723*e4b17023SJohn Marino /**
1724*e4b17023SJohn Marino * @brief Find last position of a character of C substring.
1725*e4b17023SJohn Marino * @param __s C string containing characters to locate.
1726*e4b17023SJohn Marino * @param __pos Index of character to search back from.
1727*e4b17023SJohn Marino * @param __n Number of characters from s to search for.
1728*e4b17023SJohn Marino * @return Index of last occurrence.
1729*e4b17023SJohn Marino *
1730*e4b17023SJohn Marino * Starting from @a __pos, searches backward for one of the
1731*e4b17023SJohn Marino * first @a __n characters of @a __s within this string. If
1732*e4b17023SJohn Marino * found, returns the index where it was found. If not found,
1733*e4b17023SJohn Marino * returns npos.
1734*e4b17023SJohn Marino */
1735*e4b17023SJohn Marino size_type
1736*e4b17023SJohn Marino find_last_of(const _CharT* __s, size_type __pos, size_type __n) const;
1737*e4b17023SJohn Marino
1738*e4b17023SJohn Marino /**
1739*e4b17023SJohn Marino * @brief Find last position of a character of C string.
1740*e4b17023SJohn Marino * @param __s C string containing characters to locate.
1741*e4b17023SJohn Marino * @param __pos Index of character to search back from (default end).
1742*e4b17023SJohn Marino * @return Index of last occurrence.
1743*e4b17023SJohn Marino *
1744*e4b17023SJohn Marino * Starting from @a __pos, searches backward for one of the
1745*e4b17023SJohn Marino * characters of @a __s within this string. If found, returns
1746*e4b17023SJohn Marino * the index where it was found. If not found, returns npos.
1747*e4b17023SJohn Marino */
1748*e4b17023SJohn Marino size_type
1749*e4b17023SJohn Marino find_last_of(const _CharT* __s, size_type __pos = npos) const
1750*e4b17023SJohn Marino {
1751*e4b17023SJohn Marino __glibcxx_requires_string(__s);
1752*e4b17023SJohn Marino return this->find_last_of(__s, __pos, traits_type::length(__s));
1753*e4b17023SJohn Marino }
1754*e4b17023SJohn Marino
1755*e4b17023SJohn Marino /**
1756*e4b17023SJohn Marino * @brief Find last position of a character.
1757*e4b17023SJohn Marino * @param __c Character to locate.
1758*e4b17023SJohn Marino * @param __pos Index of character to search back from (default end).
1759*e4b17023SJohn Marino * @return Index of last occurrence.
1760*e4b17023SJohn Marino *
1761*e4b17023SJohn Marino * Starting from @a __pos, searches backward for @a __c within
1762*e4b17023SJohn Marino * this string. If found, returns the index where it was
1763*e4b17023SJohn Marino * found. If not found, returns npos.
1764*e4b17023SJohn Marino *
1765*e4b17023SJohn Marino * Note: equivalent to rfind(c, pos).
1766*e4b17023SJohn Marino */
1767*e4b17023SJohn Marino size_type
1768*e4b17023SJohn Marino find_last_of(_CharT __c, size_type __pos = npos) const _GLIBCXX_NOEXCEPT
1769*e4b17023SJohn Marino { return this->rfind(__c, __pos); }
1770*e4b17023SJohn Marino
1771*e4b17023SJohn Marino /**
1772*e4b17023SJohn Marino * @brief Find position of a character not in string.
1773*e4b17023SJohn Marino * @param __str String containing characters to avoid.
1774*e4b17023SJohn Marino * @param __pos Index of character to search from (default 0).
1775*e4b17023SJohn Marino * @return Index of first occurrence.
1776*e4b17023SJohn Marino *
1777*e4b17023SJohn Marino * Starting from @a __pos, searches forward for a character not
1778*e4b17023SJohn Marino * contained in @a __str within this string. If found, returns
1779*e4b17023SJohn Marino * the index where it was found. If not found, returns npos.
1780*e4b17023SJohn Marino */
1781*e4b17023SJohn Marino size_type
1782*e4b17023SJohn Marino find_first_not_of(const __versa_string& __str, size_type __pos = 0) const
1783*e4b17023SJohn Marino _GLIBCXX_NOEXCEPT
1784*e4b17023SJohn Marino { return this->find_first_not_of(__str.data(), __pos, __str.size()); }
1785*e4b17023SJohn Marino
1786*e4b17023SJohn Marino /**
1787*e4b17023SJohn Marino * @brief Find position of a character not in C substring.
1788*e4b17023SJohn Marino * @param __s C string containing characters to avoid.
1789*e4b17023SJohn Marino * @param __pos Index of character to search from.
1790*e4b17023SJohn Marino * @param __n Number of characters from s to consider.
1791*e4b17023SJohn Marino * @return Index of first occurrence.
1792*e4b17023SJohn Marino *
1793*e4b17023SJohn Marino * Starting from @a __pos, searches forward for a character not
1794*e4b17023SJohn Marino * contained in the first @a __n characters of @a __s within
1795*e4b17023SJohn Marino * this string. If found, returns the index where it was
1796*e4b17023SJohn Marino * found. If not found, returns npos.
1797*e4b17023SJohn Marino */
1798*e4b17023SJohn Marino size_type
1799*e4b17023SJohn Marino find_first_not_of(const _CharT* __s, size_type __pos,
1800*e4b17023SJohn Marino size_type __n) const;
1801*e4b17023SJohn Marino
1802*e4b17023SJohn Marino /**
1803*e4b17023SJohn Marino * @brief Find position of a character not in C string.
1804*e4b17023SJohn Marino * @param __s C string containing characters to avoid.
1805*e4b17023SJohn Marino * @param __pos Index of character to search from (default 0).
1806*e4b17023SJohn Marino * @return Index of first occurrence.
1807*e4b17023SJohn Marino *
1808*e4b17023SJohn Marino * Starting from @a __pos, searches forward for a character not
1809*e4b17023SJohn Marino * contained in @a __s within this string. If found, returns
1810*e4b17023SJohn Marino * the index where it was found. If not found, returns npos.
1811*e4b17023SJohn Marino */
1812*e4b17023SJohn Marino size_type
1813*e4b17023SJohn Marino find_first_not_of(const _CharT* __s, size_type __pos = 0) const
1814*e4b17023SJohn Marino {
1815*e4b17023SJohn Marino __glibcxx_requires_string(__s);
1816*e4b17023SJohn Marino return this->find_first_not_of(__s, __pos, traits_type::length(__s));
1817*e4b17023SJohn Marino }
1818*e4b17023SJohn Marino
1819*e4b17023SJohn Marino /**
1820*e4b17023SJohn Marino * @brief Find position of a different character.
1821*e4b17023SJohn Marino * @param __c Character to avoid.
1822*e4b17023SJohn Marino * @param __pos Index of character to search from (default 0).
1823*e4b17023SJohn Marino * @return Index of first occurrence.
1824*e4b17023SJohn Marino *
1825*e4b17023SJohn Marino * Starting from @a __pos, searches forward for a character
1826*e4b17023SJohn Marino * other than @a __c within this string. If found, returns the
1827*e4b17023SJohn Marino * index where it was found. If not found, returns npos.
1828*e4b17023SJohn Marino */
1829*e4b17023SJohn Marino size_type
1830*e4b17023SJohn Marino find_first_not_of(_CharT __c, size_type __pos = 0) const
1831*e4b17023SJohn Marino _GLIBCXX_NOEXCEPT;
1832*e4b17023SJohn Marino
1833*e4b17023SJohn Marino /**
1834*e4b17023SJohn Marino * @brief Find last position of a character not in string.
1835*e4b17023SJohn Marino * @param __str String containing characters to avoid.
1836*e4b17023SJohn Marino * @param __pos Index of character to search back from (default end).
1837*e4b17023SJohn Marino * @return Index of last occurrence.
1838*e4b17023SJohn Marino *
1839*e4b17023SJohn Marino * Starting from @a __pos, searches backward for a character
1840*e4b17023SJohn Marino * not contained in @a __str within this string. If found,
1841*e4b17023SJohn Marino * returns the index where it was found. If not found, returns
1842*e4b17023SJohn Marino * npos.
1843*e4b17023SJohn Marino */
1844*e4b17023SJohn Marino size_type
1845*e4b17023SJohn Marino find_last_not_of(const __versa_string& __str,
1846*e4b17023SJohn Marino size_type __pos = npos) const _GLIBCXX_NOEXCEPT
1847*e4b17023SJohn Marino { return this->find_last_not_of(__str.data(), __pos, __str.size()); }
1848*e4b17023SJohn Marino
1849*e4b17023SJohn Marino /**
1850*e4b17023SJohn Marino * @brief Find last position of a character not in C substring.
1851*e4b17023SJohn Marino * @param __s C string containing characters to avoid.
1852*e4b17023SJohn Marino * @param __pos Index of character to search back from.
1853*e4b17023SJohn Marino * @param __n Number of characters from s to consider.
1854*e4b17023SJohn Marino * @return Index of last occurrence.
1855*e4b17023SJohn Marino *
1856*e4b17023SJohn Marino * Starting from @a __pos, searches backward for a character
1857*e4b17023SJohn Marino * not contained in the first @a __n characters of @a __s
1858*e4b17023SJohn Marino * within this string. If found, returns the index where it
1859*e4b17023SJohn Marino * was found. If not found, returns npos.
1860*e4b17023SJohn Marino */
1861*e4b17023SJohn Marino size_type
1862*e4b17023SJohn Marino find_last_not_of(const _CharT* __s, size_type __pos,
1863*e4b17023SJohn Marino size_type __n) const;
1864*e4b17023SJohn Marino /**
1865*e4b17023SJohn Marino * @brief Find last position of a character not in C string.
1866*e4b17023SJohn Marino * @param __s C string containing characters to avoid.
1867*e4b17023SJohn Marino * @param __pos Index of character to search back from (default end).
1868*e4b17023SJohn Marino * @return Index of last occurrence.
1869*e4b17023SJohn Marino *
1870*e4b17023SJohn Marino * Starting from @a __pos, searches backward for a character
1871*e4b17023SJohn Marino * not contained in @a __s within this string. If found,
1872*e4b17023SJohn Marino * returns the index where it was found. If not found, returns
1873*e4b17023SJohn Marino * npos.
1874*e4b17023SJohn Marino */
1875*e4b17023SJohn Marino size_type
1876*e4b17023SJohn Marino find_last_not_of(const _CharT* __s, size_type __pos = npos) const
1877*e4b17023SJohn Marino {
1878*e4b17023SJohn Marino __glibcxx_requires_string(__s);
1879*e4b17023SJohn Marino return this->find_last_not_of(__s, __pos, traits_type::length(__s));
1880*e4b17023SJohn Marino }
1881*e4b17023SJohn Marino
1882*e4b17023SJohn Marino /**
1883*e4b17023SJohn Marino * @brief Find last position of a different character.
1884*e4b17023SJohn Marino * @param __c Character to avoid.
1885*e4b17023SJohn Marino * @param __pos Index of character to search back from (default end).
1886*e4b17023SJohn Marino * @return Index of last occurrence.
1887*e4b17023SJohn Marino *
1888*e4b17023SJohn Marino * Starting from @a __pos, searches backward for a character
1889*e4b17023SJohn Marino * other than @a __c within this string. If found, returns the
1890*e4b17023SJohn Marino * index where it was found. If not found, returns npos.
1891*e4b17023SJohn Marino */
1892*e4b17023SJohn Marino size_type
1893*e4b17023SJohn Marino find_last_not_of(_CharT __c, size_type __pos = npos) const
1894*e4b17023SJohn Marino _GLIBCXX_NOEXCEPT;
1895*e4b17023SJohn Marino
1896*e4b17023SJohn Marino /**
1897*e4b17023SJohn Marino * @brief Get a substring.
1898*e4b17023SJohn Marino * @param __pos Index of first character (default 0).
1899*e4b17023SJohn Marino * @param __n Number of characters in substring (default remainder).
1900*e4b17023SJohn Marino * @return The new string.
1901*e4b17023SJohn Marino * @throw std::out_of_range If pos > size().
1902*e4b17023SJohn Marino *
1903*e4b17023SJohn Marino * Construct and return a new string using the @a __n
1904*e4b17023SJohn Marino * characters starting at @a __pos. If the string is too
1905*e4b17023SJohn Marino * short, use the remainder of the characters. If @a __pos is
1906*e4b17023SJohn Marino * beyond the end of the string, out_of_range is thrown.
1907*e4b17023SJohn Marino */
1908*e4b17023SJohn Marino __versa_string
1909*e4b17023SJohn Marino substr(size_type __pos = 0, size_type __n = npos) const
1910*e4b17023SJohn Marino {
1911*e4b17023SJohn Marino return __versa_string(*this, _M_check(__pos, "__versa_string::substr"),
1912*e4b17023SJohn Marino __n);
1913*e4b17023SJohn Marino }
1914*e4b17023SJohn Marino
1915*e4b17023SJohn Marino /**
1916*e4b17023SJohn Marino * @brief Compare to a string.
1917*e4b17023SJohn Marino * @param __str String to compare against.
1918*e4b17023SJohn Marino * @return Integer < 0, 0, or > 0.
1919*e4b17023SJohn Marino *
1920*e4b17023SJohn Marino * Returns an integer < 0 if this string is ordered before @a
1921*e4b17023SJohn Marino * __str, 0 if their values are equivalent, or > 0 if this
1922*e4b17023SJohn Marino * string is ordered after @a __str. Determines the effective
1923*e4b17023SJohn Marino * length rlen of the strings to compare as the smallest of
1924*e4b17023SJohn Marino * size() and str.size(). The function then compares the two
1925*e4b17023SJohn Marino * strings by calling traits::compare(data(), str.data(),rlen).
1926*e4b17023SJohn Marino * If the result of the comparison is nonzero returns it,
1927*e4b17023SJohn Marino * otherwise the shorter one is ordered first.
1928*e4b17023SJohn Marino */
1929*e4b17023SJohn Marino int
1930*e4b17023SJohn Marino compare(const __versa_string& __str) const
1931*e4b17023SJohn Marino {
1932*e4b17023SJohn Marino if (this->_M_compare(__str))
1933*e4b17023SJohn Marino return 0;
1934*e4b17023SJohn Marino
1935*e4b17023SJohn Marino const size_type __size = this->size();
1936*e4b17023SJohn Marino const size_type __osize = __str.size();
1937*e4b17023SJohn Marino const size_type __len = std::min(__size, __osize);
1938*e4b17023SJohn Marino
1939*e4b17023SJohn Marino int __r = traits_type::compare(this->_M_data(), __str.data(), __len);
1940*e4b17023SJohn Marino if (!__r)
1941*e4b17023SJohn Marino __r = this->_S_compare(__size, __osize);
1942*e4b17023SJohn Marino return __r;
1943*e4b17023SJohn Marino }
1944*e4b17023SJohn Marino
1945*e4b17023SJohn Marino /**
1946*e4b17023SJohn Marino * @brief Compare substring to a string.
1947*e4b17023SJohn Marino * @param __pos Index of first character of substring.
1948*e4b17023SJohn Marino * @param __n Number of characters in substring.
1949*e4b17023SJohn Marino * @param __str String to compare against.
1950*e4b17023SJohn Marino * @return Integer < 0, 0, or > 0.
1951*e4b17023SJohn Marino *
1952*e4b17023SJohn Marino * Form the substring of this string from the @a __n characters
1953*e4b17023SJohn Marino * starting at @a __pos. Returns an integer < 0 if the
1954*e4b17023SJohn Marino * substring is ordered before @a __str, 0 if their values are
1955*e4b17023SJohn Marino * equivalent, or > 0 if the substring is ordered after @a
1956*e4b17023SJohn Marino * __str. Determines the effective length rlen of the strings
1957*e4b17023SJohn Marino * to compare as the smallest of the length of the substring
1958*e4b17023SJohn Marino * and @a __str.size(). The function then compares the two
1959*e4b17023SJohn Marino * strings by calling
1960*e4b17023SJohn Marino * traits::compare(substring.data(),str.data(),rlen). If the
1961*e4b17023SJohn Marino * result of the comparison is nonzero returns it, otherwise
1962*e4b17023SJohn Marino * the shorter one is ordered first.
1963*e4b17023SJohn Marino */
1964*e4b17023SJohn Marino int
1965*e4b17023SJohn Marino compare(size_type __pos, size_type __n,
1966*e4b17023SJohn Marino const __versa_string& __str) const;
1967*e4b17023SJohn Marino
1968*e4b17023SJohn Marino /**
1969*e4b17023SJohn Marino * @brief Compare substring to a substring.
1970*e4b17023SJohn Marino * @param __pos1 Index of first character of substring.
1971*e4b17023SJohn Marino * @param __n1 Number of characters in substring.
1972*e4b17023SJohn Marino * @param __str String to compare against.
1973*e4b17023SJohn Marino * @param __pos2 Index of first character of substring of str.
1974*e4b17023SJohn Marino * @param __n2 Number of characters in substring of str.
1975*e4b17023SJohn Marino * @return Integer < 0, 0, or > 0.
1976*e4b17023SJohn Marino *
1977*e4b17023SJohn Marino * Form the substring of this string from the @a __n1
1978*e4b17023SJohn Marino * characters starting at @a __pos1. Form the substring of @a
1979*e4b17023SJohn Marino * __str from the @a __n2 characters starting at @a __pos2.
1980*e4b17023SJohn Marino * Returns an integer < 0 if this substring is ordered before
1981*e4b17023SJohn Marino * the substring of @a __str, 0 if their values are equivalent,
1982*e4b17023SJohn Marino * or > 0 if this substring is ordered after the substring of
1983*e4b17023SJohn Marino * @a __str. Determines the effective length rlen of the
1984*e4b17023SJohn Marino * strings to compare as the smallest of the lengths of the
1985*e4b17023SJohn Marino * substrings. The function then compares the two strings by
1986*e4b17023SJohn Marino * calling
1987*e4b17023SJohn Marino * traits::compare(substring.data(),str.substr(pos2,n2).data(),rlen).
1988*e4b17023SJohn Marino * If the result of the comparison is nonzero returns it,
1989*e4b17023SJohn Marino * otherwise the shorter one is ordered first.
1990*e4b17023SJohn Marino */
1991*e4b17023SJohn Marino int
1992*e4b17023SJohn Marino compare(size_type __pos1, size_type __n1, const __versa_string& __str,
1993*e4b17023SJohn Marino size_type __pos2, size_type __n2) const;
1994*e4b17023SJohn Marino
1995*e4b17023SJohn Marino /**
1996*e4b17023SJohn Marino * @brief Compare to a C string.
1997*e4b17023SJohn Marino * @param __s C string to compare against.
1998*e4b17023SJohn Marino * @return Integer < 0, 0, or > 0.
1999*e4b17023SJohn Marino *
2000*e4b17023SJohn Marino * Returns an integer < 0 if this string is ordered before @a
2001*e4b17023SJohn Marino * __s, 0 if their values are equivalent, or > 0 if this string
2002*e4b17023SJohn Marino * is ordered after @a __s. Determines the effective length
2003*e4b17023SJohn Marino * rlen of the strings to compare as the smallest of size() and
2004*e4b17023SJohn Marino * the length of a string constructed from @a __s. The
2005*e4b17023SJohn Marino * function then compares the two strings by calling
2006*e4b17023SJohn Marino * traits::compare(data(),s,rlen). If the result of the
2007*e4b17023SJohn Marino * comparison is nonzero returns it, otherwise the shorter one
2008*e4b17023SJohn Marino * is ordered first.
2009*e4b17023SJohn Marino */
2010*e4b17023SJohn Marino int
2011*e4b17023SJohn Marino compare(const _CharT* __s) const;
2012*e4b17023SJohn Marino
2013*e4b17023SJohn Marino // _GLIBCXX_RESOLVE_LIB_DEFECTS
2014*e4b17023SJohn Marino // 5 String::compare specification questionable
2015*e4b17023SJohn Marino /**
2016*e4b17023SJohn Marino * @brief Compare substring to a C string.
2017*e4b17023SJohn Marino * @param __pos Index of first character of substring.
2018*e4b17023SJohn Marino * @param __n1 Number of characters in substring.
2019*e4b17023SJohn Marino * @param __s C string to compare against.
2020*e4b17023SJohn Marino * @return Integer < 0, 0, or > 0.
2021*e4b17023SJohn Marino *
2022*e4b17023SJohn Marino * Form the substring of this string from the @a __n1
2023*e4b17023SJohn Marino * characters starting at @a __pos. Returns an integer < 0 if
2024*e4b17023SJohn Marino * the substring is ordered before @a __s, 0 if their values
2025*e4b17023SJohn Marino * are equivalent, or > 0 if the substring is ordered after @a
2026*e4b17023SJohn Marino * __s. Determines the effective length rlen of the strings to
2027*e4b17023SJohn Marino * compare as the smallest of the length of the substring and
2028*e4b17023SJohn Marino * the length of a string constructed from @a __s. The
2029*e4b17023SJohn Marino * function then compares the two string by calling
2030*e4b17023SJohn Marino * traits::compare(substring.data(),s,rlen). If the result of
2031*e4b17023SJohn Marino * the comparison is nonzero returns it, otherwise the shorter
2032*e4b17023SJohn Marino * one is ordered first.
2033*e4b17023SJohn Marino */
2034*e4b17023SJohn Marino int
2035*e4b17023SJohn Marino compare(size_type __pos, size_type __n1, const _CharT* __s) const;
2036*e4b17023SJohn Marino
2037*e4b17023SJohn Marino /**
2038*e4b17023SJohn Marino * @brief Compare substring against a character array.
2039*e4b17023SJohn Marino * @param __pos Index of first character of substring.
2040*e4b17023SJohn Marino * @param __n1 Number of characters in substring.
2041*e4b17023SJohn Marino * @param __s character array to compare against.
2042*e4b17023SJohn Marino * @param __n2 Number of characters of s.
2043*e4b17023SJohn Marino * @return Integer < 0, 0, or > 0.
2044*e4b17023SJohn Marino *
2045*e4b17023SJohn Marino * Form the substring of this string from the @a __n1
2046*e4b17023SJohn Marino * characters starting at @a __pos. Form a string from the
2047*e4b17023SJohn Marino * first @a __n2 characters of @a __s. Returns an integer < 0
2048*e4b17023SJohn Marino * if this substring is ordered before the string from @a __s,
2049*e4b17023SJohn Marino * 0 if their values are equivalent, or > 0 if this substring
2050*e4b17023SJohn Marino * is ordered after the string from @a __s. Determines the
2051*e4b17023SJohn Marino * effective length rlen of the strings to compare as the
2052*e4b17023SJohn Marino * smallest of the length of the substring and @a __n2. The
2053*e4b17023SJohn Marino * function then compares the two strings by calling
2054*e4b17023SJohn Marino * traits::compare(substring.data(),__s,rlen). If the result of
2055*e4b17023SJohn Marino * the comparison is nonzero returns it, otherwise the shorter
2056*e4b17023SJohn Marino * one is ordered first.
2057*e4b17023SJohn Marino *
2058*e4b17023SJohn Marino * NB: __s must have at least n2 characters, <em>\\0</em> has no special
2059*e4b17023SJohn Marino * meaning.
2060*e4b17023SJohn Marino */
2061*e4b17023SJohn Marino int
2062*e4b17023SJohn Marino compare(size_type __pos, size_type __n1, const _CharT* __s,
2063*e4b17023SJohn Marino size_type __n2) const;
2064*e4b17023SJohn Marino };
2065*e4b17023SJohn Marino
2066*e4b17023SJohn Marino // operator+
2067*e4b17023SJohn Marino /**
2068*e4b17023SJohn Marino * @brief Concatenate two strings.
2069*e4b17023SJohn Marino * @param __lhs First string.
2070*e4b17023SJohn Marino * @param __rhs Last string.
2071*e4b17023SJohn Marino * @return New string with value of @a __lhs followed by @a __rhs.
2072*e4b17023SJohn Marino */
2073*e4b17023SJohn Marino template<typename _CharT, typename _Traits, typename _Alloc,
2074*e4b17023SJohn Marino template <typename, typename, typename> class _Base>
2075*e4b17023SJohn Marino __versa_string<_CharT, _Traits, _Alloc, _Base>
2076*e4b17023SJohn Marino operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2077*e4b17023SJohn Marino const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs);
2078*e4b17023SJohn Marino
2079*e4b17023SJohn Marino /**
2080*e4b17023SJohn Marino * @brief Concatenate C string and string.
2081*e4b17023SJohn Marino * @param __lhs First string.
2082*e4b17023SJohn Marino * @param __rhs Last string.
2083*e4b17023SJohn Marino * @return New string with value of @a __lhs followed by @a __rhs.
2084*e4b17023SJohn Marino */
2085*e4b17023SJohn Marino template<typename _CharT, typename _Traits, typename _Alloc,
2086*e4b17023SJohn Marino template <typename, typename, typename> class _Base>
2087*e4b17023SJohn Marino __versa_string<_CharT, _Traits, _Alloc, _Base>
2088*e4b17023SJohn Marino operator+(const _CharT* __lhs,
2089*e4b17023SJohn Marino const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs);
2090*e4b17023SJohn Marino
2091*e4b17023SJohn Marino /**
2092*e4b17023SJohn Marino * @brief Concatenate character and string.
2093*e4b17023SJohn Marino * @param __lhs First string.
2094*e4b17023SJohn Marino * @param __rhs Last string.
2095*e4b17023SJohn Marino * @return New string with @a __lhs followed by @a __rhs.
2096*e4b17023SJohn Marino */
2097*e4b17023SJohn Marino template<typename _CharT, typename _Traits, typename _Alloc,
2098*e4b17023SJohn Marino template <typename, typename, typename> class _Base>
2099*e4b17023SJohn Marino __versa_string<_CharT, _Traits, _Alloc, _Base>
2100*e4b17023SJohn Marino operator+(_CharT __lhs,
2101*e4b17023SJohn Marino const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs);
2102*e4b17023SJohn Marino
2103*e4b17023SJohn Marino /**
2104*e4b17023SJohn Marino * @brief Concatenate string and C string.
2105*e4b17023SJohn Marino * @param __lhs First string.
2106*e4b17023SJohn Marino * @param __rhs Last string.
2107*e4b17023SJohn Marino * @return New string with @a __lhs followed by @a __rhs.
2108*e4b17023SJohn Marino */
2109*e4b17023SJohn Marino template<typename _CharT, typename _Traits, typename _Alloc,
2110*e4b17023SJohn Marino template <typename, typename, typename> class _Base>
2111*e4b17023SJohn Marino __versa_string<_CharT, _Traits, _Alloc, _Base>
2112*e4b17023SJohn Marino operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2113*e4b17023SJohn Marino const _CharT* __rhs);
2114*e4b17023SJohn Marino
2115*e4b17023SJohn Marino /**
2116*e4b17023SJohn Marino * @brief Concatenate string and character.
2117*e4b17023SJohn Marino * @param __lhs First string.
2118*e4b17023SJohn Marino * @param __rhs Last string.
2119*e4b17023SJohn Marino * @return New string with @a __lhs followed by @a __rhs.
2120*e4b17023SJohn Marino */
2121*e4b17023SJohn Marino template<typename _CharT, typename _Traits, typename _Alloc,
2122*e4b17023SJohn Marino template <typename, typename, typename> class _Base>
2123*e4b17023SJohn Marino __versa_string<_CharT, _Traits, _Alloc, _Base>
2124*e4b17023SJohn Marino operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2125*e4b17023SJohn Marino _CharT __rhs);
2126*e4b17023SJohn Marino
2127*e4b17023SJohn Marino #ifdef __GXX_EXPERIMENTAL_CXX0X__
2128*e4b17023SJohn Marino template<typename _CharT, typename _Traits, typename _Alloc,
2129*e4b17023SJohn Marino template <typename, typename, typename> class _Base>
2130*e4b17023SJohn Marino inline __versa_string<_CharT, _Traits, _Alloc, _Base>
2131*e4b17023SJohn Marino operator+(__versa_string<_CharT, _Traits, _Alloc, _Base>&& __lhs,
2132*e4b17023SJohn Marino const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2133*e4b17023SJohn Marino { return std::move(__lhs.append(__rhs)); }
2134*e4b17023SJohn Marino
2135*e4b17023SJohn Marino template<typename _CharT, typename _Traits, typename _Alloc,
2136*e4b17023SJohn Marino template <typename, typename, typename> class _Base>
2137*e4b17023SJohn Marino inline __versa_string<_CharT, _Traits, _Alloc, _Base>
2138*e4b17023SJohn Marino operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2139*e4b17023SJohn Marino __versa_string<_CharT, _Traits, _Alloc, _Base>&& __rhs)
2140*e4b17023SJohn Marino { return std::move(__rhs.insert(0, __lhs)); }
2141*e4b17023SJohn Marino
2142*e4b17023SJohn Marino template<typename _CharT, typename _Traits, typename _Alloc,
2143*e4b17023SJohn Marino template <typename, typename, typename> class _Base>
2144*e4b17023SJohn Marino inline __versa_string<_CharT, _Traits, _Alloc, _Base>
2145*e4b17023SJohn Marino operator+(__versa_string<_CharT, _Traits, _Alloc, _Base>&& __lhs,
2146*e4b17023SJohn Marino __versa_string<_CharT, _Traits, _Alloc, _Base>&& __rhs)
2147*e4b17023SJohn Marino {
2148*e4b17023SJohn Marino const auto __size = __lhs.size() + __rhs.size();
2149*e4b17023SJohn Marino const bool __cond = (__size > __lhs.capacity()
2150*e4b17023SJohn Marino && __size <= __rhs.capacity());
2151*e4b17023SJohn Marino return __cond ? std::move(__rhs.insert(0, __lhs))
2152*e4b17023SJohn Marino : std::move(__lhs.append(__rhs));
2153*e4b17023SJohn Marino }
2154*e4b17023SJohn Marino
2155*e4b17023SJohn Marino template<typename _CharT, typename _Traits, typename _Alloc,
2156*e4b17023SJohn Marino template <typename, typename, typename> class _Base>
2157*e4b17023SJohn Marino inline __versa_string<_CharT, _Traits, _Alloc, _Base>
2158*e4b17023SJohn Marino operator+(const _CharT* __lhs,
2159*e4b17023SJohn Marino __versa_string<_CharT, _Traits, _Alloc, _Base>&& __rhs)
2160*e4b17023SJohn Marino { return std::move(__rhs.insert(0, __lhs)); }
2161*e4b17023SJohn Marino
2162*e4b17023SJohn Marino template<typename _CharT, typename _Traits, typename _Alloc,
2163*e4b17023SJohn Marino template <typename, typename, typename> class _Base>
2164*e4b17023SJohn Marino inline __versa_string<_CharT, _Traits, _Alloc, _Base>
2165*e4b17023SJohn Marino operator+(_CharT __lhs,
2166*e4b17023SJohn Marino __versa_string<_CharT, _Traits, _Alloc, _Base>&& __rhs)
2167*e4b17023SJohn Marino { return std::move(__rhs.insert(0, 1, __lhs)); }
2168*e4b17023SJohn Marino
2169*e4b17023SJohn Marino template<typename _CharT, typename _Traits, typename _Alloc,
2170*e4b17023SJohn Marino template <typename, typename, typename> class _Base>
2171*e4b17023SJohn Marino inline __versa_string<_CharT, _Traits, _Alloc, _Base>
2172*e4b17023SJohn Marino operator+(__versa_string<_CharT, _Traits, _Alloc, _Base>&& __lhs,
2173*e4b17023SJohn Marino const _CharT* __rhs)
2174*e4b17023SJohn Marino { return std::move(__lhs.append(__rhs)); }
2175*e4b17023SJohn Marino
2176*e4b17023SJohn Marino template<typename _CharT, typename _Traits, typename _Alloc,
2177*e4b17023SJohn Marino template <typename, typename, typename> class _Base>
2178*e4b17023SJohn Marino inline __versa_string<_CharT, _Traits, _Alloc, _Base>
2179*e4b17023SJohn Marino operator+(__versa_string<_CharT, _Traits, _Alloc, _Base>&& __lhs,
2180*e4b17023SJohn Marino _CharT __rhs)
2181*e4b17023SJohn Marino { return std::move(__lhs.append(1, __rhs)); }
2182*e4b17023SJohn Marino #endif
2183*e4b17023SJohn Marino
2184*e4b17023SJohn Marino // operator ==
2185*e4b17023SJohn Marino /**
2186*e4b17023SJohn Marino * @brief Test equivalence of two strings.
2187*e4b17023SJohn Marino * @param __lhs First string.
2188*e4b17023SJohn Marino * @param __rhs Second string.
2189*e4b17023SJohn Marino * @return True if @a __lhs.compare(@a __rhs) == 0. False otherwise.
2190*e4b17023SJohn Marino */
2191*e4b17023SJohn Marino template<typename _CharT, typename _Traits, typename _Alloc,
2192*e4b17023SJohn Marino template <typename, typename, typename> class _Base>
2193*e4b17023SJohn Marino inline bool
2194*e4b17023SJohn Marino operator==(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2195*e4b17023SJohn Marino const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2196*e4b17023SJohn Marino { return __lhs.compare(__rhs) == 0; }
2197*e4b17023SJohn Marino
2198*e4b17023SJohn Marino template<typename _CharT,
2199*e4b17023SJohn Marino template <typename, typename, typename> class _Base>
2200*e4b17023SJohn Marino inline typename __enable_if<std::__is_char<_CharT>::__value, bool>::__type
2201*e4b17023SJohn Marino operator==(const __versa_string<_CharT, std::char_traits<_CharT>,
2202*e4b17023SJohn Marino std::allocator<_CharT>, _Base>& __lhs,
2203*e4b17023SJohn Marino const __versa_string<_CharT, std::char_traits<_CharT>,
2204*e4b17023SJohn Marino std::allocator<_CharT>, _Base>& __rhs)
2205*e4b17023SJohn Marino { return (__lhs.size() == __rhs.size()
2206*e4b17023SJohn Marino && !std::char_traits<_CharT>::compare(__lhs.data(), __rhs.data(),
2207*e4b17023SJohn Marino __lhs.size())); }
2208*e4b17023SJohn Marino
2209*e4b17023SJohn Marino /**
2210*e4b17023SJohn Marino * @brief Test equivalence of C string and string.
2211*e4b17023SJohn Marino * @param __lhs C string.
2212*e4b17023SJohn Marino * @param __rhs String.
2213*e4b17023SJohn Marino * @return True if @a __rhs.compare(@a __lhs) == 0. False otherwise.
2214*e4b17023SJohn Marino */
2215*e4b17023SJohn Marino template<typename _CharT, typename _Traits, typename _Alloc,
2216*e4b17023SJohn Marino template <typename, typename, typename> class _Base>
2217*e4b17023SJohn Marino inline bool
2218*e4b17023SJohn Marino operator==(const _CharT* __lhs,
2219*e4b17023SJohn Marino const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2220*e4b17023SJohn Marino { return __rhs.compare(__lhs) == 0; }
2221*e4b17023SJohn Marino
2222*e4b17023SJohn Marino /**
2223*e4b17023SJohn Marino * @brief Test equivalence of string and C string.
2224*e4b17023SJohn Marino * @param __lhs String.
2225*e4b17023SJohn Marino * @param __rhs C string.
2226*e4b17023SJohn Marino * @return True if @a __lhs.compare(@a __rhs) == 0. False otherwise.
2227*e4b17023SJohn Marino */
2228*e4b17023SJohn Marino template<typename _CharT, typename _Traits, typename _Alloc,
2229*e4b17023SJohn Marino template <typename, typename, typename> class _Base>
2230*e4b17023SJohn Marino inline bool
2231*e4b17023SJohn Marino operator==(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2232*e4b17023SJohn Marino const _CharT* __rhs)
2233*e4b17023SJohn Marino { return __lhs.compare(__rhs) == 0; }
2234*e4b17023SJohn Marino
2235*e4b17023SJohn Marino // operator !=
2236*e4b17023SJohn Marino /**
2237*e4b17023SJohn Marino * @brief Test difference of two strings.
2238*e4b17023SJohn Marino * @param __lhs First string.
2239*e4b17023SJohn Marino * @param __rhs Second string.
2240*e4b17023SJohn Marino * @return True if @a __lhs.compare(@a __rhs) != 0. False otherwise.
2241*e4b17023SJohn Marino */
2242*e4b17023SJohn Marino template<typename _CharT, typename _Traits, typename _Alloc,
2243*e4b17023SJohn Marino template <typename, typename, typename> class _Base>
2244*e4b17023SJohn Marino inline bool
2245*e4b17023SJohn Marino operator!=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2246*e4b17023SJohn Marino const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2247*e4b17023SJohn Marino { return !(__lhs == __rhs); }
2248*e4b17023SJohn Marino
2249*e4b17023SJohn Marino /**
2250*e4b17023SJohn Marino * @brief Test difference of C string and string.
2251*e4b17023SJohn Marino * @param __lhs C string.
2252*e4b17023SJohn Marino * @param __rhs String.
2253*e4b17023SJohn Marino * @return True if @a __rhs.compare(@a __lhs) != 0. False otherwise.
2254*e4b17023SJohn Marino */
2255*e4b17023SJohn Marino template<typename _CharT, typename _Traits, typename _Alloc,
2256*e4b17023SJohn Marino template <typename, typename, typename> class _Base>
2257*e4b17023SJohn Marino inline bool
2258*e4b17023SJohn Marino operator!=(const _CharT* __lhs,
2259*e4b17023SJohn Marino const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2260*e4b17023SJohn Marino { return !(__lhs == __rhs); }
2261*e4b17023SJohn Marino
2262*e4b17023SJohn Marino /**
2263*e4b17023SJohn Marino * @brief Test difference of string and C string.
2264*e4b17023SJohn Marino * @param __lhs String.
2265*e4b17023SJohn Marino * @param __rhs C string.
2266*e4b17023SJohn Marino * @return True if @a __lhs.compare(@a __rhs) != 0. False otherwise.
2267*e4b17023SJohn Marino */
2268*e4b17023SJohn Marino template<typename _CharT, typename _Traits, typename _Alloc,
2269*e4b17023SJohn Marino template <typename, typename, typename> class _Base>
2270*e4b17023SJohn Marino inline bool
2271*e4b17023SJohn Marino operator!=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2272*e4b17023SJohn Marino const _CharT* __rhs)
2273*e4b17023SJohn Marino { return !(__lhs == __rhs); }
2274*e4b17023SJohn Marino
2275*e4b17023SJohn Marino // operator <
2276*e4b17023SJohn Marino /**
2277*e4b17023SJohn Marino * @brief Test if string precedes string.
2278*e4b17023SJohn Marino * @param __lhs First string.
2279*e4b17023SJohn Marino * @param __rhs Second string.
2280*e4b17023SJohn Marino * @return True if @a __lhs precedes @a __rhs. False otherwise.
2281*e4b17023SJohn Marino */
2282*e4b17023SJohn Marino template<typename _CharT, typename _Traits, typename _Alloc,
2283*e4b17023SJohn Marino template <typename, typename, typename> class _Base>
2284*e4b17023SJohn Marino inline bool
2285*e4b17023SJohn Marino operator<(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2286*e4b17023SJohn Marino const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2287*e4b17023SJohn Marino { return __lhs.compare(__rhs) < 0; }
2288*e4b17023SJohn Marino
2289*e4b17023SJohn Marino /**
2290*e4b17023SJohn Marino * @brief Test if string precedes C string.
2291*e4b17023SJohn Marino * @param __lhs String.
2292*e4b17023SJohn Marino * @param __rhs C string.
2293*e4b17023SJohn Marino * @return True if @a __lhs precedes @a __rhs. False otherwise.
2294*e4b17023SJohn Marino */
2295*e4b17023SJohn Marino template<typename _CharT, typename _Traits, typename _Alloc,
2296*e4b17023SJohn Marino template <typename, typename, typename> class _Base>
2297*e4b17023SJohn Marino inline bool
2298*e4b17023SJohn Marino operator<(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2299*e4b17023SJohn Marino const _CharT* __rhs)
2300*e4b17023SJohn Marino { return __lhs.compare(__rhs) < 0; }
2301*e4b17023SJohn Marino
2302*e4b17023SJohn Marino /**
2303*e4b17023SJohn Marino * @brief Test if C string precedes string.
2304*e4b17023SJohn Marino * @param __lhs C string.
2305*e4b17023SJohn Marino * @param __rhs String.
2306*e4b17023SJohn Marino * @return True if @a __lhs precedes @a __rhs. False otherwise.
2307*e4b17023SJohn Marino */
2308*e4b17023SJohn Marino template<typename _CharT, typename _Traits, typename _Alloc,
2309*e4b17023SJohn Marino template <typename, typename, typename> class _Base>
2310*e4b17023SJohn Marino inline bool
2311*e4b17023SJohn Marino operator<(const _CharT* __lhs,
2312*e4b17023SJohn Marino const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2313*e4b17023SJohn Marino { return __rhs.compare(__lhs) > 0; }
2314*e4b17023SJohn Marino
2315*e4b17023SJohn Marino // operator >
2316*e4b17023SJohn Marino /**
2317*e4b17023SJohn Marino * @brief Test if string follows string.
2318*e4b17023SJohn Marino * @param __lhs First string.
2319*e4b17023SJohn Marino * @param __rhs Second string.
2320*e4b17023SJohn Marino * @return True if @a __lhs follows @a __rhs. False otherwise.
2321*e4b17023SJohn Marino */
2322*e4b17023SJohn Marino template<typename _CharT, typename _Traits, typename _Alloc,
2323*e4b17023SJohn Marino template <typename, typename, typename> class _Base>
2324*e4b17023SJohn Marino inline bool
2325*e4b17023SJohn Marino operator>(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2326*e4b17023SJohn Marino const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2327*e4b17023SJohn Marino { return __lhs.compare(__rhs) > 0; }
2328*e4b17023SJohn Marino
2329*e4b17023SJohn Marino /**
2330*e4b17023SJohn Marino * @brief Test if string follows C string.
2331*e4b17023SJohn Marino * @param __lhs String.
2332*e4b17023SJohn Marino * @param __rhs C string.
2333*e4b17023SJohn Marino * @return True if @a __lhs follows @a __rhs. False otherwise.
2334*e4b17023SJohn Marino */
2335*e4b17023SJohn Marino template<typename _CharT, typename _Traits, typename _Alloc,
2336*e4b17023SJohn Marino template <typename, typename, typename> class _Base>
2337*e4b17023SJohn Marino inline bool
2338*e4b17023SJohn Marino operator>(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2339*e4b17023SJohn Marino const _CharT* __rhs)
2340*e4b17023SJohn Marino { return __lhs.compare(__rhs) > 0; }
2341*e4b17023SJohn Marino
2342*e4b17023SJohn Marino /**
2343*e4b17023SJohn Marino * @brief Test if C string follows string.
2344*e4b17023SJohn Marino * @param __lhs C string.
2345*e4b17023SJohn Marino * @param __rhs String.
2346*e4b17023SJohn Marino * @return True if @a __lhs follows @a __rhs. False otherwise.
2347*e4b17023SJohn Marino */
2348*e4b17023SJohn Marino template<typename _CharT, typename _Traits, typename _Alloc,
2349*e4b17023SJohn Marino template <typename, typename, typename> class _Base>
2350*e4b17023SJohn Marino inline bool
2351*e4b17023SJohn Marino operator>(const _CharT* __lhs,
2352*e4b17023SJohn Marino const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2353*e4b17023SJohn Marino { return __rhs.compare(__lhs) < 0; }
2354*e4b17023SJohn Marino
2355*e4b17023SJohn Marino // operator <=
2356*e4b17023SJohn Marino /**
2357*e4b17023SJohn Marino * @brief Test if string doesn't follow string.
2358*e4b17023SJohn Marino * @param __lhs First string.
2359*e4b17023SJohn Marino * @param __rhs Second string.
2360*e4b17023SJohn Marino * @return True if @a __lhs doesn't follow @a __rhs. False otherwise.
2361*e4b17023SJohn Marino */
2362*e4b17023SJohn Marino template<typename _CharT, typename _Traits, typename _Alloc,
2363*e4b17023SJohn Marino template <typename, typename, typename> class _Base>
2364*e4b17023SJohn Marino inline bool
2365*e4b17023SJohn Marino operator<=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2366*e4b17023SJohn Marino const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2367*e4b17023SJohn Marino { return __lhs.compare(__rhs) <= 0; }
2368*e4b17023SJohn Marino
2369*e4b17023SJohn Marino /**
2370*e4b17023SJohn Marino * @brief Test if string doesn't follow C string.
2371*e4b17023SJohn Marino * @param __lhs String.
2372*e4b17023SJohn Marino * @param __rhs C string.
2373*e4b17023SJohn Marino * @return True if @a __lhs doesn't follow @a __rhs. False otherwise.
2374*e4b17023SJohn Marino */
2375*e4b17023SJohn Marino template<typename _CharT, typename _Traits, typename _Alloc,
2376*e4b17023SJohn Marino template <typename, typename, typename> class _Base>
2377*e4b17023SJohn Marino inline bool
2378*e4b17023SJohn Marino operator<=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2379*e4b17023SJohn Marino const _CharT* __rhs)
2380*e4b17023SJohn Marino { return __lhs.compare(__rhs) <= 0; }
2381*e4b17023SJohn Marino
2382*e4b17023SJohn Marino /**
2383*e4b17023SJohn Marino * @brief Test if C string doesn't follow string.
2384*e4b17023SJohn Marino * @param __lhs C string.
2385*e4b17023SJohn Marino * @param __rhs String.
2386*e4b17023SJohn Marino * @return True if @a __lhs doesn't follow @a __rhs. False otherwise.
2387*e4b17023SJohn Marino */
2388*e4b17023SJohn Marino template<typename _CharT, typename _Traits, typename _Alloc,
2389*e4b17023SJohn Marino template <typename, typename, typename> class _Base>
2390*e4b17023SJohn Marino inline bool
2391*e4b17023SJohn Marino operator<=(const _CharT* __lhs,
2392*e4b17023SJohn Marino const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2393*e4b17023SJohn Marino { return __rhs.compare(__lhs) >= 0; }
2394*e4b17023SJohn Marino
2395*e4b17023SJohn Marino // operator >=
2396*e4b17023SJohn Marino /**
2397*e4b17023SJohn Marino * @brief Test if string doesn't precede string.
2398*e4b17023SJohn Marino * @param __lhs First string.
2399*e4b17023SJohn Marino * @param __rhs Second string.
2400*e4b17023SJohn Marino * @return True if @a __lhs doesn't precede @a __rhs. False otherwise.
2401*e4b17023SJohn Marino */
2402*e4b17023SJohn Marino template<typename _CharT, typename _Traits, typename _Alloc,
2403*e4b17023SJohn Marino template <typename, typename, typename> class _Base>
2404*e4b17023SJohn Marino inline bool
2405*e4b17023SJohn Marino operator>=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2406*e4b17023SJohn Marino const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2407*e4b17023SJohn Marino { return __lhs.compare(__rhs) >= 0; }
2408*e4b17023SJohn Marino
2409*e4b17023SJohn Marino /**
2410*e4b17023SJohn Marino * @brief Test if string doesn't precede C string.
2411*e4b17023SJohn Marino * @param __lhs String.
2412*e4b17023SJohn Marino * @param __rhs C string.
2413*e4b17023SJohn Marino * @return True if @a __lhs doesn't precede @a __rhs. False otherwise.
2414*e4b17023SJohn Marino */
2415*e4b17023SJohn Marino template<typename _CharT, typename _Traits, typename _Alloc,
2416*e4b17023SJohn Marino template <typename, typename, typename> class _Base>
2417*e4b17023SJohn Marino inline bool
2418*e4b17023SJohn Marino operator>=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2419*e4b17023SJohn Marino const _CharT* __rhs)
2420*e4b17023SJohn Marino { return __lhs.compare(__rhs) >= 0; }
2421*e4b17023SJohn Marino
2422*e4b17023SJohn Marino /**
2423*e4b17023SJohn Marino * @brief Test if C string doesn't precede string.
2424*e4b17023SJohn Marino * @param __lhs C string.
2425*e4b17023SJohn Marino * @param __rhs String.
2426*e4b17023SJohn Marino * @return True if @a __lhs doesn't precede @a __rhs. False otherwise.
2427*e4b17023SJohn Marino */
2428*e4b17023SJohn Marino template<typename _CharT, typename _Traits, typename _Alloc,
2429*e4b17023SJohn Marino template <typename, typename, typename> class _Base>
2430*e4b17023SJohn Marino inline bool
2431*e4b17023SJohn Marino operator>=(const _CharT* __lhs,
2432*e4b17023SJohn Marino const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2433*e4b17023SJohn Marino { return __rhs.compare(__lhs) <= 0; }
2434*e4b17023SJohn Marino
2435*e4b17023SJohn Marino /**
2436*e4b17023SJohn Marino * @brief Swap contents of two strings.
2437*e4b17023SJohn Marino * @param __lhs First string.
2438*e4b17023SJohn Marino * @param __rhs Second string.
2439*e4b17023SJohn Marino *
2440*e4b17023SJohn Marino * Exchanges the contents of @a __lhs and @a __rhs in constant time.
2441*e4b17023SJohn Marino */
2442*e4b17023SJohn Marino template<typename _CharT, typename _Traits, typename _Alloc,
2443*e4b17023SJohn Marino template <typename, typename, typename> class _Base>
2444*e4b17023SJohn Marino inline void
2445*e4b17023SJohn Marino swap(__versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2446*e4b17023SJohn Marino __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2447*e4b17023SJohn Marino { __lhs.swap(__rhs); }
2448*e4b17023SJohn Marino
2449*e4b17023SJohn Marino _GLIBCXX_END_NAMESPACE_VERSION
2450*e4b17023SJohn Marino } // namespace
2451*e4b17023SJohn Marino
_GLIBCXX_VISIBILITY(default)2452*e4b17023SJohn Marino namespace std _GLIBCXX_VISIBILITY(default)
2453*e4b17023SJohn Marino {
2454*e4b17023SJohn Marino _GLIBCXX_BEGIN_NAMESPACE_VERSION
2455*e4b17023SJohn Marino
2456*e4b17023SJohn Marino /**
2457*e4b17023SJohn Marino * @brief Read stream into a string.
2458*e4b17023SJohn Marino * @param __is Input stream.
2459*e4b17023SJohn Marino * @param __str Buffer to store into.
2460*e4b17023SJohn Marino * @return Reference to the input stream.
2461*e4b17023SJohn Marino *
2462*e4b17023SJohn Marino * Stores characters from @a __is into @a __str until whitespace is
2463*e4b17023SJohn Marino * found, the end of the stream is encountered, or str.max_size()
2464*e4b17023SJohn Marino * is reached. If is.width() is non-zero, that is the limit on the
2465*e4b17023SJohn Marino * number of characters stored into @a __str. Any previous
2466*e4b17023SJohn Marino * contents of @a __str are erased.
2467*e4b17023SJohn Marino */
2468*e4b17023SJohn Marino template<typename _CharT, typename _Traits, typename _Alloc,
2469*e4b17023SJohn Marino template <typename, typename, typename> class _Base>
2470*e4b17023SJohn Marino basic_istream<_CharT, _Traits>&
2471*e4b17023SJohn Marino operator>>(basic_istream<_CharT, _Traits>& __is,
2472*e4b17023SJohn Marino __gnu_cxx::__versa_string<_CharT, _Traits,
2473*e4b17023SJohn Marino _Alloc, _Base>& __str);
2474*e4b17023SJohn Marino
2475*e4b17023SJohn Marino /**
2476*e4b17023SJohn Marino * @brief Write string to a stream.
2477*e4b17023SJohn Marino * @param __os Output stream.
2478*e4b17023SJohn Marino * @param __str String to write out.
2479*e4b17023SJohn Marino * @return Reference to the output stream.
2480*e4b17023SJohn Marino *
2481*e4b17023SJohn Marino * Output characters of @a __str into os following the same rules as for
2482*e4b17023SJohn Marino * writing a C string.
2483*e4b17023SJohn Marino */
2484*e4b17023SJohn Marino template<typename _CharT, typename _Traits, typename _Alloc,
2485*e4b17023SJohn Marino template <typename, typename, typename> class _Base>
2486*e4b17023SJohn Marino inline basic_ostream<_CharT, _Traits>&
2487*e4b17023SJohn Marino operator<<(basic_ostream<_CharT, _Traits>& __os,
2488*e4b17023SJohn Marino const __gnu_cxx::__versa_string<_CharT, _Traits, _Alloc,
2489*e4b17023SJohn Marino _Base>& __str)
2490*e4b17023SJohn Marino {
2491*e4b17023SJohn Marino // _GLIBCXX_RESOLVE_LIB_DEFECTS
2492*e4b17023SJohn Marino // 586. string inserter not a formatted function
2493*e4b17023SJohn Marino return __ostream_insert(__os, __str.data(), __str.size());
2494*e4b17023SJohn Marino }
2495*e4b17023SJohn Marino
2496*e4b17023SJohn Marino /**
2497*e4b17023SJohn Marino * @brief Read a line from stream into a string.
2498*e4b17023SJohn Marino * @param __is Input stream.
2499*e4b17023SJohn Marino * @param __str Buffer to store into.
2500*e4b17023SJohn Marino * @param __delim Character marking end of line.
2501*e4b17023SJohn Marino * @return Reference to the input stream.
2502*e4b17023SJohn Marino *
2503*e4b17023SJohn Marino * Stores characters from @a __is into @a __str until @a __delim is
2504*e4b17023SJohn Marino * found, the end of the stream is encountered, or str.max_size()
2505*e4b17023SJohn Marino * is reached. If is.width() is non-zero, that is the limit on the
2506*e4b17023SJohn Marino * number of characters stored into @a __str. Any previous
2507*e4b17023SJohn Marino * contents of @a __str are erased. If @a delim was encountered,
2508*e4b17023SJohn Marino * it is extracted but not stored into @a __str.
2509*e4b17023SJohn Marino */
2510*e4b17023SJohn Marino template<typename _CharT, typename _Traits, typename _Alloc,
2511*e4b17023SJohn Marino template <typename, typename, typename> class _Base>
2512*e4b17023SJohn Marino basic_istream<_CharT, _Traits>&
2513*e4b17023SJohn Marino getline(basic_istream<_CharT, _Traits>& __is,
2514*e4b17023SJohn Marino __gnu_cxx::__versa_string<_CharT, _Traits, _Alloc, _Base>& __str,
2515*e4b17023SJohn Marino _CharT __delim);
2516*e4b17023SJohn Marino
2517*e4b17023SJohn Marino /**
2518*e4b17023SJohn Marino * @brief Read a line from stream into a string.
2519*e4b17023SJohn Marino * @param __is Input stream.
2520*e4b17023SJohn Marino * @param __str Buffer to store into.
2521*e4b17023SJohn Marino * @return Reference to the input stream.
2522*e4b17023SJohn Marino *
2523*e4b17023SJohn Marino * Stores characters from is into @a __str until '\n' is
2524*e4b17023SJohn Marino * found, the end of the stream is encountered, or str.max_size()
2525*e4b17023SJohn Marino * is reached. If is.width() is non-zero, that is the limit on the
2526*e4b17023SJohn Marino * number of characters stored into @a __str. Any previous
2527*e4b17023SJohn Marino * contents of @a __str are erased. If end of line was
2528*e4b17023SJohn Marino * encountered, it is extracted but not stored into @a __str.
2529*e4b17023SJohn Marino */
2530*e4b17023SJohn Marino template<typename _CharT, typename _Traits, typename _Alloc,
2531*e4b17023SJohn Marino template <typename, typename, typename> class _Base>
2532*e4b17023SJohn Marino inline basic_istream<_CharT, _Traits>&
2533*e4b17023SJohn Marino getline(basic_istream<_CharT, _Traits>& __is,
2534*e4b17023SJohn Marino __gnu_cxx::__versa_string<_CharT, _Traits, _Alloc, _Base>& __str)
2535*e4b17023SJohn Marino { return getline(__is, __str, __is.widen('\n')); }
2536*e4b17023SJohn Marino
2537*e4b17023SJohn Marino _GLIBCXX_END_NAMESPACE_VERSION
2538*e4b17023SJohn Marino } // namespace
2539*e4b17023SJohn Marino
2540*e4b17023SJohn Marino #if (defined(__GXX_EXPERIMENTAL_CXX0X__) && defined(_GLIBCXX_USE_C99))
2541*e4b17023SJohn Marino
2542*e4b17023SJohn Marino #include <ext/string_conversions.h>
2543*e4b17023SJohn Marino
_GLIBCXX_VISIBILITY(default)2544*e4b17023SJohn Marino namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
2545*e4b17023SJohn Marino {
2546*e4b17023SJohn Marino _GLIBCXX_BEGIN_NAMESPACE_VERSION
2547*e4b17023SJohn Marino
2548*e4b17023SJohn Marino // 21.4 Numeric Conversions [string.conversions].
2549*e4b17023SJohn Marino inline int
2550*e4b17023SJohn Marino stoi(const __vstring& __str, std::size_t* __idx = 0, int __base = 10)
2551*e4b17023SJohn Marino { return __gnu_cxx::__stoa<long, int>(&std::strtol, "stoi", __str.c_str(),
2552*e4b17023SJohn Marino __idx, __base); }
2553*e4b17023SJohn Marino
2554*e4b17023SJohn Marino inline long
2555*e4b17023SJohn Marino stol(const __vstring& __str, std::size_t* __idx = 0, int __base = 10)
2556*e4b17023SJohn Marino { return __gnu_cxx::__stoa(&std::strtol, "stol", __str.c_str(),
2557*e4b17023SJohn Marino __idx, __base); }
2558*e4b17023SJohn Marino
2559*e4b17023SJohn Marino inline unsigned long
2560*e4b17023SJohn Marino stoul(const __vstring& __str, std::size_t* __idx = 0, int __base = 10)
2561*e4b17023SJohn Marino { return __gnu_cxx::__stoa(&std::strtoul, "stoul", __str.c_str(),
2562*e4b17023SJohn Marino __idx, __base); }
2563*e4b17023SJohn Marino
2564*e4b17023SJohn Marino inline long long
2565*e4b17023SJohn Marino stoll(const __vstring& __str, std::size_t* __idx = 0, int __base = 10)
2566*e4b17023SJohn Marino { return __gnu_cxx::__stoa(&std::strtoll, "stoll", __str.c_str(),
2567*e4b17023SJohn Marino __idx, __base); }
2568*e4b17023SJohn Marino
2569*e4b17023SJohn Marino inline unsigned long long
2570*e4b17023SJohn Marino stoull(const __vstring& __str, std::size_t* __idx, int __base = 10)
2571*e4b17023SJohn Marino { return __gnu_cxx::__stoa(&std::strtoull, "stoull", __str.c_str(),
2572*e4b17023SJohn Marino __idx, __base); }
2573*e4b17023SJohn Marino
2574*e4b17023SJohn Marino // NB: strtof vs strtod.
2575*e4b17023SJohn Marino inline float
2576*e4b17023SJohn Marino stof(const __vstring& __str, std::size_t* __idx = 0)
2577*e4b17023SJohn Marino { return __gnu_cxx::__stoa(&std::strtof, "stof", __str.c_str(), __idx); }
2578*e4b17023SJohn Marino
2579*e4b17023SJohn Marino inline double
2580*e4b17023SJohn Marino stod(const __vstring& __str, std::size_t* __idx = 0)
2581*e4b17023SJohn Marino { return __gnu_cxx::__stoa(&std::strtod, "stod", __str.c_str(), __idx); }
2582*e4b17023SJohn Marino
2583*e4b17023SJohn Marino inline long double
2584*e4b17023SJohn Marino stold(const __vstring& __str, std::size_t* __idx = 0)
2585*e4b17023SJohn Marino { return __gnu_cxx::__stoa(&std::strtold, "stold", __str.c_str(), __idx); }
2586*e4b17023SJohn Marino
2587*e4b17023SJohn Marino // NB: (v)snprintf vs sprintf.
2588*e4b17023SJohn Marino
2589*e4b17023SJohn Marino // DR 1261.
2590*e4b17023SJohn Marino inline __vstring
2591*e4b17023SJohn Marino to_string(int __val)
2592*e4b17023SJohn Marino { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, 4 * sizeof(int),
2593*e4b17023SJohn Marino "%d", __val); }
2594*e4b17023SJohn Marino
2595*e4b17023SJohn Marino inline __vstring
2596*e4b17023SJohn Marino to_string(unsigned __val)
2597*e4b17023SJohn Marino { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf,
2598*e4b17023SJohn Marino 4 * sizeof(unsigned),
2599*e4b17023SJohn Marino "%u", __val); }
2600*e4b17023SJohn Marino
2601*e4b17023SJohn Marino inline __vstring
2602*e4b17023SJohn Marino to_string(long __val)
2603*e4b17023SJohn Marino { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf,
2604*e4b17023SJohn Marino 4 * sizeof(long),
2605*e4b17023SJohn Marino "%ld", __val); }
2606*e4b17023SJohn Marino
2607*e4b17023SJohn Marino inline __vstring
2608*e4b17023SJohn Marino to_string(unsigned long __val)
2609*e4b17023SJohn Marino { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf,
2610*e4b17023SJohn Marino 4 * sizeof(unsigned long),
2611*e4b17023SJohn Marino "%lu", __val); }
2612*e4b17023SJohn Marino
2613*e4b17023SJohn Marino
2614*e4b17023SJohn Marino inline __vstring
2615*e4b17023SJohn Marino to_string(long long __val)
2616*e4b17023SJohn Marino { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf,
2617*e4b17023SJohn Marino 4 * sizeof(long long),
2618*e4b17023SJohn Marino "%lld", __val); }
2619*e4b17023SJohn Marino
2620*e4b17023SJohn Marino inline __vstring
2621*e4b17023SJohn Marino to_string(unsigned long long __val)
2622*e4b17023SJohn Marino { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf,
2623*e4b17023SJohn Marino 4 * sizeof(unsigned long long),
2624*e4b17023SJohn Marino "%llu", __val); }
2625*e4b17023SJohn Marino
2626*e4b17023SJohn Marino inline __vstring
2627*e4b17023SJohn Marino to_string(float __val)
2628*e4b17023SJohn Marino {
2629*e4b17023SJohn Marino const int __n = __numeric_traits<float>::__max_exponent10 + 20;
2630*e4b17023SJohn Marino return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, __n,
2631*e4b17023SJohn Marino "%f", __val);
2632*e4b17023SJohn Marino }
2633*e4b17023SJohn Marino
2634*e4b17023SJohn Marino inline __vstring
2635*e4b17023SJohn Marino to_string(double __val)
2636*e4b17023SJohn Marino {
2637*e4b17023SJohn Marino const int __n = __numeric_traits<double>::__max_exponent10 + 20;
2638*e4b17023SJohn Marino return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, __n,
2639*e4b17023SJohn Marino "%f", __val);
2640*e4b17023SJohn Marino }
2641*e4b17023SJohn Marino
2642*e4b17023SJohn Marino inline __vstring
2643*e4b17023SJohn Marino to_string(long double __val)
2644*e4b17023SJohn Marino {
2645*e4b17023SJohn Marino const int __n = __numeric_traits<long double>::__max_exponent10 + 20;
2646*e4b17023SJohn Marino return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, __n,
2647*e4b17023SJohn Marino "%Lf", __val);
2648*e4b17023SJohn Marino }
2649*e4b17023SJohn Marino
2650*e4b17023SJohn Marino #ifdef _GLIBCXX_USE_WCHAR_T
2651*e4b17023SJohn Marino inline int
2652*e4b17023SJohn Marino stoi(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10)
2653*e4b17023SJohn Marino { return __gnu_cxx::__stoa<long, int>(&std::wcstol, "stoi", __str.c_str(),
2654*e4b17023SJohn Marino __idx, __base); }
2655*e4b17023SJohn Marino
2656*e4b17023SJohn Marino inline long
2657*e4b17023SJohn Marino stol(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10)
2658*e4b17023SJohn Marino { return __gnu_cxx::__stoa(&std::wcstol, "stol", __str.c_str(),
2659*e4b17023SJohn Marino __idx, __base); }
2660*e4b17023SJohn Marino
2661*e4b17023SJohn Marino inline unsigned long
2662*e4b17023SJohn Marino stoul(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10)
2663*e4b17023SJohn Marino { return __gnu_cxx::__stoa(&std::wcstoul, "stoul", __str.c_str(),
2664*e4b17023SJohn Marino __idx, __base); }
2665*e4b17023SJohn Marino
2666*e4b17023SJohn Marino inline long long
2667*e4b17023SJohn Marino stoll(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10)
2668*e4b17023SJohn Marino { return __gnu_cxx::__stoa(&std::wcstoll, "stoll", __str.c_str(),
2669*e4b17023SJohn Marino __idx, __base); }
2670*e4b17023SJohn Marino
2671*e4b17023SJohn Marino inline unsigned long long
2672*e4b17023SJohn Marino stoull(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10)
2673*e4b17023SJohn Marino { return __gnu_cxx::__stoa(&std::wcstoull, "stoull", __str.c_str(),
2674*e4b17023SJohn Marino __idx, __base); }
2675*e4b17023SJohn Marino
2676*e4b17023SJohn Marino // NB: wcstof vs wcstod.
2677*e4b17023SJohn Marino inline float
2678*e4b17023SJohn Marino stof(const __wvstring& __str, std::size_t* __idx = 0)
2679*e4b17023SJohn Marino { return __gnu_cxx::__stoa(&std::wcstof, "stof", __str.c_str(), __idx); }
2680*e4b17023SJohn Marino
2681*e4b17023SJohn Marino inline double
2682*e4b17023SJohn Marino stod(const __wvstring& __str, std::size_t* __idx = 0)
2683*e4b17023SJohn Marino { return __gnu_cxx::__stoa(&std::wcstod, "stod", __str.c_str(), __idx); }
2684*e4b17023SJohn Marino
2685*e4b17023SJohn Marino inline long double
2686*e4b17023SJohn Marino stold(const __wvstring& __str, std::size_t* __idx = 0)
2687*e4b17023SJohn Marino { return __gnu_cxx::__stoa(&std::wcstold, "stold", __str.c_str(), __idx); }
2688*e4b17023SJohn Marino
2689*e4b17023SJohn Marino #ifndef _GLIBCXX_HAVE_BROKEN_VSWPRINTF
2690*e4b17023SJohn Marino // DR 1261.
2691*e4b17023SJohn Marino inline __wvstring
2692*e4b17023SJohn Marino to_wstring(int __val)
2693*e4b17023SJohn Marino { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
2694*e4b17023SJohn Marino 4 * sizeof(int),
2695*e4b17023SJohn Marino L"%d", __val); }
2696*e4b17023SJohn Marino
2697*e4b17023SJohn Marino inline __wvstring
2698*e4b17023SJohn Marino to_wstring(unsigned __val)
2699*e4b17023SJohn Marino { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
2700*e4b17023SJohn Marino 4 * sizeof(unsigned),
2701*e4b17023SJohn Marino L"%u", __val); }
2702*e4b17023SJohn Marino
2703*e4b17023SJohn Marino inline __wvstring
2704*e4b17023SJohn Marino to_wstring(long __val)
2705*e4b17023SJohn Marino { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
2706*e4b17023SJohn Marino 4 * sizeof(long),
2707*e4b17023SJohn Marino L"%ld", __val); }
2708*e4b17023SJohn Marino
2709*e4b17023SJohn Marino inline __wvstring
2710*e4b17023SJohn Marino to_wstring(unsigned long __val)
2711*e4b17023SJohn Marino { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
2712*e4b17023SJohn Marino 4 * sizeof(unsigned long),
2713*e4b17023SJohn Marino L"%lu", __val); }
2714*e4b17023SJohn Marino
2715*e4b17023SJohn Marino inline __wvstring
2716*e4b17023SJohn Marino to_wstring(long long __val)
2717*e4b17023SJohn Marino { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
2718*e4b17023SJohn Marino 4 * sizeof(long long),
2719*e4b17023SJohn Marino L"%lld", __val); }
2720*e4b17023SJohn Marino
2721*e4b17023SJohn Marino inline __wvstring
2722*e4b17023SJohn Marino to_wstring(unsigned long long __val)
2723*e4b17023SJohn Marino { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
2724*e4b17023SJohn Marino 4 * sizeof(unsigned long long),
2725*e4b17023SJohn Marino L"%llu", __val); }
2726*e4b17023SJohn Marino
2727*e4b17023SJohn Marino inline __wvstring
2728*e4b17023SJohn Marino to_wstring(float __val)
2729*e4b17023SJohn Marino {
2730*e4b17023SJohn Marino const int __n = __numeric_traits<float>::__max_exponent10 + 20;
2731*e4b17023SJohn Marino return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, __n,
2732*e4b17023SJohn Marino L"%f", __val);
2733*e4b17023SJohn Marino }
2734*e4b17023SJohn Marino
2735*e4b17023SJohn Marino inline __wvstring
2736*e4b17023SJohn Marino to_wstring(double __val)
2737*e4b17023SJohn Marino {
2738*e4b17023SJohn Marino const int __n = __numeric_traits<double>::__max_exponent10 + 20;
2739*e4b17023SJohn Marino return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, __n,
2740*e4b17023SJohn Marino L"%f", __val);
2741*e4b17023SJohn Marino }
2742*e4b17023SJohn Marino
2743*e4b17023SJohn Marino inline __wvstring
2744*e4b17023SJohn Marino to_wstring(long double __val)
2745*e4b17023SJohn Marino {
2746*e4b17023SJohn Marino const int __n = __numeric_traits<long double>::__max_exponent10 + 20;
2747*e4b17023SJohn Marino return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, __n,
2748*e4b17023SJohn Marino L"%Lf", __val);
2749*e4b17023SJohn Marino }
2750*e4b17023SJohn Marino #endif
2751*e4b17023SJohn Marino #endif
2752*e4b17023SJohn Marino
2753*e4b17023SJohn Marino _GLIBCXX_END_NAMESPACE_VERSION
2754*e4b17023SJohn Marino } // namespace
2755*e4b17023SJohn Marino
2756*e4b17023SJohn Marino #endif
2757*e4b17023SJohn Marino
2758*e4b17023SJohn Marino #ifdef __GXX_EXPERIMENTAL_CXX0X__
2759*e4b17023SJohn Marino
2760*e4b17023SJohn Marino #include <bits/functional_hash.h>
2761*e4b17023SJohn Marino
_GLIBCXX_VISIBILITY(default)2762*e4b17023SJohn Marino namespace std _GLIBCXX_VISIBILITY(default)
2763*e4b17023SJohn Marino {
2764*e4b17023SJohn Marino _GLIBCXX_BEGIN_NAMESPACE_VERSION
2765*e4b17023SJohn Marino
2766*e4b17023SJohn Marino /// std::hash specialization for __vstring.
2767*e4b17023SJohn Marino template<>
2768*e4b17023SJohn Marino struct hash<__gnu_cxx::__vstring>
2769*e4b17023SJohn Marino : public __hash_base<size_t, __gnu_cxx::__vstring>
2770*e4b17023SJohn Marino {
2771*e4b17023SJohn Marino size_t
2772*e4b17023SJohn Marino operator()(const __gnu_cxx::__vstring& __s) const noexcept
2773*e4b17023SJohn Marino { return std::_Hash_impl::hash(__s.data(), __s.length()); }
2774*e4b17023SJohn Marino };
2775*e4b17023SJohn Marino
2776*e4b17023SJohn Marino #ifdef _GLIBCXX_USE_WCHAR_T
2777*e4b17023SJohn Marino /// std::hash specialization for __wvstring.
2778*e4b17023SJohn Marino template<>
2779*e4b17023SJohn Marino struct hash<__gnu_cxx::__wvstring>
2780*e4b17023SJohn Marino : public __hash_base<size_t, __gnu_cxx::__wvstring>
2781*e4b17023SJohn Marino {
2782*e4b17023SJohn Marino size_t
2783*e4b17023SJohn Marino operator()(const __gnu_cxx::__wvstring& __s) const noexcept
2784*e4b17023SJohn Marino { return std::_Hash_impl::hash(__s.data(),
2785*e4b17023SJohn Marino __s.length() * sizeof(wchar_t)); }
2786*e4b17023SJohn Marino };
2787*e4b17023SJohn Marino #endif
2788*e4b17023SJohn Marino
2789*e4b17023SJohn Marino #ifdef _GLIBCXX_USE_C99_STDINT_TR1
2790*e4b17023SJohn Marino /// std::hash specialization for __u16vstring.
2791*e4b17023SJohn Marino template<>
2792*e4b17023SJohn Marino struct hash<__gnu_cxx::__u16vstring>
2793*e4b17023SJohn Marino : public __hash_base<size_t, __gnu_cxx::__u16vstring>
2794*e4b17023SJohn Marino {
2795*e4b17023SJohn Marino size_t
2796*e4b17023SJohn Marino operator()(const __gnu_cxx::__u16vstring& __s) const noexcept
2797*e4b17023SJohn Marino { return std::_Hash_impl::hash(__s.data(),
2798*e4b17023SJohn Marino __s.length() * sizeof(char16_t)); }
2799*e4b17023SJohn Marino };
2800*e4b17023SJohn Marino
2801*e4b17023SJohn Marino /// std::hash specialization for __u32vstring.
2802*e4b17023SJohn Marino template<>
2803*e4b17023SJohn Marino struct hash<__gnu_cxx::__u32vstring>
2804*e4b17023SJohn Marino : public __hash_base<size_t, __gnu_cxx::__u32vstring>
2805*e4b17023SJohn Marino {
2806*e4b17023SJohn Marino size_t
2807*e4b17023SJohn Marino operator()(const __gnu_cxx::__u32vstring& __s) const noexcept
2808*e4b17023SJohn Marino { return std::_Hash_impl::hash(__s.data(),
2809*e4b17023SJohn Marino __s.length() * sizeof(char32_t)); }
2810*e4b17023SJohn Marino };
2811*e4b17023SJohn Marino #endif
2812*e4b17023SJohn Marino
2813*e4b17023SJohn Marino _GLIBCXX_END_NAMESPACE_VERSION
2814*e4b17023SJohn Marino } // namespace
2815*e4b17023SJohn Marino
2816*e4b17023SJohn Marino #endif /* __GXX_EXPERIMENTAL_CXX0X__ */
2817*e4b17023SJohn Marino
2818*e4b17023SJohn Marino #include "vstring.tcc"
2819*e4b17023SJohn Marino
2820*e4b17023SJohn Marino #endif /* _VSTRING_H */
2821