_string.h 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182
  1. /*
  2. * Copyright (c) 1997-1999
  3. * Silicon Graphics Computer Systems, Inc.
  4. *
  5. * Copyright (c) 1999
  6. * Boris Fomitchev
  7. *
  8. * This material is provided "as is", with absolutely no warranty expressed
  9. * or implied. Any use is at your own risk.
  10. *
  11. * Permission to use or copy this software for any purpose is hereby granted
  12. * without fee, provided the above notices are retained on all copies.
  13. * Permission to modify the code and to distribute modified code is granted,
  14. * provided the above notices are retained, and a notice that the code was
  15. * modified is included with the above copyright notice.
  16. *
  17. */
  18. #ifndef _STLP_INTERNAL_STRING_H
  19. #define _STLP_INTERNAL_STRING_H
  20. #ifndef _STLP_INTERNAL_ALLOC_H
  21. # include <stl/_alloc.h>
  22. #endif
  23. #ifndef _STLP_STRING_FWD_H
  24. # include <stl/_string_fwd.h>
  25. #endif
  26. #ifndef _STLP_INTERNAL_FUNCTION_BASE_H
  27. # include <stl/_function_base.h>
  28. #endif
  29. #ifndef _STLP_INTERNAL_ALGOBASE_H
  30. # include <stl/_algobase.h>
  31. #endif
  32. #ifndef _STLP_INTERNAL_ITERATOR_H
  33. # include <stl/_iterator.h>
  34. #endif
  35. #ifndef _STLP_INTERNAL_UNINITIALIZED_H
  36. # include <stl/_uninitialized.h>
  37. #endif
  38. #if defined (_STLP_USE_TEMPLATE_EXPRESSION)
  39. # include <stl/_string_sum.h>
  40. #endif /* _STLP_USE_TEMPLATE_EXPRESSION */
  41. #if defined (__MWERKS__) && ! defined (_STLP_USE_OWN_NAMESPACE)
  42. // MSL implementation classes expect to see the definition of streampos
  43. // when this header is included. We expect this to be fixed in later MSL
  44. // implementations
  45. # if !defined( __MSL_CPP__ ) || __MSL_CPP__ < 0x4105
  46. # include <stl/msl_string.h>
  47. # endif
  48. #endif // __MWERKS__
  49. /*
  50. * Standard C++ string class. This class has performance
  51. * characteristics very much like vector<>, meaning, for example, that
  52. * it does not perform reference-count or copy-on-write, and that
  53. * concatenation of two strings is an O(N) operation.
  54. * There are three reasons why basic_string is not identical to
  55. * vector.
  56. * First, basic_string always stores a null character at the end;
  57. * this makes it possible for c_str to be a fast operation.
  58. * Second, the C++ standard requires basic_string to copy elements
  59. * using char_traits<>::assign, char_traits<>::copy, and
  60. * char_traits<>::move. This means that all of vector<>'s low-level
  61. * operations must be rewritten. Third, basic_string<> has a lot of
  62. * extra functions in its interface that are convenient but, strictly
  63. * speaking, redundant.
  64. */
  65. #include <stl/_string_base.h>
  66. _STLP_BEGIN_NAMESPACE
  67. // ------------------------------------------------------------
  68. // Class basic_string.
  69. // Class invariants:
  70. // (1) [start, finish) is a valid range.
  71. // (2) Each iterator in [start, finish) points to a valid object
  72. // of type value_type.
  73. // (3) *finish is a valid object of type value_type; when
  74. // value_type is not a POD it is value_type().
  75. // (4) [finish + 1, end_of_storage) is a valid range.
  76. // (5) Each iterator in [finish + 1, end_of_storage) points to
  77. // unininitialized memory.
  78. // Note one important consequence: a string of length n must manage
  79. // a block of memory whose size is at least n + 1.
  80. _STLP_MOVE_TO_PRIV_NAMESPACE
  81. struct _String_reserve_t {};
  82. _STLP_MOVE_TO_STD_NAMESPACE
  83. #if defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
  84. # define basic_string _STLP_NO_MEM_T_NAME(str)
  85. #elif defined (_STLP_DEBUG)
  86. # define basic_string _STLP_NON_DBG_NAME(str)
  87. #endif
  88. #if defined (basic_string)
  89. _STLP_MOVE_TO_PRIV_NAMESPACE
  90. #endif
  91. #if defined (__DMC__)
  92. # define _STLP_PRIVATE public
  93. #elif defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
  94. # define _STLP_PRIVATE protected
  95. #else
  96. # define _STLP_PRIVATE private
  97. #endif
  98. template <class _CharT, class _Traits, class _Alloc>
  99. class basic_string : _STLP_PRIVATE _STLP_PRIV _String_base<_CharT,_Alloc>
  100. #if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND) && !defined (basic_string)
  101. , public __stlport_class<basic_string<_CharT, _Traits, _Alloc> >
  102. #endif
  103. {
  104. _STLP_PRIVATE: // Private members inherited from base.
  105. typedef _STLP_PRIV _String_base<_CharT,_Alloc> _Base;
  106. typedef basic_string<_CharT, _Traits, _Alloc> _Self;
  107. public:
  108. typedef _CharT value_type;
  109. typedef _Traits traits_type;
  110. typedef value_type* pointer;
  111. typedef const value_type* const_pointer;
  112. typedef value_type& reference;
  113. typedef const value_type& const_reference;
  114. typedef typename _Base::size_type size_type;
  115. typedef ptrdiff_t difference_type;
  116. typedef random_access_iterator_tag _Iterator_category;
  117. typedef const value_type* const_iterator;
  118. typedef value_type* iterator;
  119. _STLP_DECLARE_RANDOM_ACCESS_REVERSE_ITERATORS;
  120. #include <stl/_string_npos.h>
  121. typedef _STLP_PRIV _String_reserve_t _Reserve_t;
  122. public: // Constructor, destructor, assignment.
  123. typedef typename _Base::allocator_type allocator_type;
  124. allocator_type get_allocator() const
  125. { return _STLP_CONVERT_ALLOCATOR((const allocator_type&)this->_M_start_of_storage, _CharT); }
  126. #if !defined (_STLP_DONT_SUP_DFLT_PARAM)
  127. explicit basic_string(const allocator_type& __a = allocator_type())
  128. #else
  129. basic_string()
  130. : _STLP_PRIV _String_base<_CharT,_Alloc>(allocator_type(), _Base::_DEFAULT_SIZE)
  131. { _M_terminate_string(); }
  132. explicit basic_string(const allocator_type& __a)
  133. #endif
  134. : _STLP_PRIV _String_base<_CharT,_Alloc>(__a, _Base::_DEFAULT_SIZE)
  135. { _M_terminate_string(); }
  136. #if !defined (_STLP_DONT_SUP_DFLT_PARAM)
  137. basic_string(_Reserve_t, size_t __n,
  138. const allocator_type& __a = allocator_type())
  139. #else
  140. basic_string(_Reserve_t, size_t __n)
  141. : _STLP_PRIV _String_base<_CharT,_Alloc>(allocator_type(), __n + 1)
  142. { _M_terminate_string(); }
  143. basic_string(_Reserve_t, size_t __n, const allocator_type& __a)
  144. #endif
  145. : _STLP_PRIV _String_base<_CharT,_Alloc>(__a, __n + 1)
  146. { _M_terminate_string(); }
  147. basic_string(const _Self&);
  148. #if !defined (_STLP_DONT_SUP_DFLT_PARAM)
  149. basic_string(const _Self& __s, size_type __pos, size_type __n = npos,
  150. const allocator_type& __a = allocator_type())
  151. #else
  152. basic_string(const _Self& __s, size_type __pos)
  153. : _STLP_PRIV _String_base<_CharT,_Alloc>(allocator_type()) {
  154. if (__pos > __s.size())
  155. this->_M_throw_out_of_range();
  156. else
  157. _M_range_initialize(__s._M_Start() + __pos, __s._M_Finish());
  158. }
  159. basic_string(const _Self& __s, size_type __pos, size_type __n)
  160. : _STLP_PRIV _String_base<_CharT,_Alloc>(allocator_type()) {
  161. if (__pos > __s.size())
  162. this->_M_throw_out_of_range();
  163. else
  164. _M_range_initialize(__s._M_Start() + __pos,
  165. __s._M_Start() + __pos + (min) (__n, __s.size() - __pos));
  166. }
  167. basic_string(const _Self& __s, size_type __pos, size_type __n,
  168. const allocator_type& __a)
  169. #endif
  170. : _STLP_PRIV _String_base<_CharT,_Alloc>(__a) {
  171. if (__pos > __s.size())
  172. this->_M_throw_out_of_range();
  173. else
  174. _M_range_initialize(__s._M_Start() + __pos,
  175. __s._M_Start() + __pos + (min) (__n, __s.size() - __pos));
  176. }
  177. #if !defined (_STLP_DONT_SUP_DFLT_PARAM)
  178. basic_string(const _CharT* __s, size_type __n,
  179. const allocator_type& __a = allocator_type())
  180. #else
  181. basic_string(const _CharT* __s, size_type __n)
  182. : _STLP_PRIV _String_base<_CharT,_Alloc>(allocator_type()) {
  183. _STLP_FIX_LITERAL_BUG(__s)
  184. _M_range_initialize(__s, __s + __n);
  185. }
  186. basic_string(const _CharT* __s, size_type __n, const allocator_type& __a)
  187. #endif
  188. : _STLP_PRIV _String_base<_CharT,_Alloc>(__a) {
  189. _STLP_FIX_LITERAL_BUG(__s)
  190. _M_range_initialize(__s, __s + __n);
  191. }
  192. #if !defined (_STLP_DONT_SUP_DFLT_PARAM)
  193. basic_string(const _CharT* __s,
  194. const allocator_type& __a = allocator_type());
  195. #else
  196. basic_string(const _CharT* __s);
  197. basic_string(const _CharT* __s, const allocator_type& __a);
  198. #endif
  199. #if !defined (_STLP_DONT_SUP_DFLT_PARAM)
  200. basic_string(size_type __n, _CharT __c,
  201. const allocator_type& __a = allocator_type())
  202. #else
  203. basic_string(size_type __n, _CharT __c)
  204. : _STLP_PRIV _String_base<_CharT,_Alloc>(allocator_type(), __n + 1) {
  205. this->_M_finish = _STLP_PRIV __uninitialized_fill_n(this->_M_Start(), __n, __c);
  206. _M_terminate_string();
  207. }
  208. basic_string(size_type __n, _CharT __c, const allocator_type& __a)
  209. #endif
  210. : _STLP_PRIV _String_base<_CharT,_Alloc>(__a, __n + 1) {
  211. this->_M_finish = _STLP_PRIV __uninitialized_fill_n(this->_M_Start(), __n, __c);
  212. _M_terminate_string();
  213. }
  214. #if !defined (_STLP_NO_MOVE_SEMANTIC)
  215. basic_string(__move_source<_Self> src)
  216. : _STLP_PRIV _String_base<_CharT,_Alloc>(__move_source<_Base>(src.get())) {}
  217. #endif
  218. // Check to see if _InputIterator is an integer type. If so, then
  219. // it can't be an iterator.
  220. #if defined (_STLP_MEMBER_TEMPLATES) && !defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
  221. template <class _InputIterator>
  222. basic_string(_InputIterator __f, _InputIterator __l,
  223. const allocator_type & __a _STLP_ALLOCATOR_TYPE_DFL)
  224. : _STLP_PRIV _String_base<_CharT,_Alloc>(__a) {
  225. typedef typename _IsIntegral<_InputIterator>::_Ret _Integral;
  226. _M_initialize_dispatch(__f, __l, _Integral());
  227. }
  228. # if defined (_STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS)
  229. template <class _InputIterator>
  230. basic_string(_InputIterator __f, _InputIterator __l)
  231. : _STLP_PRIV _String_base<_CharT,_Alloc>(allocator_type()) {
  232. typedef typename _IsIntegral<_InputIterator>::_Ret _Integral;
  233. _M_initialize_dispatch(__f, __l, _Integral());
  234. }
  235. # endif
  236. #else
  237. # if !defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
  238. basic_string(const _CharT* __f, const _CharT* __l,
  239. const allocator_type& __a _STLP_ALLOCATOR_TYPE_DFL)
  240. : _STLP_PRIV _String_base<_CharT,_Alloc>(__a) {
  241. _STLP_FIX_LITERAL_BUG(__f) _STLP_FIX_LITERAL_BUG(__l)
  242. _M_range_initialize(__f, __l);
  243. }
  244. # if defined (_STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS)
  245. basic_string(const _CharT* __f, const _CharT* __l)
  246. : _STLP_PRIV _String_base<_CharT,_Alloc>(allocator_type()) {
  247. _STLP_FIX_LITERAL_BUG(__f) _STLP_FIX_LITERAL_BUG(__l)
  248. _M_range_initialize(__f, __l);
  249. }
  250. # endif
  251. # endif
  252. # if defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
  253. /* We need an additionnal constructor to build an empty string without
  254. * any allocation or termination char*/
  255. protected:
  256. struct _CalledFromWorkaround_t {};
  257. basic_string(_CalledFromWorkaround_t, const allocator_type &__a)
  258. : _String_base<_CharT,_Alloc>(__a) {}
  259. # endif
  260. #endif
  261. _STLP_PRIVATE:
  262. size_type _M_compute_next_size(size_type __n) {
  263. const size_type __size = size();
  264. if (__n > max_size() - __size)
  265. this->_M_throw_length_error();
  266. size_type __len = __size + (max)(__n, __size) + 1;
  267. if (__len > max_size() || __len < __size)
  268. __len = max_size(); // overflow
  269. return __len;
  270. }
  271. template <class _InputIter>
  272. void _M_range_initialize(_InputIter __f, _InputIter __l,
  273. const input_iterator_tag &__tag) {
  274. this->_M_allocate_block();
  275. _M_construct_null(this->_M_Finish());
  276. _M_appendT(__f, __l, __tag);
  277. }
  278. template <class _ForwardIter>
  279. void _M_range_initialize(_ForwardIter __f, _ForwardIter __l,
  280. const forward_iterator_tag &) {
  281. difference_type __n = _STLP_STD::distance(__f, __l);
  282. this->_M_allocate_block(__n + 1);
  283. this->_M_finish = uninitialized_copy(__f, __l, this->_M_Start());
  284. this->_M_terminate_string();
  285. }
  286. template <class _InputIter>
  287. void _M_range_initializeT(_InputIter __f, _InputIter __l) {
  288. _M_range_initialize(__f, __l, _STLP_ITERATOR_CATEGORY(__f, _InputIter));
  289. }
  290. template <class _Integer>
  291. void _M_initialize_dispatch(_Integer __n, _Integer __x, const __true_type& /*_Integral*/) {
  292. this->_M_allocate_block(__n + 1);
  293. this->_M_finish = _STLP_PRIV __uninitialized_fill_n(this->_M_Start(), __n, __x);
  294. this->_M_terminate_string();
  295. }
  296. template <class _InputIter>
  297. void _M_initialize_dispatch(_InputIter __f, _InputIter __l, const __false_type& /*_Integral*/) {
  298. _M_range_initializeT(__f, __l);
  299. }
  300. public:
  301. _Self& operator=(const _Self& __s) {
  302. if (&__s != this)
  303. _M_assign(__s._M_Start(), __s._M_Finish());
  304. return *this;
  305. }
  306. _Self& operator=(const _CharT* __s) {
  307. _STLP_FIX_LITERAL_BUG(__s)
  308. return _M_assign(__s, __s + traits_type::length(__s));
  309. }
  310. _Self& operator=(_CharT __c)
  311. { return assign(__STATIC_CAST(size_type,1), __c); }
  312. private:
  313. static _CharT _STLP_CALL _M_null()
  314. { return _STLP_DEFAULT_CONSTRUCTED(_CharT); }
  315. _STLP_PRIVATE: // Helper functions used by constructors
  316. // and elsewhere.
  317. void _M_construct_null(_CharT* __p) const
  318. { _STLP_STD::_Construct(__p); }
  319. void _M_terminate_string()
  320. { _M_construct_null(this->_M_Finish()); }
  321. bool _M_inside(const _CharT* __s) const {
  322. _STLP_FIX_LITERAL_BUG(__s)
  323. return (__s >= this->_M_Start()) && (__s < this->_M_Finish());
  324. }
  325. void _M_range_initialize(const _CharT* __f, const _CharT* __l) {
  326. _STLP_FIX_LITERAL_BUG(__f) _STLP_FIX_LITERAL_BUG(__l)
  327. ptrdiff_t __n = __l - __f;
  328. this->_M_allocate_block(__n + 1);
  329. this->_M_finish = uninitialized_copy(__f, __l, this->_M_Start());
  330. _M_terminate_string();
  331. }
  332. public: // Iterators.
  333. iterator begin() { return this->_M_Start(); }
  334. iterator end() { return this->_M_Finish(); }
  335. const_iterator begin() const { return this->_M_Start(); }
  336. const_iterator end() const { return this->_M_Finish(); }
  337. reverse_iterator rbegin()
  338. { return reverse_iterator(this->_M_Finish()); }
  339. reverse_iterator rend()
  340. { return reverse_iterator(this->_M_Start()); }
  341. const_reverse_iterator rbegin() const
  342. { return const_reverse_iterator(this->_M_Finish()); }
  343. const_reverse_iterator rend() const
  344. { return const_reverse_iterator(this->_M_Start()); }
  345. public: // Size, capacity, etc.
  346. size_type size() const { return this->_M_Finish() - this->_M_Start(); }
  347. size_type length() const { return size(); }
  348. size_type max_size() const { return _Base::max_size(); }
  349. void resize(size_type __n, _CharT __c) {
  350. if (__n <= size())
  351. erase(begin() + __n, end());
  352. else
  353. append(__n - size(), __c);
  354. }
  355. void resize(size_type __n) { resize(__n, _M_null()); }
  356. private:
  357. void _M_reserve(size_type);
  358. public:
  359. void reserve(size_type = 0);
  360. size_type capacity() const
  361. { return this->_M_capacity() - 1; }
  362. void clear() {
  363. if (!empty()) {
  364. _Traits::assign(*(this->_M_Start()), _M_null());
  365. this->_M_finish = this->_M_Start();
  366. }
  367. }
  368. bool empty() const { return this->_M_Start() == this->_M_Finish(); }
  369. public: // Element access.
  370. const_reference operator[](size_type __n) const
  371. { return *(this->_M_Start() + __n); }
  372. reference operator[](size_type __n)
  373. { return *(this->_M_Start() + __n); }
  374. const_reference at(size_type __n) const {
  375. if (__n >= size())
  376. this->_M_throw_out_of_range();
  377. return *(this->_M_Start() + __n);
  378. }
  379. reference at(size_type __n) {
  380. if (__n >= size())
  381. this->_M_throw_out_of_range();
  382. return *(this->_M_Start() + __n);
  383. }
  384. public: // Append, operator+=, push_back.
  385. _Self& operator+=(const _Self& __s) { return append(__s); }
  386. _Self& operator+=(const _CharT* __s) { _STLP_FIX_LITERAL_BUG(__s) return append(__s); }
  387. _Self& operator+=(_CharT __c) { push_back(__c); return *this; }
  388. private:
  389. _Self& _M_append(const _CharT* __first, const _CharT* __last);
  390. #if defined (_STLP_MEMBER_TEMPLATES) && !defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
  391. template <class _InputIter>
  392. _Self& _M_appendT(_InputIter __first, _InputIter __last,
  393. const input_iterator_tag &) {
  394. for ( ; __first != __last ; ++__first)
  395. push_back(*__first);
  396. return *this;
  397. }
  398. template <class _ForwardIter>
  399. _Self& _M_appendT(_ForwardIter __first, _ForwardIter __last,
  400. const forward_iterator_tag &) {
  401. if (__first != __last) {
  402. size_type __n = __STATIC_CAST(size_type, _STLP_STD::distance(__first, __last));
  403. if (__n >= this->_M_rest()) {
  404. size_type __len = _M_compute_next_size(__n);
  405. pointer __new_start = this->_M_start_of_storage.allocate(__len, __len);
  406. pointer __new_finish = uninitialized_copy(this->_M_Start(), this->_M_Finish(), __new_start);
  407. __new_finish = uninitialized_copy(__first, __last, __new_finish);
  408. _M_construct_null(__new_finish);
  409. this->_M_deallocate_block();
  410. this->_M_reset(__new_start, __new_finish, __new_start + __len);
  411. }
  412. else {
  413. _Traits::assign(*this->_M_finish, *__first++);
  414. uninitialized_copy(__first, __last, this->_M_Finish() + 1);
  415. _M_construct_null(this->_M_Finish() + __n);
  416. this->_M_finish += __n;
  417. }
  418. }
  419. return *this;
  420. }
  421. template <class _Integer>
  422. _Self& _M_append_dispatch(_Integer __n, _Integer __x, const __true_type& /*Integral*/)
  423. { return append((size_type) __n, (_CharT) __x); }
  424. template <class _InputIter>
  425. _Self& _M_append_dispatch(_InputIter __f, _InputIter __l, const __false_type& /*Integral*/)
  426. { return _M_appendT(__f, __l, _STLP_ITERATOR_CATEGORY(__f, _InputIter)); }
  427. public:
  428. // Check to see if _InputIterator is an integer type. If so, then
  429. // it can't be an iterator.
  430. template <class _InputIter>
  431. _Self& append(_InputIter __first, _InputIter __last) {
  432. typedef typename _IsIntegral<_InputIter>::_Ret _Integral;
  433. return _M_append_dispatch(__first, __last, _Integral());
  434. }
  435. #else
  436. public:
  437. _Self& append(const _CharT* __first, const _CharT* __last) {
  438. _STLP_FIX_LITERAL_BUG(__first)_STLP_FIX_LITERAL_BUG(__last)
  439. return _M_append(__first, __last);
  440. }
  441. #endif
  442. public:
  443. _Self& append(const _Self& __s)
  444. { return _M_append(__s._M_Start(), __s._M_Finish()); }
  445. _Self& append(const _Self& __s,
  446. size_type __pos, size_type __n) {
  447. if (__pos > __s.size())
  448. this->_M_throw_out_of_range();
  449. return _M_append(__s._M_Start() + __pos,
  450. __s._M_Start() + __pos + (min) (__n, __s.size() - __pos));
  451. }
  452. _Self& append(const _CharT* __s, size_type __n)
  453. { _STLP_FIX_LITERAL_BUG(__s) return _M_append(__s, __s+__n); }
  454. _Self& append(const _CharT* __s)
  455. { _STLP_FIX_LITERAL_BUG(__s) return _M_append(__s, __s + traits_type::length(__s)); }
  456. _Self& append(size_type __n, _CharT __c);
  457. public:
  458. void push_back(_CharT __c) {
  459. if (this->_M_rest() == 1 )
  460. _M_reserve(_M_compute_next_size(1));
  461. _M_construct_null(this->_M_Finish() + 1);
  462. _Traits::assign(*(this->_M_Finish()), __c);
  463. ++this->_M_finish;
  464. }
  465. void pop_back() {
  466. _Traits::assign(*(this->_M_Finish() - 1), _M_null());
  467. --this->_M_finish;
  468. }
  469. public: // Assign
  470. _Self& assign(const _Self& __s)
  471. { return _M_assign(__s._M_Start(), __s._M_Finish()); }
  472. _Self& assign(const _Self& __s,
  473. size_type __pos, size_type __n) {
  474. if (__pos > __s.size())
  475. this->_M_throw_out_of_range();
  476. return _M_assign(__s._M_Start() + __pos,
  477. __s._M_Start() + __pos + (min) (__n, __s.size() - __pos));
  478. }
  479. _Self& assign(const _CharT* __s, size_type __n)
  480. { _STLP_FIX_LITERAL_BUG(__s) return _M_assign(__s, __s + __n); }
  481. _Self& assign(const _CharT* __s)
  482. { _STLP_FIX_LITERAL_BUG(__s) return _M_assign(__s, __s + _Traits::length(__s)); }
  483. _Self& assign(size_type __n, _CharT __c);
  484. private:
  485. _Self& _M_assign(const _CharT* __f, const _CharT* __l);
  486. #if defined (_STLP_MEMBER_TEMPLATES) && !defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
  487. // Helper functions for assign.
  488. template <class _Integer>
  489. _Self& _M_assign_dispatch(_Integer __n, _Integer __x, const __true_type& /*_Integral*/)
  490. { return assign((size_type) __n, (_CharT) __x); }
  491. template <class _InputIter>
  492. _Self& _M_assign_dispatch(_InputIter __f, _InputIter __l, const __false_type& /*_Integral*/) {
  493. pointer __cur = this->_M_Start();
  494. while (__f != __l && __cur != this->_M_Finish()) {
  495. _Traits::assign(*__cur, *__f);
  496. ++__f;
  497. ++__cur;
  498. }
  499. if (__f == __l)
  500. erase(__cur, this->end());
  501. else
  502. _M_appendT(__f, __l, _STLP_ITERATOR_CATEGORY(__f, _InputIter));
  503. return *this;
  504. }
  505. public:
  506. // Check to see if _InputIterator is an integer type. If so, then
  507. // it can't be an iterator.
  508. template <class _InputIter>
  509. _Self& assign(_InputIter __first, _InputIter __last) {
  510. typedef typename _IsIntegral<_InputIter>::_Ret _Integral;
  511. return _M_assign_dispatch(__first, __last, _Integral());
  512. }
  513. #else
  514. public:
  515. _Self& assign(const _CharT* __f, const _CharT* __l) {
  516. _STLP_FIX_LITERAL_BUG(__f) _STLP_FIX_LITERAL_BUG(__l)
  517. return _M_assign(__f, __l);
  518. }
  519. #endif
  520. public: // Insert
  521. _Self& insert(size_type __pos, const _Self& __s) {
  522. if (__pos > size())
  523. this->_M_throw_out_of_range();
  524. if (__s.size() > max_size() - size())
  525. this->_M_throw_length_error();
  526. _M_insert(begin() + __pos, __s._M_Start(), __s._M_Finish(), &__s == this);
  527. return *this;
  528. }
  529. _Self& insert(size_type __pos, const _Self& __s,
  530. size_type __beg, size_type __n) {
  531. if (__pos > size() || __beg > __s.size())
  532. this->_M_throw_out_of_range();
  533. size_type __len = (min) (__n, __s.size() - __beg);
  534. if (__len > max_size() - size())
  535. this->_M_throw_length_error();
  536. _M_insert(begin() + __pos,
  537. __s._M_Start() + __beg, __s._M_Start() + __beg + __len, &__s == this);
  538. return *this;
  539. }
  540. _Self& insert(size_type __pos, const _CharT* __s, size_type __n) {
  541. _STLP_FIX_LITERAL_BUG(__s)
  542. if (__pos > size())
  543. this->_M_throw_out_of_range();
  544. if (__n > max_size() - size())
  545. this->_M_throw_length_error();
  546. _M_insert(begin() + __pos, __s, __s + __n, _M_inside(__s));
  547. return *this;
  548. }
  549. _Self& insert(size_type __pos, const _CharT* __s) {
  550. _STLP_FIX_LITERAL_BUG(__s)
  551. if (__pos > size())
  552. this->_M_throw_out_of_range();
  553. size_type __len = _Traits::length(__s);
  554. if (__len > max_size() - size())
  555. this->_M_throw_length_error();
  556. _M_insert(this->_M_Start() + __pos, __s, __s + __len, _M_inside(__s));
  557. return *this;
  558. }
  559. _Self& insert(size_type __pos, size_type __n, _CharT __c) {
  560. if (__pos > size())
  561. this->_M_throw_out_of_range();
  562. if (__n > max_size() - size())
  563. this->_M_throw_length_error();
  564. insert(begin() + __pos, __n, __c);
  565. return *this;
  566. }
  567. iterator insert(iterator __p, _CharT __c) {
  568. _STLP_FIX_LITERAL_BUG(__p)
  569. if (__p == end()) {
  570. push_back(__c);
  571. return this->_M_Finish() - 1;
  572. }
  573. else
  574. return _M_insert_aux(__p, __c);
  575. }
  576. void insert(iterator __p, size_t __n, _CharT __c);
  577. _STLP_PRIVATE: // Helper functions for insert.
  578. void _M_insert(iterator __p, const _CharT* __first, const _CharT* __last, bool __self_ref);
  579. pointer _M_insert_aux(pointer, _CharT);
  580. void _M_copy(const _CharT* __f, const _CharT* __l, _CharT* __res) {
  581. _STLP_FIX_LITERAL_BUG(__f) _STLP_FIX_LITERAL_BUG(__l)
  582. _STLP_FIX_LITERAL_BUG(__res)
  583. _Traits::copy(__res, __f, __l - __f);
  584. }
  585. void _M_move(const _CharT* __f, const _CharT* __l, _CharT* __res) {
  586. _STLP_FIX_LITERAL_BUG(__f) _STLP_FIX_LITERAL_BUG(__l)
  587. _Traits::move(__res, __f, __l - __f);
  588. }
  589. #if defined (_STLP_MEMBER_TEMPLATES)
  590. # if !defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
  591. template <class _ForwardIter>
  592. void _M_insert_overflow(iterator __pos, _ForwardIter __first, _ForwardIter __last,
  593. size_type __n) {
  594. size_type __len = _M_compute_next_size(__n);
  595. pointer __new_start = this->_M_start_of_storage.allocate(__len, __len);
  596. pointer __new_finish = uninitialized_copy(this->_M_Start(), __pos, __new_start);
  597. __new_finish = uninitialized_copy(__first, __last, __new_finish);
  598. __new_finish = uninitialized_copy(__pos, this->_M_Finish(), __new_finish);
  599. _M_construct_null(__new_finish);
  600. this->_M_deallocate_block();
  601. this->_M_reset(__new_start, __new_finish, __new_start + __len);
  602. }
  603. template <class _InputIter>
  604. void _M_insertT(iterator __p, _InputIter __first, _InputIter __last,
  605. const input_iterator_tag &) {
  606. for ( ; __first != __last; ++__first) {
  607. __p = insert(__p, *__first);
  608. ++__p;
  609. }
  610. }
  611. template <class _ForwardIter>
  612. void _M_insertT(iterator __pos, _ForwardIter __first, _ForwardIter __last,
  613. const forward_iterator_tag &) {
  614. if (__first != __last) {
  615. size_type __n = _STLP_STD::distance(__first, __last);
  616. if (__n < this->_M_rest()) {
  617. const size_type __elems_after = this->_M_finish - __pos;
  618. if (__elems_after >= __n) {
  619. uninitialized_copy((this->_M_Finish() - __n) + 1, this->_M_Finish() + 1, this->_M_Finish() + 1);
  620. this->_M_finish += __n;
  621. _Traits::move(__pos + __n, __pos, (__elems_after - __n) + 1);
  622. _M_copyT(__first, __last, __pos);
  623. }
  624. else {
  625. pointer __old_finish = this->_M_Finish();
  626. _ForwardIter __mid = __first;
  627. _STLP_STD::advance(__mid, __elems_after + 1);
  628. _STLP_STD::uninitialized_copy(__mid, __last, this->_M_Finish() + 1);
  629. this->_M_finish += __n - __elems_after;
  630. uninitialized_copy(__pos, __old_finish + 1, this->_M_Finish());
  631. this->_M_finish += __elems_after;
  632. _M_copyT(__first, __mid, __pos);
  633. }
  634. }
  635. else {
  636. _M_insert_overflow(__pos, __first, __last, __n);
  637. }
  638. }
  639. }
  640. template <class _Integer>
  641. void _M_insert_dispatch(iterator __p, _Integer __n, _Integer __x,
  642. const __true_type& /*Integral*/)
  643. { insert(__p, (size_type) __n, (_CharT) __x); }
  644. template <class _InputIter>
  645. void _M_insert_dispatch(iterator __p, _InputIter __first, _InputIter __last,
  646. const __false_type& /*Integral*/) {
  647. _STLP_FIX_LITERAL_BUG(__p)
  648. /* We are forced to do a temporary string to avoid the self referencing issue. */
  649. const _Self __self(__first, __last, get_allocator());
  650. _M_insertT(__p, __self.begin(), __self.end(), forward_iterator_tag());
  651. }
  652. template <class _InputIterator>
  653. void _M_copyT(_InputIterator __first, _InputIterator __last, pointer __result) {
  654. _STLP_FIX_LITERAL_BUG(__result)
  655. for ( ; __first != __last; ++__first, ++__result)
  656. _Traits::assign(*__result, *__first);
  657. }
  658. # if !defined (_STLP_NO_METHOD_SPECIALIZATION)
  659. void _M_copyT(const _CharT* __f, const _CharT* __l, _CharT* __res) {
  660. _STLP_FIX_LITERAL_BUG(__f) _STLP_FIX_LITERAL_BUG(__l)
  661. _STLP_FIX_LITERAL_BUG(__res)
  662. _Traits::copy(__res, __f, __l - __f);
  663. }
  664. # endif
  665. public:
  666. // Check to see if _InputIterator is an integer type. If so, then
  667. // it can't be an iterator.
  668. template <class _InputIter>
  669. void insert(iterator __p, _InputIter __first, _InputIter __last) {
  670. typedef typename _IsIntegral<_InputIter>::_Ret _Integral;
  671. _M_insert_dispatch(__p, __first, __last, _Integral());
  672. }
  673. # endif
  674. #endif
  675. #if !defined (_STLP_MEMBER_TEMPLATES) || !defined (_STLP_NO_METHOD_SPECIALIZATION)
  676. public:
  677. void insert(iterator __p, const _CharT* __f, const _CharT* __l) {
  678. _STLP_FIX_LITERAL_BUG(__f) _STLP_FIX_LITERAL_BUG(__l)
  679. _M_insert(__p, __f, __l, _M_inside(__f));
  680. }
  681. #endif
  682. public: // Erase.
  683. _Self& erase(size_type __pos = 0, size_type __n = npos) {
  684. if (__pos > size())
  685. this->_M_throw_out_of_range();
  686. erase(begin() + __pos, begin() + __pos + (min) (__n, size() - __pos));
  687. return *this;
  688. }
  689. iterator erase(iterator __pos) {
  690. // The move includes the terminating _CharT().
  691. _Traits::move(__pos, __pos + 1, this->_M_Finish() - __pos);
  692. --this->_M_finish;
  693. return __pos;
  694. }
  695. iterator erase(iterator __first, iterator __last) {
  696. if (__first != __last) {
  697. // The move includes the terminating _CharT().
  698. traits_type::move(__first, __last, (this->_M_Finish() - __last) + 1);
  699. this->_M_finish = this->_M_Finish() - (__last - __first);
  700. }
  701. return __first;
  702. }
  703. public: // Replace. (Conceptually equivalent
  704. // to erase followed by insert.)
  705. _Self& replace(size_type __pos, size_type __n, const _Self& __s) {
  706. const size_type __size = size();
  707. if (__pos > __size)
  708. this->_M_throw_out_of_range();
  709. const size_type __len = (min) (__n, __size - __pos);
  710. if (__s.size() > max_size() - (__size - __len))
  711. this->_M_throw_length_error();
  712. return _M_replace(begin() + __pos, begin() + __pos + __len,
  713. __s._M_Start(), __s._M_Finish(), &__s == this);
  714. }
  715. _Self& replace(size_type __pos1, size_type __n1, const _Self& __s,
  716. size_type __pos2, size_type __n2) {
  717. const size_type __size1 = size();
  718. const size_type __size2 = __s.size();
  719. if (__pos1 > __size1 || __pos2 > __size2)
  720. this->_M_throw_out_of_range();
  721. const size_type __len1 = (min) (__n1, __size1 - __pos1);
  722. const size_type __len2 = (min) (__n2, __size2 - __pos2);
  723. if (__len2 > max_size() - (__size1 - __len1))
  724. this->_M_throw_length_error();
  725. return _M_replace(begin() + __pos1, begin() + __pos1 + __len1,
  726. __s._M_Start() + __pos2, __s._M_Start() + __pos2 + __len2, &__s == this);
  727. }
  728. _Self& replace(size_type __pos, size_type __n1,
  729. const _CharT* __s, size_type __n2) {
  730. _STLP_FIX_LITERAL_BUG(__s)
  731. const size_type __size = size();
  732. if (__pos > __size)
  733. this->_M_throw_out_of_range();
  734. const size_type __len = (min) (__n1, __size - __pos);
  735. if (__n2 > max_size() - (__size - __len))
  736. this->_M_throw_length_error();
  737. return _M_replace(begin() + __pos, begin() + __pos + __len,
  738. __s, __s + __n2, _M_inside(__s));
  739. }
  740. _Self& replace(size_type __pos, size_type __n1, const _CharT* __s) {
  741. _STLP_FIX_LITERAL_BUG(__s)
  742. return replace(__pos, __n1, __s, _Traits::length(__s));
  743. }
  744. _Self& replace(size_type __pos, size_type __n1,
  745. size_type __n2, _CharT __c) {
  746. const size_type __size = size();
  747. if (__pos > __size)
  748. this->_M_throw_out_of_range();
  749. const size_type __len = (min) (__n1, __size - __pos);
  750. if (__n2 > max_size() - (__size - __len))
  751. this->_M_throw_length_error();
  752. return replace(begin() + __pos, begin() + __pos + __len, __n2, __c);
  753. }
  754. _Self& replace(iterator __first, iterator __last, const _Self& __s) {
  755. _STLP_FIX_LITERAL_BUG(__first)_STLP_FIX_LITERAL_BUG(__last)
  756. return _M_replace(__first, __last, __s._M_Start(), __s._M_Finish(), &__s == this);
  757. }
  758. _Self& replace(iterator __first, iterator __last,
  759. const _CharT* __s, size_type __n) {
  760. _STLP_FIX_LITERAL_BUG(__first)_STLP_FIX_LITERAL_BUG(__last)
  761. _STLP_FIX_LITERAL_BUG(__s)
  762. return _M_replace(__first, __last, __s, __s + __n, _M_inside(__s));
  763. }
  764. _Self& replace(iterator __first, iterator __last,
  765. const _CharT* __s) {
  766. _STLP_FIX_LITERAL_BUG(__first)_STLP_FIX_LITERAL_BUG(__last)
  767. _STLP_FIX_LITERAL_BUG(__s)
  768. return _M_replace(__first, __last, __s, __s + _Traits::length(__s), _M_inside(__s));
  769. }
  770. _Self& replace(iterator __first, iterator __last, size_type __n, _CharT __c);
  771. _STLP_PRIVATE: // Helper functions for replace.
  772. _Self& _M_replace(iterator __first, iterator __last,
  773. const _CharT* __f, const _CharT* __l, bool __self_ref);
  774. #if defined (_STLP_MEMBER_TEMPLATES) && !defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
  775. template <class _Integer>
  776. _Self& _M_replace_dispatch(iterator __first, iterator __last,
  777. _Integer __n, _Integer __x, const __true_type& /*IsIntegral*/) {
  778. _STLP_FIX_LITERAL_BUG(__first) _STLP_FIX_LITERAL_BUG(__last)
  779. return replace(__first, __last, (size_type) __n, (_CharT) __x);
  780. }
  781. template <class _InputIter>
  782. _Self& _M_replace_dispatch(iterator __first, iterator __last,
  783. _InputIter __f, _InputIter __l, const __false_type& /*IsIntegral*/) {
  784. _STLP_FIX_LITERAL_BUG(__first) _STLP_FIX_LITERAL_BUG(__last)
  785. /* We are forced to do a temporary string to avoid the self referencing issue. */
  786. const _Self __self(__f, __l, get_allocator());
  787. return _M_replace(__first, __last, __self._M_Start(), __self._M_Finish(), false);
  788. }
  789. public:
  790. // Check to see if _InputIter is an integer type. If so, then
  791. // it can't be an iterator.
  792. template <class _InputIter>
  793. _Self& replace(iterator __first, iterator __last,
  794. _InputIter __f, _InputIter __l) {
  795. _STLP_FIX_LITERAL_BUG(__first)_STLP_FIX_LITERAL_BUG(__last)
  796. typedef typename _IsIntegral<_InputIter>::_Ret _Integral;
  797. return _M_replace_dispatch(__first, __last, __f, __l, _Integral());
  798. }
  799. #endif
  800. #if !defined (_STLP_MEMBER_TEMPLATES) || !defined (_STLP_NO_METHOD_SPECIALIZATION)
  801. public:
  802. _Self& replace(iterator __first, iterator __last,
  803. const _CharT* __f, const _CharT* __l) {
  804. _STLP_FIX_LITERAL_BUG(__first)_STLP_FIX_LITERAL_BUG(__last)
  805. _STLP_FIX_LITERAL_BUG(__f) _STLP_FIX_LITERAL_BUG(__l)
  806. return _M_replace(__first, __last, __f, __l, _M_inside(__f));
  807. }
  808. #endif
  809. public: // Other modifier member functions.
  810. size_type copy(_CharT* __s, size_type __n, size_type __pos = 0) const {
  811. _STLP_FIX_LITERAL_BUG(__s)
  812. if (__pos > size())
  813. this->_M_throw_out_of_range();
  814. const size_type __len = (min) (__n, size() - __pos);
  815. _Traits::copy(__s, this->_M_Start() + __pos, __len);
  816. return __len;
  817. }
  818. void swap(_Self& __s) { this->_M_swap(__s); }
  819. #if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND) && !defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER)
  820. void _M_swap_workaround(_Self& __x) { swap(__x); }
  821. #endif
  822. public: // Conversion to C string.
  823. const _CharT* c_str() const { return this->_M_Start(); }
  824. const _CharT* data() const { return this->_M_Start(); }
  825. public: // find.
  826. size_type find(const _Self& __s, size_type __pos = 0) const
  827. { return find(__s._M_Start(), __pos, __s.size()); }
  828. size_type find(const _CharT* __s, size_type __pos = 0) const
  829. { _STLP_FIX_LITERAL_BUG(__s) return find(__s, __pos, _Traits::length(__s)); }
  830. size_type find(const _CharT* __s, size_type __pos, size_type __n) const;
  831. // WIE: Versant schema compiler 5.2.2 ICE workaround
  832. size_type find(_CharT __c) const { return find(__c, 0); }
  833. size_type find(_CharT __c, size_type __pos /* = 0 */) const;
  834. public: // rfind.
  835. size_type rfind(const _Self& __s, size_type __pos = npos) const
  836. { return rfind(__s._M_Start(), __pos, __s.size()); }
  837. size_type rfind(const _CharT* __s, size_type __pos = npos) const
  838. { _STLP_FIX_LITERAL_BUG(__s) return rfind(__s, __pos, _Traits::length(__s)); }
  839. size_type rfind(const _CharT* __s, size_type __pos, size_type __n) const;
  840. size_type rfind(_CharT __c, size_type __pos = npos) const;
  841. public: // find_first_of
  842. size_type find_first_of(const _Self& __s, size_type __pos = 0) const
  843. { return find_first_of(__s._M_Start(), __pos, __s.size()); }
  844. size_type find_first_of(const _CharT* __s, size_type __pos = 0) const
  845. { _STLP_FIX_LITERAL_BUG(__s) return find_first_of(__s, __pos, _Traits::length(__s)); }
  846. size_type find_first_of(const _CharT* __s, size_type __pos, size_type __n) const;
  847. size_type find_first_of(_CharT __c, size_type __pos = 0) const
  848. { return find(__c, __pos); }
  849. public: // find_last_of
  850. size_type find_last_of(const _Self& __s, size_type __pos = npos) const
  851. { return find_last_of(__s._M_Start(), __pos, __s.size()); }
  852. size_type find_last_of(const _CharT* __s, size_type __pos = npos) const
  853. { _STLP_FIX_LITERAL_BUG(__s) return find_last_of(__s, __pos, _Traits::length(__s)); }
  854. size_type find_last_of(const _CharT* __s, size_type __pos, size_type __n) const;
  855. size_type find_last_of(_CharT __c, size_type __pos = npos) const
  856. { return rfind(__c, __pos); }
  857. public: // find_first_not_of
  858. size_type find_first_not_of(const _Self& __s, size_type __pos = 0) const
  859. { return find_first_not_of(__s._M_Start(), __pos, __s.size()); }
  860. size_type find_first_not_of(const _CharT* __s, size_type __pos = 0) const
  861. { _STLP_FIX_LITERAL_BUG(__s) return find_first_not_of(__s, __pos, _Traits::length(__s)); }
  862. size_type find_first_not_of(const _CharT* __s, size_type __pos, size_type __n) const;
  863. size_type find_first_not_of(_CharT __c, size_type __pos = 0) const;
  864. public: // find_last_not_of
  865. size_type find_last_not_of(const _Self& __s, size_type __pos = npos) const
  866. { return find_last_not_of(__s._M_Start(), __pos, __s.size()); }
  867. size_type find_last_not_of(const _CharT* __s, size_type __pos = npos) const
  868. { _STLP_FIX_LITERAL_BUG(__s) return find_last_not_of(__s, __pos, _Traits::length(__s)); }
  869. size_type find_last_not_of(const _CharT* __s, size_type __pos, size_type __n) const;
  870. size_type find_last_not_of(_CharT __c, size_type __pos = npos) const;
  871. public: // Substring.
  872. _Self substr(size_type __pos = 0, size_type __n = npos) const
  873. { return _Self(*this, __pos, __n, get_allocator()); }
  874. public: // Compare
  875. int compare(const _Self& __s) const
  876. { return _M_compare(this->_M_Start(), this->_M_Finish(), __s._M_Start(), __s._M_Finish()); }
  877. int compare(size_type __pos1, size_type __n1, const _Self& __s) const {
  878. if (__pos1 > size())
  879. this->_M_throw_out_of_range();
  880. return _M_compare(this->_M_Start() + __pos1,
  881. this->_M_Start() + __pos1 + (min) (__n1, size() - __pos1),
  882. __s._M_Start(), __s._M_Finish());
  883. }
  884. int compare(size_type __pos1, size_type __n1, const _Self& __s,
  885. size_type __pos2, size_type __n2) const {
  886. if (__pos1 > size() || __pos2 > __s.size())
  887. this->_M_throw_out_of_range();
  888. return _M_compare(this->_M_Start() + __pos1,
  889. this->_M_Start() + __pos1 + (min) (__n1, size() - __pos1),
  890. __s._M_Start() + __pos2,
  891. __s._M_Start() + __pos2 + (min) (__n2, __s.size() - __pos2));
  892. }
  893. int compare(const _CharT* __s) const {
  894. _STLP_FIX_LITERAL_BUG(__s)
  895. return _M_compare(this->_M_Start(), this->_M_Finish(), __s, __s + _Traits::length(__s));
  896. }
  897. int compare(size_type __pos1, size_type __n1, const _CharT* __s) const {
  898. _STLP_FIX_LITERAL_BUG(__s)
  899. if (__pos1 > size())
  900. this->_M_throw_out_of_range();
  901. return _M_compare(this->_M_Start() + __pos1,
  902. this->_M_Start() + __pos1 + (min) (__n1, size() - __pos1),
  903. __s, __s + _Traits::length(__s));
  904. }
  905. int compare(size_type __pos1, size_type __n1, const _CharT* __s, size_type __n2) const {
  906. _STLP_FIX_LITERAL_BUG(__s)
  907. if (__pos1 > size())
  908. this->_M_throw_out_of_range();
  909. return _M_compare(this->_M_Start() + __pos1,
  910. this->_M_Start() + __pos1 + (min) (__n1, size() - __pos1),
  911. __s, __s + __n2);
  912. }
  913. public: // Helper functions for compare.
  914. static int _STLP_CALL _M_compare(const _CharT* __f1, const _CharT* __l1,
  915. const _CharT* __f2, const _CharT* __l2) {
  916. const ptrdiff_t __n1 = __l1 - __f1;
  917. const ptrdiff_t __n2 = __l2 - __f2;
  918. const int cmp = _Traits::compare(__f1, __f2, (min) (__n1, __n2));
  919. return cmp != 0 ? cmp : (__n1 < __n2 ? -1 : (__n1 > __n2 ? 1 : 0));
  920. }
  921. #if defined (_STLP_USE_TEMPLATE_EXPRESSION) && !defined (_STLP_DEBUG) && !defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
  922. # define _STLP_STRING_SUM_BASE(__reserve, __size, __alloc) _STLP_PRIV _String_base<_CharT,_Alloc>(__alloc, __size + 1)
  923. # include <stl/_string_sum_methods.h>
  924. # undef _STLP_STRING_SUM_BASE
  925. #endif
  926. };
  927. #undef _STLP_PRIVATE
  928. #if defined (__GNUC__) && (__GNUC__ == 2) && (__GNUC_MINOR__ == 96)
  929. template <class _CharT, class _Traits, class _Alloc>
  930. const size_t basic_string<_CharT, _Traits, _Alloc>::npos = ~(size_t) 0;
  931. #endif
  932. #if defined (_STLP_USE_TEMPLATE_EXPORT)
  933. _STLP_EXPORT_TEMPLATE_CLASS basic_string<char, char_traits<char>, allocator<char> >;
  934. # if defined (_STLP_HAS_WCHAR_T)
  935. _STLP_EXPORT_TEMPLATE_CLASS basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >;
  936. # endif
  937. #endif /* _STLP_USE_TEMPLATE_EXPORT */
  938. #if defined (basic_string)
  939. _STLP_MOVE_TO_STD_NAMESPACE
  940. # undef basic_string
  941. #endif
  942. _STLP_END_NAMESPACE
  943. #if defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
  944. # include <stl/_string_workaround.h>
  945. #endif
  946. #if defined (_STLP_DEBUG)
  947. # include <stl/debug/_string.h>
  948. #endif
  949. _STLP_BEGIN_NAMESPACE
  950. // ------------------------------------------------------------
  951. // Non-member functions.
  952. // Swap.
  953. #if defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER)
  954. template <class _CharT, class _Traits, class _Alloc>
  955. inline void _STLP_CALL
  956. swap(basic_string<_CharT,_Traits,_Alloc>& __x,
  957. basic_string<_CharT,_Traits,_Alloc>& __y)
  958. { __x.swap(__y); }
  959. #else
  960. inline void _STLP_CALL swap(string& __x, string& __y)
  961. { __x.swap(__y); }
  962. # if defined (_STLP_HAS_WCHAR_T)
  963. inline void _STLP_CALL swap(wstring& __x, wstring& __y)
  964. { __x.swap(__y); }
  965. # endif
  966. #endif
  967. #if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) && !defined (_STLP_NO_MOVE_SEMANTIC)
  968. template <class _CharT, class _Traits, class _Alloc>
  969. struct __move_traits<basic_string<_CharT, _Traits, _Alloc> > {
  970. typedef __true_type implemented;
  971. //Completness depends on the allocator:
  972. typedef typename __move_traits<_Alloc>::complete complete;
  973. };
  974. /*#else
  975. * There is no need to specialize for string and wstring in this case
  976. * as the default __move_traits will already tell that string is movable
  977. * but not complete. We cannot define it as complete as nothing guaranty
  978. * that the STLport user hasn't specialized std::allocator for char or
  979. * wchar_t.
  980. */
  981. #endif
  982. _STLP_MOVE_TO_PRIV_NAMESPACE
  983. template <class _CharT, class _Traits, class _Alloc>
  984. void _STLP_CALL _S_string_copy(const basic_string<_CharT,_Traits,_Alloc>& __s,
  985. _CharT* __buf, size_t __n);
  986. #if defined(_STLP_USE_WIDE_INTERFACE)
  987. // A couple of functions to transfer between ASCII/Unicode
  988. wstring __ASCIIToWide(const char *ascii);
  989. string __WideToASCII(const wchar_t *wide);
  990. #endif
  991. inline const char* _STLP_CALL
  992. __get_c_string(const string& __str) { return __str.c_str(); }
  993. _STLP_MOVE_TO_STD_NAMESPACE
  994. _STLP_END_NAMESPACE
  995. #include <stl/_string_operators.h>
  996. #if defined(_STLP_USE_NO_IOSTREAMS) || \
  997. (defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION) && !defined (_STLP_LINK_TIME_INSTANTIATION))
  998. # include <stl/_string.c>
  999. #endif
  1000. #endif /* _STLP_INTERNAL_STRING_H */
  1001. /*
  1002. * Local Variables:
  1003. * mode:C++
  1004. * End:
  1005. */