Attempt to represent the S^2->S^3 header reorganisation as a series of "hg rename" operations
2 * © Portions copyright (c) 2006-2007 Nokia Corporation. All rights reserved.
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_STRING_H
30 # include <stl/_string.h>
34 # define basic_string _Nondebug_string
37 # if defined (_STLP_USE_OWN_NAMESPACE) || !defined (_STLP_USE_NATIVE_STRING)
39 # if defined (_STLP_NESTED_TYPE_PARAM_BUG)
40 # define __size_type__ size_t
41 # define size_type size_t
42 # define iterator _CharT*
44 # define __size_type__ _STLP_TYPENAME_ON_RETURN_TYPE basic_string<_CharT,_Traits,_Alloc>::size_type
49 // ------------------------------------------------------------
50 // Non-inline declarations.
53 // Change the string's capacity so that it is large enough to hold
54 // at least __res_arg elements, plus the terminating _CharT(). Note that,
55 // if __res_arg < capacity(), this member function may actually decrease
56 // the string's capacity.
57 template <class _CharT, class _Traits, class _Alloc>
58 _STLP_EXP_DECLSPEC void basic_string<_CharT,_Traits,_Alloc>::reserve(size_type __res_arg) {
60 if (__res_arg >= capacity())
62 if (__res_arg > max_size())
63 this->_M_throw_length_error();
65 size_type __n = __res_arg + 1;
66 _STLP_LEAVE_VOLATILE pointer __new_start = this->_M_end_of_storage.allocate(__n);
67 _STLP_LEAVE_VOLATILE pointer __new_finish = __new_start;
70 __new_finish = uninitialized_copy(this->_M_start, this->_M_finish, __new_start);
71 _M_construct_null(__new_finish);
73 _STLP_UNWIND((_STLP_STD::_Destroy(__new_start, __new_finish),
74 this->_M_end_of_storage.deallocate(__new_start, __n)));
76 _STLP_STD::_Destroy(this->_M_start, this->_M_finish + 1);
77 this->_M_deallocate_block();
78 this->_M_start = __new_start;
79 this->_M_finish = __new_finish;
80 this->_M_end_of_storage._M_data = __new_start + __n;
84 template <class _CharT, class _Traits, class _Alloc>
85 _STLP_EXP_DECLSPEC basic_string<_CharT,_Traits,_Alloc>&
86 basic_string<_CharT,_Traits,_Alloc>::append(size_type __n, _CharT __c)
88 if (__n > max_size() || size() > max_size() - __n)
89 this->_M_throw_length_error();
90 if (size() + __n > capacity())
91 reserve(size() + (max)(size(), __n));
93 uninitialized_fill_n(this->_M_finish + 1, __n - 1, __c);
95 _M_construct_null(this->_M_finish + __n);
97 _STLP_UNWIND(_STLP_STD::_Destroy(this->_M_finish + 1, this->_M_finish + __n));
98 _Traits::assign(*end(), __c);
99 this->_M_finish += __n;
104 #ifndef _STLP_MEMBER_TEMPLATES
106 template <class _CharT, class _Traits, class _Alloc>
107 _STLP_EXP_DECLSPEC basic_string<_CharT, _Traits, _Alloc>&
108 basic_string<_CharT, _Traits, _Alloc>::append(const _CharT* __first,
109 const _CharT* __last)
111 if (__first != __last) {
112 const size_type __old_size = size();
113 ptrdiff_t __n = __last - __first;
114 if ((size_type)__n > max_size() || __old_size > max_size() - __n)
115 this->_M_throw_length_error();
116 if (__old_size + __n > capacity()) {
117 const size_type __len = __old_size + (max)(__old_size, (size_t) __n) + 1;
118 pointer __new_start = this->_M_end_of_storage.allocate(__len);
119 _STLP_LEAVE_VOLATILE pointer __new_finish = __new_start;
121 __new_finish = uninitialized_copy(this->_M_start, this->_M_finish, __new_start);
122 __new_finish = uninitialized_copy(__first, __last, __new_finish);
123 _M_construct_null(__new_finish);
125 _STLP_UNWIND((_STLP_STD::_Destroy(__new_start,__new_finish),
126 this->_M_end_of_storage.deallocate(__new_start,__len)));
127 _STLP_STD::_Destroy(this->_M_start, this->_M_finish + 1);
128 this->_M_deallocate_block();
129 this->_M_start = __new_start;
130 this->_M_finish = __new_finish;
131 this->_M_end_of_storage._M_data = __new_start + __len;
134 const _CharT* __f1 = __first;
136 uninitialized_copy(__f1, __last, this->_M_finish + 1);
138 _M_construct_null(this->_M_finish + __n);
140 _STLP_UNWIND(_STLP_STD::_Destroy(this->_M_finish + 1, this->_M_finish + __n));
141 _Traits::assign(*end(), *__first);
142 this->_M_finish += __n;
148 #endif /* _STLP_MEMBER_TEMPLATES */
150 template <class _CharT, class _Traits, class _Alloc>
151 _STLP_EXP_DECLSPEC basic_string<_CharT,_Traits,_Alloc>&
152 basic_string<_CharT,_Traits,_Alloc>::assign(size_type __n, _CharT __c) {
154 _Traits::assign(this->_M_start, __n, __c);
155 erase(begin() + __n, end());
158 _Traits::assign(this->_M_start, size(), __c);
159 append(__n - size(), __c);
164 template <class _CharT, class _Traits, class _Alloc>
165 _CharT* basic_string<_CharT,_Traits,_Alloc> ::_M_insert_aux(_CharT* __p,
168 pointer __new_pos = __p;
169 if (this->_M_finish + 1 < this->_M_end_of_storage._M_data) {
170 _M_construct_null(this->_M_finish + 1);
171 _Traits::move(__p + 1, __p, this->_M_finish - __p);
172 _Traits::assign(*__p, __c);
176 const size_type __old_len = size();
177 const size_type __len = __old_len +
178 (max)(__old_len, __STATIC_CAST(size_type,1)) + 1;
179 pointer __new_start = this->_M_end_of_storage.allocate(__len);
180 _STLP_LEAVE_VOLATILE pointer __new_finish = __new_start;
182 __new_pos = uninitialized_copy(this->_M_start, __p, __new_start);
183 _Construct(__new_pos, __c);
184 __new_finish = __new_pos + 1;
185 __new_finish = uninitialized_copy(__p, this->_M_finish, __new_finish);
186 _M_construct_null(__new_finish);
188 _STLP_UNWIND((_STLP_STD::_Destroy(__new_start,__new_finish),
189 this->_M_end_of_storage.deallocate(__new_start,__len)));
190 _STLP_STD::_Destroy(this->_M_start, this->_M_finish + 1);
191 this->_M_deallocate_block();
192 this->_M_start = __new_start;
193 this->_M_finish = __new_finish;
194 this->_M_end_of_storage._M_data = __new_start + __len;
199 template <class _CharT, class _Traits, class _Alloc>
200 _STLP_EXP_DECLSPEC void basic_string<_CharT,_Traits,_Alloc>::insert(iterator __position,
201 size_t __n, _CharT __c)
204 if (size_type(this->_M_end_of_storage._M_data - this->_M_finish) >= __n + 1) {
205 const size_type __elems_after = this->_M_finish - __position;
206 pointer __old_finish = this->_M_finish;
207 if (__elems_after >= __n) {
208 uninitialized_copy((this->_M_finish - __n) + 1, this->_M_finish + 1,
209 this->_M_finish + 1);
210 this->_M_finish += __n;
211 _Traits::move(__position + __n,
212 __position, (__elems_after - __n) + 1);
213 _Traits::assign(__position, __n, __c);
216 uninitialized_fill_n(this->_M_finish + 1, __n - __elems_after - 1, __c);
217 this->_M_finish += __n - __elems_after;
219 uninitialized_copy(__position, __old_finish + 1, this->_M_finish);
220 this->_M_finish += __elems_after;
222 _STLP_UNWIND((_STLP_STD::_Destroy(__old_finish + 1, this->_M_finish),
223 this->_M_finish = __old_finish));
224 _Traits::assign(__position, __elems_after + 1, __c);
228 const size_type __old_size = size();
229 const size_type __len = __old_size + (max)(__old_size, __n) + 1;
230 pointer __new_start = this->_M_end_of_storage.allocate(__len);
231 _STLP_LEAVE_VOLATILE pointer __new_finish = __new_start;
233 __new_finish = uninitialized_copy(this->_M_start, __position, __new_start);
234 __new_finish = uninitialized_fill_n(__new_finish, __n, __c);
235 __new_finish = uninitialized_copy(__position, this->_M_finish,
237 _M_construct_null(__new_finish);
239 _STLP_UNWIND((_STLP_STD::_Destroy(__new_start,__new_finish),
240 this->_M_end_of_storage.deallocate(__new_start,__len)));
241 _STLP_STD::_Destroy(this->_M_start, this->_M_finish + 1);
242 this->_M_deallocate_block();
243 this->_M_start = __new_start;
244 this->_M_finish = __new_finish;
245 this->_M_end_of_storage._M_data = __new_start + __len;
250 #ifndef _STLP_MEMBER_TEMPLATES
252 template <class _CharT, class _Traits, class _Alloc>
253 _STLP_EXP_DECLSPEC void
254 basic_string<_CharT,_Traits,_Alloc>::insert(iterator __position,
255 const _CharT* __first,
256 const _CharT* __last)
258 if (__first != __last) {
259 const ptrdiff_t __n = __last - __first;
260 if (this->_M_end_of_storage._M_data - this->_M_finish >= __n + 1) {
261 const ptrdiff_t __elems_after = this->_M_finish - __position;
262 pointer __old_finish = this->_M_finish;
263 if (__elems_after >= __n) {
264 uninitialized_copy((this->_M_finish - __n) + 1, this->_M_finish + 1,
265 this->_M_finish + 1);
266 this->_M_finish += __n;
267 _Traits::move(__position + __n,
268 __position, (__elems_after - __n) + 1);
269 _M_copy(__first, __last, __position);
272 const _CharT* __mid = __first;
273 advance(__mid, __elems_after + 1);
274 uninitialized_copy(__mid, __last, this->_M_finish + 1);
275 this->_M_finish += __n - __elems_after;
277 uninitialized_copy(__position, __old_finish + 1, this->_M_finish);
278 this->_M_finish += __elems_after;
280 _STLP_UNWIND((_STLP_STD::_Destroy(__old_finish + 1, this->_M_finish),
281 this->_M_finish = __old_finish));
282 _M_copy(__first, __mid, __position);
286 size_type __old_size = size();
288 = __old_size + (max)(__old_size, __STATIC_CAST(const size_type,__n)) + 1;
289 pointer __new_start = this->_M_end_of_storage.allocate(__len);
290 _STLP_LEAVE_VOLATILE pointer __new_finish = __new_start;
292 __new_finish = uninitialized_copy(this->_M_start, __position, __new_start);
293 __new_finish = uninitialized_copy(__first, __last, __new_finish);
295 = uninitialized_copy(__position, this->_M_finish, __new_finish);
296 _M_construct_null(__new_finish);
298 _STLP_UNWIND((_STLP_STD::_Destroy(__new_start,__new_finish),
299 this->_M_end_of_storage.deallocate(__new_start,__len)));
300 _STLP_STD::_Destroy(this->_M_start, this->_M_finish + 1);
301 this->_M_deallocate_block();
302 this->_M_start = __new_start;
303 this->_M_finish = __new_finish;
304 this->_M_end_of_storage._M_data = __new_start + __len;
309 #endif /* _STLP_MEMBER_TEMPLATES */
311 template <class _CharT, class _Traits, class _Alloc>
312 _STLP_EXP_DECLSPEC basic_string<_CharT,_Traits,_Alloc>&
313 basic_string<_CharT,_Traits,_Alloc>::replace(iterator __first, iterator __last, size_type __n, _CharT __c)
315 size_type __len = (size_type)(__last - __first);
318 _Traits::assign(__first, __n, __c);
319 erase(__first + __n, __last);
322 _Traits::assign(__first, __len, __c);
323 insert(__last, __n - __len, __c);
328 #ifndef _STLP_MEMBER_TEMPLATES
331 template <class _CharT, class _Traits, class _Alloc>
332 _STLP_EXP_DECLSPEC basic_string<_CharT,_Traits,_Alloc>&
333 basic_string<_CharT,_Traits,_Alloc> ::replace(iterator __first, iterator __last,
334 const _CharT* __f, const _CharT* __l)
336 const ptrdiff_t __n = __l - __f;
337 const difference_type __len = __last - __first;
339 _M_copy(__f, __l, __first);
340 erase(__first + __n, __last);
343 const _CharT* __m = __f + __len;
344 _M_copy(__f, __m, __first);
345 insert(__last, __m, __l);
350 #endif /* _STLP_MEMBER_TEMPLATES */
352 template <class _CharT, class _Traits, class _Alloc>
353 _STLP_EXP_DECLSPEC __size_type__
354 basic_string<_CharT,_Traits,_Alloc> ::find(const _CharT* __s, size_type __pos, size_type __n) const
356 #ifndef __SYMBIAN32__ // A different implementation without using search
357 if (__pos + __n > size())
360 const const_pointer __result =
361 _STLP_STD::search((const _CharT*)this->_M_start + __pos, (const _CharT*)this->_M_finish,
362 __s, __s + __n, _Eq_traits<_Traits>());
363 return __result != this->_M_finish ? __result - this->_M_start : npos;
366 const size_type __len = this->size();
367 size_t __tpos = __pos;
368 const _CharT* __data = this->_M_start;
369 while (__tpos + __n <= __len) {
370 if (traits_type::compare(__data + __tpos, __s, __n) == 0)
375 #endif //__SYMBIAN32__
378 template <class _CharT, class _Traits, class _Alloc>
379 _STLP_EXP_DECLSPEC __size_type__
380 basic_string<_CharT,_Traits,_Alloc> ::find(_CharT __c, size_type __pos) const
385 const const_pointer __result =
386 _STLP_STD::find_if((const _CharT*)this->_M_start + __pos, (const _CharT*)this->_M_finish,
387 _Eq_char_bound<_Traits>(__c));
388 return __result != this->_M_finish ? __result - this->_M_start : npos;
392 template <class _CharT, class _Traits, class _Alloc>
393 _STLP_EXP_DECLSPEC __size_type__
394 basic_string<_CharT,_Traits,_Alloc> ::rfind(const _CharT* __s, size_type __pos, size_type __n) const
396 const size_t __len = size();
401 return (min) (__len, __pos);
403 const_pointer __last = this->_M_start + (min) (__len - __n, __pos) + __n;
404 const_pointer __result = _STLP_STD::find_end((const_pointer)this->_M_start, __last,
406 _Eq_traits<_Traits>());
407 return __result != __last ? __result - this->_M_start : npos;
411 template <class _CharT, class _Traits, class _Alloc>
412 _STLP_EXP_DECLSPEC __size_type__
413 basic_string<_CharT,_Traits,_Alloc> ::rfind(_CharT __c, size_type __pos) const
415 const size_type __len = size();
420 const const_iterator __last = begin() + (min) (__len - 1, __pos) + 1;
421 const_reverse_iterator __rresult =
422 _STLP_STD::find_if(const_reverse_iterator(__last), rend(),
423 _Eq_char_bound<_Traits>(__c));
424 return __rresult != rend() ? (__rresult.base() - 1) - begin() : npos;
428 template <class _CharT, class _Traits, class _Alloc>
429 _STLP_EXP_DECLSPEC __size_type__
430 basic_string<_CharT,_Traits,_Alloc>
431 ::find_first_of(const _CharT* __s, size_type __pos, size_type __n) const
436 const_iterator __result = __find_first_of(begin() + __pos, end(),
438 _Eq_traits<_Traits>());
439 return __result != end() ? __result - begin() : npos;
444 template <class _CharT, class _Traits, class _Alloc>
445 _STLP_EXP_DECLSPEC __size_type__
446 basic_string<_CharT,_Traits,_Alloc>
447 ::find_last_of(const _CharT* __s, size_type __pos, size_type __n) const
449 const size_type __len = size();
454 const const_iterator __last = begin() + (min) (__len - 1, __pos) + 1;
455 const const_reverse_iterator __rresult =
456 __find_first_of(const_reverse_iterator(__last), rend(),
458 _Eq_traits<_Traits>());
459 return __rresult != rend() ? (__rresult.base() - 1) - begin() : npos;
464 template <class _CharT, class _Traits, class _Alloc>
465 _STLP_EXP_DECLSPEC __size_type__
466 basic_string<_CharT,_Traits,_Alloc> ::find_first_not_of(const _CharT* __s, size_type __pos, size_type __n) const
468 typedef typename _Traits::char_type _CharType;
472 const_pointer __result = _STLP_STD::find_if((const _CharT*)this->_M_start + __pos,
473 (const _CharT*)this->_M_finish,
474 _Not_within_traits<_Traits>((const _CharType*)__s,
475 (const _CharType*)__s + __n));
476 return __result != this->_M_finish ? __result - this->_M_start : npos;
480 template <class _CharT, class _Traits, class _Alloc>
481 _STLP_EXP_DECLSPEC __size_type__
482 basic_string<_CharT,_Traits,_Alloc> ::find_first_not_of(_CharT __c, size_type __pos) const
487 const_pointer __result = _STLP_STD::find_if((const _CharT*)this->_M_start + __pos, (const _CharT*)this->_M_finish,
488 _Neq_char_bound<_Traits>(__c));
489 return __result != this->_M_finish ? __result - this->_M_start : npos;
493 template <class _CharT, class _Traits, class _Alloc>
494 _STLP_EXP_DECLSPEC __size_type__
495 basic_string<_CharT,_Traits,_Alloc> ::find_last_not_of(const _CharT* __s, size_type __pos, size_type __n) const
497 typedef typename _Traits::char_type _CharType;
498 const size_type __len = size();
503 const_iterator __last = begin() + (min) (__len - 1, __pos) + 1;
504 const_reverse_iterator __rlast = const_reverse_iterator(__last);
505 const_reverse_iterator __rresult =
506 _STLP_STD::find_if(__rlast, rend(),
507 _Not_within_traits<_Traits>((const _CharType*)__s,
508 (const _CharType*)__s + __n));
509 return __rresult != rend() ? (__rresult.base() - 1) - begin() : npos;
513 template <class _CharT, class _Traits, class _Alloc>
514 _STLP_EXP_DECLSPEC __size_type__
515 basic_string<_CharT, _Traits, _Alloc> ::find_last_not_of(_CharT __c, size_type __pos) const
517 const size_type __len = size();
522 const_iterator __last = begin() + (min) (__len - 1, __pos) + 1;
523 const_reverse_iterator __rlast = const_reverse_iterator(__last);
524 const_reverse_iterator __rresult =
525 _STLP_STD::find_if(__rlast, rend(),
526 _Neq_char_bound<_Traits>(__c));
527 return __rresult != rend() ? (__rresult.base() - 1) - begin() : npos;
531 template <class _CharT, class _Traits, class _Alloc>
532 void _STLP_CALL _S_string_copy(const basic_string<_CharT,_Traits,_Alloc>& __s,
537 __n = (min) (__n - 1, __s.size());
538 _STLP_STD::copy(__s.begin(), __s.begin() + __n, __buf);
539 __buf[__n] = _CharT();
544 // _string_fwd has to see clean basic_string
547 # if !defined (_STLP_LINK_TIME_INSTANTIATION)
548 # include <stl/_string_fwd.c>
552 # define basic_string _Nondebug_string
555 # include <stl/_range_errors.h>
556 _STLP_BEGIN_NAMESPACE
558 // _String_base methods
559 template <class _Tp, class _Alloc>
560 void _String_base<_Tp,_Alloc>::_M_throw_length_error() const {
561 __stl_throw_length_error("basic_string");
564 template <class _Tp, class _Alloc>
565 void _String_base<_Tp, _Alloc>::_M_throw_out_of_range() const {
566 __stl_throw_out_of_range("basic_string");
569 template <class _Tp, class _Alloc>
570 void _String_base<_Tp, _Alloc>::_M_allocate_block(size_t __n) {
571 if ((__n <= (max_size()+1)) && (__n>0)){
572 _M_start = _M_end_of_storage.allocate(__n);
573 _M_finish = _M_start;
574 _M_end_of_storage._M_data = _M_start + __n;
577 _M_throw_length_error();
580 template <class _CharT, class _Traits, class _Alloc>
581 _STLP_EXP_DECLSPEC basic_string<_CharT, _Traits, _Alloc>::basic_string()
582 : _String_base<_CharT,_Alloc>(allocator_type())
584 this->_M_start = this->_M_end_of_storage.allocate(8);
585 this->_M_finish = this->_M_start;
586 this->_M_end_of_storage._M_data = this->_M_start + 8;
587 _M_terminate_string();
588 _STLP_POP_CLEANUP_ITEM
592 template <class _CharT, class _Traits, class _Alloc>
593 _STLP_EXP_DECLSPEC basic_string<_CharT, _Traits, _Alloc>::basic_string(const _CharT* __s,
594 const allocator_type& __a)
595 : _String_base<_CharT,_Alloc>(__a)
597 _STLP_FIX_LITERAL_BUG(__s)
598 _M_range_initialize(__s, __s + traits_type::length(__s));
599 _STLP_POP_CLEANUP_ITEM
603 template <class _CharT, class _Traits, class _Alloc>
604 _STLP_EXP_DECLSPEC basic_string<_CharT, _Traits, _Alloc>::basic_string(const basic_string<_CharT, _Traits, _Alloc> & __s)
605 : _String_base<_CharT,_Alloc>(__s.get_allocator())
607 _M_range_initialize(__s._M_start, __s._M_finish);
608 _STLP_POP_CLEANUP_ITEM
611 # if defined ( __SUNPRO_CC) && ! defined(_STLP_STATIC_CONST_INIT_BUG)
612 template <class _CharT, class _Traits, class _Alloc> const size_t basic_string<_CharT, _Traits, _Alloc>::npos;
618 # undef __size_type__
623 #endif /* _STLP_STRING_C */