xref: /reactos/sdk/include/c++/stlport/stl/_string.c (revision c2c66aff)
1*c2c66affSColin Finck /*
2*c2c66affSColin Finck  * Copyright (c) 1994
3*c2c66affSColin Finck  * Hewlett-Packard Company
4*c2c66affSColin Finck  *
5*c2c66affSColin Finck  * Copyright (c) 1996,1997
6*c2c66affSColin Finck  * Silicon Graphics Computer Systems, Inc.
7*c2c66affSColin Finck  *
8*c2c66affSColin Finck  * Copyright (c) 1997
9*c2c66affSColin Finck  * Moscow Center for SPARC Technology
10*c2c66affSColin Finck  *
11*c2c66affSColin Finck  * Copyright (c) 1999
12*c2c66affSColin Finck  * Boris Fomitchev
13*c2c66affSColin Finck  *
14*c2c66affSColin Finck  * This material is provided "as is", with absolutely no warranty expressed
15*c2c66affSColin Finck  * or implied. Any use is at your own risk.
16*c2c66affSColin Finck  *
17*c2c66affSColin Finck  * Permission to use or copy this software for any purpose is hereby granted
18*c2c66affSColin Finck  * without fee, provided the above notices are retained on all copies.
19*c2c66affSColin Finck  * Permission to modify the code and to distribute modified code is granted,
20*c2c66affSColin Finck  * provided the above notices are retained, and a notice that the code was
21*c2c66affSColin Finck  * modified is included with the above copyright notice.
22*c2c66affSColin Finck  */
23*c2c66affSColin Finck 
24*c2c66affSColin Finck #ifndef _STLP_STRING_C
25*c2c66affSColin Finck #define _STLP_STRING_C
26*c2c66affSColin Finck 
27*c2c66affSColin Finck #ifndef _STLP_INTERNAL_STRING_H
28*c2c66affSColin Finck #  include <stl/_string.h>
29*c2c66affSColin Finck #endif
30*c2c66affSColin Finck 
31*c2c66affSColin Finck #ifndef _STLP_INTERNAL_CTRAITS_FUNCTIONS_H
32*c2c66affSColin Finck #  include <stl/_ctraits_fns.h>
33*c2c66affSColin Finck #endif
34*c2c66affSColin Finck 
35*c2c66affSColin Finck #ifndef _STLP_INTERNAL_FUNCTION_H
36*c2c66affSColin Finck #  include <stl/_function.h>
37*c2c66affSColin Finck #endif
38*c2c66affSColin Finck 
39*c2c66affSColin Finck #if defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
40*c2c66affSColin Finck #  define basic_string _STLP_NO_MEM_T_NAME(str)
41*c2c66affSColin Finck #elif defined (_STLP_DEBUG)
42*c2c66affSColin Finck #  define basic_string _STLP_NON_DBG_NAME(str)
43*c2c66affSColin Finck #endif
44*c2c66affSColin Finck 
45*c2c66affSColin Finck #if defined (_STLP_NESTED_TYPE_PARAM_BUG)
46*c2c66affSColin Finck #  define __size_type__ size_t
47*c2c66affSColin Finck #  define size_type size_t
48*c2c66affSColin Finck #  define iterator _CharT*
49*c2c66affSColin Finck #else
50*c2c66affSColin Finck #  define __size_type__ _STLP_TYPENAME_ON_RETURN_TYPE basic_string<_CharT,_Traits,_Alloc>::size_type
51*c2c66affSColin Finck #endif
52*c2c66affSColin Finck 
53*c2c66affSColin Finck _STLP_BEGIN_NAMESPACE
54*c2c66affSColin Finck 
55*c2c66affSColin Finck _STLP_MOVE_TO_PRIV_NAMESPACE
56*c2c66affSColin Finck 
57*c2c66affSColin Finck // A helper class to use a char_traits as a function object.
58*c2c66affSColin Finck template <class _Traits>
59*c2c66affSColin Finck struct _Not_within_traits : public unary_function<typename _Traits::char_type, bool> {
60*c2c66affSColin Finck   typedef typename _Traits::char_type _CharT;
61*c2c66affSColin Finck   const _CharT* _M_first;
62*c2c66affSColin Finck   const _CharT* _M_last;
63*c2c66affSColin Finck 
_Not_within_traits_Not_within_traits64*c2c66affSColin Finck   _Not_within_traits(const _CharT* __f, const _CharT* __l)
65*c2c66affSColin Finck     : _M_first(__f), _M_last(__l) {}
66*c2c66affSColin Finck 
operator_Not_within_traits67*c2c66affSColin Finck   bool operator()(const _CharT& __x) const {
68*c2c66affSColin Finck     return find_if(_M_first, _M_last,
69*c2c66affSColin Finck                    _STLP_PRIV _Eq_char_bound<_Traits>(__x)) == _M_last;
70*c2c66affSColin Finck   }
71*c2c66affSColin Finck };
72*c2c66affSColin Finck 
73*c2c66affSColin Finck template <class _InputIter, class _CharT, class _Traits>
__str_find_first_of_aux(_InputIter __first1,_InputIter __last1,const _CharT * __first2,const _CharT * __last2,_Traits *,const __true_type &)74*c2c66affSColin Finck inline _InputIter __str_find_first_of_aux(_InputIter __first1, _InputIter __last1,
75*c2c66affSColin Finck                                           const _CharT* __first2, const _CharT* __last2,
76*c2c66affSColin Finck                                           _Traits*, const __true_type& /* _STLportTraits */)
77*c2c66affSColin Finck { return __find_first_of(__first1, __last1, __first2, __last2); }
78*c2c66affSColin Finck 
79*c2c66affSColin Finck template <class _InputIter, class _CharT, class _Traits>
__str_find_first_of_aux(_InputIter __first1,_InputIter __last1,const _CharT * __first2,const _CharT * __last2,_Traits *,const __false_type &)80*c2c66affSColin Finck inline _InputIter __str_find_first_of_aux(_InputIter __first1, _InputIter __last1,
81*c2c66affSColin Finck                                           const _CharT* __first2, const _CharT* __last2,
82*c2c66affSColin Finck                                           _Traits*, const __false_type& /* _STLportTraits */)
83*c2c66affSColin Finck { return __find_first_of(__first1, __last1, __first2, __last2, _STLP_PRIV _Eq_traits<_Traits>()); }
84*c2c66affSColin Finck 
85*c2c66affSColin Finck template <class _InputIter, class _CharT, class _Traits>
__str_find_first_of(_InputIter __first1,_InputIter __last1,const _CharT * __first2,const _CharT * __last2,_Traits * __traits)86*c2c66affSColin Finck inline _InputIter __str_find_first_of(_InputIter __first1, _InputIter __last1,
87*c2c66affSColin Finck                                       const _CharT* __first2, const _CharT* __last2,
88*c2c66affSColin Finck                                       _Traits* __traits) {
89*c2c66affSColin Finck #if !defined (__BORLANDC__)
90*c2c66affSColin Finck   typedef typename _IsSTLportClass<_Traits>::_Ret _STLportTraits;
91*c2c66affSColin Finck #else
92*c2c66affSColin Finck   enum { _Is = _IsSTLportClass<_Traits>::_Is };
93*c2c66affSColin Finck   typedef typename __bool2type<_Is>::_Ret _STLportTraits;
94*c2c66affSColin Finck #endif
95*c2c66affSColin Finck   return __str_find_first_of_aux(__first1, __last1, __first2, __last2, __traits, _STLportTraits());
96*c2c66affSColin Finck }
97*c2c66affSColin Finck 
98*c2c66affSColin Finck template <class _InputIter, class _CharT, class _Traits>
__str_find_first_not_of_aux3(_InputIter __first1,_InputIter __last1,const _CharT * __first2,const _CharT * __last2,_Traits *,const __true_type & __useStrcspnLikeAlgo)99*c2c66affSColin Finck inline _InputIter __str_find_first_not_of_aux3(_InputIter __first1, _InputIter __last1,
100*c2c66affSColin Finck                                                const _CharT* __first2, const _CharT* __last2,
101*c2c66affSColin Finck                                                _Traits* /* __traits */, const __true_type& __useStrcspnLikeAlgo)
102*c2c66affSColin Finck { return __find_first_of_aux2(__first1, __last1, __first2, __last2, __first2, not1(_Identity<bool>()), __useStrcspnLikeAlgo); }
103*c2c66affSColin Finck 
104*c2c66affSColin Finck template <class _InputIter, class _CharT, class _Traits>
__str_find_first_not_of_aux3(_InputIter __first1,_InputIter __last1,const _CharT * __first2,const _CharT * __last2,_Traits *,const __false_type &)105*c2c66affSColin Finck inline _InputIter __str_find_first_not_of_aux3(_InputIter __first1, _InputIter __last1,
106*c2c66affSColin Finck                                                const _CharT* __first2, const _CharT* __last2,
107*c2c66affSColin Finck                                                _Traits* /* __traits */, const __false_type& /* _UseStrcspnLikeAlgo */)
108*c2c66affSColin Finck { return _STLP_STD::find_if(__first1, __last1, _STLP_PRIV _Not_within_traits<_Traits>(__first2, __last2)); }
109*c2c66affSColin Finck 
110*c2c66affSColin Finck template <class _InputIter, class _CharT, class _Tp, class _Traits>
__str_find_first_not_of_aux2(_InputIter __first1,_InputIter __last1,const _CharT * __first2,const _CharT * __last2,_Tp * __pt,_Traits * __traits)111*c2c66affSColin Finck inline _InputIter __str_find_first_not_of_aux2(_InputIter __first1, _InputIter __last1,
112*c2c66affSColin Finck                                                const _CharT* __first2, const _CharT* __last2,
113*c2c66affSColin Finck                                                _Tp* __pt, _Traits* __traits) {
114*c2c66affSColin Finck   typedef typename _IsIntegral<_Tp>::_Ret _IsIntegral;
115*c2c66affSColin Finck   typedef typename _IsCharLikeType<_CharT>::_Ret _IsCharLike;
116*c2c66affSColin Finck   typedef typename _Land2<_IsIntegral, _IsCharLike>::_Ret _UseStrcspnLikeAlgo;
117*c2c66affSColin Finck   return __str_find_first_not_of_aux3(__first1, __last1, __first2, __last2, __traits, _UseStrcspnLikeAlgo());
118*c2c66affSColin Finck }
119*c2c66affSColin Finck 
120*c2c66affSColin Finck template <class _InputIter, class _CharT, class _Traits>
__str_find_first_not_of_aux1(_InputIter __first1,_InputIter __last1,const _CharT * __first2,const _CharT * __last2,_Traits * __traits,const __true_type &)121*c2c66affSColin Finck inline _InputIter __str_find_first_not_of_aux1(_InputIter __first1, _InputIter __last1,
122*c2c66affSColin Finck                                                const _CharT* __first2, const _CharT* __last2,
123*c2c66affSColin Finck                                                _Traits* __traits, const __true_type& /* _STLportTraits */)
124*c2c66affSColin Finck { return __str_find_first_not_of_aux2(__first1, __last1, __first2, __last2,
125*c2c66affSColin Finck                                       _STLP_VALUE_TYPE(__first1, _InputIter), __traits); }
126*c2c66affSColin Finck 
127*c2c66affSColin Finck template <class _InputIter, class _CharT, class _Traits>
__str_find_first_not_of_aux1(_InputIter __first1,_InputIter __last1,const _CharT * __first2,const _CharT * __last2,_Traits *,const __false_type &)128*c2c66affSColin Finck inline _InputIter __str_find_first_not_of_aux1(_InputIter __first1, _InputIter __last1,
129*c2c66affSColin Finck                                                const _CharT* __first2, const _CharT* __last2,
130*c2c66affSColin Finck                                                _Traits*, const __false_type& /* _STLportTraits */)
131*c2c66affSColin Finck { return _STLP_STD::find_if(__first1, __last1, _STLP_PRIV _Not_within_traits<_Traits>(__first2, __last2)); }
132*c2c66affSColin Finck 
133*c2c66affSColin Finck template <class _InputIter, class _CharT, class _Traits>
__str_find_first_not_of(_InputIter __first1,_InputIter __last1,const _CharT * __first2,const _CharT * __last2,_Traits * __traits)134*c2c66affSColin Finck inline _InputIter __str_find_first_not_of(_InputIter __first1, _InputIter __last1,
135*c2c66affSColin Finck                                           const _CharT* __first2, const _CharT* __last2,
136*c2c66affSColin Finck                                           _Traits* __traits) {
137*c2c66affSColin Finck #if !defined (__BORLANDC__)
138*c2c66affSColin Finck   typedef typename _IsSTLportClass<_Traits>::_Ret _STLportTraits;
139*c2c66affSColin Finck #else
140*c2c66affSColin Finck   enum { _Is = _IsSTLportClass<_Traits>::_Is };
141*c2c66affSColin Finck   typedef typename __bool2type<_Is>::_Ret _STLportTraits;
142*c2c66affSColin Finck #endif
143*c2c66affSColin Finck   return __str_find_first_not_of_aux1(__first1, __last1, __first2, __last2, __traits, _STLportTraits());
144*c2c66affSColin Finck }
145*c2c66affSColin Finck 
146*c2c66affSColin Finck // ------------------------------------------------------------
147*c2c66affSColin Finck // Non-inline declarations.
148*c2c66affSColin Finck 
149*c2c66affSColin Finck #if !defined (basic_string)
150*c2c66affSColin Finck _STLP_MOVE_TO_STD_NAMESPACE
151*c2c66affSColin Finck #endif
152*c2c66affSColin Finck 
153*c2c66affSColin Finck // Change the string's capacity so that it is large enough to hold
154*c2c66affSColin Finck //  at least __res_arg elements, plus the terminating _CharT().  Note that,
155*c2c66affSColin Finck //  if __res_arg < capacity(), this member function may actually decrease
156*c2c66affSColin Finck //  the string's capacity.
157*c2c66affSColin Finck template <class _CharT, class _Traits, class _Alloc>
reserve(size_type __res_arg)158*c2c66affSColin Finck void basic_string<_CharT,_Traits,_Alloc>::reserve(size_type __res_arg) {
159*c2c66affSColin Finck   if (__res_arg > max_size())
160*c2c66affSColin Finck     this->_M_throw_length_error();
161*c2c66affSColin Finck 
162*c2c66affSColin Finck   size_type __n = (max)(__res_arg, size()) + 1;
163*c2c66affSColin Finck   if (__n < this->_M_capacity())
164*c2c66affSColin Finck     return;
165*c2c66affSColin Finck 
166*c2c66affSColin Finck   _M_reserve(__n);
167*c2c66affSColin Finck }
168*c2c66affSColin Finck 
169*c2c66affSColin Finck template <class _CharT, class _Traits, class _Alloc>
_M_reserve(size_type __n)170*c2c66affSColin Finck void basic_string<_CharT,_Traits,_Alloc>::_M_reserve(size_type __n) {
171*c2c66affSColin Finck   pointer __new_start = this->_M_start_of_storage.allocate(__n, __n);
172*c2c66affSColin Finck   pointer __new_finish = _STLP_PRIV __ucopy(this->_M_Start(), this->_M_Finish(), __new_start);
173*c2c66affSColin Finck   _M_construct_null(__new_finish);
174*c2c66affSColin Finck   this->_M_deallocate_block();
175*c2c66affSColin Finck   this->_M_reset(__new_start, __new_finish, __new_start + __n);
176*c2c66affSColin Finck }
177*c2c66affSColin Finck 
178*c2c66affSColin Finck template <class _CharT, class _Traits, class _Alloc>
179*c2c66affSColin Finck basic_string<_CharT,_Traits,_Alloc>&
append(size_type __n,_CharT __c)180*c2c66affSColin Finck basic_string<_CharT,_Traits,_Alloc>::append(size_type __n, _CharT __c) {
181*c2c66affSColin Finck   if (__n > 0) {
182*c2c66affSColin Finck     if (__n > max_size() - size())
183*c2c66affSColin Finck       this->_M_throw_length_error();
184*c2c66affSColin Finck     if (__n >= this->_M_rest())
185*c2c66affSColin Finck       _M_reserve(_M_compute_next_size(__n));
186*c2c66affSColin Finck     _STLP_PRIV __uninitialized_fill_n(this->_M_finish + 1, __n - 1, __c);
187*c2c66affSColin Finck     _M_construct_null(this->_M_finish + __n);
188*c2c66affSColin Finck     _Traits::assign(*end(), __c);
189*c2c66affSColin Finck     this->_M_finish += __n;
190*c2c66affSColin Finck   }
191*c2c66affSColin Finck   return *this;
192*c2c66affSColin Finck }
193*c2c66affSColin Finck 
194*c2c66affSColin Finck template <class _CharT, class _Traits, class _Alloc>
195*c2c66affSColin Finck basic_string<_CharT, _Traits, _Alloc>&
_M_append(const _CharT * __first,const _CharT * __last)196*c2c66affSColin Finck basic_string<_CharT, _Traits, _Alloc>::_M_append(const _CharT* __first, const _CharT* __last) {
197*c2c66affSColin Finck   if (__first != __last) {
198*c2c66affSColin Finck     size_type __n = __STATIC_CAST(size_type, __last - __first);
199*c2c66affSColin Finck     if (__n >= this->_M_rest()) {
200*c2c66affSColin Finck       size_type __len = _M_compute_next_size(__n);
201*c2c66affSColin Finck       pointer __new_start = this->_M_start_of_storage.allocate(__len, __len);
202*c2c66affSColin Finck       pointer __new_finish = _STLP_PRIV __ucopy(this->_M_Start(), this->_M_Finish(), __new_start);
203*c2c66affSColin Finck       __new_finish = _STLP_PRIV __ucopy(__first, __last, __new_finish);
204*c2c66affSColin Finck       _M_construct_null(__new_finish);
205*c2c66affSColin Finck       this->_M_deallocate_block();
206*c2c66affSColin Finck       this->_M_reset(__new_start, __new_finish, __new_start + __len);
207*c2c66affSColin Finck     }
208*c2c66affSColin Finck     else {
209*c2c66affSColin Finck       const _CharT* __f1 = __first;
210*c2c66affSColin Finck       ++__f1;
211*c2c66affSColin Finck       _STLP_PRIV __ucopy(__f1, __last, this->_M_finish + 1);
212*c2c66affSColin Finck       _M_construct_null(this->_M_finish + __n);
213*c2c66affSColin Finck       _Traits::assign(*end(), *__first);
214*c2c66affSColin Finck       this->_M_finish += __n;
215*c2c66affSColin Finck     }
216*c2c66affSColin Finck   }
217*c2c66affSColin Finck   return *this;
218*c2c66affSColin Finck }
219*c2c66affSColin Finck 
220*c2c66affSColin Finck template <class _CharT, class _Traits, class _Alloc>
221*c2c66affSColin Finck basic_string<_CharT,_Traits,_Alloc>&
assign(size_type __n,_CharT __c)222*c2c66affSColin Finck basic_string<_CharT,_Traits,_Alloc>::assign(size_type __n, _CharT __c) {
223*c2c66affSColin Finck   if (__n <= size()) {
224*c2c66affSColin Finck     _Traits::assign(this->_M_Start(), __n, __c);
225*c2c66affSColin Finck     erase(begin() + __n, end());
226*c2c66affSColin Finck   }
227*c2c66affSColin Finck   else {
228*c2c66affSColin Finck     if (__n < capacity()) {
229*c2c66affSColin Finck       _Traits::assign(this->_M_Start(), size(), __c);
230*c2c66affSColin Finck       append(__n - size(), __c);
231*c2c66affSColin Finck     }
232*c2c66affSColin Finck     else {
233*c2c66affSColin Finck       _Self __str(__n, __c);
234*c2c66affSColin Finck       this->swap(__str);
235*c2c66affSColin Finck     }
236*c2c66affSColin Finck   }
237*c2c66affSColin Finck   return *this;
238*c2c66affSColin Finck }
239*c2c66affSColin Finck 
240*c2c66affSColin Finck template <class _CharT, class _Traits, class _Alloc>
241*c2c66affSColin Finck basic_string<_CharT,_Traits,_Alloc>&
_M_assign(const _CharT * __f,const _CharT * __l)242*c2c66affSColin Finck basic_string<_CharT,_Traits,_Alloc>::_M_assign(const _CharT* __f, const _CharT* __l) {
243*c2c66affSColin Finck   ptrdiff_t __n = __l - __f;
244*c2c66affSColin Finck   if (__STATIC_CAST(size_type, __n) <= size()) {
245*c2c66affSColin Finck     _Traits::copy(this->_M_Start(), __f, __n);
246*c2c66affSColin Finck     erase(begin() + __n, end());
247*c2c66affSColin Finck   }
248*c2c66affSColin Finck   else {
249*c2c66affSColin Finck     _Traits::copy(this->_M_Start(), __f, size());
250*c2c66affSColin Finck     _M_append(__f + size(), __l);
251*c2c66affSColin Finck   }
252*c2c66affSColin Finck   return *this;
253*c2c66affSColin Finck }
254*c2c66affSColin Finck 
255*c2c66affSColin Finck template <class _CharT, class _Traits, class _Alloc>
_M_insert_aux(_CharT * __p,_CharT __c)256*c2c66affSColin Finck _CharT* basic_string<_CharT,_Traits,_Alloc> ::_M_insert_aux(_CharT* __p,
257*c2c66affSColin Finck                                                             _CharT __c) {
258*c2c66affSColin Finck   pointer __new_pos = __p;
259*c2c66affSColin Finck   if (this->_M_rest() > 1 ) {
260*c2c66affSColin Finck     _M_construct_null(this->_M_finish + 1);
261*c2c66affSColin Finck     _Traits::move(__p + 1, __p, this->_M_finish - __p);
262*c2c66affSColin Finck     _Traits::assign(*__p, __c);
263*c2c66affSColin Finck     ++this->_M_finish;
264*c2c66affSColin Finck   }
265*c2c66affSColin Finck   else {
266*c2c66affSColin Finck     size_type __len = _M_compute_next_size(1);
267*c2c66affSColin Finck     pointer __new_start = this->_M_start_of_storage.allocate(__len, __len);
268*c2c66affSColin Finck     __new_pos = _STLP_PRIV __ucopy(this->_M_Start(), __p, __new_start);
269*c2c66affSColin Finck     _Traits::assign(*__new_pos, __c);
270*c2c66affSColin Finck     pointer __new_finish = __new_pos + 1;
271*c2c66affSColin Finck     __new_finish = _STLP_PRIV __ucopy(__p, this->_M_finish, __new_finish);
272*c2c66affSColin Finck     _M_construct_null(__new_finish);
273*c2c66affSColin Finck     this->_M_deallocate_block();
274*c2c66affSColin Finck     this->_M_reset(__new_start, __new_finish, __new_start + __len);
275*c2c66affSColin Finck   }
276*c2c66affSColin Finck   return __new_pos;
277*c2c66affSColin Finck }
278*c2c66affSColin Finck 
279*c2c66affSColin Finck template <class _CharT, class _Traits, class _Alloc>
insert(iterator __pos,size_t __n,_CharT __c)280*c2c66affSColin Finck void basic_string<_CharT,_Traits,_Alloc>::insert(iterator __pos,
281*c2c66affSColin Finck                                                  size_t __n, _CharT __c) {
282*c2c66affSColin Finck   if (__n != 0) {
283*c2c66affSColin Finck     if (this->_M_rest() > __n) {
284*c2c66affSColin Finck       const size_type __elems_after = this->_M_finish - __pos;
285*c2c66affSColin Finck       pointer __old_finish = this->_M_finish;
286*c2c66affSColin Finck       if (__elems_after >= __n) {
287*c2c66affSColin Finck         _STLP_PRIV __ucopy((this->_M_finish - __n) + 1, this->_M_finish + 1, this->_M_finish + 1);
288*c2c66affSColin Finck         this->_M_finish += __n;
289*c2c66affSColin Finck         _Traits::move(__pos + __n, __pos, (__elems_after - __n) + 1);
290*c2c66affSColin Finck         _Traits::assign(__pos, __n, __c);
291*c2c66affSColin Finck       }
292*c2c66affSColin Finck       else {
293*c2c66affSColin Finck         _STLP_PRIV __uninitialized_fill_n(this->_M_finish + 1, __n - __elems_after - 1, __c);
294*c2c66affSColin Finck         this->_M_finish += __n - __elems_after;
295*c2c66affSColin Finck         _STLP_PRIV __ucopy(__pos, __old_finish + 1, this->_M_finish);
296*c2c66affSColin Finck         this->_M_finish += __elems_after;
297*c2c66affSColin Finck         _Traits::assign(__pos, __elems_after + 1, __c);
298*c2c66affSColin Finck       }
299*c2c66affSColin Finck     }
300*c2c66affSColin Finck     else {
301*c2c66affSColin Finck       size_type __len = _M_compute_next_size(__n);
302*c2c66affSColin Finck       pointer __new_start = this->_M_start_of_storage.allocate(__len, __len);
303*c2c66affSColin Finck       pointer __new_finish = _STLP_PRIV __ucopy(this->_M_Start(), __pos, __new_start);
304*c2c66affSColin Finck       __new_finish = _STLP_PRIV __uninitialized_fill_n(__new_finish, __n, __c);
305*c2c66affSColin Finck       __new_finish = _STLP_PRIV __ucopy(__pos, this->_M_finish, __new_finish);
306*c2c66affSColin Finck       _M_construct_null(__new_finish);
307*c2c66affSColin Finck       this->_M_deallocate_block();
308*c2c66affSColin Finck       this->_M_reset(__new_start, __new_finish, __new_start + __len);
309*c2c66affSColin Finck     }
310*c2c66affSColin Finck   }
311*c2c66affSColin Finck }
312*c2c66affSColin Finck 
313*c2c66affSColin Finck template <class _CharT, class _Traits, class _Alloc>
_M_insert(iterator __pos,const _CharT * __first,const _CharT * __last,bool __self_ref)314*c2c66affSColin Finck void basic_string<_CharT,_Traits,_Alloc>::_M_insert(iterator __pos,
315*c2c66affSColin Finck                                                     const _CharT* __first, const _CharT* __last,
316*c2c66affSColin Finck                                                     bool __self_ref) {
317*c2c66affSColin Finck   //this version has to take care about the auto referencing
318*c2c66affSColin Finck   if (__first != __last) {
319*c2c66affSColin Finck     const size_t __n = __last - __first;
320*c2c66affSColin Finck     if (this->_M_rest() > __n) {
321*c2c66affSColin Finck       const size_t __elems_after = this->_M_finish - __pos;
322*c2c66affSColin Finck       pointer __old_finish = this->_M_finish;
323*c2c66affSColin Finck       if (__elems_after >= __n) {
324*c2c66affSColin Finck         _STLP_PRIV __ucopy((this->_M_finish - __n) + 1, this->_M_finish + 1, this->_M_finish + 1);
325*c2c66affSColin Finck         this->_M_finish += __n;
326*c2c66affSColin Finck         _Traits::move(__pos + __n, __pos, (__elems_after - __n) + 1);
327*c2c66affSColin Finck         if (!__self_ref || __last < __pos) {
328*c2c66affSColin Finck           _M_copy(__first, __last, __pos);
329*c2c66affSColin Finck         }
330*c2c66affSColin Finck         else {
331*c2c66affSColin Finck           //We have to check that the source buffer hasn't move
332*c2c66affSColin Finck           if (__first >= __pos) {
333*c2c66affSColin Finck             //The source buffer has move
334*c2c66affSColin Finck             __first += __n;
335*c2c66affSColin Finck             __last += __n;
336*c2c66affSColin Finck             _M_copy(__first, __last, __pos);
337*c2c66affSColin Finck           }
338*c2c66affSColin Finck           else {
339*c2c66affSColin Finck             //The source buffer hasn't move, it has been duplicated
340*c2c66affSColin Finck             _M_move(__first, __last, __pos);
341*c2c66affSColin Finck           }
342*c2c66affSColin Finck         }
343*c2c66affSColin Finck       }
344*c2c66affSColin Finck       else {
345*c2c66affSColin Finck         const_iterator __mid = __first;
346*c2c66affSColin Finck         __mid += __elems_after + 1;
347*c2c66affSColin Finck         _STLP_PRIV __ucopy(__mid, __last, this->_M_finish + 1);
348*c2c66affSColin Finck         this->_M_finish += __n - __elems_after;
349*c2c66affSColin Finck         _STLP_PRIV __ucopy(__pos, __old_finish + 1, this->_M_finish);
350*c2c66affSColin Finck         this->_M_finish += __elems_after;
351*c2c66affSColin Finck         if (!__self_ref)
352*c2c66affSColin Finck           _M_copy(__first, __mid, __pos);
353*c2c66affSColin Finck         else
354*c2c66affSColin Finck           _M_move(__first, __mid, __pos);
355*c2c66affSColin Finck       }
356*c2c66affSColin Finck     }
357*c2c66affSColin Finck     else {
358*c2c66affSColin Finck       size_type __len = _M_compute_next_size(__n);
359*c2c66affSColin Finck       pointer __new_start = this->_M_start_of_storage.allocate(__len, __len);
360*c2c66affSColin Finck       pointer __new_finish = _STLP_PRIV __ucopy(this->_M_Start(), __pos, __new_start);
361*c2c66affSColin Finck       __new_finish = _STLP_PRIV __ucopy(__first, __last, __new_finish);
362*c2c66affSColin Finck       __new_finish = _STLP_PRIV __ucopy(__pos, this->_M_finish, __new_finish);
363*c2c66affSColin Finck       _M_construct_null(__new_finish);
364*c2c66affSColin Finck       this->_M_deallocate_block();
365*c2c66affSColin Finck       this->_M_reset(__new_start, __new_finish, __new_start + __len);
366*c2c66affSColin Finck     }
367*c2c66affSColin Finck   }
368*c2c66affSColin Finck }
369*c2c66affSColin Finck 
370*c2c66affSColin Finck template <class _CharT, class _Traits, class _Alloc>
371*c2c66affSColin Finck basic_string<_CharT,_Traits,_Alloc>&
replace(iterator __first,iterator __last,size_type __n,_CharT __c)372*c2c66affSColin Finck basic_string<_CharT,_Traits,_Alloc> ::replace(iterator __first, iterator __last,
373*c2c66affSColin Finck                                               size_type __n, _CharT __c) {
374*c2c66affSColin Finck   size_type __len = (size_type)(__last - __first);
375*c2c66affSColin Finck 
376*c2c66affSColin Finck   if (__len >= __n) {
377*c2c66affSColin Finck     _Traits::assign(__first, __n, __c);
378*c2c66affSColin Finck     erase(__first + __n, __last);
379*c2c66affSColin Finck   }
380*c2c66affSColin Finck   else {
381*c2c66affSColin Finck     _Traits::assign(__first, __len, __c);
382*c2c66affSColin Finck     insert(__last, __n - __len, __c);
383*c2c66affSColin Finck   }
384*c2c66affSColin Finck   return *this;
385*c2c66affSColin Finck }
386*c2c66affSColin Finck 
387*c2c66affSColin Finck template <class _CharT, class _Traits, class _Alloc>
388*c2c66affSColin Finck basic_string<_CharT,_Traits,_Alloc>&
_M_replace(iterator __first,iterator __last,const _CharT * __f,const _CharT * __l,bool __self_ref)389*c2c66affSColin Finck basic_string<_CharT,_Traits,_Alloc> ::_M_replace(iterator __first, iterator __last,
390*c2c66affSColin Finck                                                  const _CharT* __f, const _CharT* __l,
391*c2c66affSColin Finck                                                  bool __self_ref) {
392*c2c66affSColin Finck   const ptrdiff_t       __n = __l - __f;
393*c2c66affSColin Finck   const difference_type __len = __last - __first;
394*c2c66affSColin Finck   if (__len >= __n) {
395*c2c66affSColin Finck     if (!__self_ref || __l < __first || __f >= __last)
396*c2c66affSColin Finck       _M_copy(__f, __l, __first);
397*c2c66affSColin Finck     else
398*c2c66affSColin Finck       _M_move(__f, __l, __first);
399*c2c66affSColin Finck     erase(__first + __n, __last);
400*c2c66affSColin Finck   } else if (!__self_ref || (__f >= __last) || (__l <= __first)) { // no overlap
401*c2c66affSColin Finck     const_iterator __m = __f + __len;
402*c2c66affSColin Finck     _M_copy(__f, __m, __first);
403*c2c66affSColin Finck     _M_insert(__last, __m, __l, __self_ref );
404*c2c66affSColin Finck   } else if (__f < __first) { // we have to take care of overlaping
405*c2c66affSColin Finck     const_iterator __m = __f + __len;
406*c2c66affSColin Finck     // We have to deal with possible reallocation because we do insert first.
407*c2c66affSColin Finck     const difference_type __off_dest = __first - this->begin();
408*c2c66affSColin Finck     const difference_type __off_src = __f - this->begin();
409*c2c66affSColin Finck     _M_insert(__last, __m, __l, true);
410*c2c66affSColin Finck     _Traits::move(begin() + __off_dest, begin() + __off_src, __len);
411*c2c66affSColin Finck   } else {
412*c2c66affSColin Finck     const_iterator __m = __f + __len;
413*c2c66affSColin Finck     _Traits::move(__first, __f, __len);
414*c2c66affSColin Finck     _M_insert(__last, __m, __l, true);
415*c2c66affSColin Finck   }
416*c2c66affSColin Finck   return *this;
417*c2c66affSColin Finck }
418*c2c66affSColin Finck 
419*c2c66affSColin Finck template <class _CharT, class _Traits, class _Alloc>
find(const _CharT * __s,size_type __pos,size_type __n)420*c2c66affSColin Finck __size_type__ basic_string<_CharT,_Traits,_Alloc>::find( const _CharT* __s, size_type __pos,
421*c2c66affSColin Finck                                                          size_type __n) const
422*c2c66affSColin Finck {
423*c2c66affSColin Finck   const size_t __len = size();
424*c2c66affSColin Finck   if (__pos >= __len || __pos + __n > __len) {
425*c2c66affSColin Finck     if ( __n == 0 && __pos <= __len ) { // marginal case
426*c2c66affSColin Finck       return __pos;
427*c2c66affSColin Finck     }
428*c2c66affSColin Finck     return npos;
429*c2c66affSColin Finck   }
430*c2c66affSColin Finck 
431*c2c66affSColin Finck   const_pointer __result =
432*c2c66affSColin Finck     _STLP_STD::search(this->_M_Start() + __pos, this->_M_Finish(),
433*c2c66affSColin Finck                       __s, __s + __n, _STLP_PRIV _Eq_traits<_Traits>());
434*c2c66affSColin Finck   return __result != this->_M_Finish() ? __result - this->_M_Start() : npos;
435*c2c66affSColin Finck }
436*c2c66affSColin Finck 
437*c2c66affSColin Finck template <class _CharT, class _Traits, class _Alloc>
find(_CharT __c,size_type __pos)438*c2c66affSColin Finck __size_type__ basic_string<_CharT,_Traits,_Alloc>::find(_CharT __c, size_type __pos) const
439*c2c66affSColin Finck {
440*c2c66affSColin Finck   if (__pos >= size()) { /*__pos + 1 > size()*/
441*c2c66affSColin Finck     return npos;
442*c2c66affSColin Finck   }
443*c2c66affSColin Finck 
444*c2c66affSColin Finck   const_pointer __result =
445*c2c66affSColin Finck     _STLP_STD::find_if(this->_M_Start() + __pos, this->_M_Finish(),
446*c2c66affSColin Finck                        _STLP_PRIV _Eq_char_bound<_Traits>(__c));
447*c2c66affSColin Finck   return __result != this->_M_Finish() ? __result - this->_M_Start() : npos;
448*c2c66affSColin Finck }
449*c2c66affSColin Finck 
450*c2c66affSColin Finck template <class _CharT, class _Traits, class _Alloc>
rfind(const _CharT * __s,size_type __pos,size_type __n)451*c2c66affSColin Finck __size_type__ basic_string<_CharT,_Traits,_Alloc>::rfind(const _CharT* __s, size_type __pos,
452*c2c66affSColin Finck                                                          size_type __n) const
453*c2c66affSColin Finck {
454*c2c66affSColin Finck   const size_type __len = size();
455*c2c66affSColin Finck   if ( __len < __n ) {
456*c2c66affSColin Finck     return npos;
457*c2c66affSColin Finck   }
458*c2c66affSColin Finck   const_pointer __last = this->_M_Start() + (min)( __len - __n, __pos) + __n;
459*c2c66affSColin Finck   if ( __n == 0 ) { // marginal case
460*c2c66affSColin Finck     return __last - this->_M_Start();
461*c2c66affSColin Finck   }
462*c2c66affSColin Finck   const_pointer __result = _STLP_STD::find_end(this->_M_Start(), __last,
463*c2c66affSColin Finck                                                __s, __s + __n, _STLP_PRIV _Eq_traits<_Traits>());
464*c2c66affSColin Finck   return __result != __last ? __result - this->_M_Start() : npos;
465*c2c66affSColin Finck }
466*c2c66affSColin Finck 
467*c2c66affSColin Finck template <class _CharT, class _Traits, class _Alloc>
rfind(_CharT __c,size_type __pos)468*c2c66affSColin Finck __size_type__ basic_string<_CharT,_Traits,_Alloc>::rfind(_CharT __c, size_type __pos) const
469*c2c66affSColin Finck {
470*c2c66affSColin Finck   const size_type __len = size();
471*c2c66affSColin Finck   if ( __len < 1 ) {
472*c2c66affSColin Finck     return npos;
473*c2c66affSColin Finck   }
474*c2c66affSColin Finck   const_iterator __last = begin() + (min)(__len - 1, __pos) + 1;
475*c2c66affSColin Finck   const_reverse_iterator __rresult =
476*c2c66affSColin Finck     _STLP_STD::find_if(const_reverse_iterator(__last), rend(),
477*c2c66affSColin Finck                        _STLP_PRIV _Eq_char_bound<_Traits>(__c));
478*c2c66affSColin Finck   return __rresult != rend() ? (__rresult.base() - 1) - begin() : npos;
479*c2c66affSColin Finck }
480*c2c66affSColin Finck 
481*c2c66affSColin Finck template <class _CharT, class _Traits, class _Alloc> __size_type__
find_first_of(const _CharT * __s,size_type __pos,size_type __n)482*c2c66affSColin Finck basic_string<_CharT,_Traits,_Alloc> ::find_first_of(const _CharT* __s, size_type __pos,
483*c2c66affSColin Finck                                                     size_type __n) const {
484*c2c66affSColin Finck   if (__pos >= size()) /*__pos + 1 > size()*/
485*c2c66affSColin Finck     return npos;
486*c2c66affSColin Finck   else {
487*c2c66affSColin Finck     const_iterator __result = _STLP_PRIV __str_find_first_of(begin() + __pos, end(),
488*c2c66affSColin Finck                                                              __s, __s + __n,
489*c2c66affSColin Finck                                                              __STATIC_CAST(_Traits*, 0));
490*c2c66affSColin Finck     return __result != end() ? __result - begin() : npos;
491*c2c66affSColin Finck   }
492*c2c66affSColin Finck }
493*c2c66affSColin Finck 
494*c2c66affSColin Finck template <class _CharT, class _Traits, class _Alloc>
495*c2c66affSColin Finck  __size_type__
find_last_of(const _CharT * __s,size_type __pos,size_type __n)496*c2c66affSColin Finck basic_string<_CharT,_Traits,_Alloc> ::find_last_of(const _CharT* __s, size_type __pos,
497*c2c66affSColin Finck                                                    size_type __n) const
498*c2c66affSColin Finck {
499*c2c66affSColin Finck   const size_type __len = size();
500*c2c66affSColin Finck   if ( __len < 1 ) {
501*c2c66affSColin Finck     return npos;
502*c2c66affSColin Finck   }
503*c2c66affSColin Finck   const const_iterator __last = begin() + (min)(__len - 1, __pos) + 1;
504*c2c66affSColin Finck   const const_reverse_iterator __rresult =
505*c2c66affSColin Finck     _STLP_PRIV __str_find_first_of(const_reverse_iterator(__last), rend(),
506*c2c66affSColin Finck                                    __s, __s + __n,
507*c2c66affSColin Finck                                    __STATIC_CAST(_Traits*, 0));
508*c2c66affSColin Finck   return __rresult != rend() ? (__rresult.base() - 1) - begin() : npos;
509*c2c66affSColin Finck }
510*c2c66affSColin Finck 
511*c2c66affSColin Finck 
512*c2c66affSColin Finck template <class _CharT, class _Traits, class _Alloc> __size_type__
find_first_not_of(const _CharT * __s,size_type __pos,size_type __n)513*c2c66affSColin Finck basic_string<_CharT,_Traits,_Alloc> ::find_first_not_of(const _CharT* __s, size_type __pos,
514*c2c66affSColin Finck                                                         size_type __n) const {
515*c2c66affSColin Finck   typedef typename _Traits::char_type _CharType;
516*c2c66affSColin Finck   if (__pos >= size()) /*__pos + 1 >= size()*/
517*c2c66affSColin Finck     return npos;
518*c2c66affSColin Finck   else {
519*c2c66affSColin Finck     const_pointer __result = _STLP_PRIV __str_find_first_not_of(this->_M_Start() + __pos, this->_M_Finish(),
520*c2c66affSColin Finck                                                                 __STATIC_CAST(const _CharType*, __s),
521*c2c66affSColin Finck                                                                 __STATIC_CAST(const _CharType*, __s) + __n,
522*c2c66affSColin Finck                                                                 __STATIC_CAST(_Traits*, 0));
523*c2c66affSColin Finck     return __result != this->_M_finish ? __result - this->_M_Start() : npos;
524*c2c66affSColin Finck   }
525*c2c66affSColin Finck }
526*c2c66affSColin Finck 
527*c2c66affSColin Finck template <class _CharT, class _Traits, class _Alloc> __size_type__
find_first_not_of(_CharT __c,size_type __pos)528*c2c66affSColin Finck basic_string<_CharT,_Traits,_Alloc> ::find_first_not_of(_CharT __c, size_type __pos) const {
529*c2c66affSColin Finck   if (1 > size())
530*c2c66affSColin Finck     return npos;
531*c2c66affSColin Finck   else {
532*c2c66affSColin Finck     const_pointer __result = _STLP_STD::find_if(this->_M_Start() + __pos, this->_M_Finish(),
533*c2c66affSColin Finck                                                 _STLP_PRIV _Neq_char_bound<_Traits>(__c));
534*c2c66affSColin Finck     return __result != this->_M_finish ? __result - this->_M_Start() : npos;
535*c2c66affSColin Finck   }
536*c2c66affSColin Finck }
537*c2c66affSColin Finck 
538*c2c66affSColin Finck template <class _CharT, class _Traits, class _Alloc>
539*c2c66affSColin Finck __size_type__
find_last_not_of(const _CharT * __s,size_type __pos,size_type __n)540*c2c66affSColin Finck basic_string<_CharT,_Traits,_Alloc>::find_last_not_of(const _CharT* __s, size_type __pos, size_type __n) const
541*c2c66affSColin Finck {
542*c2c66affSColin Finck   typedef typename _Traits::char_type _CharType;
543*c2c66affSColin Finck   const size_type __len = size();
544*c2c66affSColin Finck   if ( __len < 1 ) {
545*c2c66affSColin Finck     return npos;
546*c2c66affSColin Finck   }
547*c2c66affSColin Finck   const_iterator __last = begin() + (min)(__len - 1, __pos) + 1;
548*c2c66affSColin Finck   const_reverse_iterator __rlast = const_reverse_iterator(__last);
549*c2c66affSColin Finck   const_reverse_iterator __rresult =
550*c2c66affSColin Finck     _STLP_PRIV __str_find_first_not_of(__rlast, rend(),
551*c2c66affSColin Finck                                        __STATIC_CAST(const _CharType*, __s),
552*c2c66affSColin Finck                                        __STATIC_CAST(const _CharType*, __s) + __n,
553*c2c66affSColin Finck                                        __STATIC_CAST(_Traits*, 0));
554*c2c66affSColin Finck   return __rresult != rend() ? (__rresult.base() - 1) - begin() : npos;
555*c2c66affSColin Finck }
556*c2c66affSColin Finck 
557*c2c66affSColin Finck template <class _CharT, class _Traits, class _Alloc>
558*c2c66affSColin Finck __size_type__
find_last_not_of(_CharT __c,size_type __pos)559*c2c66affSColin Finck basic_string<_CharT, _Traits, _Alloc>::find_last_not_of(_CharT __c, size_type __pos) const
560*c2c66affSColin Finck {
561*c2c66affSColin Finck   const size_type __len = size();
562*c2c66affSColin Finck   if ( __len < 1 ) {
563*c2c66affSColin Finck     return npos;
564*c2c66affSColin Finck   }
565*c2c66affSColin Finck   const_iterator __last = begin() + (min)(__len - 1, __pos) + 1;
566*c2c66affSColin Finck   const_reverse_iterator __rlast = const_reverse_iterator(__last);
567*c2c66affSColin Finck   const_reverse_iterator __rresult =
568*c2c66affSColin Finck     _STLP_STD::find_if(__rlast, rend(),
569*c2c66affSColin Finck                        _STLP_PRIV _Neq_char_bound<_Traits>(__c));
570*c2c66affSColin Finck   return __rresult != rend() ? (__rresult.base() - 1) - begin() : npos;
571*c2c66affSColin Finck }
572*c2c66affSColin Finck 
573*c2c66affSColin Finck #if !defined (basic_string)
574*c2c66affSColin Finck _STLP_MOVE_TO_PRIV_NAMESPACE
575*c2c66affSColin Finck #endif
576*c2c66affSColin Finck 
577*c2c66affSColin Finck template <class _CharT, class _Traits, class _Alloc>
_S_string_copy(const basic_string<_CharT,_Traits,_Alloc> & __s,_CharT * __buf,size_t __n)578*c2c66affSColin Finck void _STLP_CALL _S_string_copy(const basic_string<_CharT,_Traits,_Alloc>& __s,
579*c2c66affSColin Finck                                _CharT* __buf, size_t __n) {
580*c2c66affSColin Finck   if (__n > 0) {
581*c2c66affSColin Finck     __n = (min) (__n - 1, __s.size());
582*c2c66affSColin Finck     _STLP_STD::copy(__s.begin(), __s.begin() + __n, __buf);
583*c2c66affSColin Finck     __buf[__n] = _CharT();
584*c2c66affSColin Finck   }
585*c2c66affSColin Finck }
586*c2c66affSColin Finck 
587*c2c66affSColin Finck _STLP_MOVE_TO_STD_NAMESPACE
588*c2c66affSColin Finck 
589*c2c66affSColin Finck _STLP_END_NAMESPACE
590*c2c66affSColin Finck 
591*c2c66affSColin Finck #include <stl/_range_errors.h>
592*c2c66affSColin Finck 
593*c2c66affSColin Finck _STLP_BEGIN_NAMESPACE
594*c2c66affSColin Finck 
595*c2c66affSColin Finck _STLP_MOVE_TO_PRIV_NAMESPACE
596*c2c66affSColin Finck 
597*c2c66affSColin Finck // _String_base methods
598*c2c66affSColin Finck template <class _Tp, class _Alloc>
_M_throw_length_error()599*c2c66affSColin Finck void _String_base<_Tp,_Alloc>::_M_throw_length_error() const
600*c2c66affSColin Finck { __stl_throw_length_error("basic_string"); }
601*c2c66affSColin Finck 
602*c2c66affSColin Finck template <class _Tp, class _Alloc>
_M_throw_out_of_range()603*c2c66affSColin Finck void _String_base<_Tp, _Alloc>::_M_throw_out_of_range() const
604*c2c66affSColin Finck { __stl_throw_out_of_range("basic_string"); }
605*c2c66affSColin Finck 
606*c2c66affSColin Finck template <class _Tp, class _Alloc>
_M_allocate_block(size_t __n)607*c2c66affSColin Finck void _String_base<_Tp, _Alloc>::_M_allocate_block(size_t __n) {
608*c2c66affSColin Finck   if ((__n <= (max_size() + 1)) && (__n > 0)) {
609*c2c66affSColin Finck #if defined (_STLP_USE_SHORT_STRING_OPTIM)
610*c2c66affSColin Finck     if (__n > _DEFAULT_SIZE) {
611*c2c66affSColin Finck       this->_M_start_of_storage._M_data = _M_start_of_storage.allocate(__n, __n);
612*c2c66affSColin Finck       this->_M_finish = this->_M_start_of_storage._M_data;
613*c2c66affSColin Finck       this->_M_buffers._M_end_of_storage = this->_M_start_of_storage._M_data + __n;
614*c2c66affSColin Finck     }
615*c2c66affSColin Finck #else
616*c2c66affSColin Finck     this->_M_start_of_storage._M_data = _M_start_of_storage.allocate(__n, __n);
617*c2c66affSColin Finck     this->_M_finish = this->_M_start_of_storage._M_data;
618*c2c66affSColin Finck     this->_M_end_of_storage = this->_M_start_of_storage._M_data + __n;
619*c2c66affSColin Finck #endif
620*c2c66affSColin Finck   } else {
621*c2c66affSColin Finck     this->_M_throw_length_error();
622*c2c66affSColin Finck   }
623*c2c66affSColin Finck }
624*c2c66affSColin Finck 
625*c2c66affSColin Finck #if !defined (basic_string)
626*c2c66affSColin Finck _STLP_MOVE_TO_STD_NAMESPACE
627*c2c66affSColin Finck #endif
628*c2c66affSColin Finck 
629*c2c66affSColin Finck #if defined (_STLP_DONT_SUP_DFLT_PARAM)
630*c2c66affSColin Finck template <class _CharT, class _Traits, class _Alloc>
basic_string(const _CharT * __s)631*c2c66affSColin Finck basic_string<_CharT, _Traits, _Alloc>::basic_string(const _CharT* __s)
632*c2c66affSColin Finck   : _STLP_PRIV _String_base<_CharT,_Alloc>(allocator_type()) {
633*c2c66affSColin Finck   _STLP_FIX_LITERAL_BUG(__s)
634*c2c66affSColin Finck   _M_range_initialize(__s, __s + traits_type::length(__s));
635*c2c66affSColin Finck }
636*c2c66affSColin Finck #endif
637*c2c66affSColin Finck 
638*c2c66affSColin Finck template <class _CharT, class _Traits, class _Alloc>
basic_string(const _CharT * __s,const allocator_type & __a)639*c2c66affSColin Finck basic_string<_CharT, _Traits, _Alloc>::basic_string(const _CharT* __s,
640*c2c66affSColin Finck                                                     const allocator_type& __a)
641*c2c66affSColin Finck   : _STLP_PRIV _String_base<_CharT,_Alloc>(__a) {
642*c2c66affSColin Finck   _STLP_FIX_LITERAL_BUG(__s)
643*c2c66affSColin Finck   _M_range_initialize(__s, __s + traits_type::length(__s));
644*c2c66affSColin Finck }
645*c2c66affSColin Finck 
646*c2c66affSColin Finck template <class _CharT, class _Traits, class _Alloc>
basic_string(const basic_string<_CharT,_Traits,_Alloc> & __s)647*c2c66affSColin Finck basic_string<_CharT, _Traits, _Alloc>::basic_string(const basic_string<_CharT, _Traits, _Alloc> & __s)
648*c2c66affSColin Finck   : _STLP_PRIV _String_base<_CharT,_Alloc>(__s.get_allocator())
649*c2c66affSColin Finck { _M_range_initialize(__s._M_Start(), __s._M_Finish()); }
650*c2c66affSColin Finck 
651*c2c66affSColin Finck #if defined (basic_string)
652*c2c66affSColin Finck _STLP_MOVE_TO_STD_NAMESPACE
653*c2c66affSColin Finck #  undef basic_string
654*c2c66affSColin Finck #endif
655*c2c66affSColin Finck 
656*c2c66affSColin Finck #if !defined (_STLP_STATIC_CONST_INIT_BUG) && !defined (_STLP_NO_STATIC_CONST_DEFINITION)
657*c2c66affSColin Finck template <class _CharT, class _Traits, class _Alloc>
658*c2c66affSColin Finck const size_t basic_string<_CharT, _Traits, _Alloc>::npos;
659*c2c66affSColin Finck #endif
660*c2c66affSColin Finck 
661*c2c66affSColin Finck _STLP_END_NAMESPACE
662*c2c66affSColin Finck 
663*c2c66affSColin Finck #undef __size_type__
664*c2c66affSColin Finck #if defined (_STLP_NESTED_TYPE_PARAM_BUG)
665*c2c66affSColin Finck #  undef size_type
666*c2c66affSColin Finck #  undef iterator
667*c2c66affSColin Finck #endif
668*c2c66affSColin Finck 
669*c2c66affSColin Finck #endif /*  _STLP_STRING_C */
670*c2c66affSColin Finck 
671*c2c66affSColin Finck // Local Variables:
672*c2c66affSColin Finck // mode:C++
673*c2c66affSColin Finck // End:
674