string 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075
  1. // Debugging string implementation -*- C++ -*-
  2. // Copyright (C) 2003, 2005, 2006, 2009
  3. // Free Software Foundation, Inc.
  4. //
  5. // This file is part of the GNU ISO C++ Library. This library is free
  6. // software; you can redistribute it and/or modify it under the
  7. // terms of the GNU General Public License as published by the
  8. // Free Software Foundation; either version 3, or (at your option)
  9. // any later version.
  10. // This library is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. // GNU General Public License for more details.
  14. // Under Section 7 of GPL version 3, you are granted additional
  15. // permissions described in the GCC Runtime Library Exception, version
  16. // 3.1, as published by the Free Software Foundation.
  17. // You should have received a copy of the GNU General Public License and
  18. // a copy of the GCC Runtime Library Exception along with this program;
  19. // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  20. // <http://www.gnu.org/licenses/>.
  21. /** @file debug/string
  22. * This file is a GNU debug extension to the Standard C++ Library.
  23. */
  24. #ifndef _GLIBCXX_DEBUG_STRING
  25. #define _GLIBCXX_DEBUG_STRING 1
  26. #include <string>
  27. #include <debug/safe_sequence.h>
  28. #include <debug/safe_iterator.h>
  29. namespace __gnu_debug
  30. {
  31. template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
  32. typename _Allocator = std::allocator<_CharT> >
  33. class basic_string
  34. : public std::basic_string<_CharT, _Traits, _Allocator>,
  35. public __gnu_debug::_Safe_sequence<basic_string<_CharT, _Traits,
  36. _Allocator> >
  37. {
  38. typedef std::basic_string<_CharT, _Traits, _Allocator> _Base;
  39. typedef __gnu_debug::_Safe_sequence<basic_string> _Safe_base;
  40. public:
  41. // types:
  42. typedef _Traits traits_type;
  43. typedef typename _Traits::char_type value_type;
  44. typedef _Allocator allocator_type;
  45. typedef typename _Base::size_type size_type;
  46. typedef typename _Base::difference_type difference_type;
  47. typedef typename _Base::reference reference;
  48. typedef typename _Base::const_reference const_reference;
  49. typedef typename _Base::pointer pointer;
  50. typedef typename _Base::const_pointer const_pointer;
  51. typedef __gnu_debug::_Safe_iterator<typename _Base::iterator, basic_string>
  52. iterator;
  53. typedef __gnu_debug::_Safe_iterator<typename _Base::const_iterator,
  54. basic_string> const_iterator;
  55. typedef std::reverse_iterator<iterator> reverse_iterator;
  56. typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
  57. using _Base::npos;
  58. // 21.3.1 construct/copy/destroy:
  59. explicit basic_string(const _Allocator& __a = _Allocator())
  60. : _Base(__a)
  61. { }
  62. // Provides conversion from a release-mode string to a debug-mode string
  63. basic_string(const _Base& __base) : _Base(__base), _Safe_base() { }
  64. // _GLIBCXX_RESOLVE_LIB_DEFECTS
  65. // 42. string ctors specify wrong default allocator
  66. basic_string(const basic_string& __str)
  67. : _Base(__str, 0, _Base::npos, __str.get_allocator()), _Safe_base()
  68. { }
  69. // _GLIBCXX_RESOLVE_LIB_DEFECTS
  70. // 42. string ctors specify wrong default allocator
  71. basic_string(const basic_string& __str, size_type __pos,
  72. size_type __n = _Base::npos,
  73. const _Allocator& __a = _Allocator())
  74. : _Base(__str, __pos, __n, __a)
  75. { }
  76. basic_string(const _CharT* __s, size_type __n,
  77. const _Allocator& __a = _Allocator())
  78. : _Base(__gnu_debug::__check_string(__s, __n), __n, __a)
  79. { }
  80. basic_string(const _CharT* __s, const _Allocator& __a = _Allocator())
  81. : _Base(__gnu_debug::__check_string(__s), __a)
  82. { this->assign(__s); }
  83. basic_string(size_type __n, _CharT __c,
  84. const _Allocator& __a = _Allocator())
  85. : _Base(__n, __c, __a)
  86. { }
  87. template<typename _InputIterator>
  88. basic_string(_InputIterator __begin, _InputIterator __end,
  89. const _Allocator& __a = _Allocator())
  90. : _Base(__gnu_debug::__check_valid_range(__begin, __end), __end, __a)
  91. { }
  92. #ifdef __GXX_EXPERIMENTAL_CXX0X__
  93. basic_string(initializer_list<_CharT> __l, const _Alloc& __a = _Alloc())
  94. : _Base(__l, __a)
  95. { }
  96. #endif // __GXX_EXPERIMENTAL_CXX0X__
  97. ~basic_string() { }
  98. basic_string&
  99. operator=(const basic_string& __str)
  100. {
  101. *static_cast<_Base*>(this) = __str;
  102. this->_M_invalidate_all();
  103. return *this;
  104. }
  105. basic_string&
  106. operator=(const _CharT* __s)
  107. {
  108. __glibcxx_check_string(__s);
  109. *static_cast<_Base*>(this) = __s;
  110. this->_M_invalidate_all();
  111. return *this;
  112. }
  113. basic_string&
  114. operator=(_CharT __c)
  115. {
  116. *static_cast<_Base*>(this) = __c;
  117. this->_M_invalidate_all();
  118. return *this;
  119. }
  120. #ifdef __GXX_EXPERIMENTAL_CXX0X__
  121. basic_string&
  122. operator=(initializer_list<_CharT> __l)
  123. {
  124. *static_cast<_Base*>(this) = __l;
  125. this->_M_invalidate_all();
  126. return *this;
  127. }
  128. #endif // __GXX_EXPERIMENTAL_CXX0X__
  129. // 21.3.2 iterators:
  130. iterator
  131. begin()
  132. { return iterator(_Base::begin(), this); }
  133. const_iterator
  134. begin() const
  135. { return const_iterator(_Base::begin(), this); }
  136. iterator
  137. end()
  138. { return iterator(_Base::end(), this); }
  139. const_iterator
  140. end() const
  141. { return const_iterator(_Base::end(), this); }
  142. reverse_iterator
  143. rbegin()
  144. { return reverse_iterator(end()); }
  145. const_reverse_iterator
  146. rbegin() const
  147. { return const_reverse_iterator(end()); }
  148. reverse_iterator
  149. rend()
  150. { return reverse_iterator(begin()); }
  151. const_reverse_iterator
  152. rend() const
  153. { return const_reverse_iterator(begin()); }
  154. // 21.3.3 capacity:
  155. using _Base::size;
  156. using _Base::length;
  157. using _Base::max_size;
  158. void
  159. resize(size_type __n, _CharT __c)
  160. {
  161. _Base::resize(__n, __c);
  162. this->_M_invalidate_all();
  163. }
  164. void
  165. resize(size_type __n)
  166. { this->resize(__n, _CharT()); }
  167. using _Base::capacity;
  168. using _Base::reserve;
  169. void
  170. clear()
  171. {
  172. _Base::clear();
  173. this->_M_invalidate_all();
  174. }
  175. using _Base::empty;
  176. // 21.3.4 element access:
  177. const_reference
  178. operator[](size_type __pos) const
  179. {
  180. _GLIBCXX_DEBUG_VERIFY(__pos <= this->size(),
  181. _M_message(__gnu_debug::__msg_subscript_oob)
  182. ._M_sequence(*this, "this")
  183. ._M_integer(__pos, "__pos")
  184. ._M_integer(this->size(), "size"));
  185. return _M_base()[__pos];
  186. }
  187. reference
  188. operator[](size_type __pos)
  189. {
  190. #ifdef _GLIBCXX_DEBUG_PEDANTIC
  191. __glibcxx_check_subscript(__pos);
  192. #else
  193. // as an extension v3 allows s[s.size()] when s is non-const.
  194. _GLIBCXX_DEBUG_VERIFY(__pos <= this->size(),
  195. _M_message(__gnu_debug::__msg_subscript_oob)
  196. ._M_sequence(*this, "this")
  197. ._M_integer(__pos, "__pos")
  198. ._M_integer(this->size(), "size"));
  199. #endif
  200. return _M_base()[__pos];
  201. }
  202. using _Base::at;
  203. // 21.3.5 modifiers:
  204. basic_string&
  205. operator+=(const basic_string& __str)
  206. {
  207. _M_base() += __str;
  208. this->_M_invalidate_all();
  209. return *this;
  210. }
  211. basic_string&
  212. operator+=(const _CharT* __s)
  213. {
  214. __glibcxx_check_string(__s);
  215. _M_base() += __s;
  216. this->_M_invalidate_all();
  217. return *this;
  218. }
  219. basic_string&
  220. operator+=(_CharT __c)
  221. {
  222. _M_base() += __c;
  223. this->_M_invalidate_all();
  224. return *this;
  225. }
  226. #ifdef __GXX_EXPERIMENTAL_CXX0X__
  227. basic_string&
  228. operator+=(initializer_list<_CharT> __l)
  229. {
  230. _M_base() += __l;
  231. this->_M_invalidate_all();
  232. return *this;
  233. }
  234. #endif // __GXX_EXPERIMENTAL_CXX0X__
  235. basic_string&
  236. append(const basic_string& __str)
  237. {
  238. _Base::append(__str);
  239. this->_M_invalidate_all();
  240. return *this;
  241. }
  242. basic_string&
  243. append(const basic_string& __str, size_type __pos, size_type __n)
  244. {
  245. _Base::append(__str, __pos, __n);
  246. this->_M_invalidate_all();
  247. return *this;
  248. }
  249. basic_string&
  250. append(const _CharT* __s, size_type __n)
  251. {
  252. __glibcxx_check_string_len(__s, __n);
  253. _Base::append(__s, __n);
  254. this->_M_invalidate_all();
  255. return *this;
  256. }
  257. basic_string&
  258. append(const _CharT* __s)
  259. {
  260. __glibcxx_check_string(__s);
  261. _Base::append(__s);
  262. this->_M_invalidate_all();
  263. return *this;
  264. }
  265. basic_string&
  266. append(size_type __n, _CharT __c)
  267. {
  268. _Base::append(__n, __c);
  269. this->_M_invalidate_all();
  270. return *this;
  271. }
  272. template<typename _InputIterator>
  273. basic_string&
  274. append(_InputIterator __first, _InputIterator __last)
  275. {
  276. __glibcxx_check_valid_range(__first, __last);
  277. _Base::append(__first, __last);
  278. this->_M_invalidate_all();
  279. return *this;
  280. }
  281. // _GLIBCXX_RESOLVE_LIB_DEFECTS
  282. // 7. string clause minor problems
  283. void
  284. push_back(_CharT __c)
  285. {
  286. _Base::push_back(__c);
  287. this->_M_invalidate_all();
  288. }
  289. basic_string&
  290. assign(const basic_string& __x)
  291. {
  292. _Base::assign(__x);
  293. this->_M_invalidate_all();
  294. return *this;
  295. }
  296. basic_string&
  297. assign(const basic_string& __str, size_type __pos, size_type __n)
  298. {
  299. _Base::assign(__str, __pos, __n);
  300. this->_M_invalidate_all();
  301. return *this;
  302. }
  303. basic_string&
  304. assign(const _CharT* __s, size_type __n)
  305. {
  306. __glibcxx_check_string_len(__s, __n);
  307. _Base::assign(__s, __n);
  308. this->_M_invalidate_all();
  309. return *this;
  310. }
  311. basic_string&
  312. assign(const _CharT* __s)
  313. {
  314. __glibcxx_check_string(__s);
  315. _Base::assign(__s);
  316. this->_M_invalidate_all();
  317. return *this;
  318. }
  319. basic_string&
  320. assign(size_type __n, _CharT __c)
  321. {
  322. _Base::assign(__n, __c);
  323. this->_M_invalidate_all();
  324. return *this;
  325. }
  326. template<typename _InputIterator>
  327. basic_string&
  328. assign(_InputIterator __first, _InputIterator __last)
  329. {
  330. __glibcxx_check_valid_range(__first, __last);
  331. _Base::assign(__first, __last);
  332. this->_M_invalidate_all();
  333. return *this;
  334. }
  335. #ifdef __GXX_EXPERIMENTAL_CXX0X__
  336. basic_string&
  337. assign(initializer_list<_CharT> __l)
  338. {
  339. _Base::assign(__l);
  340. this->_M_invalidate_all();
  341. return *this;
  342. }
  343. #endif // __GXX_EXPERIMENTAL_CXX0X__
  344. basic_string&
  345. insert(size_type __pos1, const basic_string& __str)
  346. {
  347. _Base::insert(__pos1, __str);
  348. this->_M_invalidate_all();
  349. return *this;
  350. }
  351. basic_string&
  352. insert(size_type __pos1, const basic_string& __str,
  353. size_type __pos2, size_type __n)
  354. {
  355. _Base::insert(__pos1, __str, __pos2, __n);
  356. this->_M_invalidate_all();
  357. return *this;
  358. }
  359. basic_string&
  360. insert(size_type __pos, const _CharT* __s, size_type __n)
  361. {
  362. __glibcxx_check_string(__s);
  363. _Base::insert(__pos, __s, __n);
  364. this->_M_invalidate_all();
  365. return *this;
  366. }
  367. basic_string&
  368. insert(size_type __pos, const _CharT* __s)
  369. {
  370. __glibcxx_check_string(__s);
  371. _Base::insert(__pos, __s);
  372. this->_M_invalidate_all();
  373. return *this;
  374. }
  375. basic_string&
  376. insert(size_type __pos, size_type __n, _CharT __c)
  377. {
  378. _Base::insert(__pos, __n, __c);
  379. this->_M_invalidate_all();
  380. return *this;
  381. }
  382. iterator
  383. insert(iterator __p, _CharT __c)
  384. {
  385. __glibcxx_check_insert(__p);
  386. typename _Base::iterator __res = _Base::insert(__p.base(), __c);
  387. this->_M_invalidate_all();
  388. return iterator(__res, this);
  389. }
  390. void
  391. insert(iterator __p, size_type __n, _CharT __c)
  392. {
  393. __glibcxx_check_insert(__p);
  394. _Base::insert(__p.base(), __n, __c);
  395. this->_M_invalidate_all();
  396. }
  397. template<typename _InputIterator>
  398. void
  399. insert(iterator __p, _InputIterator __first, _InputIterator __last)
  400. {
  401. __glibcxx_check_insert_range(__p, __first, __last);
  402. _Base::insert(__p.base(), __first, __last);
  403. this->_M_invalidate_all();
  404. }
  405. #ifdef __GXX_EXPERIMENTAL_CXX0X__
  406. void
  407. insert(iterator __p, initializer_list<_CharT> __l)
  408. {
  409. _Base::insert(__p, __l);
  410. this->_M_invalidate_all();
  411. }
  412. #endif // __GXX_EXPERIMENTAL_CXX0X__
  413. basic_string&
  414. erase(size_type __pos = 0, size_type __n = _Base::npos)
  415. {
  416. _Base::erase(__pos, __n);
  417. this->_M_invalidate_all();
  418. return *this;
  419. }
  420. iterator
  421. erase(iterator __position)
  422. {
  423. __glibcxx_check_erase(__position);
  424. typename _Base::iterator __res = _Base::erase(__position.base());
  425. this->_M_invalidate_all();
  426. return iterator(__res, this);
  427. }
  428. iterator
  429. erase(iterator __first, iterator __last)
  430. {
  431. // _GLIBCXX_RESOLVE_LIB_DEFECTS
  432. // 151. can't currently clear() empty container
  433. __glibcxx_check_erase_range(__first, __last);
  434. typename _Base::iterator __res = _Base::erase(__first.base(),
  435. __last.base());
  436. this->_M_invalidate_all();
  437. return iterator(__res, this);
  438. }
  439. basic_string&
  440. replace(size_type __pos1, size_type __n1, const basic_string& __str)
  441. {
  442. _Base::replace(__pos1, __n1, __str);
  443. this->_M_invalidate_all();
  444. return *this;
  445. }
  446. basic_string&
  447. replace(size_type __pos1, size_type __n1, const basic_string& __str,
  448. size_type __pos2, size_type __n2)
  449. {
  450. _Base::replace(__pos1, __n1, __str, __pos2, __n2);
  451. this->_M_invalidate_all();
  452. return *this;
  453. }
  454. basic_string&
  455. replace(size_type __pos, size_type __n1, const _CharT* __s,
  456. size_type __n2)
  457. {
  458. __glibcxx_check_string_len(__s, __n2);
  459. _Base::replace(__pos, __n1, __s, __n2);
  460. this->_M_invalidate_all();
  461. return *this;
  462. }
  463. basic_string&
  464. replace(size_type __pos, size_type __n1, const _CharT* __s)
  465. {
  466. __glibcxx_check_string(__s);
  467. _Base::replace(__pos, __n1, __s);
  468. this->_M_invalidate_all();
  469. return *this;
  470. }
  471. basic_string&
  472. replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
  473. {
  474. _Base::replace(__pos, __n1, __n2, __c);
  475. this->_M_invalidate_all();
  476. return *this;
  477. }
  478. basic_string&
  479. replace(iterator __i1, iterator __i2, const basic_string& __str)
  480. {
  481. __glibcxx_check_erase_range(__i1, __i2);
  482. _Base::replace(__i1.base(), __i2.base(), __str);
  483. this->_M_invalidate_all();
  484. return *this;
  485. }
  486. basic_string&
  487. replace(iterator __i1, iterator __i2, const _CharT* __s, size_type __n)
  488. {
  489. __glibcxx_check_erase_range(__i1, __i2);
  490. __glibcxx_check_string_len(__s, __n);
  491. _Base::replace(__i1.base(), __i2.base(), __s, __n);
  492. this->_M_invalidate_all();
  493. return *this;
  494. }
  495. basic_string&
  496. replace(iterator __i1, iterator __i2, const _CharT* __s)
  497. {
  498. __glibcxx_check_erase_range(__i1, __i2);
  499. __glibcxx_check_string(__s);
  500. _Base::replace(__i1.base(), __i2.base(), __s);
  501. this->_M_invalidate_all();
  502. return *this;
  503. }
  504. basic_string&
  505. replace(iterator __i1, iterator __i2, size_type __n, _CharT __c)
  506. {
  507. __glibcxx_check_erase_range(__i1, __i2);
  508. _Base::replace(__i1.base(), __i2.base(), __n, __c);
  509. this->_M_invalidate_all();
  510. return *this;
  511. }
  512. template<typename _InputIterator>
  513. basic_string&
  514. replace(iterator __i1, iterator __i2,
  515. _InputIterator __j1, _InputIterator __j2)
  516. {
  517. __glibcxx_check_erase_range(__i1, __i2);
  518. __glibcxx_check_valid_range(__j1, __j2);
  519. _Base::replace(__i1.base(), __i2.base(), __j1, __j2);
  520. this->_M_invalidate_all();
  521. return *this;
  522. }
  523. #ifdef __GXX_EXPERIMENTAL_CXX0X__
  524. basic_string& replace(iterator __i1, iterator __i2,
  525. initializer_list<_CharT> __l)
  526. {
  527. __glibcxx_check_erase_range(__i1, __i2);
  528. _Base::replace(__i1.base(), __i2.base(), __l);
  529. this->_M_invalidate_all();
  530. return *this;
  531. }
  532. #endif // __GXX_EXPERIMENTAL_CXX0X__
  533. size_type
  534. copy(_CharT* __s, size_type __n, size_type __pos = 0) const
  535. {
  536. __glibcxx_check_string_len(__s, __n);
  537. return _Base::copy(__s, __n, __pos);
  538. }
  539. void
  540. swap(basic_string<_CharT,_Traits,_Allocator>& __x)
  541. {
  542. _Base::swap(__x);
  543. this->_M_swap(__x);
  544. this->_M_invalidate_all();
  545. __x._M_invalidate_all();
  546. }
  547. // 21.3.6 string operations:
  548. const _CharT*
  549. c_str() const
  550. {
  551. const _CharT* __res = _Base::c_str();
  552. this->_M_invalidate_all();
  553. return __res;
  554. }
  555. const _CharT*
  556. data() const
  557. {
  558. const _CharT* __res = _Base::data();
  559. this->_M_invalidate_all();
  560. return __res;
  561. }
  562. using _Base::get_allocator;
  563. size_type
  564. find(const basic_string& __str, size_type __pos = 0) const
  565. { return _Base::find(__str, __pos); }
  566. size_type
  567. find(const _CharT* __s, size_type __pos, size_type __n) const
  568. {
  569. __glibcxx_check_string(__s);
  570. return _Base::find(__s, __pos, __n);
  571. }
  572. size_type
  573. find(const _CharT* __s, size_type __pos = 0) const
  574. {
  575. __glibcxx_check_string(__s);
  576. return _Base::find(__s, __pos);
  577. }
  578. size_type
  579. find(_CharT __c, size_type __pos = 0) const
  580. { return _Base::find(__c, __pos); }
  581. size_type
  582. rfind(const basic_string& __str, size_type __pos = _Base::npos) const
  583. { return _Base::rfind(__str, __pos); }
  584. size_type
  585. rfind(const _CharT* __s, size_type __pos, size_type __n) const
  586. {
  587. __glibcxx_check_string_len(__s, __n);
  588. return _Base::rfind(__s, __pos, __n);
  589. }
  590. size_type
  591. rfind(const _CharT* __s, size_type __pos = _Base::npos) const
  592. {
  593. __glibcxx_check_string(__s);
  594. return _Base::rfind(__s, __pos);
  595. }
  596. size_type
  597. rfind(_CharT __c, size_type __pos = _Base::npos) const
  598. { return _Base::rfind(__c, __pos); }
  599. size_type
  600. find_first_of(const basic_string& __str, size_type __pos = 0) const
  601. { return _Base::find_first_of(__str, __pos); }
  602. size_type
  603. find_first_of(const _CharT* __s, size_type __pos, size_type __n) const
  604. {
  605. __glibcxx_check_string(__s);
  606. return _Base::find_first_of(__s, __pos, __n);
  607. }
  608. size_type
  609. find_first_of(const _CharT* __s, size_type __pos = 0) const
  610. {
  611. __glibcxx_check_string(__s);
  612. return _Base::find_first_of(__s, __pos);
  613. }
  614. size_type
  615. find_first_of(_CharT __c, size_type __pos = 0) const
  616. { return _Base::find_first_of(__c, __pos); }
  617. size_type
  618. find_last_of(const basic_string& __str,
  619. size_type __pos = _Base::npos) const
  620. { return _Base::find_last_of(__str, __pos); }
  621. size_type
  622. find_last_of(const _CharT* __s, size_type __pos, size_type __n) const
  623. {
  624. __glibcxx_check_string(__s);
  625. return _Base::find_last_of(__s, __pos, __n);
  626. }
  627. size_type
  628. find_last_of(const _CharT* __s, size_type __pos = _Base::npos) const
  629. {
  630. __glibcxx_check_string(__s);
  631. return _Base::find_last_of(__s, __pos);
  632. }
  633. size_type
  634. find_last_of(_CharT __c, size_type __pos = _Base::npos) const
  635. { return _Base::find_last_of(__c, __pos); }
  636. size_type
  637. find_first_not_of(const basic_string& __str, size_type __pos = 0) const
  638. { return _Base::find_first_not_of(__str, __pos); }
  639. size_type
  640. find_first_not_of(const _CharT* __s, size_type __pos, size_type __n) const
  641. {
  642. __glibcxx_check_string_len(__s, __n);
  643. return _Base::find_first_not_of(__s, __pos, __n);
  644. }
  645. size_type
  646. find_first_not_of(const _CharT* __s, size_type __pos = 0) const
  647. {
  648. __glibcxx_check_string(__s);
  649. return _Base::find_first_not_of(__s, __pos);
  650. }
  651. size_type
  652. find_first_not_of(_CharT __c, size_type __pos = 0) const
  653. { return _Base::find_first_not_of(__c, __pos); }
  654. size_type
  655. find_last_not_of(const basic_string& __str,
  656. size_type __pos = _Base::npos) const
  657. { return _Base::find_last_not_of(__str, __pos); }
  658. size_type
  659. find_last_not_of(const _CharT* __s, size_type __pos, size_type __n) const
  660. {
  661. __glibcxx_check_string(__s);
  662. return _Base::find_last_not_of(__s, __pos, __n);
  663. }
  664. size_type
  665. find_last_not_of(const _CharT* __s, size_type __pos = _Base::npos) const
  666. {
  667. __glibcxx_check_string(__s);
  668. return _Base::find_last_not_of(__s, __pos);
  669. }
  670. size_type
  671. find_last_not_of(_CharT __c, size_type __pos = _Base::npos) const
  672. { return _Base::find_last_not_of(__c, __pos); }
  673. basic_string
  674. substr(size_type __pos = 0, size_type __n = _Base::npos) const
  675. { return basic_string(_Base::substr(__pos, __n)); }
  676. int
  677. compare(const basic_string& __str) const
  678. { return _Base::compare(__str); }
  679. int
  680. compare(size_type __pos1, size_type __n1,
  681. const basic_string& __str) const
  682. { return _Base::compare(__pos1, __n1, __str); }
  683. int
  684. compare(size_type __pos1, size_type __n1, const basic_string& __str,
  685. size_type __pos2, size_type __n2) const
  686. { return _Base::compare(__pos1, __n1, __str, __pos2, __n2); }
  687. int
  688. compare(const _CharT* __s) const
  689. {
  690. __glibcxx_check_string(__s);
  691. return _Base::compare(__s);
  692. }
  693. // _GLIBCXX_RESOLVE_LIB_DEFECTS
  694. // 5. string::compare specification questionable
  695. int
  696. compare(size_type __pos1, size_type __n1, const _CharT* __s) const
  697. {
  698. __glibcxx_check_string(__s);
  699. return _Base::compare(__pos1, __n1, __s);
  700. }
  701. // _GLIBCXX_RESOLVE_LIB_DEFECTS
  702. // 5. string::compare specification questionable
  703. int
  704. compare(size_type __pos1, size_type __n1,const _CharT* __s,
  705. size_type __n2) const
  706. {
  707. __glibcxx_check_string_len(__s, __n2);
  708. return _Base::compare(__pos1, __n1, __s, __n2);
  709. }
  710. _Base&
  711. _M_base() { return *this; }
  712. const _Base&
  713. _M_base() const { return *this; }
  714. using _Safe_base::_M_invalidate_all;
  715. };
  716. template<typename _CharT, typename _Traits, typename _Allocator>
  717. inline basic_string<_CharT,_Traits,_Allocator>
  718. operator+(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
  719. const basic_string<_CharT,_Traits,_Allocator>& __rhs)
  720. { return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs; }
  721. template<typename _CharT, typename _Traits, typename _Allocator>
  722. inline basic_string<_CharT,_Traits,_Allocator>
  723. operator+(const _CharT* __lhs,
  724. const basic_string<_CharT,_Traits,_Allocator>& __rhs)
  725. {
  726. __glibcxx_check_string(__lhs);
  727. return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs;
  728. }
  729. template<typename _CharT, typename _Traits, typename _Allocator>
  730. inline basic_string<_CharT,_Traits,_Allocator>
  731. operator+(_CharT __lhs,
  732. const basic_string<_CharT,_Traits,_Allocator>& __rhs)
  733. { return basic_string<_CharT,_Traits,_Allocator>(1, __lhs) += __rhs; }
  734. template<typename _CharT, typename _Traits, typename _Allocator>
  735. inline basic_string<_CharT,_Traits,_Allocator>
  736. operator+(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
  737. const _CharT* __rhs)
  738. {
  739. __glibcxx_check_string(__rhs);
  740. return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs;
  741. }
  742. template<typename _CharT, typename _Traits, typename _Allocator>
  743. inline basic_string<_CharT,_Traits,_Allocator>
  744. operator+(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
  745. _CharT __rhs)
  746. { return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs; }
  747. template<typename _CharT, typename _Traits, typename _Allocator>
  748. inline bool
  749. operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
  750. const basic_string<_CharT,_Traits,_Allocator>& __rhs)
  751. { return __lhs._M_base() == __rhs._M_base(); }
  752. template<typename _CharT, typename _Traits, typename _Allocator>
  753. inline bool
  754. operator==(const _CharT* __lhs,
  755. const basic_string<_CharT,_Traits,_Allocator>& __rhs)
  756. {
  757. __glibcxx_check_string(__lhs);
  758. return __lhs == __rhs._M_base();
  759. }
  760. template<typename _CharT, typename _Traits, typename _Allocator>
  761. inline bool
  762. operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
  763. const _CharT* __rhs)
  764. {
  765. __glibcxx_check_string(__rhs);
  766. return __lhs._M_base() == __rhs;
  767. }
  768. template<typename _CharT, typename _Traits, typename _Allocator>
  769. inline bool
  770. operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
  771. const basic_string<_CharT,_Traits,_Allocator>& __rhs)
  772. { return __lhs._M_base() != __rhs._M_base(); }
  773. template<typename _CharT, typename _Traits, typename _Allocator>
  774. inline bool
  775. operator!=(const _CharT* __lhs,
  776. const basic_string<_CharT,_Traits,_Allocator>& __rhs)
  777. {
  778. __glibcxx_check_string(__lhs);
  779. return __lhs != __rhs._M_base();
  780. }
  781. template<typename _CharT, typename _Traits, typename _Allocator>
  782. inline bool
  783. operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
  784. const _CharT* __rhs)
  785. {
  786. __glibcxx_check_string(__rhs);
  787. return __lhs._M_base() != __rhs;
  788. }
  789. template<typename _CharT, typename _Traits, typename _Allocator>
  790. inline bool
  791. operator<(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
  792. const basic_string<_CharT,_Traits,_Allocator>& __rhs)
  793. { return __lhs._M_base() < __rhs._M_base(); }
  794. template<typename _CharT, typename _Traits, typename _Allocator>
  795. inline bool
  796. operator<(const _CharT* __lhs,
  797. const basic_string<_CharT,_Traits,_Allocator>& __rhs)
  798. {
  799. __glibcxx_check_string(__lhs);
  800. return __lhs < __rhs._M_base();
  801. }
  802. template<typename _CharT, typename _Traits, typename _Allocator>
  803. inline bool
  804. operator<(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
  805. const _CharT* __rhs)
  806. {
  807. __glibcxx_check_string(__rhs);
  808. return __lhs._M_base() < __rhs;
  809. }
  810. template<typename _CharT, typename _Traits, typename _Allocator>
  811. inline bool
  812. operator<=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
  813. const basic_string<_CharT,_Traits,_Allocator>& __rhs)
  814. { return __lhs._M_base() <= __rhs._M_base(); }
  815. template<typename _CharT, typename _Traits, typename _Allocator>
  816. inline bool
  817. operator<=(const _CharT* __lhs,
  818. const basic_string<_CharT,_Traits,_Allocator>& __rhs)
  819. {
  820. __glibcxx_check_string(__lhs);
  821. return __lhs <= __rhs._M_base();
  822. }
  823. template<typename _CharT, typename _Traits, typename _Allocator>
  824. inline bool
  825. operator<=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
  826. const _CharT* __rhs)
  827. {
  828. __glibcxx_check_string(__rhs);
  829. return __lhs._M_base() <= __rhs;
  830. }
  831. template<typename _CharT, typename _Traits, typename _Allocator>
  832. inline bool
  833. operator>=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
  834. const basic_string<_CharT,_Traits,_Allocator>& __rhs)
  835. { return __lhs._M_base() >= __rhs._M_base(); }
  836. template<typename _CharT, typename _Traits, typename _Allocator>
  837. inline bool
  838. operator>=(const _CharT* __lhs,
  839. const basic_string<_CharT,_Traits,_Allocator>& __rhs)
  840. {
  841. __glibcxx_check_string(__lhs);
  842. return __lhs >= __rhs._M_base();
  843. }
  844. template<typename _CharT, typename _Traits, typename _Allocator>
  845. inline bool
  846. operator>=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
  847. const _CharT* __rhs)
  848. {
  849. __glibcxx_check_string(__rhs);
  850. return __lhs._M_base() >= __rhs;
  851. }
  852. template<typename _CharT, typename _Traits, typename _Allocator>
  853. inline bool
  854. operator>(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
  855. const basic_string<_CharT,_Traits,_Allocator>& __rhs)
  856. { return __lhs._M_base() > __rhs._M_base(); }
  857. template<typename _CharT, typename _Traits, typename _Allocator>
  858. inline bool
  859. operator>(const _CharT* __lhs,
  860. const basic_string<_CharT,_Traits,_Allocator>& __rhs)
  861. {
  862. __glibcxx_check_string(__lhs);
  863. return __lhs > __rhs._M_base();
  864. }
  865. template<typename _CharT, typename _Traits, typename _Allocator>
  866. inline bool
  867. operator>(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
  868. const _CharT* __rhs)
  869. {
  870. __glibcxx_check_string(__rhs);
  871. return __lhs._M_base() > __rhs;
  872. }
  873. // 21.3.7.8:
  874. template<typename _CharT, typename _Traits, typename _Allocator>
  875. inline void
  876. swap(basic_string<_CharT,_Traits,_Allocator>& __lhs,
  877. basic_string<_CharT,_Traits,_Allocator>& __rhs)
  878. { __lhs.swap(__rhs); }
  879. template<typename _CharT, typename _Traits, typename _Allocator>
  880. std::basic_ostream<_CharT, _Traits>&
  881. operator<<(std::basic_ostream<_CharT, _Traits>& __os,
  882. const basic_string<_CharT, _Traits, _Allocator>& __str)
  883. { return __os << __str._M_base(); }
  884. template<typename _CharT, typename _Traits, typename _Allocator>
  885. std::basic_istream<_CharT,_Traits>&
  886. operator>>(std::basic_istream<_CharT,_Traits>& __is,
  887. basic_string<_CharT,_Traits,_Allocator>& __str)
  888. {
  889. std::basic_istream<_CharT,_Traits>& __res = __is >> __str._M_base();
  890. __str._M_invalidate_all();
  891. return __res;
  892. }
  893. template<typename _CharT, typename _Traits, typename _Allocator>
  894. std::basic_istream<_CharT,_Traits>&
  895. getline(std::basic_istream<_CharT,_Traits>& __is,
  896. basic_string<_CharT,_Traits,_Allocator>& __str, _CharT __delim)
  897. {
  898. std::basic_istream<_CharT,_Traits>& __res = getline(__is,
  899. __str._M_base(),
  900. __delim);
  901. __str._M_invalidate_all();
  902. return __res;
  903. }
  904. template<typename _CharT, typename _Traits, typename _Allocator>
  905. std::basic_istream<_CharT,_Traits>&
  906. getline(std::basic_istream<_CharT,_Traits>& __is,
  907. basic_string<_CharT,_Traits,_Allocator>& __str)
  908. {
  909. std::basic_istream<_CharT,_Traits>& __res = getline(__is,
  910. __str._M_base());
  911. __str._M_invalidate_all();
  912. return __res;
  913. }
  914. typedef basic_string<char> string;
  915. #ifdef _GLIBCXX_USE_WCHAR_T
  916. typedef basic_string<wchar_t> wstring;
  917. #endif
  918. } // namespace __gnu_debug
  919. #endif