/home/ntakagi/work/STLport-5.1.5/stlport/stl/_string.c

Go to the documentation of this file.
00001 /*
00002  *
00003  *
00004  * Copyright (c) 1994
00005  * Hewlett-Packard Company
00006  *
00007  * Copyright (c) 1996,1997
00008  * Silicon Graphics Computer Systems, Inc.
00009  *
00010  * Copyright (c) 1997
00011  * Moscow Center for SPARC Technology
00012  *
00013  * Copyright (c) 1999
00014  * Boris Fomitchev
00015  *
00016  * This material is provided "as is", with absolutely no warranty expressed
00017  * or implied. Any use is at your own risk.
00018  *
00019  * Permission to use or copy this software for any purpose is hereby granted
00020  * without fee, provided the above notices are retained on all copies.
00021  * Permission to modify the code and to distribute modified code is granted,
00022  * provided the above notices are retained, and a notice that the code was
00023  * modified is included with the above copyright notice.
00024  *
00025  */
00026 #ifndef _STLP_STRING_C
00027 #define _STLP_STRING_C
00028 
00029 #ifndef _STLP_INTERNAL_STRING_H
00030 #  include <stl/_string.h>
00031 #endif
00032 
00033 #ifndef _STLP_INTERNAL_CTRAITS_FUNCTIONS_H
00034 #  include <stl/_ctraits_fns.h>
00035 #endif
00036 
00037 #if defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
00038 #  define basic_string _STLP_NO_MEM_T_NAME(str)
00039 #elif defined (_STLP_DEBUG)
00040 #  define basic_string _STLP_NON_DBG_NAME(str)
00041 #endif
00042 
00043 #if defined (_STLP_NESTED_TYPE_PARAM_BUG)
00044 #  define __size_type__ size_t
00045 #  define size_type size_t
00046 #  define iterator _CharT*
00047 #else
00048 #  define __size_type__ _STLP_TYPENAME_ON_RETURN_TYPE basic_string<_CharT,_Traits,_Alloc>::size_type
00049 #endif
00050 
00051 _STLP_BEGIN_NAMESPACE
00052 
00053 _STLP_MOVE_TO_PRIV_NAMESPACE
00054 
00055 // A helper class to use a char_traits as a function object.
00056 template <class _Traits>
00057 struct _Not_within_traits : public unary_function<typename _Traits::char_type, bool> {
00058   typedef typename _Traits::char_type _CharT;
00059   const _CharT* _M_first;
00060   const _CharT* _M_last;
00061 
00062   _Not_within_traits(const _CharT* __f, const _CharT* __l)
00063     : _M_first(__f), _M_last(__l) {}
00064 
00065   bool operator()(const _CharT& __x) const {
00066     return find_if(_M_first, _M_last,
00067                    _STLP_PRIV _Eq_char_bound<_Traits>(__x)) == _M_last;
00068   }
00069 };
00070 
00071 // ------------------------------------------------------------
00072 // Non-inline declarations.
00073 
00074 #if !defined (basic_string)
00075 _STLP_MOVE_TO_STD_NAMESPACE
00076 #endif
00077 
00078 // Change the string's capacity so that it is large enough to hold
00079 //  at least __res_arg elements, plus the terminating _CharT().  Note that,
00080 //  if __res_arg < capacity(), this member function may actually decrease
00081 //  the string's capacity.
00082 template <class _CharT, class _Traits, class _Alloc>
00083 void basic_string<_CharT,_Traits,_Alloc>::reserve(size_type __res_arg) {
00084   if (__res_arg > max_size())
00085     this->_M_throw_length_error();
00086 
00087   size_type __n = (max)(__res_arg, size()) + 1;
00088   if (__n <= capacity() + 1)
00089     return;
00090 
00091   pointer __new_start = this->_M_end_of_storage.allocate(__n, __n);
00092   pointer __new_finish = __new_start;
00093 
00094   _STLP_TRY {
00095     __new_finish = _STLP_PRIV __ucopy(this->_M_Start(), this->_M_Finish(), __new_start);
00096     _M_construct_null(__new_finish);
00097   }
00098   _STLP_UNWIND((_STLP_STD::_Destroy_Range(__new_start, __new_finish),
00099                 this->_M_end_of_storage.deallocate(__new_start, __n)))
00100 
00101   this->_M_destroy_range();
00102   this->_M_deallocate_block();
00103   this->_M_reset(__new_start, __new_finish, __new_start + __n);
00104 }
00105 
00106 template <class _CharT, class _Traits, class _Alloc>
00107 basic_string<_CharT,_Traits,_Alloc>&
00108 basic_string<_CharT,_Traits,_Alloc>::append(size_type __n, _CharT __c) {
00109   if (__n > max_size() || size() > max_size() - __n)
00110     this->_M_throw_length_error();
00111   if (size() + __n > capacity())
00112     reserve(size() + (max)(size(), __n));
00113   if (__n > 0) {
00114 #if defined (_STLP_USE_SHORT_STRING_OPTIM)
00115     if (this->_M_using_static_buf())
00116       _Traits::assign(this->_M_finish + 1, __n - 1, __c);
00117     else
00118 #endif /* _STLP_USE_SHORT_STRING_OPTIM */
00119     _STLP_PRIV __uninitialized_fill_n(this->_M_finish + 1, __n - 1, __c);
00120     _STLP_TRY {
00121       _M_construct_null(this->_M_finish + __n);
00122     }
00123     _STLP_UNWIND(this->_M_destroy_ptr_range(this->_M_finish + 1, this->_M_finish + __n))
00124     _Traits::assign(*end(), __c);
00125     this->_M_finish += __n;
00126   }
00127   return *this;
00128 }
00129 
00130 template <class _CharT, class _Traits, class _Alloc>
00131 basic_string<_CharT, _Traits, _Alloc>&
00132 basic_string<_CharT, _Traits, _Alloc>::_M_append(const _CharT* __first, const _CharT* __last) {
00133   if (__first != __last) {
00134     const size_type __old_size = size();
00135     ptrdiff_t __n = __last - __first;
00136     if ((size_type)__n > max_size() || __old_size > max_size() - __n)
00137       this->_M_throw_length_error();
00138     if (__old_size + __n > capacity()) {
00139       size_type __len = __old_size + (max)(__old_size, (size_t) __n) + 1;
00140       pointer __new_start = this->_M_end_of_storage.allocate(__len, __len);
00141       pointer __new_finish = __new_start;
00142       _STLP_TRY {
00143         __new_finish = _STLP_PRIV __ucopy(this->_M_Start(), this->_M_Finish(), __new_start);
00144         __new_finish = _STLP_PRIV __ucopy(__first, __last, __new_finish);
00145         _M_construct_null(__new_finish);
00146       }
00147       _STLP_UNWIND((_STLP_STD::_Destroy_Range(__new_start,__new_finish),
00148                     this->_M_end_of_storage.deallocate(__new_start,__len)))
00149       this->_M_destroy_range();
00150       this->_M_deallocate_block();
00151       this->_M_reset(__new_start, __new_finish, __new_start + __len);
00152     }
00153     else {
00154       const _CharT* __f1 = __first;
00155       ++__f1;
00156 #if defined (_STLP_USE_SHORT_STRING_OPTIM)
00157       if (this->_M_using_static_buf())
00158         _M_copy(__f1, __last, this->_M_Finish() + 1);
00159       else
00160 #endif /* _STLP_USE_SHORT_STRING_OPTIM */
00161       _STLP_PRIV __ucopy(__f1, __last, this->_M_finish + 1);
00162       _STLP_TRY {
00163         _M_construct_null(this->_M_finish + __n);
00164       }
00165       _STLP_UNWIND(this->_M_destroy_ptr_range(this->_M_finish + 1, this->_M_finish + __n))
00166       _Traits::assign(*end(), *__first);
00167       this->_M_finish += __n;
00168     }
00169   }
00170   return *this;
00171 }
00172 
00173 template <class _CharT, class _Traits, class _Alloc>
00174 basic_string<_CharT,_Traits,_Alloc>&
00175 basic_string<_CharT,_Traits,_Alloc>::assign(size_type __n, _CharT __c) {
00176   if (__n <= size()) {
00177     _Traits::assign(this->_M_Start(), __n, __c);
00178     erase(begin() + __n, end());
00179   }
00180   else {
00181     if (__n < capacity()) {
00182       _Traits::assign(this->_M_Start(), size(), __c);
00183       append(__n - size(), __c);
00184     }
00185     else {
00186       _Self __str(__n, __c);
00187       this->swap(__str);
00188     }
00189   }
00190   return *this;
00191 }
00192 
00193 template <class _CharT, class _Traits, class _Alloc>
00194 basic_string<_CharT,_Traits,_Alloc>&
00195 basic_string<_CharT,_Traits,_Alloc>::_M_assign(const _CharT* __f, const _CharT* __l) {
00196   ptrdiff_t __n = __l - __f;
00197   if (__STATIC_CAST(size_type, __n) <= size()) {
00198     _Traits::copy(this->_M_Start(), __f, __n);
00199     erase(begin() + __n, end());
00200   }
00201   else {
00202     _Traits::copy(this->_M_Start(), __f, size());
00203     _M_append(__f + size(), __l);
00204   }
00205   return *this;
00206 }
00207 
00208 template <class _CharT, class _Traits, class _Alloc>
00209 _CharT* basic_string<_CharT,_Traits,_Alloc> ::_M_insert_aux(_CharT* __p,
00210                                                             _CharT __c) {
00211   pointer __new_pos = __p;
00212   if (this->_M_finish + 1 < this->_M_end_of_storage._M_data) {
00213     _M_construct_null(this->_M_finish + 1);
00214     _Traits::move(__p + 1, __p, this->_M_finish - __p);
00215     _Traits::assign(*__p, __c);
00216     ++this->_M_finish;
00217   }
00218   else {
00219     const size_type __old_len = size();
00220     size_type __len = __old_len + (max)(__old_len, __STATIC_CAST(size_type,1)) + 1;
00221     pointer __new_start = this->_M_end_of_storage.allocate(__len, __len);
00222     pointer __new_finish = __new_start;
00223     _STLP_TRY {
00224       __new_pos = _STLP_PRIV __ucopy(this->_M_Start(), __p, __new_start);
00225       _Copy_Construct(__new_pos, __c);
00226       __new_finish = __new_pos + 1;
00227       __new_finish = _STLP_PRIV __ucopy(__p, this->_M_finish, __new_finish);
00228       _M_construct_null(__new_finish);
00229     }
00230     _STLP_UNWIND((_STLP_STD::_Destroy_Range(__new_start,__new_finish),
00231                   this->_M_end_of_storage.deallocate(__new_start,__len)))
00232     this->_M_destroy_range();
00233     this->_M_deallocate_block();
00234     this->_M_reset(__new_start, __new_finish, __new_start + __len);
00235   }
00236   return __new_pos;
00237 }
00238 
00239 template <class _CharT, class _Traits, class _Alloc>
00240 void basic_string<_CharT,_Traits,_Alloc>::insert(iterator __pos,
00241                                                  size_t __n, _CharT __c) {
00242   if (__n != 0) {
00243     if (size_type(this->_M_end_of_storage._M_data - this->_M_finish) >= __n + 1) {
00244       const size_type __elems_after = this->_M_finish - __pos;
00245       pointer __old_finish = this->_M_finish;
00246       if (__elems_after >= __n) {
00247 #if defined (_STLP_USE_SHORT_STRING_OPTIM)
00248         if (this->_M_using_static_buf())
00249           _M_copy((this->_M_finish - __n) + 1, this->_M_finish + 1, this->_M_finish + 1);
00250         else
00251 #endif /* _STLP_USE_SHORT_STRING_OPTIM */
00252         _STLP_PRIV __ucopy((this->_M_finish - __n) + 1, this->_M_finish + 1,
00253                            this->_M_finish + 1);
00254         this->_M_finish += __n;
00255         _Traits::move(__pos + __n, __pos, (__elems_after - __n) + 1);
00256         _Traits::assign(__pos, __n, __c);
00257       }
00258       else {
00259 #if defined (_STLP_USE_SHORT_STRING_OPTIM)
00260         if (this->_M_using_static_buf())
00261           _Traits::assign(this->_M_finish + 1, __n - __elems_after - 1, __c);
00262         else
00263 #endif /* _STLP_USE_SHORT_STRING_OPTIM */
00264         _STLP_PRIV __uninitialized_fill_n(this->_M_finish + 1, __n - __elems_after - 1, __c);
00265         this->_M_finish += __n - __elems_after;
00266         _STLP_TRY {
00267 #if defined (_STLP_USE_SHORT_STRING_OPTIM)
00268           if (this->_M_using_static_buf())
00269             _M_copy(__pos, __old_finish + 1, this->_M_finish);
00270           else
00271 #endif /* _STLP_USE_SHORT_STRING_OPTIM */
00272           _STLP_PRIV __ucopy(__pos, __old_finish + 1, this->_M_finish);
00273           this->_M_finish += __elems_after;
00274         }
00275         _STLP_UNWIND((_STLP_STD::_Destroy_Range(__old_finish + 1, this->_M_finish),
00276                       this->_M_finish = __old_finish))
00277         _Traits::assign(__pos, __elems_after + 1, __c);
00278       }
00279     }
00280     else {
00281       const size_type __old_size = size();
00282       size_type __len = __old_size + (max)(__old_size, __n) + 1;
00283       pointer __new_start = this->_M_end_of_storage.allocate(__len, __len);
00284       pointer __new_finish = __new_start;
00285       _STLP_TRY {
00286         __new_finish = _STLP_PRIV __ucopy(this->_M_Start(), __pos, __new_start);
00287         __new_finish = _STLP_PRIV __uninitialized_fill_n(__new_finish, __n, __c);
00288         __new_finish = _STLP_PRIV __ucopy(__pos, this->_M_finish, __new_finish);
00289         _M_construct_null(__new_finish);
00290       }
00291       _STLP_UNWIND((_STLP_STD::_Destroy_Range(__new_start,__new_finish),
00292                     this->_M_end_of_storage.deallocate(__new_start,__len)))
00293       this->_M_destroy_range();
00294       this->_M_deallocate_block();
00295       this->_M_reset(__new_start, __new_finish, __new_start + __len);
00296     }
00297   }
00298 }
00299 
00300 template <class _CharT, class _Traits, class _Alloc>
00301 void basic_string<_CharT,_Traits,_Alloc>::_M_insert(iterator __pos,
00302                                                     const _CharT* __first, const _CharT* __last,
00303                                                     bool __self_ref) {
00304   //this version has to take care about the auto referencing
00305   if (__first != __last) {
00306     const ptrdiff_t __n = __last - __first;
00307     if (this->_M_end_of_storage._M_data - this->_M_finish >= __n + 1) {
00308       const ptrdiff_t __elems_after = this->_M_finish - __pos;
00309       pointer __old_finish = this->_M_finish;
00310       if (__elems_after >= __n) {
00311 #if defined (_STLP_USE_SHORT_STRING_OPTIM)
00312         if (this->_M_using_static_buf())
00313           _M_copy((this->_M_finish - __n) + 1, this->_M_finish + 1, this->_M_finish + 1);
00314         else
00315 #endif /* _STLP_USE_SHORT_STRING_OPTIM */
00316         _STLP_PRIV __ucopy((this->_M_finish - __n) + 1, this->_M_finish + 1, this->_M_finish + 1);
00317         this->_M_finish += __n;
00318         _Traits::move(__pos + __n, __pos, (__elems_after - __n) + 1);
00319         if (!__self_ref || __last < __pos) {
00320           _M_copy(__first, __last, __pos);
00321         }
00322         else {
00323           //We have to check that the source buffer hasn't move
00324           if (__first >= __pos) {
00325             //The source buffer has move
00326             __first += __n;
00327             __last += __n;
00328             _M_copy(__first, __last, __pos);
00329           }
00330           else {
00331             //The source buffer hasn't move, it has been duplicated
00332             _M_move(__first, __last, __pos);
00333           }
00334         }
00335       }
00336       else {
00337         const_iterator __mid = __first;
00338         __mid += __elems_after + 1;
00339 #if defined (_STLP_USE_SHORT_STRING_OPTIM)
00340         if (this->_M_using_static_buf())
00341           _M_copy(__mid, __last, this->_M_finish + 1);
00342         else
00343 #endif /* _STLP_USE_SHORT_STRING_OPTIM */
00344         _STLP_PRIV __ucopy(__mid, __last, this->_M_finish + 1);
00345         this->_M_finish += __n - __elems_after;
00346         _STLP_TRY {
00347 #if defined (_STLP_USE_SHORT_STRING_OPTIM)
00348           if (this->_M_using_static_buf())
00349             _M_copy(__pos, __old_finish + 1, this->_M_finish);
00350           else
00351 #endif /* _STLP_USE_SHORT_STRING_OPTIM */
00352           _STLP_PRIV __ucopy(__pos, __old_finish + 1, this->_M_finish);
00353           this->_M_finish += __elems_after;
00354         }
00355         _STLP_UNWIND((_STLP_STD::_Destroy_Range(__old_finish + 1, this->_M_finish),
00356                       this->_M_finish = __old_finish))
00357         if (!__self_ref)
00358           _M_copy(__first, __mid, __pos);
00359         else
00360           _M_move(__first, __mid, __pos);
00361       }
00362     }
00363     else {
00364       const size_type __old_size = size();
00365       size_type __len = __old_size + (max)(__old_size, __STATIC_CAST(const size_type,__n)) + 1;
00366       pointer __new_start = this->_M_end_of_storage.allocate(__len, __len);
00367       pointer __new_finish = __new_start;
00368       _STLP_TRY {
00369         __new_finish = _STLP_PRIV __ucopy(this->_M_Start(), __pos, __new_start);
00370         __new_finish = _STLP_PRIV __ucopy(__first, __last, __new_finish);
00371         __new_finish = _STLP_PRIV __ucopy(__pos, this->_M_finish, __new_finish);
00372         _M_construct_null(__new_finish);
00373       }
00374       _STLP_UNWIND((_STLP_STD::_Destroy_Range(__new_start,__new_finish),
00375                     this->_M_end_of_storage.deallocate(__new_start,__len)))
00376       this->_M_destroy_range();
00377       this->_M_deallocate_block();
00378       this->_M_reset(__new_start, __new_finish, __new_start + __len);
00379     }
00380   }
00381 }
00382 
00383 template <class _CharT, class _Traits, class _Alloc>
00384 basic_string<_CharT,_Traits,_Alloc>&
00385 basic_string<_CharT,_Traits,_Alloc> ::replace(iterator __first, iterator __last,
00386                                               size_type __n, _CharT __c) {
00387   size_type __len = (size_type)(__last - __first);
00388 
00389   if (__len >= __n) {
00390     _Traits::assign(__first, __n, __c);
00391     erase(__first + __n, __last);
00392   }
00393   else {
00394     _Traits::assign(__first, __len, __c);
00395     insert(__last, __n - __len, __c);
00396   }
00397   return *this;
00398 }
00399 
00400 template <class _CharT, class _Traits, class _Alloc>
00401 basic_string<_CharT,_Traits,_Alloc>&
00402 basic_string<_CharT,_Traits,_Alloc> ::_M_replace(iterator __first, iterator __last,
00403                                                  const _CharT* __f, const _CharT* __l,
00404                                                  bool __self_ref) {
00405   const ptrdiff_t       __n = __l - __f;
00406   const difference_type __len = __last - __first;
00407   if (__len >= __n) {
00408     if (!__self_ref || __l < __first || __f >= __last)
00409       _M_copy(__f, __l, __first);
00410     else
00411       _M_move(__f, __l, __first);
00412     erase(__first + __n, __last);
00413   }
00414   else {
00415     if (!__self_ref || (__f >= __last) || (__l <= __first)) {
00416       //no overlap:
00417       const_iterator __m = __f + __len;
00418       _M_copy(__f, __m, __first);
00419       _M_insert(__last, __m, __l, false );
00420     }
00421     else {
00422       //we have to take care of overlaping
00423       if (__f < __first) {
00424         const_iterator __m = __f + __len;
00425         //We have to deal with possible reallocation because we do insert first.
00426         const difference_type __off_dest = __first - this->begin();
00427         const difference_type __off_src = __f - this->begin();
00428         _M_insert(__last, __m, __l, true);
00429         _Traits::move(begin() + __off_dest, begin() + __off_src, __len);
00430       }
00431       else {
00432         const_iterator __m = __f + __len;
00433         _Traits::move(__first, __f, __len);
00434         _M_insert(__last, __m, __l, true);
00435       }
00436     }
00437   }
00438   return *this;
00439 }
00440 
00441 template <class _CharT, class _Traits, class _Alloc> __size_type__
00442 basic_string<_CharT,_Traits,_Alloc> ::find(const _CharT* __s, size_type __pos,
00443                                            size_type __n) const {
00444   const size_t __len = size();
00445   if (__pos >= __len || __pos + __n > __len)
00446     return npos;
00447   else {
00448     const_pointer __result =
00449       _STLP_STD::search(this->_M_Start() + __pos, this->_M_Finish(),
00450                         __s, __s + __n, _STLP_PRIV _Eq_traits<_Traits>());
00451     return __result != this->_M_Finish() ? __result - this->_M_Start() : npos;
00452   }
00453 }
00454 
00455 template <class _CharT, class _Traits, class _Alloc> __size_type__
00456 basic_string<_CharT,_Traits,_Alloc> ::find(_CharT __c, size_type __pos) const {
00457   if (__pos >= size()) /*__pos + 1 > size()*/
00458     return npos;
00459   else {
00460     const_pointer __result =
00461       _STLP_STD::find_if(this->_M_Start() + __pos, this->_M_Finish(),
00462                          _STLP_PRIV _Eq_char_bound<_Traits>(__c));
00463     return __result != this->_M_Finish() ? __result - this->_M_Start() : npos;
00464   }
00465 }
00466 
00467 template <class _CharT, class _Traits, class _Alloc>
00468 __size_type__
00469 basic_string<_CharT,_Traits,_Alloc>::rfind(const _CharT* __s, size_type __pos, size_type __n) const
00470 {
00471   const size_type __len = size();
00472   if ( __len < __n ) {
00473     return npos;
00474   }
00475   const_pointer __last = this->_M_Start() + (min)( __len - __n, __pos) + __n;
00476   const_pointer __result = find_end(this->_M_Start(), __last,
00477                                     __s, __s + __n, _STLP_PRIV _Eq_traits<_Traits>());
00478   return __result != __last ? __result - this->_M_Start() : npos;
00479 }
00480 
00481 template <class _CharT, class _Traits, class _Alloc>
00482 __size_type__
00483 basic_string<_CharT,_Traits,_Alloc>::rfind(_CharT __c, size_type __pos) const
00484 {
00485   const size_type __len = size();
00486   if ( __len < 1 ) {
00487     return npos;
00488   }
00489   const_iterator __last = begin() + (min)(__len - 1, __pos) + 1;
00490   const_reverse_iterator __rresult =
00491     _STLP_STD::find_if(const_reverse_iterator(__last), rend(),
00492                        _STLP_PRIV _Eq_char_bound<_Traits>(__c));
00493   return __rresult != rend() ? (__rresult.base() - 1) - begin() : npos;
00494 }
00495 
00496 template <class _CharT, class _Traits, class _Alloc> __size_type__
00497 basic_string<_CharT,_Traits,_Alloc> ::find_first_of(const _CharT* __s, size_type __pos,
00498                                                     size_type __n) const {
00499   if (__pos >= size()) /*__pos + 1 > size()*/
00500     return npos;
00501   else {
00502     const_iterator __result = _STLP_PRIV __find_first_of(begin() + __pos, end(),
00503                                                          __s, __s + __n,
00504                                                          _STLP_PRIV _Eq_traits<_Traits>());
00505     return __result != end() ? __result - begin() : npos;
00506   }
00507 }
00508 
00509 template <class _CharT, class _Traits, class _Alloc>
00510  __size_type__
00511 basic_string<_CharT,_Traits,_Alloc> ::find_last_of(const _CharT* __s, size_type __pos,
00512                                                    size_type __n) const
00513 {
00514   const size_type __len = size();
00515   if ( __len < 1 ) {
00516     return npos;
00517   }
00518   const const_iterator __last = begin() + (min)(__len - 1, __pos) + 1;
00519   const const_reverse_iterator __rresult =
00520     _STLP_PRIV __find_first_of(const_reverse_iterator(__last), rend(),
00521                                __s, __s + __n,
00522                               _STLP_PRIV _Eq_traits<_Traits>());
00523   return __rresult != rend() ? (__rresult.base() - 1) - begin() : npos;
00524 }
00525 
00526 
00527 template <class _CharT, class _Traits, class _Alloc> __size_type__
00528 basic_string<_CharT,_Traits,_Alloc> ::find_first_not_of(const _CharT* __s, size_type __pos,
00529                                                         size_type __n) const {
00530   typedef typename _Traits::char_type _CharType;
00531   if (__pos >= size()) /*__pos + 1 >= size()*/
00532     return npos;
00533   else {
00534     const_pointer __result = _STLP_STD::find_if(this->_M_Start() + __pos, this->_M_Finish(),
00535                                                 _STLP_PRIV _Not_within_traits<_Traits>(__CONST_CAST(const _CharType*, __s),
00536                                                                                         __CONST_CAST(const _CharType*, __s) + __n));
00537     return __result != this->_M_finish ? __result - this->_M_Start() : npos;
00538   }
00539 }
00540 
00541 template <class _CharT, class _Traits, class _Alloc> __size_type__
00542 basic_string<_CharT,_Traits,_Alloc> ::find_first_not_of(_CharT __c, size_type __pos) const {
00543   if (1 > size())
00544     return npos;
00545   else {
00546     const_pointer __result = _STLP_STD::find_if(this->_M_Start() + __pos, this->_M_Finish(),
00547                                                 _STLP_PRIV _Neq_char_bound<_Traits>(__c));
00548     return __result != this->_M_finish ? __result - this->_M_Start() : npos;
00549   }
00550 }
00551 
00552 template <class _CharT, class _Traits, class _Alloc>
00553 __size_type__
00554 basic_string<_CharT,_Traits,_Alloc>::find_last_not_of(const _CharT* __s, size_type __pos, size_type __n) const
00555 {
00556   typedef typename _Traits::char_type _CharType;
00557   const size_type __len = size();
00558   if ( __len < 1 ) {
00559     return npos;
00560   }
00561   const_iterator __last = begin() + (min)(__len - 1, __pos) + 1;
00562   const_reverse_iterator __rlast = const_reverse_iterator(__last);
00563   const_reverse_iterator __rresult =
00564     _STLP_STD::find_if(__rlast, rend(),
00565                        _STLP_PRIV _Not_within_traits<_Traits>((const _CharType*)__s,
00566                                                               (const _CharType*)__s + __n));
00567   return __rresult != rend() ? (__rresult.base() - 1) - begin() : npos;
00568 }
00569 
00570 template <class _CharT, class _Traits, class _Alloc>
00571 __size_type__
00572 basic_string<_CharT, _Traits, _Alloc>::find_last_not_of(_CharT __c, size_type __pos) const
00573 {
00574   const size_type __len = size();
00575   if ( __len < 1 ) {
00576     return npos;
00577   }
00578   const_iterator __last = begin() + (min)(__len - 1, __pos) + 1;
00579   const_reverse_iterator __rlast = const_reverse_iterator(__last);
00580   const_reverse_iterator __rresult =
00581     _STLP_STD::find_if(__rlast, rend(),
00582                        _STLP_PRIV _Neq_char_bound<_Traits>(__c));
00583   return __rresult != rend() ? (__rresult.base() - 1) - begin() : npos;
00584 }
00585 
00586 #if !defined (basic_string)
00587 _STLP_MOVE_TO_PRIV_NAMESPACE
00588 #endif
00589 
00590 template <class _CharT, class _Traits, class _Alloc>
00591 void _STLP_CALL _S_string_copy(const basic_string<_CharT,_Traits,_Alloc>& __s,
00592                                _CharT* __buf, size_t __n) {
00593   if (__n > 0) {
00594     __n = (min) (__n - 1, __s.size());
00595     _STLP_STD::copy(__s.begin(), __s.begin() + __n, __buf);
00596     __buf[__n] = _CharT();
00597   }
00598 }
00599 
00600 _STLP_MOVE_TO_STD_NAMESPACE
00601 
00602 _STLP_END_NAMESPACE
00603 
00604 #include <stl/_range_errors.h>
00605 
00606 _STLP_BEGIN_NAMESPACE
00607 
00608 _STLP_MOVE_TO_PRIV_NAMESPACE
00609 
00610 // _String_base methods
00611 template <class _Tp, class _Alloc>
00612 void _String_base<_Tp,_Alloc>::_M_throw_length_error() const
00613 { __stl_throw_length_error("basic_string"); }
00614 
00615 template <class _Tp, class _Alloc>
00616 void _String_base<_Tp, _Alloc>::_M_throw_out_of_range() const
00617 { __stl_throw_out_of_range("basic_string"); }
00618 
00619 template <class _Tp, class _Alloc>
00620 void _String_base<_Tp, _Alloc>::_M_allocate_block(size_t __n) {
00621   if ((__n <= (max_size() + 1)) && (__n > 0)) {
00622 #if defined (_STLP_USE_SHORT_STRING_OPTIM)
00623     if (__n > _DEFAULT_SIZE) {
00624       this->_M_buffers._M_dynamic_buf = _M_end_of_storage.allocate(__n, __n);
00625       this->_M_finish = this->_M_buffers._M_dynamic_buf;
00626       this->_M_end_of_storage._M_data = this->_M_finish + __n;
00627     }
00628 #else
00629     this->_M_start  = _M_end_of_storage.allocate(__n, __n);
00630     this->_M_finish = this->_M_start;
00631     this->_M_end_of_storage._M_data = this->_M_finish + __n;
00632 #endif /*_STLP_USE_SHORT_STRING_OPTIM  */
00633   } else {
00634     this->_M_throw_length_error();
00635   }
00636 }
00637 
00638 #if !defined (basic_string)
00639 _STLP_MOVE_TO_STD_NAMESPACE
00640 #endif
00641 
00642 #if defined (_STLP_DONT_SUP_DFLT_PARAM)
00643 template <class _CharT, class _Traits, class _Alloc>
00644 basic_string<_CharT, _Traits, _Alloc>::basic_string(const _CharT* __s)
00645   : _STLP_PRIV _String_base<_CharT,_Alloc>(allocator_type()) {
00646   _STLP_FIX_LITERAL_BUG(__s)
00647   _M_range_initialize(__s, __s + traits_type::length(__s));
00648 }
00649 #endif
00650 
00651 template <class _CharT, class _Traits, class _Alloc>
00652 basic_string<_CharT, _Traits, _Alloc>::basic_string(const _CharT* __s,
00653                                                     const allocator_type& __a)
00654   : _STLP_PRIV _String_base<_CharT,_Alloc>(__a) {
00655   _STLP_FIX_LITERAL_BUG(__s)
00656   _M_range_initialize(__s, __s + traits_type::length(__s));
00657 }
00658 
00659 template <class _CharT, class _Traits, class _Alloc>
00660 basic_string<_CharT, _Traits, _Alloc>::basic_string(const basic_string<_CharT, _Traits, _Alloc> & __s)
00661   : _STLP_PRIV _String_base<_CharT,_Alloc>(__s.get_allocator())
00662 { _M_range_initialize(__s._M_Start(), __s._M_Finish()); }
00663 
00664 #if defined (basic_string)
00665 _STLP_MOVE_TO_STD_NAMESPACE
00666 #  undef basic_string
00667 #else
00668 /* If basic_string is defined it means that it won't be the basic_string class
00669  * exposed to STLport users so npos do not need external linkage.
00670  */
00671 #  if !defined (_STLP_STATIC_CONST_INIT_BUG)
00672 #    if !defined (__GNUC__) || (__GNUC__ != 2) || (__GNUC_MINOR__ != 96)
00673 template <class _CharT, class _Traits, class _Alloc>
00674 const size_t basic_string<_CharT, _Traits, _Alloc>::npos;
00675 #    endif
00676 #  endif
00677 #endif
00678 
00679 _STLP_END_NAMESPACE
00680 
00681 #undef __size_type__
00682 #if defined (_STLP_NESTED_TYPE_PARAM_BUG)
00683 #  undef size_type
00684 #  undef iterator
00685 #endif
00686 
00687 #endif /*  _STLP_STRING_C */
00688 
00689 // Local Variables:
00690 // mode:C++
00691 // End:



Generated on Mon Mar 10 15:32:37 2008 by  doxygen 1.5.1