epoc32/include/tools/stlport/stl/_string.c
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:33:34 +0100
branchSymbian3
changeset 4 837f303aceeb
permissions -rw-r--r--
Current Symbian^3 public API header files (from PDK 3.0.h)
This is the epoc32/include tree with the "platform" subtrees removed, and
all but a selected few mbg and rsg files removed.
     1 /*
     2  *
     3  *
     4  * Copyright (c) 1994
     5  * Hewlett-Packard Company
     6  *
     7  * Copyright (c) 1996,1997
     8  * Silicon Graphics Computer Systems, Inc.
     9  *
    10  * Copyright (c) 1997
    11  * Moscow Center for SPARC Technology
    12  *
    13  * Copyright (c) 1999
    14  * Boris Fomitchev
    15  *
    16  * This material is provided "as is", with absolutely no warranty expressed
    17  * or implied. Any use is at your own risk.
    18  *
    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.
    24  *
    25  */
    26 #ifndef _STLP_STRING_C
    27 #define _STLP_STRING_C
    28 
    29 #ifndef _STLP_INTERNAL_STRING_H
    30 #  include <stl/_string.h>
    31 #endif
    32 
    33 #ifndef _STLP_INTERNAL_CTRAITS_FUNCTIONS_H
    34 #  include <stl/_ctraits_fns.h>
    35 #endif
    36 
    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)
    41 #endif
    42 
    43 #if defined (_STLP_NESTED_TYPE_PARAM_BUG)
    44 #  define __size_type__ size_t
    45 #  define size_type size_t
    46 #  define iterator _CharT*
    47 #else
    48 #  define __size_type__ _STLP_TYPENAME_ON_RETURN_TYPE basic_string<_CharT,_Traits,_Alloc>::size_type
    49 #endif
    50 
    51 _STLP_BEGIN_NAMESPACE
    52 
    53 _STLP_MOVE_TO_PRIV_NAMESPACE
    54 
    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;
    61 
    62   _Not_within_traits(const _CharT* __f, const _CharT* __l)
    63     : _M_first(__f), _M_last(__l) {}
    64 
    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;
    68   }
    69 };
    70 
    71 // ------------------------------------------------------------
    72 // Non-inline declarations.
    73 
    74 #if !defined (basic_string)
    75 _STLP_MOVE_TO_STD_NAMESPACE
    76 #endif
    77 
    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();
    86 
    87   size_type __n = (max)(__res_arg, size()) + 1;
    88   if (__n <= capacity() + 1)
    89     return;
    90 
    91   pointer __new_start = this->_M_end_of_storage.allocate(__n, __n);
    92   pointer __new_finish = __new_start;
    93 
    94   _STLP_TRY {
    95     __new_finish = _STLP_PRIV __ucopy(this->_M_Start(), this->_M_Finish(), __new_start);
    96     _M_construct_null(__new_finish);
    97   }
    98   _STLP_UNWIND((_STLP_STD::_Destroy_Range(__new_start, __new_finish),
    99                 this->_M_end_of_storage.deallocate(__new_start, __n)))
   100 
   101   this->_M_destroy_range();
   102   this->_M_deallocate_block();
   103   this->_M_reset(__new_start, __new_finish, __new_start + __n);
   104 }
   105 
   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));
   113   if (__n > 0) {
   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);
   117     else
   118 #endif /* _STLP_USE_SHORT_STRING_OPTIM */
   119     _STLP_PRIV __uninitialized_fill_n(this->_M_finish + 1, __n - 1, __c);
   120     _STLP_TRY {
   121       _M_construct_null(this->_M_finish + __n);
   122     }
   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;
   126   }
   127   return *this;
   128 }
   129 
   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;
   142       _STLP_TRY {
   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);
   146       }
   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);
   152     }
   153     else {
   154       const _CharT* __f1 = __first;
   155       ++__f1;
   156 #if defined (_STLP_USE_SHORT_STRING_OPTIM)
   157       if (this->_M_using_static_buf())
   158         _M_copy(__f1, __last, this->_M_Finish() + 1);
   159       else
   160 #endif /* _STLP_USE_SHORT_STRING_OPTIM */
   161       _STLP_PRIV __ucopy(__f1, __last, this->_M_finish + 1);
   162       _STLP_TRY {
   163         _M_construct_null(this->_M_finish + __n);
   164       }
   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;
   168     }
   169   }
   170   return *this;
   171 }
   172 
   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) {
   176   if (__n <= size()) {
   177     _Traits::assign(this->_M_Start(), __n, __c);
   178     erase(begin() + __n, end());
   179   }
   180   else {
   181     if (__n < capacity()) {
   182       _Traits::assign(this->_M_Start(), size(), __c);
   183       append(__n - size(), __c);
   184     }
   185     else {
   186       _Self __str(__n, __c);
   187       this->swap(__str);
   188     }
   189   }
   190   return *this;
   191 }
   192 
   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());
   200   }
   201   else {
   202     _Traits::copy(this->_M_Start(), __f, size());
   203     _M_append(__f + size(), __l);
   204   }
   205   return *this;
   206 }
   207 
   208 template <class _CharT, class _Traits, class _Alloc>
   209 _CharT* basic_string<_CharT,_Traits,_Alloc> ::_M_insert_aux(_CharT* __p,
   210                                                             _CharT __c) {
   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);
   216     ++this->_M_finish;
   217   }
   218   else {
   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;
   223     _STLP_TRY {
   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);
   229     }
   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);
   235   }
   236   return __new_pos;
   237 }
   238 
   239 template <class _CharT, class _Traits, class _Alloc>
   240 void basic_string<_CharT,_Traits,_Alloc>::insert(iterator __pos,
   241                                                  size_t __n, _CharT __c) {
   242   if (__n != 0) {
   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);
   250         else
   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);
   257       }
   258       else {
   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);
   262         else
   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;
   266         _STLP_TRY {
   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);
   270           else
   271 #endif /* _STLP_USE_SHORT_STRING_OPTIM */
   272           _STLP_PRIV __ucopy(__pos, __old_finish + 1, this->_M_finish);
   273           this->_M_finish += __elems_after;
   274         }
   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);
   278       }
   279     }
   280     else {
   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;
   285       _STLP_TRY {
   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);
   290       }
   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);
   296     }
   297   }
   298 }
   299 
   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,
   303                                                     bool __self_ref) {
   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);
   314         else
   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);
   321         }
   322         else {
   323           //We have to check that the source buffer hasn't move
   324           if (__first >= __pos) {
   325             //The source buffer has move
   326             __first += __n;
   327             __last += __n;
   328             _M_copy(__first, __last, __pos);
   329           }
   330           else {
   331             //The source buffer hasn't move, it has been duplicated
   332             _M_move(__first, __last, __pos);
   333           }
   334         }
   335       }
   336       else {
   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);
   342         else
   343 #endif /* _STLP_USE_SHORT_STRING_OPTIM */
   344         _STLP_PRIV __ucopy(__mid, __last, this->_M_finish + 1);
   345         this->_M_finish += __n - __elems_after;
   346         _STLP_TRY {
   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);
   350           else
   351 #endif /* _STLP_USE_SHORT_STRING_OPTIM */
   352           _STLP_PRIV __ucopy(__pos, __old_finish + 1, this->_M_finish);
   353           this->_M_finish += __elems_after;
   354         }
   355         _STLP_UNWIND((_STLP_STD::_Destroy_Range(__old_finish + 1, this->_M_finish),
   356                       this->_M_finish = __old_finish))
   357         if (!__self_ref)
   358           _M_copy(__first, __mid, __pos);
   359         else
   360           _M_move(__first, __mid, __pos);
   361       }
   362     }
   363     else {
   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;
   368       _STLP_TRY {
   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);
   373       }
   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);
   379     }
   380   }
   381 }
   382 
   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);
   388 
   389   if (__len >= __n) {
   390     _Traits::assign(__first, __n, __c);
   391     erase(__first + __n, __last);
   392   }
   393   else {
   394     _Traits::assign(__first, __len, __c);
   395     insert(__last, __n - __len, __c);
   396   }
   397   return *this;
   398 }
   399 
   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,
   404                                                  bool __self_ref) {
   405   const ptrdiff_t       __n = __l - __f;
   406   const difference_type __len = __last - __first;
   407   if (__len >= __n) {
   408     if (!__self_ref || __l < __first || __f >= __last)
   409       _M_copy(__f, __l, __first);
   410     else
   411       _M_move(__f, __l, __first);
   412     erase(__first + __n, __last);
   413   }
   414   else {
   415     if (!__self_ref || (__f >= __last) || (__l <= __first)) {
   416       //no overlap:
   417       const_iterator __m = __f + __len;
   418       _M_copy(__f, __m, __first);
   419       _M_insert(__last, __m, __l, false );
   420     }
   421     else {
   422       //we have to take care of overlaping
   423       if (__f < __first) {
   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);
   430       }
   431       else {
   432         const_iterator __m = __f + __len;
   433         _Traits::move(__first, __f, __len);
   434         _M_insert(__last, __m, __l, true);
   435       }
   436     }
   437   }
   438   return *this;
   439 }
   440 
   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)
   446     return npos;
   447   else {
   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;
   452   }
   453 }
   454 
   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()*/
   458     return npos;
   459   else {
   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;
   464   }
   465 }
   466 
   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)
   472     return npos;
   473   else if (__n == 0)
   474     return (min) (__len, __pos);
   475   else {
   476     const_pointer __last = this->_M_Start() + (min) (__len - __n, __pos) + __n;
   477     const_pointer __result = _STLP_PRIV __find_end(this->_M_Start(), __last,
   478                                                    __s, __s + __n,
   479                                                    bidirectional_iterator_tag(), bidirectional_iterator_tag(),
   480                                                    _STLP_PRIV _Eq_traits<_Traits>());
   481     return __result != __last ? __result - this->_M_Start() : npos;
   482   }
   483 }
   484 
   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)
   489     return npos;
   490   else {
   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;
   496   }
   497 }
   498 
   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()*/
   503     return npos;
   504   else {
   505     const_iterator __result = _STLP_PRIV __find_first_of(begin() + __pos, end(),
   506                                                          __s, __s + __n,
   507                                                          _STLP_PRIV _Eq_traits<_Traits>());
   508     return __result != end() ? __result - begin() : npos;
   509   }
   510 }
   511 
   512 
   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)
   518     return npos;
   519   else {
   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(),
   523                                  __s, __s + __n,
   524                                  _STLP_PRIV _Eq_traits<_Traits>());
   525     return __rresult != rend() ? (__rresult.base() - 1) - begin() : npos;
   526   }
   527 }
   528 
   529 
   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()*/
   535     return npos;
   536   else {
   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;
   541   }
   542 }
   543 
   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 {
   546   if (1 > size())
   547     return npos;
   548   else {
   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;
   552   }
   553 }
   554 
   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)
   561     return npos;
   562   else {
   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;
   570   }
   571 }
   572 
   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)
   577     return npos;
   578   else {
   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;
   585   }
   586 }
   587 
   588 #if !defined (basic_string)
   589 _STLP_MOVE_TO_PRIV_NAMESPACE
   590 #endif
   591 
   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) {
   595   if (__n > 0) {
   596     __n = (min) (__n - 1, __s.size());
   597     _STLP_STD::copy(__s.begin(), __s.begin() + __n, __buf);
   598     __buf[__n] = _CharT();
   599   }
   600 }
   601 
   602 _STLP_MOVE_TO_STD_NAMESPACE
   603 
   604 _STLP_END_NAMESPACE
   605 
   606 #include <stl/_range_errors.h>
   607 
   608 _STLP_BEGIN_NAMESPACE
   609 
   610 _STLP_MOVE_TO_PRIV_NAMESPACE
   611 
   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"); }
   616 
   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"); }
   620 
   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;
   629     }
   630 #else
   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  */
   635   } else {
   636     this->_M_throw_length_error();
   637   }
   638 }
   639 
   640 #if !defined (basic_string)
   641 _STLP_MOVE_TO_STD_NAMESPACE
   642 #endif
   643 
   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));
   650 }
   651 #endif
   652 
   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));
   659 }
   660 
   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()); }
   665 
   666 #if defined (basic_string)
   667 _STLP_MOVE_TO_STD_NAMESPACE
   668 #  undef basic_string
   669 #else
   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.
   672  */
   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;
   677 #    endif
   678 #  endif
   679 #endif
   680 
   681 _STLP_END_NAMESPACE
   682 
   683 #undef __size_type__
   684 #if defined (_STLP_NESTED_TYPE_PARAM_BUG)
   685 #  undef size_type
   686 #  undef iterator
   687 #endif
   688 
   689 #endif /*  _STLP_STRING_C */
   690 
   691 // Local Variables:
   692 // mode:C++
   693 // End: