epoc32/include/tools/stlport/stl/_string.c
branchSymbian3
changeset 4 837f303aceeb
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/epoc32/include/tools/stlport/stl/_string.c	Wed Mar 31 12:33:34 2010 +0100
     1.3 @@ -0,0 +1,693 @@
     1.4 +/*
     1.5 + *
     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_INTERNAL_STRING_H
    1.33 +#  include <stl/_string.h>
    1.34 +#endif
    1.35 +
    1.36 +#ifndef _STLP_INTERNAL_CTRAITS_FUNCTIONS_H
    1.37 +#  include <stl/_ctraits_fns.h>
    1.38 +#endif
    1.39 +
    1.40 +#if defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
    1.41 +#  define basic_string _STLP_NO_MEM_T_NAME(str)
    1.42 +#elif defined (_STLP_DEBUG)
    1.43 +#  define basic_string _STLP_NON_DBG_NAME(str)
    1.44 +#endif
    1.45 +
    1.46 +#if defined (_STLP_NESTED_TYPE_PARAM_BUG)
    1.47 +#  define __size_type__ size_t
    1.48 +#  define size_type size_t
    1.49 +#  define iterator _CharT*
    1.50 +#else
    1.51 +#  define __size_type__ _STLP_TYPENAME_ON_RETURN_TYPE basic_string<_CharT,_Traits,_Alloc>::size_type
    1.52 +#endif
    1.53 +
    1.54 +_STLP_BEGIN_NAMESPACE
    1.55 +
    1.56 +_STLP_MOVE_TO_PRIV_NAMESPACE
    1.57 +
    1.58 +// A helper class to use a char_traits as a function object.
    1.59 +template <class _Traits>
    1.60 +struct _Not_within_traits : public unary_function<typename _Traits::char_type, bool> {
    1.61 +  typedef typename _Traits::char_type _CharT;
    1.62 +  const _CharT* _M_first;
    1.63 +  const _CharT* _M_last;
    1.64 +
    1.65 +  _Not_within_traits(const _CharT* __f, const _CharT* __l)
    1.66 +    : _M_first(__f), _M_last(__l) {}
    1.67 +
    1.68 +  bool operator()(const _CharT& __x) const {
    1.69 +    return find_if(_M_first, _M_last,
    1.70 +                   _STLP_PRIV _Eq_char_bound<_Traits>(__x)) == _M_last;
    1.71 +  }
    1.72 +};
    1.73 +
    1.74 +// ------------------------------------------------------------
    1.75 +// Non-inline declarations.
    1.76 +
    1.77 +#if !defined (basic_string)
    1.78 +_STLP_MOVE_TO_STD_NAMESPACE
    1.79 +#endif
    1.80 +
    1.81 +// Change the string's capacity so that it is large enough to hold
    1.82 +//  at least __res_arg elements, plus the terminating _CharT().  Note that,
    1.83 +//  if __res_arg < capacity(), this member function may actually decrease
    1.84 +//  the string's capacity.
    1.85 +template <class _CharT, class _Traits, class _Alloc>
    1.86 +void basic_string<_CharT,_Traits,_Alloc>::reserve(size_type __res_arg) {
    1.87 +  if (__res_arg > max_size())
    1.88 +    this->_M_throw_length_error();
    1.89 +
    1.90 +  size_type __n = (max)(__res_arg, size()) + 1;
    1.91 +  if (__n <= capacity() + 1)
    1.92 +    return;
    1.93 +
    1.94 +  pointer __new_start = this->_M_end_of_storage.allocate(__n, __n);
    1.95 +  pointer __new_finish = __new_start;
    1.96 +
    1.97 +  _STLP_TRY {
    1.98 +    __new_finish = _STLP_PRIV __ucopy(this->_M_Start(), this->_M_Finish(), __new_start);
    1.99 +    _M_construct_null(__new_finish);
   1.100 +  }
   1.101 +  _STLP_UNWIND((_STLP_STD::_Destroy_Range(__new_start, __new_finish),
   1.102 +                this->_M_end_of_storage.deallocate(__new_start, __n)))
   1.103 +
   1.104 +  this->_M_destroy_range();
   1.105 +  this->_M_deallocate_block();
   1.106 +  this->_M_reset(__new_start, __new_finish, __new_start + __n);
   1.107 +}
   1.108 +
   1.109 +template <class _CharT, class _Traits, class _Alloc>
   1.110 +basic_string<_CharT,_Traits,_Alloc>&
   1.111 +basic_string<_CharT,_Traits,_Alloc>::append(size_type __n, _CharT __c) {
   1.112 +  if (__n > max_size() || size() > max_size() - __n)
   1.113 +    this->_M_throw_length_error();
   1.114 +  if (size() + __n > capacity())
   1.115 +    reserve(size() + (max)(size(), __n));
   1.116 +  if (__n > 0) {
   1.117 +#if defined (_STLP_USE_SHORT_STRING_OPTIM)
   1.118 +    if (this->_M_using_static_buf())
   1.119 +      _Traits::assign(this->_M_finish + 1, __n - 1, __c);
   1.120 +    else
   1.121 +#endif /* _STLP_USE_SHORT_STRING_OPTIM */
   1.122 +    _STLP_PRIV __uninitialized_fill_n(this->_M_finish + 1, __n - 1, __c);
   1.123 +    _STLP_TRY {
   1.124 +      _M_construct_null(this->_M_finish + __n);
   1.125 +    }
   1.126 +    _STLP_UNWIND(this->_M_destroy_ptr_range(this->_M_finish + 1, this->_M_finish + __n))
   1.127 +    _Traits::assign(*end(), __c);
   1.128 +    this->_M_finish += __n;
   1.129 +  }
   1.130 +  return *this;
   1.131 +}
   1.132 +
   1.133 +template <class _CharT, class _Traits, class _Alloc>
   1.134 +basic_string<_CharT, _Traits, _Alloc>&
   1.135 +basic_string<_CharT, _Traits, _Alloc>::_M_append(const _CharT* __first, const _CharT* __last) {
   1.136 +  if (__first != __last) {
   1.137 +    const size_type __old_size = size();
   1.138 +    ptrdiff_t __n = __last - __first;
   1.139 +    if ((size_type)__n > max_size() || __old_size > max_size() - __n)
   1.140 +      this->_M_throw_length_error();
   1.141 +    if (__old_size + __n > capacity()) {
   1.142 +      size_type __len = __old_size + (max)(__old_size, (size_t) __n) + 1;
   1.143 +      pointer __new_start = this->_M_end_of_storage.allocate(__len, __len);
   1.144 +      pointer __new_finish = __new_start;
   1.145 +      _STLP_TRY {
   1.146 +        __new_finish = _STLP_PRIV __ucopy(this->_M_Start(), this->_M_Finish(), __new_start);
   1.147 +        __new_finish = _STLP_PRIV __ucopy(__first, __last, __new_finish);
   1.148 +        _M_construct_null(__new_finish);
   1.149 +      }
   1.150 +      _STLP_UNWIND((_STLP_STD::_Destroy_Range(__new_start,__new_finish),
   1.151 +                    this->_M_end_of_storage.deallocate(__new_start,__len)))
   1.152 +      this->_M_destroy_range();
   1.153 +      this->_M_deallocate_block();
   1.154 +      this->_M_reset(__new_start, __new_finish, __new_start + __len);
   1.155 +    }
   1.156 +    else {
   1.157 +      const _CharT* __f1 = __first;
   1.158 +      ++__f1;
   1.159 +#if defined (_STLP_USE_SHORT_STRING_OPTIM)
   1.160 +      if (this->_M_using_static_buf())
   1.161 +        _M_copy(__f1, __last, this->_M_Finish() + 1);
   1.162 +      else
   1.163 +#endif /* _STLP_USE_SHORT_STRING_OPTIM */
   1.164 +      _STLP_PRIV __ucopy(__f1, __last, this->_M_finish + 1);
   1.165 +      _STLP_TRY {
   1.166 +        _M_construct_null(this->_M_finish + __n);
   1.167 +      }
   1.168 +      _STLP_UNWIND(this->_M_destroy_ptr_range(this->_M_finish + 1, this->_M_finish + __n))
   1.169 +      _Traits::assign(*end(), *__first);
   1.170 +      this->_M_finish += __n;
   1.171 +    }
   1.172 +  }
   1.173 +  return *this;
   1.174 +}
   1.175 +
   1.176 +template <class _CharT, class _Traits, class _Alloc>
   1.177 +basic_string<_CharT,_Traits,_Alloc>&
   1.178 +basic_string<_CharT,_Traits,_Alloc>::assign(size_type __n, _CharT __c) {
   1.179 +  if (__n <= size()) {
   1.180 +    _Traits::assign(this->_M_Start(), __n, __c);
   1.181 +    erase(begin() + __n, end());
   1.182 +  }
   1.183 +  else {
   1.184 +    if (__n < capacity()) {
   1.185 +      _Traits::assign(this->_M_Start(), size(), __c);
   1.186 +      append(__n - size(), __c);
   1.187 +    }
   1.188 +    else {
   1.189 +      _Self __str(__n, __c);
   1.190 +      this->swap(__str);
   1.191 +    }
   1.192 +  }
   1.193 +  return *this;
   1.194 +}
   1.195 +
   1.196 +template <class _CharT, class _Traits, class _Alloc>
   1.197 +basic_string<_CharT,_Traits,_Alloc>&
   1.198 +basic_string<_CharT,_Traits,_Alloc>::_M_assign(const _CharT* __f, const _CharT* __l) {
   1.199 +  ptrdiff_t __n = __l - __f;
   1.200 +  if (__STATIC_CAST(size_type, __n) <= size()) {
   1.201 +    _Traits::copy(this->_M_Start(), __f, __n);
   1.202 +    erase(begin() + __n, end());
   1.203 +  }
   1.204 +  else {
   1.205 +    _Traits::copy(this->_M_Start(), __f, size());
   1.206 +    _M_append(__f + size(), __l);
   1.207 +  }
   1.208 +  return *this;
   1.209 +}
   1.210 +
   1.211 +template <class _CharT, class _Traits, class _Alloc>
   1.212 +_CharT* basic_string<_CharT,_Traits,_Alloc> ::_M_insert_aux(_CharT* __p,
   1.213 +                                                            _CharT __c) {
   1.214 +  pointer __new_pos = __p;
   1.215 +  if (this->_M_finish + 1 < this->_M_end_of_storage._M_data) {
   1.216 +    _M_construct_null(this->_M_finish + 1);
   1.217 +    _Traits::move(__p + 1, __p, this->_M_finish - __p);
   1.218 +    _Traits::assign(*__p, __c);
   1.219 +    ++this->_M_finish;
   1.220 +  }
   1.221 +  else {
   1.222 +    const size_type __old_len = size();
   1.223 +    size_type __len = __old_len + (max)(__old_len, __STATIC_CAST(size_type,1)) + 1;
   1.224 +    pointer __new_start = this->_M_end_of_storage.allocate(__len, __len);
   1.225 +    pointer __new_finish = __new_start;
   1.226 +    _STLP_TRY {
   1.227 +      __new_pos = _STLP_PRIV __ucopy(this->_M_Start(), __p, __new_start);
   1.228 +      _Copy_Construct(__new_pos, __c);
   1.229 +      __new_finish = __new_pos + 1;
   1.230 +      __new_finish = _STLP_PRIV __ucopy(__p, this->_M_finish, __new_finish);
   1.231 +      _M_construct_null(__new_finish);
   1.232 +    }
   1.233 +    _STLP_UNWIND((_STLP_STD::_Destroy_Range(__new_start,__new_finish),
   1.234 +                  this->_M_end_of_storage.deallocate(__new_start,__len)))
   1.235 +    this->_M_destroy_range();
   1.236 +    this->_M_deallocate_block();
   1.237 +    this->_M_reset(__new_start, __new_finish, __new_start + __len);
   1.238 +  }
   1.239 +  return __new_pos;
   1.240 +}
   1.241 +
   1.242 +template <class _CharT, class _Traits, class _Alloc>
   1.243 +void basic_string<_CharT,_Traits,_Alloc>::insert(iterator __pos,
   1.244 +                                                 size_t __n, _CharT __c) {
   1.245 +  if (__n != 0) {
   1.246 +    if (size_type(this->_M_end_of_storage._M_data - this->_M_finish) >= __n + 1) {
   1.247 +      const size_type __elems_after = this->_M_finish - __pos;
   1.248 +      pointer __old_finish = this->_M_finish;
   1.249 +      if (__elems_after >= __n) {
   1.250 +#if defined (_STLP_USE_SHORT_STRING_OPTIM)
   1.251 +        if (this->_M_using_static_buf())
   1.252 +          _M_copy((this->_M_finish - __n) + 1, this->_M_finish + 1, this->_M_finish + 1);
   1.253 +        else
   1.254 +#endif /* _STLP_USE_SHORT_STRING_OPTIM */
   1.255 +        _STLP_PRIV __ucopy((this->_M_finish - __n) + 1, this->_M_finish + 1,
   1.256 +                           this->_M_finish + 1);
   1.257 +        this->_M_finish += __n;
   1.258 +        _Traits::move(__pos + __n, __pos, (__elems_after - __n) + 1);
   1.259 +        _Traits::assign(__pos, __n, __c);
   1.260 +      }
   1.261 +      else {
   1.262 +#if defined (_STLP_USE_SHORT_STRING_OPTIM)
   1.263 +        if (this->_M_using_static_buf())
   1.264 +          _Traits::assign(this->_M_finish + 1, __n - __elems_after - 1, __c);
   1.265 +        else
   1.266 +#endif /* _STLP_USE_SHORT_STRING_OPTIM */
   1.267 +        _STLP_PRIV __uninitialized_fill_n(this->_M_finish + 1, __n - __elems_after - 1, __c);
   1.268 +        this->_M_finish += __n - __elems_after;
   1.269 +        _STLP_TRY {
   1.270 +#if defined (_STLP_USE_SHORT_STRING_OPTIM)
   1.271 +          if (this->_M_using_static_buf())
   1.272 +            _M_copy(__pos, __old_finish + 1, this->_M_finish);
   1.273 +          else
   1.274 +#endif /* _STLP_USE_SHORT_STRING_OPTIM */
   1.275 +          _STLP_PRIV __ucopy(__pos, __old_finish + 1, this->_M_finish);
   1.276 +          this->_M_finish += __elems_after;
   1.277 +        }
   1.278 +        _STLP_UNWIND((_STLP_STD::_Destroy_Range(__old_finish + 1, this->_M_finish),
   1.279 +                      this->_M_finish = __old_finish))
   1.280 +        _Traits::assign(__pos, __elems_after + 1, __c);
   1.281 +      }
   1.282 +    }
   1.283 +    else {
   1.284 +      const size_type __old_size = size();
   1.285 +      size_type __len = __old_size + (max)(__old_size, __n) + 1;
   1.286 +      pointer __new_start = this->_M_end_of_storage.allocate(__len, __len);
   1.287 +      pointer __new_finish = __new_start;
   1.288 +      _STLP_TRY {
   1.289 +        __new_finish = _STLP_PRIV __ucopy(this->_M_Start(), __pos, __new_start);
   1.290 +        __new_finish = _STLP_PRIV __uninitialized_fill_n(__new_finish, __n, __c);
   1.291 +        __new_finish = _STLP_PRIV __ucopy(__pos, this->_M_finish, __new_finish);
   1.292 +        _M_construct_null(__new_finish);
   1.293 +      }
   1.294 +      _STLP_UNWIND((_STLP_STD::_Destroy_Range(__new_start,__new_finish),
   1.295 +                    this->_M_end_of_storage.deallocate(__new_start,__len)))
   1.296 +      this->_M_destroy_range();
   1.297 +      this->_M_deallocate_block();
   1.298 +      this->_M_reset(__new_start, __new_finish, __new_start + __len);
   1.299 +    }
   1.300 +  }
   1.301 +}
   1.302 +
   1.303 +template <class _CharT, class _Traits, class _Alloc>
   1.304 +void basic_string<_CharT,_Traits,_Alloc>::_M_insert(iterator __pos,
   1.305 +                                                    const _CharT* __first, const _CharT* __last,
   1.306 +                                                    bool __self_ref) {
   1.307 +  //this version has to take care about the auto referencing
   1.308 +  if (__first != __last) {
   1.309 +    const ptrdiff_t __n = __last - __first;
   1.310 +    if (this->_M_end_of_storage._M_data - this->_M_finish >= __n + 1) {
   1.311 +      const ptrdiff_t __elems_after = this->_M_finish - __pos;
   1.312 +      pointer __old_finish = this->_M_finish;
   1.313 +      if (__elems_after >= __n) {
   1.314 +#if defined (_STLP_USE_SHORT_STRING_OPTIM)
   1.315 +        if (this->_M_using_static_buf())
   1.316 +          _M_copy((this->_M_finish - __n) + 1, this->_M_finish + 1, this->_M_finish + 1);
   1.317 +        else
   1.318 +#endif /* _STLP_USE_SHORT_STRING_OPTIM */
   1.319 +        _STLP_PRIV __ucopy((this->_M_finish - __n) + 1, this->_M_finish + 1, this->_M_finish + 1);
   1.320 +        this->_M_finish += __n;
   1.321 +        _Traits::move(__pos + __n, __pos, (__elems_after - __n) + 1);
   1.322 +        if (!__self_ref || __last < __pos) {
   1.323 +          _M_copy(__first, __last, __pos);
   1.324 +        }
   1.325 +        else {
   1.326 +          //We have to check that the source buffer hasn't move
   1.327 +          if (__first >= __pos) {
   1.328 +            //The source buffer has move
   1.329 +            __first += __n;
   1.330 +            __last += __n;
   1.331 +            _M_copy(__first, __last, __pos);
   1.332 +          }
   1.333 +          else {
   1.334 +            //The source buffer hasn't move, it has been duplicated
   1.335 +            _M_move(__first, __last, __pos);
   1.336 +          }
   1.337 +        }
   1.338 +      }
   1.339 +      else {
   1.340 +        const_iterator __mid = __first;
   1.341 +        __mid += __elems_after + 1;
   1.342 +#if defined (_STLP_USE_SHORT_STRING_OPTIM)
   1.343 +        if (this->_M_using_static_buf())
   1.344 +          _M_copy(__mid, __last, this->_M_finish + 1);
   1.345 +        else
   1.346 +#endif /* _STLP_USE_SHORT_STRING_OPTIM */
   1.347 +        _STLP_PRIV __ucopy(__mid, __last, this->_M_finish + 1);
   1.348 +        this->_M_finish += __n - __elems_after;
   1.349 +        _STLP_TRY {
   1.350 +#if defined (_STLP_USE_SHORT_STRING_OPTIM)
   1.351 +          if (this->_M_using_static_buf())
   1.352 +            _M_copy(__pos, __old_finish + 1, this->_M_finish);
   1.353 +          else
   1.354 +#endif /* _STLP_USE_SHORT_STRING_OPTIM */
   1.355 +          _STLP_PRIV __ucopy(__pos, __old_finish + 1, this->_M_finish);
   1.356 +          this->_M_finish += __elems_after;
   1.357 +        }
   1.358 +        _STLP_UNWIND((_STLP_STD::_Destroy_Range(__old_finish + 1, this->_M_finish),
   1.359 +                      this->_M_finish = __old_finish))
   1.360 +        if (!__self_ref)
   1.361 +          _M_copy(__first, __mid, __pos);
   1.362 +        else
   1.363 +          _M_move(__first, __mid, __pos);
   1.364 +      }
   1.365 +    }
   1.366 +    else {
   1.367 +      const size_type __old_size = size();
   1.368 +      size_type __len = __old_size + (max)(__old_size, __STATIC_CAST(const size_type,__n)) + 1;
   1.369 +      pointer __new_start = this->_M_end_of_storage.allocate(__len, __len);
   1.370 +      pointer __new_finish = __new_start;
   1.371 +      _STLP_TRY {
   1.372 +        __new_finish = _STLP_PRIV __ucopy(this->_M_Start(), __pos, __new_start);
   1.373 +        __new_finish = _STLP_PRIV __ucopy(__first, __last, __new_finish);
   1.374 +        __new_finish = _STLP_PRIV __ucopy(__pos, this->_M_finish, __new_finish);
   1.375 +        _M_construct_null(__new_finish);
   1.376 +      }
   1.377 +      _STLP_UNWIND((_STLP_STD::_Destroy_Range(__new_start,__new_finish),
   1.378 +                    this->_M_end_of_storage.deallocate(__new_start,__len)))
   1.379 +      this->_M_destroy_range();
   1.380 +      this->_M_deallocate_block();
   1.381 +      this->_M_reset(__new_start, __new_finish, __new_start + __len);
   1.382 +    }
   1.383 +  }
   1.384 +}
   1.385 +
   1.386 +template <class _CharT, class _Traits, class _Alloc>
   1.387 +basic_string<_CharT,_Traits,_Alloc>&
   1.388 +basic_string<_CharT,_Traits,_Alloc> ::replace(iterator __first, iterator __last,
   1.389 +                                              size_type __n, _CharT __c) {
   1.390 +  size_type __len = (size_type)(__last - __first);
   1.391 +
   1.392 +  if (__len >= __n) {
   1.393 +    _Traits::assign(__first, __n, __c);
   1.394 +    erase(__first + __n, __last);
   1.395 +  }
   1.396 +  else {
   1.397 +    _Traits::assign(__first, __len, __c);
   1.398 +    insert(__last, __n - __len, __c);
   1.399 +  }
   1.400 +  return *this;
   1.401 +}
   1.402 +
   1.403 +template <class _CharT, class _Traits, class _Alloc>
   1.404 +basic_string<_CharT,_Traits,_Alloc>&
   1.405 +basic_string<_CharT,_Traits,_Alloc> ::_M_replace(iterator __first, iterator __last,
   1.406 +                                                 const _CharT* __f, const _CharT* __l,
   1.407 +                                                 bool __self_ref) {
   1.408 +  const ptrdiff_t       __n = __l - __f;
   1.409 +  const difference_type __len = __last - __first;
   1.410 +  if (__len >= __n) {
   1.411 +    if (!__self_ref || __l < __first || __f >= __last)
   1.412 +      _M_copy(__f, __l, __first);
   1.413 +    else
   1.414 +      _M_move(__f, __l, __first);
   1.415 +    erase(__first + __n, __last);
   1.416 +  }
   1.417 +  else {
   1.418 +    if (!__self_ref || (__f >= __last) || (__l <= __first)) {
   1.419 +      //no overlap:
   1.420 +      const_iterator __m = __f + __len;
   1.421 +      _M_copy(__f, __m, __first);
   1.422 +      _M_insert(__last, __m, __l, false );
   1.423 +    }
   1.424 +    else {
   1.425 +      //we have to take care of overlaping
   1.426 +      if (__f < __first) {
   1.427 +        const_iterator __m = __f + __len;
   1.428 +        //We have to deal with possible reallocation because we do insert first.
   1.429 +        const difference_type __off_dest = __first - this->begin();
   1.430 +        const difference_type __off_src = __f - this->begin();
   1.431 +        _M_insert(__last, __m, __l, true);
   1.432 +        _Traits::move(begin() + __off_dest, begin() + __off_src, __len);
   1.433 +      }
   1.434 +      else {
   1.435 +        const_iterator __m = __f + __len;
   1.436 +        _Traits::move(__first, __f, __len);
   1.437 +        _M_insert(__last, __m, __l, true);
   1.438 +      }
   1.439 +    }
   1.440 +  }
   1.441 +  return *this;
   1.442 +}
   1.443 +
   1.444 +template <class _CharT, class _Traits, class _Alloc> __size_type__
   1.445 +basic_string<_CharT,_Traits,_Alloc> ::find(const _CharT* __s, size_type __pos,
   1.446 +                                           size_type __n) const {
   1.447 +  const size_t __len = size();
   1.448 +  if (__pos >= __len || __pos + __n > __len)
   1.449 +    return npos;
   1.450 +  else {
   1.451 +    const_pointer __result =
   1.452 +      _STLP_STD::search(this->_M_Start() + __pos, this->_M_Finish(),
   1.453 +                        __s, __s + __n, _STLP_PRIV _Eq_traits<_Traits>());
   1.454 +    return __result != this->_M_Finish() ? __result - this->_M_Start() : npos;
   1.455 +  }
   1.456 +}
   1.457 +
   1.458 +template <class _CharT, class _Traits, class _Alloc> __size_type__
   1.459 +basic_string<_CharT,_Traits,_Alloc> ::find(_CharT __c, size_type __pos) const {
   1.460 +  if (__pos >= size()) /*__pos + 1 > size()*/
   1.461 +    return npos;
   1.462 +  else {
   1.463 +    const_pointer __result =
   1.464 +      _STLP_STD::find_if(this->_M_Start() + __pos, this->_M_Finish(),
   1.465 +                         _STLP_PRIV _Eq_char_bound<_Traits>(__c));
   1.466 +    return __result != this->_M_Finish() ? __result - this->_M_Start() : npos;
   1.467 +  }
   1.468 +}
   1.469 +
   1.470 +template <class _CharT, class _Traits, class _Alloc> __size_type__
   1.471 +basic_string<_CharT,_Traits,_Alloc> ::rfind(const _CharT* __s, size_type __pos,
   1.472 +                                            size_type __n) const {
   1.473 +  const size_t __len = size();
   1.474 +  if (__n > __len || __pos < __n)
   1.475 +    return npos;
   1.476 +  else if (__n == 0)
   1.477 +    return (min) (__len, __pos);
   1.478 +  else {
   1.479 +    const_pointer __last = this->_M_Start() + (min) (__len - __n, __pos) + __n;
   1.480 +    const_pointer __result = _STLP_PRIV __find_end(this->_M_Start(), __last,
   1.481 +                                                   __s, __s + __n,
   1.482 +                                                   bidirectional_iterator_tag(), bidirectional_iterator_tag(),
   1.483 +                                                   _STLP_PRIV _Eq_traits<_Traits>());
   1.484 +    return __result != __last ? __result - this->_M_Start() : npos;
   1.485 +  }
   1.486 +}
   1.487 +
   1.488 +template <class _CharT, class _Traits, class _Alloc> __size_type__
   1.489 +basic_string<_CharT,_Traits,_Alloc> ::rfind(_CharT __c, size_type __pos) const {
   1.490 +  const size_type __len = size();
   1.491 +  if (1 > __len || __pos < 1)
   1.492 +    return npos;
   1.493 +  else {
   1.494 +    const_iterator __last = begin() + (min) (__len - 1, __pos) + 1;
   1.495 +    const_reverse_iterator __rresult =
   1.496 +      _STLP_STD::find_if(const_reverse_iterator(__last), rend(),
   1.497 +                         _STLP_PRIV _Eq_char_bound<_Traits>(__c));
   1.498 +    return __rresult != rend() ? (__rresult.base() - 1) - begin() : npos;
   1.499 +  }
   1.500 +}
   1.501 +
   1.502 +template <class _CharT, class _Traits, class _Alloc> __size_type__
   1.503 +basic_string<_CharT,_Traits,_Alloc> ::find_first_of(const _CharT* __s, size_type __pos,
   1.504 +                                                    size_type __n) const {
   1.505 +  if (__pos >= size()) /*__pos + 1 > size()*/
   1.506 +    return npos;
   1.507 +  else {
   1.508 +    const_iterator __result = _STLP_PRIV __find_first_of(begin() + __pos, end(),
   1.509 +                                                         __s, __s + __n,
   1.510 +                                                         _STLP_PRIV _Eq_traits<_Traits>());
   1.511 +    return __result != end() ? __result - begin() : npos;
   1.512 +  }
   1.513 +}
   1.514 +
   1.515 +
   1.516 +template <class _CharT, class _Traits, class _Alloc> __size_type__
   1.517 +basic_string<_CharT,_Traits,_Alloc> ::find_last_of(const _CharT* __s, size_type __pos,
   1.518 +                                                   size_type __n) const {
   1.519 +  const size_type __len = size();
   1.520 +  if (1 > __len || __pos < 1)
   1.521 +    return npos;
   1.522 +  else {
   1.523 +    const const_iterator __last = begin() + (min) (__len - 1, __pos) + 1;
   1.524 +    const const_reverse_iterator __rresult =
   1.525 +      _STLP_PRIV __find_first_of(const_reverse_iterator(__last), rend(),
   1.526 +                                 __s, __s + __n,
   1.527 +                                 _STLP_PRIV _Eq_traits<_Traits>());
   1.528 +    return __rresult != rend() ? (__rresult.base() - 1) - begin() : npos;
   1.529 +  }
   1.530 +}
   1.531 +
   1.532 +
   1.533 +template <class _CharT, class _Traits, class _Alloc> __size_type__
   1.534 +basic_string<_CharT,_Traits,_Alloc> ::find_first_not_of(const _CharT* __s, size_type __pos,
   1.535 +                                                        size_type __n) const {
   1.536 +  typedef typename _Traits::char_type _CharType;
   1.537 +  if (__pos >= size()) /*__pos + 1 >= size()*/
   1.538 +    return npos;
   1.539 +  else {
   1.540 +    const_pointer __result = _STLP_STD::find_if(this->_M_Start() + __pos, this->_M_Finish(),
   1.541 +                                                _STLP_PRIV _Not_within_traits<_Traits>(__CONST_CAST(const _CharType*, __s),
   1.542 +                                                                                        __CONST_CAST(const _CharType*, __s) + __n));
   1.543 +    return __result != this->_M_finish ? __result - this->_M_Start() : npos;
   1.544 +  }
   1.545 +}
   1.546 +
   1.547 +template <class _CharT, class _Traits, class _Alloc> __size_type__
   1.548 +basic_string<_CharT,_Traits,_Alloc> ::find_first_not_of(_CharT __c, size_type __pos) const {
   1.549 +  if (1 > size())
   1.550 +    return npos;
   1.551 +  else {
   1.552 +    const_pointer __result = _STLP_STD::find_if(this->_M_Start() + __pos, this->_M_Finish(),
   1.553 +                                                _STLP_PRIV _Neq_char_bound<_Traits>(__c));
   1.554 +    return __result != this->_M_finish ? __result - this->_M_Start() : npos;
   1.555 +  }
   1.556 +}
   1.557 +
   1.558 +template <class _CharT, class _Traits, class _Alloc> __size_type__
   1.559 +basic_string<_CharT,_Traits,_Alloc> ::find_last_not_of(const _CharT* __s, size_type __pos,
   1.560 +                                                       size_type __n) const {
   1.561 +  typedef typename _Traits::char_type _CharType;
   1.562 +  const size_type __len = size();
   1.563 +  if (1 > __len || __pos < 1)
   1.564 +    return npos;
   1.565 +  else {
   1.566 +    const_iterator __last = begin() + (min) (__len - 1, __pos) + 1;
   1.567 +    const_reverse_iterator __rlast = const_reverse_iterator(__last);
   1.568 +    const_reverse_iterator __rresult =
   1.569 +      _STLP_STD::find_if(__rlast, rend(),
   1.570 +                         _STLP_PRIV _Not_within_traits<_Traits>((const _CharType*)__s,
   1.571 +                                                                 (const _CharType*)__s + __n));
   1.572 +    return __rresult != rend() ? (__rresult.base() - 1) - begin() : npos;
   1.573 +  }
   1.574 +}
   1.575 +
   1.576 +template <class _CharT, class _Traits, class _Alloc> __size_type__
   1.577 +basic_string<_CharT, _Traits, _Alloc> ::find_last_not_of(_CharT __c, size_type __pos) const {
   1.578 +  const size_type __len = size();
   1.579 +  if (1 > __len || __pos < 1)
   1.580 +    return npos;
   1.581 +  else {
   1.582 +    const_iterator __last = begin() + (min) (__len - 1, __pos) + 1;
   1.583 +    const_reverse_iterator __rlast = const_reverse_iterator(__last);
   1.584 +    const_reverse_iterator __rresult =
   1.585 +      _STLP_STD::find_if(__rlast, rend(),
   1.586 +                         _STLP_PRIV _Neq_char_bound<_Traits>(__c));
   1.587 +    return __rresult != rend() ? (__rresult.base() - 1) - begin() : npos;
   1.588 +  }
   1.589 +}
   1.590 +
   1.591 +#if !defined (basic_string)
   1.592 +_STLP_MOVE_TO_PRIV_NAMESPACE
   1.593 +#endif
   1.594 +
   1.595 +template <class _CharT, class _Traits, class _Alloc>
   1.596 +void _STLP_CALL _S_string_copy(const basic_string<_CharT,_Traits,_Alloc>& __s,
   1.597 +                               _CharT* __buf, size_t __n) {
   1.598 +  if (__n > 0) {
   1.599 +    __n = (min) (__n - 1, __s.size());
   1.600 +    _STLP_STD::copy(__s.begin(), __s.begin() + __n, __buf);
   1.601 +    __buf[__n] = _CharT();
   1.602 +  }
   1.603 +}
   1.604 +
   1.605 +_STLP_MOVE_TO_STD_NAMESPACE
   1.606 +
   1.607 +_STLP_END_NAMESPACE
   1.608 +
   1.609 +#include <stl/_range_errors.h>
   1.610 +
   1.611 +_STLP_BEGIN_NAMESPACE
   1.612 +
   1.613 +_STLP_MOVE_TO_PRIV_NAMESPACE
   1.614 +
   1.615 +// _String_base methods
   1.616 +template <class _Tp, class _Alloc>
   1.617 +void _String_base<_Tp,_Alloc>::_M_throw_length_error() const
   1.618 +{ __stl_throw_length_error("basic_string"); }
   1.619 +
   1.620 +template <class _Tp, class _Alloc>
   1.621 +void _String_base<_Tp, _Alloc>::_M_throw_out_of_range() const
   1.622 +{ __stl_throw_out_of_range("basic_string"); }
   1.623 +
   1.624 +template <class _Tp, class _Alloc>
   1.625 +void _String_base<_Tp, _Alloc>::_M_allocate_block(size_t __n) {
   1.626 +  if ((__n <= (max_size() + 1)) && (__n > 0)) {
   1.627 +#if defined (_STLP_USE_SHORT_STRING_OPTIM)
   1.628 +    if (__n > _DEFAULT_SIZE) {
   1.629 +      this->_M_buffers._M_dynamic_buf = _M_end_of_storage.allocate(__n, __n);
   1.630 +      this->_M_finish = this->_M_buffers._M_dynamic_buf;
   1.631 +      this->_M_end_of_storage._M_data = this->_M_finish + __n;
   1.632 +    }
   1.633 +#else
   1.634 +    this->_M_start  = _M_end_of_storage.allocate(__n, __n);
   1.635 +    this->_M_finish = this->_M_start;
   1.636 +    this->_M_end_of_storage._M_data = this->_M_finish + __n;
   1.637 +#endif /*_STLP_USE_SHORT_STRING_OPTIM  */
   1.638 +  } else {
   1.639 +    this->_M_throw_length_error();
   1.640 +  }
   1.641 +}
   1.642 +
   1.643 +#if !defined (basic_string)
   1.644 +_STLP_MOVE_TO_STD_NAMESPACE
   1.645 +#endif
   1.646 +
   1.647 +#if defined (_STLP_DONT_SUP_DFLT_PARAM)
   1.648 +template <class _CharT, class _Traits, class _Alloc>
   1.649 +basic_string<_CharT, _Traits, _Alloc>::basic_string(const _CharT* __s)
   1.650 +  : _STLP_PRIV _String_base<_CharT,_Alloc>(allocator_type()) {
   1.651 +  _STLP_FIX_LITERAL_BUG(__s)
   1.652 +  _M_range_initialize(__s, __s + traits_type::length(__s));
   1.653 +}
   1.654 +#endif
   1.655 +
   1.656 +template <class _CharT, class _Traits, class _Alloc>
   1.657 +basic_string<_CharT, _Traits, _Alloc>::basic_string(const _CharT* __s,
   1.658 +                                                    const allocator_type& __a)
   1.659 +  : _STLP_PRIV _String_base<_CharT,_Alloc>(__a) {
   1.660 +  _STLP_FIX_LITERAL_BUG(__s)
   1.661 +  _M_range_initialize(__s, __s + traits_type::length(__s));
   1.662 +}
   1.663 +
   1.664 +template <class _CharT, class _Traits, class _Alloc>
   1.665 +basic_string<_CharT, _Traits, _Alloc>::basic_string(const basic_string<_CharT, _Traits, _Alloc> & __s)
   1.666 +  : _STLP_PRIV _String_base<_CharT,_Alloc>(__s.get_allocator())
   1.667 +{ _M_range_initialize(__s._M_Start(), __s._M_Finish()); }
   1.668 +
   1.669 +#if defined (basic_string)
   1.670 +_STLP_MOVE_TO_STD_NAMESPACE
   1.671 +#  undef basic_string
   1.672 +#else
   1.673 +/* If basic_string is defined it means that it won't be the basic_string class
   1.674 + * exposed to STLport users so npos do not need external linkage.
   1.675 + */
   1.676 +#  if !defined (_STLP_STATIC_CONST_INIT_BUG)
   1.677 +#    if !defined (__GNUC__) || (__GNUC__ != 2) || (__GNUC_MINOR__ != 96)
   1.678 +template <class _CharT, class _Traits, class _Alloc>
   1.679 +const size_t basic_string<_CharT, _Traits, _Alloc>::npos;
   1.680 +#    endif
   1.681 +#  endif
   1.682 +#endif
   1.683 +
   1.684 +_STLP_END_NAMESPACE
   1.685 +
   1.686 +#undef __size_type__
   1.687 +#if defined (_STLP_NESTED_TYPE_PARAM_BUG)
   1.688 +#  undef size_type
   1.689 +#  undef iterator
   1.690 +#endif
   1.691 +
   1.692 +#endif /*  _STLP_STRING_C */
   1.693 +
   1.694 +// Local Variables:
   1.695 +// mode:C++
   1.696 +// End: