vstring.h 108 KB

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