1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/epoc32/include/stdapis/stlportv5/stl/_string.c Wed Mar 31 12:27:01 2010 +0100
1.3 @@ -0,0 +1,627 @@
1.4 +/*
1.5 + * © Portions copyright (c) 2006-2007 Nokia Corporation. All rights reserved.
1.6 + *
1.7 + * Copyright (c) 1994
1.8 + * Hewlett-Packard Company
1.9 + *
1.10 + * Copyright (c) 1996,1997
1.11 + * Silicon Graphics Computer Systems, Inc.
1.12 + *
1.13 + * Copyright (c) 1997
1.14 + * Moscow Center for SPARC Technology
1.15 + *
1.16 + * Copyright (c) 1999
1.17 + * Boris Fomitchev
1.18 + *
1.19 + * This material is provided "as is", with absolutely no warranty expressed
1.20 + * or implied. Any use is at your own risk.
1.21 + *
1.22 + * Permission to use or copy this software for any purpose is hereby granted
1.23 + * without fee, provided the above notices are retained on all copies.
1.24 + * Permission to modify the code and to distribute modified code is granted,
1.25 + * provided the above notices are retained, and a notice that the code was
1.26 + * modified is included with the above copyright notice.
1.27 + *
1.28 + */
1.29 +#ifndef _STLP_STRING_C
1.30 +#define _STLP_STRING_C
1.31 +
1.32 +#ifndef _STLP_STRING_H
1.33 +# include <stl/_string.h>
1.34 +#endif
1.35 +
1.36 +# ifdef _STLP_DEBUG
1.37 +# define basic_string _Nondebug_string
1.38 +# endif
1.39 +
1.40 +# if defined (_STLP_USE_OWN_NAMESPACE) || !defined (_STLP_USE_NATIVE_STRING)
1.41 +
1.42 +# if defined (_STLP_NESTED_TYPE_PARAM_BUG)
1.43 +# define __size_type__ size_t
1.44 +# define size_type size_t
1.45 +# define iterator _CharT*
1.46 +# else
1.47 +# define __size_type__ _STLP_TYPENAME_ON_RETURN_TYPE basic_string<_CharT,_Traits,_Alloc>::size_type
1.48 +# endif
1.49 +
1.50 +_STLP_BEGIN_NAMESPACE
1.51 +
1.52 +// ------------------------------------------------------------
1.53 +// Non-inline declarations.
1.54 +
1.55 +
1.56 +// Change the string's capacity so that it is large enough to hold
1.57 +// at least __res_arg elements, plus the terminating _CharT(). Note that,
1.58 +// if __res_arg < capacity(), this member function may actually decrease
1.59 +// the string's capacity.
1.60 +template <class _CharT, class _Traits, class _Alloc>
1.61 +_STLP_EXP_DECLSPEC void basic_string<_CharT,_Traits,_Alloc>::reserve(size_type __res_arg) {
1.62 +
1.63 + if (__res_arg >= capacity())
1.64 + {
1.65 + if (__res_arg > max_size())
1.66 + this->_M_throw_length_error();
1.67 +
1.68 + size_type __n = __res_arg + 1;
1.69 + _STLP_LEAVE_VOLATILE pointer __new_start = this->_M_end_of_storage.allocate(__n);
1.70 + _STLP_LEAVE_VOLATILE pointer __new_finish = __new_start;
1.71 +
1.72 + _STLP_TRY {
1.73 + __new_finish = uninitialized_copy(this->_M_start, this->_M_finish, __new_start);
1.74 + _M_construct_null(__new_finish);
1.75 + }
1.76 + _STLP_UNWIND((_STLP_STD::_Destroy(__new_start, __new_finish),
1.77 + this->_M_end_of_storage.deallocate(__new_start, __n)));
1.78 +
1.79 + _STLP_STD::_Destroy(this->_M_start, this->_M_finish + 1);
1.80 + this->_M_deallocate_block();
1.81 + this->_M_start = __new_start;
1.82 + this->_M_finish = __new_finish;
1.83 + this->_M_end_of_storage._M_data = __new_start + __n;
1.84 + }
1.85 +}
1.86 +
1.87 +template <class _CharT, class _Traits, class _Alloc>
1.88 +_STLP_EXP_DECLSPEC basic_string<_CharT,_Traits,_Alloc>&
1.89 +basic_string<_CharT,_Traits,_Alloc>::append(size_type __n, _CharT __c)
1.90 +{
1.91 + if (__n > max_size() || size() > max_size() - __n)
1.92 + this->_M_throw_length_error();
1.93 + if (size() + __n > capacity())
1.94 + reserve(size() + (max)(size(), __n));
1.95 + if (__n > 0) {
1.96 + uninitialized_fill_n(this->_M_finish + 1, __n - 1, __c);
1.97 + _STLP_TRY {
1.98 + _M_construct_null(this->_M_finish + __n);
1.99 + }
1.100 + _STLP_UNWIND(_STLP_STD::_Destroy(this->_M_finish + 1, this->_M_finish + __n));
1.101 + _Traits::assign(*end(), __c);
1.102 + this->_M_finish += __n;
1.103 + }
1.104 + return *this;
1.105 +}
1.106 +
1.107 +#ifndef _STLP_MEMBER_TEMPLATES
1.108 +
1.109 +template <class _CharT, class _Traits, class _Alloc>
1.110 +_STLP_EXP_DECLSPEC basic_string<_CharT, _Traits, _Alloc>&
1.111 +basic_string<_CharT, _Traits, _Alloc>::append(const _CharT* __first,
1.112 + const _CharT* __last)
1.113 +{
1.114 + if (__first != __last) {
1.115 + const size_type __old_size = size();
1.116 + ptrdiff_t __n = __last - __first;
1.117 + if ((size_type)__n > max_size() || __old_size > max_size() - __n)
1.118 + this->_M_throw_length_error();
1.119 + if (__old_size + __n > capacity()) {
1.120 + const size_type __len = __old_size + (max)(__old_size, (size_t) __n) + 1;
1.121 + pointer __new_start = this->_M_end_of_storage.allocate(__len);
1.122 + _STLP_LEAVE_VOLATILE pointer __new_finish = __new_start;
1.123 + _STLP_TRY {
1.124 + __new_finish = uninitialized_copy(this->_M_start, this->_M_finish, __new_start);
1.125 + __new_finish = uninitialized_copy(__first, __last, __new_finish);
1.126 + _M_construct_null(__new_finish);
1.127 + }
1.128 + _STLP_UNWIND((_STLP_STD::_Destroy(__new_start,__new_finish),
1.129 + this->_M_end_of_storage.deallocate(__new_start,__len)));
1.130 + _STLP_STD::_Destroy(this->_M_start, this->_M_finish + 1);
1.131 + this->_M_deallocate_block();
1.132 + this->_M_start = __new_start;
1.133 + this->_M_finish = __new_finish;
1.134 + this->_M_end_of_storage._M_data = __new_start + __len;
1.135 + }
1.136 + else {
1.137 + const _CharT* __f1 = __first;
1.138 + ++__f1;
1.139 + uninitialized_copy(__f1, __last, this->_M_finish + 1);
1.140 + _STLP_TRY {
1.141 + _M_construct_null(this->_M_finish + __n);
1.142 + }
1.143 + _STLP_UNWIND(_STLP_STD::_Destroy(this->_M_finish + 1, this->_M_finish + __n));
1.144 + _Traits::assign(*end(), *__first);
1.145 + this->_M_finish += __n;
1.146 + }
1.147 + }
1.148 + return *this;
1.149 +}
1.150 +
1.151 +#endif /* _STLP_MEMBER_TEMPLATES */
1.152 +
1.153 +template <class _CharT, class _Traits, class _Alloc>
1.154 +_STLP_EXP_DECLSPEC basic_string<_CharT,_Traits,_Alloc>&
1.155 +basic_string<_CharT,_Traits,_Alloc>::assign(size_type __n, _CharT __c) {
1.156 + if (__n <= size()) {
1.157 + _Traits::assign(this->_M_start, __n, __c);
1.158 + erase(begin() + __n, end());
1.159 + }
1.160 + else {
1.161 + _Traits::assign(this->_M_start, size(), __c);
1.162 + append(__n - size(), __c);
1.163 + }
1.164 + return *this;
1.165 +}
1.166 +
1.167 +template <class _CharT, class _Traits, class _Alloc>
1.168 +_CharT* basic_string<_CharT,_Traits,_Alloc> ::_M_insert_aux(_CharT* __p,
1.169 + _CharT __c)
1.170 +{
1.171 + pointer __new_pos = __p;
1.172 + if (this->_M_finish + 1 < this->_M_end_of_storage._M_data) {
1.173 + _M_construct_null(this->_M_finish + 1);
1.174 + _Traits::move(__p + 1, __p, this->_M_finish - __p);
1.175 + _Traits::assign(*__p, __c);
1.176 + ++this->_M_finish;
1.177 + }
1.178 + else {
1.179 + const size_type __old_len = size();
1.180 + const size_type __len = __old_len +
1.181 + (max)(__old_len, __STATIC_CAST(size_type,1)) + 1;
1.182 + pointer __new_start = this->_M_end_of_storage.allocate(__len);
1.183 + _STLP_LEAVE_VOLATILE pointer __new_finish = __new_start;
1.184 + _STLP_TRY {
1.185 + __new_pos = uninitialized_copy(this->_M_start, __p, __new_start);
1.186 + _Construct(__new_pos, __c);
1.187 + __new_finish = __new_pos + 1;
1.188 + __new_finish = uninitialized_copy(__p, this->_M_finish, __new_finish);
1.189 + _M_construct_null(__new_finish);
1.190 + }
1.191 + _STLP_UNWIND((_STLP_STD::_Destroy(__new_start,__new_finish),
1.192 + this->_M_end_of_storage.deallocate(__new_start,__len)));
1.193 + _STLP_STD::_Destroy(this->_M_start, this->_M_finish + 1);
1.194 + this->_M_deallocate_block();
1.195 + this->_M_start = __new_start;
1.196 + this->_M_finish = __new_finish;
1.197 + this->_M_end_of_storage._M_data = __new_start + __len;
1.198 + }
1.199 + return __new_pos;
1.200 +}
1.201 +
1.202 +template <class _CharT, class _Traits, class _Alloc>
1.203 +_STLP_EXP_DECLSPEC void basic_string<_CharT,_Traits,_Alloc>::insert(iterator __position,
1.204 + size_t __n, _CharT __c)
1.205 +{
1.206 + if (__n != 0) {
1.207 + if (size_type(this->_M_end_of_storage._M_data - this->_M_finish) >= __n + 1) {
1.208 + const size_type __elems_after = this->_M_finish - __position;
1.209 + pointer __old_finish = this->_M_finish;
1.210 + if (__elems_after >= __n) {
1.211 + uninitialized_copy((this->_M_finish - __n) + 1, this->_M_finish + 1,
1.212 + this->_M_finish + 1);
1.213 + this->_M_finish += __n;
1.214 + _Traits::move(__position + __n,
1.215 + __position, (__elems_after - __n) + 1);
1.216 + _Traits::assign(__position, __n, __c);
1.217 + }
1.218 + else {
1.219 + uninitialized_fill_n(this->_M_finish + 1, __n - __elems_after - 1, __c);
1.220 + this->_M_finish += __n - __elems_after;
1.221 + _STLP_TRY {
1.222 + uninitialized_copy(__position, __old_finish + 1, this->_M_finish);
1.223 + this->_M_finish += __elems_after;
1.224 + }
1.225 + _STLP_UNWIND((_STLP_STD::_Destroy(__old_finish + 1, this->_M_finish),
1.226 + this->_M_finish = __old_finish));
1.227 + _Traits::assign(__position, __elems_after + 1, __c);
1.228 + }
1.229 + }
1.230 + else {
1.231 + const size_type __old_size = size();
1.232 + const size_type __len = __old_size + (max)(__old_size, __n) + 1;
1.233 + pointer __new_start = this->_M_end_of_storage.allocate(__len);
1.234 + _STLP_LEAVE_VOLATILE pointer __new_finish = __new_start;
1.235 + _STLP_TRY {
1.236 + __new_finish = uninitialized_copy(this->_M_start, __position, __new_start);
1.237 + __new_finish = uninitialized_fill_n(__new_finish, __n, __c);
1.238 + __new_finish = uninitialized_copy(__position, this->_M_finish,
1.239 + __new_finish);
1.240 + _M_construct_null(__new_finish);
1.241 + }
1.242 + _STLP_UNWIND((_STLP_STD::_Destroy(__new_start,__new_finish),
1.243 + this->_M_end_of_storage.deallocate(__new_start,__len)));
1.244 + _STLP_STD::_Destroy(this->_M_start, this->_M_finish + 1);
1.245 + this->_M_deallocate_block();
1.246 + this->_M_start = __new_start;
1.247 + this->_M_finish = __new_finish;
1.248 + this->_M_end_of_storage._M_data = __new_start + __len;
1.249 + }
1.250 + }
1.251 +}
1.252 +
1.253 +#ifndef _STLP_MEMBER_TEMPLATES
1.254 +
1.255 +template <class _CharT, class _Traits, class _Alloc>
1.256 +_STLP_EXP_DECLSPEC void
1.257 +basic_string<_CharT,_Traits,_Alloc>::insert(iterator __position,
1.258 + const _CharT* __first,
1.259 + const _CharT* __last)
1.260 +{
1.261 + if (__first != __last) {
1.262 + const ptrdiff_t __n = __last - __first;
1.263 + if (this->_M_end_of_storage._M_data - this->_M_finish >= __n + 1) {
1.264 + const ptrdiff_t __elems_after = this->_M_finish - __position;
1.265 + pointer __old_finish = this->_M_finish;
1.266 + if (__elems_after >= __n) {
1.267 + uninitialized_copy((this->_M_finish - __n) + 1, this->_M_finish + 1,
1.268 + this->_M_finish + 1);
1.269 + this->_M_finish += __n;
1.270 + _Traits::move(__position + __n,
1.271 + __position, (__elems_after - __n) + 1);
1.272 + _M_copy(__first, __last, __position);
1.273 + }
1.274 + else {
1.275 + const _CharT* __mid = __first;
1.276 + advance(__mid, __elems_after + 1);
1.277 + uninitialized_copy(__mid, __last, this->_M_finish + 1);
1.278 + this->_M_finish += __n - __elems_after;
1.279 + _STLP_TRY {
1.280 + uninitialized_copy(__position, __old_finish + 1, this->_M_finish);
1.281 + this->_M_finish += __elems_after;
1.282 + }
1.283 + _STLP_UNWIND((_STLP_STD::_Destroy(__old_finish + 1, this->_M_finish),
1.284 + this->_M_finish = __old_finish));
1.285 + _M_copy(__first, __mid, __position);
1.286 + }
1.287 + }
1.288 + else {
1.289 + size_type __old_size = size();
1.290 + size_type __len
1.291 + = __old_size + (max)(__old_size, __STATIC_CAST(const size_type,__n)) + 1;
1.292 + pointer __new_start = this->_M_end_of_storage.allocate(__len);
1.293 + _STLP_LEAVE_VOLATILE pointer __new_finish = __new_start;
1.294 + _STLP_TRY {
1.295 + __new_finish = uninitialized_copy(this->_M_start, __position, __new_start);
1.296 + __new_finish = uninitialized_copy(__first, __last, __new_finish);
1.297 + __new_finish
1.298 + = uninitialized_copy(__position, this->_M_finish, __new_finish);
1.299 + _M_construct_null(__new_finish);
1.300 + }
1.301 + _STLP_UNWIND((_STLP_STD::_Destroy(__new_start,__new_finish),
1.302 + this->_M_end_of_storage.deallocate(__new_start,__len)));
1.303 + _STLP_STD::_Destroy(this->_M_start, this->_M_finish + 1);
1.304 + this->_M_deallocate_block();
1.305 + this->_M_start = __new_start;
1.306 + this->_M_finish = __new_finish;
1.307 + this->_M_end_of_storage._M_data = __new_start + __len;
1.308 + }
1.309 + }
1.310 +}
1.311 +
1.312 +#endif /* _STLP_MEMBER_TEMPLATES */
1.313 +
1.314 +template <class _CharT, class _Traits, class _Alloc>
1.315 +_STLP_EXP_DECLSPEC basic_string<_CharT,_Traits,_Alloc>&
1.316 +basic_string<_CharT,_Traits,_Alloc>::replace(iterator __first, iterator __last, size_type __n, _CharT __c)
1.317 +{
1.318 + size_type __len = (size_type)(__last - __first);
1.319 +
1.320 + if (__len >= __n) {
1.321 + _Traits::assign(__first, __n, __c);
1.322 + erase(__first + __n, __last);
1.323 + }
1.324 + else {
1.325 + _Traits::assign(__first, __len, __c);
1.326 + insert(__last, __n - __len, __c);
1.327 + }
1.328 + return *this;
1.329 +}
1.330 +
1.331 +#ifndef _STLP_MEMBER_TEMPLATES
1.332 +
1.333 +
1.334 +template <class _CharT, class _Traits, class _Alloc>
1.335 +_STLP_EXP_DECLSPEC basic_string<_CharT,_Traits,_Alloc>&
1.336 +basic_string<_CharT,_Traits,_Alloc> ::replace(iterator __first, iterator __last,
1.337 + const _CharT* __f, const _CharT* __l)
1.338 +{
1.339 + const ptrdiff_t __n = __l - __f;
1.340 + const difference_type __len = __last - __first;
1.341 + if (__len >= __n) {
1.342 + _M_copy(__f, __l, __first);
1.343 + erase(__first + __n, __last);
1.344 + }
1.345 + else {
1.346 + const _CharT* __m = __f + __len;
1.347 + _M_copy(__f, __m, __first);
1.348 + insert(__last, __m, __l);
1.349 + }
1.350 + return *this;
1.351 +}
1.352 +
1.353 +#endif /* _STLP_MEMBER_TEMPLATES */
1.354 +
1.355 +template <class _CharT, class _Traits, class _Alloc>
1.356 +_STLP_EXP_DECLSPEC __size_type__
1.357 +basic_string<_CharT,_Traits,_Alloc> ::find(const _CharT* __s, size_type __pos, size_type __n) const
1.358 +{
1.359 +#ifndef __SYMBIAN32__ // A different implementation without using search
1.360 + if (__pos + __n > size())
1.361 + return npos;
1.362 + else {
1.363 + const const_pointer __result =
1.364 + _STLP_STD::search((const _CharT*)this->_M_start + __pos, (const _CharT*)this->_M_finish,
1.365 + __s, __s + __n, _Eq_traits<_Traits>());
1.366 + return __result != this->_M_finish ? __result - this->_M_start : npos;
1.367 + }
1.368 +#else
1.369 + const size_type __len = this->size();
1.370 + size_t __tpos = __pos;
1.371 + const _CharT* __data = this->_M_start;
1.372 + while (__tpos + __n <= __len) {
1.373 + if (traits_type::compare(__data + __tpos, __s, __n) == 0)
1.374 + return __tpos;
1.375 + ++__tpos;
1.376 + }
1.377 + return npos;
1.378 +#endif //__SYMBIAN32__
1.379 +}
1.380 +
1.381 +template <class _CharT, class _Traits, class _Alloc>
1.382 +_STLP_EXP_DECLSPEC __size_type__
1.383 +basic_string<_CharT,_Traits,_Alloc> ::find(_CharT __c, size_type __pos) const
1.384 +{
1.385 + if (__pos >= size())
1.386 + return npos;
1.387 + else {
1.388 + const const_pointer __result =
1.389 + _STLP_STD::find_if((const _CharT*)this->_M_start + __pos, (const _CharT*)this->_M_finish,
1.390 + _Eq_char_bound<_Traits>(__c));
1.391 + return __result != this->_M_finish ? __result - this->_M_start : npos;
1.392 + }
1.393 +}
1.394 +
1.395 +template <class _CharT, class _Traits, class _Alloc>
1.396 +_STLP_EXP_DECLSPEC __size_type__
1.397 +basic_string<_CharT,_Traits,_Alloc> ::rfind(const _CharT* __s, size_type __pos, size_type __n) const
1.398 +{
1.399 + const size_t __len = size();
1.400 +
1.401 + if (__n > __len)
1.402 + return npos;
1.403 + else if (__n == 0)
1.404 + return (min) (__len, __pos);
1.405 + else {
1.406 + const_pointer __last = this->_M_start + (min) (__len - __n, __pos) + __n;
1.407 + const_pointer __result = _STLP_STD::find_end((const_pointer)this->_M_start, __last,
1.408 + __s, __s + __n,
1.409 + _Eq_traits<_Traits>());
1.410 + return __result != __last ? __result - this->_M_start : npos;
1.411 + }
1.412 +}
1.413 +
1.414 +template <class _CharT, class _Traits, class _Alloc>
1.415 +_STLP_EXP_DECLSPEC __size_type__
1.416 +basic_string<_CharT,_Traits,_Alloc> ::rfind(_CharT __c, size_type __pos) const
1.417 +{
1.418 + const size_type __len = size();
1.419 +
1.420 + if (__len < 1)
1.421 + return npos;
1.422 + else {
1.423 + const const_iterator __last = begin() + (min) (__len - 1, __pos) + 1;
1.424 + const_reverse_iterator __rresult =
1.425 + _STLP_STD::find_if(const_reverse_iterator(__last), rend(),
1.426 + _Eq_char_bound<_Traits>(__c));
1.427 + return __rresult != rend() ? (__rresult.base() - 1) - begin() : npos;
1.428 + }
1.429 +}
1.430 +
1.431 +template <class _CharT, class _Traits, class _Alloc>
1.432 +_STLP_EXP_DECLSPEC __size_type__
1.433 +basic_string<_CharT,_Traits,_Alloc>
1.434 + ::find_first_of(const _CharT* __s, size_type __pos, size_type __n) const
1.435 +{
1.436 + if (__pos >= size())
1.437 + return npos;
1.438 + else {
1.439 + const_iterator __result = __find_first_of(begin() + __pos, end(),
1.440 + __s, __s + __n,
1.441 + _Eq_traits<_Traits>());
1.442 + return __result != end() ? __result - begin() : npos;
1.443 + }
1.444 +}
1.445 +
1.446 +
1.447 +template <class _CharT, class _Traits, class _Alloc>
1.448 +_STLP_EXP_DECLSPEC __size_type__
1.449 +basic_string<_CharT,_Traits,_Alloc>
1.450 + ::find_last_of(const _CharT* __s, size_type __pos, size_type __n) const
1.451 +{
1.452 + const size_type __len = size();
1.453 +
1.454 + if (__len < 1)
1.455 + return npos;
1.456 + else {
1.457 + const const_iterator __last = begin() + (min) (__len - 1, __pos) + 1;
1.458 + const const_reverse_iterator __rresult =
1.459 + __find_first_of(const_reverse_iterator(__last), rend(),
1.460 + __s, __s + __n,
1.461 + _Eq_traits<_Traits>());
1.462 + return __rresult != rend() ? (__rresult.base() - 1) - begin() : npos;
1.463 + }
1.464 +}
1.465 +
1.466 +
1.467 +template <class _CharT, class _Traits, class _Alloc>
1.468 +_STLP_EXP_DECLSPEC __size_type__
1.469 +basic_string<_CharT,_Traits,_Alloc> ::find_first_not_of(const _CharT* __s, size_type __pos, size_type __n) const
1.470 +{
1.471 + typedef typename _Traits::char_type _CharType;
1.472 + if (__pos > size())
1.473 + return npos;
1.474 + else {
1.475 + const_pointer __result = _STLP_STD::find_if((const _CharT*)this->_M_start + __pos,
1.476 + (const _CharT*)this->_M_finish,
1.477 + _Not_within_traits<_Traits>((const _CharType*)__s,
1.478 + (const _CharType*)__s + __n));
1.479 + return __result != this->_M_finish ? __result - this->_M_start : npos;
1.480 + }
1.481 +}
1.482 +
1.483 +template <class _CharT, class _Traits, class _Alloc>
1.484 +_STLP_EXP_DECLSPEC __size_type__
1.485 +basic_string<_CharT,_Traits,_Alloc> ::find_first_not_of(_CharT __c, size_type __pos) const
1.486 +{
1.487 + if (__pos > size())
1.488 + return npos;
1.489 + else {
1.490 + const_pointer __result = _STLP_STD::find_if((const _CharT*)this->_M_start + __pos, (const _CharT*)this->_M_finish,
1.491 + _Neq_char_bound<_Traits>(__c));
1.492 + return __result != this->_M_finish ? __result - this->_M_start : npos;
1.493 + }
1.494 +}
1.495 +
1.496 +template <class _CharT, class _Traits, class _Alloc>
1.497 +_STLP_EXP_DECLSPEC __size_type__
1.498 +basic_string<_CharT,_Traits,_Alloc> ::find_last_not_of(const _CharT* __s, size_type __pos, size_type __n) const
1.499 +{
1.500 + typedef typename _Traits::char_type _CharType;
1.501 + const size_type __len = size();
1.502 +
1.503 + if (__len < 1)
1.504 + return npos;
1.505 + else {
1.506 + const_iterator __last = begin() + (min) (__len - 1, __pos) + 1;
1.507 + const_reverse_iterator __rlast = const_reverse_iterator(__last);
1.508 + const_reverse_iterator __rresult =
1.509 + _STLP_STD::find_if(__rlast, rend(),
1.510 + _Not_within_traits<_Traits>((const _CharType*)__s,
1.511 + (const _CharType*)__s + __n));
1.512 + return __rresult != rend() ? (__rresult.base() - 1) - begin() : npos;
1.513 + }
1.514 +}
1.515 +
1.516 +template <class _CharT, class _Traits, class _Alloc>
1.517 +_STLP_EXP_DECLSPEC __size_type__
1.518 +basic_string<_CharT, _Traits, _Alloc> ::find_last_not_of(_CharT __c, size_type __pos) const
1.519 +{
1.520 + const size_type __len = size();
1.521 +
1.522 + if (__len < 1)
1.523 + return npos;
1.524 + else {
1.525 + const_iterator __last = begin() + (min) (__len - 1, __pos) + 1;
1.526 + const_reverse_iterator __rlast = const_reverse_iterator(__last);
1.527 + const_reverse_iterator __rresult =
1.528 + _STLP_STD::find_if(__rlast, rend(),
1.529 + _Neq_char_bound<_Traits>(__c));
1.530 + return __rresult != rend() ? (__rresult.base() - 1) - begin() : npos;
1.531 + }
1.532 +}
1.533 +
1.534 +template <class _CharT, class _Traits, class _Alloc>
1.535 +void _STLP_CALL _S_string_copy(const basic_string<_CharT,_Traits,_Alloc>& __s,
1.536 + _CharT* __buf,
1.537 + size_t __n)
1.538 +{
1.539 + if (__n > 0) {
1.540 + __n = (min) (__n - 1, __s.size());
1.541 + _STLP_STD::copy(__s.begin(), __s.begin() + __n, __buf);
1.542 + __buf[__n] = _CharT();
1.543 + }
1.544 +}
1.545 +_STLP_END_NAMESPACE
1.546 +
1.547 +// _string_fwd has to see clean basic_string
1.548 +# undef basic_string
1.549 +
1.550 +# if !defined (_STLP_LINK_TIME_INSTANTIATION)
1.551 +# include <stl/_string_fwd.c>
1.552 +# endif
1.553 +
1.554 +# ifdef _STLP_DEBUG
1.555 +# define basic_string _Nondebug_string
1.556 +# endif
1.557 +
1.558 +# include <stl/_range_errors.h>
1.559 +_STLP_BEGIN_NAMESPACE
1.560 +
1.561 +// _String_base methods
1.562 +template <class _Tp, class _Alloc>
1.563 +void _String_base<_Tp,_Alloc>::_M_throw_length_error() const {
1.564 + __stl_throw_length_error("basic_string");
1.565 +}
1.566 +
1.567 +template <class _Tp, class _Alloc>
1.568 +void _String_base<_Tp, _Alloc>::_M_throw_out_of_range() const {
1.569 + __stl_throw_out_of_range("basic_string");
1.570 +}
1.571 +
1.572 +template <class _Tp, class _Alloc>
1.573 +void _String_base<_Tp, _Alloc>::_M_allocate_block(size_t __n) {
1.574 + if ((__n <= (max_size()+1)) && (__n>0)){
1.575 + _M_start = _M_end_of_storage.allocate(__n);
1.576 + _M_finish = _M_start;
1.577 + _M_end_of_storage._M_data = _M_start + __n;
1.578 + }
1.579 + else
1.580 + _M_throw_length_error();
1.581 +}
1.582 +
1.583 +template <class _CharT, class _Traits, class _Alloc>
1.584 +_STLP_EXP_DECLSPEC basic_string<_CharT, _Traits, _Alloc>::basic_string()
1.585 + : _String_base<_CharT,_Alloc>(allocator_type())
1.586 +{
1.587 + this->_M_start = this->_M_end_of_storage.allocate(8);
1.588 + this->_M_finish = this->_M_start;
1.589 + this->_M_end_of_storage._M_data = this->_M_start + 8;
1.590 + _M_terminate_string();
1.591 + _STLP_POP_CLEANUP_ITEM
1.592 +}
1.593 +
1.594 +
1.595 +template <class _CharT, class _Traits, class _Alloc>
1.596 +_STLP_EXP_DECLSPEC basic_string<_CharT, _Traits, _Alloc>::basic_string(const _CharT* __s,
1.597 + const allocator_type& __a)
1.598 + : _String_base<_CharT,_Alloc>(__a)
1.599 +{
1.600 + _STLP_FIX_LITERAL_BUG(__s)
1.601 + _M_range_initialize(__s, __s + traits_type::length(__s));
1.602 + _STLP_POP_CLEANUP_ITEM
1.603 +}
1.604 +
1.605 +
1.606 +template <class _CharT, class _Traits, class _Alloc>
1.607 +_STLP_EXP_DECLSPEC basic_string<_CharT, _Traits, _Alloc>::basic_string(const basic_string<_CharT, _Traits, _Alloc> & __s)
1.608 + : _String_base<_CharT,_Alloc>(__s.get_allocator())
1.609 +{
1.610 + _M_range_initialize(__s._M_start, __s._M_finish);
1.611 + _STLP_POP_CLEANUP_ITEM
1.612 +}
1.613 +
1.614 +# if defined ( __SUNPRO_CC) && ! defined(_STLP_STATIC_CONST_INIT_BUG)
1.615 +template <class _CharT, class _Traits, class _Alloc> const size_t basic_string<_CharT, _Traits, _Alloc>::npos;
1.616 +# endif
1.617 +
1.618 +_STLP_END_NAMESPACE
1.619 +
1.620 +# undef basic_string
1.621 +# undef __size_type__
1.622 +# undef size_type
1.623 +# undef iterator
1.624 +# endif /* NATIVE */
1.625 +
1.626 +#endif /* _STLP_STRING_C */
1.627 +
1.628 +// Local Variables:
1.629 +// mode:C++
1.630 +// End: