vstring.h 108 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962
  1. // Versatile string -*- C++ -*-
  2. // Copyright (C) 2005-2023 Free Software Foundation, Inc.
  3. //
  4. // This file is part of the GNU ISO C++ Library. This library is free
  5. // software; you can redistribute it and/or modify it under the
  6. // terms of the GNU General Public License as published by the
  7. // Free Software Foundation; either version 3, or (at your option)
  8. // any later version.
  9. // This library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. // Under Section 7 of GPL version 3, you are granted additional
  14. // permissions described in the GCC Runtime Library Exception, version
  15. // 3.1, as published by the Free Software Foundation.
  16. // You should have received a copy of the GNU General Public License and
  17. // a copy of the GCC Runtime Library Exception along with this program;
  18. // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  19. // <http://www.gnu.org/licenses/>.
  20. /** @file ext/vstring.h
  21. * This file is a GNU extension to the Standard C++ Library.
  22. */
  23. #ifndef _VSTRING_H
  24. #define _VSTRING_H 1
  25. #pragma GCC system_header
  26. #include <bits/requires_hosted.h> // GNU extensions are currently omitted
  27. #if __cplusplus >= 201103L
  28. #include <initializer_list>
  29. #endif
  30. #include <ext/vstring_util.h>
  31. #include <ext/rc_string_base.h>
  32. #include <ext/sso_string_base.h>
  33. #include <bits/stl_algobase.h> // std::min
  34. namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
  35. {
  36. _GLIBCXX_BEGIN_NAMESPACE_VERSION
  37. /**
  38. * @class __versa_string vstring.h
  39. * @brief Template class __versa_string.
  40. * @ingroup extensions
  41. *
  42. * Data structure managing sequences of characters and
  43. * character-like objects.
  44. */
  45. template<typename _CharT, typename _Traits, typename _Alloc,
  46. template <typename, typename, typename> class _Base>
  47. class __versa_string
  48. : private _Base<_CharT, _Traits, _Alloc>
  49. {
  50. typedef _Base<_CharT, _Traits, _Alloc> __vstring_base;
  51. typedef typename __vstring_base::_CharT_alloc_type _CharT_alloc_type;
  52. typedef __alloc_traits<_CharT_alloc_type> _CharT_alloc_traits;
  53. // Types:
  54. public:
  55. typedef _Traits traits_type;
  56. typedef typename _Traits::char_type value_type;
  57. typedef _Alloc allocator_type;
  58. typedef typename _CharT_alloc_type::size_type size_type;
  59. typedef typename _CharT_alloc_type::difference_type difference_type;
  60. typedef value_type& reference;
  61. typedef const value_type& const_reference;
  62. typedef typename _CharT_alloc_traits::pointer pointer;
  63. typedef typename _CharT_alloc_traits::const_pointer const_pointer;
  64. typedef __gnu_cxx::__normal_iterator<pointer, __versa_string> iterator;
  65. typedef __gnu_cxx::__normal_iterator<const_pointer, __versa_string>
  66. const_iterator;
  67. typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
  68. typedef std::reverse_iterator<iterator> reverse_iterator;
  69. // Data Member (public):
  70. /// Value returned by various member functions when they fail.
  71. static const size_type npos = static_cast<size_type>(-1);
  72. private:
  73. size_type
  74. _M_check(size_type __pos, const char* __s) const
  75. {
  76. if (__pos > this->size())
  77. std::__throw_out_of_range_fmt(__N("%s: __pos (which is %zu) > "
  78. "this->size() (which is %zu)"),
  79. __s, __pos, this->size());
  80. return __pos;
  81. }
  82. void
  83. _M_check_length(size_type __n1, size_type __n2, const char* __s) const
  84. {
  85. if (this->max_size() - (this->size() - __n1) < __n2)
  86. std::__throw_length_error(__N(__s));
  87. }
  88. // NB: _M_limit doesn't check for a bad __pos value.
  89. size_type
  90. _M_limit(size_type __pos, size_type __off) const _GLIBCXX_NOEXCEPT
  91. {
  92. const bool __testoff = __off < this->size() - __pos;
  93. return __testoff ? __off : this->size() - __pos;
  94. }
  95. // True if _Rep and source do not overlap.
  96. bool
  97. _M_disjunct(const _CharT* __s) const _GLIBCXX_NOEXCEPT
  98. {
  99. return (std::less<const _CharT*>()(__s, this->_M_data())
  100. || std::less<const _CharT*>()(this->_M_data()
  101. + this->size(), __s));
  102. }
  103. // For the internal use we have functions similar to `begin'/`end'
  104. // but they do not call _M_leak.
  105. iterator
  106. _M_ibegin() const _GLIBCXX_NOEXCEPT
  107. { return iterator(this->_M_data()); }
  108. iterator
  109. _M_iend() const _GLIBCXX_NOEXCEPT
  110. { return iterator(this->_M_data() + this->_M_length()); }
  111. public:
  112. // Construct/copy/destroy:
  113. // NB: We overload ctors in some cases instead of using default
  114. // arguments, per 17.4.4.4 para. 2 item 2.
  115. /**
  116. * @brief Construct an empty string using allocator @a a.
  117. */
  118. explicit
  119. __versa_string(const _Alloc& __a = _Alloc()) _GLIBCXX_NOEXCEPT
  120. : __vstring_base(__a) { }
  121. // NB: per LWG issue 42, semantics different from IS:
  122. /**
  123. * @brief Construct string with copy of value of @a __str.
  124. * @param __str Source string.
  125. */
  126. __versa_string(const __versa_string& __str)
  127. : __vstring_base(__str) { }
  128. #if __cplusplus >= 201103L
  129. /**
  130. * @brief String move constructor.
  131. * @param __str Source string.
  132. *
  133. * The newly-constructed %string contains the exact contents of
  134. * @a __str. The contents of @a __str are a valid, but unspecified
  135. * string.
  136. */
  137. __versa_string(__versa_string&& __str) noexcept
  138. : __vstring_base(std::move(__str)) { }
  139. /**
  140. * @brief Construct string from an initializer list.
  141. * @param __l std::initializer_list of characters.
  142. * @param __a Allocator to use (default is default allocator).
  143. */
  144. __versa_string(std::initializer_list<_CharT> __l,
  145. const _Alloc& __a = _Alloc())
  146. : __vstring_base(__l.begin(), __l.end(), __a) { }
  147. #endif
  148. /**
  149. * @brief Construct string as copy of a substring.
  150. * @param __str Source string.
  151. * @param __pos Index of first character to copy from.
  152. * @param __n Number of characters to copy (default remainder).
  153. */
  154. __versa_string(const __versa_string& __str, size_type __pos,
  155. size_type __n = npos)
  156. : __vstring_base(__str._M_data()
  157. + __str._M_check(__pos,
  158. "__versa_string::__versa_string"),
  159. __str._M_data() + __str._M_limit(__pos, __n)
  160. + __pos, _Alloc()) { }
  161. /**
  162. * @brief Construct string as copy of a substring.
  163. * @param __str Source string.
  164. * @param __pos Index of first character to copy from.
  165. * @param __n Number of characters to copy.
  166. * @param __a Allocator to use.
  167. */
  168. __versa_string(const __versa_string& __str, size_type __pos,
  169. size_type __n, const _Alloc& __a)
  170. : __vstring_base(__str._M_data()
  171. + __str._M_check(__pos,
  172. "__versa_string::__versa_string"),
  173. __str._M_data() + __str._M_limit(__pos, __n)
  174. + __pos, __a) { }
  175. /**
  176. * @brief Construct string initialized by a character array.
  177. * @param __s Source character array.
  178. * @param __n Number of characters to copy.
  179. * @param __a Allocator to use (default is default allocator).
  180. *
  181. * NB: @a __s must have at least @a __n characters, '\\0' has no special
  182. * meaning.
  183. */
  184. __versa_string(const _CharT* __s, size_type __n,
  185. const _Alloc& __a = _Alloc())
  186. : __vstring_base(__s, __s + __n, __a) { }
  187. /**
  188. * @brief Construct string as copy of a C string.
  189. * @param __s Source C string.
  190. * @param __a Allocator to use (default is default allocator).
  191. */
  192. __versa_string(const _CharT* __s, const _Alloc& __a = _Alloc())
  193. : __vstring_base(__s, __s ? __s + traits_type::length(__s) :
  194. __s + npos, __a) { }
  195. /**
  196. * @brief Construct string as multiple characters.
  197. * @param __n Number of characters.
  198. * @param __c Character to use.
  199. * @param __a Allocator to use (default is default allocator).
  200. */
  201. __versa_string(size_type __n, _CharT __c, const _Alloc& __a = _Alloc())
  202. : __vstring_base(__n, __c, __a) { }
  203. /**
  204. * @brief Construct string as copy of a range.
  205. * @param __beg Start of range.
  206. * @param __end End of range.
  207. * @param __a Allocator to use (default is default allocator).
  208. */
  209. #if __cplusplus >= 201103L
  210. template<class _InputIterator,
  211. typename = std::_RequireInputIter<_InputIterator>>
  212. #else
  213. template<class _InputIterator>
  214. #endif
  215. __versa_string(_InputIterator __beg, _InputIterator __end,
  216. const _Alloc& __a = _Alloc())
  217. : __vstring_base(__beg, __end, __a) { }
  218. /**
  219. * @brief Destroy the string instance.
  220. */
  221. ~__versa_string() _GLIBCXX_NOEXCEPT { }
  222. /**
  223. * @brief Assign the value of @a str to this string.
  224. * @param __str Source string.
  225. */
  226. __versa_string&
  227. operator=(const __versa_string& __str)
  228. { return this->assign(__str); }
  229. #if __cplusplus >= 201103L
  230. /**
  231. * @brief String move assignment operator.
  232. * @param __str Source string.
  233. *
  234. * The contents of @a __str are moved into this string (without
  235. * copying). @a __str is a valid, but unspecified string.
  236. */
  237. __versa_string&
  238. operator=(__versa_string&& __str) noexcept
  239. {
  240. // NB: DR 1204.
  241. this->swap(__str);
  242. return *this;
  243. }
  244. /**
  245. * @brief Set value to string constructed from initializer list.
  246. * @param __l std::initializer_list.
  247. */
  248. __versa_string&
  249. operator=(std::initializer_list<_CharT> __l)
  250. {
  251. this->assign(__l.begin(), __l.end());
  252. return *this;
  253. }
  254. #endif
  255. /**
  256. * @brief Copy contents of @a __s into this string.
  257. * @param __s Source null-terminated string.
  258. */
  259. __versa_string&
  260. operator=(const _CharT* __s)
  261. { return this->assign(__s); }
  262. /**
  263. * @brief Set value to string of length 1.
  264. * @param __c Source character.
  265. *
  266. * Assigning to a character makes this string length 1 and
  267. * (*this)[0] == @a __c.
  268. */
  269. __versa_string&
  270. operator=(_CharT __c)
  271. {
  272. this->assign(1, __c);
  273. return *this;
  274. }
  275. // Iterators:
  276. /**
  277. * Returns a read/write iterator that points to the first character in
  278. * the %string. Unshares the string.
  279. */
  280. iterator
  281. begin() _GLIBCXX_NOEXCEPT
  282. {
  283. this->_M_leak();
  284. return iterator(this->_M_data());
  285. }
  286. /**
  287. * Returns a read-only (constant) iterator that points to the first
  288. * character in the %string.
  289. */
  290. const_iterator
  291. begin() const _GLIBCXX_NOEXCEPT
  292. { return const_iterator(this->_M_data()); }
  293. /**
  294. * Returns a read/write iterator that points one past the last
  295. * character in the %string. Unshares the string.
  296. */
  297. iterator
  298. end() _GLIBCXX_NOEXCEPT
  299. {
  300. this->_M_leak();
  301. return iterator(this->_M_data() + this->size());
  302. }
  303. /**
  304. * Returns a read-only (constant) iterator that points one past the
  305. * last character in the %string.
  306. */
  307. const_iterator
  308. end() const _GLIBCXX_NOEXCEPT
  309. { return const_iterator(this->_M_data() + this->size()); }
  310. /**
  311. * Returns a read/write reverse iterator that points to the last
  312. * character in the %string. Iteration is done in reverse element
  313. * order. Unshares the string.
  314. */
  315. reverse_iterator
  316. rbegin() _GLIBCXX_NOEXCEPT
  317. { return reverse_iterator(this->end()); }
  318. /**
  319. * Returns a read-only (constant) reverse iterator that points
  320. * to the last character in the %string. Iteration is done in
  321. * reverse element order.
  322. */
  323. const_reverse_iterator
  324. rbegin() const _GLIBCXX_NOEXCEPT
  325. { return const_reverse_iterator(this->end()); }
  326. /**
  327. * Returns a read/write reverse iterator that points to one before the
  328. * first character in the %string. Iteration is done in reverse
  329. * element order. Unshares the string.
  330. */
  331. reverse_iterator
  332. rend() _GLIBCXX_NOEXCEPT
  333. { return reverse_iterator(this->begin()); }
  334. /**
  335. * Returns a read-only (constant) reverse iterator that points
  336. * to one before the first character in the %string. Iteration
  337. * is done in reverse element order.
  338. */
  339. const_reverse_iterator
  340. rend() const _GLIBCXX_NOEXCEPT
  341. { return const_reverse_iterator(this->begin()); }
  342. #if __cplusplus >= 201103L
  343. /**
  344. * Returns a read-only (constant) iterator that points to the first
  345. * character in the %string.
  346. */
  347. const_iterator
  348. cbegin() const noexcept
  349. { return const_iterator(this->_M_data()); }
  350. /**
  351. * Returns a read-only (constant) iterator that points one past the
  352. * last character in the %string.
  353. */
  354. const_iterator
  355. cend() const noexcept
  356. { return const_iterator(this->_M_data() + this->size()); }
  357. /**
  358. * Returns a read-only (constant) reverse iterator that points
  359. * to the last character in the %string. Iteration is done in
  360. * reverse element order.
  361. */
  362. const_reverse_iterator
  363. crbegin() const noexcept
  364. { return const_reverse_iterator(this->end()); }
  365. /**
  366. * Returns a read-only (constant) reverse iterator that points
  367. * to one before the first character in the %string. Iteration
  368. * is done in reverse element order.
  369. */
  370. const_reverse_iterator
  371. crend() const noexcept
  372. { return const_reverse_iterator(this->begin()); }
  373. #endif
  374. public:
  375. // Capacity:
  376. /// Returns the number of characters in the string, not including any
  377. /// null-termination.
  378. size_type
  379. size() const _GLIBCXX_NOEXCEPT
  380. { return this->_M_length(); }
  381. /// Returns the number of characters in the string, not including any
  382. /// null-termination.
  383. size_type
  384. length() const _GLIBCXX_NOEXCEPT
  385. { return this->_M_length(); }
  386. /// Returns the size() of the largest possible %string.
  387. size_type
  388. max_size() const _GLIBCXX_NOEXCEPT
  389. { return this->_M_max_size(); }
  390. /**
  391. * @brief Resizes the %string to the specified number of characters.
  392. * @param __n Number of characters the %string should contain.
  393. * @param __c Character to fill any new elements.
  394. *
  395. * This function will %resize the %string to the specified
  396. * number of characters. If the number is smaller than the
  397. * %string's current size the %string is truncated, otherwise
  398. * the %string is extended and new elements are set to @a __c.
  399. */
  400. void
  401. resize(size_type __n, _CharT __c);
  402. /**
  403. * @brief Resizes the %string to the specified number of characters.
  404. * @param __n Number of characters the %string should contain.
  405. *
  406. * This function will resize the %string to the specified
  407. * length. If the new size is smaller than the %string's
  408. * current size the %string is truncated, otherwise the %string
  409. * is extended and new characters are default-constructed. For
  410. * basic types such as char, this means setting them to 0.
  411. */
  412. void
  413. resize(size_type __n)
  414. { this->resize(__n, _CharT()); }
  415. #if __cplusplus >= 201103L
  416. /// A non-binding request to reduce capacity() to size().
  417. void
  418. shrink_to_fit() noexcept
  419. {
  420. if (capacity() > size())
  421. {
  422. __try
  423. { this->reserve(0); }
  424. __catch(...)
  425. { }
  426. }
  427. }
  428. #endif
  429. /**
  430. * Returns the total number of characters that the %string can
  431. * hold before needing to allocate more memory.
  432. */
  433. size_type
  434. capacity() const _GLIBCXX_NOEXCEPT
  435. { return this->_M_capacity(); }
  436. /**
  437. * @brief Attempt to preallocate enough memory for specified number of
  438. * characters.
  439. * @param __res_arg Number of characters required.
  440. * @throw std::length_error If @a __res_arg exceeds @c max_size().
  441. *
  442. * This function attempts to reserve enough memory for the
  443. * %string to hold the specified number of characters. If the
  444. * number requested is more than max_size(), length_error is
  445. * thrown.
  446. *
  447. * The advantage of this function is that if optimal code is a
  448. * necessity and the user can determine the string length that
  449. * will be required, the user can reserve the memory in
  450. * %advance, and thus prevent a possible reallocation of memory
  451. * and copying of %string data.
  452. */
  453. void
  454. reserve(size_type __res_arg = 0)
  455. { this->_M_reserve(__res_arg); }
  456. /**
  457. * Erases the string, making it empty.
  458. */
  459. void
  460. clear() _GLIBCXX_NOEXCEPT
  461. { this->_M_clear(); }
  462. /**
  463. * Returns true if the %string is empty. Equivalent to
  464. * <code>*this == ""</code>.
  465. */
  466. _GLIBCXX_NODISCARD bool
  467. empty() const _GLIBCXX_NOEXCEPT
  468. { return this->size() == 0; }
  469. // Element access:
  470. /**
  471. * @brief Subscript access to the data contained in the %string.
  472. * @param __pos The index of the character to access.
  473. * @return Read-only (constant) reference to the character.
  474. *
  475. * This operator allows for easy, array-style, data access.
  476. * Note that data access with this operator is unchecked and
  477. * out_of_range lookups are not defined. (For checked lookups
  478. * see at().)
  479. */
  480. const_reference
  481. operator[] (size_type __pos) const _GLIBCXX_NOEXCEPT
  482. {
  483. __glibcxx_assert(__pos <= this->size());
  484. return this->_M_data()[__pos];
  485. }
  486. /**
  487. * @brief Subscript access to the data contained in the %string.
  488. * @param __pos The index of the character to access.
  489. * @return Read/write reference to the character.
  490. *
  491. * This operator allows for easy, array-style, data access.
  492. * Note that data access with this operator is unchecked and
  493. * out_of_range lookups are not defined. (For checked lookups
  494. * see at().) Unshares the string.
  495. */
  496. reference
  497. operator[](size_type __pos) _GLIBCXX_NOEXCEPT
  498. {
  499. // Allow pos == size() both in C++98 mode, as v3 extension,
  500. // and in C++11 mode.
  501. __glibcxx_assert(__pos <= this->size());
  502. // In pedantic mode be strict in C++98 mode.
  503. _GLIBCXX_DEBUG_PEDASSERT(__cplusplus >= 201103L
  504. || __pos < this->size());
  505. this->_M_leak();
  506. return this->_M_data()[__pos];
  507. }
  508. /**
  509. * @brief Provides access to the data contained in the %string.
  510. * @param __n The index of the character to access.
  511. * @return Read-only (const) reference to the character.
  512. * @throw std::out_of_range If @a __n is an invalid index.
  513. *
  514. * This function provides for safer data access. The parameter
  515. * is first checked that it is in the range of the string. The
  516. * function throws out_of_range if the check fails.
  517. */
  518. const_reference
  519. at(size_type __n) const
  520. {
  521. if (__n >= this->size())
  522. std::__throw_out_of_range_fmt(__N("__versa_string::at: __n "
  523. "(which is %zu) >= this->size() "
  524. "(which is %zu)"),
  525. __n, this->size());
  526. return this->_M_data()[__n];
  527. }
  528. /**
  529. * @brief Provides access to the data contained in the %string.
  530. * @param __n The index of the character to access.
  531. * @return Read/write reference to the character.
  532. * @throw std::out_of_range If @a __n is an invalid index.
  533. *
  534. * This function provides for safer data access. The parameter
  535. * is first checked that it is in the range of the string. The
  536. * function throws out_of_range if the check fails. Success
  537. * results in unsharing the string.
  538. */
  539. reference
  540. at(size_type __n)
  541. {
  542. if (__n >= this->size())
  543. std::__throw_out_of_range_fmt(__N("__versa_string::at: __n "
  544. "(which is %zu) >= this->size() "
  545. "(which is %zu)"),
  546. __n, this->size());
  547. this->_M_leak();
  548. return this->_M_data()[__n];
  549. }
  550. #if __cplusplus >= 201103L
  551. /**
  552. * Returns a read/write reference to the data at the first
  553. * element of the %string.
  554. */
  555. reference
  556. front() noexcept
  557. { return operator[](0); }
  558. /**
  559. * Returns a read-only (constant) reference to the data at the first
  560. * element of the %string.
  561. */
  562. const_reference
  563. front() const noexcept
  564. { return operator[](0); }
  565. /**
  566. * Returns a read/write reference to the data at the last
  567. * element of the %string.
  568. */
  569. reference
  570. back() noexcept
  571. { return operator[](this->size() - 1); }
  572. /**
  573. * Returns a read-only (constant) reference to the data at the
  574. * last element of the %string.
  575. */
  576. const_reference
  577. back() const noexcept
  578. { return operator[](this->size() - 1); }
  579. #endif
  580. // Modifiers:
  581. /**
  582. * @brief Append a string to this string.
  583. * @param __str The string to append.
  584. * @return Reference to this string.
  585. */
  586. __versa_string&
  587. operator+=(const __versa_string& __str)
  588. { return this->append(__str); }
  589. /**
  590. * @brief Append a C string.
  591. * @param __s The C string to append.
  592. * @return Reference to this string.
  593. */
  594. __versa_string&
  595. operator+=(const _CharT* __s)
  596. { return this->append(__s); }
  597. /**
  598. * @brief Append a character.
  599. * @param __c The character to append.
  600. * @return Reference to this string.
  601. */
  602. __versa_string&
  603. operator+=(_CharT __c)
  604. {
  605. this->push_back(__c);
  606. return *this;
  607. }
  608. #if __cplusplus >= 201103L
  609. /**
  610. * @brief Append an initializer_list of characters.
  611. * @param __l The initializer_list of characters to be appended.
  612. * @return Reference to this string.
  613. */
  614. __versa_string&
  615. operator+=(std::initializer_list<_CharT> __l)
  616. { return this->append(__l.begin(), __l.end()); }
  617. #endif // C++11
  618. /**
  619. * @brief Append a string to this string.
  620. * @param __str The string to append.
  621. * @return Reference to this string.
  622. */
  623. __versa_string&
  624. append(const __versa_string& __str)
  625. { return _M_append(__str._M_data(), __str.size()); }
  626. /**
  627. * @brief Append a substring.
  628. * @param __str The string to append.
  629. * @param __pos Index of the first character of str to append.
  630. * @param __n The number of characters to append.
  631. * @return Reference to this string.
  632. * @throw std::out_of_range if @a pos is not a valid index.
  633. *
  634. * This function appends @a __n characters from @a __str
  635. * starting at @a __pos to this string. If @a __n is is larger
  636. * than the number of available characters in @a __str, the
  637. * remainder of @a __str is appended.
  638. */
  639. __versa_string&
  640. append(const __versa_string& __str, size_type __pos, size_type __n)
  641. { return _M_append(__str._M_data()
  642. + __str._M_check(__pos, "__versa_string::append"),
  643. __str._M_limit(__pos, __n)); }
  644. /**
  645. * @brief Append a C substring.
  646. * @param __s The C string to append.
  647. * @param __n The number of characters to append.
  648. * @return Reference to this string.
  649. */
  650. __versa_string&
  651. append(const _CharT* __s, size_type __n)
  652. {
  653. __glibcxx_requires_string_len(__s, __n);
  654. _M_check_length(size_type(0), __n, "__versa_string::append");
  655. return _M_append(__s, __n);
  656. }
  657. /**
  658. * @brief Append a C string.
  659. * @param __s The C string to append.
  660. * @return Reference to this string.
  661. */
  662. __versa_string&
  663. append(const _CharT* __s)
  664. {
  665. __glibcxx_requires_string(__s);
  666. const size_type __n = traits_type::length(__s);
  667. _M_check_length(size_type(0), __n, "__versa_string::append");
  668. return _M_append(__s, __n);
  669. }
  670. /**
  671. * @brief Append multiple characters.
  672. * @param __n The number of characters to append.
  673. * @param __c The character to use.
  674. * @return Reference to this string.
  675. *
  676. * Appends n copies of c to this string.
  677. */
  678. __versa_string&
  679. append(size_type __n, _CharT __c)
  680. { return _M_replace_aux(this->size(), size_type(0), __n, __c); }
  681. #if __cplusplus >= 201103L
  682. /**
  683. * @brief Append an initializer_list of characters.
  684. * @param __l The initializer_list of characters to append.
  685. * @return Reference to this string.
  686. */
  687. __versa_string&
  688. append(std::initializer_list<_CharT> __l)
  689. { return this->append(__l.begin(), __l.end()); }
  690. #endif // C++11
  691. /**
  692. * @brief Append a range of characters.
  693. * @param __first Iterator referencing the first character to append.
  694. * @param __last Iterator marking the end of the range.
  695. * @return Reference to this string.
  696. *
  697. * Appends characters in the range [first,last) to this string.
  698. */
  699. #if __cplusplus >= 201103L
  700. template<class _InputIterator,
  701. typename = std::_RequireInputIter<_InputIterator>>
  702. #else
  703. template<class _InputIterator>
  704. #endif
  705. __versa_string&
  706. append(_InputIterator __first, _InputIterator __last)
  707. { return this->replace(_M_iend(), _M_iend(), __first, __last); }
  708. /**
  709. * @brief Append a single character.
  710. * @param __c Character to append.
  711. */
  712. void
  713. push_back(_CharT __c)
  714. {
  715. const size_type __size = this->size();
  716. if (__size + 1 > this->capacity() || this->_M_is_shared())
  717. this->_M_mutate(__size, size_type(0), 0, size_type(1));
  718. traits_type::assign(this->_M_data()[__size], __c);
  719. this->_M_set_length(__size + 1);
  720. }
  721. /**
  722. * @brief Set value to contents of another string.
  723. * @param __str Source string to use.
  724. * @return Reference to this string.
  725. */
  726. __versa_string&
  727. assign(const __versa_string& __str)
  728. {
  729. this->_M_assign(__str);
  730. return *this;
  731. }
  732. #if __cplusplus >= 201103L
  733. /**
  734. * @brief Set value to contents of another string.
  735. * @param __str Source string to use.
  736. * @return Reference to this string.
  737. *
  738. * This function sets this string to the exact contents of @a __str.
  739. * @a __str is a valid, but unspecified string.
  740. */
  741. __versa_string&
  742. assign(__versa_string&& __str) noexcept
  743. {
  744. this->swap(__str);
  745. return *this;
  746. }
  747. #endif // C++11
  748. /**
  749. * @brief Set value to a substring of a string.
  750. * @param __str The string to use.
  751. * @param __pos Index of the first character of str.
  752. * @param __n Number of characters to use.
  753. * @return Reference to this string.
  754. * @throw std::out_of_range if @a __pos is not a valid index.
  755. *
  756. * This function sets this string to the substring of @a __str
  757. * consisting of @a __n characters at @a __pos. If @a __n is
  758. * is larger than the number of available characters in @a
  759. * __str, the remainder of @a __str is used.
  760. */
  761. __versa_string&
  762. assign(const __versa_string& __str, size_type __pos, size_type __n)
  763. { return _M_replace(size_type(0), this->size(), __str._M_data()
  764. + __str._M_check(__pos, "__versa_string::assign"),
  765. __str._M_limit(__pos, __n)); }
  766. /**
  767. * @brief Set value to a C substring.
  768. * @param __s The C string to use.
  769. * @param __n Number of characters to use.
  770. * @return Reference to this string.
  771. *
  772. * This function sets the value of this string to the first @a
  773. * __n characters of @a __s. If @a __n is is larger than the
  774. * number of available characters in @a __s, the remainder of
  775. * @a __s is used.
  776. */
  777. __versa_string&
  778. assign(const _CharT* __s, size_type __n)
  779. {
  780. __glibcxx_requires_string_len(__s, __n);
  781. return _M_replace(size_type(0), this->size(), __s, __n);
  782. }
  783. /**
  784. * @brief Set value to contents of a C string.
  785. * @param __s The C string to use.
  786. * @return Reference to this string.
  787. *
  788. * This function sets the value of this string to the value of
  789. * @a __s. The data is copied, so there is no dependence on @a
  790. * __s once the function returns.
  791. */
  792. __versa_string&
  793. assign(const _CharT* __s)
  794. {
  795. __glibcxx_requires_string(__s);
  796. return _M_replace(size_type(0), this->size(), __s,
  797. traits_type::length(__s));
  798. }
  799. /**
  800. * @brief Set value to multiple characters.
  801. * @param __n Length of the resulting string.
  802. * @param __c The character to use.
  803. * @return Reference to this string.
  804. *
  805. * This function sets the value of this string to @a __n copies of
  806. * character @a __c.
  807. */
  808. __versa_string&
  809. assign(size_type __n, _CharT __c)
  810. { return _M_replace_aux(size_type(0), this->size(), __n, __c); }
  811. /**
  812. * @brief Set value to a range of characters.
  813. * @param __first Iterator referencing the first character to append.
  814. * @param __last Iterator marking the end of the range.
  815. * @return Reference to this string.
  816. *
  817. * Sets value of string to characters in the range
  818. * [first,last).
  819. */
  820. #if __cplusplus >= 201103L
  821. template<class _InputIterator,
  822. typename = std::_RequireInputIter<_InputIterator>>
  823. #else
  824. template<class _InputIterator>
  825. #endif
  826. __versa_string&
  827. assign(_InputIterator __first, _InputIterator __last)
  828. { return this->replace(_M_ibegin(), _M_iend(), __first, __last); }
  829. #if __cplusplus >= 201103L
  830. /**
  831. * @brief Set value to an initializer_list of characters.
  832. * @param __l The initializer_list of characters to assign.
  833. * @return Reference to this string.
  834. */
  835. __versa_string&
  836. assign(std::initializer_list<_CharT> __l)
  837. { return this->assign(__l.begin(), __l.end()); }
  838. #endif // C++11
  839. #if __cplusplus >= 201103L
  840. /**
  841. * @brief Insert multiple characters.
  842. * @param __p Const_iterator referencing location in string to
  843. * insert at.
  844. * @param __n Number of characters to insert
  845. * @param __c The character to insert.
  846. * @return Iterator referencing the first inserted char.
  847. * @throw std::length_error If new length exceeds @c max_size().
  848. *
  849. * Inserts @a __n copies of character @a __c starting at the
  850. * position referenced by iterator @a __p. If adding
  851. * characters causes the length to exceed max_size(),
  852. * length_error is thrown. The value of the string doesn't
  853. * change if an error is thrown.
  854. */
  855. iterator
  856. insert(const_iterator __p, size_type __n, _CharT __c)
  857. {
  858. _GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend());
  859. const size_type __pos = __p - _M_ibegin();
  860. this->replace(__p, __p, __n, __c);
  861. return iterator(this->_M_data() + __pos);
  862. }
  863. #else
  864. /**
  865. * @brief Insert multiple characters.
  866. * @param __p Iterator referencing location in string to insert at.
  867. * @param __n Number of characters to insert
  868. * @param __c The character to insert.
  869. * @throw std::length_error If new length exceeds @c max_size().
  870. *
  871. * Inserts @a __n copies of character @a __c starting at the
  872. * position referenced by iterator @a __p. If adding
  873. * characters causes the length to exceed max_size(),
  874. * length_error is thrown. The value of the string doesn't
  875. * change if an error is thrown.
  876. */
  877. void
  878. insert(iterator __p, size_type __n, _CharT __c)
  879. { this->replace(__p, __p, __n, __c); }
  880. #endif
  881. #if __cplusplus >= 201103L
  882. /**
  883. * @brief Insert a range of characters.
  884. * @param __p Const_iterator referencing location in string to
  885. * insert at.
  886. * @param __beg Start of range.
  887. * @param __end End of range.
  888. * @return Iterator referencing the first inserted char.
  889. * @throw std::length_error If new length exceeds @c max_size().
  890. *
  891. * Inserts characters in range [beg,end). If adding characters
  892. * causes the length to exceed max_size(), length_error is
  893. * thrown. The value of the string doesn't change if an error
  894. * is thrown.
  895. */
  896. template<class _InputIterator,
  897. typename = std::_RequireInputIter<_InputIterator>>
  898. iterator
  899. insert(const_iterator __p, _InputIterator __beg, _InputIterator __end)
  900. {
  901. _GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend());
  902. const size_type __pos = __p - _M_ibegin();
  903. this->replace(__p, __p, __beg, __end);
  904. return iterator(this->_M_data() + __pos);
  905. }
  906. #else
  907. /**
  908. * @brief Insert a range of characters.
  909. * @param __p Iterator referencing location in string to insert at.
  910. * @param __beg Start of range.
  911. * @param __end End of range.
  912. * @throw std::length_error If new length exceeds @c max_size().
  913. *
  914. * Inserts characters in range [beg,end). If adding characters
  915. * causes the length to exceed max_size(), length_error is
  916. * thrown. The value of the string doesn't change if an error
  917. * is thrown.
  918. */
  919. template<class _InputIterator>
  920. void
  921. insert(iterator __p, _InputIterator __beg, _InputIterator __end)
  922. { this->replace(__p, __p, __beg, __end); }
  923. #endif
  924. #if __cplusplus >= 201103L
  925. /**
  926. * @brief Insert an initializer_list of characters.
  927. * @param __p Const_iterator referencing location in string to
  928. * insert at.
  929. * @param __l The initializer_list of characters to insert.
  930. * @return Iterator referencing the first inserted char.
  931. * @throw std::length_error If new length exceeds @c max_size().
  932. */
  933. iterator
  934. insert(const_iterator __p, std::initializer_list<_CharT> __l)
  935. { return this->insert(__p, __l.begin(), __l.end()); }
  936. #endif // C++11
  937. /**
  938. * @brief Insert value of a string.
  939. * @param __pos1 Iterator referencing location in string to insert at.
  940. * @param __str The string to insert.
  941. * @return Reference to this string.
  942. * @throw std::length_error If new length exceeds @c max_size().
  943. *
  944. * Inserts value of @a __str starting at @a __pos1. If adding
  945. * characters causes the length to exceed max_size(),
  946. * length_error is thrown. The value of the string doesn't
  947. * change if an error is thrown.
  948. */
  949. __versa_string&
  950. insert(size_type __pos1, const __versa_string& __str)
  951. { return this->replace(__pos1, size_type(0),
  952. __str._M_data(), __str.size()); }
  953. /**
  954. * @brief Insert a substring.
  955. * @param __pos1 Iterator referencing location in string to insert at.
  956. * @param __str The string to insert.
  957. * @param __pos2 Start of characters in str to insert.
  958. * @param __n Number of characters to insert.
  959. * @return Reference to this string.
  960. * @throw std::length_error If new length exceeds @c max_size().
  961. * @throw std::out_of_range If @a __pos1 > size() or
  962. * @a __pos2 > @a __str.size().
  963. *
  964. * Starting at @a __pos1, insert @a __n character of @a __str
  965. * beginning with @a __pos2. If adding characters causes the
  966. * length to exceed max_size(), length_error is thrown. If @a
  967. * __pos1 is beyond the end of this string or @a __pos2 is
  968. * beyond the end of @a __str, out_of_range is thrown. The
  969. * value of the string doesn't change if an error is thrown.
  970. */
  971. __versa_string&
  972. insert(size_type __pos1, const __versa_string& __str,
  973. size_type __pos2, size_type __n)
  974. { return this->replace(__pos1, size_type(0), __str._M_data()
  975. + __str._M_check(__pos2, "__versa_string::insert"),
  976. __str._M_limit(__pos2, __n)); }
  977. /**
  978. * @brief Insert a C substring.
  979. * @param __pos Iterator referencing location in string to insert at.
  980. * @param __s The C string to insert.
  981. * @param __n The number of characters to insert.
  982. * @return Reference to this string.
  983. * @throw std::length_error If new length exceeds @c max_size().
  984. * @throw std::out_of_range If @a __pos is beyond the end of this
  985. * string.
  986. *
  987. * Inserts the first @a __n characters of @a __s starting at @a
  988. * __pos. If adding characters causes the length to exceed
  989. * max_size(), length_error is thrown. If @a __pos is beyond
  990. * end(), out_of_range is thrown. The value of the string
  991. * doesn't change if an error is thrown.
  992. */
  993. __versa_string&
  994. insert(size_type __pos, const _CharT* __s, size_type __n)
  995. { return this->replace(__pos, size_type(0), __s, __n); }
  996. /**
  997. * @brief Insert a C string.
  998. * @param __pos Iterator referencing location in string to insert at.
  999. * @param __s The C string to insert.
  1000. * @return Reference to this string.
  1001. * @throw std::length_error If new length exceeds @c max_size().
  1002. * @throw std::out_of_range If @a __pos is beyond the end of this
  1003. * string.
  1004. *
  1005. * Inserts the first @a __n characters of @a __s starting at @a
  1006. * __pos. If adding characters causes the length to exceed
  1007. * max_size(), length_error is thrown. If @a __pos is beyond
  1008. * end(), out_of_range is thrown. The value of the string
  1009. * doesn't change if an error is thrown.
  1010. */
  1011. __versa_string&
  1012. insert(size_type __pos, const _CharT* __s)
  1013. {
  1014. __glibcxx_requires_string(__s);
  1015. return this->replace(__pos, size_type(0), __s,
  1016. traits_type::length(__s));
  1017. }
  1018. /**
  1019. * @brief Insert multiple characters.
  1020. * @param __pos Index in string to insert at.
  1021. * @param __n Number of characters to insert
  1022. * @param __c The character to insert.
  1023. * @return Reference to this string.
  1024. * @throw std::length_error If new length exceeds @c max_size().
  1025. * @throw std::out_of_range If @a __pos is beyond the end of this
  1026. * string.
  1027. *
  1028. * Inserts @a __n copies of character @a __c starting at index
  1029. * @a __pos. If adding characters causes the length to exceed
  1030. * max_size(), length_error is thrown. If @a __pos > length(),
  1031. * out_of_range is thrown. The value of the string doesn't
  1032. * change if an error is thrown.
  1033. */
  1034. __versa_string&
  1035. insert(size_type __pos, size_type __n, _CharT __c)
  1036. { return _M_replace_aux(_M_check(__pos, "__versa_string::insert"),
  1037. size_type(0), __n, __c); }
  1038. /**
  1039. * @brief Insert one character.
  1040. * @param __p Iterator referencing position in string to insert at.
  1041. * @param __c The character to insert.
  1042. * @return Iterator referencing newly inserted char.
  1043. * @throw std::length_error If new length exceeds @c max_size().
  1044. *
  1045. * Inserts character @a __c at position referenced by @a __p.
  1046. * If adding character causes the length to exceed max_size(),
  1047. * length_error is thrown. If @a __p is beyond end of string,
  1048. * out_of_range is thrown. The value of the string doesn't
  1049. * change if an error is thrown.
  1050. */
  1051. iterator
  1052. #if __cplusplus >= 201103L
  1053. insert(const_iterator __p, _CharT __c)
  1054. #else
  1055. insert(iterator __p, _CharT __c)
  1056. #endif
  1057. {
  1058. _GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend());
  1059. const size_type __pos = __p - _M_ibegin();
  1060. _M_replace_aux(__pos, size_type(0), size_type(1), __c);
  1061. this->_M_set_leaked();
  1062. return iterator(this->_M_data() + __pos);
  1063. }
  1064. /**
  1065. * @brief Remove characters.
  1066. * @param __pos Index of first character to remove (default 0).
  1067. * @param __n Number of characters to remove (default remainder).
  1068. * @return Reference to this string.
  1069. * @throw std::out_of_range If @a __pos is beyond the end of this
  1070. * string.
  1071. *
  1072. * Removes @a __n characters from this string starting at @a
  1073. * __pos. The length of the string is reduced by @a __n. If
  1074. * there are < @a __n characters to remove, the remainder of
  1075. * the string is truncated. If @a __p is beyond end of string,
  1076. * out_of_range is thrown. The value of the string doesn't
  1077. * change if an error is thrown.
  1078. */
  1079. __versa_string&
  1080. erase(size_type __pos = 0, size_type __n = npos)
  1081. {
  1082. this->_M_erase(_M_check(__pos, "__versa_string::erase"),
  1083. _M_limit(__pos, __n));
  1084. return *this;
  1085. }
  1086. /**
  1087. * @brief Remove one character.
  1088. * @param __position Iterator referencing the character to remove.
  1089. * @return iterator referencing same location after removal.
  1090. *
  1091. * Removes the character at @a __position from this string. The
  1092. * value of the string doesn't change if an error is thrown.
  1093. */
  1094. iterator
  1095. #if __cplusplus >= 201103L
  1096. erase(const_iterator __position)
  1097. #else
  1098. erase(iterator __position)
  1099. #endif
  1100. {
  1101. _GLIBCXX_DEBUG_PEDASSERT(__position >= _M_ibegin()
  1102. && __position < _M_iend());
  1103. const size_type __pos = __position - _M_ibegin();
  1104. this->_M_erase(__pos, size_type(1));
  1105. this->_M_set_leaked();
  1106. return iterator(this->_M_data() + __pos);
  1107. }
  1108. /**
  1109. * @brief Remove a range of characters.
  1110. * @param __first Iterator referencing the first character to remove.
  1111. * @param __last Iterator referencing the end of the range.
  1112. * @return Iterator referencing location of first after removal.
  1113. *
  1114. * Removes the characters in the range [first,last) from this
  1115. * string. The value of the string doesn't change if an error
  1116. * is thrown.
  1117. */
  1118. iterator
  1119. #if __cplusplus >= 201103L
  1120. erase(const_iterator __first, const_iterator __last)
  1121. #else
  1122. erase(iterator __first, iterator __last)
  1123. #endif
  1124. {
  1125. _GLIBCXX_DEBUG_PEDASSERT(__first >= _M_ibegin() && __first <= __last
  1126. && __last <= _M_iend());
  1127. const size_type __pos = __first - _M_ibegin();
  1128. this->_M_erase(__pos, __last - __first);
  1129. this->_M_set_leaked();
  1130. return iterator(this->_M_data() + __pos);
  1131. }
  1132. #if __cplusplus >= 201103L
  1133. /**
  1134. * @brief Remove the last character.
  1135. *
  1136. * The string must be non-empty.
  1137. */
  1138. void
  1139. pop_back()
  1140. { this->_M_erase(size()-1, 1); }
  1141. #endif // C++11
  1142. /**
  1143. * @brief Replace characters with value from another string.
  1144. * @param __pos Index of first character to replace.
  1145. * @param __n Number of characters to be replaced.
  1146. * @param __str String to insert.
  1147. * @return Reference to this string.
  1148. * @throw std::out_of_range If @a __pos is beyond the end of this
  1149. * string.
  1150. * @throw std::length_error If new length exceeds @c max_size().
  1151. *
  1152. * Removes the characters in the range [pos,pos+n) from this
  1153. * string. In place, the value of @a __str is inserted. If @a
  1154. * __pos is beyond end of string, out_of_range is thrown. If
  1155. * the length of the result exceeds max_size(), length_error is
  1156. * thrown. The value of the string doesn't change if an error
  1157. * is thrown.
  1158. */
  1159. __versa_string&
  1160. replace(size_type __pos, size_type __n, const __versa_string& __str)
  1161. { return this->replace(__pos, __n, __str._M_data(), __str.size()); }
  1162. /**
  1163. * @brief Replace characters with value from another string.
  1164. * @param __pos1 Index of first character to replace.
  1165. * @param __n1 Number of characters to be replaced.
  1166. * @param __str String to insert.
  1167. * @param __pos2 Index of first character of str to use.
  1168. * @param __n2 Number of characters from str to use.
  1169. * @return Reference to this string.
  1170. * @throw std::out_of_range If @a __pos1 > size() or @a __pos2 >
  1171. * str.size().
  1172. * @throw std::length_error If new length exceeds @c max_size().
  1173. *
  1174. * Removes the characters in the range [pos1,pos1 + n) from
  1175. * this string. In place, the value of @a __str is inserted.
  1176. * If @a __pos is beyond end of string, out_of_range is thrown.
  1177. * If the length of the result exceeds max_size(), length_error
  1178. * is thrown. The value of the string doesn't change if an
  1179. * error is thrown.
  1180. */
  1181. __versa_string&
  1182. replace(size_type __pos1, size_type __n1, const __versa_string& __str,
  1183. size_type __pos2, size_type __n2)
  1184. {
  1185. return this->replace(__pos1, __n1, __str._M_data()
  1186. + __str._M_check(__pos2,
  1187. "__versa_string::replace"),
  1188. __str._M_limit(__pos2, __n2));
  1189. }
  1190. /**
  1191. * @brief Replace characters with value of a C substring.
  1192. * @param __pos Index of first character to replace.
  1193. * @param __n1 Number of characters to be replaced.
  1194. * @param __s C string to insert.
  1195. * @param __n2 Number of characters from @a __s to use.
  1196. * @return Reference to this string.
  1197. * @throw std::out_of_range If @a __pos1 > size().
  1198. * @throw std::length_error If new length exceeds @c max_size().
  1199. *
  1200. * Removes the characters in the range [pos,pos + n1) from this
  1201. * string. In place, the first @a __n2 characters of @a __s
  1202. * are inserted, or all of @a __s if @a __n2 is too large. If
  1203. * @a __pos is beyond end of string, out_of_range is thrown.
  1204. * If the length of result exceeds max_size(), length_error is
  1205. * thrown. The value of the string doesn't change if an error
  1206. * is thrown.
  1207. */
  1208. __versa_string&
  1209. replace(size_type __pos, size_type __n1, const _CharT* __s,
  1210. size_type __n2)
  1211. {
  1212. __glibcxx_requires_string_len(__s, __n2);
  1213. return _M_replace(_M_check(__pos, "__versa_string::replace"),
  1214. _M_limit(__pos, __n1), __s, __n2);
  1215. }
  1216. /**
  1217. * @brief Replace characters with value of a C string.
  1218. * @param __pos Index of first character to replace.
  1219. * @param __n1 Number of characters to be replaced.
  1220. * @param __s C string to insert.
  1221. * @return Reference to this string.
  1222. * @throw std::out_of_range If @a __pos > size().
  1223. * @throw std::length_error If new length exceeds @c max_size().
  1224. *
  1225. * Removes the characters in the range [pos,pos + n1) from this
  1226. * string. In place, the characters of @a __s are inserted. If
  1227. * @a pos is beyond end of string, out_of_range is thrown. If
  1228. * the length of result exceeds max_size(), length_error is thrown.
  1229. * The value of the string doesn't change if an error is thrown.
  1230. */
  1231. __versa_string&
  1232. replace(size_type __pos, size_type __n1, const _CharT* __s)
  1233. {
  1234. __glibcxx_requires_string(__s);
  1235. return this->replace(__pos, __n1, __s, traits_type::length(__s));
  1236. }
  1237. /**
  1238. * @brief Replace characters with multiple characters.
  1239. * @param __pos Index of first character to replace.
  1240. * @param __n1 Number of characters to be replaced.
  1241. * @param __n2 Number of characters to insert.
  1242. * @param __c Character to insert.
  1243. * @return Reference to this string.
  1244. * @throw std::out_of_range If @a __pos > size().
  1245. * @throw std::length_error If new length exceeds @c max_size().
  1246. *
  1247. * Removes the characters in the range [pos,pos + n1) from this
  1248. * string. In place, @a __n2 copies of @a __c are inserted.
  1249. * If @a __pos is beyond end of string, out_of_range is thrown.
  1250. * If the length of result exceeds max_size(), length_error is
  1251. * thrown. The value of the string doesn't change if an error
  1252. * is thrown.
  1253. */
  1254. __versa_string&
  1255. replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
  1256. { return _M_replace_aux(_M_check(__pos, "__versa_string::replace"),
  1257. _M_limit(__pos, __n1), __n2, __c); }
  1258. /**
  1259. * @brief Replace range of characters with string.
  1260. * @param __i1 Iterator referencing start of range to replace.
  1261. * @param __i2 Iterator referencing end of range to replace.
  1262. * @param __str String value to insert.
  1263. * @return Reference to this string.
  1264. * @throw std::length_error If new length exceeds @c max_size().
  1265. *
  1266. * Removes the characters in the range [i1,i2). In place, the
  1267. * value of @a __str is inserted. If the length of result
  1268. * exceeds max_size(), length_error is thrown. The value of
  1269. * the string doesn't change if an error is thrown.
  1270. */
  1271. __versa_string&
  1272. #if __cplusplus >= 201103L
  1273. replace(const_iterator __i1, const_iterator __i2,
  1274. const __versa_string& __str)
  1275. #else
  1276. replace(iterator __i1, iterator __i2, const __versa_string& __str)
  1277. #endif
  1278. { return this->replace(__i1, __i2, __str._M_data(), __str.size()); }
  1279. /**
  1280. * @brief Replace range of characters with C substring.
  1281. * @param __i1 Iterator referencing start of range to replace.
  1282. * @param __i2 Iterator referencing end of range to replace.
  1283. * @param __s C string value to insert.
  1284. * @param __n Number of characters from s to insert.
  1285. * @return Reference to this string.
  1286. * @throw std::length_error If new length exceeds @c max_size().
  1287. *
  1288. * Removes the characters in the range [i1,i2). In place, the
  1289. * first @a n characters of @a __s are inserted. If the length
  1290. * of result exceeds max_size(), length_error is thrown. The
  1291. * value of the string doesn't change if an error is thrown.
  1292. */
  1293. __versa_string&
  1294. #if __cplusplus >= 201103L
  1295. replace(const_iterator __i1, const_iterator __i2,
  1296. const _CharT* __s, size_type __n)
  1297. #else
  1298. replace(iterator __i1, iterator __i2, const _CharT* __s, size_type __n)
  1299. #endif
  1300. {
  1301. _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
  1302. && __i2 <= _M_iend());
  1303. return this->replace(__i1 - _M_ibegin(), __i2 - __i1, __s, __n);
  1304. }
  1305. /**
  1306. * @brief Replace range of characters with C string.
  1307. * @param __i1 Iterator referencing start of range to replace.
  1308. * @param __i2 Iterator referencing end of range to replace.
  1309. * @param __s C string value to insert.
  1310. * @return Reference to this string.
  1311. * @throw std::length_error If new length exceeds @c max_size().
  1312. *
  1313. * Removes the characters in the range [i1,i2). In place, the
  1314. * characters of @a __s are inserted. If the length of result
  1315. * exceeds max_size(), length_error is thrown. The value of
  1316. * the string doesn't change if an error is thrown.
  1317. */
  1318. __versa_string&
  1319. #if __cplusplus >= 201103L
  1320. replace(const_iterator __i1, const_iterator __i2, const _CharT* __s)
  1321. #else
  1322. replace(iterator __i1, iterator __i2, const _CharT* __s)
  1323. #endif
  1324. {
  1325. __glibcxx_requires_string(__s);
  1326. return this->replace(__i1, __i2, __s, traits_type::length(__s));
  1327. }
  1328. /**
  1329. * @brief Replace range of characters with multiple characters
  1330. * @param __i1 Iterator referencing start of range to replace.
  1331. * @param __i2 Iterator referencing end of range to replace.
  1332. * @param __n Number of characters to insert.
  1333. * @param __c Character to insert.
  1334. * @return Reference to this string.
  1335. * @throw std::length_error If new length exceeds @c max_size().
  1336. *
  1337. * Removes the characters in the range [i1,i2). In place, @a
  1338. * __n copies of @a __c are inserted. If the length of result
  1339. * exceeds max_size(), length_error is thrown. The value of
  1340. * the string doesn't change if an error is thrown.
  1341. */
  1342. __versa_string&
  1343. #if __cplusplus >= 201103L
  1344. replace(const_iterator __i1, const_iterator __i2, size_type __n,
  1345. _CharT __c)
  1346. #else
  1347. replace(iterator __i1, iterator __i2, size_type __n, _CharT __c)
  1348. #endif
  1349. {
  1350. _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
  1351. && __i2 <= _M_iend());
  1352. return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __c);
  1353. }
  1354. /**
  1355. * @brief Replace range of characters with range.
  1356. * @param __i1 Iterator referencing start of range to replace.
  1357. * @param __i2 Iterator referencing end of range to replace.
  1358. * @param __k1 Iterator referencing start of range to insert.
  1359. * @param __k2 Iterator referencing end of range to insert.
  1360. * @return Reference to this string.
  1361. * @throw std::length_error If new length exceeds @c max_size().
  1362. *
  1363. * Removes the characters in the range [i1,i2). In place,
  1364. * characters in the range [k1,k2) are inserted. If the length
  1365. * of result exceeds max_size(), length_error is thrown. The
  1366. * value of the string doesn't change if an error is thrown.
  1367. */
  1368. #if __cplusplus >= 201103L
  1369. template<class _InputIterator,
  1370. typename = std::_RequireInputIter<_InputIterator>>
  1371. __versa_string&
  1372. replace(const_iterator __i1, const_iterator __i2,
  1373. _InputIterator __k1, _InputIterator __k2)
  1374. {
  1375. _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
  1376. && __i2 <= _M_iend());
  1377. __glibcxx_requires_valid_range(__k1, __k2);
  1378. return this->_M_replace_dispatch(__i1, __i2, __k1, __k2,
  1379. std::__false_type());
  1380. }
  1381. #else
  1382. template<class _InputIterator>
  1383. __versa_string&
  1384. replace(iterator __i1, iterator __i2,
  1385. _InputIterator __k1, _InputIterator __k2)
  1386. {
  1387. _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
  1388. && __i2 <= _M_iend());
  1389. __glibcxx_requires_valid_range(__k1, __k2);
  1390. typedef typename std::__is_integer<_InputIterator>::__type _Integral;
  1391. return this->_M_replace_dispatch(__i1, __i2, __k1, __k2, _Integral());
  1392. }
  1393. #endif
  1394. // Specializations for the common case of pointer and iterator:
  1395. // useful to avoid the overhead of temporary buffering in _M_replace.
  1396. __versa_string&
  1397. #if __cplusplus >= 201103L
  1398. replace(const_iterator __i1, const_iterator __i2,
  1399. _CharT* __k1, _CharT* __k2)
  1400. #else
  1401. replace(iterator __i1, iterator __i2,
  1402. _CharT* __k1, _CharT* __k2)
  1403. #endif
  1404. {
  1405. _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
  1406. && __i2 <= _M_iend());
  1407. __glibcxx_requires_valid_range(__k1, __k2);
  1408. return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
  1409. __k1, __k2 - __k1);
  1410. }
  1411. __versa_string&
  1412. #if __cplusplus >= 201103L
  1413. replace(const_iterator __i1, const_iterator __i2,
  1414. const _CharT* __k1, const _CharT* __k2)
  1415. #else
  1416. replace(iterator __i1, iterator __i2,
  1417. const _CharT* __k1, const _CharT* __k2)
  1418. #endif
  1419. {
  1420. _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
  1421. && __i2 <= _M_iend());
  1422. __glibcxx_requires_valid_range(__k1, __k2);
  1423. return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
  1424. __k1, __k2 - __k1);
  1425. }
  1426. __versa_string&
  1427. #if __cplusplus >= 201103L
  1428. replace(const_iterator __i1, const_iterator __i2,
  1429. iterator __k1, iterator __k2)
  1430. #else
  1431. replace(iterator __i1, iterator __i2,
  1432. iterator __k1, iterator __k2)
  1433. #endif
  1434. {
  1435. _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
  1436. && __i2 <= _M_iend());
  1437. __glibcxx_requires_valid_range(__k1, __k2);
  1438. return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
  1439. __k1.base(), __k2 - __k1);
  1440. }
  1441. __versa_string&
  1442. #if __cplusplus >= 201103L
  1443. replace(const_iterator __i1, const_iterator __i2,
  1444. const_iterator __k1, const_iterator __k2)
  1445. #else
  1446. replace(iterator __i1, iterator __i2,
  1447. const_iterator __k1, const_iterator __k2)
  1448. #endif
  1449. {
  1450. _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
  1451. && __i2 <= _M_iend());
  1452. __glibcxx_requires_valid_range(__k1, __k2);
  1453. return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
  1454. __k1.base(), __k2 - __k1);
  1455. }
  1456. #if __cplusplus >= 201103L
  1457. /**
  1458. * @brief Replace range of characters with initializer_list.
  1459. * @param __i1 Iterator referencing start of range to replace.
  1460. * @param __i2 Iterator referencing end of range to replace.
  1461. * @param __l The initializer_list of characters to insert.
  1462. * @return Reference to this string.
  1463. * @throw std::length_error If new length exceeds @c max_size().
  1464. *
  1465. * Removes the characters in the range [i1,i2). In place,
  1466. * characters in the range [k1,k2) are inserted. If the length
  1467. * of result exceeds max_size(), length_error is thrown. The
  1468. * value of the string doesn't change if an error is thrown.
  1469. */
  1470. __versa_string&
  1471. replace(const_iterator __i1, const_iterator __i2,
  1472. std::initializer_list<_CharT> __l)
  1473. { return this->replace(__i1, __i2, __l.begin(), __l.end()); }
  1474. #endif // C++11
  1475. private:
  1476. template<class _Integer>
  1477. __versa_string&
  1478. _M_replace_dispatch(const_iterator __i1, const_iterator __i2,
  1479. _Integer __n, _Integer __val, std::__true_type)
  1480. { return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __val); }
  1481. template<class _InputIterator>
  1482. __versa_string&
  1483. _M_replace_dispatch(const_iterator __i1, const_iterator __i2,
  1484. _InputIterator __k1, _InputIterator __k2,
  1485. std::__false_type);
  1486. __versa_string&
  1487. _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2,
  1488. _CharT __c);
  1489. __versa_string&
  1490. _M_replace(size_type __pos, size_type __len1, const _CharT* __s,
  1491. const size_type __len2);
  1492. __versa_string&
  1493. _M_append(const _CharT* __s, size_type __n);
  1494. public:
  1495. /**
  1496. * @brief Copy substring into C string.
  1497. * @param __s C string to copy value into.
  1498. * @param __n Number of characters to copy.
  1499. * @param __pos Index of first character to copy.
  1500. * @return Number of characters actually copied
  1501. * @throw std::out_of_range If pos > size().
  1502. *
  1503. * Copies up to @a __n characters starting at @a __pos into the
  1504. * C string @a s. If @a __pos is greater than size(),
  1505. * out_of_range is thrown.
  1506. */
  1507. size_type
  1508. copy(_CharT* __s, size_type __n, size_type __pos = 0) const;
  1509. /**
  1510. * @brief Swap contents with another string.
  1511. * @param __s String to swap with.
  1512. *
  1513. * Exchanges the contents of this string with that of @a __s in
  1514. * constant time.
  1515. */
  1516. void
  1517. swap(__versa_string& __s) _GLIBCXX_NOEXCEPT
  1518. { this->_M_swap(__s); }
  1519. // String operations:
  1520. /**
  1521. * @brief Return const pointer to null-terminated contents.
  1522. *
  1523. * This is a handle to internal data. Do not modify or dire things may
  1524. * happen.
  1525. */
  1526. const _CharT*
  1527. c_str() const _GLIBCXX_NOEXCEPT
  1528. { return this->_M_data(); }
  1529. /**
  1530. * @brief Return const pointer to contents.
  1531. *
  1532. * This is a handle to internal data. Do not modify or dire things may
  1533. * happen.
  1534. */
  1535. const _CharT*
  1536. data() const _GLIBCXX_NOEXCEPT
  1537. { return this->_M_data(); }
  1538. /**
  1539. * @brief Return copy of allocator used to construct this string.
  1540. */
  1541. allocator_type
  1542. get_allocator() const _GLIBCXX_NOEXCEPT
  1543. { return allocator_type(this->_M_get_allocator()); }
  1544. /**
  1545. * @brief Find position of a C substring.
  1546. * @param __s C string to locate.
  1547. * @param __pos Index of character to search from.
  1548. * @param __n Number of characters from @a __s to search for.
  1549. * @return Index of start of first occurrence.
  1550. *
  1551. * Starting from @a __pos, searches forward for the first @a
  1552. * __n characters in @a __s within this string. If found,
  1553. * returns the index where it begins. If not found, returns
  1554. * npos.
  1555. */
  1556. size_type
  1557. find(const _CharT* __s, size_type __pos, size_type __n) const;
  1558. /**
  1559. * @brief Find position of a string.
  1560. * @param __str String to locate.
  1561. * @param __pos Index of character to search from (default 0).
  1562. * @return Index of start of first occurrence.
  1563. *
  1564. * Starting from @a __pos, searches forward for value of @a
  1565. * __str within this string. If found, returns the index where
  1566. * it begins. If not found, returns npos.
  1567. */
  1568. size_type
  1569. find(const __versa_string& __str, size_type __pos = 0) const
  1570. _GLIBCXX_NOEXCEPT
  1571. { return this->find(__str.data(), __pos, __str.size()); }
  1572. /**
  1573. * @brief Find position of a C string.
  1574. * @param __s C string to locate.
  1575. * @param __pos Index of character to search from (default 0).
  1576. * @return Index of start of first occurrence.
  1577. *
  1578. * Starting from @a __pos, searches forward for the value of @a
  1579. * __s within this string. If found, returns the index where
  1580. * it begins. If not found, returns npos.
  1581. */
  1582. size_type
  1583. find(const _CharT* __s, size_type __pos = 0) const
  1584. {
  1585. __glibcxx_requires_string(__s);
  1586. return this->find(__s, __pos, traits_type::length(__s));
  1587. }
  1588. /**
  1589. * @brief Find position of a character.
  1590. * @param __c Character to locate.
  1591. * @param __pos Index of character to search from (default 0).
  1592. * @return Index of first occurrence.
  1593. *
  1594. * Starting from @a __pos, searches forward for @a __c within
  1595. * this string. If found, returns the index where it was
  1596. * found. If not found, returns npos.
  1597. */
  1598. size_type
  1599. find(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT;
  1600. /**
  1601. * @brief Find last position of a string.
  1602. * @param __str String to locate.
  1603. * @param __pos Index of character to search back from (default end).
  1604. * @return Index of start of last occurrence.
  1605. *
  1606. * Starting from @a __pos, searches backward for value of @a
  1607. * __str within this string. If found, returns the index where
  1608. * it begins. If not found, returns npos.
  1609. */
  1610. size_type
  1611. rfind(const __versa_string& __str, size_type __pos = npos) const
  1612. _GLIBCXX_NOEXCEPT
  1613. { return this->rfind(__str.data(), __pos, __str.size()); }
  1614. /**
  1615. * @brief Find last position of a C substring.
  1616. * @param __s C string to locate.
  1617. * @param __pos Index of character to search back from.
  1618. * @param __n Number of characters from s to search for.
  1619. * @return Index of start of last occurrence.
  1620. *
  1621. * Starting from @a __pos, searches backward for the first @a
  1622. * __n characters in @a __s within this string. If found,
  1623. * returns the index where it begins. If not found, returns
  1624. * npos.
  1625. */
  1626. size_type
  1627. rfind(const _CharT* __s, size_type __pos, size_type __n) const;
  1628. /**
  1629. * @brief Find last position of a C string.
  1630. * @param __s C string to locate.
  1631. * @param __pos Index of character to start search at (default end).
  1632. * @return Index of start of last occurrence.
  1633. *
  1634. * Starting from @a __pos, searches backward for the value of
  1635. * @a __s within this string. If found, returns the index
  1636. * where it begins. If not found, returns npos.
  1637. */
  1638. size_type
  1639. rfind(const _CharT* __s, size_type __pos = npos) const
  1640. {
  1641. __glibcxx_requires_string(__s);
  1642. return this->rfind(__s, __pos, traits_type::length(__s));
  1643. }
  1644. /**
  1645. * @brief Find last position of a character.
  1646. * @param __c Character to locate.
  1647. * @param __pos Index of character to search back from (default end).
  1648. * @return Index of last occurrence.
  1649. *
  1650. * Starting from @a __pos, searches backward for @a __c within
  1651. * this string. If found, returns the index where it was
  1652. * found. If not found, returns npos.
  1653. */
  1654. size_type
  1655. rfind(_CharT __c, size_type __pos = npos) const _GLIBCXX_NOEXCEPT;
  1656. /**
  1657. * @brief Find position of a character of string.
  1658. * @param __str String containing characters to locate.
  1659. * @param __pos Index of character to search from (default 0).
  1660. * @return Index of first occurrence.
  1661. *
  1662. * Starting from @a __pos, searches forward for one of the characters of
  1663. * @a __str within this string. If found, returns the index where it was
  1664. * found. If not found, returns npos.
  1665. */
  1666. size_type
  1667. find_first_of(const __versa_string& __str, size_type __pos = 0) const
  1668. _GLIBCXX_NOEXCEPT
  1669. { return this->find_first_of(__str.data(), __pos, __str.size()); }
  1670. /**
  1671. * @brief Find position of a character of C substring.
  1672. * @param __s String containing characters to locate.
  1673. * @param __pos Index of character to search from.
  1674. * @param __n Number of characters from s to search for.
  1675. * @return Index of first occurrence.
  1676. *
  1677. * Starting from @a __pos, searches forward for one of the
  1678. * first @a __n characters of @a __s within this string. If
  1679. * found, returns the index where it was found. If not found,
  1680. * returns npos.
  1681. */
  1682. size_type
  1683. find_first_of(const _CharT* __s, size_type __pos, size_type __n) const;
  1684. /**
  1685. * @brief Find position of a character of C string.
  1686. * @param __s String containing characters to locate.
  1687. * @param __pos Index of character to search from (default 0).
  1688. * @return Index of first occurrence.
  1689. *
  1690. * Starting from @a __pos, searches forward for one of the
  1691. * characters of @a __s within this string. If found, returns
  1692. * the index where it was found. If not found, returns npos.
  1693. */
  1694. size_type
  1695. find_first_of(const _CharT* __s, size_type __pos = 0) const
  1696. {
  1697. __glibcxx_requires_string(__s);
  1698. return this->find_first_of(__s, __pos, traits_type::length(__s));
  1699. }
  1700. /**
  1701. * @brief Find position of a character.
  1702. * @param __c Character to locate.
  1703. * @param __pos Index of character to search from (default 0).
  1704. * @return Index of first occurrence.
  1705. *
  1706. * Starting from @a __pos, searches forward for the character
  1707. * @a __c within this string. If found, returns the index
  1708. * where it was found. If not found, returns npos.
  1709. *
  1710. * Note: equivalent to find(c, pos).
  1711. */
  1712. size_type
  1713. find_first_of(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT
  1714. { return this->find(__c, __pos); }
  1715. /**
  1716. * @brief Find last position of a character of string.
  1717. * @param __str String containing characters to locate.
  1718. * @param __pos Index of character to search back from (default end).
  1719. * @return Index of last occurrence.
  1720. *
  1721. * Starting from @a __pos, searches backward for one of the
  1722. * characters of @a __str within this string. If found,
  1723. * returns the index where it was found. If not found, returns
  1724. * npos.
  1725. */
  1726. size_type
  1727. find_last_of(const __versa_string& __str, size_type __pos = npos) const
  1728. _GLIBCXX_NOEXCEPT
  1729. { return this->find_last_of(__str.data(), __pos, __str.size()); }
  1730. /**
  1731. * @brief Find last position of a character of C substring.
  1732. * @param __s C string containing characters to locate.
  1733. * @param __pos Index of character to search back from.
  1734. * @param __n Number of characters from s to search for.
  1735. * @return Index of last occurrence.
  1736. *
  1737. * Starting from @a __pos, searches backward for one of the
  1738. * first @a __n characters of @a __s within this string. If
  1739. * found, returns the index where it was found. If not found,
  1740. * returns npos.
  1741. */
  1742. size_type
  1743. find_last_of(const _CharT* __s, size_type __pos, size_type __n) const;
  1744. /**
  1745. * @brief Find last position of a character of C string.
  1746. * @param __s C string containing characters to locate.
  1747. * @param __pos Index of character to search back from (default end).
  1748. * @return Index of last occurrence.
  1749. *
  1750. * Starting from @a __pos, searches backward for one of the
  1751. * characters of @a __s within this string. If found, returns
  1752. * the index where it was found. If not found, returns npos.
  1753. */
  1754. size_type
  1755. find_last_of(const _CharT* __s, size_type __pos = npos) const
  1756. {
  1757. __glibcxx_requires_string(__s);
  1758. return this->find_last_of(__s, __pos, traits_type::length(__s));
  1759. }
  1760. /**
  1761. * @brief Find last position of a character.
  1762. * @param __c Character to locate.
  1763. * @param __pos Index of character to search back from (default end).
  1764. * @return Index of last occurrence.
  1765. *
  1766. * Starting from @a __pos, searches backward for @a __c within
  1767. * this string. If found, returns the index where it was
  1768. * found. If not found, returns npos.
  1769. *
  1770. * Note: equivalent to rfind(c, pos).
  1771. */
  1772. size_type
  1773. find_last_of(_CharT __c, size_type __pos = npos) const _GLIBCXX_NOEXCEPT
  1774. { return this->rfind(__c, __pos); }
  1775. /**
  1776. * @brief Find position of a character not in string.
  1777. * @param __str String containing characters to avoid.
  1778. * @param __pos Index of character to search from (default 0).
  1779. * @return Index of first occurrence.
  1780. *
  1781. * Starting from @a __pos, searches forward for a character not
  1782. * contained in @a __str within this string. If found, returns
  1783. * the index where it was found. If not found, returns npos.
  1784. */
  1785. size_type
  1786. find_first_not_of(const __versa_string& __str, size_type __pos = 0) const
  1787. _GLIBCXX_NOEXCEPT
  1788. { return this->find_first_not_of(__str.data(), __pos, __str.size()); }
  1789. /**
  1790. * @brief Find position of a character not in C substring.
  1791. * @param __s C string containing characters to avoid.
  1792. * @param __pos Index of character to search from.
  1793. * @param __n Number of characters from s to consider.
  1794. * @return Index of first occurrence.
  1795. *
  1796. * Starting from @a __pos, searches forward for a character not
  1797. * contained in the first @a __n characters of @a __s within
  1798. * this string. If found, returns the index where it was
  1799. * found. If not found, returns npos.
  1800. */
  1801. size_type
  1802. find_first_not_of(const _CharT* __s, size_type __pos,
  1803. size_type __n) const;
  1804. /**
  1805. * @brief Find position of a character not in C string.
  1806. * @param __s C string containing characters to avoid.
  1807. * @param __pos Index of character to search from (default 0).
  1808. * @return Index of first occurrence.
  1809. *
  1810. * Starting from @a __pos, searches forward for a character not
  1811. * contained in @a __s within this string. If found, returns
  1812. * the index where it was found. If not found, returns npos.
  1813. */
  1814. size_type
  1815. find_first_not_of(const _CharT* __s, size_type __pos = 0) const
  1816. {
  1817. __glibcxx_requires_string(__s);
  1818. return this->find_first_not_of(__s, __pos, traits_type::length(__s));
  1819. }
  1820. /**
  1821. * @brief Find position of a different character.
  1822. * @param __c Character to avoid.
  1823. * @param __pos Index of character to search from (default 0).
  1824. * @return Index of first occurrence.
  1825. *
  1826. * Starting from @a __pos, searches forward for a character
  1827. * other than @a __c within this string. If found, returns the
  1828. * index where it was found. If not found, returns npos.
  1829. */
  1830. size_type
  1831. find_first_not_of(_CharT __c, size_type __pos = 0) const
  1832. _GLIBCXX_NOEXCEPT;
  1833. /**
  1834. * @brief Find last position of a character not in string.
  1835. * @param __str String containing characters to avoid.
  1836. * @param __pos Index of character to search back from (default end).
  1837. * @return Index of last occurrence.
  1838. *
  1839. * Starting from @a __pos, searches backward for a character
  1840. * not contained in @a __str within this string. If found,
  1841. * returns the index where it was found. If not found, returns
  1842. * npos.
  1843. */
  1844. size_type
  1845. find_last_not_of(const __versa_string& __str,
  1846. size_type __pos = npos) const _GLIBCXX_NOEXCEPT
  1847. { return this->find_last_not_of(__str.data(), __pos, __str.size()); }
  1848. /**
  1849. * @brief Find last position of a character not in C substring.
  1850. * @param __s C string containing characters to avoid.
  1851. * @param __pos Index of character to search back from.
  1852. * @param __n Number of characters from s to consider.
  1853. * @return Index of last occurrence.
  1854. *
  1855. * Starting from @a __pos, searches backward for a character
  1856. * not contained in the first @a __n characters of @a __s
  1857. * within this string. If found, returns the index where it
  1858. * was found. If not found, returns npos.
  1859. */
  1860. size_type
  1861. find_last_not_of(const _CharT* __s, size_type __pos,
  1862. size_type __n) const;
  1863. /**
  1864. * @brief Find last position of a character not in C string.
  1865. * @param __s C string containing characters to avoid.
  1866. * @param __pos Index of character to search back from (default end).
  1867. * @return Index of last occurrence.
  1868. *
  1869. * Starting from @a __pos, searches backward for a character
  1870. * not contained in @a __s within this string. If found,
  1871. * returns the index where it was found. If not found, returns
  1872. * npos.
  1873. */
  1874. size_type
  1875. find_last_not_of(const _CharT* __s, size_type __pos = npos) const
  1876. {
  1877. __glibcxx_requires_string(__s);
  1878. return this->find_last_not_of(__s, __pos, traits_type::length(__s));
  1879. }
  1880. /**
  1881. * @brief Find last position of a different character.
  1882. * @param __c Character to avoid.
  1883. * @param __pos Index of character to search back from (default end).
  1884. * @return Index of last occurrence.
  1885. *
  1886. * Starting from @a __pos, searches backward for a character
  1887. * other than @a __c within this string. If found, returns the
  1888. * index where it was found. If not found, returns npos.
  1889. */
  1890. size_type
  1891. find_last_not_of(_CharT __c, size_type __pos = npos) const
  1892. _GLIBCXX_NOEXCEPT;
  1893. /**
  1894. * @brief Get a substring.
  1895. * @param __pos Index of first character (default 0).
  1896. * @param __n Number of characters in substring (default remainder).
  1897. * @return The new string.
  1898. * @throw std::out_of_range If pos > size().
  1899. *
  1900. * Construct and return a new string using the @a __n
  1901. * characters starting at @a __pos. If the string is too
  1902. * short, use the remainder of the characters. If @a __pos is
  1903. * beyond the end of the string, out_of_range is thrown.
  1904. */
  1905. __versa_string
  1906. substr(size_type __pos = 0, size_type __n = npos) const
  1907. {
  1908. return __versa_string(*this, _M_check(__pos, "__versa_string::substr"),
  1909. __n);
  1910. }
  1911. /**
  1912. * @brief Compare to a string.
  1913. * @param __str String to compare against.
  1914. * @return Integer < 0, 0, or > 0.
  1915. *
  1916. * Returns an integer < 0 if this string is ordered before @a
  1917. * __str, 0 if their values are equivalent, or > 0 if this
  1918. * string is ordered after @a __str. Determines the effective
  1919. * length rlen of the strings to compare as the smallest of
  1920. * size() and str.size(). The function then compares the two
  1921. * strings by calling traits::compare(data(), str.data(),rlen).
  1922. * If the result of the comparison is nonzero returns it,
  1923. * otherwise the shorter one is ordered first.
  1924. */
  1925. int
  1926. compare(const __versa_string& __str) const
  1927. {
  1928. if (this->_M_compare(__str))
  1929. return 0;
  1930. const size_type __size = this->size();
  1931. const size_type __osize = __str.size();
  1932. const size_type __len = std::min(__size, __osize);
  1933. int __r = traits_type::compare(this->_M_data(), __str.data(), __len);
  1934. if (!__r)
  1935. __r = this->_S_compare(__size, __osize);
  1936. return __r;
  1937. }
  1938. /**
  1939. * @brief Compare substring to a string.
  1940. * @param __pos Index of first character of substring.
  1941. * @param __n Number of characters in substring.
  1942. * @param __str String to compare against.
  1943. * @return Integer < 0, 0, or > 0.
  1944. *
  1945. * Form the substring of this string from the @a __n characters
  1946. * starting at @a __pos. Returns an integer < 0 if the
  1947. * substring is ordered before @a __str, 0 if their values are
  1948. * equivalent, or > 0 if the substring is ordered after @a
  1949. * __str. Determines the effective length rlen of the strings
  1950. * to compare as the smallest of the length of the substring
  1951. * and @a __str.size(). The function then compares the two
  1952. * strings by calling
  1953. * traits::compare(substring.data(),str.data(),rlen). If the
  1954. * result of the comparison is nonzero returns it, otherwise
  1955. * the shorter one is ordered first.
  1956. */
  1957. int
  1958. compare(size_type __pos, size_type __n,
  1959. const __versa_string& __str) const;
  1960. /**
  1961. * @brief Compare substring to a substring.
  1962. * @param __pos1 Index of first character of substring.
  1963. * @param __n1 Number of characters in substring.
  1964. * @param __str String to compare against.
  1965. * @param __pos2 Index of first character of substring of str.
  1966. * @param __n2 Number of characters in substring of str.
  1967. * @return Integer < 0, 0, or > 0.
  1968. *
  1969. * Form the substring of this string from the @a __n1
  1970. * characters starting at @a __pos1. Form the substring of @a
  1971. * __str from the @a __n2 characters starting at @a __pos2.
  1972. * Returns an integer < 0 if this substring is ordered before
  1973. * the substring of @a __str, 0 if their values are equivalent,
  1974. * or > 0 if this substring is ordered after the substring of
  1975. * @a __str. Determines the effective length rlen of the
  1976. * strings to compare as the smallest of the lengths of the
  1977. * substrings. The function then compares the two strings by
  1978. * calling
  1979. * traits::compare(substring.data(),str.substr(pos2,n2).data(),rlen).
  1980. * If the result of the comparison is nonzero returns it,
  1981. * otherwise the shorter one is ordered first.
  1982. */
  1983. int
  1984. compare(size_type __pos1, size_type __n1, const __versa_string& __str,
  1985. size_type __pos2, size_type __n2) const;
  1986. /**
  1987. * @brief Compare to a C string.
  1988. * @param __s C string to compare against.
  1989. * @return Integer < 0, 0, or > 0.
  1990. *
  1991. * Returns an integer < 0 if this string is ordered before @a
  1992. * __s, 0 if their values are equivalent, or > 0 if this string
  1993. * is ordered after @a __s. Determines the effective length
  1994. * rlen of the strings to compare as the smallest of size() and
  1995. * the length of a string constructed from @a __s. The
  1996. * function then compares the two strings by calling
  1997. * traits::compare(data(),s,rlen). If the result of the
  1998. * comparison is nonzero returns it, otherwise the shorter one
  1999. * is ordered first.
  2000. */
  2001. int
  2002. compare(const _CharT* __s) const;
  2003. // _GLIBCXX_RESOLVE_LIB_DEFECTS
  2004. // 5 String::compare specification questionable
  2005. /**
  2006. * @brief Compare substring to a C string.
  2007. * @param __pos Index of first character of substring.
  2008. * @param __n1 Number of characters in substring.
  2009. * @param __s C string to compare against.
  2010. * @return Integer < 0, 0, or > 0.
  2011. *
  2012. * Form the substring of this string from the @a __n1
  2013. * characters starting at @a __pos. Returns an integer < 0 if
  2014. * the substring is ordered before @a __s, 0 if their values
  2015. * are equivalent, or > 0 if the substring is ordered after @a
  2016. * __s. Determines the effective length rlen of the strings to
  2017. * compare as the smallest of the length of the substring and
  2018. * the length of a string constructed from @a __s. The
  2019. * function then compares the two string by calling
  2020. * traits::compare(substring.data(),s,rlen). If the result of
  2021. * the comparison is nonzero returns it, otherwise the shorter
  2022. * one is ordered first.
  2023. */
  2024. int
  2025. compare(size_type __pos, size_type __n1, const _CharT* __s) const;
  2026. /**
  2027. * @brief Compare substring against a character array.
  2028. * @param __pos Index of first character of substring.
  2029. * @param __n1 Number of characters in substring.
  2030. * @param __s character array to compare against.
  2031. * @param __n2 Number of characters of s.
  2032. * @return Integer < 0, 0, or > 0.
  2033. *
  2034. * Form the substring of this string from the @a __n1
  2035. * characters starting at @a __pos. Form a string from the
  2036. * first @a __n2 characters of @a __s. Returns an integer < 0
  2037. * if this substring is ordered before the string from @a __s,
  2038. * 0 if their values are equivalent, or > 0 if this substring
  2039. * is ordered after the string from @a __s. Determines the
  2040. * effective length rlen of the strings to compare as the
  2041. * smallest of the length of the substring and @a __n2. The
  2042. * function then compares the two strings by calling
  2043. * traits::compare(substring.data(),__s,rlen). If the result of
  2044. * the comparison is nonzero returns it, otherwise the shorter
  2045. * one is ordered first.
  2046. *
  2047. * NB: __s must have at least n2 characters, <em>\\0</em> has no special
  2048. * meaning.
  2049. */
  2050. int
  2051. compare(size_type __pos, size_type __n1, const _CharT* __s,
  2052. size_type __n2) const;
  2053. };
  2054. // operator+
  2055. /**
  2056. * @brief Concatenate two strings.
  2057. * @param __lhs First string.
  2058. * @param __rhs Last string.
  2059. * @return New string with value of @a __lhs followed by @a __rhs.
  2060. */
  2061. template<typename _CharT, typename _Traits, typename _Alloc,
  2062. template <typename, typename, typename> class _Base>
  2063. __versa_string<_CharT, _Traits, _Alloc, _Base>
  2064. operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
  2065. const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs);
  2066. /**
  2067. * @brief Concatenate C string and string.
  2068. * @param __lhs First string.
  2069. * @param __rhs Last string.
  2070. * @return New string with value of @a __lhs followed by @a __rhs.
  2071. */
  2072. template<typename _CharT, typename _Traits, typename _Alloc,
  2073. template <typename, typename, typename> class _Base>
  2074. __versa_string<_CharT, _Traits, _Alloc, _Base>
  2075. operator+(const _CharT* __lhs,
  2076. const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs);
  2077. /**
  2078. * @brief Concatenate character and string.
  2079. * @param __lhs First string.
  2080. * @param __rhs Last string.
  2081. * @return New string with @a __lhs followed by @a __rhs.
  2082. */
  2083. template<typename _CharT, typename _Traits, typename _Alloc,
  2084. template <typename, typename, typename> class _Base>
  2085. __versa_string<_CharT, _Traits, _Alloc, _Base>
  2086. operator+(_CharT __lhs,
  2087. const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs);
  2088. /**
  2089. * @brief Concatenate string and C string.
  2090. * @param __lhs First string.
  2091. * @param __rhs Last string.
  2092. * @return New string with @a __lhs followed by @a __rhs.
  2093. */
  2094. template<typename _CharT, typename _Traits, typename _Alloc,
  2095. template <typename, typename, typename> class _Base>
  2096. __versa_string<_CharT, _Traits, _Alloc, _Base>
  2097. operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
  2098. const _CharT* __rhs);
  2099. /**
  2100. * @brief Concatenate string and character.
  2101. * @param __lhs First string.
  2102. * @param __rhs Last string.
  2103. * @return New string with @a __lhs followed by @a __rhs.
  2104. */
  2105. template<typename _CharT, typename _Traits, typename _Alloc,
  2106. template <typename, typename, typename> class _Base>
  2107. __versa_string<_CharT, _Traits, _Alloc, _Base>
  2108. operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
  2109. _CharT __rhs);
  2110. #if __cplusplus >= 201103L
  2111. template<typename _CharT, typename _Traits, typename _Alloc,
  2112. template <typename, typename, typename> class _Base>
  2113. inline __versa_string<_CharT, _Traits, _Alloc, _Base>
  2114. operator+(__versa_string<_CharT, _Traits, _Alloc, _Base>&& __lhs,
  2115. const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
  2116. { return std::move(__lhs.append(__rhs)); }
  2117. template<typename _CharT, typename _Traits, typename _Alloc,
  2118. template <typename, typename, typename> class _Base>
  2119. inline __versa_string<_CharT, _Traits, _Alloc, _Base>
  2120. operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
  2121. __versa_string<_CharT, _Traits, _Alloc, _Base>&& __rhs)
  2122. { return std::move(__rhs.insert(0, __lhs)); }
  2123. template<typename _CharT, typename _Traits, typename _Alloc,
  2124. template <typename, typename, typename> class _Base>
  2125. inline __versa_string<_CharT, _Traits, _Alloc, _Base>
  2126. operator+(__versa_string<_CharT, _Traits, _Alloc, _Base>&& __lhs,
  2127. __versa_string<_CharT, _Traits, _Alloc, _Base>&& __rhs)
  2128. {
  2129. const auto __size = __lhs.size() + __rhs.size();
  2130. const bool __cond = (__size > __lhs.capacity()
  2131. && __size <= __rhs.capacity());
  2132. return __cond ? std::move(__rhs.insert(0, __lhs))
  2133. : std::move(__lhs.append(__rhs));
  2134. }
  2135. template<typename _CharT, typename _Traits, typename _Alloc,
  2136. template <typename, typename, typename> class _Base>
  2137. inline __versa_string<_CharT, _Traits, _Alloc, _Base>
  2138. operator+(const _CharT* __lhs,
  2139. __versa_string<_CharT, _Traits, _Alloc, _Base>&& __rhs)
  2140. { return std::move(__rhs.insert(0, __lhs)); }
  2141. template<typename _CharT, typename _Traits, typename _Alloc,
  2142. template <typename, typename, typename> class _Base>
  2143. inline __versa_string<_CharT, _Traits, _Alloc, _Base>
  2144. operator+(_CharT __lhs,
  2145. __versa_string<_CharT, _Traits, _Alloc, _Base>&& __rhs)
  2146. { return std::move(__rhs.insert(0, 1, __lhs)); }
  2147. template<typename _CharT, typename _Traits, typename _Alloc,
  2148. template <typename, typename, typename> class _Base>
  2149. inline __versa_string<_CharT, _Traits, _Alloc, _Base>
  2150. operator+(__versa_string<_CharT, _Traits, _Alloc, _Base>&& __lhs,
  2151. const _CharT* __rhs)
  2152. { return std::move(__lhs.append(__rhs)); }
  2153. template<typename _CharT, typename _Traits, typename _Alloc,
  2154. template <typename, typename, typename> class _Base>
  2155. inline __versa_string<_CharT, _Traits, _Alloc, _Base>
  2156. operator+(__versa_string<_CharT, _Traits, _Alloc, _Base>&& __lhs,
  2157. _CharT __rhs)
  2158. { return std::move(__lhs.append(1, __rhs)); }
  2159. #endif
  2160. // operator ==
  2161. /**
  2162. * @brief Test equivalence of two strings.
  2163. * @param __lhs First string.
  2164. * @param __rhs Second string.
  2165. * @return True if @a __lhs.compare(@a __rhs) == 0. False otherwise.
  2166. */
  2167. template<typename _CharT, typename _Traits, typename _Alloc,
  2168. template <typename, typename, typename> class _Base>
  2169. inline bool
  2170. operator==(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
  2171. const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
  2172. {
  2173. return __lhs.size() == __rhs.size()
  2174. && !_Traits::compare(__lhs.data(), __rhs.data(), __lhs.size());
  2175. }
  2176. /**
  2177. * @brief Test equivalence of string and C string.
  2178. * @param __lhs String.
  2179. * @param __rhs C string.
  2180. * @return True if @a __lhs.compare(@a __rhs) == 0. False otherwise.
  2181. */
  2182. template<typename _CharT, typename _Traits, typename _Alloc,
  2183. template <typename, typename, typename> class _Base>
  2184. inline bool
  2185. operator==(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
  2186. const _CharT* __rhs)
  2187. {
  2188. return __lhs.size() == _Traits::length(__rhs)
  2189. && !_Traits::compare(__lhs.data(), __rhs, __lhs.size());
  2190. }
  2191. /**
  2192. * @brief Test equivalence of C string and string.
  2193. * @param __lhs C string.
  2194. * @param __rhs String.
  2195. * @return True if @a __rhs.compare(@a __lhs) == 0. False otherwise.
  2196. */
  2197. template<typename _CharT, typename _Traits, typename _Alloc,
  2198. template <typename, typename, typename> class _Base>
  2199. inline bool
  2200. operator==(const _CharT* __lhs,
  2201. const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
  2202. { return __rhs == __lhs; }
  2203. // operator !=
  2204. /**
  2205. * @brief Test difference of two strings.
  2206. * @param __lhs First string.
  2207. * @param __rhs Second string.
  2208. * @return True if @a __lhs.compare(@a __rhs) != 0. False otherwise.
  2209. */
  2210. template<typename _CharT, typename _Traits, typename _Alloc,
  2211. template <typename, typename, typename> class _Base>
  2212. inline bool
  2213. operator!=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
  2214. const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
  2215. { return !(__lhs == __rhs); }
  2216. /**
  2217. * @brief Test difference of C string and string.
  2218. * @param __lhs C string.
  2219. * @param __rhs String.
  2220. * @return True if @a __rhs.compare(@a __lhs) != 0. False otherwise.
  2221. */
  2222. template<typename _CharT, typename _Traits, typename _Alloc,
  2223. template <typename, typename, typename> class _Base>
  2224. inline bool
  2225. operator!=(const _CharT* __lhs,
  2226. const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
  2227. { return !(__rhs == __lhs); }
  2228. /**
  2229. * @brief Test difference of string and C string.
  2230. * @param __lhs String.
  2231. * @param __rhs C string.
  2232. * @return True if @a __lhs.compare(@a __rhs) != 0. False otherwise.
  2233. */
  2234. template<typename _CharT, typename _Traits, typename _Alloc,
  2235. template <typename, typename, typename> class _Base>
  2236. inline bool
  2237. operator!=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
  2238. const _CharT* __rhs)
  2239. { return !(__lhs == __rhs); }
  2240. // operator <
  2241. /**
  2242. * @brief Test if string precedes string.
  2243. * @param __lhs First string.
  2244. * @param __rhs Second string.
  2245. * @return True if @a __lhs precedes @a __rhs. False otherwise.
  2246. */
  2247. template<typename _CharT, typename _Traits, typename _Alloc,
  2248. template <typename, typename, typename> class _Base>
  2249. inline bool
  2250. operator<(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
  2251. const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
  2252. { return __lhs.compare(__rhs) < 0; }
  2253. /**
  2254. * @brief Test if string precedes C string.
  2255. * @param __lhs String.
  2256. * @param __rhs C string.
  2257. * @return True if @a __lhs precedes @a __rhs. False otherwise.
  2258. */
  2259. template<typename _CharT, typename _Traits, typename _Alloc,
  2260. template <typename, typename, typename> class _Base>
  2261. inline bool
  2262. operator<(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
  2263. const _CharT* __rhs)
  2264. { return __lhs.compare(__rhs) < 0; }
  2265. /**
  2266. * @brief Test if C string precedes string.
  2267. * @param __lhs C string.
  2268. * @param __rhs String.
  2269. * @return True if @a __lhs precedes @a __rhs. False otherwise.
  2270. */
  2271. template<typename _CharT, typename _Traits, typename _Alloc,
  2272. template <typename, typename, typename> class _Base>
  2273. inline bool
  2274. operator<(const _CharT* __lhs,
  2275. const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
  2276. { return __rhs.compare(__lhs) > 0; }
  2277. // operator >
  2278. /**
  2279. * @brief Test if string follows string.
  2280. * @param __lhs First string.
  2281. * @param __rhs Second string.
  2282. * @return True if @a __lhs follows @a __rhs. False otherwise.
  2283. */
  2284. template<typename _CharT, typename _Traits, typename _Alloc,
  2285. template <typename, typename, typename> class _Base>
  2286. inline bool
  2287. operator>(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
  2288. const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
  2289. { return __lhs.compare(__rhs) > 0; }
  2290. /**
  2291. * @brief Test if string follows C string.
  2292. * @param __lhs String.
  2293. * @param __rhs C string.
  2294. * @return True if @a __lhs follows @a __rhs. False otherwise.
  2295. */
  2296. template<typename _CharT, typename _Traits, typename _Alloc,
  2297. template <typename, typename, typename> class _Base>
  2298. inline bool
  2299. operator>(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
  2300. const _CharT* __rhs)
  2301. { return __lhs.compare(__rhs) > 0; }
  2302. /**
  2303. * @brief Test if C string follows string.
  2304. * @param __lhs C string.
  2305. * @param __rhs String.
  2306. * @return True if @a __lhs follows @a __rhs. False otherwise.
  2307. */
  2308. template<typename _CharT, typename _Traits, typename _Alloc,
  2309. template <typename, typename, typename> class _Base>
  2310. inline bool
  2311. operator>(const _CharT* __lhs,
  2312. const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
  2313. { return __rhs.compare(__lhs) < 0; }
  2314. // operator <=
  2315. /**
  2316. * @brief Test if string doesn't follow string.
  2317. * @param __lhs First string.
  2318. * @param __rhs Second string.
  2319. * @return True if @a __lhs doesn't follow @a __rhs. False otherwise.
  2320. */
  2321. template<typename _CharT, typename _Traits, typename _Alloc,
  2322. template <typename, typename, typename> class _Base>
  2323. inline bool
  2324. operator<=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
  2325. const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
  2326. { return __lhs.compare(__rhs) <= 0; }
  2327. /**
  2328. * @brief Test if string doesn't follow C string.
  2329. * @param __lhs String.
  2330. * @param __rhs C string.
  2331. * @return True if @a __lhs doesn't follow @a __rhs. False otherwise.
  2332. */
  2333. template<typename _CharT, typename _Traits, typename _Alloc,
  2334. template <typename, typename, typename> class _Base>
  2335. inline bool
  2336. operator<=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
  2337. const _CharT* __rhs)
  2338. { return __lhs.compare(__rhs) <= 0; }
  2339. /**
  2340. * @brief Test if C string doesn't follow string.
  2341. * @param __lhs C string.
  2342. * @param __rhs String.
  2343. * @return True if @a __lhs doesn't follow @a __rhs. False otherwise.
  2344. */
  2345. template<typename _CharT, typename _Traits, typename _Alloc,
  2346. template <typename, typename, typename> class _Base>
  2347. inline bool
  2348. operator<=(const _CharT* __lhs,
  2349. const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
  2350. { return __rhs.compare(__lhs) >= 0; }
  2351. // operator >=
  2352. /**
  2353. * @brief Test if string doesn't precede string.
  2354. * @param __lhs First string.
  2355. * @param __rhs Second string.
  2356. * @return True if @a __lhs doesn't precede @a __rhs. False otherwise.
  2357. */
  2358. template<typename _CharT, typename _Traits, typename _Alloc,
  2359. template <typename, typename, typename> class _Base>
  2360. inline bool
  2361. operator>=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
  2362. const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
  2363. { return __lhs.compare(__rhs) >= 0; }
  2364. /**
  2365. * @brief Test if string doesn't precede C string.
  2366. * @param __lhs String.
  2367. * @param __rhs C string.
  2368. * @return True if @a __lhs doesn't precede @a __rhs. False otherwise.
  2369. */
  2370. template<typename _CharT, typename _Traits, typename _Alloc,
  2371. template <typename, typename, typename> class _Base>
  2372. inline bool
  2373. operator>=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
  2374. const _CharT* __rhs)
  2375. { return __lhs.compare(__rhs) >= 0; }
  2376. /**
  2377. * @brief Test if C string doesn't precede string.
  2378. * @param __lhs C string.
  2379. * @param __rhs String.
  2380. * @return True if @a __lhs doesn't precede @a __rhs. False otherwise.
  2381. */
  2382. template<typename _CharT, typename _Traits, typename _Alloc,
  2383. template <typename, typename, typename> class _Base>
  2384. inline bool
  2385. operator>=(const _CharT* __lhs,
  2386. const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
  2387. { return __rhs.compare(__lhs) <= 0; }
  2388. /**
  2389. * @brief Swap contents of two strings.
  2390. * @param __lhs First string.
  2391. * @param __rhs Second string.
  2392. *
  2393. * Exchanges the contents of @a __lhs and @a __rhs in constant time.
  2394. */
  2395. template<typename _CharT, typename _Traits, typename _Alloc,
  2396. template <typename, typename, typename> class _Base>
  2397. inline void
  2398. swap(__versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
  2399. __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
  2400. { __lhs.swap(__rhs); }
  2401. _GLIBCXX_END_NAMESPACE_VERSION
  2402. } // namespace
  2403. namespace std _GLIBCXX_VISIBILITY(default)
  2404. {
  2405. _GLIBCXX_BEGIN_NAMESPACE_VERSION
  2406. /**
  2407. * @brief Read stream into a string.
  2408. * @param __is Input stream.
  2409. * @param __str Buffer to store into.
  2410. * @return Reference to the input stream.
  2411. *
  2412. * Stores characters from @a __is into @a __str until whitespace is
  2413. * found, the end of the stream is encountered, or str.max_size()
  2414. * is reached. If is.width() is non-zero, that is the limit on the
  2415. * number of characters stored into @a __str. Any previous
  2416. * contents of @a __str are erased.
  2417. */
  2418. template<typename _CharT, typename _Traits, typename _Alloc,
  2419. template <typename, typename, typename> class _Base>
  2420. basic_istream<_CharT, _Traits>&
  2421. operator>>(basic_istream<_CharT, _Traits>& __is,
  2422. __gnu_cxx::__versa_string<_CharT, _Traits,
  2423. _Alloc, _Base>& __str);
  2424. /**
  2425. * @brief Write string to a stream.
  2426. * @param __os Output stream.
  2427. * @param __str String to write out.
  2428. * @return Reference to the output stream.
  2429. *
  2430. * Output characters of @a __str into os following the same rules as for
  2431. * writing a C string.
  2432. */
  2433. template<typename _CharT, typename _Traits, typename _Alloc,
  2434. template <typename, typename, typename> class _Base>
  2435. inline basic_ostream<_CharT, _Traits>&
  2436. operator<<(basic_ostream<_CharT, _Traits>& __os,
  2437. const __gnu_cxx::__versa_string<_CharT, _Traits, _Alloc,
  2438. _Base>& __str)
  2439. {
  2440. // _GLIBCXX_RESOLVE_LIB_DEFECTS
  2441. // 586. string inserter not a formatted function
  2442. return __ostream_insert(__os, __str.data(), __str.size());
  2443. }
  2444. /**
  2445. * @brief Read a line from stream into a string.
  2446. * @param __is Input stream.
  2447. * @param __str Buffer to store into.
  2448. * @param __delim Character marking end of line.
  2449. * @return Reference to the input stream.
  2450. *
  2451. * Stores characters from @a __is into @a __str until @a __delim is
  2452. * found, the end of the stream is encountered, or str.max_size()
  2453. * is reached. If is.width() is non-zero, that is the limit on the
  2454. * number of characters stored into @a __str. Any previous
  2455. * contents of @a __str are erased. If @a delim was encountered,
  2456. * it is extracted but not stored into @a __str.
  2457. */
  2458. template<typename _CharT, typename _Traits, typename _Alloc,
  2459. template <typename, typename, typename> class _Base>
  2460. basic_istream<_CharT, _Traits>&
  2461. getline(basic_istream<_CharT, _Traits>& __is,
  2462. __gnu_cxx::__versa_string<_CharT, _Traits, _Alloc, _Base>& __str,
  2463. _CharT __delim);
  2464. /**
  2465. * @brief Read a line from stream into a string.
  2466. * @param __is Input stream.
  2467. * @param __str Buffer to store into.
  2468. * @return Reference to the input stream.
  2469. *
  2470. * Stores characters from is into @a __str until &apos;\n&apos; is
  2471. * found, the end of the stream is encountered, or str.max_size()
  2472. * is reached. If is.width() is non-zero, that is the limit on the
  2473. * number of characters stored into @a __str. Any previous
  2474. * contents of @a __str are erased. If end of line was
  2475. * encountered, it is extracted but not stored into @a __str.
  2476. */
  2477. template<typename _CharT, typename _Traits, typename _Alloc,
  2478. template <typename, typename, typename> class _Base>
  2479. inline basic_istream<_CharT, _Traits>&
  2480. getline(basic_istream<_CharT, _Traits>& __is,
  2481. __gnu_cxx::__versa_string<_CharT, _Traits, _Alloc, _Base>& __str)
  2482. { return getline(__is, __str, __is.widen('\n')); }
  2483. _GLIBCXX_END_NAMESPACE_VERSION
  2484. } // namespace
  2485. #if __cplusplus >= 201103L
  2486. #include <ext/string_conversions.h>
  2487. namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
  2488. {
  2489. _GLIBCXX_BEGIN_NAMESPACE_VERSION
  2490. #if _GLIBCXX_USE_C99_STDLIB
  2491. // 21.4 Numeric Conversions [string.conversions].
  2492. inline int
  2493. stoi(const __vstring& __str, std::size_t* __idx = 0, int __base = 10)
  2494. { return __gnu_cxx::__stoa<long, int>(&std::strtol, "stoi", __str.c_str(),
  2495. __idx, __base); }
  2496. inline long
  2497. stol(const __vstring& __str, std::size_t* __idx = 0, int __base = 10)
  2498. { return __gnu_cxx::__stoa(&std::strtol, "stol", __str.c_str(),
  2499. __idx, __base); }
  2500. inline unsigned long
  2501. stoul(const __vstring& __str, std::size_t* __idx = 0, int __base = 10)
  2502. { return __gnu_cxx::__stoa(&std::strtoul, "stoul", __str.c_str(),
  2503. __idx, __base); }
  2504. inline long long
  2505. stoll(const __vstring& __str, std::size_t* __idx = 0, int __base = 10)
  2506. { return __gnu_cxx::__stoa(&std::strtoll, "stoll", __str.c_str(),
  2507. __idx, __base); }
  2508. inline unsigned long long
  2509. stoull(const __vstring& __str, std::size_t* __idx, int __base = 10)
  2510. { return __gnu_cxx::__stoa(&std::strtoull, "stoull", __str.c_str(),
  2511. __idx, __base); }
  2512. // NB: strtof vs strtod.
  2513. inline float
  2514. stof(const __vstring& __str, std::size_t* __idx = 0)
  2515. { return __gnu_cxx::__stoa(&std::strtof, "stof", __str.c_str(), __idx); }
  2516. inline double
  2517. stod(const __vstring& __str, std::size_t* __idx = 0)
  2518. { return __gnu_cxx::__stoa(&std::strtod, "stod", __str.c_str(), __idx); }
  2519. inline long double
  2520. stold(const __vstring& __str, std::size_t* __idx = 0)
  2521. { return __gnu_cxx::__stoa(&std::strtold, "stold", __str.c_str(), __idx); }
  2522. #endif // _GLIBCXX_USE_C99_STDLIB
  2523. #if _GLIBCXX_USE_C99_STDIO
  2524. // NB: (v)snprintf vs sprintf.
  2525. // DR 1261.
  2526. inline __vstring
  2527. to_string(int __val)
  2528. { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, 4 * sizeof(int),
  2529. "%d", __val); }
  2530. inline __vstring
  2531. to_string(unsigned __val)
  2532. { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf,
  2533. 4 * sizeof(unsigned),
  2534. "%u", __val); }
  2535. inline __vstring
  2536. to_string(long __val)
  2537. { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf,
  2538. 4 * sizeof(long),
  2539. "%ld", __val); }
  2540. inline __vstring
  2541. to_string(unsigned long __val)
  2542. { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf,
  2543. 4 * sizeof(unsigned long),
  2544. "%lu", __val); }
  2545. inline __vstring
  2546. to_string(long long __val)
  2547. { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf,
  2548. 4 * sizeof(long long),
  2549. "%lld", __val); }
  2550. inline __vstring
  2551. to_string(unsigned long long __val)
  2552. { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf,
  2553. 4 * sizeof(unsigned long long),
  2554. "%llu", __val); }
  2555. inline __vstring
  2556. to_string(float __val)
  2557. {
  2558. const int __n = __numeric_traits<float>::__max_exponent10 + 20;
  2559. return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, __n,
  2560. "%f", __val);
  2561. }
  2562. inline __vstring
  2563. to_string(double __val)
  2564. {
  2565. const int __n = __numeric_traits<double>::__max_exponent10 + 20;
  2566. return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, __n,
  2567. "%f", __val);
  2568. }
  2569. inline __vstring
  2570. to_string(long double __val)
  2571. {
  2572. const int __n = __numeric_traits<long double>::__max_exponent10 + 20;
  2573. return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, __n,
  2574. "%Lf", __val);
  2575. }
  2576. #endif // _GLIBCXX_USE_C99_STDIO
  2577. #if defined(_GLIBCXX_USE_WCHAR_T) && _GLIBCXX_USE_C99_WCHAR
  2578. inline int
  2579. stoi(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10)
  2580. { return __gnu_cxx::__stoa<long, int>(&std::wcstol, "stoi", __str.c_str(),
  2581. __idx, __base); }
  2582. inline long
  2583. stol(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10)
  2584. { return __gnu_cxx::__stoa(&std::wcstol, "stol", __str.c_str(),
  2585. __idx, __base); }
  2586. inline unsigned long
  2587. stoul(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10)
  2588. { return __gnu_cxx::__stoa(&std::wcstoul, "stoul", __str.c_str(),
  2589. __idx, __base); }
  2590. inline long long
  2591. stoll(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10)
  2592. { return __gnu_cxx::__stoa(&std::wcstoll, "stoll", __str.c_str(),
  2593. __idx, __base); }
  2594. inline unsigned long long
  2595. stoull(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10)
  2596. { return __gnu_cxx::__stoa(&std::wcstoull, "stoull", __str.c_str(),
  2597. __idx, __base); }
  2598. // NB: wcstof vs wcstod.
  2599. inline float
  2600. stof(const __wvstring& __str, std::size_t* __idx = 0)
  2601. { return __gnu_cxx::__stoa(&std::wcstof, "stof", __str.c_str(), __idx); }
  2602. inline double
  2603. stod(const __wvstring& __str, std::size_t* __idx = 0)
  2604. { return __gnu_cxx::__stoa(&std::wcstod, "stod", __str.c_str(), __idx); }
  2605. inline long double
  2606. stold(const __wvstring& __str, std::size_t* __idx = 0)
  2607. { return __gnu_cxx::__stoa(&std::wcstold, "stold", __str.c_str(), __idx); }
  2608. #ifndef _GLIBCXX_HAVE_BROKEN_VSWPRINTF
  2609. // DR 1261.
  2610. inline __wvstring
  2611. to_wstring(int __val)
  2612. { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
  2613. 4 * sizeof(int),
  2614. L"%d", __val); }
  2615. inline __wvstring
  2616. to_wstring(unsigned __val)
  2617. { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
  2618. 4 * sizeof(unsigned),
  2619. L"%u", __val); }
  2620. inline __wvstring
  2621. to_wstring(long __val)
  2622. { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
  2623. 4 * sizeof(long),
  2624. L"%ld", __val); }
  2625. inline __wvstring
  2626. to_wstring(unsigned long __val)
  2627. { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
  2628. 4 * sizeof(unsigned long),
  2629. L"%lu", __val); }
  2630. inline __wvstring
  2631. to_wstring(long long __val)
  2632. { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
  2633. 4 * sizeof(long long),
  2634. L"%lld", __val); }
  2635. inline __wvstring
  2636. to_wstring(unsigned long long __val)
  2637. { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
  2638. 4 * sizeof(unsigned long long),
  2639. L"%llu", __val); }
  2640. inline __wvstring
  2641. to_wstring(float __val)
  2642. {
  2643. const int __n = __numeric_traits<float>::__max_exponent10 + 20;
  2644. return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, __n,
  2645. L"%f", __val);
  2646. }
  2647. inline __wvstring
  2648. to_wstring(double __val)
  2649. {
  2650. const int __n = __numeric_traits<double>::__max_exponent10 + 20;
  2651. return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, __n,
  2652. L"%f", __val);
  2653. }
  2654. inline __wvstring
  2655. to_wstring(long double __val)
  2656. {
  2657. const int __n = __numeric_traits<long double>::__max_exponent10 + 20;
  2658. return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, __n,
  2659. L"%Lf", __val);
  2660. }
  2661. #endif // _GLIBCXX_HAVE_BROKEN_VSWPRINTF
  2662. #endif // _GLIBCXX_USE_WCHAR_T && _GLIBCXX_USE_C99_WCHAR
  2663. _GLIBCXX_END_NAMESPACE_VERSION
  2664. } // namespace
  2665. #endif
  2666. #if __cplusplus >= 201103L
  2667. #include <bits/functional_hash.h>
  2668. namespace std _GLIBCXX_VISIBILITY(default)
  2669. {
  2670. _GLIBCXX_BEGIN_NAMESPACE_VERSION
  2671. /// std::hash specialization for __vstring.
  2672. template<>
  2673. struct hash<__gnu_cxx::__vstring>
  2674. : public __hash_base<size_t, __gnu_cxx::__vstring>
  2675. {
  2676. size_t
  2677. operator()(const __gnu_cxx::__vstring& __s) const noexcept
  2678. { return std::_Hash_impl::hash(__s.data(), __s.length()); }
  2679. };
  2680. /// std::hash specialization for __wvstring.
  2681. template<>
  2682. struct hash<__gnu_cxx::__wvstring>
  2683. : public __hash_base<size_t, __gnu_cxx::__wvstring>
  2684. {
  2685. size_t
  2686. operator()(const __gnu_cxx::__wvstring& __s) const noexcept
  2687. { return std::_Hash_impl::hash(__s.data(),
  2688. __s.length() * sizeof(wchar_t)); }
  2689. };
  2690. /// std::hash specialization for __u16vstring.
  2691. template<>
  2692. struct hash<__gnu_cxx::__u16vstring>
  2693. : public __hash_base<size_t, __gnu_cxx::__u16vstring>
  2694. {
  2695. size_t
  2696. operator()(const __gnu_cxx::__u16vstring& __s) const noexcept
  2697. { return std::_Hash_impl::hash(__s.data(),
  2698. __s.length() * sizeof(char16_t)); }
  2699. };
  2700. /// std::hash specialization for __u32vstring.
  2701. template<>
  2702. struct hash<__gnu_cxx::__u32vstring>
  2703. : public __hash_base<size_t, __gnu_cxx::__u32vstring>
  2704. {
  2705. size_t
  2706. operator()(const __gnu_cxx::__u32vstring& __s) const noexcept
  2707. { return std::_Hash_impl::hash(__s.data(),
  2708. __s.length() * sizeof(char32_t)); }
  2709. };
  2710. _GLIBCXX_END_NAMESPACE_VERSION
  2711. } // namespace
  2712. #endif // C++11
  2713. #include <ext/vstring.tcc>
  2714. #endif /* _VSTRING_H */