_string_workaround.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599
  1. /*
  2. * Copyright (c) 2004
  3. * Francois Dumont
  4. *
  5. * This material is provided "as is", with absolutely no warranty expressed
  6. * or implied. Any use is at your own risk.
  7. *
  8. * Permission to use or copy this software for any purpose is hereby granted
  9. * without fee, provided the above notices are retained on all copies.
  10. * Permission to modify the code and to distribute modified code is granted,
  11. * provided the above notices are retained, and a notice that the code was
  12. * modified is included with the above copyright notice.
  13. *
  14. */
  15. //Included from _string.h, no need for macro guarding.
  16. _STLP_BEGIN_NAMESPACE
  17. #if defined (_STLP_DEBUG)
  18. # define basic_string _STLP_NON_DBG_NAME(str)
  19. _STLP_MOVE_TO_PRIV_NAMESPACE
  20. #endif
  21. #define _STLP_NO_MEM_T_STRING_BASE _STLP_PRIV _STLP_NO_MEM_T_NAME(str)<_CharT, _Traits, _Alloc>
  22. template <class _CharT, class _Traits, class _Alloc>
  23. class basic_string : public _STLP_NO_MEM_T_STRING_BASE
  24. #if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND) && !defined (basic_string)
  25. , public __stlport_class<basic_string<_CharT, _Traits, _Alloc> >
  26. #endif
  27. {
  28. private: // Protected members inherited from base.
  29. typedef basic_string<_CharT, _Traits, _Alloc> _Self;
  30. typedef _STLP_NO_MEM_T_STRING_BASE _Base;
  31. typedef typename _Base::_CalledFromWorkaround_t _CalledFromWorkaround_t;
  32. public:
  33. __IMPORT_WITH_REVERSE_ITERATORS(_Base)
  34. typedef typename _Base::_Iterator_category _Iterator_category;
  35. typedef typename _Base::traits_type traits_type;
  36. typedef typename _Base::_Reserve_t _Reserve_t;
  37. #include <stl/_string_npos.h>
  38. public: // Constructor, destructor, assignment.
  39. explicit basic_string(const allocator_type& __a = allocator_type())
  40. : _STLP_NO_MEM_T_STRING_BASE(__a) {}
  41. basic_string(_Reserve_t __r, size_t __n,
  42. const allocator_type& __a = allocator_type())
  43. : _STLP_NO_MEM_T_STRING_BASE(__r, __n, __a) {}
  44. basic_string(const _Self& __s)
  45. : _STLP_NO_MEM_T_STRING_BASE(__s) {}
  46. basic_string(const _Self& __s, size_type __pos, size_type __n = npos,
  47. const allocator_type& __a = allocator_type())
  48. : _STLP_NO_MEM_T_STRING_BASE(__s, __pos, __n, __a) {}
  49. basic_string(const _CharT* __s, size_type __n,
  50. const allocator_type& __a = allocator_type())
  51. : _STLP_NO_MEM_T_STRING_BASE(__s, __n, __a) {}
  52. basic_string(const _CharT* __s,
  53. const allocator_type& __a = allocator_type())
  54. : _STLP_NO_MEM_T_STRING_BASE(__s, __a) {}
  55. basic_string(size_type __n, _CharT __c,
  56. const allocator_type& __a = allocator_type())
  57. : _STLP_NO_MEM_T_STRING_BASE(__n, __c, __a) {}
  58. #if !defined (_STLP_NO_MOVE_SEMANTIC)
  59. basic_string(__move_source<_Self> src)
  60. : _STLP_NO_MEM_T_STRING_BASE(__move_source<_Base>(src.get())) {}
  61. #endif
  62. // Check to see if _InputIterator is an integer type. If so, then
  63. // it can't be an iterator.
  64. template <class _InputIterator>
  65. basic_string(_InputIterator __f, _InputIterator __l,
  66. const allocator_type & __a _STLP_ALLOCATOR_TYPE_DFL)
  67. : _STLP_NO_MEM_T_STRING_BASE(_CalledFromWorkaround_t(), __a) {
  68. typedef typename _IsIntegral<_InputIterator>::_Ret _Integral;
  69. _M_initialize_dispatch(__f, __l, _Integral());
  70. }
  71. # if defined (_STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS)
  72. template <class _InputIterator>
  73. basic_string(_InputIterator __f, _InputIterator __l)
  74. : _STLP_NO_MEM_T_STRING_BASE(_CalledFromWorkaround_t(), allocator_type()) {
  75. typedef typename _IsIntegral<_InputIterator>::_Ret _Integral;
  76. _M_initialize_dispatch(__f, __l, _Integral());
  77. }
  78. # endif
  79. _Self& operator=(const _Self& __s) {
  80. _Base::operator=(__s);
  81. return *this;
  82. }
  83. _Self& operator=(const _CharT* __s) {
  84. _Base::operator=(__s);
  85. return *this;
  86. }
  87. _Self& operator=(_CharT __c) {
  88. _Base::operator=(__c);
  89. return *this;
  90. }
  91. private:
  92. template <class _InputIter>
  93. void _M_range_initialize(_InputIter __f, _InputIter __l,
  94. const input_iterator_tag &__tag) {
  95. this->_M_allocate_block();
  96. this->_M_construct_null(this->_M_Finish());
  97. _M_appendT(__f, __l, __tag);
  98. }
  99. template <class _ForwardIter>
  100. void _M_range_initialize(_ForwardIter __f, _ForwardIter __l,
  101. const forward_iterator_tag &) {
  102. difference_type __n = _STLP_STD::distance(__f, __l);
  103. this->_M_allocate_block(__n + 1);
  104. this->_M_finish = uninitialized_copy(__f, __l, this->_M_Start());
  105. this->_M_terminate_string();
  106. }
  107. template <class _InputIter>
  108. void _M_range_initializeT(_InputIter __f, _InputIter __l) {
  109. _M_range_initialize(__f, __l, _STLP_ITERATOR_CATEGORY(__f, _InputIter));
  110. }
  111. template <class _Integer>
  112. void _M_initialize_dispatch(_Integer __n, _Integer __x, const __true_type& /*_Integral*/) {
  113. this->_M_allocate_block(__n + 1);
  114. this->_M_finish = uninitialized_fill_n(this->_M_Start(), __n, __x);
  115. this->_M_terminate_string();
  116. }
  117. template <class _InputIter>
  118. void _M_initialize_dispatch(_InputIter __f, _InputIter __l, const __false_type& /*_Integral*/) {
  119. _M_range_initializeT(__f, __l);
  120. }
  121. public: // Append, operator+=, push_back.
  122. _Self& operator+=(const _Self& __s) {
  123. _Base::operator+=(__s);
  124. return *this;
  125. }
  126. _Self& operator+=(const _CharT* __s) {
  127. _STLP_FIX_LITERAL_BUG(__s)
  128. _Base::operator+=(__s);
  129. return *this;
  130. }
  131. _Self& operator+=(_CharT __c) {
  132. _Base::operator+=(__c);
  133. return *this;
  134. }
  135. _Self& append(const _Self& __s) {
  136. _Base::append(__s);
  137. return *this;
  138. }
  139. _Self& append(const _Self& __s,
  140. size_type __pos, size_type __n) {
  141. _Base::append(__s, __pos, __n);
  142. return *this;
  143. }
  144. _Self& append(const _CharT* __s, size_type __n) {
  145. _STLP_FIX_LITERAL_BUG(__s)
  146. _Base::append(__s, __n);
  147. return *this;
  148. }
  149. _Self& append(const _CharT* __s) {
  150. _STLP_FIX_LITERAL_BUG(__s)
  151. _Base::append(__s);
  152. return *this;
  153. }
  154. _Self& append(size_type __n, _CharT __c) {
  155. _Base::append(__n, __c);
  156. return *this;
  157. }
  158. // Check to see if _InputIterator is an integer type. If so, then
  159. // it can't be an iterator.
  160. template <class _InputIter>
  161. _Self& append(_InputIter __first, _InputIter __last) {
  162. typedef typename _IsIntegral<_InputIter>::_Ret _Integral;
  163. return _M_append_dispatch(__first, __last, _Integral());
  164. }
  165. #if !defined (_STLP_NO_METHOD_SPECIALIZATION) && !defined (_STLP_NO_EXTENSIONS)
  166. //See equivalent assign method remark.
  167. _Self& append(const _CharT* __f, const _CharT* __l) {
  168. _STLP_FIX_LITERAL_BUG(__f)_STLP_FIX_LITERAL_BUG(__l)
  169. _Base::append(__f, __l);
  170. return *this;
  171. }
  172. #endif
  173. private: // Helper functions for append.
  174. template <class _InputIter>
  175. _Self& _M_appendT(_InputIter __first, _InputIter __last,
  176. const input_iterator_tag &) {
  177. for ( ; __first != __last ; ++__first)
  178. _Base::push_back(*__first);
  179. return *this;
  180. }
  181. template <class _ForwardIter>
  182. _Self& _M_appendT(_ForwardIter __first, _ForwardIter __last,
  183. const forward_iterator_tag &) {
  184. if (__first != __last) {
  185. const size_type __n = __STATIC_CAST(size_type, _STLP_STD::distance(__first, __last));
  186. if (__n >= this->_M_rest()) {
  187. size_type __len = this->_M_compute_next_size(__n);
  188. pointer __new_start = this->_M_start_of_storage.allocate(__len, __len);
  189. pointer __new_finish = uninitialized_copy(this->_M_Start(), this->_M_Finish(), __new_start);
  190. __new_finish = uninitialized_copy(__first, __last, __new_finish);
  191. this->_M_construct_null(__new_finish);
  192. this->_M_deallocate_block();
  193. this->_M_reset(__new_start, __new_finish, __new_start + __len);
  194. }
  195. else {
  196. _Traits::assign(*this->_M_finish, *__first++);
  197. uninitialized_copy(__first, __last, this->_M_Finish() + 1);
  198. this->_M_construct_null(this->_M_Finish() + __n);
  199. this->_M_finish += __n;
  200. }
  201. }
  202. return *this;
  203. }
  204. template <class _Integer>
  205. _Self& _M_append_dispatch(_Integer __n, _Integer __x, const __true_type& /*Integral*/)
  206. { return append((size_type) __n, (_CharT) __x); }
  207. template <class _InputIter>
  208. _Self& _M_append_dispatch(_InputIter __f, _InputIter __l, const __false_type& /*Integral*/)
  209. { return _M_appendT(__f, __l, _STLP_ITERATOR_CATEGORY(__f, _InputIter)); }
  210. public: // Assign
  211. _Self& assign(const _Self& __s) {
  212. _Base::assign(__s);
  213. return *this;
  214. }
  215. _Self& assign(const _Self& __s,
  216. size_type __pos, size_type __n) {
  217. _Base::assign(__s, __pos, __n);
  218. return *this;
  219. }
  220. _Self& assign(const _CharT* __s, size_type __n) {
  221. _STLP_FIX_LITERAL_BUG(__s)
  222. _Base::assign(__s, __n);
  223. return *this;
  224. }
  225. _Self& assign(const _CharT* __s) {
  226. _STLP_FIX_LITERAL_BUG(__s)
  227. _Base::assign(__s);
  228. return *this;
  229. }
  230. _Self& assign(size_type __n, _CharT __c) {
  231. _Base::assign(__n, __c);
  232. return *this;
  233. }
  234. private: // Helper functions for assign.
  235. template <class _Integer>
  236. _Self& _M_assign_dispatch(_Integer __n, _Integer __x, const __true_type& /*_Integral*/)
  237. { return assign((size_type) __n, (_CharT) __x); }
  238. template <class _InputIter>
  239. _Self& _M_assign_dispatch(_InputIter __f, _InputIter __l, const __false_type& /*_Integral*/) {
  240. pointer __cur = this->_M_Start();
  241. while (__f != __l && __cur != this->_M_Finish()) {
  242. _Traits::assign(*__cur, *__f);
  243. ++__f;
  244. ++__cur;
  245. }
  246. if (__f == __l)
  247. _Base::erase(__cur, this->_M_Finish());
  248. else
  249. _M_appendT(__f, __l, _STLP_ITERATOR_CATEGORY(__f, _InputIter));
  250. return *this;
  251. }
  252. public:
  253. // Check to see if _InputIterator is an integer type. If so, then
  254. // it can't be an iterator.
  255. template <class _InputIter>
  256. _Self& assign(_InputIter __first, _InputIter __last) {
  257. typedef typename _IsIntegral<_InputIter>::_Ret _Integral;
  258. return _M_assign_dispatch(__first, __last, _Integral());
  259. }
  260. #if !defined (_STLP_NO_METHOD_SPECIALIZATION) && !defined (_STLP_NO_EXTENSIONS)
  261. /* This method is not part of the standard and is a specialization of the
  262. * template method assign. It is only granted for convenience to call assign
  263. * with mixed parameters iterator and const_iterator.
  264. */
  265. _Self& assign(const _CharT* __f, const _CharT* __l) {
  266. _STLP_FIX_LITERAL_BUG(__f)_STLP_FIX_LITERAL_BUG(__l)
  267. _Base::assign(__f, __l);
  268. return *this;
  269. }
  270. #endif
  271. public: // Insert
  272. _Self& insert(size_type __pos, const _Self& __s) {
  273. _Base::insert(__pos, __s);
  274. return *this;
  275. }
  276. _Self& insert(size_type __pos, const _Self& __s,
  277. size_type __beg, size_type __n) {
  278. _Base::insert(__pos, __s, __beg, __n);
  279. return *this;
  280. }
  281. _Self& insert(size_type __pos, const _CharT* __s, size_type __n) {
  282. _STLP_FIX_LITERAL_BUG(__s)
  283. _Base::insert(__pos, __s, __n);
  284. return *this;
  285. }
  286. _Self& insert(size_type __pos, const _CharT* __s) {
  287. _STLP_FIX_LITERAL_BUG(__s)
  288. _Base::insert(__pos, __s);
  289. return *this;
  290. }
  291. _Self& insert(size_type __pos, size_type __n, _CharT __c) {
  292. _Base::insert(__pos, __n, __c);
  293. return *this;
  294. }
  295. iterator insert(iterator __p, _CharT __c)
  296. { return _Base::insert(__p, __c); }
  297. void insert(iterator __p, size_t __n, _CharT __c)
  298. { _Base::insert(__p, __n, __c); }
  299. // Check to see if _InputIterator is an integer type. If so, then
  300. // it can't be an iterator.
  301. template <class _InputIter>
  302. void insert(iterator __p, _InputIter __first, _InputIter __last) {
  303. typedef typename _IsIntegral<_InputIter>::_Ret _Integral;
  304. _M_insert_dispatch(__p, __first, __last, _Integral());
  305. }
  306. #if !defined (_STLP_NO_METHOD_SPECIALIZATION)
  307. public:
  308. void insert(iterator __p, const _CharT* __f, const _CharT* __l) {
  309. _STLP_FIX_LITERAL_BUG(__f) _STLP_FIX_LITERAL_BUG(__l)
  310. _M_insert(__p, __f, __l, this->_M_inside(__f));
  311. }
  312. #endif
  313. private: // Helper functions for insert.
  314. void _M_insert(iterator __p, const _CharT* __f, const _CharT* __l, bool __self_ref) {
  315. _STLP_FIX_LITERAL_BUG(__f)_STLP_FIX_LITERAL_BUG(__l)
  316. _Base::_M_insert(__p, __f, __l, __self_ref);
  317. }
  318. template <class _ForwardIter>
  319. void _M_insert_overflow(iterator __pos, _ForwardIter __first, _ForwardIter __last,
  320. size_type __n) {
  321. size_type __len = this->_M_compute_next_size(__n);
  322. pointer __new_start = this->_M_start_of_storage.allocate(__len, __len);
  323. pointer __new_finish = uninitialized_copy(this->_M_Start(), __pos, __new_start);
  324. __new_finish = uninitialized_copy(__first, __last, __new_finish);
  325. __new_finish = uninitialized_copy(__pos, this->_M_Finish(), __new_finish);
  326. this->_M_construct_null(__new_finish);
  327. this->_M_deallocate_block();
  328. this->_M_reset(__new_start, __new_finish, __new_start + __len);
  329. }
  330. template <class _InputIter>
  331. void _M_insertT(iterator __p, _InputIter __first, _InputIter __last,
  332. const input_iterator_tag &) {
  333. for ( ; __first != __last; ++__first) {
  334. __p = insert(__p, *__first);
  335. ++__p;
  336. }
  337. }
  338. template <class _ForwardIter>
  339. void _M_insertT(iterator __pos, _ForwardIter __first, _ForwardIter __last,
  340. const forward_iterator_tag &) {
  341. if (__first != __last) {
  342. size_type __n = __STATIC_CAST(size_type, _STLP_STD::distance(__first, __last));
  343. if (__n < this->_M_rest()) {
  344. const size_type __elems_after = this->_M_finish - __pos;
  345. if (__elems_after >= __n) {
  346. uninitialized_copy((this->_M_Finish() - __n) + 1, this->_M_Finish() + 1, this->_M_Finish() + 1);
  347. this->_M_finish += __n;
  348. _Traits::move(__pos + __n, __pos, (__elems_after - __n) + 1);
  349. _M_copyT(__first, __last, __pos);
  350. }
  351. else {
  352. pointer __old_finish = this->_M_Finish();
  353. _ForwardIter __mid = __first;
  354. _STLP_STD::advance(__mid, __elems_after + 1);
  355. _STLP_STD::uninitialized_copy(__mid, __last, this->_M_Finish() + 1);
  356. this->_M_finish += __n - __elems_after;
  357. uninitialized_copy(__pos, __old_finish + 1, this->_M_Finish());
  358. this->_M_finish += __elems_after;
  359. _M_copyT(__first, __mid, __pos);
  360. }
  361. }
  362. else {
  363. _M_insert_overflow(__pos, __first, __last, __n);
  364. }
  365. }
  366. }
  367. template <class _Integer>
  368. void _M_insert_dispatch(iterator __p, _Integer __n, _Integer __x,
  369. const __true_type& /*Integral*/)
  370. { insert(__p, (size_type) __n, (_CharT) __x); }
  371. template <class _InputIter>
  372. void _M_insert_dispatch(iterator __p, _InputIter __first, _InputIter __last,
  373. const __false_type& /*Integral*/) {
  374. _STLP_FIX_LITERAL_BUG(__p)
  375. /* We are forced to do a temporary string to avoid the self referencing issue. */
  376. const _Self __self(__first, __last, this->get_allocator());
  377. _M_insertT(__p, __self.begin(), __self.end(), _STLP_ITERATOR_CATEGORY(__first, _InputIter));
  378. }
  379. template <class _InputIterator>
  380. void _M_copyT(_InputIterator __first, _InputIterator __last, pointer __result) {
  381. _STLP_FIX_LITERAL_BUG(__p)
  382. for ( ; __first != __last; ++__first, ++__result)
  383. _Traits::assign(*__result, *__first);
  384. }
  385. #if !defined (_STLP_NO_METHOD_SPECIALIZATION)
  386. void _M_copyT(const _CharT* __f, const _CharT* __l, _CharT* __res) {
  387. _STLP_FIX_LITERAL_BUG(__f) _STLP_FIX_LITERAL_BUG(__l) _STLP_FIX_LITERAL_BUG(__res)
  388. _Base::_M_copy(__f, __l, __res);
  389. }
  390. #endif
  391. public: // Erase.
  392. _Self& erase(size_type __pos = 0, size_type __n = npos) {
  393. _Base::erase(__pos, __n);
  394. return *this;
  395. }
  396. iterator erase(iterator __pos) {
  397. _STLP_FIX_LITERAL_BUG(__pos)
  398. return _Base::erase(__pos);
  399. }
  400. iterator erase(iterator __first, iterator __last) {
  401. _STLP_FIX_LITERAL_BUG(__first) _STLP_FIX_LITERAL_BUG(__last)
  402. return _Base::erase(__first, __last);
  403. }
  404. public: // Replace. (Conceptually equivalent
  405. // to erase followed by insert.)
  406. _Self& replace(size_type __pos, size_type __n, const _Self& __s) {
  407. _Base::replace(__pos, __n, __s);
  408. return *this;
  409. }
  410. _Self& replace(size_type __pos1, size_type __n1, const _Self& __s,
  411. size_type __pos2, size_type __n2) {
  412. _Base::replace(__pos1, __n1, __s, __pos2, __n2);
  413. return *this;
  414. }
  415. _Self& replace(size_type __pos, size_type __n1,
  416. const _CharT* __s, size_type __n2) {
  417. _STLP_FIX_LITERAL_BUG(__s)
  418. _Base::replace(__pos, __n1, __s, __n2);
  419. return *this;
  420. }
  421. _Self& replace(size_type __pos, size_type __n1, const _CharT* __s) {
  422. _STLP_FIX_LITERAL_BUG(__s)
  423. _Base::replace(__pos, __n1, __s);
  424. return *this;
  425. }
  426. _Self& replace(size_type __pos, size_type __n1,
  427. size_type __n2, _CharT __c) {
  428. _Base::replace(__pos, __n1, __n2, __c);
  429. return *this;
  430. }
  431. _Self& replace(iterator __first, iterator __last, const _Self& __s) {
  432. _STLP_FIX_LITERAL_BUG(__first) _STLP_FIX_LITERAL_BUG(__last)
  433. _Base::replace(__first, __last, __s);
  434. return *this;
  435. }
  436. _Self& replace(iterator __first, iterator __last,
  437. const _CharT* __s, size_type __n) {
  438. _STLP_FIX_LITERAL_BUG(__first) _STLP_FIX_LITERAL_BUG(__last)
  439. _STLP_FIX_LITERAL_BUG(__s)
  440. _Base::replace(__first, __last, __s, __n);
  441. return *this;
  442. }
  443. _Self& replace(iterator __first, iterator __last,
  444. const _CharT* __s) {
  445. _STLP_FIX_LITERAL_BUG(__first) _STLP_FIX_LITERAL_BUG(__last)
  446. _STLP_FIX_LITERAL_BUG(__s)
  447. _Base::replace(__first, __last, __s);
  448. return *this;
  449. }
  450. _Self& replace(iterator __first, iterator __last,
  451. size_type __n, _CharT __c) {
  452. _STLP_FIX_LITERAL_BUG(__first) _STLP_FIX_LITERAL_BUG(__last)
  453. _Base::replace(__first, __last, __n, __c);
  454. return *this;
  455. }
  456. // Check to see if _InputIter is an integer type. If so, then
  457. // it can't be an iterator.
  458. template <class _InputIter>
  459. _Self& replace(iterator __first, iterator __last,
  460. _InputIter __f, _InputIter __l) {
  461. _STLP_FIX_LITERAL_BUG(__first)_STLP_FIX_LITERAL_BUG(__last)
  462. typedef typename _IsIntegral<_InputIter>::_Ret _Integral;
  463. return _M_replace_dispatch(__first, __last, __f, __l, _Integral());
  464. }
  465. #if !defined (_STLP_NO_METHOD_SPECIALIZATION)
  466. _Self& replace(iterator __first, iterator __last,
  467. const _CharT* __f, const _CharT* __l) {
  468. _STLP_FIX_LITERAL_BUG(__first) _STLP_FIX_LITERAL_BUG(__last)
  469. _STLP_FIX_LITERAL_BUG(__f) _STLP_FIX_LITERAL_BUG(__l)
  470. return _M_replace(__first, __last, __f, __l, this->_M_inside(__f));
  471. }
  472. #endif
  473. private: // Helper functions for replace.
  474. _Self& _M_replace(iterator __first, iterator __last,
  475. const _CharT* __f, const _CharT* __l, bool __self_ref) {
  476. _STLP_FIX_LITERAL_BUG(__first) _STLP_FIX_LITERAL_BUG(__last)
  477. _STLP_FIX_LITERAL_BUG(__f) _STLP_FIX_LITERAL_BUG(__l)
  478. _Base::_M_replace(__first, __last, __f, __l, __self_ref);
  479. return *this;
  480. }
  481. template <class _Integer>
  482. _Self& _M_replace_dispatch(iterator __first, iterator __last,
  483. _Integer __n, _Integer __x, const __true_type& /*IsIntegral*/) {
  484. _STLP_FIX_LITERAL_BUG(__first) _STLP_FIX_LITERAL_BUG(__last)
  485. return replace(__first, __last, (size_type) __n, (_CharT) __x);
  486. }
  487. template <class _InputIter>
  488. _Self& _M_replace_dispatch(iterator __first, iterator __last,
  489. _InputIter __f, _InputIter __l, const __false_type& /*IsIntegral*/) {
  490. _STLP_FIX_LITERAL_BUG(__first) _STLP_FIX_LITERAL_BUG(__last)
  491. /* We are forced to do a temporary string to avoid the self referencing issue. */
  492. const _Self __self(__f, __l, this->get_allocator());
  493. return _M_replace(__first, __last, __self._M_Start(), __self._M_Finish(), false);
  494. }
  495. public: // Other modifier member functions.
  496. void swap(_Self& __s) { _Base::swap(__s); }
  497. #if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND) && !defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER)
  498. void _M_swap_workaround(_Self& __x) { swap(__x); }
  499. #endif
  500. public: // Substring.
  501. _Self substr(size_type __pos = 0, size_type __n = npos) const
  502. { return _Self(*this, __pos, __n, this->get_allocator()); }
  503. #if defined (_STLP_USE_TEMPLATE_EXPRESSION) && !defined (_STLP_DEBUG)
  504. # define _STLP_STRING_SUM_BASE _STLP_NO_MEM_T_STRING_BASE
  505. # include <stl/_string_sum_methods.h>
  506. # undef _STLP_STRING_SUM_BASE
  507. #endif
  508. };
  509. #undef _STLP_NO_MEM_T_STRING_BASE
  510. #if defined (basic_string)
  511. _STLP_MOVE_TO_STD_NAMESPACE
  512. # undef basic_string
  513. #endif
  514. _STLP_END_NAMESPACE