regex.h 100 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984
  1. // class template regex -*- C++ -*-
  2. // Copyright (C) 2010-2021 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. /**
  21. * @file bits/regex.h
  22. * This is an internal header file, included by other library headers.
  23. * Do not attempt to use it directly. @headername{regex}
  24. */
  25. namespace std _GLIBCXX_VISIBILITY(default)
  26. {
  27. _GLIBCXX_BEGIN_NAMESPACE_VERSION
  28. _GLIBCXX_BEGIN_NAMESPACE_CXX11
  29. template<typename, typename>
  30. class basic_regex;
  31. template<typename, typename>
  32. class match_results;
  33. _GLIBCXX_END_NAMESPACE_CXX11
  34. namespace __detail
  35. {
  36. enum class _RegexExecutorPolicy : int { _S_auto, _S_alternate };
  37. template<typename _BiIter, typename _Alloc,
  38. typename _CharT, typename _TraitsT,
  39. _RegexExecutorPolicy __policy,
  40. bool __match_mode>
  41. bool
  42. __regex_algo_impl(_BiIter __s,
  43. _BiIter __e,
  44. match_results<_BiIter, _Alloc>& __m,
  45. const basic_regex<_CharT, _TraitsT>& __re,
  46. regex_constants::match_flag_type __flags);
  47. template<typename, typename, typename, bool>
  48. class _Executor;
  49. }
  50. _GLIBCXX_BEGIN_NAMESPACE_CXX11
  51. /**
  52. * @addtogroup regex
  53. * @{
  54. */
  55. /**
  56. * @brief Describes aspects of a regular expression.
  57. *
  58. * A regular expression traits class that satisfies the requirements of
  59. * section [28.7].
  60. *
  61. * The class %regex is parameterized around a set of related types and
  62. * functions used to complete the definition of its semantics. This class
  63. * satisfies the requirements of such a traits class.
  64. */
  65. template<typename _Ch_type>
  66. class regex_traits
  67. {
  68. public:
  69. typedef _Ch_type char_type;
  70. typedef std::basic_string<char_type> string_type;
  71. typedef std::locale locale_type;
  72. private:
  73. struct _RegexMask
  74. {
  75. typedef std::ctype_base::mask _BaseType;
  76. _BaseType _M_base;
  77. unsigned char _M_extended;
  78. static constexpr unsigned char _S_under = 1 << 0;
  79. static constexpr unsigned char _S_valid_mask = 0x1;
  80. constexpr _RegexMask(_BaseType __base = 0,
  81. unsigned char __extended = 0)
  82. : _M_base(__base), _M_extended(__extended)
  83. { }
  84. constexpr _RegexMask
  85. operator&(_RegexMask __other) const
  86. {
  87. return _RegexMask(_M_base & __other._M_base,
  88. _M_extended & __other._M_extended);
  89. }
  90. constexpr _RegexMask
  91. operator|(_RegexMask __other) const
  92. {
  93. return _RegexMask(_M_base | __other._M_base,
  94. _M_extended | __other._M_extended);
  95. }
  96. constexpr _RegexMask
  97. operator^(_RegexMask __other) const
  98. {
  99. return _RegexMask(_M_base ^ __other._M_base,
  100. _M_extended ^ __other._M_extended);
  101. }
  102. constexpr _RegexMask
  103. operator~() const
  104. { return _RegexMask(~_M_base, ~_M_extended); }
  105. _RegexMask&
  106. operator&=(_RegexMask __other)
  107. { return *this = (*this) & __other; }
  108. _RegexMask&
  109. operator|=(_RegexMask __other)
  110. { return *this = (*this) | __other; }
  111. _RegexMask&
  112. operator^=(_RegexMask __other)
  113. { return *this = (*this) ^ __other; }
  114. constexpr bool
  115. operator==(_RegexMask __other) const
  116. {
  117. return (_M_extended & _S_valid_mask)
  118. == (__other._M_extended & _S_valid_mask)
  119. && _M_base == __other._M_base;
  120. }
  121. #if __cpp_impl_three_way_comparison < 201907L
  122. constexpr bool
  123. operator!=(_RegexMask __other) const
  124. { return !((*this) == __other); }
  125. #endif
  126. };
  127. public:
  128. typedef _RegexMask char_class_type;
  129. public:
  130. /**
  131. * @brief Constructs a default traits object.
  132. */
  133. regex_traits() { }
  134. /**
  135. * @brief Gives the length of a C-style string starting at @p __p.
  136. *
  137. * @param __p a pointer to the start of a character sequence.
  138. *
  139. * @returns the number of characters between @p *__p and the first
  140. * default-initialized value of type @p char_type. In other words, uses
  141. * the C-string algorithm for determining the length of a sequence of
  142. * characters.
  143. */
  144. static std::size_t
  145. length(const char_type* __p)
  146. { return string_type::traits_type::length(__p); }
  147. /**
  148. * @brief Performs the identity translation.
  149. *
  150. * @param __c A character to the locale-specific character set.
  151. *
  152. * @returns __c.
  153. */
  154. char_type
  155. translate(char_type __c) const
  156. { return __c; }
  157. /**
  158. * @brief Translates a character into a case-insensitive equivalent.
  159. *
  160. * @param __c A character to the locale-specific character set.
  161. *
  162. * @returns the locale-specific lower-case equivalent of __c.
  163. * @throws std::bad_cast if the imbued locale does not support the ctype
  164. * facet.
  165. */
  166. char_type
  167. translate_nocase(char_type __c) const
  168. {
  169. typedef std::ctype<char_type> __ctype_type;
  170. const __ctype_type& __fctyp(use_facet<__ctype_type>(_M_locale));
  171. return __fctyp.tolower(__c);
  172. }
  173. /**
  174. * @brief Gets a sort key for a character sequence.
  175. *
  176. * @param __first beginning of the character sequence.
  177. * @param __last one-past-the-end of the character sequence.
  178. *
  179. * Returns a sort key for the character sequence designated by the
  180. * iterator range [F1, F2) such that if the character sequence [G1, G2)
  181. * sorts before the character sequence [H1, H2) then
  182. * v.transform(G1, G2) < v.transform(H1, H2).
  183. *
  184. * What this really does is provide a more efficient way to compare a
  185. * string to multiple other strings in locales with fancy collation
  186. * rules and equivalence classes.
  187. *
  188. * @returns a locale-specific sort key equivalent to the input range.
  189. *
  190. * @throws std::bad_cast if the current locale does not have a collate
  191. * facet.
  192. */
  193. template<typename _Fwd_iter>
  194. string_type
  195. transform(_Fwd_iter __first, _Fwd_iter __last) const
  196. {
  197. typedef std::collate<char_type> __collate_type;
  198. const __collate_type& __fclt(use_facet<__collate_type>(_M_locale));
  199. string_type __s(__first, __last);
  200. return __fclt.transform(__s.data(), __s.data() + __s.size());
  201. }
  202. /**
  203. * @brief Gets a sort key for a character sequence, independent of case.
  204. *
  205. * @param __first beginning of the character sequence.
  206. * @param __last one-past-the-end of the character sequence.
  207. *
  208. * Effects: if typeid(use_facet<collate<_Ch_type> >) ==
  209. * typeid(collate_byname<_Ch_type>) and the form of the sort key
  210. * returned by collate_byname<_Ch_type>::transform(__first, __last)
  211. * is known and can be converted into a primary sort key
  212. * then returns that key, otherwise returns an empty string.
  213. *
  214. * @todo Implement this function correctly.
  215. */
  216. template<typename _Fwd_iter>
  217. string_type
  218. transform_primary(_Fwd_iter __first, _Fwd_iter __last) const
  219. {
  220. // TODO : this is not entirely correct.
  221. // This function requires extra support from the platform.
  222. //
  223. // Read http://gcc.gnu.org/ml/libstdc++/2013-09/msg00117.html and
  224. // http://www.open-std.org/Jtc1/sc22/wg21/docs/papers/2003/n1429.htm
  225. // for details.
  226. typedef std::ctype<char_type> __ctype_type;
  227. const __ctype_type& __fctyp(use_facet<__ctype_type>(_M_locale));
  228. std::vector<char_type> __s(__first, __last);
  229. __fctyp.tolower(__s.data(), __s.data() + __s.size());
  230. return this->transform(__s.data(), __s.data() + __s.size());
  231. }
  232. /**
  233. * @brief Gets a collation element by name.
  234. *
  235. * @param __first beginning of the collation element name.
  236. * @param __last one-past-the-end of the collation element name.
  237. *
  238. * @returns a sequence of one or more characters that represents the
  239. * collating element consisting of the character sequence designated by
  240. * the iterator range [__first, __last). Returns an empty string if the
  241. * character sequence is not a valid collating element.
  242. */
  243. template<typename _Fwd_iter>
  244. string_type
  245. lookup_collatename(_Fwd_iter __first, _Fwd_iter __last) const;
  246. /**
  247. * @brief Maps one or more characters to a named character
  248. * classification.
  249. *
  250. * @param __first beginning of the character sequence.
  251. * @param __last one-past-the-end of the character sequence.
  252. * @param __icase ignores the case of the classification name.
  253. *
  254. * @returns an unspecified value that represents the character
  255. * classification named by the character sequence designated by
  256. * the iterator range [__first, __last). If @p icase is true,
  257. * the returned mask identifies the classification regardless of
  258. * the case of the characters to be matched (for example,
  259. * [[:lower:]] is the same as [[:alpha:]]), otherwise a
  260. * case-dependent classification is returned. The value
  261. * returned shall be independent of the case of the characters
  262. * in the character sequence. If the name is not recognized then
  263. * returns a value that compares equal to 0.
  264. *
  265. * At least the following names (or their wide-character equivalent) are
  266. * supported.
  267. * - d
  268. * - w
  269. * - s
  270. * - alnum
  271. * - alpha
  272. * - blank
  273. * - cntrl
  274. * - digit
  275. * - graph
  276. * - lower
  277. * - print
  278. * - punct
  279. * - space
  280. * - upper
  281. * - xdigit
  282. */
  283. template<typename _Fwd_iter>
  284. char_class_type
  285. lookup_classname(_Fwd_iter __first, _Fwd_iter __last,
  286. bool __icase = false) const;
  287. /**
  288. * @brief Determines if @p c is a member of an identified class.
  289. *
  290. * @param __c a character.
  291. * @param __f a class type (as returned from lookup_classname).
  292. *
  293. * @returns true if the character @p __c is a member of the classification
  294. * represented by @p __f, false otherwise.
  295. *
  296. * @throws std::bad_cast if the current locale does not have a ctype
  297. * facet.
  298. */
  299. bool
  300. isctype(_Ch_type __c, char_class_type __f) const;
  301. /**
  302. * @brief Converts a digit to an int.
  303. *
  304. * @param __ch a character representing a digit.
  305. * @param __radix the radix if the numeric conversion (limited to 8, 10,
  306. * or 16).
  307. *
  308. * @returns the value represented by the digit __ch in base radix if the
  309. * character __ch is a valid digit in base radix; otherwise returns -1.
  310. */
  311. int
  312. value(_Ch_type __ch, int __radix) const;
  313. /**
  314. * @brief Imbues the regex_traits object with a copy of a new locale.
  315. *
  316. * @param __loc A locale.
  317. *
  318. * @returns a copy of the previous locale in use by the regex_traits
  319. * object.
  320. *
  321. * @note Calling imbue with a different locale than the one currently in
  322. * use invalidates all cached data held by *this.
  323. */
  324. locale_type
  325. imbue(locale_type __loc)
  326. {
  327. std::swap(_M_locale, __loc);
  328. return __loc;
  329. }
  330. /**
  331. * @brief Gets a copy of the current locale in use by the regex_traits
  332. * object.
  333. */
  334. locale_type
  335. getloc() const
  336. { return _M_locale; }
  337. protected:
  338. locale_type _M_locale;
  339. };
  340. // [7.8] Class basic_regex
  341. /**
  342. * Objects of specializations of this class represent regular expressions
  343. * constructed from sequences of character type @p _Ch_type.
  344. *
  345. * Storage for the regular expression is allocated and deallocated as
  346. * necessary by the member functions of this class.
  347. */
  348. template<typename _Ch_type, typename _Rx_traits = regex_traits<_Ch_type>>
  349. class basic_regex
  350. {
  351. public:
  352. static_assert(is_same<_Ch_type, typename _Rx_traits::char_type>::value,
  353. "regex traits class must have the same char_type");
  354. // types:
  355. typedef _Ch_type value_type;
  356. typedef _Rx_traits traits_type;
  357. typedef typename traits_type::string_type string_type;
  358. typedef regex_constants::syntax_option_type flag_type;
  359. typedef typename traits_type::locale_type locale_type;
  360. /**
  361. * @name Constants
  362. * std [28.8.1](1)
  363. */
  364. ///@{
  365. static constexpr flag_type icase = regex_constants::icase;
  366. static constexpr flag_type nosubs = regex_constants::nosubs;
  367. static constexpr flag_type optimize = regex_constants::optimize;
  368. static constexpr flag_type collate = regex_constants::collate;
  369. static constexpr flag_type ECMAScript = regex_constants::ECMAScript;
  370. static constexpr flag_type basic = regex_constants::basic;
  371. static constexpr flag_type extended = regex_constants::extended;
  372. static constexpr flag_type awk = regex_constants::awk;
  373. static constexpr flag_type grep = regex_constants::grep;
  374. static constexpr flag_type egrep = regex_constants::egrep;
  375. ///@}
  376. // [7.8.2] construct/copy/destroy
  377. /**
  378. * Constructs a basic regular expression that does not match any
  379. * character sequence.
  380. */
  381. basic_regex()
  382. : _M_flags(ECMAScript), _M_loc(), _M_automaton(nullptr)
  383. { }
  384. /**
  385. * @brief Constructs a basic regular expression from the
  386. * sequence [__p, __p + char_traits<_Ch_type>::length(__p))
  387. * interpreted according to the flags in @p __f.
  388. *
  389. * @param __p A pointer to the start of a C-style null-terminated string
  390. * containing a regular expression.
  391. * @param __f Flags indicating the syntax rules and options.
  392. *
  393. * @throws regex_error if @p __p is not a valid regular expression.
  394. */
  395. explicit
  396. basic_regex(const _Ch_type* __p, flag_type __f = ECMAScript)
  397. : basic_regex(__p, __p + char_traits<_Ch_type>::length(__p), __f)
  398. { }
  399. /**
  400. * @brief Constructs a basic regular expression from the sequence
  401. * [p, p + len) interpreted according to the flags in @p f.
  402. *
  403. * @param __p A pointer to the start of a string containing a regular
  404. * expression.
  405. * @param __len The length of the string containing the regular
  406. * expression.
  407. * @param __f Flags indicating the syntax rules and options.
  408. *
  409. * @throws regex_error if @p __p is not a valid regular expression.
  410. */
  411. basic_regex(const _Ch_type* __p, std::size_t __len,
  412. flag_type __f = ECMAScript)
  413. : basic_regex(__p, __p + __len, __f)
  414. { }
  415. /**
  416. * @brief Copy-constructs a basic regular expression.
  417. *
  418. * @param __rhs A @p regex object.
  419. */
  420. basic_regex(const basic_regex& __rhs) = default;
  421. /**
  422. * @brief Move-constructs a basic regular expression.
  423. *
  424. * @param __rhs A @p regex object.
  425. */
  426. basic_regex(basic_regex&& __rhs) noexcept = default;
  427. /**
  428. * @brief Constructs a basic regular expression from the string
  429. * @p s interpreted according to the flags in @p f.
  430. *
  431. * @param __s A string containing a regular expression.
  432. * @param __f Flags indicating the syntax rules and options.
  433. *
  434. * @throws regex_error if @p __s is not a valid regular expression.
  435. */
  436. template<typename _Ch_traits, typename _Ch_alloc>
  437. explicit
  438. basic_regex(const std::basic_string<_Ch_type, _Ch_traits,
  439. _Ch_alloc>& __s,
  440. flag_type __f = ECMAScript)
  441. : basic_regex(__s.data(), __s.data() + __s.size(), __f)
  442. { }
  443. /**
  444. * @brief Constructs a basic regular expression from the range
  445. * [first, last) interpreted according to the flags in @p f.
  446. *
  447. * @param __first The start of a range containing a valid regular
  448. * expression.
  449. * @param __last The end of a range containing a valid regular
  450. * expression.
  451. * @param __f The format flags of the regular expression.
  452. *
  453. * @throws regex_error if @p [__first, __last) is not a valid regular
  454. * expression.
  455. */
  456. template<typename _FwdIter>
  457. basic_regex(_FwdIter __first, _FwdIter __last,
  458. flag_type __f = ECMAScript)
  459. : basic_regex(std::move(__first), std::move(__last), locale_type(), __f)
  460. { }
  461. /**
  462. * @brief Constructs a basic regular expression from an initializer list.
  463. *
  464. * @param __l The initializer list.
  465. * @param __f The format flags of the regular expression.
  466. *
  467. * @throws regex_error if @p __l is not a valid regular expression.
  468. */
  469. basic_regex(initializer_list<_Ch_type> __l, flag_type __f = ECMAScript)
  470. : basic_regex(__l.begin(), __l.end(), __f)
  471. { }
  472. /**
  473. * @brief Destroys a basic regular expression.
  474. */
  475. ~basic_regex()
  476. { }
  477. /**
  478. * @brief Assigns one regular expression to another.
  479. */
  480. basic_regex&
  481. operator=(const basic_regex& __rhs)
  482. { return this->assign(__rhs); }
  483. /**
  484. * @brief Move-assigns one regular expression to another.
  485. */
  486. basic_regex&
  487. operator=(basic_regex&& __rhs) noexcept
  488. { return this->assign(std::move(__rhs)); }
  489. /**
  490. * @brief Replaces a regular expression with a new one constructed from
  491. * a C-style null-terminated string.
  492. *
  493. * @param __p A pointer to the start of a null-terminated C-style string
  494. * containing a regular expression.
  495. */
  496. basic_regex&
  497. operator=(const _Ch_type* __p)
  498. { return this->assign(__p); }
  499. /**
  500. * @brief Replaces a regular expression with a new one constructed from
  501. * an initializer list.
  502. *
  503. * @param __l The initializer list.
  504. *
  505. * @throws regex_error if @p __l is not a valid regular expression.
  506. */
  507. basic_regex&
  508. operator=(initializer_list<_Ch_type> __l)
  509. { return this->assign(__l.begin(), __l.end()); }
  510. /**
  511. * @brief Replaces a regular expression with a new one constructed from
  512. * a string.
  513. *
  514. * @param __s A pointer to a string containing a regular expression.
  515. */
  516. template<typename _Ch_traits, typename _Alloc>
  517. basic_regex&
  518. operator=(const basic_string<_Ch_type, _Ch_traits, _Alloc>& __s)
  519. { return this->assign(__s); }
  520. // [7.8.3] assign
  521. /**
  522. * @brief the real assignment operator.
  523. *
  524. * @param __rhs Another regular expression object.
  525. */
  526. basic_regex&
  527. assign(const basic_regex& __rhs)
  528. {
  529. basic_regex __tmp(__rhs);
  530. this->swap(__tmp);
  531. return *this;
  532. }
  533. /**
  534. * @brief The move-assignment operator.
  535. *
  536. * @param __rhs Another regular expression object.
  537. */
  538. basic_regex&
  539. assign(basic_regex&& __rhs) noexcept
  540. {
  541. basic_regex __tmp(std::move(__rhs));
  542. this->swap(__tmp);
  543. return *this;
  544. }
  545. /**
  546. * @brief Assigns a new regular expression to a regex object from a
  547. * C-style null-terminated string containing a regular expression
  548. * pattern.
  549. *
  550. * @param __p A pointer to a C-style null-terminated string containing
  551. * a regular expression pattern.
  552. * @param __flags Syntax option flags.
  553. *
  554. * @throws regex_error if __p does not contain a valid regular
  555. * expression pattern interpreted according to @p __flags. If
  556. * regex_error is thrown, *this remains unchanged.
  557. */
  558. basic_regex&
  559. assign(const _Ch_type* __p, flag_type __flags = ECMAScript)
  560. { return this->assign(string_type(__p), __flags); }
  561. /**
  562. * @brief Assigns a new regular expression to a regex object from a
  563. * C-style string containing a regular expression pattern.
  564. *
  565. * @param __p A pointer to a C-style string containing a
  566. * regular expression pattern.
  567. * @param __len The length of the regular expression pattern string.
  568. * @param __flags Syntax option flags.
  569. *
  570. * @throws regex_error if p does not contain a valid regular
  571. * expression pattern interpreted according to @p __flags. If
  572. * regex_error is thrown, *this remains unchanged.
  573. */
  574. // _GLIBCXX_RESOLVE_LIB_DEFECTS
  575. // 3296. Inconsistent default argument for basic_regex<>::assign
  576. basic_regex&
  577. assign(const _Ch_type* __p, size_t __len, flag_type __flags = ECMAScript)
  578. { return this->assign(string_type(__p, __len), __flags); }
  579. /**
  580. * @brief Assigns a new regular expression to a regex object from a
  581. * string containing a regular expression pattern.
  582. *
  583. * @param __s A string containing a regular expression pattern.
  584. * @param __flags Syntax option flags.
  585. *
  586. * @throws regex_error if __s does not contain a valid regular
  587. * expression pattern interpreted according to @p __flags. If
  588. * regex_error is thrown, *this remains unchanged.
  589. */
  590. template<typename _Ch_traits, typename _Alloc>
  591. basic_regex&
  592. assign(const basic_string<_Ch_type, _Ch_traits, _Alloc>& __s,
  593. flag_type __flags = ECMAScript)
  594. {
  595. return this->assign(basic_regex(__s.data(), __s.data() + __s.size(),
  596. _M_loc, __flags));
  597. }
  598. /**
  599. * @brief Assigns a new regular expression to a regex object.
  600. *
  601. * @param __first The start of a range containing a valid regular
  602. * expression.
  603. * @param __last The end of a range containing a valid regular
  604. * expression.
  605. * @param __flags Syntax option flags.
  606. *
  607. * @throws regex_error if p does not contain a valid regular
  608. * expression pattern interpreted according to @p __flags. If
  609. * regex_error is thrown, the object remains unchanged.
  610. */
  611. template<typename _InputIterator>
  612. basic_regex&
  613. assign(_InputIterator __first, _InputIterator __last,
  614. flag_type __flags = ECMAScript)
  615. { return this->assign(string_type(__first, __last), __flags); }
  616. /**
  617. * @brief Assigns a new regular expression to a regex object.
  618. *
  619. * @param __l An initializer list representing a regular expression.
  620. * @param __flags Syntax option flags.
  621. *
  622. * @throws regex_error if @p __l does not contain a valid
  623. * regular expression pattern interpreted according to @p
  624. * __flags. If regex_error is thrown, the object remains
  625. * unchanged.
  626. */
  627. basic_regex&
  628. assign(initializer_list<_Ch_type> __l, flag_type __flags = ECMAScript)
  629. { return this->assign(__l.begin(), __l.end(), __flags); }
  630. // [7.8.4] const operations
  631. /**
  632. * @brief Gets the number of marked subexpressions within the regular
  633. * expression.
  634. */
  635. unsigned int
  636. mark_count() const
  637. {
  638. if (_M_automaton)
  639. return _M_automaton->_M_sub_count() - 1;
  640. return 0;
  641. }
  642. /**
  643. * @brief Gets the flags used to construct the regular expression
  644. * or in the last call to assign().
  645. */
  646. flag_type
  647. flags() const
  648. { return _M_flags; }
  649. // [7.8.5] locale
  650. /**
  651. * @brief Imbues the regular expression object with the given locale.
  652. *
  653. * @param __loc A locale.
  654. */
  655. locale_type
  656. imbue(locale_type __loc)
  657. {
  658. std::swap(__loc, _M_loc);
  659. _M_automaton.reset();
  660. return __loc;
  661. }
  662. /**
  663. * @brief Gets the locale currently imbued in the regular expression
  664. * object.
  665. */
  666. locale_type
  667. getloc() const
  668. { return _M_loc; }
  669. // [7.8.6] swap
  670. /**
  671. * @brief Swaps the contents of two regular expression objects.
  672. *
  673. * @param __rhs Another regular expression object.
  674. */
  675. void
  676. swap(basic_regex& __rhs)
  677. {
  678. std::swap(_M_flags, __rhs._M_flags);
  679. std::swap(_M_loc, __rhs._M_loc);
  680. std::swap(_M_automaton, __rhs._M_automaton);
  681. }
  682. #ifdef _GLIBCXX_DEBUG
  683. void
  684. _M_dot(std::ostream& __ostr)
  685. { _M_automaton->_M_dot(__ostr); }
  686. #endif
  687. private:
  688. typedef std::shared_ptr<const __detail::_NFA<_Rx_traits>> _AutomatonPtr;
  689. template<typename _FwdIter>
  690. basic_regex(_FwdIter __first, _FwdIter __last, locale_type __loc,
  691. flag_type __f)
  692. : _M_flags(__f), _M_loc(std::move(__loc)),
  693. _M_automaton(__detail::__compile_nfa<_Rx_traits>(
  694. std::move(__first), std::move(__last), _M_loc, _M_flags))
  695. { }
  696. template<typename _Bp, typename _Ap, typename _Cp, typename _Rp,
  697. __detail::_RegexExecutorPolicy, bool>
  698. friend bool
  699. __detail::__regex_algo_impl(_Bp, _Bp, match_results<_Bp, _Ap>&,
  700. const basic_regex<_Cp, _Rp>&,
  701. regex_constants::match_flag_type);
  702. template<typename, typename, typename, bool>
  703. friend class __detail::_Executor;
  704. flag_type _M_flags;
  705. locale_type _M_loc;
  706. _AutomatonPtr _M_automaton;
  707. };
  708. #if __cplusplus < 201703L
  709. template<typename _Ch, typename _Tr>
  710. constexpr regex_constants::syntax_option_type
  711. basic_regex<_Ch, _Tr>::icase;
  712. template<typename _Ch, typename _Tr>
  713. constexpr regex_constants::syntax_option_type
  714. basic_regex<_Ch, _Tr>::nosubs;
  715. template<typename _Ch, typename _Tr>
  716. constexpr regex_constants::syntax_option_type
  717. basic_regex<_Ch, _Tr>::optimize;
  718. template<typename _Ch, typename _Tr>
  719. constexpr regex_constants::syntax_option_type
  720. basic_regex<_Ch, _Tr>::collate;
  721. template<typename _Ch, typename _Tr>
  722. constexpr regex_constants::syntax_option_type
  723. basic_regex<_Ch, _Tr>::ECMAScript;
  724. template<typename _Ch, typename _Tr>
  725. constexpr regex_constants::syntax_option_type
  726. basic_regex<_Ch, _Tr>::basic;
  727. template<typename _Ch, typename _Tr>
  728. constexpr regex_constants::syntax_option_type
  729. basic_regex<_Ch, _Tr>::extended;
  730. template<typename _Ch, typename _Tr>
  731. constexpr regex_constants::syntax_option_type
  732. basic_regex<_Ch, _Tr>::awk;
  733. template<typename _Ch, typename _Tr>
  734. constexpr regex_constants::syntax_option_type
  735. basic_regex<_Ch, _Tr>::grep;
  736. template<typename _Ch, typename _Tr>
  737. constexpr regex_constants::syntax_option_type
  738. basic_regex<_Ch, _Tr>::egrep;
  739. #endif // ! C++17
  740. #if __cpp_deduction_guides >= 201606
  741. template<typename _ForwardIterator>
  742. basic_regex(_ForwardIterator, _ForwardIterator,
  743. regex_constants::syntax_option_type = {})
  744. -> basic_regex<typename iterator_traits<_ForwardIterator>::value_type>;
  745. #endif
  746. /** @brief Standard regular expressions. */
  747. typedef basic_regex<char> regex;
  748. #ifdef _GLIBCXX_USE_WCHAR_T
  749. /** @brief Standard wide-character regular expressions. */
  750. typedef basic_regex<wchar_t> wregex;
  751. #endif
  752. // [7.8.6] basic_regex swap
  753. /**
  754. * @brief Swaps the contents of two regular expression objects.
  755. * @param __lhs First regular expression.
  756. * @param __rhs Second regular expression.
  757. * @relates basic_regex
  758. */
  759. template<typename _Ch_type, typename _Rx_traits>
  760. inline void
  761. swap(basic_regex<_Ch_type, _Rx_traits>& __lhs,
  762. basic_regex<_Ch_type, _Rx_traits>& __rhs)
  763. { __lhs.swap(__rhs); }
  764. // C++11 28.9 [re.submatch] Class template sub_match
  765. /**
  766. * A sequence of characters matched by a particular marked sub-expression.
  767. *
  768. * An object of this class is essentially a pair of iterators marking a
  769. * matched subexpression within a regular expression pattern match. Such
  770. * objects can be converted to and compared with std::basic_string objects
  771. * of a similar base character type as the pattern matched by the regular
  772. * expression.
  773. *
  774. * The iterators that make up the pair are the usual half-open interval
  775. * referencing the actual original pattern matched.
  776. */
  777. template<typename _BiIter>
  778. class sub_match : public std::pair<_BiIter, _BiIter>
  779. {
  780. typedef iterator_traits<_BiIter> __iter_traits;
  781. public:
  782. typedef typename __iter_traits::value_type value_type;
  783. typedef typename __iter_traits::difference_type difference_type;
  784. typedef _BiIter iterator;
  785. typedef basic_string<value_type> string_type;
  786. bool matched;
  787. constexpr sub_match() noexcept : matched() { }
  788. /// Gets the length of the matching sequence.
  789. difference_type
  790. length() const noexcept
  791. { return this->matched ? std::distance(this->first, this->second) : 0; }
  792. /**
  793. * @brief Gets the matching sequence as a string.
  794. *
  795. * @returns the matching sequence as a string.
  796. *
  797. * This is the implicit conversion operator. It is identical to the
  798. * str() member function except that it will want to pop up in
  799. * unexpected places and cause a great deal of confusion and cursing
  800. * from the unwary.
  801. */
  802. operator string_type() const
  803. { return str(); }
  804. /**
  805. * @brief Gets the matching sequence as a string.
  806. *
  807. * @returns the matching sequence as a string.
  808. */
  809. string_type
  810. str() const
  811. {
  812. return this->matched
  813. ? string_type(this->first, this->second)
  814. : string_type();
  815. }
  816. /**
  817. * @brief Compares this and another matched sequence.
  818. *
  819. * @param __s Another matched sequence to compare to this one.
  820. *
  821. * @retval negative This matched sequence will collate before `__s`.
  822. * @retval zero This matched sequence is equivalent to `__s`.
  823. * @retval positive This matched sequence will collate after `__s`.
  824. */
  825. int
  826. compare(const sub_match& __s) const
  827. { return this->_M_str().compare(__s._M_str()); }
  828. /**
  829. * @{
  830. * @brief Compares this `sub_match` to a string.
  831. *
  832. * @param __s A string to compare to this `sub_match`.
  833. *
  834. * @retval negative This matched sequence will collate before `__s`.
  835. * @retval zero This matched sequence is equivalent to `__s`.
  836. * @retval positive This matched sequence will collate after `__s`.
  837. */
  838. int
  839. compare(const string_type& __s) const
  840. { return this->_M_str().compare(__s); }
  841. int
  842. compare(const value_type* __s) const
  843. { return this->_M_str().compare(__s); }
  844. /// @}
  845. /// @cond undocumented
  846. // Non-standard, used by comparison operators
  847. int
  848. _M_compare(const value_type* __s, size_t __n) const
  849. { return this->_M_str().compare({__s, __n}); }
  850. /// @endcond
  851. private:
  852. // Simplified basic_string_view for C++11
  853. struct __string_view
  854. {
  855. using traits_type = typename string_type::traits_type;
  856. __string_view() = default;
  857. __string_view(const value_type* __s, size_t __n) noexcept
  858. : _M_data(__s), _M_len(__n) { }
  859. __string_view(const value_type* __s) noexcept
  860. : _M_data(__s), _M_len(traits_type::length(__s)) { }
  861. __string_view(const string_type& __s) noexcept
  862. : _M_data(__s.data()), _M_len(__s.length()) { }
  863. int
  864. compare(__string_view __s) const noexcept
  865. {
  866. if (const size_t __n = std::min(_M_len, __s._M_len))
  867. if (int __ret = traits_type::compare(_M_data, __s._M_data, __n))
  868. return __ret;
  869. using __limits = __gnu_cxx::__int_traits<int>;
  870. const difference_type __diff = _M_len - __s._M_len;
  871. if (__diff > __limits::__max)
  872. return __limits::__max;
  873. if (__diff < __limits::__min)
  874. return __limits::__min;
  875. return static_cast<int>(__diff);
  876. }
  877. private:
  878. const value_type* _M_data = nullptr;
  879. size_t _M_len = 0;
  880. };
  881. // Create a __string_view over the iterator range.
  882. template<typename _Iter = _BiIter>
  883. __enable_if_t<__detail::__is_contiguous_iter<_Iter>::value,
  884. __string_view>
  885. _M_str() const noexcept
  886. {
  887. if (this->matched)
  888. if (size_t __len = this->second - this->first)
  889. return { std::__addressof(*this->first), __len };
  890. return {};
  891. }
  892. // Create a temporary string that can be converted to __string_view.
  893. template<typename _Iter = _BiIter>
  894. __enable_if_t<!__detail::__is_contiguous_iter<_Iter>::value,
  895. string_type>
  896. _M_str() const
  897. { return str(); }
  898. };
  899. /** @brief Standard regex submatch over a C-style null-terminated string. */
  900. typedef sub_match<const char*> csub_match;
  901. /** @brief Standard regex submatch over a standard string. */
  902. typedef sub_match<string::const_iterator> ssub_match;
  903. #ifdef _GLIBCXX_USE_WCHAR_T
  904. /** @brief Regex submatch over a C-style null-terminated wide string. */
  905. typedef sub_match<const wchar_t*> wcsub_match;
  906. /** @brief Regex submatch over a standard wide string. */
  907. typedef sub_match<wstring::const_iterator> wssub_match;
  908. #endif
  909. // [7.9.2] sub_match non-member operators
  910. /// @relates sub_match @{
  911. /**
  912. * @brief Tests the equivalence of two regular expression submatches.
  913. * @param __lhs First regular expression submatch.
  914. * @param __rhs Second regular expression submatch.
  915. * @returns true if @a __lhs is equivalent to @a __rhs, false otherwise.
  916. */
  917. template<typename _BiIter>
  918. inline bool
  919. operator==(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs)
  920. { return __lhs.compare(__rhs) == 0; }
  921. #if __cpp_lib_three_way_comparison
  922. /**
  923. * @brief Three-way comparison of two regular expression submatches.
  924. * @param __lhs First regular expression submatch.
  925. * @param __rhs Second regular expression submatch.
  926. * @returns A value indicating whether `__lhs` is less than, equal to,
  927. * greater than, or incomparable with `__rhs`.
  928. */
  929. template<typename _BiIter>
  930. inline auto
  931. operator<=>(const sub_match<_BiIter>& __lhs,
  932. const sub_match<_BiIter>& __rhs)
  933. noexcept(__detail::__is_contiguous_iter<_BiIter>::value)
  934. {
  935. using _Tr = char_traits<typename iterator_traits<_BiIter>::value_type>;
  936. return __detail::__char_traits_cmp_cat<_Tr>(__lhs.compare(__rhs));
  937. }
  938. #else
  939. /**
  940. * @brief Tests the inequivalence of two regular expression submatches.
  941. * @param __lhs First regular expression submatch.
  942. * @param __rhs Second regular expression submatch.
  943. * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise.
  944. */
  945. template<typename _BiIter>
  946. inline bool
  947. operator!=(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs)
  948. { return __lhs.compare(__rhs) != 0; }
  949. /**
  950. * @brief Tests the ordering of two regular expression submatches.
  951. * @param __lhs First regular expression submatch.
  952. * @param __rhs Second regular expression submatch.
  953. * @returns true if @a __lhs precedes @a __rhs, false otherwise.
  954. */
  955. template<typename _BiIter>
  956. inline bool
  957. operator<(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs)
  958. { return __lhs.compare(__rhs) < 0; }
  959. /**
  960. * @brief Tests the ordering of two regular expression submatches.
  961. * @param __lhs First regular expression submatch.
  962. * @param __rhs Second regular expression submatch.
  963. * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
  964. */
  965. template<typename _BiIter>
  966. inline bool
  967. operator<=(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs)
  968. { return __lhs.compare(__rhs) <= 0; }
  969. /**
  970. * @brief Tests the ordering of two regular expression submatches.
  971. * @param __lhs First regular expression submatch.
  972. * @param __rhs Second regular expression submatch.
  973. * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
  974. */
  975. template<typename _BiIter>
  976. inline bool
  977. operator>=(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs)
  978. { return __lhs.compare(__rhs) >= 0; }
  979. /**
  980. * @brief Tests the ordering of two regular expression submatches.
  981. * @param __lhs First regular expression submatch.
  982. * @param __rhs Second regular expression submatch.
  983. * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
  984. */
  985. template<typename _BiIter>
  986. inline bool
  987. operator>(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs)
  988. { return __lhs.compare(__rhs) > 0; }
  989. #endif // three-way comparison
  990. /// @cond undocumented
  991. // Alias for a basic_string that can be compared to a sub_match.
  992. template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
  993. using __sub_match_string = basic_string<
  994. typename iterator_traits<_Bi_iter>::value_type,
  995. _Ch_traits, _Ch_alloc>;
  996. /// @endcond
  997. #if ! __cpp_lib_three_way_comparison
  998. /**
  999. * @brief Tests the equivalence of a string and a regular expression
  1000. * submatch.
  1001. * @param __lhs A string.
  1002. * @param __rhs A regular expression submatch.
  1003. * @returns true if @a __lhs is equivalent to @a __rhs, false otherwise.
  1004. */
  1005. template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
  1006. inline bool
  1007. operator==(const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __lhs,
  1008. const sub_match<_Bi_iter>& __rhs)
  1009. { return __rhs._M_compare(__lhs.data(), __lhs.size()) == 0; }
  1010. /**
  1011. * @brief Tests the inequivalence of a string and a regular expression
  1012. * submatch.
  1013. * @param __lhs A string.
  1014. * @param __rhs A regular expression submatch.
  1015. * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise.
  1016. */
  1017. template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
  1018. inline bool
  1019. operator!=(const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __lhs,
  1020. const sub_match<_Bi_iter>& __rhs)
  1021. { return !(__lhs == __rhs); }
  1022. /**
  1023. * @brief Tests the ordering of a string and a regular expression submatch.
  1024. * @param __lhs A string.
  1025. * @param __rhs A regular expression submatch.
  1026. * @returns true if @a __lhs precedes @a __rhs, false otherwise.
  1027. */
  1028. template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
  1029. inline bool
  1030. operator<(const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __lhs,
  1031. const sub_match<_Bi_iter>& __rhs)
  1032. { return __rhs._M_compare(__lhs.data(), __lhs.size()) > 0; }
  1033. /**
  1034. * @brief Tests the ordering of a string and a regular expression submatch.
  1035. * @param __lhs A string.
  1036. * @param __rhs A regular expression submatch.
  1037. * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
  1038. */
  1039. template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
  1040. inline bool
  1041. operator>(const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __lhs,
  1042. const sub_match<_Bi_iter>& __rhs)
  1043. { return __rhs < __lhs; }
  1044. /**
  1045. * @brief Tests the ordering of a string and a regular expression submatch.
  1046. * @param __lhs A string.
  1047. * @param __rhs A regular expression submatch.
  1048. * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
  1049. */
  1050. template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
  1051. inline bool
  1052. operator>=(const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __lhs,
  1053. const sub_match<_Bi_iter>& __rhs)
  1054. { return !(__lhs < __rhs); }
  1055. /**
  1056. * @brief Tests the ordering of a string and a regular expression submatch.
  1057. * @param __lhs A string.
  1058. * @param __rhs A regular expression submatch.
  1059. * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
  1060. */
  1061. template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
  1062. inline bool
  1063. operator<=(const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __lhs,
  1064. const sub_match<_Bi_iter>& __rhs)
  1065. { return !(__rhs < __lhs); }
  1066. #endif // three-way comparison
  1067. /**
  1068. * @brief Tests the equivalence of a regular expression submatch and a
  1069. * string.
  1070. * @param __lhs A regular expression submatch.
  1071. * @param __rhs A string.
  1072. * @returns true if @a __lhs is equivalent to @a __rhs, false otherwise.
  1073. */
  1074. template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
  1075. inline bool
  1076. operator==(const sub_match<_Bi_iter>& __lhs,
  1077. const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __rhs)
  1078. { return __lhs._M_compare(__rhs.data(), __rhs.size()) == 0; }
  1079. #if __cpp_lib_three_way_comparison
  1080. /**
  1081. * @brief Three-way comparison of a regular expression submatch and a string.
  1082. * @param __lhs A regular expression submatch.
  1083. * @param __rhs A string.
  1084. * @returns A value indicating whether `__lhs` is less than, equal to,
  1085. * greater than, or incomparable with `__rhs`.
  1086. */
  1087. template<typename _Bi_iter, typename _Ch_traits, typename _Alloc>
  1088. inline auto
  1089. operator<=>(const sub_match<_Bi_iter>& __lhs,
  1090. const __sub_match_string<_Bi_iter, _Ch_traits, _Alloc>& __rhs)
  1091. noexcept(__detail::__is_contiguous_iter<_Bi_iter>::value)
  1092. {
  1093. return __detail::__char_traits_cmp_cat<_Ch_traits>(
  1094. __lhs._M_compare(__rhs.data(), __rhs.size()));
  1095. }
  1096. #else
  1097. /**
  1098. * @brief Tests the inequivalence of a regular expression submatch and a
  1099. * string.
  1100. * @param __lhs A regular expression submatch.
  1101. * @param __rhs A string.
  1102. * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise.
  1103. */
  1104. template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
  1105. inline bool
  1106. operator!=(const sub_match<_Bi_iter>& __lhs,
  1107. const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __rhs)
  1108. { return !(__lhs == __rhs); }
  1109. /**
  1110. * @brief Tests the ordering of a regular expression submatch and a string.
  1111. * @param __lhs A regular expression submatch.
  1112. * @param __rhs A string.
  1113. * @returns true if @a __lhs precedes @a __rhs, false otherwise.
  1114. */
  1115. template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
  1116. inline bool
  1117. operator<(const sub_match<_Bi_iter>& __lhs,
  1118. const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __rhs)
  1119. { return __lhs._M_compare(__rhs.data(), __rhs.size()) < 0; }
  1120. /**
  1121. * @brief Tests the ordering of a regular expression submatch and a string.
  1122. * @param __lhs A regular expression submatch.
  1123. * @param __rhs A string.
  1124. * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
  1125. */
  1126. template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
  1127. inline bool
  1128. operator>(const sub_match<_Bi_iter>& __lhs,
  1129. const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __rhs)
  1130. { return __rhs < __lhs; }
  1131. /**
  1132. * @brief Tests the ordering of a regular expression submatch and a string.
  1133. * @param __lhs A regular expression submatch.
  1134. * @param __rhs A string.
  1135. * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
  1136. */
  1137. template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
  1138. inline bool
  1139. operator>=(const sub_match<_Bi_iter>& __lhs,
  1140. const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __rhs)
  1141. { return !(__lhs < __rhs); }
  1142. /**
  1143. * @brief Tests the ordering of a regular expression submatch and a string.
  1144. * @param __lhs A regular expression submatch.
  1145. * @param __rhs A string.
  1146. * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
  1147. */
  1148. template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
  1149. inline bool
  1150. operator<=(const sub_match<_Bi_iter>& __lhs,
  1151. const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __rhs)
  1152. { return !(__rhs < __lhs); }
  1153. /**
  1154. * @brief Tests the equivalence of a C string and a regular expression
  1155. * submatch.
  1156. * @param __lhs A null-terminated string.
  1157. * @param __rhs A regular expression submatch.
  1158. * @returns true if @a __lhs is equivalent to @a __rhs, false otherwise.
  1159. */
  1160. template<typename _Bi_iter>
  1161. inline bool
  1162. operator==(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
  1163. const sub_match<_Bi_iter>& __rhs)
  1164. { return __rhs.compare(__lhs) == 0; }
  1165. /**
  1166. * @brief Tests the inequivalence of a C string and a regular
  1167. * expression submatch.
  1168. * @param __lhs A null-terminated string.
  1169. * @param __rhs A regular expression submatch.
  1170. * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise.
  1171. */
  1172. template<typename _Bi_iter>
  1173. inline bool
  1174. operator!=(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
  1175. const sub_match<_Bi_iter>& __rhs)
  1176. { return !(__lhs == __rhs); }
  1177. /**
  1178. * @brief Tests the ordering of a C string and a regular expression submatch.
  1179. * @param __lhs A null-terminated string.
  1180. * @param __rhs A regular expression submatch.
  1181. * @returns true if @a __lhs precedes @a __rhs, false otherwise.
  1182. */
  1183. template<typename _Bi_iter>
  1184. inline bool
  1185. operator<(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
  1186. const sub_match<_Bi_iter>& __rhs)
  1187. { return __rhs.compare(__lhs) > 0; }
  1188. /**
  1189. * @brief Tests the ordering of a C string and a regular expression submatch.
  1190. * @param __lhs A null-terminated string.
  1191. * @param __rhs A regular expression submatch.
  1192. * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
  1193. */
  1194. template<typename _Bi_iter>
  1195. inline bool
  1196. operator>(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
  1197. const sub_match<_Bi_iter>& __rhs)
  1198. { return __rhs < __lhs; }
  1199. /**
  1200. * @brief Tests the ordering of a C string and a regular expression submatch.
  1201. * @param __lhs A null-terminated string.
  1202. * @param __rhs A regular expression submatch.
  1203. * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
  1204. */
  1205. template<typename _Bi_iter>
  1206. inline bool
  1207. operator>=(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
  1208. const sub_match<_Bi_iter>& __rhs)
  1209. { return !(__lhs < __rhs); }
  1210. /**
  1211. * @brief Tests the ordering of a C string and a regular expression submatch.
  1212. * @param __lhs A null-terminated string.
  1213. * @param __rhs A regular expression submatch.
  1214. * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
  1215. */
  1216. template<typename _Bi_iter>
  1217. inline bool
  1218. operator<=(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
  1219. const sub_match<_Bi_iter>& __rhs)
  1220. { return !(__rhs < __lhs); }
  1221. #endif // three-way comparison
  1222. /**
  1223. * @brief Tests the equivalence of a regular expression submatch and a C
  1224. * string.
  1225. * @param __lhs A regular expression submatch.
  1226. * @param __rhs A null-terminated string.
  1227. * @returns true if @a __lhs is equivalent to @a __rhs, false otherwise.
  1228. */
  1229. template<typename _Bi_iter>
  1230. inline bool
  1231. operator==(const sub_match<_Bi_iter>& __lhs,
  1232. typename iterator_traits<_Bi_iter>::value_type const* __rhs)
  1233. { return __lhs.compare(__rhs) == 0; }
  1234. #if __cpp_lib_three_way_comparison
  1235. /**
  1236. * @brief Three-way comparison of a regular expression submatch and a C
  1237. * string.
  1238. * @param __lhs A regular expression submatch.
  1239. * @param __rhs A null-terminated string.
  1240. * @returns A value indicating whether `__lhs` is less than, equal to,
  1241. * greater than, or incomparable with `__rhs`.
  1242. */
  1243. template<typename _Bi_iter>
  1244. inline auto
  1245. operator<=>(const sub_match<_Bi_iter>& __lhs,
  1246. typename iterator_traits<_Bi_iter>::value_type const* __rhs)
  1247. noexcept(__detail::__is_contiguous_iter<_Bi_iter>::value)
  1248. {
  1249. using _Tr = char_traits<typename iterator_traits<_Bi_iter>::value_type>;
  1250. return __detail::__char_traits_cmp_cat<_Tr>(__lhs.compare(__rhs));
  1251. }
  1252. #else
  1253. /**
  1254. * @brief Tests the inequivalence of a regular expression submatch and a
  1255. * string.
  1256. * @param __lhs A regular expression submatch.
  1257. * @param __rhs A null-terminated string.
  1258. * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise.
  1259. */
  1260. template<typename _Bi_iter>
  1261. inline bool
  1262. operator!=(const sub_match<_Bi_iter>& __lhs,
  1263. typename iterator_traits<_Bi_iter>::value_type const* __rhs)
  1264. { return !(__lhs == __rhs); }
  1265. /**
  1266. * @brief Tests the ordering of a regular expression submatch and a C string.
  1267. * @param __lhs A regular expression submatch.
  1268. * @param __rhs A null-terminated string.
  1269. * @returns true if @a __lhs precedes @a __rhs, false otherwise.
  1270. */
  1271. template<typename _Bi_iter>
  1272. inline bool
  1273. operator<(const sub_match<_Bi_iter>& __lhs,
  1274. typename iterator_traits<_Bi_iter>::value_type const* __rhs)
  1275. { return __lhs.compare(__rhs) < 0; }
  1276. /**
  1277. * @brief Tests the ordering of a regular expression submatch and a C string.
  1278. * @param __lhs A regular expression submatch.
  1279. * @param __rhs A null-terminated string.
  1280. * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
  1281. */
  1282. template<typename _Bi_iter>
  1283. inline bool
  1284. operator>(const sub_match<_Bi_iter>& __lhs,
  1285. typename iterator_traits<_Bi_iter>::value_type const* __rhs)
  1286. { return __rhs < __lhs; }
  1287. /**
  1288. * @brief Tests the ordering of a regular expression submatch and a C string.
  1289. * @param __lhs A regular expression submatch.
  1290. * @param __rhs A null-terminated string.
  1291. * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
  1292. */
  1293. template<typename _Bi_iter>
  1294. inline bool
  1295. operator>=(const sub_match<_Bi_iter>& __lhs,
  1296. typename iterator_traits<_Bi_iter>::value_type const* __rhs)
  1297. { return !(__lhs < __rhs); }
  1298. /**
  1299. * @brief Tests the ordering of a regular expression submatch and a C string.
  1300. * @param __lhs A regular expression submatch.
  1301. * @param __rhs A null-terminated string.
  1302. * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
  1303. */
  1304. template<typename _Bi_iter>
  1305. inline bool
  1306. operator<=(const sub_match<_Bi_iter>& __lhs,
  1307. typename iterator_traits<_Bi_iter>::value_type const* __rhs)
  1308. { return !(__rhs < __lhs); }
  1309. /**
  1310. * @brief Tests the equivalence of a character and a regular expression
  1311. * submatch.
  1312. * @param __lhs A character.
  1313. * @param __rhs A regular expression submatch.
  1314. * @returns true if @a __lhs is equivalent to @a __rhs, false otherwise.
  1315. */
  1316. template<typename _Bi_iter>
  1317. inline bool
  1318. operator==(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
  1319. const sub_match<_Bi_iter>& __rhs)
  1320. { return __rhs._M_compare(std::__addressof(__lhs), 1) == 0; }
  1321. /**
  1322. * @brief Tests the inequivalence of a character and a regular expression
  1323. * submatch.
  1324. * @param __lhs A character.
  1325. * @param __rhs A regular expression submatch.
  1326. * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise.
  1327. */
  1328. template<typename _Bi_iter>
  1329. inline bool
  1330. operator!=(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
  1331. const sub_match<_Bi_iter>& __rhs)
  1332. { return !(__lhs == __rhs); }
  1333. /**
  1334. * @brief Tests the ordering of a character and a regular expression
  1335. * submatch.
  1336. * @param __lhs A character.
  1337. * @param __rhs A regular expression submatch.
  1338. * @returns true if @a __lhs precedes @a __rhs, false otherwise.
  1339. */
  1340. template<typename _Bi_iter>
  1341. inline bool
  1342. operator<(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
  1343. const sub_match<_Bi_iter>& __rhs)
  1344. { return __rhs._M_compare(std::__addressof(__lhs), 1) > 0; }
  1345. /**
  1346. * @brief Tests the ordering of a character and a regular expression
  1347. * submatch.
  1348. * @param __lhs A character.
  1349. * @param __rhs A regular expression submatch.
  1350. * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
  1351. */
  1352. template<typename _Bi_iter>
  1353. inline bool
  1354. operator>(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
  1355. const sub_match<_Bi_iter>& __rhs)
  1356. { return __rhs < __lhs; }
  1357. /**
  1358. * @brief Tests the ordering of a character and a regular expression
  1359. * submatch.
  1360. * @param __lhs A character.
  1361. * @param __rhs A regular expression submatch.
  1362. * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
  1363. */
  1364. template<typename _Bi_iter>
  1365. inline bool
  1366. operator>=(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
  1367. const sub_match<_Bi_iter>& __rhs)
  1368. { return !(__lhs < __rhs); }
  1369. /**
  1370. * @brief Tests the ordering of a character and a regular expression
  1371. * submatch.
  1372. * @param __lhs A character.
  1373. * @param __rhs A regular expression submatch.
  1374. * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
  1375. */
  1376. template<typename _Bi_iter>
  1377. inline bool
  1378. operator<=(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
  1379. const sub_match<_Bi_iter>& __rhs)
  1380. { return !(__rhs < __lhs); }
  1381. #endif // three-way comparison
  1382. /**
  1383. * @brief Tests the equivalence of a regular expression submatch and a
  1384. * character.
  1385. * @param __lhs A regular expression submatch.
  1386. * @param __rhs A character.
  1387. * @returns true if @a __lhs is equivalent to @a __rhs, false otherwise.
  1388. */
  1389. template<typename _Bi_iter>
  1390. inline bool
  1391. operator==(const sub_match<_Bi_iter>& __lhs,
  1392. typename iterator_traits<_Bi_iter>::value_type const& __rhs)
  1393. { return __lhs._M_compare(std::__addressof(__rhs), 1) == 0; }
  1394. #if __cpp_lib_three_way_comparison
  1395. /**
  1396. * @brief Three-way comparison of a regular expression submatch and a
  1397. * character.
  1398. * @param __lhs A regular expression submatch.
  1399. * @param __rhs A character.
  1400. * @returns A value indicating whether `__lhs` is less than, equal to,
  1401. * greater than, or incomparable with `__rhs`.
  1402. */
  1403. template<typename _Bi_iter>
  1404. inline auto
  1405. operator<=>(const sub_match<_Bi_iter>& __lhs,
  1406. typename iterator_traits<_Bi_iter>::value_type const& __rhs)
  1407. noexcept(__detail::__is_contiguous_iter<_Bi_iter>::value)
  1408. {
  1409. using _Tr = char_traits<typename iterator_traits<_Bi_iter>::value_type>;
  1410. return __detail::__char_traits_cmp_cat<_Tr>(
  1411. __lhs._M_compare(std::__addressof(__rhs), 1));
  1412. }
  1413. #else
  1414. /**
  1415. * @brief Tests the inequivalence of a regular expression submatch and a
  1416. * character.
  1417. * @param __lhs A regular expression submatch.
  1418. * @param __rhs A character.
  1419. * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise.
  1420. */
  1421. template<typename _Bi_iter>
  1422. inline bool
  1423. operator!=(const sub_match<_Bi_iter>& __lhs,
  1424. typename iterator_traits<_Bi_iter>::value_type const& __rhs)
  1425. { return !(__lhs == __rhs); }
  1426. /**
  1427. * @brief Tests the ordering of a regular expression submatch and a
  1428. * character.
  1429. * @param __lhs A regular expression submatch.
  1430. * @param __rhs A character.
  1431. * @returns true if @a __lhs precedes @a __rhs, false otherwise.
  1432. */
  1433. template<typename _Bi_iter>
  1434. inline bool
  1435. operator<(const sub_match<_Bi_iter>& __lhs,
  1436. typename iterator_traits<_Bi_iter>::value_type const& __rhs)
  1437. { return __lhs._M_compare(std::__addressof(__rhs), 1) < 0; }
  1438. /**
  1439. * @brief Tests the ordering of a regular expression submatch and a
  1440. * character.
  1441. * @param __lhs A regular expression submatch.
  1442. * @param __rhs A character.
  1443. * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
  1444. */
  1445. template<typename _Bi_iter>
  1446. inline bool
  1447. operator>(const sub_match<_Bi_iter>& __lhs,
  1448. typename iterator_traits<_Bi_iter>::value_type const& __rhs)
  1449. { return __rhs < __lhs; }
  1450. /**
  1451. * @brief Tests the ordering of a regular expression submatch and a
  1452. * character.
  1453. * @param __lhs A regular expression submatch.
  1454. * @param __rhs A character.
  1455. * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
  1456. */
  1457. template<typename _Bi_iter>
  1458. inline bool
  1459. operator>=(const sub_match<_Bi_iter>& __lhs,
  1460. typename iterator_traits<_Bi_iter>::value_type const& __rhs)
  1461. { return !(__lhs < __rhs); }
  1462. /**
  1463. * @brief Tests the ordering of a regular expression submatch and a
  1464. * character.
  1465. * @param __lhs A regular expression submatch.
  1466. * @param __rhs A character.
  1467. * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
  1468. */
  1469. template<typename _Bi_iter>
  1470. inline bool
  1471. operator<=(const sub_match<_Bi_iter>& __lhs,
  1472. typename iterator_traits<_Bi_iter>::value_type const& __rhs)
  1473. { return !(__rhs < __lhs); }
  1474. #endif // three-way comparison
  1475. /**
  1476. * @brief Inserts a matched string into an output stream.
  1477. *
  1478. * @param __os The output stream.
  1479. * @param __m A submatch string.
  1480. *
  1481. * @returns the output stream with the submatch string inserted.
  1482. */
  1483. template<typename _Ch_type, typename _Ch_traits, typename _Bi_iter>
  1484. inline
  1485. basic_ostream<_Ch_type, _Ch_traits>&
  1486. operator<<(basic_ostream<_Ch_type, _Ch_traits>& __os,
  1487. const sub_match<_Bi_iter>& __m)
  1488. { return __os << __m.str(); }
  1489. /// @} relates sub_match
  1490. // [7.10] Class template match_results
  1491. /**
  1492. * @brief The results of a match or search operation.
  1493. *
  1494. * A collection of character sequences representing the result of a regular
  1495. * expression match. Storage for the collection is allocated and freed as
  1496. * necessary by the member functions of class template match_results.
  1497. *
  1498. * This class satisfies the Sequence requirements, with the exception that
  1499. * only the operations defined for a const-qualified Sequence are supported.
  1500. *
  1501. * The sub_match object stored at index 0 represents sub-expression 0, i.e.
  1502. * the whole match. In this case the %sub_match member matched is always true.
  1503. * The sub_match object stored at index n denotes what matched the marked
  1504. * sub-expression n within the matched expression. If the sub-expression n
  1505. * participated in a regular expression match then the %sub_match member
  1506. * matched evaluates to true, and members first and second denote the range
  1507. * of characters [first, second) which formed that match. Otherwise matched
  1508. * is false, and members first and second point to the end of the sequence
  1509. * that was searched.
  1510. */
  1511. template<typename _Bi_iter,
  1512. typename _Alloc = allocator<sub_match<_Bi_iter> > >
  1513. class match_results
  1514. : private std::vector<sub_match<_Bi_iter>, _Alloc>
  1515. {
  1516. private:
  1517. /*
  1518. * The vector base is empty if this does not represent a match (!ready());
  1519. * Otherwise if it's a match failure, it contains 3 elements:
  1520. * [0] unmatched
  1521. * [1] prefix
  1522. * [2] suffix
  1523. * Otherwise it contains n+4 elements where n is the number of marked
  1524. * sub-expressions:
  1525. * [0] entire match
  1526. * [1] 1st marked subexpression
  1527. * ...
  1528. * [n] nth marked subexpression
  1529. * [n+1] unmatched
  1530. * [n+2] prefix
  1531. * [n+3] suffix
  1532. */
  1533. typedef std::vector<sub_match<_Bi_iter>, _Alloc> _Base_type;
  1534. typedef std::iterator_traits<_Bi_iter> __iter_traits;
  1535. typedef regex_constants::match_flag_type match_flag_type;
  1536. public:
  1537. /**
  1538. * @name 28.10 Public Types
  1539. */
  1540. ///@{
  1541. typedef sub_match<_Bi_iter> value_type;
  1542. typedef const value_type& const_reference;
  1543. typedef value_type& reference;
  1544. typedef typename _Base_type::const_iterator const_iterator;
  1545. typedef const_iterator iterator;
  1546. typedef typename __iter_traits::difference_type difference_type;
  1547. typedef typename allocator_traits<_Alloc>::size_type size_type;
  1548. typedef _Alloc allocator_type;
  1549. typedef typename __iter_traits::value_type char_type;
  1550. typedef std::basic_string<char_type> string_type;
  1551. ///@}
  1552. public:
  1553. /**
  1554. * @name 28.10.1 Construction, Copying, and Destruction
  1555. */
  1556. ///@{
  1557. /**
  1558. * @brief Constructs a default %match_results container.
  1559. * @post size() returns 0 and str() returns an empty string.
  1560. */
  1561. match_results() : match_results(_Alloc()) { }
  1562. /**
  1563. * @brief Constructs a default %match_results container.
  1564. * @post size() returns 0 and str() returns an empty string.
  1565. */
  1566. explicit
  1567. match_results(const _Alloc& __a) noexcept
  1568. : _Base_type(__a)
  1569. { }
  1570. /**
  1571. * @brief Copy constructs a %match_results.
  1572. */
  1573. match_results(const match_results&) = default;
  1574. /**
  1575. * @brief Move constructs a %match_results.
  1576. */
  1577. match_results(match_results&&) noexcept = default;
  1578. /**
  1579. * @brief Assigns rhs to *this.
  1580. */
  1581. match_results&
  1582. operator=(const match_results&) = default;
  1583. /**
  1584. * @brief Move-assigns rhs to *this.
  1585. */
  1586. match_results&
  1587. operator=(match_results&&) = default;
  1588. /**
  1589. * @brief Destroys a %match_results object.
  1590. */
  1591. ~match_results() = default;
  1592. ///@}
  1593. // 28.10.2, state:
  1594. /**
  1595. * @brief Indicates if the %match_results is ready.
  1596. * @retval true The object has a fully-established result state.
  1597. * @retval false The object is not ready.
  1598. */
  1599. bool ready() const noexcept { return !_Base_type::empty(); }
  1600. /**
  1601. * @name 28.10.2 Size
  1602. */
  1603. ///@{
  1604. /**
  1605. * @brief Gets the number of matches and submatches.
  1606. *
  1607. * The number of matches for a given regular expression will be either 0
  1608. * if there was no match or mark_count() + 1 if a match was successful.
  1609. * Some matches may be empty.
  1610. *
  1611. * @returns the number of matches found.
  1612. */
  1613. size_type
  1614. size() const noexcept
  1615. { return _Base_type::empty() ? 0 : _Base_type::size() - 3; }
  1616. size_type
  1617. max_size() const noexcept
  1618. { return _Base_type::max_size() - 3; }
  1619. /**
  1620. * @brief Indicates if the %match_results contains no results.
  1621. * @retval true The %match_results object is empty.
  1622. * @retval false The %match_results object is not empty.
  1623. */
  1624. _GLIBCXX_NODISCARD bool
  1625. empty() const noexcept
  1626. { return size() == 0; }
  1627. ///@}
  1628. /**
  1629. * @name 28.10.4 Element Access
  1630. */
  1631. ///@{
  1632. /**
  1633. * @brief Gets the length of the indicated submatch.
  1634. * @param __sub indicates the submatch.
  1635. * @pre ready() == true
  1636. *
  1637. * This function returns the length of the indicated submatch, or the
  1638. * length of the entire match if @p __sub is zero (the default).
  1639. */
  1640. difference_type
  1641. length(size_type __sub = 0) const
  1642. { return (*this)[__sub].length(); }
  1643. /**
  1644. * @brief Gets the offset of the beginning of the indicated submatch.
  1645. * @param __sub indicates the submatch.
  1646. * @pre ready() == true
  1647. *
  1648. * This function returns the offset from the beginning of the target
  1649. * sequence to the beginning of the submatch, unless the value of @p __sub
  1650. * is zero (the default), in which case this function returns the offset
  1651. * from the beginning of the target sequence to the beginning of the
  1652. * match.
  1653. */
  1654. difference_type
  1655. position(size_type __sub = 0) const
  1656. { return std::distance(_M_begin, (*this)[__sub].first); }
  1657. /**
  1658. * @brief Gets the match or submatch converted to a string type.
  1659. * @param __sub indicates the submatch.
  1660. * @pre ready() == true
  1661. *
  1662. * This function gets the submatch (or match, if @p __sub is
  1663. * zero) extracted from the target range and converted to the
  1664. * associated string type.
  1665. */
  1666. string_type
  1667. str(size_type __sub = 0) const
  1668. { return string_type((*this)[__sub]); }
  1669. /**
  1670. * @brief Gets a %sub_match reference for the match or submatch.
  1671. * @param __sub indicates the submatch.
  1672. * @pre ready() == true
  1673. *
  1674. * This function gets a reference to the indicated submatch, or
  1675. * the entire match if @p __sub is zero.
  1676. *
  1677. * If @p __sub >= size() then this function returns a %sub_match with a
  1678. * special value indicating no submatch.
  1679. */
  1680. const_reference
  1681. operator[](size_type __sub) const
  1682. {
  1683. __glibcxx_assert( ready() );
  1684. return __sub < size()
  1685. ? _Base_type::operator[](__sub)
  1686. : _M_unmatched_sub();
  1687. }
  1688. /**
  1689. * @brief Gets a %sub_match representing the match prefix.
  1690. * @pre ready() == true
  1691. *
  1692. * This function gets a reference to a %sub_match object representing the
  1693. * part of the target range between the start of the target range and the
  1694. * start of the match.
  1695. */
  1696. const_reference
  1697. prefix() const
  1698. {
  1699. __glibcxx_assert( ready() );
  1700. return !empty() ? _M_prefix() : _M_unmatched_sub();
  1701. }
  1702. /**
  1703. * @brief Gets a %sub_match representing the match suffix.
  1704. * @pre ready() == true
  1705. *
  1706. * This function gets a reference to a %sub_match object representing the
  1707. * part of the target range between the end of the match and the end of
  1708. * the target range.
  1709. */
  1710. const_reference
  1711. suffix() const
  1712. {
  1713. __glibcxx_assert( ready() );
  1714. return !empty() ? _M_suffix() : _M_unmatched_sub();
  1715. }
  1716. /**
  1717. * @brief Gets an iterator to the start of the %sub_match collection.
  1718. */
  1719. const_iterator
  1720. begin() const noexcept
  1721. { return _Base_type::begin(); }
  1722. /**
  1723. * @brief Gets an iterator to the start of the %sub_match collection.
  1724. */
  1725. const_iterator
  1726. cbegin() const noexcept
  1727. { return this->begin(); }
  1728. /**
  1729. * @brief Gets an iterator to one-past-the-end of the collection.
  1730. */
  1731. const_iterator
  1732. end() const noexcept
  1733. { return _Base_type::end() - (empty() ? 0 : 3); }
  1734. /**
  1735. * @brief Gets an iterator to one-past-the-end of the collection.
  1736. */
  1737. const_iterator
  1738. cend() const noexcept
  1739. { return this->end(); }
  1740. ///@}
  1741. /**
  1742. * @name 28.10.5 Formatting
  1743. *
  1744. * These functions perform formatted substitution of the matched
  1745. * character sequences into their target. The format specifiers and
  1746. * escape sequences accepted by these functions are determined by
  1747. * their @p flags parameter as documented above.
  1748. */
  1749. ///@{
  1750. /**
  1751. * @pre ready() == true
  1752. */
  1753. template<typename _Out_iter>
  1754. _Out_iter
  1755. format(_Out_iter __out, const char_type* __fmt_first,
  1756. const char_type* __fmt_last,
  1757. match_flag_type __flags = regex_constants::format_default) const;
  1758. /**
  1759. * @pre ready() == true
  1760. */
  1761. template<typename _Out_iter, typename _St, typename _Sa>
  1762. _Out_iter
  1763. format(_Out_iter __out, const basic_string<char_type, _St, _Sa>& __fmt,
  1764. match_flag_type __flags = regex_constants::format_default) const
  1765. {
  1766. return format(__out, __fmt.data(), __fmt.data() + __fmt.size(),
  1767. __flags);
  1768. }
  1769. /**
  1770. * @pre ready() == true
  1771. */
  1772. template<typename _St, typename _Sa>
  1773. basic_string<char_type, _St, _Sa>
  1774. format(const basic_string<char_type, _St, _Sa>& __fmt,
  1775. match_flag_type __flags = regex_constants::format_default) const
  1776. {
  1777. basic_string<char_type, _St, _Sa> __result;
  1778. format(std::back_inserter(__result), __fmt, __flags);
  1779. return __result;
  1780. }
  1781. /**
  1782. * @pre ready() == true
  1783. */
  1784. string_type
  1785. format(const char_type* __fmt,
  1786. match_flag_type __flags = regex_constants::format_default) const
  1787. {
  1788. string_type __result;
  1789. format(std::back_inserter(__result),
  1790. __fmt,
  1791. __fmt + char_traits<char_type>::length(__fmt),
  1792. __flags);
  1793. return __result;
  1794. }
  1795. ///@}
  1796. /**
  1797. * @name 28.10.6 Allocator
  1798. */
  1799. ///@{
  1800. /**
  1801. * @brief Gets a copy of the allocator.
  1802. */
  1803. allocator_type
  1804. get_allocator() const noexcept
  1805. { return _Base_type::get_allocator(); }
  1806. ///@}
  1807. /**
  1808. * @name 28.10.7 Swap
  1809. */
  1810. ///@{
  1811. /**
  1812. * @brief Swaps the contents of two match_results.
  1813. */
  1814. void
  1815. swap(match_results& __that) noexcept
  1816. {
  1817. using std::swap;
  1818. _Base_type::swap(__that);
  1819. swap(_M_begin, __that._M_begin);
  1820. }
  1821. ///@}
  1822. private:
  1823. template<typename, typename, typename>
  1824. friend class regex_iterator;
  1825. /// @cond undocumented
  1826. template<typename, typename, typename, bool>
  1827. friend class __detail::_Executor;
  1828. template<typename _Bp, typename _Ap, typename _Cp, typename _Rp,
  1829. __detail::_RegexExecutorPolicy, bool>
  1830. friend bool
  1831. __detail::__regex_algo_impl(_Bp, _Bp, match_results<_Bp, _Ap>&,
  1832. const basic_regex<_Cp, _Rp>&,
  1833. regex_constants::match_flag_type);
  1834. // Reset contents to __size unmatched sub_match objects
  1835. // (plus additional objects for prefix, suffix and unmatched sub).
  1836. void
  1837. _M_resize(unsigned int __size)
  1838. { _Base_type::assign(__size + 3, sub_match<_Bi_iter>{}); }
  1839. // Set state to a failed match for the given past-the-end iterator.
  1840. void
  1841. _M_establish_failed_match(_Bi_iter __end)
  1842. {
  1843. sub_match<_Bi_iter> __sm;
  1844. __sm.first = __sm.second = __end;
  1845. _Base_type::assign(3, __sm);
  1846. }
  1847. const_reference
  1848. _M_unmatched_sub() const
  1849. { return _Base_type::operator[](_Base_type::size() - 3); }
  1850. sub_match<_Bi_iter>&
  1851. _M_unmatched_sub()
  1852. { return _Base_type::operator[](_Base_type::size() - 3); }
  1853. const_reference
  1854. _M_prefix() const
  1855. { return _Base_type::operator[](_Base_type::size() - 2); }
  1856. sub_match<_Bi_iter>&
  1857. _M_prefix()
  1858. { return _Base_type::operator[](_Base_type::size() - 2); }
  1859. const_reference
  1860. _M_suffix() const
  1861. { return _Base_type::operator[](_Base_type::size() - 1); }
  1862. sub_match<_Bi_iter>&
  1863. _M_suffix()
  1864. { return _Base_type::operator[](_Base_type::size() - 1); }
  1865. _Bi_iter _M_begin;
  1866. /// @endcond
  1867. };
  1868. typedef match_results<const char*> cmatch;
  1869. typedef match_results<string::const_iterator> smatch;
  1870. #ifdef _GLIBCXX_USE_WCHAR_T
  1871. typedef match_results<const wchar_t*> wcmatch;
  1872. typedef match_results<wstring::const_iterator> wsmatch;
  1873. #endif
  1874. // match_results comparisons
  1875. /**
  1876. * @brief Compares two match_results for equality.
  1877. * @returns true if the two objects refer to the same match,
  1878. * false otherwise.
  1879. */
  1880. template<typename _Bi_iter, typename _Alloc>
  1881. inline bool
  1882. operator==(const match_results<_Bi_iter, _Alloc>& __m1,
  1883. const match_results<_Bi_iter, _Alloc>& __m2)
  1884. {
  1885. if (__m1.ready() != __m2.ready())
  1886. return false;
  1887. if (!__m1.ready()) // both are not ready
  1888. return true;
  1889. if (__m1.empty() != __m2.empty())
  1890. return false;
  1891. if (__m1.empty()) // both are empty
  1892. return true;
  1893. return __m1.prefix() == __m2.prefix()
  1894. && __m1.size() == __m2.size()
  1895. && std::equal(__m1.begin(), __m1.end(), __m2.begin())
  1896. && __m1.suffix() == __m2.suffix();
  1897. }
  1898. #if ! __cpp_lib_three_way_comparison
  1899. /**
  1900. * @brief Compares two match_results for inequality.
  1901. * @returns true if the two objects do not refer to the same match,
  1902. * false otherwise.
  1903. */
  1904. template<typename _Bi_iter, class _Alloc>
  1905. inline bool
  1906. operator!=(const match_results<_Bi_iter, _Alloc>& __m1,
  1907. const match_results<_Bi_iter, _Alloc>& __m2)
  1908. { return !(__m1 == __m2); }
  1909. #endif
  1910. // [7.10.6] match_results swap
  1911. /**
  1912. * @brief Swaps two match results.
  1913. * @param __lhs A match result.
  1914. * @param __rhs A match result.
  1915. *
  1916. * The contents of the two match_results objects are swapped.
  1917. */
  1918. template<typename _Bi_iter, typename _Alloc>
  1919. inline void
  1920. swap(match_results<_Bi_iter, _Alloc>& __lhs,
  1921. match_results<_Bi_iter, _Alloc>& __rhs) noexcept
  1922. { __lhs.swap(__rhs); }
  1923. _GLIBCXX_END_NAMESPACE_CXX11
  1924. // [28.11.2] Function template regex_match
  1925. /**
  1926. * @name Matching, Searching, and Replacing
  1927. */
  1928. ///@{
  1929. /**
  1930. * @brief Determines if there is a match between the regular expression @p e
  1931. * and all of the character sequence [first, last).
  1932. *
  1933. * @param __s Start of the character sequence to match.
  1934. * @param __e One-past-the-end of the character sequence to match.
  1935. * @param __m The match results.
  1936. * @param __re The regular expression.
  1937. * @param __flags Controls how the regular expression is matched.
  1938. *
  1939. * @retval true A match exists.
  1940. * @retval false Otherwise.
  1941. *
  1942. * @throws an exception of type regex_error.
  1943. */
  1944. template<typename _Bi_iter, typename _Alloc,
  1945. typename _Ch_type, typename _Rx_traits>
  1946. inline bool
  1947. regex_match(_Bi_iter __s,
  1948. _Bi_iter __e,
  1949. match_results<_Bi_iter, _Alloc>& __m,
  1950. const basic_regex<_Ch_type, _Rx_traits>& __re,
  1951. regex_constants::match_flag_type __flags
  1952. = regex_constants::match_default)
  1953. {
  1954. return __detail::__regex_algo_impl<_Bi_iter, _Alloc, _Ch_type, _Rx_traits,
  1955. __detail::_RegexExecutorPolicy::_S_auto, true>
  1956. (__s, __e, __m, __re, __flags);
  1957. }
  1958. /**
  1959. * @brief Indicates if there is a match between the regular expression @p e
  1960. * and all of the character sequence [first, last).
  1961. *
  1962. * @param __first Beginning of the character sequence to match.
  1963. * @param __last One-past-the-end of the character sequence to match.
  1964. * @param __re The regular expression.
  1965. * @param __flags Controls how the regular expression is matched.
  1966. *
  1967. * @retval true A match exists.
  1968. * @retval false Otherwise.
  1969. *
  1970. * @throws an exception of type regex_error.
  1971. */
  1972. template<typename _Bi_iter, typename _Ch_type, typename _Rx_traits>
  1973. inline bool
  1974. regex_match(_Bi_iter __first, _Bi_iter __last,
  1975. const basic_regex<_Ch_type, _Rx_traits>& __re,
  1976. regex_constants::match_flag_type __flags
  1977. = regex_constants::match_default)
  1978. {
  1979. match_results<_Bi_iter> __what;
  1980. return regex_match(__first, __last, __what, __re, __flags);
  1981. }
  1982. /**
  1983. * @brief Determines if there is a match between the regular expression @p e
  1984. * and a C-style null-terminated string.
  1985. *
  1986. * @param __s The C-style null-terminated string to match.
  1987. * @param __m The match results.
  1988. * @param __re The regular expression.
  1989. * @param __f Controls how the regular expression is matched.
  1990. *
  1991. * @retval true A match exists.
  1992. * @retval false Otherwise.
  1993. *
  1994. * @throws an exception of type regex_error.
  1995. */
  1996. template<typename _Ch_type, typename _Alloc, typename _Rx_traits>
  1997. inline bool
  1998. regex_match(const _Ch_type* __s,
  1999. match_results<const _Ch_type*, _Alloc>& __m,
  2000. const basic_regex<_Ch_type, _Rx_traits>& __re,
  2001. regex_constants::match_flag_type __f
  2002. = regex_constants::match_default)
  2003. { return regex_match(__s, __s + _Rx_traits::length(__s), __m, __re, __f); }
  2004. /**
  2005. * @brief Determines if there is a match between the regular expression @p e
  2006. * and a string.
  2007. *
  2008. * @param __s The string to match.
  2009. * @param __m The match results.
  2010. * @param __re The regular expression.
  2011. * @param __flags Controls how the regular expression is matched.
  2012. *
  2013. * @retval true A match exists.
  2014. * @retval false Otherwise.
  2015. *
  2016. * @throws an exception of type regex_error.
  2017. */
  2018. template<typename _Ch_traits, typename _Ch_alloc,
  2019. typename _Alloc, typename _Ch_type, typename _Rx_traits>
  2020. inline bool
  2021. regex_match(const basic_string<_Ch_type, _Ch_traits, _Ch_alloc>& __s,
  2022. match_results<typename basic_string<_Ch_type,
  2023. _Ch_traits, _Ch_alloc>::const_iterator, _Alloc>& __m,
  2024. const basic_regex<_Ch_type, _Rx_traits>& __re,
  2025. regex_constants::match_flag_type __flags
  2026. = regex_constants::match_default)
  2027. { return regex_match(__s.begin(), __s.end(), __m, __re, __flags); }
  2028. // _GLIBCXX_RESOLVE_LIB_DEFECTS
  2029. // 2329. regex_match() with match_results should forbid temporary strings
  2030. /// Prevent unsafe attempts to get match_results from a temporary string.
  2031. template<typename _Ch_traits, typename _Ch_alloc,
  2032. typename _Alloc, typename _Ch_type, typename _Rx_traits>
  2033. bool
  2034. regex_match(const basic_string<_Ch_type, _Ch_traits, _Ch_alloc>&&,
  2035. match_results<typename basic_string<_Ch_type,
  2036. _Ch_traits, _Ch_alloc>::const_iterator, _Alloc>&,
  2037. const basic_regex<_Ch_type, _Rx_traits>&,
  2038. regex_constants::match_flag_type
  2039. = regex_constants::match_default) = delete;
  2040. /**
  2041. * @brief Indicates if there is a match between the regular expression @p e
  2042. * and a C-style null-terminated string.
  2043. *
  2044. * @param __s The C-style null-terminated string to match.
  2045. * @param __re The regular expression.
  2046. * @param __f Controls how the regular expression is matched.
  2047. *
  2048. * @retval true A match exists.
  2049. * @retval false Otherwise.
  2050. *
  2051. * @throws an exception of type regex_error.
  2052. */
  2053. template<typename _Ch_type, class _Rx_traits>
  2054. inline bool
  2055. regex_match(const _Ch_type* __s,
  2056. const basic_regex<_Ch_type, _Rx_traits>& __re,
  2057. regex_constants::match_flag_type __f
  2058. = regex_constants::match_default)
  2059. { return regex_match(__s, __s + _Rx_traits::length(__s), __re, __f); }
  2060. /**
  2061. * @brief Indicates if there is a match between the regular expression @p e
  2062. * and a string.
  2063. *
  2064. * @param __s [IN] The string to match.
  2065. * @param __re [IN] The regular expression.
  2066. * @param __flags [IN] Controls how the regular expression is matched.
  2067. *
  2068. * @retval true A match exists.
  2069. * @retval false Otherwise.
  2070. *
  2071. * @throws an exception of type regex_error.
  2072. */
  2073. template<typename _Ch_traits, typename _Str_allocator,
  2074. typename _Ch_type, typename _Rx_traits>
  2075. inline bool
  2076. regex_match(const basic_string<_Ch_type, _Ch_traits, _Str_allocator>& __s,
  2077. const basic_regex<_Ch_type, _Rx_traits>& __re,
  2078. regex_constants::match_flag_type __flags
  2079. = regex_constants::match_default)
  2080. { return regex_match(__s.begin(), __s.end(), __re, __flags); }
  2081. // [7.11.3] Function template regex_search
  2082. /**
  2083. * Searches for a regular expression within a range.
  2084. * @param __s [IN] The start of the string to search.
  2085. * @param __e [IN] One-past-the-end of the string to search.
  2086. * @param __m [OUT] The match results.
  2087. * @param __re [IN] The regular expression to search for.
  2088. * @param __flags [IN] Search policy flags.
  2089. * @retval true A match was found within the string.
  2090. * @retval false No match was found within the string, the content of %m is
  2091. * undefined.
  2092. *
  2093. * @throws an exception of type regex_error.
  2094. */
  2095. template<typename _Bi_iter, typename _Alloc,
  2096. typename _Ch_type, typename _Rx_traits>
  2097. inline bool
  2098. regex_search(_Bi_iter __s, _Bi_iter __e,
  2099. match_results<_Bi_iter, _Alloc>& __m,
  2100. const basic_regex<_Ch_type, _Rx_traits>& __re,
  2101. regex_constants::match_flag_type __flags
  2102. = regex_constants::match_default)
  2103. {
  2104. return __detail::__regex_algo_impl<_Bi_iter, _Alloc, _Ch_type, _Rx_traits,
  2105. __detail::_RegexExecutorPolicy::_S_auto, false>
  2106. (__s, __e, __m, __re, __flags);
  2107. }
  2108. /**
  2109. * Searches for a regular expression within a range.
  2110. * @param __first [IN] The start of the string to search.
  2111. * @param __last [IN] One-past-the-end of the string to search.
  2112. * @param __re [IN] The regular expression to search for.
  2113. * @param __flags [IN] Search policy flags.
  2114. * @retval true A match was found within the string.
  2115. * @retval false No match was found within the string.
  2116. *
  2117. * @throws an exception of type regex_error.
  2118. */
  2119. template<typename _Bi_iter, typename _Ch_type, typename _Rx_traits>
  2120. inline bool
  2121. regex_search(_Bi_iter __first, _Bi_iter __last,
  2122. const basic_regex<_Ch_type, _Rx_traits>& __re,
  2123. regex_constants::match_flag_type __flags
  2124. = regex_constants::match_default)
  2125. {
  2126. match_results<_Bi_iter> __what;
  2127. return regex_search(__first, __last, __what, __re, __flags);
  2128. }
  2129. /**
  2130. * @brief Searches for a regular expression within a C-string.
  2131. * @param __s [IN] A C-string to search for the regex.
  2132. * @param __m [OUT] The set of regex matches.
  2133. * @param __e [IN] The regex to search for in @p s.
  2134. * @param __f [IN] The search flags.
  2135. * @retval true A match was found within the string.
  2136. * @retval false No match was found within the string, the content of %m is
  2137. * undefined.
  2138. *
  2139. * @throws an exception of type regex_error.
  2140. */
  2141. template<typename _Ch_type, class _Alloc, class _Rx_traits>
  2142. inline bool
  2143. regex_search(const _Ch_type* __s,
  2144. match_results<const _Ch_type*, _Alloc>& __m,
  2145. const basic_regex<_Ch_type, _Rx_traits>& __e,
  2146. regex_constants::match_flag_type __f
  2147. = regex_constants::match_default)
  2148. { return regex_search(__s, __s + _Rx_traits::length(__s), __m, __e, __f); }
  2149. /**
  2150. * @brief Searches for a regular expression within a C-string.
  2151. * @param __s [IN] The C-string to search.
  2152. * @param __e [IN] The regular expression to search for.
  2153. * @param __f [IN] Search policy flags.
  2154. * @retval true A match was found within the string.
  2155. * @retval false No match was found within the string.
  2156. *
  2157. * @throws an exception of type regex_error.
  2158. */
  2159. template<typename _Ch_type, typename _Rx_traits>
  2160. inline bool
  2161. regex_search(const _Ch_type* __s,
  2162. const basic_regex<_Ch_type, _Rx_traits>& __e,
  2163. regex_constants::match_flag_type __f
  2164. = regex_constants::match_default)
  2165. { return regex_search(__s, __s + _Rx_traits::length(__s), __e, __f); }
  2166. /**
  2167. * @brief Searches for a regular expression within a string.
  2168. * @param __s [IN] The string to search.
  2169. * @param __e [IN] The regular expression to search for.
  2170. * @param __flags [IN] Search policy flags.
  2171. * @retval true A match was found within the string.
  2172. * @retval false No match was found within the string.
  2173. *
  2174. * @throws an exception of type regex_error.
  2175. */
  2176. template<typename _Ch_traits, typename _String_allocator,
  2177. typename _Ch_type, typename _Rx_traits>
  2178. inline bool
  2179. regex_search(const basic_string<_Ch_type, _Ch_traits,
  2180. _String_allocator>& __s,
  2181. const basic_regex<_Ch_type, _Rx_traits>& __e,
  2182. regex_constants::match_flag_type __flags
  2183. = regex_constants::match_default)
  2184. { return regex_search(__s.begin(), __s.end(), __e, __flags); }
  2185. /**
  2186. * @brief Searches for a regular expression within a string.
  2187. * @param __s [IN] A C++ string to search for the regex.
  2188. * @param __m [OUT] The set of regex matches.
  2189. * @param __e [IN] The regex to search for in @p s.
  2190. * @param __f [IN] The search flags.
  2191. * @retval true A match was found within the string.
  2192. * @retval false No match was found within the string, the content of %m is
  2193. * undefined.
  2194. *
  2195. * @throws an exception of type regex_error.
  2196. */
  2197. template<typename _Ch_traits, typename _Ch_alloc,
  2198. typename _Alloc, typename _Ch_type,
  2199. typename _Rx_traits>
  2200. inline bool
  2201. regex_search(const basic_string<_Ch_type, _Ch_traits, _Ch_alloc>& __s,
  2202. match_results<typename basic_string<_Ch_type,
  2203. _Ch_traits, _Ch_alloc>::const_iterator, _Alloc>& __m,
  2204. const basic_regex<_Ch_type, _Rx_traits>& __e,
  2205. regex_constants::match_flag_type __f
  2206. = regex_constants::match_default)
  2207. { return regex_search(__s.begin(), __s.end(), __m, __e, __f); }
  2208. // _GLIBCXX_RESOLVE_LIB_DEFECTS
  2209. // 2329. regex_search() with match_results should forbid temporary strings
  2210. /// Prevent unsafe attempts to get match_results from a temporary string.
  2211. template<typename _Ch_traits, typename _Ch_alloc,
  2212. typename _Alloc, typename _Ch_type,
  2213. typename _Rx_traits>
  2214. bool
  2215. regex_search(const basic_string<_Ch_type, _Ch_traits, _Ch_alloc>&&,
  2216. match_results<typename basic_string<_Ch_type,
  2217. _Ch_traits, _Ch_alloc>::const_iterator, _Alloc>&,
  2218. const basic_regex<_Ch_type, _Rx_traits>&,
  2219. regex_constants::match_flag_type
  2220. = regex_constants::match_default) = delete;
  2221. // std [28.11.4] Function template regex_replace
  2222. /**
  2223. * @brief Search for a regular expression within a range for multiple times,
  2224. and replace the matched parts through filling a format string.
  2225. * @param __out [OUT] The output iterator.
  2226. * @param __first [IN] The start of the string to search.
  2227. * @param __last [IN] One-past-the-end of the string to search.
  2228. * @param __e [IN] The regular expression to search for.
  2229. * @param __fmt [IN] The format string.
  2230. * @param __flags [IN] Search and replace policy flags.
  2231. *
  2232. * @returns __out
  2233. * @throws an exception of type regex_error.
  2234. */
  2235. template<typename _Out_iter, typename _Bi_iter,
  2236. typename _Rx_traits, typename _Ch_type,
  2237. typename _St, typename _Sa>
  2238. inline _Out_iter
  2239. regex_replace(_Out_iter __out, _Bi_iter __first, _Bi_iter __last,
  2240. const basic_regex<_Ch_type, _Rx_traits>& __e,
  2241. const basic_string<_Ch_type, _St, _Sa>& __fmt,
  2242. regex_constants::match_flag_type __flags
  2243. = regex_constants::match_default)
  2244. {
  2245. return regex_replace(__out, __first, __last, __e, __fmt.c_str(), __flags);
  2246. }
  2247. /**
  2248. * @brief Search for a regular expression within a range for multiple times,
  2249. and replace the matched parts through filling a format C-string.
  2250. * @param __out [OUT] The output iterator.
  2251. * @param __first [IN] The start of the string to search.
  2252. * @param __last [IN] One-past-the-end of the string to search.
  2253. * @param __e [IN] The regular expression to search for.
  2254. * @param __fmt [IN] The format C-string.
  2255. * @param __flags [IN] Search and replace policy flags.
  2256. *
  2257. * @returns __out
  2258. * @throws an exception of type regex_error.
  2259. */
  2260. template<typename _Out_iter, typename _Bi_iter,
  2261. typename _Rx_traits, typename _Ch_type>
  2262. _Out_iter
  2263. regex_replace(_Out_iter __out, _Bi_iter __first, _Bi_iter __last,
  2264. const basic_regex<_Ch_type, _Rx_traits>& __e,
  2265. const _Ch_type* __fmt,
  2266. regex_constants::match_flag_type __flags
  2267. = regex_constants::match_default);
  2268. /**
  2269. * @brief Search for a regular expression within a string for multiple times,
  2270. and replace the matched parts through filling a format string.
  2271. * @param __s [IN] The string to search and replace.
  2272. * @param __e [IN] The regular expression to search for.
  2273. * @param __fmt [IN] The format string.
  2274. * @param __flags [IN] Search and replace policy flags.
  2275. *
  2276. * @returns The string after replacing.
  2277. * @throws an exception of type regex_error.
  2278. */
  2279. template<typename _Rx_traits, typename _Ch_type,
  2280. typename _St, typename _Sa, typename _Fst, typename _Fsa>
  2281. inline basic_string<_Ch_type, _St, _Sa>
  2282. regex_replace(const basic_string<_Ch_type, _St, _Sa>& __s,
  2283. const basic_regex<_Ch_type, _Rx_traits>& __e,
  2284. const basic_string<_Ch_type, _Fst, _Fsa>& __fmt,
  2285. regex_constants::match_flag_type __flags
  2286. = regex_constants::match_default)
  2287. {
  2288. basic_string<_Ch_type, _St, _Sa> __result;
  2289. regex_replace(std::back_inserter(__result),
  2290. __s.begin(), __s.end(), __e, __fmt, __flags);
  2291. return __result;
  2292. }
  2293. /**
  2294. * @brief Search for a regular expression within a string for multiple times,
  2295. and replace the matched parts through filling a format C-string.
  2296. * @param __s [IN] The string to search and replace.
  2297. * @param __e [IN] The regular expression to search for.
  2298. * @param __fmt [IN] The format C-string.
  2299. * @param __flags [IN] Search and replace policy flags.
  2300. *
  2301. * @returns The string after replacing.
  2302. * @throws an exception of type regex_error.
  2303. */
  2304. template<typename _Rx_traits, typename _Ch_type,
  2305. typename _St, typename _Sa>
  2306. inline basic_string<_Ch_type, _St, _Sa>
  2307. regex_replace(const basic_string<_Ch_type, _St, _Sa>& __s,
  2308. const basic_regex<_Ch_type, _Rx_traits>& __e,
  2309. const _Ch_type* __fmt,
  2310. regex_constants::match_flag_type __flags
  2311. = regex_constants::match_default)
  2312. {
  2313. basic_string<_Ch_type, _St, _Sa> __result;
  2314. regex_replace(std::back_inserter(__result),
  2315. __s.begin(), __s.end(), __e, __fmt, __flags);
  2316. return __result;
  2317. }
  2318. /**
  2319. * @brief Search for a regular expression within a C-string for multiple
  2320. times, and replace the matched parts through filling a format string.
  2321. * @param __s [IN] The C-string to search and replace.
  2322. * @param __e [IN] The regular expression to search for.
  2323. * @param __fmt [IN] The format string.
  2324. * @param __flags [IN] Search and replace policy flags.
  2325. *
  2326. * @returns The string after replacing.
  2327. * @throws an exception of type regex_error.
  2328. */
  2329. template<typename _Rx_traits, typename _Ch_type,
  2330. typename _St, typename _Sa>
  2331. inline basic_string<_Ch_type>
  2332. regex_replace(const _Ch_type* __s,
  2333. const basic_regex<_Ch_type, _Rx_traits>& __e,
  2334. const basic_string<_Ch_type, _St, _Sa>& __fmt,
  2335. regex_constants::match_flag_type __flags
  2336. = regex_constants::match_default)
  2337. {
  2338. basic_string<_Ch_type> __result;
  2339. regex_replace(std::back_inserter(__result), __s,
  2340. __s + char_traits<_Ch_type>::length(__s),
  2341. __e, __fmt, __flags);
  2342. return __result;
  2343. }
  2344. /**
  2345. * @brief Search for a regular expression within a C-string for multiple
  2346. times, and replace the matched parts through filling a format C-string.
  2347. * @param __s [IN] The C-string to search and replace.
  2348. * @param __e [IN] The regular expression to search for.
  2349. * @param __fmt [IN] The format C-string.
  2350. * @param __flags [IN] Search and replace policy flags.
  2351. *
  2352. * @returns The string after replacing.
  2353. * @throws an exception of type regex_error.
  2354. */
  2355. template<typename _Rx_traits, typename _Ch_type>
  2356. inline basic_string<_Ch_type>
  2357. regex_replace(const _Ch_type* __s,
  2358. const basic_regex<_Ch_type, _Rx_traits>& __e,
  2359. const _Ch_type* __fmt,
  2360. regex_constants::match_flag_type __flags
  2361. = regex_constants::match_default)
  2362. {
  2363. basic_string<_Ch_type> __result;
  2364. regex_replace(std::back_inserter(__result), __s,
  2365. __s + char_traits<_Ch_type>::length(__s),
  2366. __e, __fmt, __flags);
  2367. return __result;
  2368. }
  2369. ///@}
  2370. _GLIBCXX_BEGIN_NAMESPACE_CXX11
  2371. // std [28.12] Class template regex_iterator
  2372. /**
  2373. * An iterator adaptor that will provide repeated calls of regex_search over
  2374. * a range until no more matches remain.
  2375. */
  2376. template<typename _Bi_iter,
  2377. typename _Ch_type = typename iterator_traits<_Bi_iter>::value_type,
  2378. typename _Rx_traits = regex_traits<_Ch_type> >
  2379. class regex_iterator
  2380. {
  2381. public:
  2382. typedef basic_regex<_Ch_type, _Rx_traits> regex_type;
  2383. typedef match_results<_Bi_iter> value_type;
  2384. typedef std::ptrdiff_t difference_type;
  2385. typedef const value_type* pointer;
  2386. typedef const value_type& reference;
  2387. typedef std::forward_iterator_tag iterator_category;
  2388. /**
  2389. * @brief Provides a singular iterator, useful for indicating
  2390. * one-past-the-end of a range.
  2391. */
  2392. regex_iterator() = default;
  2393. /**
  2394. * Constructs a %regex_iterator...
  2395. * @param __a [IN] The start of a text range to search.
  2396. * @param __b [IN] One-past-the-end of the text range to search.
  2397. * @param __re [IN] The regular expression to match.
  2398. * @param __m [IN] Policy flags for match rules.
  2399. */
  2400. regex_iterator(_Bi_iter __a, _Bi_iter __b, const regex_type& __re,
  2401. regex_constants::match_flag_type __m
  2402. = regex_constants::match_default)
  2403. : _M_begin(__a), _M_end(__b), _M_pregex(&__re), _M_flags(__m), _M_match()
  2404. {
  2405. if (!regex_search(_M_begin, _M_end, _M_match, *_M_pregex, _M_flags))
  2406. *this = regex_iterator();
  2407. }
  2408. // _GLIBCXX_RESOLVE_LIB_DEFECTS
  2409. // 2332. regex_iterator should forbid temporary regexes
  2410. regex_iterator(_Bi_iter, _Bi_iter, const regex_type&&,
  2411. regex_constants::match_flag_type
  2412. = regex_constants::match_default) = delete;
  2413. /// Copy constructs a %regex_iterator.
  2414. regex_iterator(const regex_iterator&) = default;
  2415. /// Copy assigns one %regex_iterator to another.
  2416. regex_iterator&
  2417. operator=(const regex_iterator&) = default;
  2418. ~regex_iterator() = default;
  2419. /**
  2420. * @brief Tests the equivalence of two regex iterators.
  2421. */
  2422. bool
  2423. operator==(const regex_iterator&) const noexcept;
  2424. /**
  2425. * @brief Tests the inequivalence of two regex iterators.
  2426. */
  2427. bool
  2428. operator!=(const regex_iterator& __rhs) const noexcept
  2429. { return !(*this == __rhs); }
  2430. /**
  2431. * @brief Dereferences a %regex_iterator.
  2432. */
  2433. const value_type&
  2434. operator*() const noexcept
  2435. { return _M_match; }
  2436. /**
  2437. * @brief Selects a %regex_iterator member.
  2438. */
  2439. const value_type*
  2440. operator->() const noexcept
  2441. { return &_M_match; }
  2442. /**
  2443. * @brief Increments a %regex_iterator.
  2444. */
  2445. regex_iterator&
  2446. operator++();
  2447. /**
  2448. * @brief Postincrements a %regex_iterator.
  2449. */
  2450. regex_iterator
  2451. operator++(int)
  2452. {
  2453. auto __tmp = *this;
  2454. ++(*this);
  2455. return __tmp;
  2456. }
  2457. private:
  2458. _Bi_iter _M_begin {};
  2459. _Bi_iter _M_end {};
  2460. const regex_type* _M_pregex = nullptr;
  2461. regex_constants::match_flag_type _M_flags {};
  2462. match_results<_Bi_iter> _M_match;
  2463. };
  2464. typedef regex_iterator<const char*> cregex_iterator;
  2465. typedef regex_iterator<string::const_iterator> sregex_iterator;
  2466. #ifdef _GLIBCXX_USE_WCHAR_T
  2467. typedef regex_iterator<const wchar_t*> wcregex_iterator;
  2468. typedef regex_iterator<wstring::const_iterator> wsregex_iterator;
  2469. #endif
  2470. // [7.12.2] Class template regex_token_iterator
  2471. /**
  2472. * Iterates over submatches in a range (or @a splits a text string).
  2473. *
  2474. * The purpose of this iterator is to enumerate all, or all specified,
  2475. * matches of a regular expression within a text range. The dereferenced
  2476. * value of an iterator of this class is a std::sub_match object.
  2477. */
  2478. template<typename _Bi_iter,
  2479. typename _Ch_type = typename iterator_traits<_Bi_iter>::value_type,
  2480. typename _Rx_traits = regex_traits<_Ch_type> >
  2481. class regex_token_iterator
  2482. {
  2483. public:
  2484. typedef basic_regex<_Ch_type, _Rx_traits> regex_type;
  2485. typedef sub_match<_Bi_iter> value_type;
  2486. typedef std::ptrdiff_t difference_type;
  2487. typedef const value_type* pointer;
  2488. typedef const value_type& reference;
  2489. typedef std::forward_iterator_tag iterator_category;
  2490. public:
  2491. /**
  2492. * @brief Default constructs a %regex_token_iterator.
  2493. *
  2494. * A default-constructed %regex_token_iterator is a singular iterator
  2495. * that will compare equal to the one-past-the-end value for any
  2496. * iterator of the same type.
  2497. */
  2498. regex_token_iterator()
  2499. : _M_position(), _M_subs(), _M_suffix(), _M_n(0), _M_result(nullptr),
  2500. _M_has_m1(false)
  2501. { }
  2502. /**
  2503. * Constructs a %regex_token_iterator...
  2504. * @param __a [IN] The start of the text to search.
  2505. * @param __b [IN] One-past-the-end of the text to search.
  2506. * @param __re [IN] The regular expression to search for.
  2507. * @param __submatch [IN] Which submatch to return. There are some
  2508. * special values for this parameter:
  2509. * - -1 each enumerated subexpression does NOT
  2510. * match the regular expression (aka field
  2511. * splitting)
  2512. * - 0 the entire string matching the
  2513. * subexpression is returned for each match
  2514. * within the text.
  2515. * - >0 enumerates only the indicated
  2516. * subexpression from a match within the text.
  2517. * @param __m [IN] Policy flags for match rules.
  2518. */
  2519. regex_token_iterator(_Bi_iter __a, _Bi_iter __b, const regex_type& __re,
  2520. int __submatch = 0,
  2521. regex_constants::match_flag_type __m
  2522. = regex_constants::match_default)
  2523. : _M_position(__a, __b, __re, __m), _M_subs(1, __submatch), _M_n(0)
  2524. { _M_init(__a, __b); }
  2525. /**
  2526. * Constructs a %regex_token_iterator...
  2527. * @param __a [IN] The start of the text to search.
  2528. * @param __b [IN] One-past-the-end of the text to search.
  2529. * @param __re [IN] The regular expression to search for.
  2530. * @param __submatches [IN] A list of subexpressions to return for each
  2531. * regular expression match within the text.
  2532. * @param __m [IN] Policy flags for match rules.
  2533. */
  2534. regex_token_iterator(_Bi_iter __a, _Bi_iter __b,
  2535. const regex_type& __re,
  2536. const std::vector<int>& __submatches,
  2537. regex_constants::match_flag_type __m
  2538. = regex_constants::match_default)
  2539. : _M_position(__a, __b, __re, __m), _M_subs(__submatches), _M_n(0)
  2540. { _M_init(__a, __b); }
  2541. /**
  2542. * Constructs a %regex_token_iterator...
  2543. * @param __a [IN] The start of the text to search.
  2544. * @param __b [IN] One-past-the-end of the text to search.
  2545. * @param __re [IN] The regular expression to search for.
  2546. * @param __submatches [IN] A list of subexpressions to return for each
  2547. * regular expression match within the text.
  2548. * @param __m [IN] Policy flags for match rules.
  2549. */
  2550. regex_token_iterator(_Bi_iter __a, _Bi_iter __b,
  2551. const regex_type& __re,
  2552. initializer_list<int> __submatches,
  2553. regex_constants::match_flag_type __m
  2554. = regex_constants::match_default)
  2555. : _M_position(__a, __b, __re, __m), _M_subs(__submatches), _M_n(0)
  2556. { _M_init(__a, __b); }
  2557. /**
  2558. * Constructs a %regex_token_iterator...
  2559. * @param __a [IN] The start of the text to search.
  2560. * @param __b [IN] One-past-the-end of the text to search.
  2561. * @param __re [IN] The regular expression to search for.
  2562. * @param __submatches [IN] A list of subexpressions to return for each
  2563. * regular expression match within the text.
  2564. * @param __m [IN] Policy flags for match rules.
  2565. */
  2566. template<std::size_t _Nm>
  2567. regex_token_iterator(_Bi_iter __a, _Bi_iter __b,
  2568. const regex_type& __re,
  2569. const int (&__submatches)[_Nm],
  2570. regex_constants::match_flag_type __m
  2571. = regex_constants::match_default)
  2572. : _M_position(__a, __b, __re, __m),
  2573. _M_subs(__submatches, __submatches + _Nm), _M_n(0)
  2574. { _M_init(__a, __b); }
  2575. // _GLIBCXX_RESOLVE_LIB_DEFECTS
  2576. // 2332. regex_token_iterator should forbid temporary regexes
  2577. regex_token_iterator(_Bi_iter, _Bi_iter, const regex_type&&, int = 0,
  2578. regex_constants::match_flag_type =
  2579. regex_constants::match_default) = delete;
  2580. regex_token_iterator(_Bi_iter, _Bi_iter, const regex_type&&,
  2581. const std::vector<int>&,
  2582. regex_constants::match_flag_type =
  2583. regex_constants::match_default) = delete;
  2584. regex_token_iterator(_Bi_iter, _Bi_iter, const regex_type&&,
  2585. initializer_list<int>,
  2586. regex_constants::match_flag_type =
  2587. regex_constants::match_default) = delete;
  2588. template <std::size_t _Nm>
  2589. regex_token_iterator(_Bi_iter, _Bi_iter, const regex_type&&,
  2590. const int (&)[_Nm],
  2591. regex_constants::match_flag_type =
  2592. regex_constants::match_default) = delete;
  2593. /**
  2594. * @brief Copy constructs a %regex_token_iterator.
  2595. * @param __rhs [IN] A %regex_token_iterator to copy.
  2596. */
  2597. regex_token_iterator(const regex_token_iterator& __rhs)
  2598. : _M_position(__rhs._M_position), _M_subs(__rhs._M_subs),
  2599. _M_suffix(__rhs._M_suffix), _M_n(__rhs._M_n), _M_has_m1(__rhs._M_has_m1)
  2600. { _M_normalize_result(); }
  2601. /**
  2602. * @brief Assigns a %regex_token_iterator to another.
  2603. * @param __rhs [IN] A %regex_token_iterator to copy.
  2604. */
  2605. regex_token_iterator&
  2606. operator=(const regex_token_iterator& __rhs);
  2607. /**
  2608. * @brief Compares a %regex_token_iterator to another for equality.
  2609. */
  2610. bool
  2611. operator==(const regex_token_iterator& __rhs) const;
  2612. /**
  2613. * @brief Compares a %regex_token_iterator to another for inequality.
  2614. */
  2615. bool
  2616. operator!=(const regex_token_iterator& __rhs) const
  2617. { return !(*this == __rhs); }
  2618. /**
  2619. * @brief Dereferences a %regex_token_iterator.
  2620. */
  2621. const value_type&
  2622. operator*() const
  2623. { return *_M_result; }
  2624. /**
  2625. * @brief Selects a %regex_token_iterator member.
  2626. */
  2627. const value_type*
  2628. operator->() const
  2629. { return _M_result; }
  2630. /**
  2631. * @brief Increments a %regex_token_iterator.
  2632. */
  2633. regex_token_iterator&
  2634. operator++();
  2635. /**
  2636. * @brief Postincrements a %regex_token_iterator.
  2637. */
  2638. regex_token_iterator
  2639. operator++(int)
  2640. {
  2641. auto __tmp = *this;
  2642. ++(*this);
  2643. return __tmp;
  2644. }
  2645. private:
  2646. typedef regex_iterator<_Bi_iter, _Ch_type, _Rx_traits> _Position;
  2647. void
  2648. _M_init(_Bi_iter __a, _Bi_iter __b);
  2649. const value_type&
  2650. _M_current_match() const
  2651. {
  2652. if (_M_subs[_M_n] == -1)
  2653. return (*_M_position).prefix();
  2654. else
  2655. return (*_M_position)[_M_subs[_M_n]];
  2656. }
  2657. constexpr bool
  2658. _M_end_of_seq() const
  2659. { return _M_result == nullptr; }
  2660. // [28.12.2.2.4]
  2661. void
  2662. _M_normalize_result()
  2663. {
  2664. if (_M_position != _Position())
  2665. _M_result = &_M_current_match();
  2666. else if (_M_has_m1)
  2667. _M_result = &_M_suffix;
  2668. else
  2669. _M_result = nullptr;
  2670. }
  2671. _Position _M_position;
  2672. std::vector<int> _M_subs;
  2673. value_type _M_suffix;
  2674. std::size_t _M_n;
  2675. const value_type* _M_result;
  2676. // Show whether _M_subs contains -1
  2677. bool _M_has_m1;
  2678. };
  2679. /** @brief Token iterator for C-style NULL-terminated strings. */
  2680. typedef regex_token_iterator<const char*> cregex_token_iterator;
  2681. /** @brief Token iterator for standard strings. */
  2682. typedef regex_token_iterator<string::const_iterator> sregex_token_iterator;
  2683. #ifdef _GLIBCXX_USE_WCHAR_T
  2684. /** @brief Token iterator for C-style NULL-terminated wide strings. */
  2685. typedef regex_token_iterator<const wchar_t*> wcregex_token_iterator;
  2686. /** @brief Token iterator for standard wide-character strings. */
  2687. typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator;
  2688. #endif
  2689. ///@} // group regex
  2690. _GLIBCXX_END_NAMESPACE_CXX11
  2691. _GLIBCXX_END_NAMESPACE_VERSION
  2692. } // namespace
  2693. #include <bits/regex.tcc>