5 * Hewlett-Packard Company
7 * Copyright (c) 1996,1997
8 * Silicon Graphics Computer Systems, Inc.
11 * Moscow Center for SPARC Technology
16 * This material is provided "as is", with absolutely no warranty expressed
17 * or implied. Any use is at your own risk.
19 * Permission to use or copy this software for any purpose is hereby granted
20 * without fee, provided the above notices are retained on all copies.
21 * Permission to modify the code and to distribute modified code is granted,
22 * provided the above notices are retained, and a notice that the code was
23 * modified is included with the above copyright notice.
26 #ifndef _STLP_STRING_C
27 #define _STLP_STRING_C
29 #ifndef _STLP_INTERNAL_STRING_H
30 # include <stl/_string.h>
33 #ifndef _STLP_INTERNAL_CTRAITS_FUNCTIONS_H
34 # include <stl/_ctraits_fns.h>
37 #if defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
38 # define basic_string _STLP_NO_MEM_T_NAME(str)
39 #elif defined (_STLP_DEBUG)
40 # define basic_string _STLP_NON_DBG_NAME(str)
43 #if defined (_STLP_NESTED_TYPE_PARAM_BUG)
44 # define __size_type__ size_t
45 # define size_type size_t
46 # define iterator _CharT*
48 # define __size_type__ _STLP_TYPENAME_ON_RETURN_TYPE basic_string<_CharT,_Traits,_Alloc>::size_type
53 _STLP_MOVE_TO_PRIV_NAMESPACE
55 // A helper class to use a char_traits as a function object.
56 template <class _Traits>
57 struct _Not_within_traits : public unary_function<typename _Traits::char_type, bool> {
58 typedef typename _Traits::char_type _CharT;
59 const _CharT* _M_first;
60 const _CharT* _M_last;
62 _Not_within_traits(const _CharT* __f, const _CharT* __l)
63 : _M_first(__f), _M_last(__l) {}
65 bool operator()(const _CharT& __x) const {
66 return find_if(_M_first, _M_last,
67 _STLP_PRIV _Eq_char_bound<_Traits>(__x)) == _M_last;
71 // ------------------------------------------------------------
72 // Non-inline declarations.
74 #if !defined (basic_string)
75 _STLP_MOVE_TO_STD_NAMESPACE
78 // Change the string's capacity so that it is large enough to hold
79 // at least __res_arg elements, plus the terminating _CharT(). Note that,
80 // if __res_arg < capacity(), this member function may actually decrease
81 // the string's capacity.
82 template <class _CharT, class _Traits, class _Alloc>
83 void basic_string<_CharT,_Traits,_Alloc>::reserve(size_type __res_arg) {
84 if (__res_arg > max_size())
85 this->_M_throw_length_error();
87 size_type __n = (max)(__res_arg, size()) + 1;
88 if (__n <= capacity() + 1)
91 pointer __new_start = this->_M_end_of_storage.allocate(__n, __n);
92 pointer __new_finish = __new_start;
95 __new_finish = _STLP_PRIV __ucopy(this->_M_Start(), this->_M_Finish(), __new_start);
96 _M_construct_null(__new_finish);
98 _STLP_UNWIND((_STLP_STD::_Destroy_Range(__new_start, __new_finish),
99 this->_M_end_of_storage.deallocate(__new_start, __n)))
101 this->_M_destroy_range();
102 this->_M_deallocate_block();
103 this->_M_reset(__new_start, __new_finish, __new_start + __n);
106 template <class _CharT, class _Traits, class _Alloc>
107 basic_string<_CharT,_Traits,_Alloc>&
108 basic_string<_CharT,_Traits,_Alloc>::append(size_type __n, _CharT __c) {
109 if (__n > max_size() || size() > max_size() - __n)
110 this->_M_throw_length_error();
111 if (size() + __n > capacity())
112 reserve(size() + (max)(size(), __n));
114 #if defined (_STLP_USE_SHORT_STRING_OPTIM)
115 if (this->_M_using_static_buf())
116 _Traits::assign(this->_M_finish + 1, __n - 1, __c);
118 #endif /* _STLP_USE_SHORT_STRING_OPTIM */
119 _STLP_PRIV __uninitialized_fill_n(this->_M_finish + 1, __n - 1, __c);
121 _M_construct_null(this->_M_finish + __n);
123 _STLP_UNWIND(this->_M_destroy_ptr_range(this->_M_finish + 1, this->_M_finish + __n))
124 _Traits::assign(*end(), __c);
125 this->_M_finish += __n;
130 template <class _CharT, class _Traits, class _Alloc>
131 basic_string<_CharT, _Traits, _Alloc>&
132 basic_string<_CharT, _Traits, _Alloc>::_M_append(const _CharT* __first, const _CharT* __last) {
133 if (__first != __last) {
134 const size_type __old_size = size();
135 ptrdiff_t __n = __last - __first;
136 if ((size_type)__n > max_size() || __old_size > max_size() - __n)
137 this->_M_throw_length_error();
138 if (__old_size + __n > capacity()) {
139 size_type __len = __old_size + (max)(__old_size, (size_t) __n) + 1;
140 pointer __new_start = this->_M_end_of_storage.allocate(__len, __len);
141 pointer __new_finish = __new_start;
143 __new_finish = _STLP_PRIV __ucopy(this->_M_Start(), this->_M_Finish(), __new_start);
144 __new_finish = _STLP_PRIV __ucopy(__first, __last, __new_finish);
145 _M_construct_null(__new_finish);
147 _STLP_UNWIND((_STLP_STD::_Destroy_Range(__new_start,__new_finish),
148 this->_M_end_of_storage.deallocate(__new_start,__len)))
149 this->_M_destroy_range();
150 this->_M_deallocate_block();
151 this->_M_reset(__new_start, __new_finish, __new_start + __len);
154 const _CharT* __f1 = __first;
156 #if defined (_STLP_USE_SHORT_STRING_OPTIM)
157 if (this->_M_using_static_buf())
158 _M_copy(__f1, __last, this->_M_Finish() + 1);
160 #endif /* _STLP_USE_SHORT_STRING_OPTIM */
161 _STLP_PRIV __ucopy(__f1, __last, this->_M_finish + 1);
163 _M_construct_null(this->_M_finish + __n);
165 _STLP_UNWIND(this->_M_destroy_ptr_range(this->_M_finish + 1, this->_M_finish + __n))
166 _Traits::assign(*end(), *__first);
167 this->_M_finish += __n;
173 template <class _CharT, class _Traits, class _Alloc>
174 basic_string<_CharT,_Traits,_Alloc>&
175 basic_string<_CharT,_Traits,_Alloc>::assign(size_type __n, _CharT __c) {
177 _Traits::assign(this->_M_Start(), __n, __c);
178 erase(begin() + __n, end());
181 if (__n < capacity()) {
182 _Traits::assign(this->_M_Start(), size(), __c);
183 append(__n - size(), __c);
186 _Self __str(__n, __c);
193 template <class _CharT, class _Traits, class _Alloc>
194 basic_string<_CharT,_Traits,_Alloc>&
195 basic_string<_CharT,_Traits,_Alloc>::_M_assign(const _CharT* __f, const _CharT* __l) {
196 ptrdiff_t __n = __l - __f;
197 if (__STATIC_CAST(size_type, __n) <= size()) {
198 _Traits::copy(this->_M_Start(), __f, __n);
199 erase(begin() + __n, end());
202 _Traits::copy(this->_M_Start(), __f, size());
203 _M_append(__f + size(), __l);
208 template <class _CharT, class _Traits, class _Alloc>
209 _CharT* basic_string<_CharT,_Traits,_Alloc> ::_M_insert_aux(_CharT* __p,
211 pointer __new_pos = __p;
212 if (this->_M_finish + 1 < this->_M_end_of_storage._M_data) {
213 _M_construct_null(this->_M_finish + 1);
214 _Traits::move(__p + 1, __p, this->_M_finish - __p);
215 _Traits::assign(*__p, __c);
219 const size_type __old_len = size();
220 size_type __len = __old_len + (max)(__old_len, __STATIC_CAST(size_type,1)) + 1;
221 pointer __new_start = this->_M_end_of_storage.allocate(__len, __len);
222 pointer __new_finish = __new_start;
224 __new_pos = _STLP_PRIV __ucopy(this->_M_Start(), __p, __new_start);
225 _Copy_Construct(__new_pos, __c);
226 __new_finish = __new_pos + 1;
227 __new_finish = _STLP_PRIV __ucopy(__p, this->_M_finish, __new_finish);
228 _M_construct_null(__new_finish);
230 _STLP_UNWIND((_STLP_STD::_Destroy_Range(__new_start,__new_finish),
231 this->_M_end_of_storage.deallocate(__new_start,__len)))
232 this->_M_destroy_range();
233 this->_M_deallocate_block();
234 this->_M_reset(__new_start, __new_finish, __new_start + __len);
239 template <class _CharT, class _Traits, class _Alloc>
240 void basic_string<_CharT,_Traits,_Alloc>::insert(iterator __pos,
241 size_t __n, _CharT __c) {
243 if (size_type(this->_M_end_of_storage._M_data - this->_M_finish) >= __n + 1) {
244 const size_type __elems_after = this->_M_finish - __pos;
245 pointer __old_finish = this->_M_finish;
246 if (__elems_after >= __n) {
247 #if defined (_STLP_USE_SHORT_STRING_OPTIM)
248 if (this->_M_using_static_buf())
249 _M_copy((this->_M_finish - __n) + 1, this->_M_finish + 1, this->_M_finish + 1);
251 #endif /* _STLP_USE_SHORT_STRING_OPTIM */
252 _STLP_PRIV __ucopy((this->_M_finish - __n) + 1, this->_M_finish + 1,
253 this->_M_finish + 1);
254 this->_M_finish += __n;
255 _Traits::move(__pos + __n, __pos, (__elems_after - __n) + 1);
256 _Traits::assign(__pos, __n, __c);
259 #if defined (_STLP_USE_SHORT_STRING_OPTIM)
260 if (this->_M_using_static_buf())
261 _Traits::assign(this->_M_finish + 1, __n - __elems_after - 1, __c);
263 #endif /* _STLP_USE_SHORT_STRING_OPTIM */
264 _STLP_PRIV __uninitialized_fill_n(this->_M_finish + 1, __n - __elems_after - 1, __c);
265 this->_M_finish += __n - __elems_after;
267 #if defined (_STLP_USE_SHORT_STRING_OPTIM)
268 if (this->_M_using_static_buf())
269 _M_copy(__pos, __old_finish + 1, this->_M_finish);
271 #endif /* _STLP_USE_SHORT_STRING_OPTIM */
272 _STLP_PRIV __ucopy(__pos, __old_finish + 1, this->_M_finish);
273 this->_M_finish += __elems_after;
275 _STLP_UNWIND((_STLP_STD::_Destroy_Range(__old_finish + 1, this->_M_finish),
276 this->_M_finish = __old_finish))
277 _Traits::assign(__pos, __elems_after + 1, __c);
281 const size_type __old_size = size();
282 size_type __len = __old_size + (max)(__old_size, __n) + 1;
283 pointer __new_start = this->_M_end_of_storage.allocate(__len, __len);
284 pointer __new_finish = __new_start;
286 __new_finish = _STLP_PRIV __ucopy(this->_M_Start(), __pos, __new_start);
287 __new_finish = _STLP_PRIV __uninitialized_fill_n(__new_finish, __n, __c);
288 __new_finish = _STLP_PRIV __ucopy(__pos, this->_M_finish, __new_finish);
289 _M_construct_null(__new_finish);
291 _STLP_UNWIND((_STLP_STD::_Destroy_Range(__new_start,__new_finish),
292 this->_M_end_of_storage.deallocate(__new_start,__len)))
293 this->_M_destroy_range();
294 this->_M_deallocate_block();
295 this->_M_reset(__new_start, __new_finish, __new_start + __len);
300 template <class _CharT, class _Traits, class _Alloc>
301 void basic_string<_CharT,_Traits,_Alloc>::_M_insert(iterator __pos,
302 const _CharT* __first, const _CharT* __last,
304 //this version has to take care about the auto referencing
305 if (__first != __last) {
306 const ptrdiff_t __n = __last - __first;
307 if (this->_M_end_of_storage._M_data - this->_M_finish >= __n + 1) {
308 const ptrdiff_t __elems_after = this->_M_finish - __pos;
309 pointer __old_finish = this->_M_finish;
310 if (__elems_after >= __n) {
311 #if defined (_STLP_USE_SHORT_STRING_OPTIM)
312 if (this->_M_using_static_buf())
313 _M_copy((this->_M_finish - __n) + 1, this->_M_finish + 1, this->_M_finish + 1);
315 #endif /* _STLP_USE_SHORT_STRING_OPTIM */
316 _STLP_PRIV __ucopy((this->_M_finish - __n) + 1, this->_M_finish + 1, this->_M_finish + 1);
317 this->_M_finish += __n;
318 _Traits::move(__pos + __n, __pos, (__elems_after - __n) + 1);
319 if (!__self_ref || __last < __pos) {
320 _M_copy(__first, __last, __pos);
323 //We have to check that the source buffer hasn't move
324 if (__first >= __pos) {
325 //The source buffer has move
328 _M_copy(__first, __last, __pos);
331 //The source buffer hasn't move, it has been duplicated
332 _M_move(__first, __last, __pos);
337 const_iterator __mid = __first;
338 __mid += __elems_after + 1;
339 #if defined (_STLP_USE_SHORT_STRING_OPTIM)
340 if (this->_M_using_static_buf())
341 _M_copy(__mid, __last, this->_M_finish + 1);
343 #endif /* _STLP_USE_SHORT_STRING_OPTIM */
344 _STLP_PRIV __ucopy(__mid, __last, this->_M_finish + 1);
345 this->_M_finish += __n - __elems_after;
347 #if defined (_STLP_USE_SHORT_STRING_OPTIM)
348 if (this->_M_using_static_buf())
349 _M_copy(__pos, __old_finish + 1, this->_M_finish);
351 #endif /* _STLP_USE_SHORT_STRING_OPTIM */
352 _STLP_PRIV __ucopy(__pos, __old_finish + 1, this->_M_finish);
353 this->_M_finish += __elems_after;
355 _STLP_UNWIND((_STLP_STD::_Destroy_Range(__old_finish + 1, this->_M_finish),
356 this->_M_finish = __old_finish))
358 _M_copy(__first, __mid, __pos);
360 _M_move(__first, __mid, __pos);
364 const size_type __old_size = size();
365 size_type __len = __old_size + (max)(__old_size, __STATIC_CAST(const size_type,__n)) + 1;
366 pointer __new_start = this->_M_end_of_storage.allocate(__len, __len);
367 pointer __new_finish = __new_start;
369 __new_finish = _STLP_PRIV __ucopy(this->_M_Start(), __pos, __new_start);
370 __new_finish = _STLP_PRIV __ucopy(__first, __last, __new_finish);
371 __new_finish = _STLP_PRIV __ucopy(__pos, this->_M_finish, __new_finish);
372 _M_construct_null(__new_finish);
374 _STLP_UNWIND((_STLP_STD::_Destroy_Range(__new_start,__new_finish),
375 this->_M_end_of_storage.deallocate(__new_start,__len)))
376 this->_M_destroy_range();
377 this->_M_deallocate_block();
378 this->_M_reset(__new_start, __new_finish, __new_start + __len);
383 template <class _CharT, class _Traits, class _Alloc>
384 basic_string<_CharT,_Traits,_Alloc>&
385 basic_string<_CharT,_Traits,_Alloc> ::replace(iterator __first, iterator __last,
386 size_type __n, _CharT __c) {
387 size_type __len = (size_type)(__last - __first);
390 _Traits::assign(__first, __n, __c);
391 erase(__first + __n, __last);
394 _Traits::assign(__first, __len, __c);
395 insert(__last, __n - __len, __c);
400 template <class _CharT, class _Traits, class _Alloc>
401 basic_string<_CharT,_Traits,_Alloc>&
402 basic_string<_CharT,_Traits,_Alloc> ::_M_replace(iterator __first, iterator __last,
403 const _CharT* __f, const _CharT* __l,
405 const ptrdiff_t __n = __l - __f;
406 const difference_type __len = __last - __first;
408 if (!__self_ref || __l < __first || __f >= __last)
409 _M_copy(__f, __l, __first);
411 _M_move(__f, __l, __first);
412 erase(__first + __n, __last);
415 if (!__self_ref || (__f >= __last) || (__l <= __first)) {
417 const_iterator __m = __f + __len;
418 _M_copy(__f, __m, __first);
419 _M_insert(__last, __m, __l, false );
422 //we have to take care of overlaping
424 const_iterator __m = __f + __len;
425 //We have to deal with possible reallocation because we do insert first.
426 const difference_type __off_dest = __first - this->begin();
427 const difference_type __off_src = __f - this->begin();
428 _M_insert(__last, __m, __l, true);
429 _Traits::move(begin() + __off_dest, begin() + __off_src, __len);
432 const_iterator __m = __f + __len;
433 _Traits::move(__first, __f, __len);
434 _M_insert(__last, __m, __l, true);
441 template <class _CharT, class _Traits, class _Alloc> __size_type__
442 basic_string<_CharT,_Traits,_Alloc> ::find(const _CharT* __s, size_type __pos,
443 size_type __n) const {
444 const size_t __len = size();
445 if (__pos >= __len || __pos + __n > __len)
448 const_pointer __result =
449 _STLP_STD::search(this->_M_Start() + __pos, this->_M_Finish(),
450 __s, __s + __n, _STLP_PRIV _Eq_traits<_Traits>());
451 return __result != this->_M_Finish() ? __result - this->_M_Start() : npos;
455 template <class _CharT, class _Traits, class _Alloc> __size_type__
456 basic_string<_CharT,_Traits,_Alloc> ::find(_CharT __c, size_type __pos) const {
457 if (__pos >= size()) /*__pos + 1 > size()*/
460 const_pointer __result =
461 _STLP_STD::find_if(this->_M_Start() + __pos, this->_M_Finish(),
462 _STLP_PRIV _Eq_char_bound<_Traits>(__c));
463 return __result != this->_M_Finish() ? __result - this->_M_Start() : npos;
467 template <class _CharT, class _Traits, class _Alloc> __size_type__
468 basic_string<_CharT,_Traits,_Alloc> ::rfind(const _CharT* __s, size_type __pos,
469 size_type __n) const {
470 const size_t __len = size();
471 if (__n > __len || __pos < __n)
474 return (min) (__len, __pos);
476 const_pointer __last = this->_M_Start() + (min) (__len - __n, __pos) + __n;
477 const_pointer __result = _STLP_PRIV __find_end(this->_M_Start(), __last,
479 bidirectional_iterator_tag(), bidirectional_iterator_tag(),
480 _STLP_PRIV _Eq_traits<_Traits>());
481 return __result != __last ? __result - this->_M_Start() : npos;
485 template <class _CharT, class _Traits, class _Alloc> __size_type__
486 basic_string<_CharT,_Traits,_Alloc> ::rfind(_CharT __c, size_type __pos) const {
487 const size_type __len = size();
488 if (1 > __len || __pos < 1)
491 const_iterator __last = begin() + (min) (__len - 1, __pos) + 1;
492 const_reverse_iterator __rresult =
493 _STLP_STD::find_if(const_reverse_iterator(__last), rend(),
494 _STLP_PRIV _Eq_char_bound<_Traits>(__c));
495 return __rresult != rend() ? (__rresult.base() - 1) - begin() : npos;
499 template <class _CharT, class _Traits, class _Alloc> __size_type__
500 basic_string<_CharT,_Traits,_Alloc> ::find_first_of(const _CharT* __s, size_type __pos,
501 size_type __n) const {
502 if (__pos >= size()) /*__pos + 1 > size()*/
505 const_iterator __result = _STLP_PRIV __find_first_of(begin() + __pos, end(),
507 _STLP_PRIV _Eq_traits<_Traits>());
508 return __result != end() ? __result - begin() : npos;
513 template <class _CharT, class _Traits, class _Alloc> __size_type__
514 basic_string<_CharT,_Traits,_Alloc> ::find_last_of(const _CharT* __s, size_type __pos,
515 size_type __n) const {
516 const size_type __len = size();
517 if (1 > __len || __pos < 1)
520 const const_iterator __last = begin() + (min) (__len - 1, __pos) + 1;
521 const const_reverse_iterator __rresult =
522 _STLP_PRIV __find_first_of(const_reverse_iterator(__last), rend(),
524 _STLP_PRIV _Eq_traits<_Traits>());
525 return __rresult != rend() ? (__rresult.base() - 1) - begin() : npos;
530 template <class _CharT, class _Traits, class _Alloc> __size_type__
531 basic_string<_CharT,_Traits,_Alloc> ::find_first_not_of(const _CharT* __s, size_type __pos,
532 size_type __n) const {
533 typedef typename _Traits::char_type _CharType;
534 if (__pos >= size()) /*__pos + 1 >= size()*/
537 const_pointer __result = _STLP_STD::find_if(this->_M_Start() + __pos, this->_M_Finish(),
538 _STLP_PRIV _Not_within_traits<_Traits>(__CONST_CAST(const _CharType*, __s),
539 __CONST_CAST(const _CharType*, __s) + __n));
540 return __result != this->_M_finish ? __result - this->_M_Start() : npos;
544 template <class _CharT, class _Traits, class _Alloc> __size_type__
545 basic_string<_CharT,_Traits,_Alloc> ::find_first_not_of(_CharT __c, size_type __pos) const {
549 const_pointer __result = _STLP_STD::find_if(this->_M_Start() + __pos, this->_M_Finish(),
550 _STLP_PRIV _Neq_char_bound<_Traits>(__c));
551 return __result != this->_M_finish ? __result - this->_M_Start() : npos;
555 template <class _CharT, class _Traits, class _Alloc> __size_type__
556 basic_string<_CharT,_Traits,_Alloc> ::find_last_not_of(const _CharT* __s, size_type __pos,
557 size_type __n) const {
558 typedef typename _Traits::char_type _CharType;
559 const size_type __len = size();
560 if (1 > __len || __pos < 1)
563 const_iterator __last = begin() + (min) (__len - 1, __pos) + 1;
564 const_reverse_iterator __rlast = const_reverse_iterator(__last);
565 const_reverse_iterator __rresult =
566 _STLP_STD::find_if(__rlast, rend(),
567 _STLP_PRIV _Not_within_traits<_Traits>((const _CharType*)__s,
568 (const _CharType*)__s + __n));
569 return __rresult != rend() ? (__rresult.base() - 1) - begin() : npos;
573 template <class _CharT, class _Traits, class _Alloc> __size_type__
574 basic_string<_CharT, _Traits, _Alloc> ::find_last_not_of(_CharT __c, size_type __pos) const {
575 const size_type __len = size();
576 if (1 > __len || __pos < 1)
579 const_iterator __last = begin() + (min) (__len - 1, __pos) + 1;
580 const_reverse_iterator __rlast = const_reverse_iterator(__last);
581 const_reverse_iterator __rresult =
582 _STLP_STD::find_if(__rlast, rend(),
583 _STLP_PRIV _Neq_char_bound<_Traits>(__c));
584 return __rresult != rend() ? (__rresult.base() - 1) - begin() : npos;
588 #if !defined (basic_string)
589 _STLP_MOVE_TO_PRIV_NAMESPACE
592 template <class _CharT, class _Traits, class _Alloc>
593 void _STLP_CALL _S_string_copy(const basic_string<_CharT,_Traits,_Alloc>& __s,
594 _CharT* __buf, size_t __n) {
596 __n = (min) (__n - 1, __s.size());
597 _STLP_STD::copy(__s.begin(), __s.begin() + __n, __buf);
598 __buf[__n] = _CharT();
602 _STLP_MOVE_TO_STD_NAMESPACE
606 #include <stl/_range_errors.h>
608 _STLP_BEGIN_NAMESPACE
610 _STLP_MOVE_TO_PRIV_NAMESPACE
612 // _String_base methods
613 template <class _Tp, class _Alloc>
614 void _String_base<_Tp,_Alloc>::_M_throw_length_error() const
615 { __stl_throw_length_error("basic_string"); }
617 template <class _Tp, class _Alloc>
618 void _String_base<_Tp, _Alloc>::_M_throw_out_of_range() const
619 { __stl_throw_out_of_range("basic_string"); }
621 template <class _Tp, class _Alloc>
622 void _String_base<_Tp, _Alloc>::_M_allocate_block(size_t __n) {
623 if ((__n <= (max_size() + 1)) && (__n > 0)) {
624 #if defined (_STLP_USE_SHORT_STRING_OPTIM)
625 if (__n > _DEFAULT_SIZE) {
626 this->_M_buffers._M_dynamic_buf = _M_end_of_storage.allocate(__n, __n);
627 this->_M_finish = this->_M_buffers._M_dynamic_buf;
628 this->_M_end_of_storage._M_data = this->_M_finish + __n;
631 this->_M_start = _M_end_of_storage.allocate(__n, __n);
632 this->_M_finish = this->_M_start;
633 this->_M_end_of_storage._M_data = this->_M_finish + __n;
634 #endif /*_STLP_USE_SHORT_STRING_OPTIM */
636 this->_M_throw_length_error();
640 #if !defined (basic_string)
641 _STLP_MOVE_TO_STD_NAMESPACE
644 #if defined (_STLP_DONT_SUP_DFLT_PARAM)
645 template <class _CharT, class _Traits, class _Alloc>
646 basic_string<_CharT, _Traits, _Alloc>::basic_string(const _CharT* __s)
647 : _STLP_PRIV _String_base<_CharT,_Alloc>(allocator_type()) {
648 _STLP_FIX_LITERAL_BUG(__s)
649 _M_range_initialize(__s, __s + traits_type::length(__s));
653 template <class _CharT, class _Traits, class _Alloc>
654 basic_string<_CharT, _Traits, _Alloc>::basic_string(const _CharT* __s,
655 const allocator_type& __a)
656 : _STLP_PRIV _String_base<_CharT,_Alloc>(__a) {
657 _STLP_FIX_LITERAL_BUG(__s)
658 _M_range_initialize(__s, __s + traits_type::length(__s));
661 template <class _CharT, class _Traits, class _Alloc>
662 basic_string<_CharT, _Traits, _Alloc>::basic_string(const basic_string<_CharT, _Traits, _Alloc> & __s)
663 : _STLP_PRIV _String_base<_CharT,_Alloc>(__s.get_allocator())
664 { _M_range_initialize(__s._M_Start(), __s._M_Finish()); }
666 #if defined (basic_string)
667 _STLP_MOVE_TO_STD_NAMESPACE
670 /* If basic_string is defined it means that it won't be the basic_string class
671 * exposed to STLport users so npos do not need external linkage.
673 # if !defined (_STLP_STATIC_CONST_INIT_BUG)
674 # if !defined (__GNUC__) || (__GNUC__ != 2) || (__GNUC_MINOR__ != 96)
675 template <class _CharT, class _Traits, class _Alloc>
676 const size_t basic_string<_CharT, _Traits, _Alloc>::npos;
684 #if defined (_STLP_NESTED_TYPE_PARAM_BUG)
689 #endif /* _STLP_STRING_C */