Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygen_string.h
Go to the documentation of this file.
00001 /* 00002 * Copyright (c) 1997-1999 00003 * Silicon Graphics Computer Systems, Inc. 00004 * 00005 * Copyright (c) 1999 00006 * Boris Fomitchev 00007 * 00008 * This material is provided "as is", with absolutely no warranty expressed 00009 * or implied. Any use is at your own risk. 00010 * 00011 * Permission to use or copy this software for any purpose is hereby granted 00012 * without fee, provided the above notices are retained on all copies. 00013 * Permission to modify the code and to distribute modified code is granted, 00014 * provided the above notices are retained, and a notice that the code was 00015 * modified is included with the above copyright notice. 00016 * 00017 */ 00018 00019 #ifndef _STLP_INTERNAL_STRING_H 00020 #define _STLP_INTERNAL_STRING_H 00021 00022 #ifndef _STLP_INTERNAL_ALLOC_H 00023 # include <stl/_alloc.h> 00024 #endif 00025 00026 #ifndef _STLP_STRING_FWD_H 00027 # include <stl/_string_fwd.h> 00028 #endif 00029 00030 #ifndef _STLP_INTERNAL_FUNCTION_BASE_H 00031 # include <stl/_function_base.h> 00032 #endif 00033 00034 #ifndef _STLP_INTERNAL_ALGOBASE_H 00035 # include <stl/_algobase.h> 00036 #endif 00037 00038 #ifndef _STLP_INTERNAL_ITERATOR_H 00039 # include <stl/_iterator.h> 00040 #endif 00041 00042 #ifndef _STLP_INTERNAL_UNINITIALIZED_H 00043 # include <stl/_uninitialized.h> 00044 #endif 00045 00046 #if defined (_STLP_USE_TEMPLATE_EXPRESSION) 00047 # include <stl/_string_sum.h> 00048 #endif /* _STLP_USE_TEMPLATE_EXPRESSION */ 00049 00050 #if defined (__MWERKS__) && ! defined (_STLP_USE_OWN_NAMESPACE) 00051 00052 // MSL implementation classes expect to see the definition of streampos 00053 // when this header is included. We expect this to be fixed in later MSL 00054 // implementations 00055 # if !defined( __MSL_CPP__ ) || __MSL_CPP__ < 0x4105 00056 # include <stl/msl_string.h> 00057 # endif 00058 #endif // __MWERKS__ 00059 00060 /* 00061 * Standard C++ string class. This class has performance 00062 * characteristics very much like vector<>, meaning, for example, that 00063 * it does not perform reference-count or copy-on-write, and that 00064 * concatenation of two strings is an O(N) operation. 00065 00066 * There are three reasons why basic_string is not identical to 00067 * vector. 00068 * First, basic_string always stores a null character at the end; 00069 * this makes it possible for c_str to be a fast operation. 00070 * Second, the C++ standard requires basic_string to copy elements 00071 * using char_traits<>::assign, char_traits<>::copy, and 00072 * char_traits<>::move. This means that all of vector<>'s low-level 00073 * operations must be rewritten. Third, basic_string<> has a lot of 00074 * extra functions in its interface that are convenient but, strictly 00075 * speaking, redundant. 00076 */ 00077 00078 #include <stl/_string_base.h> 00079 00080 _STLP_BEGIN_NAMESPACE 00081 00082 // ------------------------------------------------------------ 00083 // Class basic_string. 00084 00085 // Class invariants: 00086 // (1) [start, finish) is a valid range. 00087 // (2) Each iterator in [start, finish) points to a valid object 00088 // of type value_type. 00089 // (3) *finish is a valid object of type value_type; when 00090 // value_type is not a POD it is value_type(). 00091 // (4) [finish + 1, end_of_storage) is a valid range. 00092 // (5) Each iterator in [finish + 1, end_of_storage) points to 00093 // unininitialized memory. 00094 00095 // Note one important consequence: a string of length n must manage 00096 // a block of memory whose size is at least n + 1. 00097 00098 _STLP_MOVE_TO_PRIV_NAMESPACE 00099 struct _String_reserve_t {}; 00100 _STLP_MOVE_TO_STD_NAMESPACE 00101 00102 #if defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND) 00103 # define basic_string _STLP_NO_MEM_T_NAME(str) 00104 #elif defined (_STLP_DEBUG) 00105 # define basic_string _STLP_NON_DBG_NAME(str) 00106 #endif 00107 00108 #if defined (basic_string) 00109 _STLP_MOVE_TO_PRIV_NAMESPACE 00110 #endif 00111 00112 #if defined (__DMC__) 00113 # define _STLP_PRIVATE public 00114 #elif defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND) 00115 # define _STLP_PRIVATE protected 00116 #else 00117 # define _STLP_PRIVATE private 00118 #endif 00119 00120 template <class _CharT, class _Traits, class _Alloc> 00121 class basic_string : _STLP_PRIVATE _STLP_PRIV _String_base<_CharT,_Alloc> 00122 #if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND) && !defined (basic_string) 00123 , public __stlport_class<basic_string<_CharT, _Traits, _Alloc> > 00124 #endif 00125 { 00126 _STLP_PRIVATE: // Private members inherited from base. 00127 typedef _STLP_PRIV _String_base<_CharT,_Alloc> _Base; 00128 typedef basic_string<_CharT, _Traits, _Alloc> _Self; 00129 00130 public: 00131 typedef _CharT value_type; 00132 typedef _Traits traits_type; 00133 00134 typedef value_type* pointer; 00135 typedef const value_type* const_pointer; 00136 typedef value_type& reference; 00137 typedef const value_type& const_reference; 00138 typedef typename _Base::size_type size_type; 00139 typedef ptrdiff_t difference_type; 00140 typedef random_access_iterator_tag _Iterator_category; 00141 00142 typedef const value_type* const_iterator; 00143 typedef value_type* iterator; 00144 00145 _STLP_DECLARE_RANDOM_ACCESS_REVERSE_ITERATORS; 00146 00147 #include <stl/_string_npos.h> 00148 00149 typedef _STLP_PRIV _String_reserve_t _Reserve_t; 00150 00151 public: // Constructor, destructor, assignment. 00152 typedef typename _Base::allocator_type allocator_type; 00153 00154 allocator_type get_allocator() const 00155 { return _STLP_CONVERT_ALLOCATOR((const allocator_type&)this->_M_start_of_storage, _CharT); } 00156 00157 #if !defined (_STLP_DONT_SUP_DFLT_PARAM) 00158 explicit basic_string(const allocator_type& __a = allocator_type()) 00159 #else 00160 basic_string() 00161 : _STLP_PRIV _String_base<_CharT,_Alloc>(allocator_type(), _Base::_DEFAULT_SIZE) 00162 { _M_terminate_string(); } 00163 explicit basic_string(const allocator_type& __a) 00164 #endif 00165 : _STLP_PRIV _String_base<_CharT,_Alloc>(__a, _Base::_DEFAULT_SIZE) 00166 { _M_terminate_string(); } 00167 00168 #if !defined (_STLP_DONT_SUP_DFLT_PARAM) 00169 basic_string(_Reserve_t, size_t __n, 00170 const allocator_type& __a = allocator_type()) 00171 #else 00172 basic_string(_Reserve_t, size_t __n) 00173 : _STLP_PRIV _String_base<_CharT,_Alloc>(allocator_type(), __n + 1) 00174 { _M_terminate_string(); } 00175 basic_string(_Reserve_t, size_t __n, const allocator_type& __a) 00176 #endif 00177 : _STLP_PRIV _String_base<_CharT,_Alloc>(__a, __n + 1) 00178 { _M_terminate_string(); } 00179 00180 basic_string(const _Self&); 00181 00182 #if !defined (_STLP_DONT_SUP_DFLT_PARAM) 00183 basic_string(const _Self& __s, size_type __pos, size_type __n = npos, 00184 const allocator_type& __a = allocator_type()) 00185 #else 00186 basic_string(const _Self& __s, size_type __pos) 00187 : _STLP_PRIV _String_base<_CharT,_Alloc>(allocator_type()) { 00188 if (__pos > __s.size()) 00189 this->_M_throw_out_of_range(); 00190 else 00191 _M_range_initialize(__s._M_Start() + __pos, __s._M_Finish()); 00192 } 00193 basic_string(const _Self& __s, size_type __pos, size_type __n) 00194 : _STLP_PRIV _String_base<_CharT,_Alloc>(allocator_type()) { 00195 if (__pos > __s.size()) 00196 this->_M_throw_out_of_range(); 00197 else 00198 _M_range_initialize(__s._M_Start() + __pos, 00199 __s._M_Start() + __pos + (min) (__n, __s.size() - __pos)); 00200 } 00201 basic_string(const _Self& __s, size_type __pos, size_type __n, 00202 const allocator_type& __a) 00203 #endif 00204 : _STLP_PRIV _String_base<_CharT,_Alloc>(__a) { 00205 if (__pos > __s.size()) 00206 this->_M_throw_out_of_range(); 00207 else 00208 _M_range_initialize(__s._M_Start() + __pos, 00209 __s._M_Start() + __pos + (min) (__n, __s.size() - __pos)); 00210 } 00211 00212 #if !defined (_STLP_DONT_SUP_DFLT_PARAM) 00213 basic_string(const _CharT* __s, size_type __n, 00214 const allocator_type& __a = allocator_type()) 00215 #else 00216 basic_string(const _CharT* __s, size_type __n) 00217 : _STLP_PRIV _String_base<_CharT,_Alloc>(allocator_type()) { 00218 _STLP_FIX_LITERAL_BUG(__s) 00219 _M_range_initialize(__s, __s + __n); 00220 } 00221 basic_string(const _CharT* __s, size_type __n, const allocator_type& __a) 00222 #endif 00223 : _STLP_PRIV _String_base<_CharT,_Alloc>(__a) { 00224 _STLP_FIX_LITERAL_BUG(__s) 00225 _M_range_initialize(__s, __s + __n); 00226 } 00227 00228 #if !defined (_STLP_DONT_SUP_DFLT_PARAM) 00229 basic_string(const _CharT* __s, 00230 const allocator_type& __a = allocator_type()); 00231 #else 00232 basic_string(const _CharT* __s); 00233 basic_string(const _CharT* __s, const allocator_type& __a); 00234 #endif 00235 00236 #if !defined (_STLP_DONT_SUP_DFLT_PARAM) 00237 basic_string(size_type __n, _CharT __c, 00238 const allocator_type& __a = allocator_type()) 00239 #else 00240 basic_string(size_type __n, _CharT __c) 00241 : _STLP_PRIV _String_base<_CharT,_Alloc>(allocator_type(), __n + 1) { 00242 this->_M_finish = _STLP_PRIV __uninitialized_fill_n(this->_M_Start(), __n, __c); 00243 _M_terminate_string(); 00244 } 00245 basic_string(size_type __n, _CharT __c, const allocator_type& __a) 00246 #endif 00247 : _STLP_PRIV _String_base<_CharT,_Alloc>(__a, __n + 1) { 00248 this->_M_finish = _STLP_PRIV __uninitialized_fill_n(this->_M_Start(), __n, __c); 00249 _M_terminate_string(); 00250 } 00251 00252 #if !defined (_STLP_NO_MOVE_SEMANTIC) 00253 basic_string(__move_source<_Self> src) 00254 : _STLP_PRIV _String_base<_CharT,_Alloc>(__move_source<_Base>(src.get())) {} 00255 #endif 00256 00257 // Check to see if _InputIterator is an integer type. If so, then 00258 // it can't be an iterator. 00259 #if defined (_STLP_MEMBER_TEMPLATES) && !defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND) 00260 template <class _InputIterator> 00261 basic_string(_InputIterator __f, _InputIterator __l, 00262 const allocator_type & __a _STLP_ALLOCATOR_TYPE_DFL) 00263 : _STLP_PRIV _String_base<_CharT,_Alloc>(__a) { 00264 typedef typename _IsIntegral<_InputIterator>::_Ret _Integral; 00265 _M_initialize_dispatch(__f, __l, _Integral()); 00266 } 00267 # if defined (_STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS) 00268 template <class _InputIterator> 00269 basic_string(_InputIterator __f, _InputIterator __l) 00270 : _STLP_PRIV _String_base<_CharT,_Alloc>(allocator_type()) { 00271 typedef typename _IsIntegral<_InputIterator>::_Ret _Integral; 00272 _M_initialize_dispatch(__f, __l, _Integral()); 00273 } 00274 # endif 00275 #else 00276 # if !defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND) 00277 basic_string(const _CharT* __f, const _CharT* __l, 00278 const allocator_type& __a _STLP_ALLOCATOR_TYPE_DFL) 00279 : _STLP_PRIV _String_base<_CharT,_Alloc>(__a) { 00280 _STLP_FIX_LITERAL_BUG(__f) _STLP_FIX_LITERAL_BUG(__l) 00281 _M_range_initialize(__f, __l); 00282 } 00283 # if defined (_STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS) 00284 basic_string(const _CharT* __f, const _CharT* __l) 00285 : _STLP_PRIV _String_base<_CharT,_Alloc>(allocator_type()) { 00286 _STLP_FIX_LITERAL_BUG(__f) _STLP_FIX_LITERAL_BUG(__l) 00287 _M_range_initialize(__f, __l); 00288 } 00289 # endif 00290 # endif 00291 # if defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND) 00292 /* We need an additionnal constructor to build an empty string without 00293 * any allocation or termination char*/ 00294 protected: 00295 struct _CalledFromWorkaround_t {}; 00296 basic_string(_CalledFromWorkaround_t, const allocator_type &__a) 00297 : _String_base<_CharT,_Alloc>(__a) {} 00298 # endif 00299 #endif 00300 00301 _STLP_PRIVATE: 00302 size_type _M_compute_next_size(size_type __n) { 00303 const size_type __size = size(); 00304 if (__n > max_size() - __size) 00305 this->_M_throw_length_error(); 00306 size_type __len = __size + (max)(__n, __size) + 1; 00307 if (__len > max_size() || __len < __size) 00308 __len = max_size(); // overflow 00309 return __len; 00310 } 00311 00312 template <class _InputIter> 00313 void _M_range_initialize(_InputIter __f, _InputIter __l, 00314 const input_iterator_tag &__tag) { 00315 this->_M_allocate_block(); 00316 _M_construct_null(this->_M_Finish()); 00317 _M_appendT(__f, __l, __tag); 00318 } 00319 00320 template <class _ForwardIter> 00321 void _M_range_initialize(_ForwardIter __f, _ForwardIter __l, 00322 const forward_iterator_tag &) { 00323 difference_type __n = _STLP_STD::distance(__f, __l); 00324 this->_M_allocate_block(__n + 1); 00325 this->_M_finish = uninitialized_copy(__f, __l, this->_M_Start()); 00326 this->_M_terminate_string(); 00327 } 00328 00329 template <class _InputIter> 00330 void _M_range_initializeT(_InputIter __f, _InputIter __l) { 00331 _M_range_initialize(__f, __l, _STLP_ITERATOR_CATEGORY(__f, _InputIter)); 00332 } 00333 00334 template <class _Integer> 00335 void _M_initialize_dispatch(_Integer __n, _Integer __x, const __true_type& /*_Integral*/) { 00336 this->_M_allocate_block(__n + 1); 00337 this->_M_finish = _STLP_PRIV __uninitialized_fill_n(this->_M_Start(), __n, __x); 00338 this->_M_terminate_string(); 00339 } 00340 00341 template <class _InputIter> 00342 void _M_initialize_dispatch(_InputIter __f, _InputIter __l, const __false_type& /*_Integral*/) { 00343 _M_range_initializeT(__f, __l); 00344 } 00345 00346 public: 00347 _Self& operator=(const _Self& __s) { 00348 if (&__s != this) 00349 _M_assign(__s._M_Start(), __s._M_Finish()); 00350 return *this; 00351 } 00352 00353 _Self& operator=(const _CharT* __s) { 00354 _STLP_FIX_LITERAL_BUG(__s) 00355 return _M_assign(__s, __s + traits_type::length(__s)); 00356 } 00357 00358 _Self& operator=(_CharT __c) 00359 { return assign(__STATIC_CAST(size_type,1), __c); } 00360 00361 private: 00362 static _CharT _STLP_CALL _M_null() 00363 { return _STLP_DEFAULT_CONSTRUCTED(_CharT); } 00364 00365 _STLP_PRIVATE: // Helper functions used by constructors 00366 // and elsewhere. 00367 void _M_construct_null(_CharT* __p) const 00368 { _STLP_STD::_Construct(__p); } 00369 void _M_terminate_string() 00370 { _M_construct_null(this->_M_Finish()); } 00371 bool _M_inside(const _CharT* __s) const { 00372 _STLP_FIX_LITERAL_BUG(__s) 00373 return (__s >= this->_M_Start()) && (__s < this->_M_Finish()); 00374 } 00375 00376 void _M_range_initialize(const _CharT* __f, const _CharT* __l) { 00377 _STLP_FIX_LITERAL_BUG(__f) _STLP_FIX_LITERAL_BUG(__l) 00378 ptrdiff_t __n = __l - __f; 00379 this->_M_allocate_block(__n + 1); 00380 this->_M_finish = uninitialized_copy(__f, __l, this->_M_Start()); 00381 _M_terminate_string(); 00382 } 00383 00384 public: // Iterators. 00385 iterator begin() { return this->_M_Start(); } 00386 iterator end() { return this->_M_Finish(); } 00387 const_iterator begin() const { return this->_M_Start(); } 00388 const_iterator end() const { return this->_M_Finish(); } 00389 00390 reverse_iterator rbegin() 00391 { return reverse_iterator(this->_M_Finish()); } 00392 reverse_iterator rend() 00393 { return reverse_iterator(this->_M_Start()); } 00394 const_reverse_iterator rbegin() const 00395 { return const_reverse_iterator(this->_M_Finish()); } 00396 const_reverse_iterator rend() const 00397 { return const_reverse_iterator(this->_M_Start()); } 00398 00399 public: // Size, capacity, etc. 00400 size_type size() const { return this->_M_Finish() - this->_M_Start(); } 00401 size_type length() const { return size(); } 00402 size_type max_size() const { return _Base::max_size(); } 00403 00404 void resize(size_type __n, _CharT __c) { 00405 if (__n <= size()) 00406 erase(begin() + __n, end()); 00407 else 00408 append(__n - size(), __c); 00409 } 00410 00411 void resize(size_type __n) { resize(__n, _M_null()); } 00412 00413 private: 00414 void _M_reserve(size_type); 00415 public: 00416 void reserve(size_type = 0); 00417 00418 size_type capacity() const 00419 { return this->_M_capacity() - 1; } 00420 00421 void clear() { 00422 if (!empty()) { 00423 _Traits::assign(*(this->_M_Start()), _M_null()); 00424 this->_M_finish = this->_M_Start(); 00425 } 00426 } 00427 00428 bool empty() const { return this->_M_Start() == this->_M_Finish(); } 00429 00430 public: // Element access. 00431 00432 const_reference operator[](size_type __n) const 00433 { return *(this->_M_Start() + __n); } 00434 reference operator[](size_type __n) 00435 { return *(this->_M_Start() + __n); } 00436 00437 const_reference at(size_type __n) const { 00438 if (__n >= size()) 00439 this->_M_throw_out_of_range(); 00440 return *(this->_M_Start() + __n); 00441 } 00442 00443 reference at(size_type __n) { 00444 if (__n >= size()) 00445 this->_M_throw_out_of_range(); 00446 return *(this->_M_Start() + __n); 00447 } 00448 00449 public: // Append, operator+=, push_back. 00450 00451 _Self& operator+=(const _Self& __s) { return append(__s); } 00452 _Self& operator+=(const _CharT* __s) { _STLP_FIX_LITERAL_BUG(__s) return append(__s); } 00453 _Self& operator+=(_CharT __c) { push_back(__c); return *this; } 00454 00455 private: 00456 _Self& _M_append(const _CharT* __first, const _CharT* __last); 00457 00458 #if defined (_STLP_MEMBER_TEMPLATES) && !defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND) 00459 template <class _InputIter> 00460 _Self& _M_appendT(_InputIter __first, _InputIter __last, 00461 const input_iterator_tag &) { 00462 for ( ; __first != __last ; ++__first) 00463 push_back(*__first); 00464 return *this; 00465 } 00466 00467 template <class _ForwardIter> 00468 _Self& _M_appendT(_ForwardIter __first, _ForwardIter __last, 00469 const forward_iterator_tag &) { 00470 if (__first != __last) { 00471 size_type __n = __STATIC_CAST(size_type, _STLP_STD::distance(__first, __last)); 00472 if (__n >= this->_M_rest()) { 00473 size_type __len = _M_compute_next_size(__n); 00474 pointer __new_start = this->_M_start_of_storage.allocate(__len, __len); 00475 pointer __new_finish = uninitialized_copy(this->_M_Start(), this->_M_Finish(), __new_start); 00476 __new_finish = uninitialized_copy(__first, __last, __new_finish); 00477 _M_construct_null(__new_finish); 00478 this->_M_deallocate_block(); 00479 this->_M_reset(__new_start, __new_finish, __new_start + __len); 00480 } 00481 else { 00482 _Traits::assign(*this->_M_finish, *__first++); 00483 uninitialized_copy(__first, __last, this->_M_Finish() + 1); 00484 _M_construct_null(this->_M_Finish() + __n); 00485 this->_M_finish += __n; 00486 } 00487 } 00488 return *this; 00489 } 00490 00491 template <class _Integer> 00492 _Self& _M_append_dispatch(_Integer __n, _Integer __x, const __true_type& /*Integral*/) 00493 { return append((size_type) __n, (_CharT) __x); } 00494 00495 template <class _InputIter> 00496 _Self& _M_append_dispatch(_InputIter __f, _InputIter __l, const __false_type& /*Integral*/) 00497 { return _M_appendT(__f, __l, _STLP_ITERATOR_CATEGORY(__f, _InputIter)); } 00498 00499 public: 00500 // Check to see if _InputIterator is an integer type. If so, then 00501 // it can't be an iterator. 00502 template <class _InputIter> 00503 _Self& append(_InputIter __first, _InputIter __last) { 00504 typedef typename _IsIntegral<_InputIter>::_Ret _Integral; 00505 return _M_append_dispatch(__first, __last, _Integral()); 00506 } 00507 #else 00508 public: 00509 _Self& append(const _CharT* __first, const _CharT* __last) { 00510 _STLP_FIX_LITERAL_BUG(__first)_STLP_FIX_LITERAL_BUG(__last) 00511 return _M_append(__first, __last); 00512 } 00513 #endif 00514 00515 public: 00516 _Self& append(const _Self& __s) 00517 { return _M_append(__s._M_Start(), __s._M_Finish()); } 00518 00519 _Self& append(const _Self& __s, 00520 size_type __pos, size_type __n) { 00521 if (__pos > __s.size()) 00522 this->_M_throw_out_of_range(); 00523 return _M_append(__s._M_Start() + __pos, 00524 __s._M_Start() + __pos + (min) (__n, __s.size() - __pos)); 00525 } 00526 00527 _Self& append(const _CharT* __s, size_type __n) 00528 { _STLP_FIX_LITERAL_BUG(__s) return _M_append(__s, __s+__n); } 00529 _Self& append(const _CharT* __s) 00530 { _STLP_FIX_LITERAL_BUG(__s) return _M_append(__s, __s + traits_type::length(__s)); } 00531 _Self& append(size_type __n, _CharT __c); 00532 00533 public: 00534 void push_back(_CharT __c) { 00535 if (this->_M_rest() == 1 ) 00536 _M_reserve(_M_compute_next_size(1)); 00537 _M_construct_null(this->_M_Finish() + 1); 00538 _Traits::assign(*(this->_M_Finish()), __c); 00539 ++this->_M_finish; 00540 } 00541 00542 void pop_back() { 00543 _Traits::assign(*(this->_M_Finish() - 1), _M_null()); 00544 --this->_M_finish; 00545 } 00546 00547 public: // Assign 00548 _Self& assign(const _Self& __s) 00549 { return _M_assign(__s._M_Start(), __s._M_Finish()); } 00550 00551 _Self& assign(const _Self& __s, 00552 size_type __pos, size_type __n) { 00553 if (__pos > __s.size()) 00554 this->_M_throw_out_of_range(); 00555 return _M_assign(__s._M_Start() + __pos, 00556 __s._M_Start() + __pos + (min) (__n, __s.size() - __pos)); 00557 } 00558 00559 _Self& assign(const _CharT* __s, size_type __n) 00560 { _STLP_FIX_LITERAL_BUG(__s) return _M_assign(__s, __s + __n); } 00561 00562 _Self& assign(const _CharT* __s) 00563 { _STLP_FIX_LITERAL_BUG(__s) return _M_assign(__s, __s + _Traits::length(__s)); } 00564 00565 _Self& assign(size_type __n, _CharT __c); 00566 00567 private: 00568 _Self& _M_assign(const _CharT* __f, const _CharT* __l); 00569 00570 #if defined (_STLP_MEMBER_TEMPLATES) && !defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND) 00571 // Helper functions for assign. 00572 template <class _Integer> 00573 _Self& _M_assign_dispatch(_Integer __n, _Integer __x, const __true_type& /*_Integral*/) 00574 { return assign((size_type) __n, (_CharT) __x); } 00575 00576 template <class _InputIter> 00577 _Self& _M_assign_dispatch(_InputIter __f, _InputIter __l, const __false_type& /*_Integral*/) { 00578 pointer __cur = this->_M_Start(); 00579 while (__f != __l && __cur != this->_M_Finish()) { 00580 _Traits::assign(*__cur, *__f); 00581 ++__f; 00582 ++__cur; 00583 } 00584 if (__f == __l) 00585 erase(__cur, this->end()); 00586 else 00587 _M_appendT(__f, __l, _STLP_ITERATOR_CATEGORY(__f, _InputIter)); 00588 return *this; 00589 } 00590 00591 public: 00592 // Check to see if _InputIterator is an integer type. If so, then 00593 // it can't be an iterator. 00594 template <class _InputIter> 00595 _Self& assign(_InputIter __first, _InputIter __last) { 00596 typedef typename _IsIntegral<_InputIter>::_Ret _Integral; 00597 return _M_assign_dispatch(__first, __last, _Integral()); 00598 } 00599 #else 00600 public: 00601 _Self& assign(const _CharT* __f, const _CharT* __l) { 00602 _STLP_FIX_LITERAL_BUG(__f) _STLP_FIX_LITERAL_BUG(__l) 00603 return _M_assign(__f, __l); 00604 } 00605 #endif 00606 00607 public: // Insert 00608 _Self& insert(size_type __pos, const _Self& __s) { 00609 if (__pos > size()) 00610 this->_M_throw_out_of_range(); 00611 if (__s.size() > max_size() - size()) 00612 this->_M_throw_length_error(); 00613 _M_insert(begin() + __pos, __s._M_Start(), __s._M_Finish(), &__s == this); 00614 return *this; 00615 } 00616 00617 _Self& insert(size_type __pos, const _Self& __s, 00618 size_type __beg, size_type __n) { 00619 if (__pos > size() || __beg > __s.size()) 00620 this->_M_throw_out_of_range(); 00621 size_type __len = (min) (__n, __s.size() - __beg); 00622 if (__len > max_size() - size()) 00623 this->_M_throw_length_error(); 00624 _M_insert(begin() + __pos, 00625 __s._M_Start() + __beg, __s._M_Start() + __beg + __len, &__s == this); 00626 return *this; 00627 } 00628 _Self& insert(size_type __pos, const _CharT* __s, size_type __n) { 00629 _STLP_FIX_LITERAL_BUG(__s) 00630 if (__pos > size()) 00631 this->_M_throw_out_of_range(); 00632 if (__n > max_size() - size()) 00633 this->_M_throw_length_error(); 00634 _M_insert(begin() + __pos, __s, __s + __n, _M_inside(__s)); 00635 return *this; 00636 } 00637 00638 _Self& insert(size_type __pos, const _CharT* __s) { 00639 _STLP_FIX_LITERAL_BUG(__s) 00640 if (__pos > size()) 00641 this->_M_throw_out_of_range(); 00642 size_type __len = _Traits::length(__s); 00643 if (__len > max_size() - size()) 00644 this->_M_throw_length_error(); 00645 _M_insert(this->_M_Start() + __pos, __s, __s + __len, _M_inside(__s)); 00646 return *this; 00647 } 00648 00649 _Self& insert(size_type __pos, size_type __n, _CharT __c) { 00650 if (__pos > size()) 00651 this->_M_throw_out_of_range(); 00652 if (__n > max_size() - size()) 00653 this->_M_throw_length_error(); 00654 insert(begin() + __pos, __n, __c); 00655 return *this; 00656 } 00657 00658 iterator insert(iterator __p, _CharT __c) { 00659 _STLP_FIX_LITERAL_BUG(__p) 00660 if (__p == end()) { 00661 push_back(__c); 00662 return this->_M_Finish() - 1; 00663 } 00664 else 00665 return _M_insert_aux(__p, __c); 00666 } 00667 00668 void insert(iterator __p, size_t __n, _CharT __c); 00669 00670 _STLP_PRIVATE: // Helper functions for insert. 00671 void _M_insert(iterator __p, const _CharT* __first, const _CharT* __last, bool __self_ref); 00672 00673 pointer _M_insert_aux(pointer, _CharT); 00674 00675 void _M_copy(const _CharT* __f, const _CharT* __l, _CharT* __res) { 00676 _STLP_FIX_LITERAL_BUG(__f) _STLP_FIX_LITERAL_BUG(__l) 00677 _STLP_FIX_LITERAL_BUG(__res) 00678 _Traits::copy(__res, __f, __l - __f); 00679 } 00680 00681 void _M_move(const _CharT* __f, const _CharT* __l, _CharT* __res) { 00682 _STLP_FIX_LITERAL_BUG(__f) _STLP_FIX_LITERAL_BUG(__l) 00683 _Traits::move(__res, __f, __l - __f); 00684 } 00685 00686 #if defined (_STLP_MEMBER_TEMPLATES) 00687 # if !defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND) 00688 template <class _ForwardIter> 00689 void _M_insert_overflow(iterator __pos, _ForwardIter __first, _ForwardIter __last, 00690 size_type __n) { 00691 size_type __len = _M_compute_next_size(__n); 00692 pointer __new_start = this->_M_start_of_storage.allocate(__len, __len); 00693 pointer __new_finish = uninitialized_copy(this->_M_Start(), __pos, __new_start); 00694 __new_finish = uninitialized_copy(__first, __last, __new_finish); 00695 __new_finish = uninitialized_copy(__pos, this->_M_Finish(), __new_finish); 00696 _M_construct_null(__new_finish); 00697 this->_M_deallocate_block(); 00698 this->_M_reset(__new_start, __new_finish, __new_start + __len); 00699 } 00700 00701 template <class _InputIter> 00702 void _M_insertT(iterator __p, _InputIter __first, _InputIter __last, 00703 const input_iterator_tag &) { 00704 for ( ; __first != __last; ++__first) { 00705 __p = insert(__p, *__first); 00706 ++__p; 00707 } 00708 } 00709 00710 template <class _ForwardIter> 00711 void _M_insertT(iterator __pos, _ForwardIter __first, _ForwardIter __last, 00712 const forward_iterator_tag &) { 00713 if (__first != __last) { 00714 size_type __n = _STLP_STD::distance(__first, __last); 00715 if (__n < this->_M_rest()) { 00716 const size_type __elems_after = this->_M_finish - __pos; 00717 if (__elems_after >= __n) { 00718 uninitialized_copy((this->_M_Finish() - __n) + 1, this->_M_Finish() + 1, this->_M_Finish() + 1); 00719 this->_M_finish += __n; 00720 _Traits::move(__pos + __n, __pos, (__elems_after - __n) + 1); 00721 _M_copyT(__first, __last, __pos); 00722 } 00723 else { 00724 pointer __old_finish = this->_M_Finish(); 00725 _ForwardIter __mid = __first; 00726 _STLP_STD::advance(__mid, __elems_after + 1); 00727 _STLP_STD::uninitialized_copy(__mid, __last, this->_M_Finish() + 1); 00728 this->_M_finish += __n - __elems_after; 00729 uninitialized_copy(__pos, __old_finish + 1, this->_M_Finish()); 00730 this->_M_finish += __elems_after; 00731 _M_copyT(__first, __mid, __pos); 00732 } 00733 } 00734 else { 00735 _M_insert_overflow(__pos, __first, __last, __n); 00736 } 00737 } 00738 } 00739 00740 template <class _Integer> 00741 void _M_insert_dispatch(iterator __p, _Integer __n, _Integer __x, 00742 const __true_type& /*Integral*/) 00743 { insert(__p, (size_type) __n, (_CharT) __x); } 00744 00745 template <class _InputIter> 00746 void _M_insert_dispatch(iterator __p, _InputIter __first, _InputIter __last, 00747 const __false_type& /*Integral*/) { 00748 _STLP_FIX_LITERAL_BUG(__p) 00749 /* We are forced to do a temporary string to avoid the self referencing issue. */ 00750 const _Self __self(__first, __last, get_allocator()); 00751 _M_insertT(__p, __self.begin(), __self.end(), forward_iterator_tag()); 00752 } 00753 00754 template <class _InputIterator> 00755 void _M_copyT(_InputIterator __first, _InputIterator __last, pointer __result) { 00756 _STLP_FIX_LITERAL_BUG(__result) 00757 for ( ; __first != __last; ++__first, ++__result) 00758 _Traits::assign(*__result, *__first); 00759 } 00760 00761 # if !defined (_STLP_NO_METHOD_SPECIALIZATION) 00762 void _M_copyT(const _CharT* __f, const _CharT* __l, _CharT* __res) { 00763 _STLP_FIX_LITERAL_BUG(__f) _STLP_FIX_LITERAL_BUG(__l) 00764 _STLP_FIX_LITERAL_BUG(__res) 00765 _Traits::copy(__res, __f, __l - __f); 00766 } 00767 # endif 00768 public: 00769 // Check to see if _InputIterator is an integer type. If so, then 00770 // it can't be an iterator. 00771 template <class _InputIter> 00772 void insert(iterator __p, _InputIter __first, _InputIter __last) { 00773 typedef typename _IsIntegral<_InputIter>::_Ret _Integral; 00774 _M_insert_dispatch(__p, __first, __last, _Integral()); 00775 } 00776 # endif 00777 #endif 00778 00779 #if !defined (_STLP_MEMBER_TEMPLATES) || !defined (_STLP_NO_METHOD_SPECIALIZATION) 00780 public: 00781 void insert(iterator __p, const _CharT* __f, const _CharT* __l) { 00782 _STLP_FIX_LITERAL_BUG(__f) _STLP_FIX_LITERAL_BUG(__l) 00783 _M_insert(__p, __f, __l, _M_inside(__f)); 00784 } 00785 #endif 00786 00787 public: // Erase. 00788 _Self& erase(size_type __pos = 0, size_type __n = npos) { 00789 if (__pos > size()) 00790 this->_M_throw_out_of_range(); 00791 erase(begin() + __pos, begin() + __pos + (min) (__n, size() - __pos)); 00792 return *this; 00793 } 00794 00795 iterator erase(iterator __pos) { 00796 // The move includes the terminating _CharT(). 00797 _Traits::move(__pos, __pos + 1, this->_M_Finish() - __pos); 00798 --this->_M_finish; 00799 return __pos; 00800 } 00801 00802 iterator erase(iterator __first, iterator __last) { 00803 if (__first != __last) { 00804 // The move includes the terminating _CharT(). 00805 traits_type::move(__first, __last, (this->_M_Finish() - __last) + 1); 00806 this->_M_finish = this->_M_Finish() - (__last - __first); 00807 } 00808 return __first; 00809 } 00810 00811 public: // Replace. (Conceptually equivalent 00812 // to erase followed by insert.) 00813 _Self& replace(size_type __pos, size_type __n, const _Self& __s) { 00814 const size_type __size = size(); 00815 if (__pos > __size) 00816 this->_M_throw_out_of_range(); 00817 const size_type __len = (min) (__n, __size - __pos); 00818 if (__s.size() > max_size() - (__size - __len)) 00819 this->_M_throw_length_error(); 00820 return _M_replace(begin() + __pos, begin() + __pos + __len, 00821 __s._M_Start(), __s._M_Finish(), &__s == this); 00822 } 00823 00824 _Self& replace(size_type __pos1, size_type __n1, const _Self& __s, 00825 size_type __pos2, size_type __n2) { 00826 const size_type __size1 = size(); 00827 const size_type __size2 = __s.size(); 00828 if (__pos1 > __size1 || __pos2 > __size2) 00829 this->_M_throw_out_of_range(); 00830 const size_type __len1 = (min) (__n1, __size1 - __pos1); 00831 const size_type __len2 = (min) (__n2, __size2 - __pos2); 00832 if (__len2 > max_size() - (__size1 - __len1)) 00833 this->_M_throw_length_error(); 00834 return _M_replace(begin() + __pos1, begin() + __pos1 + __len1, 00835 __s._M_Start() + __pos2, __s._M_Start() + __pos2 + __len2, &__s == this); 00836 } 00837 00838 _Self& replace(size_type __pos, size_type __n1, 00839 const _CharT* __s, size_type __n2) { 00840 _STLP_FIX_LITERAL_BUG(__s) 00841 const size_type __size = size(); 00842 if (__pos > __size) 00843 this->_M_throw_out_of_range(); 00844 const size_type __len = (min) (__n1, __size - __pos); 00845 if (__n2 > max_size() - (__size - __len)) 00846 this->_M_throw_length_error(); 00847 return _M_replace(begin() + __pos, begin() + __pos + __len, 00848 __s, __s + __n2, _M_inside(__s)); 00849 } 00850 00851 _Self& replace(size_type __pos, size_type __n1, const _CharT* __s) { 00852 _STLP_FIX_LITERAL_BUG(__s) 00853 return replace(__pos, __n1, __s, _Traits::length(__s)); 00854 } 00855 00856 _Self& replace(size_type __pos, size_type __n1, 00857 size_type __n2, _CharT __c) { 00858 const size_type __size = size(); 00859 if (__pos > __size) 00860 this->_M_throw_out_of_range(); 00861 const size_type __len = (min) (__n1, __size - __pos); 00862 if (__n2 > max_size() - (__size - __len)) 00863 this->_M_throw_length_error(); 00864 return replace(begin() + __pos, begin() + __pos + __len, __n2, __c); 00865 } 00866 00867 _Self& replace(iterator __first, iterator __last, const _Self& __s) { 00868 _STLP_FIX_LITERAL_BUG(__first)_STLP_FIX_LITERAL_BUG(__last) 00869 return _M_replace(__first, __last, __s._M_Start(), __s._M_Finish(), &__s == this); 00870 } 00871 00872 _Self& replace(iterator __first, iterator __last, 00873 const _CharT* __s, size_type __n) { 00874 _STLP_FIX_LITERAL_BUG(__first)_STLP_FIX_LITERAL_BUG(__last) 00875 _STLP_FIX_LITERAL_BUG(__s) 00876 return _M_replace(__first, __last, __s, __s + __n, _M_inside(__s)); 00877 } 00878 00879 _Self& replace(iterator __first, iterator __last, 00880 const _CharT* __s) { 00881 _STLP_FIX_LITERAL_BUG(__first)_STLP_FIX_LITERAL_BUG(__last) 00882 _STLP_FIX_LITERAL_BUG(__s) 00883 return _M_replace(__first, __last, __s, __s + _Traits::length(__s), _M_inside(__s)); 00884 } 00885 00886 _Self& replace(iterator __first, iterator __last, size_type __n, _CharT __c); 00887 00888 _STLP_PRIVATE: // Helper functions for replace. 00889 _Self& _M_replace(iterator __first, iterator __last, 00890 const _CharT* __f, const _CharT* __l, bool __self_ref); 00891 00892 #if defined (_STLP_MEMBER_TEMPLATES) && !defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND) 00893 template <class _Integer> 00894 _Self& _M_replace_dispatch(iterator __first, iterator __last, 00895 _Integer __n, _Integer __x, const __true_type& /*IsIntegral*/) { 00896 _STLP_FIX_LITERAL_BUG(__first) _STLP_FIX_LITERAL_BUG(__last) 00897 return replace(__first, __last, (size_type) __n, (_CharT) __x); 00898 } 00899 00900 template <class _InputIter> 00901 _Self& _M_replace_dispatch(iterator __first, iterator __last, 00902 _InputIter __f, _InputIter __l, const __false_type& /*IsIntegral*/) { 00903 _STLP_FIX_LITERAL_BUG(__first) _STLP_FIX_LITERAL_BUG(__last) 00904 /* We are forced to do a temporary string to avoid the self referencing issue. */ 00905 const _Self __self(__f, __l, get_allocator()); 00906 return _M_replace(__first, __last, __self._M_Start(), __self._M_Finish(), false); 00907 } 00908 00909 public: 00910 // Check to see if _InputIter is an integer type. If so, then 00911 // it can't be an iterator. 00912 template <class _InputIter> 00913 _Self& replace(iterator __first, iterator __last, 00914 _InputIter __f, _InputIter __l) { 00915 _STLP_FIX_LITERAL_BUG(__first)_STLP_FIX_LITERAL_BUG(__last) 00916 typedef typename _IsIntegral<_InputIter>::_Ret _Integral; 00917 return _M_replace_dispatch(__first, __last, __f, __l, _Integral()); 00918 } 00919 #endif 00920 00921 #if !defined (_STLP_MEMBER_TEMPLATES) || !defined (_STLP_NO_METHOD_SPECIALIZATION) 00922 public: 00923 _Self& replace(iterator __first, iterator __last, 00924 const _CharT* __f, const _CharT* __l) { 00925 _STLP_FIX_LITERAL_BUG(__first)_STLP_FIX_LITERAL_BUG(__last) 00926 _STLP_FIX_LITERAL_BUG(__f) _STLP_FIX_LITERAL_BUG(__l) 00927 return _M_replace(__first, __last, __f, __l, _M_inside(__f)); 00928 } 00929 #endif 00930 00931 public: // Other modifier member functions. 00932 00933 size_type copy(_CharT* __s, size_type __n, size_type __pos = 0) const { 00934 _STLP_FIX_LITERAL_BUG(__s) 00935 if (__pos > size()) 00936 this->_M_throw_out_of_range(); 00937 const size_type __len = (min) (__n, size() - __pos); 00938 _Traits::copy(__s, this->_M_Start() + __pos, __len); 00939 return __len; 00940 } 00941 00942 void swap(_Self& __s) { this->_M_swap(__s); } 00943 #if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND) && !defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER) 00944 void _M_swap_workaround(_Self& __x) { swap(__x); } 00945 #endif 00946 00947 public: // Conversion to C string. 00948 00949 const _CharT* c_str() const { return this->_M_Start(); } 00950 const _CharT* data() const { return this->_M_Start(); } 00951 00952 public: // find. 00953 size_type find(const _Self& __s, size_type __pos = 0) const 00954 { return find(__s._M_Start(), __pos, __s.size()); } 00955 00956 size_type find(const _CharT* __s, size_type __pos = 0) const 00957 { _STLP_FIX_LITERAL_BUG(__s) return find(__s, __pos, _Traits::length(__s)); } 00958 00959 size_type find(const _CharT* __s, size_type __pos, size_type __n) const; 00960 00961 // WIE: Versant schema compiler 5.2.2 ICE workaround 00962 size_type find(_CharT __c) const { return find(__c, 0); } 00963 size_type find(_CharT __c, size_type __pos /* = 0 */) const; 00964 00965 public: // rfind. 00966 size_type rfind(const _Self& __s, size_type __pos = npos) const 00967 { return rfind(__s._M_Start(), __pos, __s.size()); } 00968 00969 size_type rfind(const _CharT* __s, size_type __pos = npos) const 00970 { _STLP_FIX_LITERAL_BUG(__s) return rfind(__s, __pos, _Traits::length(__s)); } 00971 00972 size_type rfind(const _CharT* __s, size_type __pos, size_type __n) const; 00973 size_type rfind(_CharT __c, size_type __pos = npos) const; 00974 00975 public: // find_first_of 00976 size_type find_first_of(const _Self& __s, size_type __pos = 0) const 00977 { return find_first_of(__s._M_Start(), __pos, __s.size()); } 00978 00979 size_type find_first_of(const _CharT* __s, size_type __pos = 0) const 00980 { _STLP_FIX_LITERAL_BUG(__s) return find_first_of(__s, __pos, _Traits::length(__s)); } 00981 00982 size_type find_first_of(const _CharT* __s, size_type __pos, size_type __n) const; 00983 00984 size_type find_first_of(_CharT __c, size_type __pos = 0) const 00985 { return find(__c, __pos); } 00986 00987 public: // find_last_of 00988 size_type find_last_of(const _Self& __s, size_type __pos = npos) const 00989 { return find_last_of(__s._M_Start(), __pos, __s.size()); } 00990 00991 size_type find_last_of(const _CharT* __s, size_type __pos = npos) const 00992 { _STLP_FIX_LITERAL_BUG(__s) return find_last_of(__s, __pos, _Traits::length(__s)); } 00993 00994 size_type find_last_of(const _CharT* __s, size_type __pos, size_type __n) const; 00995 00996 size_type find_last_of(_CharT __c, size_type __pos = npos) const 00997 { return rfind(__c, __pos); } 00998 00999 public: // find_first_not_of 01000 size_type find_first_not_of(const _Self& __s, size_type __pos = 0) const 01001 { return find_first_not_of(__s._M_Start(), __pos, __s.size()); } 01002 01003 size_type find_first_not_of(const _CharT* __s, size_type __pos = 0) const 01004 { _STLP_FIX_LITERAL_BUG(__s) return find_first_not_of(__s, __pos, _Traits::length(__s)); } 01005 01006 size_type find_first_not_of(const _CharT* __s, size_type __pos, size_type __n) const; 01007 01008 size_type find_first_not_of(_CharT __c, size_type __pos = 0) const; 01009 01010 public: // find_last_not_of 01011 size_type find_last_not_of(const _Self& __s, size_type __pos = npos) const 01012 { return find_last_not_of(__s._M_Start(), __pos, __s.size()); } 01013 01014 size_type find_last_not_of(const _CharT* __s, size_type __pos = npos) const 01015 { _STLP_FIX_LITERAL_BUG(__s) return find_last_not_of(__s, __pos, _Traits::length(__s)); } 01016 01017 size_type find_last_not_of(const _CharT* __s, size_type __pos, size_type __n) const; 01018 01019 size_type find_last_not_of(_CharT __c, size_type __pos = npos) const; 01020 01021 public: // Substring. 01022 _Self substr(size_type __pos = 0, size_type __n = npos) const 01023 { return _Self(*this, __pos, __n, get_allocator()); } 01024 01025 public: // Compare 01026 int compare(const _Self& __s) const 01027 { return _M_compare(this->_M_Start(), this->_M_Finish(), __s._M_Start(), __s._M_Finish()); } 01028 01029 int compare(size_type __pos1, size_type __n1, const _Self& __s) const { 01030 if (__pos1 > size()) 01031 this->_M_throw_out_of_range(); 01032 return _M_compare(this->_M_Start() + __pos1, 01033 this->_M_Start() + __pos1 + (min) (__n1, size() - __pos1), 01034 __s._M_Start(), __s._M_Finish()); 01035 } 01036 01037 int compare(size_type __pos1, size_type __n1, const _Self& __s, 01038 size_type __pos2, size_type __n2) const { 01039 if (__pos1 > size() || __pos2 > __s.size()) 01040 this->_M_throw_out_of_range(); 01041 return _M_compare(this->_M_Start() + __pos1, 01042 this->_M_Start() + __pos1 + (min) (__n1, size() - __pos1), 01043 __s._M_Start() + __pos2, 01044 __s._M_Start() + __pos2 + (min) (__n2, __s.size() - __pos2)); 01045 } 01046 01047 int compare(const _CharT* __s) const { 01048 _STLP_FIX_LITERAL_BUG(__s) 01049 return _M_compare(this->_M_Start(), this->_M_Finish(), __s, __s + _Traits::length(__s)); 01050 } 01051 01052 int compare(size_type __pos1, size_type __n1, const _CharT* __s) const { 01053 _STLP_FIX_LITERAL_BUG(__s) 01054 if (__pos1 > size()) 01055 this->_M_throw_out_of_range(); 01056 return _M_compare(this->_M_Start() + __pos1, 01057 this->_M_Start() + __pos1 + (min) (__n1, size() - __pos1), 01058 __s, __s + _Traits::length(__s)); 01059 } 01060 01061 int compare(size_type __pos1, size_type __n1, const _CharT* __s, size_type __n2) const { 01062 _STLP_FIX_LITERAL_BUG(__s) 01063 if (__pos1 > size()) 01064 this->_M_throw_out_of_range(); 01065 return _M_compare(this->_M_Start() + __pos1, 01066 this->_M_Start() + __pos1 + (min) (__n1, size() - __pos1), 01067 __s, __s + __n2); 01068 } 01069 01070 public: // Helper functions for compare. 01071 static int _STLP_CALL _M_compare(const _CharT* __f1, const _CharT* __l1, 01072 const _CharT* __f2, const _CharT* __l2) { 01073 const ptrdiff_t __n1 = __l1 - __f1; 01074 const ptrdiff_t __n2 = __l2 - __f2; 01075 const int cmp = _Traits::compare(__f1, __f2, (min) (__n1, __n2)); 01076 return cmp != 0 ? cmp : (__n1 < __n2 ? -1 : (__n1 > __n2 ? 1 : 0)); 01077 } 01078 #if defined (_STLP_USE_TEMPLATE_EXPRESSION) && !defined (_STLP_DEBUG) && !defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND) 01079 # define _STLP_STRING_SUM_BASE(__reserve, __size, __alloc) _STLP_PRIV _String_base<_CharT,_Alloc>(__alloc, __size + 1) 01080 # include <stl/_string_sum_methods.h> 01081 # undef _STLP_STRING_SUM_BASE 01082 #endif 01083 }; 01084 01085 #undef _STLP_PRIVATE 01086 01087 #if defined (__GNUC__) && (__GNUC__ == 2) && (__GNUC_MINOR__ == 96) 01088 template <class _CharT, class _Traits, class _Alloc> 01089 const size_t basic_string<_CharT, _Traits, _Alloc>::npos = ~(size_t) 0; 01090 #endif 01091 01092 #if defined (_STLP_USE_TEMPLATE_EXPORT) 01093 _STLP_EXPORT_TEMPLATE_CLASS basic_string<char, char_traits<char>, allocator<char> >; 01094 # if defined (_STLP_HAS_WCHAR_T) 01095 _STLP_EXPORT_TEMPLATE_CLASS basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >; 01096 # endif 01097 #endif /* _STLP_USE_TEMPLATE_EXPORT */ 01098 01099 #if defined (basic_string) 01100 _STLP_MOVE_TO_STD_NAMESPACE 01101 # undef basic_string 01102 #endif 01103 01104 _STLP_END_NAMESPACE 01105 01106 #if defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND) 01107 # include <stl/_string_workaround.h> 01108 #endif 01109 01110 #if defined (_STLP_DEBUG) 01111 # include <stl/debug/_string.h> 01112 #endif 01113 01114 _STLP_BEGIN_NAMESPACE 01115 01116 // ------------------------------------------------------------ 01117 // Non-member functions. 01118 // Swap. 01119 #if defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER) 01120 template <class _CharT, class _Traits, class _Alloc> 01121 inline void _STLP_CALL 01122 swap(basic_string<_CharT,_Traits,_Alloc>& __x, 01123 basic_string<_CharT,_Traits,_Alloc>& __y) 01124 { __x.swap(__y); } 01125 #else 01126 inline void _STLP_CALL swap(string& __x, string& __y) 01127 { __x.swap(__y); } 01128 # if defined (_STLP_HAS_WCHAR_T) 01129 inline void _STLP_CALL swap(wstring& __x, wstring& __y) 01130 { __x.swap(__y); } 01131 # endif 01132 #endif 01133 01134 #if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) && !defined (_STLP_NO_MOVE_SEMANTIC) 01135 template <class _CharT, class _Traits, class _Alloc> 01136 struct __move_traits<basic_string<_CharT, _Traits, _Alloc> > { 01137 typedef __true_type implemented; 01138 //Completness depends on the allocator: 01139 typedef typename __move_traits<_Alloc>::complete complete; 01140 }; 01141 /*#else 01142 * There is no need to specialize for string and wstring in this case 01143 * as the default __move_traits will already tell that string is movable 01144 * but not complete. We cannot define it as complete as nothing guaranty 01145 * that the STLport user hasn't specialized std::allocator for char or 01146 * wchar_t. 01147 */ 01148 #endif 01149 01150 _STLP_MOVE_TO_PRIV_NAMESPACE 01151 01152 template <class _CharT, class _Traits, class _Alloc> 01153 void _STLP_CALL _S_string_copy(const basic_string<_CharT,_Traits,_Alloc>& __s, 01154 _CharT* __buf, size_t __n); 01155 01156 #if defined(_STLP_USE_WIDE_INTERFACE) 01157 // A couple of functions to transfer between ASCII/Unicode 01158 wstring __ASCIIToWide(const char *ascii); 01159 string __WideToASCII(const wchar_t *wide); 01160 #endif 01161 01162 inline const char* _STLP_CALL 01163 __get_c_string(const string& __str) { return __str.c_str(); } 01164 01165 _STLP_MOVE_TO_STD_NAMESPACE 01166 01167 _STLP_END_NAMESPACE 01168 01169 #include <stl/_string_operators.h> 01170 01171 #if defined(_STLP_USE_NO_IOSTREAMS) || \ 01172 (defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION) && !defined (_STLP_LINK_TIME_INSTANTIATION)) 01173 # include <stl/_string.c> 01174 #endif 01175 01176 #endif /* _STLP_INTERNAL_STRING_H */ 01177 01178 /* 01179 * Local Variables: 01180 * mode:C++ 01181 * End: 01182 */ Generated on Sat May 26 2012 04:28:12 for ReactOS by
1.7.6.1
|