regex 91 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730
  1. // class template regex -*- C++ -*-
  2. // Copyright (C) 2007-2015 Free Software Foundation, Inc.
  3. //
  4. // This file is part of the GNU ISO C++ Library. This library is free
  5. // software; you can redistribute it and/or modify it under the
  6. // terms of the GNU General Public License as published by the
  7. // Free Software Foundation; either version 3, or (at your option)
  8. // any later version.
  9. // This library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. // Under Section 7 of GPL version 3, you are granted additional
  14. // permissions described in the GCC Runtime Library Exception, version
  15. // 3.1, as published by the Free Software Foundation.
  16. // You should have received a copy of the GNU General Public License and
  17. // a copy of the GCC Runtime Library Exception along with this program;
  18. // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  19. // <http://www.gnu.org/licenses/>.
  20. /**
  21. * @file tr1/regex
  22. * @author Stephen M. Webb <stephen.webb@bregmasoft.ca>
  23. * This is a TR1 C++ Library header.
  24. */
  25. #ifndef _GLIBCXX_TR1_REGEX
  26. #define _GLIBCXX_TR1_REGEX 1
  27. #pragma GCC system_header
  28. #include <algorithm>
  29. #include <bitset>
  30. #include <iterator>
  31. #include <locale>
  32. #include <stdexcept>
  33. #include <string>
  34. #include <vector>
  35. #include <utility>
  36. #include <sstream>
  37. namespace std _GLIBCXX_VISIBILITY(default)
  38. {
  39. namespace tr1
  40. {
  41. /**
  42. * @defgroup tr1_regex Regular Expressions
  43. * A facility for performing regular expression pattern matching.
  44. */
  45. //@{
  46. /** @namespace std::regex_constants
  47. * @brief ISO C++ 0x entities sub namespace for regex.
  48. */
  49. namespace regex_constants
  50. {
  51. _GLIBCXX_BEGIN_NAMESPACE_VERSION
  52. /**
  53. * @name 5.1 Regular Expression Syntax Options
  54. */
  55. //@{
  56. enum __syntax_option
  57. {
  58. _S_icase,
  59. _S_nosubs,
  60. _S_optimize,
  61. _S_collate,
  62. _S_ECMAScript,
  63. _S_basic,
  64. _S_extended,
  65. _S_awk,
  66. _S_grep,
  67. _S_egrep,
  68. _S_syntax_last
  69. };
  70. /**
  71. * @brief This is a bitmask type indicating how to interpret the regex.
  72. *
  73. * The @c syntax_option_type is implementation defined but it is valid to
  74. * perform bitwise operations on these values and expect the right thing to
  75. * happen.
  76. *
  77. * A valid value of type syntax_option_type shall have exactly one of the
  78. * elements @c ECMAScript, @c basic, @c extended, @c awk, @c grep, @c egrep
  79. * %set.
  80. */
  81. typedef unsigned int syntax_option_type;
  82. /**
  83. * Specifies that the matching of regular expressions against a character
  84. * sequence shall be performed without regard to case.
  85. */
  86. static const syntax_option_type icase = 1 << _S_icase;
  87. /**
  88. * Specifies that when a regular expression is matched against a character
  89. * container sequence, no sub-expression matches are to be stored in the
  90. * supplied match_results structure.
  91. */
  92. static const syntax_option_type nosubs = 1 << _S_nosubs;
  93. /**
  94. * Specifies that the regular expression engine should pay more attention to
  95. * the speed with which regular expressions are matched, and less to the
  96. * speed with which regular expression objects are constructed. Otherwise
  97. * it has no detectable effect on the program output.
  98. */
  99. static const syntax_option_type optimize = 1 << _S_optimize;
  100. /**
  101. * Specifies that character ranges of the form [a-b] should be locale
  102. * sensitive.
  103. */
  104. static const syntax_option_type collate = 1 << _S_collate;
  105. /**
  106. * Specifies that the grammar recognized by the regular expression engine is
  107. * that used by ECMAScript in ECMA-262 [Ecma International, ECMAScript
  108. * Language Specification, Standard Ecma-262, third edition, 1999], as
  109. * modified in tr1 section [7.13]. This grammar is similar to that defined
  110. * in the PERL scripting language but extended with elements found in the
  111. * POSIX regular expression grammar.
  112. */
  113. static const syntax_option_type ECMAScript = 1 << _S_ECMAScript;
  114. /**
  115. * Specifies that the grammar recognized by the regular expression engine is
  116. * that used by POSIX basic regular expressions in IEEE Std 1003.1-2001,
  117. * Portable Operating System Interface (POSIX), Base Definitions and
  118. * Headers, Section 9, Regular Expressions [IEEE, Information Technology --
  119. * Portable Operating System Interface (POSIX), IEEE Standard 1003.1-2001].
  120. */
  121. static const syntax_option_type basic = 1 << _S_basic;
  122. /**
  123. * Specifies that the grammar recognized by the regular expression engine is
  124. * that used by POSIX extended regular expressions in IEEE Std 1003.1-2001,
  125. * Portable Operating System Interface (POSIX), Base Definitions and Headers,
  126. * Section 9, Regular Expressions.
  127. */
  128. static const syntax_option_type extended = 1 << _S_extended;
  129. /**
  130. * Specifies that the grammar recognized by the regular expression engine is
  131. * that used by POSIX utility awk in IEEE Std 1003.1-2001. This option is
  132. * identical to syntax_option_type extended, except that C-style escape
  133. * sequences are supported. These sequences are:
  134. * \\\\, \\a, \\b, \\f,
  135. * \\n, \\r, \\t , \\v,
  136. * \\&apos;, &apos;, and \\ddd
  137. * (where ddd is one, two, or three octal digits).
  138. */
  139. static const syntax_option_type awk = 1 << _S_awk;
  140. /**
  141. * Specifies that the grammar recognized by the regular expression engine is
  142. * that used by POSIX utility grep in IEEE Std 1003.1-2001. This option is
  143. * identical to syntax_option_type basic, except that newlines are treated
  144. * as whitespace.
  145. */
  146. static const syntax_option_type grep = 1 << _S_grep;
  147. /**
  148. * Specifies that the grammar recognized by the regular expression engine is
  149. * that used by POSIX utility grep when given the -E option in
  150. * IEEE Std 1003.1-2001. This option is identical to syntax_option_type
  151. * extended, except that newlines are treated as whitespace.
  152. */
  153. static const syntax_option_type egrep = 1 << _S_egrep;
  154. //@}
  155. /**
  156. * @name 5.2 Matching Rules
  157. *
  158. * Matching a regular expression against a sequence of characters [first,
  159. * last) proceeds according to the rules of the grammar specified for the
  160. * regular expression object, modified according to the effects listed
  161. * below for any bitmask elements set.
  162. *
  163. */
  164. //@{
  165. enum __match_flag
  166. {
  167. _S_not_bol,
  168. _S_not_eol,
  169. _S_not_bow,
  170. _S_not_eow,
  171. _S_any,
  172. _S_not_null,
  173. _S_continuous,
  174. _S_prev_avail,
  175. _S_sed,
  176. _S_no_copy,
  177. _S_first_only,
  178. _S_match_flag_last
  179. };
  180. /**
  181. * @brief This is a bitmask type indicating regex matching rules.
  182. *
  183. * The @c match_flag_type is implementation defined but it is valid to
  184. * perform bitwise operations on these values and expect the right thing to
  185. * happen.
  186. */
  187. typedef std::bitset<_S_match_flag_last> match_flag_type;
  188. /**
  189. * The default matching rules.
  190. */
  191. static const match_flag_type match_default = 0;
  192. /**
  193. * The first character in the sequence [first, last) is treated as though it
  194. * is not at the beginning of a line, so the character (^) in the regular
  195. * expression shall not match [first, first).
  196. */
  197. static const match_flag_type match_not_bol = 1 << _S_not_bol;
  198. /**
  199. * The last character in the sequence [first, last) is treated as though it
  200. * is not at the end of a line, so the character ($) in the regular
  201. * expression shall not match [last, last).
  202. */
  203. static const match_flag_type match_not_eol = 1 << _S_not_eol;
  204. /**
  205. * The expression \\b is not matched against the sub-sequence
  206. * [first,first).
  207. */
  208. static const match_flag_type match_not_bow = 1 << _S_not_bow;
  209. /**
  210. * The expression \\b should not be matched against the sub-sequence
  211. * [last,last).
  212. */
  213. static const match_flag_type match_not_eow = 1 << _S_not_eow;
  214. /**
  215. * If more than one match is possible then any match is an acceptable
  216. * result.
  217. */
  218. static const match_flag_type match_any = 1 << _S_any;
  219. /**
  220. * The expression does not match an empty sequence.
  221. */
  222. static const match_flag_type match_not_null = 1 << _S_not_null;
  223. /**
  224. * The expression only matches a sub-sequence that begins at first .
  225. */
  226. static const match_flag_type match_continuous = 1 << _S_continuous;
  227. /**
  228. * --first is a valid iterator position. When this flag is set then the
  229. * flags match_not_bol and match_not_bow are ignored by the regular
  230. * expression algorithms 7.11 and iterators 7.12.
  231. */
  232. static const match_flag_type match_prev_avail = 1 << _S_prev_avail;
  233. /**
  234. * When a regular expression match is to be replaced by a new string, the
  235. * new string is constructed using the rules used by the ECMAScript replace
  236. * function in ECMA- 262 [Ecma International, ECMAScript Language
  237. * Specification, Standard Ecma-262, third edition, 1999], part 15.5.4.11
  238. * String.prototype.replace. In addition, during search and replace
  239. * operations all non-overlapping occurrences of the regular expression
  240. * are located and replaced, and sections of the input that did not match
  241. * the expression are copied unchanged to the output string.
  242. *
  243. * Format strings (from ECMA-262 [15.5.4.11]):
  244. * @li $$ The dollar-sign itself ($)
  245. * @li $& The matched substring.
  246. * @li $` The portion of @a string that precedes the matched substring.
  247. * This would be match_results::prefix().
  248. * @li $' The portion of @a string that follows the matched substring.
  249. * This would be match_results::suffix().
  250. * @li $n The nth capture, where n is in [1,9] and $n is not followed by a
  251. * decimal digit. If n <= match_results::size() and the nth capture
  252. * is undefined, use the empty string instead. If n >
  253. * match_results::size(), the result is implementation-defined.
  254. * @li $nn The nnth capture, where nn is a two-digit decimal number on
  255. * [01, 99]. If nn <= match_results::size() and the nth capture is
  256. * undefined, use the empty string instead. If
  257. * nn > match_results::size(), the result is implementation-defined.
  258. */
  259. static const match_flag_type format_default = 0;
  260. /**
  261. * When a regular expression match is to be replaced by a new string, the
  262. * new string is constructed using the rules used by the POSIX sed utility
  263. * in IEEE Std 1003.1- 2001 [IEEE, Information Technology -- Portable
  264. * Operating System Interface (POSIX), IEEE Standard 1003.1-2001].
  265. */
  266. static const match_flag_type format_sed = 1 << _S_sed;
  267. /**
  268. * During a search and replace operation, sections of the character
  269. * container sequence being searched that do not match the regular
  270. * expression shall not be copied to the output string.
  271. */
  272. static const match_flag_type format_no_copy = 1 << _S_no_copy;
  273. /**
  274. * When specified during a search and replace operation, only the first
  275. * occurrence of the regular expression shall be replaced.
  276. */
  277. static const match_flag_type format_first_only = 1 << _S_first_only;
  278. //@}
  279. /**
  280. * @name 5.3 Error Types
  281. */
  282. //@{
  283. enum error_type
  284. {
  285. _S_error_collate,
  286. _S_error_ctype,
  287. _S_error_escape,
  288. _S_error_backref,
  289. _S_error_brack,
  290. _S_error_paren,
  291. _S_error_brace,
  292. _S_error_badbrace,
  293. _S_error_range,
  294. _S_error_space,
  295. _S_error_badrepeat,
  296. _S_error_complexity,
  297. _S_error_stack,
  298. _S_error_last
  299. };
  300. /** The expression contained an invalid collating element name. */
  301. static const error_type error_collate(_S_error_collate);
  302. /** The expression contained an invalid character class name. */
  303. static const error_type error_ctype(_S_error_ctype);
  304. /**
  305. * The expression contained an invalid escaped character, or a trailing
  306. * escape.
  307. */
  308. static const error_type error_escape(_S_error_escape);
  309. /** The expression contained an invalid back reference. */
  310. static const error_type error_backref(_S_error_backref);
  311. /** The expression contained mismatched [ and ]. */
  312. static const error_type error_brack(_S_error_brack);
  313. /** The expression contained mismatched ( and ). */
  314. static const error_type error_paren(_S_error_paren);
  315. /** The expression contained mismatched { and } */
  316. static const error_type error_brace(_S_error_brace);
  317. /** The expression contained an invalid range in a {} expression. */
  318. static const error_type error_badbrace(_S_error_badbrace);
  319. /**
  320. * The expression contained an invalid character range,
  321. * such as [b-a] in most encodings.
  322. */
  323. static const error_type error_range(_S_error_range);
  324. /**
  325. * There was insufficient memory to convert the expression into a
  326. * finite state machine.
  327. */
  328. static const error_type error_space(_S_error_space);
  329. /**
  330. * One of <em>*?+{</em> was not preceded by a valid regular expression.
  331. */
  332. static const error_type error_badrepeat(_S_error_badrepeat);
  333. /**
  334. * The complexity of an attempted match against a regular expression
  335. * exceeded a pre-set level.
  336. */
  337. static const error_type error_complexity(_S_error_complexity);
  338. /**
  339. * There was insufficient memory to determine whether the
  340. * regular expression could match the specified character sequence.
  341. */
  342. static const error_type error_stack(_S_error_stack);
  343. //@}
  344. _GLIBCXX_END_NAMESPACE_VERSION
  345. }
  346. _GLIBCXX_BEGIN_NAMESPACE_VERSION
  347. // [7.8] Class regex_error
  348. /**
  349. * @brief A regular expression exception class.
  350. * @ingroup exceptions
  351. *
  352. * The regular expression library throws objects of this class on error.
  353. */
  354. class regex_error
  355. : public std::runtime_error
  356. {
  357. public:
  358. /**
  359. * @brief Constructs a regex_error object.
  360. *
  361. * @param ecode the regex error code.
  362. */
  363. explicit
  364. regex_error(regex_constants::error_type __ecode)
  365. : std::runtime_error("regex_error"), _M_code(__ecode)
  366. { }
  367. /**
  368. * @brief Gets the regex error code.
  369. *
  370. * @returns the regex error code.
  371. */
  372. regex_constants::error_type
  373. code() const
  374. { return _M_code; }
  375. protected:
  376. regex_constants::error_type _M_code;
  377. };
  378. // [7.7] Class regex_traits
  379. /**
  380. * @brief Describes aspects of a regular expression.
  381. *
  382. * A regular expression traits class that satisfies the requirements of tr1
  383. * section [7.2].
  384. *
  385. * The class %regex is parameterized around a set of related types and
  386. * functions used to complete the definition of its semantics. This class
  387. * satisfies the requirements of such a traits class.
  388. */
  389. template<typename _Ch_type>
  390. struct regex_traits
  391. {
  392. public:
  393. typedef _Ch_type char_type;
  394. typedef std::basic_string<char_type> string_type;
  395. typedef std::locale locale_type;
  396. typedef std::ctype_base::mask char_class_type;
  397. public:
  398. /**
  399. * @brief Constructs a default traits object.
  400. */
  401. regex_traits()
  402. { }
  403. /**
  404. * @brief Gives the length of a C-style string starting at @p __p.
  405. *
  406. * @param __p a pointer to the start of a character sequence.
  407. *
  408. * @returns the number of characters between @p *__p and the first
  409. * default-initialized value of type @p char_type. In other words, uses
  410. * the C-string algorithm for determining the length of a sequence of
  411. * characters.
  412. */
  413. static std::size_t
  414. length(const char_type* __p)
  415. { return string_type::traits_type::length(__p); }
  416. /**
  417. * @brief Performs the identity translation.
  418. *
  419. * @param c A character to the locale-specific character set.
  420. *
  421. * @returns c.
  422. */
  423. char_type
  424. translate(char_type __c) const
  425. { return __c; }
  426. /**
  427. * @brief Translates a character into a case-insensitive equivalent.
  428. *
  429. * @param c A character to the locale-specific character set.
  430. *
  431. * @returns the locale-specific lower-case equivalent of c.
  432. * @throws std::bad_cast if the imbued locale does not support the ctype
  433. * facet.
  434. */
  435. char_type
  436. translate_nocase(char_type __c) const
  437. {
  438. using std::ctype;
  439. using std::use_facet;
  440. return use_facet<ctype<char_type> >(_M_locale).tolower(__c);
  441. }
  442. /**
  443. * @brief Gets a sort key for a character sequence.
  444. *
  445. * @param first beginning of the character sequence.
  446. * @param last one-past-the-end of the character sequence.
  447. *
  448. * Returns a sort key for the character sequence designated by the
  449. * iterator range [F1, F2) such that if the character sequence [G1, G2)
  450. * sorts before the character sequence [H1, H2) then
  451. * v.transform(G1, G2) < v.transform(H1, H2).
  452. *
  453. * What this really does is provide a more efficient way to compare a
  454. * string to multiple other strings in locales with fancy collation
  455. * rules and equivalence classes.
  456. *
  457. * @returns a locale-specific sort key equivalent to the input range.
  458. *
  459. * @throws std::bad_cast if the current locale does not have a collate
  460. * facet.
  461. */
  462. template<typename _Fwd_iter>
  463. string_type
  464. transform(_Fwd_iter __first, _Fwd_iter __last) const
  465. {
  466. using std::collate;
  467. using std::use_facet;
  468. const collate<_Ch_type>& __c(use_facet<
  469. collate<_Ch_type> >(_M_locale));
  470. string_type __s(__first, __last);
  471. return __c.transform(__s.data(), __s.data() + __s.size());
  472. }
  473. /**
  474. * @brief Dunno.
  475. *
  476. * @param first beginning of the character sequence.
  477. * @param last one-past-the-end of the character sequence.
  478. *
  479. * Effects: if typeid(use_facet<collate<_Ch_type> >) ==
  480. * typeid(collate_byname<_Ch_type>) and the form of the sort key
  481. * returned by collate_byname<_Ch_type>::transform(first, last) is known
  482. * and can be converted into a primary sort key then returns that key,
  483. * otherwise returns an empty string. WTF??
  484. *
  485. * @todo Implement this function.
  486. */
  487. template<typename _Fwd_iter>
  488. string_type
  489. transform_primary(_Fwd_iter __first, _Fwd_iter __last) const;
  490. /**
  491. * @brief Gets a collation element by name.
  492. *
  493. * @param first beginning of the collation element name.
  494. * @param last one-past-the-end of the collation element name.
  495. *
  496. * @returns a sequence of one or more characters that represents the
  497. * collating element consisting of the character sequence designated by
  498. * the iterator range [first, last). Returns an empty string if the
  499. * character sequence is not a valid collating element.
  500. *
  501. * @todo Implement this function.
  502. */
  503. template<typename _Fwd_iter>
  504. string_type
  505. lookup_collatename(_Fwd_iter __first, _Fwd_iter __last) const;
  506. /**
  507. * @brief Maps one or more characters to a named character
  508. * classification.
  509. *
  510. * @param first beginning of the character sequence.
  511. * @param last one-past-the-end of the character sequence.
  512. *
  513. * @returns an unspecified value that represents the character
  514. * classification named by the character sequence designated by the
  515. * iterator range [first, last). The value returned shall be independent
  516. * of the case of the characters in the character sequence. If the name
  517. * is not recognized then returns a value that compares equal to 0.
  518. *
  519. * At least the following names (or their wide-character equivalent) are
  520. * supported.
  521. * - d
  522. * - w
  523. * - s
  524. * - alnum
  525. * - alpha
  526. * - blank
  527. * - cntrl
  528. * - digit
  529. * - graph
  530. * - lower
  531. * - print
  532. * - punct
  533. * - space
  534. * - upper
  535. * - xdigit
  536. *
  537. * @todo Implement this function.
  538. */
  539. template<typename _Fwd_iter>
  540. char_class_type
  541. lookup_classname(_Fwd_iter __first, _Fwd_iter __last) const;
  542. /**
  543. * @brief Determines if @p c is a member of an identified class.
  544. *
  545. * @param c a character.
  546. * @param f a class type (as returned from lookup_classname).
  547. *
  548. * @returns true if the character @p c is a member of the classification
  549. * represented by @p f, false otherwise.
  550. *
  551. * @throws std::bad_cast if the current locale does not have a ctype
  552. * facet.
  553. */
  554. bool
  555. isctype(_Ch_type __c, char_class_type __f) const;
  556. /**
  557. * @brief Converts a digit to an int.
  558. *
  559. * @param ch a character representing a digit.
  560. * @param radix the radix if the numeric conversion (limited to 8, 10,
  561. * or 16).
  562. *
  563. * @returns the value represented by the digit ch in base radix if the
  564. * character ch is a valid digit in base radix; otherwise returns -1.
  565. */
  566. int
  567. value(_Ch_type __ch, int __radix) const;
  568. /**
  569. * @brief Imbues the regex_traits object with a copy of a new locale.
  570. *
  571. * @param loc A locale.
  572. *
  573. * @returns a copy of the previous locale in use by the regex_traits
  574. * object.
  575. *
  576. * @note Calling imbue with a different locale than the one currently in
  577. * use invalidates all cached data held by *this.
  578. */
  579. locale_type
  580. imbue(locale_type __loc)
  581. {
  582. std::swap(_M_locale, __loc);
  583. return __loc;
  584. }
  585. /**
  586. * @brief Gets a copy of the current locale in use by the regex_traits
  587. * object.
  588. */
  589. locale_type
  590. getloc() const
  591. { return _M_locale; }
  592. protected:
  593. locale_type _M_locale;
  594. };
  595. template<typename _Ch_type>
  596. bool regex_traits<_Ch_type>::
  597. isctype(_Ch_type __c, char_class_type __f) const
  598. {
  599. using std::ctype;
  600. using std::use_facet;
  601. const ctype<_Ch_type>& __ctype(use_facet<
  602. ctype<_Ch_type> >(_M_locale));
  603. if (__ctype.is(__c, __f))
  604. return true;
  605. #if 0
  606. // special case of underscore in [[:w:]]
  607. if (__c == __ctype.widen('_'))
  608. {
  609. const char* const __wb[] = "w";
  610. char_class_type __wt = this->lookup_classname(__wb,
  611. __wb + sizeof(__wb));
  612. if (__f | __wt)
  613. return true;
  614. }
  615. // special case of [[:space:]] in [[:blank:]]
  616. if (__c == __ctype.isspace(__c))
  617. {
  618. const char* const __bb[] = "blank";
  619. char_class_type __bt = this->lookup_classname(__bb,
  620. __bb + sizeof(__bb));
  621. if (__f | __bt)
  622. return true;
  623. }
  624. #endif
  625. return false;
  626. }
  627. template<typename _Ch_type>
  628. int regex_traits<_Ch_type>::
  629. value(_Ch_type __ch, int __radix) const
  630. {
  631. std::basic_istringstream<_Ch_type> __is(string_type(1, __ch));
  632. int __v;
  633. if (__radix == 8)
  634. __is >> std::oct;
  635. else if (__radix == 16)
  636. __is >> std::hex;
  637. __is >> __v;
  638. return __is.fail() ? -1 : __v;
  639. }
  640. // [7.8] Class basic_regex
  641. /**
  642. * Objects of specializations of this class represent regular expressions
  643. * constructed from sequences of character type @p _Ch_type.
  644. *
  645. * Storage for the regular expression is allocated and deallocated as
  646. * necessary by the member functions of this class.
  647. */
  648. template<typename _Ch_type, typename _Rx_traits = regex_traits<_Ch_type> >
  649. class basic_regex
  650. {
  651. public:
  652. // types:
  653. typedef _Ch_type value_type;
  654. typedef regex_constants::syntax_option_type flag_type;
  655. typedef typename _Rx_traits::locale_type locale_type;
  656. typedef typename _Rx_traits::string_type string_type;
  657. /**
  658. * @name Constants
  659. * tr1 [7.8.1] std [28.8.1]
  660. */
  661. //@{
  662. static const regex_constants::syntax_option_type icase
  663. = regex_constants::icase;
  664. static const regex_constants::syntax_option_type nosubs
  665. = regex_constants::nosubs;
  666. static const regex_constants::syntax_option_type optimize
  667. = regex_constants::optimize;
  668. static const regex_constants::syntax_option_type collate
  669. = regex_constants::collate;
  670. static const regex_constants::syntax_option_type ECMAScript
  671. = regex_constants::ECMAScript;
  672. static const regex_constants::syntax_option_type basic
  673. = regex_constants::basic;
  674. static const regex_constants::syntax_option_type extended
  675. = regex_constants::extended;
  676. static const regex_constants::syntax_option_type awk
  677. = regex_constants::awk;
  678. static const regex_constants::syntax_option_type grep
  679. = regex_constants::grep;
  680. static const regex_constants::syntax_option_type egrep
  681. = regex_constants::egrep;
  682. //@}
  683. // [7.8.2] construct/copy/destroy
  684. /**
  685. * Constructs a basic regular expression that does not match any
  686. * character sequence.
  687. */
  688. basic_regex()
  689. : _M_flags(regex_constants::ECMAScript), _M_pattern(), _M_mark_count(0)
  690. { _M_compile(); }
  691. /**
  692. * @brief Constructs a basic regular expression from the sequence
  693. * [p, p + char_traits<_Ch_type>::length(p)) interpreted according to the
  694. * flags in @p f.
  695. *
  696. * @param p A pointer to the start of a C-style null-terminated string
  697. * containing a regular expression.
  698. * @param f Flags indicating the syntax rules and options.
  699. *
  700. * @throws regex_error if @p p is not a valid regular expression.
  701. */
  702. explicit
  703. basic_regex(const _Ch_type* __p,
  704. flag_type __f = regex_constants::ECMAScript)
  705. : _M_flags(__f), _M_pattern(__p), _M_mark_count(0)
  706. { _M_compile(); }
  707. /**
  708. * @brief Constructs a basic regular expression from the sequence
  709. * [p, p + len) interpreted according to the flags in @p f.
  710. *
  711. * @param p A pointer to the start of a string containing a regular
  712. * expression.
  713. * @param len The length of the string containing the regular expression.
  714. * @param f Flags indicating the syntax rules and options.
  715. *
  716. * @throws regex_error if @p p is not a valid regular expression.
  717. */
  718. basic_regex(const _Ch_type* __p, std::size_t __len, flag_type __f)
  719. : _M_flags(__f) , _M_pattern(__p, __len), _M_mark_count(0)
  720. { _M_compile(); }
  721. /**
  722. * @brief Copy-constructs a basic regular expression.
  723. *
  724. * @param rhs A @p regex object.
  725. */
  726. basic_regex(const basic_regex& __rhs)
  727. : _M_flags(__rhs._M_flags), _M_pattern(__rhs._M_pattern),
  728. _M_mark_count(__rhs._M_mark_count)
  729. { _M_compile(); }
  730. /**
  731. * @brief Constructs a basic regular expression from the string
  732. * @p s interpreted according to the flags in @p f.
  733. *
  734. * @param s A string containing a regular expression.
  735. * @param f Flags indicating the syntax rules and options.
  736. *
  737. * @throws regex_error if @p s is not a valid regular expression.
  738. */
  739. template<typename _Ch_traits, typename _Ch_alloc>
  740. explicit
  741. basic_regex(const basic_string<_Ch_type, _Ch_traits, _Ch_alloc>& __s,
  742. flag_type __f = regex_constants::ECMAScript)
  743. : _M_flags(__f), _M_pattern(__s.begin(), __s.end()), _M_mark_count(0)
  744. { _M_compile(); }
  745. /**
  746. * @brief Constructs a basic regular expression from the range
  747. * [first, last) interpreted according to the flags in @p f.
  748. *
  749. * @param first The start of a range containing a valid regular
  750. * expression.
  751. * @param last The end of a range containing a valid regular
  752. * expression.
  753. * @param f The format flags of the regular expression.
  754. *
  755. * @throws regex_error if @p [first, last) is not a valid regular
  756. * expression.
  757. */
  758. template<typename _InputIterator>
  759. basic_regex(_InputIterator __first, _InputIterator __last,
  760. flag_type __f = regex_constants::ECMAScript)
  761. : _M_flags(__f), _M_pattern(__first, __last), _M_mark_count(0)
  762. { _M_compile(); }
  763. #ifdef _GLIBCXX_INCLUDE_AS_CXX11
  764. /**
  765. * @brief Constructs a basic regular expression from an initializer list.
  766. *
  767. * @param l The initializer list.
  768. * @param f The format flags of the regular expression.
  769. *
  770. * @throws regex_error if @p l is not a valid regular expression.
  771. */
  772. basic_regex(initializer_list<_Ch_type> __l,
  773. flag_type __f = regex_constants::ECMAScript)
  774. : _M_flags(__f), _M_pattern(__l.begin(), __l.end()), _M_mark_count(0)
  775. { _M_compile(); }
  776. #endif
  777. /**
  778. * @brief Destroys a basic regular expression.
  779. */
  780. ~basic_regex()
  781. { }
  782. /**
  783. * @brief Assigns one regular expression to another.
  784. */
  785. basic_regex&
  786. operator=(const basic_regex& __rhs)
  787. { return this->assign(__rhs); }
  788. /**
  789. * @brief Replaces a regular expression with a new one constructed from
  790. * a C-style null-terminated string.
  791. *
  792. * @param A pointer to the start of a null-terminated C-style string
  793. * containing a regular expression.
  794. */
  795. basic_regex&
  796. operator=(const _Ch_type* __p)
  797. { return this->assign(__p, flags()); }
  798. /**
  799. * @brief Replaces a regular expression with a new one constructed from
  800. * a string.
  801. *
  802. * @param A pointer to a string containing a regular expression.
  803. */
  804. template<typename _Ch_typeraits, typename _Allocator>
  805. basic_regex&
  806. operator=(const basic_string<_Ch_type, _Ch_typeraits, _Allocator>& __s)
  807. { return this->assign(__s, flags()); }
  808. // [7.8.3] assign
  809. /**
  810. * @brief the real assignment operator.
  811. *
  812. * @param that Another regular expression object.
  813. */
  814. basic_regex&
  815. assign(const basic_regex& __that)
  816. {
  817. basic_regex __tmp(__that);
  818. this->swap(__tmp);
  819. return *this;
  820. }
  821. /**
  822. * @brief Assigns a new regular expression to a regex object from a
  823. * C-style null-terminated string containing a regular expression
  824. * pattern.
  825. *
  826. * @param p A pointer to a C-style null-terminated string containing
  827. * a regular expression pattern.
  828. * @param flags Syntax option flags.
  829. *
  830. * @throws regex_error if p does not contain a valid regular expression
  831. * pattern interpreted according to @p flags. If regex_error is thrown,
  832. * *this remains unchanged.
  833. */
  834. basic_regex&
  835. assign(const _Ch_type* __p,
  836. flag_type __flags = regex_constants::ECMAScript)
  837. { return this->assign(string_type(__p), __flags); }
  838. /**
  839. * @brief Assigns a new regular expression to a regex object from a
  840. * C-style string containing a regular expression pattern.
  841. *
  842. * @param p A pointer to a C-style string containing a
  843. * regular expression pattern.
  844. * @param len The length of the regular expression pattern string.
  845. * @param flags Syntax option flags.
  846. *
  847. * @throws regex_error if p does not contain a valid regular expression
  848. * pattern interpreted according to @p flags. If regex_error is thrown,
  849. * *this remains unchanged.
  850. */
  851. basic_regex&
  852. assign(const _Ch_type* __p, std::size_t __len, flag_type __flags)
  853. { return this->assign(string_type(__p, __len), __flags); }
  854. /**
  855. * @brief Assigns a new regular expression to a regex object from a
  856. * string containing a regular expression pattern.
  857. *
  858. * @param s A string containing a regular expression pattern.
  859. * @param flags Syntax option flags.
  860. *
  861. * @throws regex_error if p does not contain a valid regular expression
  862. * pattern interpreted according to @p flags. If regex_error is thrown,
  863. * *this remains unchanged.
  864. */
  865. template<typename _Ch_typeraits, typename _Allocator>
  866. basic_regex&
  867. assign(const basic_string<_Ch_type, _Ch_typeraits, _Allocator>& __s,
  868. flag_type __f = regex_constants::ECMAScript)
  869. {
  870. basic_regex __tmp(__s, __f);
  871. this->swap(__tmp);
  872. return *this;
  873. }
  874. /**
  875. * @brief Assigns a new regular expression to a regex object.
  876. *
  877. * @param first The start of a range containing a valid regular
  878. * expression.
  879. * @param last The end of a range containing a valid regular
  880. * expression.
  881. * @param flags Syntax option flags.
  882. *
  883. * @throws regex_error if p does not contain a valid regular expression
  884. * pattern interpreted according to @p flags. If regex_error is thrown,
  885. * the object remains unchanged.
  886. */
  887. template<typename _InputIterator>
  888. basic_regex&
  889. assign(_InputIterator __first, _InputIterator __last,
  890. flag_type __flags = regex_constants::ECMAScript)
  891. { return this->assign(string_type(__first, __last), __flags); }
  892. #ifdef _GLIBCXX_INCLUDE_AS_CXX11
  893. /**
  894. * @brief Assigns a new regular expression to a regex object.
  895. *
  896. * @param l An initializer list representing a regular expression.
  897. * @param flags Syntax option flags.
  898. *
  899. * @throws regex_error if @p l does not contain a valid regular
  900. * expression pattern interpreted according to @p flags. If regex_error
  901. * is thrown, the object remains unchanged.
  902. */
  903. basic_regex&
  904. assign(initializer_list<_Ch_type> __l,
  905. flag_type __f = regex_constants::ECMAScript)
  906. { return this->assign(__l.begin(), __l.end(), __f); }
  907. #endif
  908. // [7.8.4] const operations
  909. /**
  910. * @brief Gets the number of marked subexpressions within the regular
  911. * expression.
  912. */
  913. unsigned int
  914. mark_count() const
  915. { return _M_mark_count; }
  916. /**
  917. * @brief Gets the flags used to construct the regular expression
  918. * or in the last call to assign().
  919. */
  920. flag_type
  921. flags() const
  922. { return _M_flags; }
  923. // [7.8.5] locale
  924. /**
  925. * @brief Imbues the regular expression object with the given locale.
  926. *
  927. * @param loc A locale.
  928. */
  929. locale_type
  930. imbue(locale_type __loc)
  931. { return _M_traits.imbue(__loc); }
  932. /**
  933. * @brief Gets the locale currently imbued in the regular expression
  934. * object.
  935. */
  936. locale_type
  937. getloc() const
  938. { return _M_traits.getloc(); }
  939. // [7.8.6] swap
  940. /**
  941. * @brief Swaps the contents of two regular expression objects.
  942. *
  943. * @param rhs Another regular expression object.
  944. */
  945. void
  946. swap(basic_regex& __rhs)
  947. {
  948. std::swap(_M_flags, __rhs._M_flags);
  949. std::swap(_M_pattern, __rhs._M_pattern);
  950. std::swap(_M_mark_count, __rhs._M_mark_count);
  951. std::swap(_M_traits, __rhs._M_traits);
  952. }
  953. private:
  954. /**
  955. * @brief Compiles a regular expression pattern into a NFA.
  956. * @todo Implement this function.
  957. */
  958. void _M_compile();
  959. protected:
  960. flag_type _M_flags;
  961. string_type _M_pattern;
  962. unsigned int _M_mark_count;
  963. _Rx_traits _M_traits;
  964. };
  965. /** @brief Standard regular expressions. */
  966. typedef basic_regex<char> regex;
  967. #ifdef _GLIBCXX_USE_WCHAR_T
  968. /** @brief Standard wide-character regular expressions. */
  969. typedef basic_regex<wchar_t> wregex;
  970. #endif
  971. // [7.8.6] basic_regex swap
  972. /**
  973. * @brief Swaps the contents of two regular expression objects.
  974. * @param lhs First regular expression.
  975. * @param rhs Second regular expression.
  976. */
  977. template<typename _Ch_type, typename _Rx_traits>
  978. inline void
  979. swap(basic_regex<_Ch_type, _Rx_traits>& __lhs,
  980. basic_regex<_Ch_type, _Rx_traits>& __rhs)
  981. { __lhs.swap(__rhs); }
  982. // [7.9] Class template sub_match
  983. /**
  984. * A sequence of characters matched by a particular marked sub-expression.
  985. *
  986. * An object of this class is essentially a pair of iterators marking a
  987. * matched subexpression within a regular expression pattern match. Such
  988. * objects can be converted to and compared with std::basic_string objects
  989. * of a similar base character type as the pattern matched by the regular
  990. * expression.
  991. *
  992. * The iterators that make up the pair are the usual half-open interval
  993. * referencing the actual original pattern matched.
  994. */
  995. template<typename _BiIter>
  996. class sub_match : public std::pair<_BiIter, _BiIter>
  997. {
  998. public:
  999. typedef typename iterator_traits<_BiIter>::value_type value_type;
  1000. typedef typename iterator_traits<_BiIter>::difference_type
  1001. difference_type;
  1002. typedef _BiIter iterator;
  1003. public:
  1004. bool matched;
  1005. /**
  1006. * Gets the length of the matching sequence.
  1007. */
  1008. difference_type
  1009. length() const
  1010. { return this->matched ? std::distance(this->first, this->second) : 0; }
  1011. /**
  1012. * @brief Gets the matching sequence as a string.
  1013. *
  1014. * @returns the matching sequence as a string.
  1015. *
  1016. * This is the implicit conversion operator. It is identical to the
  1017. * str() member function except that it will want to pop up in
  1018. * unexpected places and cause a great deal of confusion and cursing
  1019. * from the unwary.
  1020. */
  1021. operator basic_string<value_type>() const
  1022. {
  1023. return this->matched
  1024. ? std::basic_string<value_type>(this->first, this->second)
  1025. : std::basic_string<value_type>();
  1026. }
  1027. /**
  1028. * @brief Gets the matching sequence as a string.
  1029. *
  1030. * @returns the matching sequence as a string.
  1031. */
  1032. basic_string<value_type>
  1033. str() const
  1034. {
  1035. return this->matched
  1036. ? std::basic_string<value_type>(this->first, this->second)
  1037. : std::basic_string<value_type>();
  1038. }
  1039. /**
  1040. * @brief Compares this and another matched sequence.
  1041. *
  1042. * @param s Another matched sequence to compare to this one.
  1043. *
  1044. * @retval <0 this matched sequence will collate before @p s.
  1045. * @retval =0 this matched sequence is equivalent to @p s.
  1046. * @retval <0 this matched sequence will collate after @p s.
  1047. */
  1048. int
  1049. compare(const sub_match& __s) const
  1050. { return this->str().compare(__s.str()); }
  1051. /**
  1052. * @brief Compares this sub_match to a string.
  1053. *
  1054. * @param s A string to compare to this sub_match.
  1055. *
  1056. * @retval <0 this matched sequence will collate before @p s.
  1057. * @retval =0 this matched sequence is equivalent to @p s.
  1058. * @retval <0 this matched sequence will collate after @p s.
  1059. */
  1060. int
  1061. compare(const basic_string<value_type>& __s) const
  1062. { return this->str().compare(__s); }
  1063. /**
  1064. * @brief Compares this sub_match to a C-style string.
  1065. *
  1066. * @param s A C-style string to compare to this sub_match.
  1067. *
  1068. * @retval <0 this matched sequence will collate before @p s.
  1069. * @retval =0 this matched sequence is equivalent to @p s.
  1070. * @retval <0 this matched sequence will collate after @p s.
  1071. */
  1072. int
  1073. compare(const value_type* __s) const
  1074. { return this->str().compare(__s); }
  1075. };
  1076. /** @brief Standard regex submatch over a C-style null-terminated string. */
  1077. typedef sub_match<const char*> csub_match;
  1078. /** @brief Standard regex submatch over a standard string. */
  1079. typedef sub_match<string::const_iterator> ssub_match;
  1080. #ifdef _GLIBCXX_USE_WCHAR_T
  1081. /** @brief Regex submatch over a C-style null-terminated wide string. */
  1082. typedef sub_match<const wchar_t*> wcsub_match;
  1083. /** @brief Regex submatch over a standard wide string. */
  1084. typedef sub_match<wstring::const_iterator> wssub_match;
  1085. #endif
  1086. // [7.9.2] sub_match non-member operators
  1087. /**
  1088. * @brief Tests the equivalence of two regular expression submatches.
  1089. * @param lhs First regular expression submatch.
  1090. * @param rhs Second regular expression submatch.
  1091. * @returns true if @a lhs is equivalent to @a rhs, false otherwise.
  1092. */
  1093. template<typename _BiIter>
  1094. inline bool
  1095. operator==(const sub_match<_BiIter>& __lhs,
  1096. const sub_match<_BiIter>& __rhs)
  1097. { return __lhs.compare(__rhs) == 0; }
  1098. /**
  1099. * @brief Tests the inequivalence of two regular expression submatches.
  1100. * @param lhs First regular expression submatch.
  1101. * @param rhs Second regular expression submatch.
  1102. * @returns true if @a lhs is not equivalent to @a rhs, false otherwise.
  1103. */
  1104. template<typename _BiIter>
  1105. inline bool
  1106. operator!=(const sub_match<_BiIter>& __lhs,
  1107. const sub_match<_BiIter>& __rhs)
  1108. { return __lhs.compare(__rhs) != 0; }
  1109. /**
  1110. * @brief Tests the ordering of two regular expression submatches.
  1111. * @param lhs First regular expression submatch.
  1112. * @param rhs Second regular expression submatch.
  1113. * @returns true if @a lhs precedes @a rhs, false otherwise.
  1114. */
  1115. template<typename _BiIter>
  1116. inline bool
  1117. operator<(const sub_match<_BiIter>& __lhs,
  1118. const sub_match<_BiIter>& __rhs)
  1119. { return __lhs.compare(__rhs) < 0; }
  1120. /**
  1121. * @brief Tests the ordering of two regular expression submatches.
  1122. * @param lhs First regular expression submatch.
  1123. * @param rhs Second regular expression submatch.
  1124. * @returns true if @a lhs does not succeed @a rhs, false otherwise.
  1125. */
  1126. template<typename _BiIter>
  1127. inline bool
  1128. operator<=(const sub_match<_BiIter>& __lhs,
  1129. const sub_match<_BiIter>& __rhs)
  1130. { return __lhs.compare(__rhs) <= 0; }
  1131. /**
  1132. * @brief Tests the ordering of two regular expression submatches.
  1133. * @param lhs First regular expression submatch.
  1134. * @param rhs Second regular expression submatch.
  1135. * @returns true if @a lhs does not precede @a rhs, false otherwise.
  1136. */
  1137. template<typename _BiIter>
  1138. inline bool
  1139. operator>=(const sub_match<_BiIter>& __lhs,
  1140. const sub_match<_BiIter>& __rhs)
  1141. { return __lhs.compare(__rhs) >= 0; }
  1142. /**
  1143. * @brief Tests the ordering of two regular expression submatches.
  1144. * @param lhs First regular expression submatch.
  1145. * @param rhs Second regular expression submatch.
  1146. * @returns true if @a lhs succeeds @a rhs, false otherwise.
  1147. */
  1148. template<typename _BiIter>
  1149. inline bool
  1150. operator>(const sub_match<_BiIter>& __lhs,
  1151. const sub_match<_BiIter>& __rhs)
  1152. { return __lhs.compare(__rhs) > 0; }
  1153. /**
  1154. * @brief Tests the equivalence of a string and a regular expression
  1155. * submatch.
  1156. * @param lhs A 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, typename _Ch_traits, typename _Ch_alloc>
  1161. inline bool
  1162. operator==(const basic_string<
  1163. typename iterator_traits<_Bi_iter>::value_type,
  1164. _Ch_traits, _Ch_alloc>& __lhs,
  1165. const sub_match<_Bi_iter>& __rhs)
  1166. { return __lhs == __rhs.str(); }
  1167. /**
  1168. * @brief Tests the inequivalence of a string and a regular expression
  1169. * submatch.
  1170. * @param lhs A string.
  1171. * @param rhs A regular expression submatch.
  1172. * @returns true if @a lhs is not equivalent to @a rhs, false otherwise.
  1173. */
  1174. template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
  1175. inline bool
  1176. operator!=(const basic_string<
  1177. typename iterator_traits<_Bi_iter>::value_type,
  1178. _Ch_traits, _Ch_alloc>& __lhs, const sub_match<_Bi_iter>& __rhs)
  1179. { return __lhs != __rhs.str(); }
  1180. /**
  1181. * @brief Tests the ordering of a string and a regular expression submatch.
  1182. * @param lhs A string.
  1183. * @param rhs A regular expression submatch.
  1184. * @returns true if @a lhs precedes @a rhs, false otherwise.
  1185. */
  1186. template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
  1187. inline bool
  1188. operator<(const basic_string<
  1189. typename iterator_traits<_Bi_iter>::value_type,
  1190. _Ch_traits, _Ch_alloc>& __lhs, const sub_match<_Bi_iter>& __rhs)
  1191. { return __lhs < __rhs.str(); }
  1192. /**
  1193. * @brief Tests the ordering of a string and a regular expression submatch.
  1194. * @param lhs A string.
  1195. * @param rhs A regular expression submatch.
  1196. * @returns true if @a lhs succeeds @a rhs, false otherwise.
  1197. */
  1198. template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
  1199. inline bool
  1200. operator>(const basic_string<
  1201. typename iterator_traits<_Bi_iter>::value_type,
  1202. _Ch_traits, _Ch_alloc>& __lhs, const sub_match<_Bi_iter>& __rhs)
  1203. { return __lhs > __rhs.str(); }
  1204. /**
  1205. * @brief Tests the ordering of a string and a regular expression submatch.
  1206. * @param lhs A string.
  1207. * @param rhs A regular expression submatch.
  1208. * @returns true if @a lhs does not precede @a rhs, false otherwise.
  1209. */
  1210. template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
  1211. inline bool
  1212. operator>=(const basic_string<
  1213. typename iterator_traits<_Bi_iter>::value_type,
  1214. _Ch_traits, _Ch_alloc>& __lhs, const sub_match<_Bi_iter>& __rhs)
  1215. { return __lhs >= __rhs.str(); }
  1216. /**
  1217. * @brief Tests the ordering of a string and a regular expression submatch.
  1218. * @param lhs A string.
  1219. * @param rhs A regular expression submatch.
  1220. * @returns true if @a lhs does not succeed @a rhs, false otherwise.
  1221. */
  1222. template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
  1223. inline bool
  1224. operator<=(const basic_string<
  1225. typename iterator_traits<_Bi_iter>::value_type,
  1226. _Ch_traits, _Ch_alloc>& __lhs, const sub_match<_Bi_iter>& __rhs)
  1227. { return __lhs <= __rhs.str(); }
  1228. /**
  1229. * @brief Tests the equivalence of a regular expression submatch and a
  1230. * string.
  1231. * @param lhs A regular expression submatch.
  1232. * @param rhs A string.
  1233. * @returns true if @a lhs is equivalent to @a rhs, false otherwise.
  1234. */
  1235. template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
  1236. inline bool
  1237. operator==(const sub_match<_Bi_iter>& __lhs,
  1238. const basic_string<
  1239. typename iterator_traits<_Bi_iter>::value_type,
  1240. _Ch_traits, _Ch_alloc>& __rhs)
  1241. { return __lhs.str() == __rhs; }
  1242. /**
  1243. * @brief Tests the inequivalence of a regular expression submatch and a
  1244. * string.
  1245. * @param lhs A regular expression submatch.
  1246. * @param rhs A string.
  1247. * @returns true if @a lhs is not equivalent to @a rhs, false otherwise.
  1248. */
  1249. template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
  1250. inline bool
  1251. operator!=(const sub_match<_Bi_iter>& __lhs,
  1252. const basic_string<
  1253. typename iterator_traits<_Bi_iter>::value_type,
  1254. _Ch_traits, _Ch_alloc>& __rhs)
  1255. { return __lhs.str() != __rhs; }
  1256. /**
  1257. * @brief Tests the ordering of a regular expression submatch and a string.
  1258. * @param lhs A regular expression submatch.
  1259. * @param rhs A string.
  1260. * @returns true if @a lhs precedes @a rhs, false otherwise.
  1261. */
  1262. template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc>
  1263. inline bool
  1264. operator<(const sub_match<_Bi_iter>& __lhs,
  1265. const basic_string<
  1266. typename iterator_traits<_Bi_iter>::value_type,
  1267. _Ch_traits, _Ch_alloc>& __rhs)
  1268. { return __lhs.str() < __rhs; }
  1269. /**
  1270. * @brief Tests the ordering of a regular expression submatch and a string.
  1271. * @param lhs A regular expression submatch.
  1272. * @param rhs A string.
  1273. * @returns true if @a lhs succeeds @a rhs, false otherwise.
  1274. */
  1275. template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc>
  1276. inline bool
  1277. operator>(const sub_match<_Bi_iter>& __lhs,
  1278. const basic_string<
  1279. typename iterator_traits<_Bi_iter>::value_type,
  1280. _Ch_traits, _Ch_alloc>& __rhs)
  1281. { return __lhs.str() > __rhs; }
  1282. /**
  1283. * @brief Tests the ordering of a regular expression submatch and a string.
  1284. * @param lhs A regular expression submatch.
  1285. * @param rhs A string.
  1286. * @returns true if @a lhs does not precede @a rhs, false otherwise.
  1287. */
  1288. template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc>
  1289. inline bool
  1290. operator>=(const sub_match<_Bi_iter>& __lhs,
  1291. const basic_string<
  1292. typename iterator_traits<_Bi_iter>::value_type,
  1293. _Ch_traits, _Ch_alloc>& __rhs)
  1294. { return __lhs.str() >= __rhs; }
  1295. /**
  1296. * @brief Tests the ordering of a regular expression submatch and a string.
  1297. * @param lhs A regular expression submatch.
  1298. * @param rhs A string.
  1299. * @returns true if @a lhs does not succeed @a rhs, false otherwise.
  1300. */
  1301. template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc>
  1302. inline bool
  1303. operator<=(const sub_match<_Bi_iter>& __lhs,
  1304. const basic_string<
  1305. typename iterator_traits<_Bi_iter>::value_type,
  1306. _Ch_traits, _Ch_alloc>& __rhs)
  1307. { return __lhs.str() <= __rhs; }
  1308. /**
  1309. * @brief Tests the equivalence of a C string and a regular expression
  1310. * submatch.
  1311. * @param lhs A C string.
  1312. * @param rhs A regular expression submatch.
  1313. * @returns true if @a lhs is equivalent to @a rhs, false otherwise.
  1314. */
  1315. template<typename _Bi_iter>
  1316. inline bool
  1317. operator==(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
  1318. const sub_match<_Bi_iter>& __rhs)
  1319. { return __lhs == __rhs.str(); }
  1320. /**
  1321. * @brief Tests the inequivalence of an iterator value and a regular
  1322. * expression submatch.
  1323. * @param lhs A regular expression submatch.
  1324. * @param rhs A string.
  1325. * @returns true if @a lhs is not equivalent to @a rhs, false otherwise.
  1326. */
  1327. template<typename _Bi_iter>
  1328. inline bool
  1329. operator!=(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
  1330. const sub_match<_Bi_iter>& __rhs)
  1331. { return __lhs != __rhs.str(); }
  1332. /**
  1333. * @brief Tests the ordering of a string and a regular expression submatch.
  1334. * @param lhs A string.
  1335. * @param rhs A regular expression submatch.
  1336. * @returns true if @a lhs precedes @a rhs, false otherwise.
  1337. */
  1338. template<typename _Bi_iter>
  1339. inline bool
  1340. operator<(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
  1341. const sub_match<_Bi_iter>& __rhs)
  1342. { return __lhs < __rhs.str(); }
  1343. /**
  1344. * @brief Tests the ordering of a string and a regular expression submatch.
  1345. * @param lhs A string.
  1346. * @param rhs A regular expression submatch.
  1347. * @returns true if @a lhs succeeds @a rhs, false otherwise.
  1348. */
  1349. template<typename _Bi_iter>
  1350. inline bool
  1351. operator>(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
  1352. const sub_match<_Bi_iter>& __rhs)
  1353. { return __lhs > __rhs.str(); }
  1354. /**
  1355. * @brief Tests the ordering of a string and a regular expression submatch.
  1356. * @param lhs A string.
  1357. * @param rhs A regular expression submatch.
  1358. * @returns true if @a lhs does not precede @a rhs, false otherwise.
  1359. */
  1360. template<typename _Bi_iter>
  1361. inline bool
  1362. operator>=(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
  1363. const sub_match<_Bi_iter>& __rhs)
  1364. { return __lhs >= __rhs.str(); }
  1365. /**
  1366. * @brief Tests the ordering of a string and a regular expression submatch.
  1367. * @param lhs A string.
  1368. * @param rhs A regular expression submatch.
  1369. * @returns true if @a lhs does not succeed @a rhs, false otherwise.
  1370. */
  1371. template<typename _Bi_iter>
  1372. inline bool
  1373. operator<=(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
  1374. const sub_match<_Bi_iter>& __rhs)
  1375. { return __lhs <= __rhs.str(); }
  1376. /**
  1377. * @brief Tests the equivalence of a regular expression submatch and a
  1378. * string.
  1379. * @param lhs A regular expression submatch.
  1380. * @param rhs A pointer to a string?
  1381. * @returns true if @a lhs is equivalent to @a rhs, false otherwise.
  1382. */
  1383. template<typename _Bi_iter>
  1384. inline bool
  1385. operator==(const sub_match<_Bi_iter>& __lhs,
  1386. typename iterator_traits<_Bi_iter>::value_type const* __rhs)
  1387. { return __lhs.str() == __rhs; }
  1388. /**
  1389. * @brief Tests the inequivalence of a regular expression submatch and a
  1390. * string.
  1391. * @param lhs A regular expression submatch.
  1392. * @param rhs A pointer to a string.
  1393. * @returns true if @a lhs is not equivalent to @a rhs, false otherwise.
  1394. */
  1395. template<typename _Bi_iter>
  1396. inline bool
  1397. operator!=(const sub_match<_Bi_iter>& __lhs,
  1398. typename iterator_traits<_Bi_iter>::value_type const* __rhs)
  1399. { return __lhs.str() != __rhs; }
  1400. /**
  1401. * @brief Tests the ordering of a regular expression submatch and a string.
  1402. * @param lhs A regular expression submatch.
  1403. * @param rhs A string.
  1404. * @returns true if @a lhs precedes @a rhs, false otherwise.
  1405. */
  1406. template<typename _Bi_iter>
  1407. inline bool
  1408. operator<(const sub_match<_Bi_iter>& __lhs,
  1409. typename iterator_traits<_Bi_iter>::value_type const* __rhs)
  1410. { return __lhs.str() < __rhs; }
  1411. /**
  1412. * @brief Tests the ordering of a regular expression submatch and a string.
  1413. * @param lhs A regular expression submatch.
  1414. * @param rhs A string.
  1415. * @returns true if @a lhs succeeds @a rhs, false otherwise.
  1416. */
  1417. template<typename _Bi_iter>
  1418. inline bool
  1419. operator>(const sub_match<_Bi_iter>& __lhs,
  1420. typename iterator_traits<_Bi_iter>::value_type const* __rhs)
  1421. { return __lhs.str() > __rhs; }
  1422. /**
  1423. * @brief Tests the ordering of a regular expression submatch and a string.
  1424. * @param lhs A regular expression submatch.
  1425. * @param rhs A string.
  1426. * @returns true if @a lhs does not precede @a rhs, false otherwise.
  1427. */
  1428. template<typename _Bi_iter>
  1429. inline bool
  1430. operator>=(const sub_match<_Bi_iter>& __lhs,
  1431. typename iterator_traits<_Bi_iter>::value_type const* __rhs)
  1432. { return __lhs.str() >= __rhs; }
  1433. /**
  1434. * @brief Tests the ordering of a regular expression submatch and a string.
  1435. * @param lhs A regular expression submatch.
  1436. * @param rhs A string.
  1437. * @returns true if @a lhs does not succeed @a rhs, false otherwise.
  1438. */
  1439. template<typename _Bi_iter>
  1440. inline bool
  1441. operator<=(const sub_match<_Bi_iter>& __lhs,
  1442. typename iterator_traits<_Bi_iter>::value_type const* __rhs)
  1443. { return __lhs.str() <= __rhs; }
  1444. /**
  1445. * @brief Tests the equivalence of a string and a regular expression
  1446. * submatch.
  1447. * @param lhs A string.
  1448. * @param rhs A regular expression submatch.
  1449. * @returns true if @a lhs is equivalent to @a rhs, false otherwise.
  1450. */
  1451. template<typename _Bi_iter>
  1452. inline bool
  1453. operator==(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
  1454. const sub_match<_Bi_iter>& __rhs)
  1455. { return __lhs == __rhs.str(); }
  1456. /**
  1457. * @brief Tests the inequivalence of a string and a regular expression
  1458. * submatch.
  1459. * @param lhs A string.
  1460. * @param rhs A regular expression submatch.
  1461. * @returns true if @a lhs is not equivalent to @a rhs, false otherwise.
  1462. */
  1463. template<typename _Bi_iter>
  1464. inline bool
  1465. operator!=(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
  1466. const sub_match<_Bi_iter>& __rhs)
  1467. { return __lhs != __rhs.str(); }
  1468. /**
  1469. * @brief Tests the ordering of a string and a regular expression submatch.
  1470. * @param lhs A string.
  1471. * @param rhs A regular expression submatch.
  1472. * @returns true if @a lhs precedes @a rhs, false otherwise.
  1473. */
  1474. template<typename _Bi_iter>
  1475. inline bool
  1476. operator<(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
  1477. const sub_match<_Bi_iter>& __rhs)
  1478. { return __lhs < __rhs.str(); }
  1479. /**
  1480. * @brief Tests the ordering of a string and a regular expression submatch.
  1481. * @param lhs A string.
  1482. * @param rhs A regular expression submatch.
  1483. * @returns true if @a lhs succeeds @a rhs, false otherwise.
  1484. */
  1485. template<typename _Bi_iter>
  1486. inline bool
  1487. operator>(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
  1488. const sub_match<_Bi_iter>& __rhs)
  1489. { return __lhs > __rhs.str(); }
  1490. /**
  1491. * @brief Tests the ordering of a string and a regular expression submatch.
  1492. * @param lhs A string.
  1493. * @param rhs A regular expression submatch.
  1494. * @returns true if @a lhs does not precede @a rhs, false otherwise.
  1495. */
  1496. template<typename _Bi_iter>
  1497. inline bool
  1498. operator>=(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
  1499. const sub_match<_Bi_iter>& __rhs)
  1500. { return __lhs >= __rhs.str(); }
  1501. /**
  1502. * @brief Tests the ordering of a string and a regular expression submatch.
  1503. * @param lhs A string.
  1504. * @param rhs A regular expression submatch.
  1505. * @returns true if @a lhs does not succeed @a rhs, false otherwise.
  1506. */
  1507. template<typename _Bi_iter>
  1508. inline bool
  1509. operator<=(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
  1510. const sub_match<_Bi_iter>& __rhs)
  1511. { return __lhs <= __rhs.str(); }
  1512. /**
  1513. * @brief Tests the equivalence of a regular expression submatch and a
  1514. * string.
  1515. * @param lhs A regular expression submatch.
  1516. * @param rhs A const string reference.
  1517. * @returns true if @a lhs is equivalent to @a rhs, false otherwise.
  1518. */
  1519. template<typename _Bi_iter>
  1520. inline bool
  1521. operator==(const sub_match<_Bi_iter>& __lhs,
  1522. typename iterator_traits<_Bi_iter>::value_type const& __rhs)
  1523. { return __lhs.str() == __rhs; }
  1524. /**
  1525. * @brief Tests the inequivalence of a regular expression submatch and a
  1526. * string.
  1527. * @param lhs A regular expression submatch.
  1528. * @param rhs A const string reference.
  1529. * @returns true if @a lhs is not equivalent to @a rhs, false otherwise.
  1530. */
  1531. template<typename _Bi_iter>
  1532. inline bool
  1533. operator!=(const sub_match<_Bi_iter>& __lhs,
  1534. typename iterator_traits<_Bi_iter>::value_type const& __rhs)
  1535. { return __lhs.str() != __rhs; }
  1536. /**
  1537. * @brief Tests the ordering of a regular expression submatch and a string.
  1538. * @param lhs A regular expression submatch.
  1539. * @param rhs A const string reference.
  1540. * @returns true if @a lhs precedes @a rhs, false otherwise.
  1541. */
  1542. template<typename _Bi_iter>
  1543. inline bool
  1544. operator<(const sub_match<_Bi_iter>& __lhs,
  1545. typename iterator_traits<_Bi_iter>::value_type const& __rhs)
  1546. { return __lhs.str() < __rhs; }
  1547. /**
  1548. * @brief Tests the ordering of a regular expression submatch and a string.
  1549. * @param lhs A regular expression submatch.
  1550. * @param rhs A const string reference.
  1551. * @returns true if @a lhs succeeds @a rhs, false otherwise.
  1552. */
  1553. template<typename _Bi_iter>
  1554. inline bool
  1555. operator>(const sub_match<_Bi_iter>& __lhs,
  1556. typename iterator_traits<_Bi_iter>::value_type const& __rhs)
  1557. { return __lhs.str() > __rhs; }
  1558. /**
  1559. * @brief Tests the ordering of a regular expression submatch and a string.
  1560. * @param lhs A regular expression submatch.
  1561. * @param rhs A const string reference.
  1562. * @returns true if @a lhs does not precede @a rhs, false otherwise.
  1563. */
  1564. template<typename _Bi_iter>
  1565. inline bool
  1566. operator>=(const sub_match<_Bi_iter>& __lhs,
  1567. typename iterator_traits<_Bi_iter>::value_type const& __rhs)
  1568. { return __lhs.str() >= __rhs; }
  1569. /**
  1570. * @brief Tests the ordering of a regular expression submatch and a string.
  1571. * @param lhs A regular expression submatch.
  1572. * @param rhs A const string reference.
  1573. * @returns true if @a lhs does not succeed @a rhs, false otherwise.
  1574. */
  1575. template<typename _Bi_iter>
  1576. inline bool
  1577. operator<=(const sub_match<_Bi_iter>& __lhs,
  1578. typename iterator_traits<_Bi_iter>::value_type const& __rhs)
  1579. { return __lhs.str() <= __rhs; }
  1580. /**
  1581. * @brief Inserts a matched string into an output stream.
  1582. *
  1583. * @param os The output stream.
  1584. * @param m A submatch string.
  1585. *
  1586. * @returns the output stream with the submatch string inserted.
  1587. */
  1588. template<typename _Ch_type, typename _Ch_traits, typename _Bi_iter>
  1589. inline
  1590. basic_ostream<_Ch_type, _Ch_traits>&
  1591. operator<<(basic_ostream<_Ch_type, _Ch_traits>& __os,
  1592. const sub_match<_Bi_iter>& __m)
  1593. { return __os << __m.str(); }
  1594. // [7.10] Class template match_results
  1595. /**
  1596. * @brief The results of a match or search operation.
  1597. *
  1598. * A collection of character sequences representing the result of a regular
  1599. * expression match. Storage for the collection is allocated and freed as
  1600. * necessary by the member functions of class template match_results.
  1601. *
  1602. * This class satisfies the Sequence requirements, with the exception that
  1603. * only the operations defined for a const-qualified Sequence are supported.
  1604. *
  1605. * The sub_match object stored at index 0 represents sub-expression 0, i.e.
  1606. * the whole match. In this case the sub_match member matched is always true.
  1607. * The sub_match object stored at index n denotes what matched the marked
  1608. * sub-expression n within the matched expression. If the sub-expression n
  1609. * participated in a regular expression match then the sub_match member
  1610. * matched evaluates to true, and members first and second denote the range
  1611. * of characters [first, second) which formed that match. Otherwise matched
  1612. * is false, and members first and second point to the end of the sequence
  1613. * that was searched.
  1614. *
  1615. * @nosubgrouping
  1616. */
  1617. template<typename _Bi_iter,
  1618. typename _Allocator = allocator<sub_match<_Bi_iter> > >
  1619. class match_results
  1620. : private std::vector<std::tr1::sub_match<_Bi_iter>, _Allocator>
  1621. {
  1622. private:
  1623. typedef std::vector<std::tr1::sub_match<_Bi_iter>, _Allocator>
  1624. _Base_type;
  1625. public:
  1626. /**
  1627. * @name 10.? Public Types
  1628. */
  1629. //@{
  1630. typedef sub_match<_Bi_iter> value_type;
  1631. typedef typename _Allocator::const_reference const_reference;
  1632. typedef const_reference reference;
  1633. typedef typename _Base_type::const_iterator const_iterator;
  1634. typedef const_iterator iterator;
  1635. typedef typename iterator_traits<_Bi_iter>::difference_type
  1636. difference_type;
  1637. typedef typename _Allocator::size_type size_type;
  1638. typedef _Allocator allocator_type;
  1639. typedef typename iterator_traits<_Bi_iter>::value_type char_type;
  1640. typedef basic_string<char_type> string_type;
  1641. //@}
  1642. public:
  1643. /**
  1644. * @name 10.1 Construction, Copying, and Destruction
  1645. */
  1646. //@{
  1647. /**
  1648. * @brief Constructs a default %match_results container.
  1649. * @post size() returns 0 and str() returns an empty string.
  1650. */
  1651. explicit
  1652. match_results(const _Allocator& __a = _Allocator())
  1653. : _Base_type(__a), _M_matched(false)
  1654. { }
  1655. /**
  1656. * @brief Copy constructs a %match_results.
  1657. */
  1658. match_results(const match_results& __rhs)
  1659. : _Base_type(__rhs), _M_matched(__rhs._M_matched),
  1660. _M_prefix(__rhs._M_prefix), _M_suffix(__rhs._M_suffix)
  1661. { }
  1662. /**
  1663. * @brief Assigns rhs to *this.
  1664. */
  1665. match_results&
  1666. operator=(const match_results& __rhs)
  1667. {
  1668. match_results __tmp(__rhs);
  1669. this->swap(__tmp);
  1670. return *this;
  1671. }
  1672. /**
  1673. * @brief Destroys a %match_results object.
  1674. */
  1675. ~match_results()
  1676. { }
  1677. //@}
  1678. /**
  1679. * @name 10.2 Size
  1680. */
  1681. //@{
  1682. /**
  1683. * @brief Gets the number of matches and submatches.
  1684. *
  1685. * The number of matches for a given regular expression will be either 0
  1686. * if there was no match or mark_count() + 1 if a match was successful.
  1687. * Some matches may be empty.
  1688. *
  1689. * @returns the number of matches found.
  1690. */
  1691. size_type
  1692. size() const
  1693. { return _M_matched ? _Base_type::size() + 1 : 0; }
  1694. //size_type
  1695. //max_size() const;
  1696. using _Base_type::max_size;
  1697. /**
  1698. * @brief Indicates if the %match_results contains no results.
  1699. * @retval true The %match_results object is empty.
  1700. * @retval false The %match_results object is not empty.
  1701. */
  1702. bool
  1703. empty() const
  1704. { return size() == 0; }
  1705. //@}
  1706. /**
  1707. * @name 10.3 Element Access
  1708. */
  1709. //@{
  1710. /**
  1711. * @brief Gets the length of the indicated submatch.
  1712. * @param sub indicates the submatch.
  1713. *
  1714. * This function returns the length of the indicated submatch, or the
  1715. * length of the entire match if @p sub is zero (the default).
  1716. */
  1717. difference_type
  1718. length(size_type __sub = 0) const
  1719. { return _M_matched ? this->str(__sub).length() : 0; }
  1720. /**
  1721. * @brief Gets the offset of the beginning of the indicated submatch.
  1722. * @param sub indicates the submatch.
  1723. *
  1724. * This function returns the offset from the beginning of the target
  1725. * sequence to the beginning of the submatch, unless the value of @p sub
  1726. * is zero (the default), in which case this function returns the offset
  1727. * from the beginning of the target sequence to the beginning of the
  1728. * match.
  1729. */
  1730. difference_type
  1731. position(size_type __sub = 0) const
  1732. {
  1733. return _M_matched ? std::distance(this->prefix().first,
  1734. (*this)[__sub].first) : 0;
  1735. }
  1736. /**
  1737. * @brief Gets the match or submatch converted to a string type.
  1738. * @param sub indicates the submatch.
  1739. *
  1740. * This function gets the submatch (or match, if @p sub is zero) extracted
  1741. * from the target range and converted to the associated string type.
  1742. */
  1743. string_type
  1744. str(size_type __sub = 0) const
  1745. { return _M_matched ? (*this)[__sub].str() : string_type(); }
  1746. /**
  1747. * @brief Gets a %sub_match reference for the match or submatch.
  1748. * @param sub indicates the submatch.
  1749. *
  1750. * This function gets a reference to the indicated submatch, or the entire
  1751. * match if @p sub is zero.
  1752. *
  1753. * If @p sub >= size() then this function returns a %sub_match with a
  1754. * special value indicating no submatch.
  1755. */
  1756. const_reference
  1757. operator[](size_type __sub) const
  1758. { return _Base_type::operator[](__sub); }
  1759. /**
  1760. * @brief Gets a %sub_match representing the match prefix.
  1761. *
  1762. * This function gets a reference to a %sub_match object representing the
  1763. * part of the target range between the start of the target range and the
  1764. * start of the match.
  1765. */
  1766. const_reference
  1767. prefix() const
  1768. { return _M_prefix; }
  1769. /**
  1770. * @brief Gets a %sub_match representing the match suffix.
  1771. *
  1772. * This function gets a reference to a %sub_match object representing the
  1773. * part of the target range between the end of the match and the end of
  1774. * the target range.
  1775. */
  1776. const_reference
  1777. suffix() const
  1778. { return _M_suffix; }
  1779. /**
  1780. * @brief Gets an iterator to the start of the %sub_match collection.
  1781. */
  1782. const_iterator
  1783. begin() const
  1784. { return _Base_type::begin(); }
  1785. #ifdef _GLIBCXX_INCLUDE_AS_CXX11
  1786. /**
  1787. * @brief Gets an iterator to the start of the %sub_match collection.
  1788. */
  1789. const_iterator
  1790. cbegin() const
  1791. { return _Base_type::begin(); }
  1792. #endif
  1793. /**
  1794. * @brief Gets an iterator to one-past-the-end of the collection.
  1795. */
  1796. const_iterator
  1797. end() const
  1798. { return _Base_type::end(); }
  1799. #ifdef _GLIBCXX_INCLUDE_AS_CXX11
  1800. /**
  1801. * @brief Gets an iterator to one-past-the-end of the collection.
  1802. */
  1803. const_iterator
  1804. cend() const
  1805. { return _Base_type::end(); }
  1806. #endif
  1807. //@}
  1808. /**
  1809. * @name 10.4 Formatting
  1810. *
  1811. * These functions perform formatted substitution of the matched
  1812. * character sequences into their target. The format specifiers
  1813. * and escape sequences accepted by these functions are
  1814. * determined by their @p flags parameter as documented above.
  1815. */
  1816. //@{
  1817. /**
  1818. * @todo Implement this function.
  1819. */
  1820. template<typename _Out_iter>
  1821. _Out_iter
  1822. format(_Out_iter __out, const string_type& __fmt,
  1823. regex_constants::match_flag_type __flags
  1824. = regex_constants::format_default) const;
  1825. /**
  1826. * @todo Implement this function.
  1827. */
  1828. string_type
  1829. format(const string_type& __fmt,
  1830. regex_constants::match_flag_type __flags
  1831. = regex_constants::format_default) const;
  1832. //@}
  1833. /**
  1834. * @name 10.5 Allocator
  1835. */
  1836. //@{
  1837. /**
  1838. * @brief Gets a copy of the allocator.
  1839. */
  1840. //allocator_type
  1841. //get_allocator() const;
  1842. using _Base_type::get_allocator;
  1843. //@}
  1844. /**
  1845. * @name 10.6 Swap
  1846. */
  1847. //@{
  1848. /**
  1849. * @brief Swaps the contents of two match_results.
  1850. */
  1851. void
  1852. swap(match_results& __that)
  1853. {
  1854. _Base_type::swap(__that);
  1855. std::swap(_M_matched, __that._M_matched);
  1856. std::swap(_M_prefix, __that._M_prefix);
  1857. std::swap(_M_suffix, __that._M_suffix);
  1858. }
  1859. //@}
  1860. private:
  1861. bool _M_matched;
  1862. value_type _M_prefix;
  1863. value_type _M_suffix;
  1864. };
  1865. typedef match_results<const char*> cmatch;
  1866. typedef match_results<string::const_iterator> smatch;
  1867. #ifdef _GLIBCXX_USE_WCHAR_T
  1868. typedef match_results<const wchar_t*> wcmatch;
  1869. typedef match_results<wstring::const_iterator> wsmatch;
  1870. #endif
  1871. // match_results comparisons
  1872. /**
  1873. * @brief Compares two match_results for equality.
  1874. * @returns true if the two objects refer to the same match,
  1875. * false otherwise.
  1876. * @todo Implement this function.
  1877. */
  1878. template<typename _Bi_iter, typename _Allocator>
  1879. inline bool
  1880. operator==(const match_results<_Bi_iter, _Allocator>& __m1,
  1881. const match_results<_Bi_iter, _Allocator>& __m2);
  1882. /**
  1883. * @brief Compares two match_results for inequality.
  1884. * @returns true if the two objects do not refer to the same match,
  1885. * false otherwise.
  1886. */
  1887. template<typename _Bi_iter, class _Allocator>
  1888. inline bool
  1889. operator!=(const match_results<_Bi_iter, _Allocator>& __m1,
  1890. const match_results<_Bi_iter, _Allocator>& __m2)
  1891. { return !(__m1 == __m2); }
  1892. // [7.10.6] match_results swap
  1893. /**
  1894. * @brief Swaps two match results.
  1895. * @param lhs A match result.
  1896. * @param rhs A match result.
  1897. *
  1898. * The contents of the two match_results objects are swapped.
  1899. */
  1900. template<typename _Bi_iter, typename _Allocator>
  1901. inline void
  1902. swap(match_results<_Bi_iter, _Allocator>& __lhs,
  1903. match_results<_Bi_iter, _Allocator>& __rhs)
  1904. { __lhs.swap(__rhs); }
  1905. // [7.11.2] Function template regex_match
  1906. /**
  1907. * @name Matching, Searching, and Replacing
  1908. */
  1909. //@{
  1910. /**
  1911. * @brief Determines if there is a match between the regular expression @p e
  1912. * and all of the character sequence [first, last).
  1913. *
  1914. * @param first Beginning of the character sequence to match.
  1915. * @param last One-past-the-end of the character sequence to match.
  1916. * @param m The match results.
  1917. * @param re The regular expression.
  1918. * @param flags Controls how the regular expression is matched.
  1919. *
  1920. * @retval true A match exists.
  1921. * @retval false Otherwise.
  1922. *
  1923. * @throws an exception of type regex_error.
  1924. *
  1925. * @todo Implement this function.
  1926. */
  1927. template<typename _Bi_iter, typename _Allocator,
  1928. typename _Ch_type, typename _Rx_traits>
  1929. bool
  1930. regex_match(_Bi_iter __first, _Bi_iter __last,
  1931. match_results<_Bi_iter, _Allocator>& __m,
  1932. const basic_regex<_Ch_type, _Rx_traits>& __re,
  1933. regex_constants::match_flag_type __flags
  1934. = regex_constants::match_default);
  1935. /**
  1936. * @brief Indicates if there is a match between the regular expression @p e
  1937. * and all of the character sequence [first, last).
  1938. *
  1939. * @param first Beginning of the character sequence to match.
  1940. * @param last One-past-the-end of the character sequence to match.
  1941. * @param re The regular expression.
  1942. * @param flags Controls how the regular expression is matched.
  1943. *
  1944. * @retval true A match exists.
  1945. * @retval false Otherwise.
  1946. *
  1947. * @throws an exception of type regex_error.
  1948. */
  1949. template<typename _Bi_iter, typename _Ch_type, typename _Rx_traits>
  1950. bool
  1951. regex_match(_Bi_iter __first, _Bi_iter __last,
  1952. const basic_regex<_Ch_type, _Rx_traits>& __re,
  1953. regex_constants::match_flag_type __flags
  1954. = regex_constants::match_default)
  1955. {
  1956. match_results<_Bi_iter> __what;
  1957. return regex_match(__first, __last, __what, __re, __flags);
  1958. }
  1959. /**
  1960. * @brief Determines if there is a match between the regular expression @p e
  1961. * and a C-style null-terminated string.
  1962. *
  1963. * @param s The C-style null-terminated string to match.
  1964. * @param m The match results.
  1965. * @param re The regular expression.
  1966. * @param f Controls how the regular expression is matched.
  1967. *
  1968. * @retval true A match exists.
  1969. * @retval false Otherwise.
  1970. *
  1971. * @throws an exception of type regex_error.
  1972. */
  1973. template<typename _Ch_type, typename _Allocator, typename _Rx_traits>
  1974. inline bool
  1975. regex_match(const _Ch_type* __s,
  1976. match_results<const _Ch_type*, _Allocator>& __m,
  1977. const basic_regex<_Ch_type, _Rx_traits>& __re,
  1978. regex_constants::match_flag_type __f
  1979. = regex_constants::match_default)
  1980. { return regex_match(__s, __s + _Rx_traits::length(__s), __m, __re, __f); }
  1981. /**
  1982. * @brief Determines if there is a match between the regular expression @p e
  1983. * and a string.
  1984. *
  1985. * @param s The string to match.
  1986. * @param m The match results.
  1987. * @param re The regular expression.
  1988. * @param flags Controls how the regular expression is matched.
  1989. *
  1990. * @retval true A match exists.
  1991. * @retval false Otherwise.
  1992. *
  1993. * @throws an exception of type regex_error.
  1994. */
  1995. template<typename _Ch_traits, typename _Ch_alloc,
  1996. typename _Allocator, typename _Ch_type, typename _Rx_traits>
  1997. inline bool
  1998. regex_match(const basic_string<_Ch_type, _Ch_traits, _Ch_alloc>& __s,
  1999. match_results<typename basic_string<_Ch_type,
  2000. _Ch_traits, _Ch_alloc>::const_iterator, _Allocator>& __m,
  2001. const basic_regex<_Ch_type, _Rx_traits>& __re,
  2002. regex_constants::match_flag_type __flags
  2003. = regex_constants::match_default)
  2004. { return regex_match(__s.begin(), __s.end(), __m, __re, __flags); }
  2005. /**
  2006. * @brief Indicates if there is a match between the regular expression @p e
  2007. * and a C-style null-terminated string.
  2008. *
  2009. * @param s The C-style null-terminated string to match.
  2010. * @param re The regular expression.
  2011. * @param f 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_type, class _Rx_traits>
  2019. inline bool
  2020. regex_match(const _Ch_type* __s,
  2021. const basic_regex<_Ch_type, _Rx_traits>& __re,
  2022. regex_constants::match_flag_type __f
  2023. = regex_constants::match_default)
  2024. { return regex_match(__s, __s + _Rx_traits::length(__s), __re, __f); }
  2025. /**
  2026. * @brief Indicates if there is a match between the regular expression @p e
  2027. * and a string.
  2028. *
  2029. * @param s [IN] The string to match.
  2030. * @param re [IN] The regular expression.
  2031. * @param flags [IN] Controls how the regular expression is matched.
  2032. *
  2033. * @retval true A match exists.
  2034. * @retval false Otherwise.
  2035. *
  2036. * @throws an exception of type regex_error.
  2037. */
  2038. template<typename _Ch_traits, typename _Str_allocator,
  2039. typename _Ch_type, typename _Rx_traits>
  2040. inline bool
  2041. regex_match(const basic_string<_Ch_type, _Ch_traits, _Str_allocator>& __s,
  2042. const basic_regex<_Ch_type, _Rx_traits>& __re,
  2043. regex_constants::match_flag_type __flags
  2044. = regex_constants::match_default)
  2045. { return regex_match(__s.begin(), __s.end(), __re, __flags); }
  2046. // [7.11.3] Function template regex_search
  2047. /**
  2048. * Searches for a regular expression within a range.
  2049. * @param first [IN] The start of the string to search.
  2050. * @param last [IN] One-past-the-end of the string to search.
  2051. * @param m [OUT] The match results.
  2052. * @param re [IN] The regular expression to search for.
  2053. * @param flags [IN] Search policy flags.
  2054. * @retval true A match was found within the string.
  2055. * @retval false No match was found within the string, the content of %m is
  2056. * undefined.
  2057. *
  2058. * @throws an exception of type regex_error.
  2059. *
  2060. * @todo Implement this function.
  2061. */
  2062. template<typename _Bi_iter, typename _Allocator,
  2063. typename _Ch_type, typename _Rx_traits>
  2064. inline bool
  2065. regex_search(_Bi_iter __first, _Bi_iter __last,
  2066. match_results<_Bi_iter, _Allocator>& __m,
  2067. const basic_regex<_Ch_type, _Rx_traits>& __re,
  2068. regex_constants::match_flag_type __flags
  2069. = regex_constants::match_default);
  2070. /**
  2071. * Searches for a regular expression within a range.
  2072. * @param first [IN] The start of the string to search.
  2073. * @param last [IN] One-past-the-end of the string to search.
  2074. * @param re [IN] The regular expression to search for.
  2075. * @param flags [IN] Search policy flags.
  2076. * @retval true A match was found within the string.
  2077. * @retval false No match was found within the string.
  2078. * @doctodo
  2079. *
  2080. * @throws an exception of type regex_error.
  2081. */
  2082. template<typename _Bi_iter, typename _Ch_type, typename _Rx_traits>
  2083. inline bool
  2084. regex_search(_Bi_iter __first, _Bi_iter __last,
  2085. const basic_regex<_Ch_type, _Rx_traits>& __re,
  2086. regex_constants::match_flag_type __flags
  2087. = regex_constants::match_default)
  2088. {
  2089. match_results<_Bi_iter> __what;
  2090. return regex_search(__first, __last, __what, __re, __flags);
  2091. }
  2092. /**
  2093. * @brief Searches for a regular expression within a C-string.
  2094. * @param s [IN] A C-string to search for the regex.
  2095. * @param m [OUT] The set of regex matches.
  2096. * @param e [IN] The regex to search for in @p s.
  2097. * @param f [IN] The search flags.
  2098. * @retval true A match was found within the string.
  2099. * @retval false No match was found within the string, the content of %m is
  2100. * undefined.
  2101. * @doctodo
  2102. *
  2103. * @throws an exception of type regex_error.
  2104. */
  2105. template<typename _Ch_type, class _Allocator, class _Rx_traits>
  2106. inline bool
  2107. regex_search(const _Ch_type* __s,
  2108. match_results<const _Ch_type*, _Allocator>& __m,
  2109. const basic_regex<_Ch_type, _Rx_traits>& __e,
  2110. regex_constants::match_flag_type __f
  2111. = regex_constants::match_default)
  2112. { return regex_search(__s, __s + _Rx_traits::length(__s), __m, __e, __f); }
  2113. /**
  2114. * @brief Searches for a regular expression within a C-string.
  2115. * @param s [IN] The C-string to search.
  2116. * @param e [IN] The regular expression to search for.
  2117. * @param f [IN] Search policy flags.
  2118. * @retval true A match was found within the string.
  2119. * @retval false No match was found within the string.
  2120. * @doctodo
  2121. *
  2122. * @throws an exception of type regex_error.
  2123. */
  2124. template<typename _Ch_type, typename _Rx_traits>
  2125. inline bool
  2126. regex_search(const _Ch_type* __s,
  2127. const basic_regex<_Ch_type, _Rx_traits>& __e,
  2128. regex_constants::match_flag_type __f
  2129. = regex_constants::match_default)
  2130. { return regex_search(__s, __s + _Rx_traits::length(__s), __e, __f); }
  2131. /**
  2132. * @brief Searches for a regular expression within a string.
  2133. * @param s [IN] The string to search.
  2134. * @param e [IN] The regular expression to search for.
  2135. * @param flags [IN] Search policy flags.
  2136. * @retval true A match was found within the string.
  2137. * @retval false No match was found within the string.
  2138. * @doctodo
  2139. *
  2140. * @throws an exception of type regex_error.
  2141. */
  2142. template<typename _Ch_traits, typename _String_allocator,
  2143. typename _Ch_type, typename _Rx_traits>
  2144. inline bool
  2145. regex_search(const basic_string<_Ch_type, _Ch_traits,
  2146. _String_allocator>& __s,
  2147. const basic_regex<_Ch_type, _Rx_traits>& __e,
  2148. regex_constants::match_flag_type __flags
  2149. = regex_constants::match_default)
  2150. { return regex_search(__s.begin(), __s.end(), __e, __flags); }
  2151. /**
  2152. * @brief Searches for a regular expression within a string.
  2153. * @param s [IN] A C++ string to search for the regex.
  2154. * @param m [OUT] The set of regex matches.
  2155. * @param e [IN] The regex to search for in @p s.
  2156. * @param f [IN] The search flags.
  2157. * @retval true A match was found within the string.
  2158. * @retval false No match was found within the string, the content of %m is
  2159. * undefined.
  2160. *
  2161. * @throws an exception of type regex_error.
  2162. */
  2163. template<typename _Ch_traits, typename _Ch_alloc,
  2164. typename _Allocator, typename _Ch_type,
  2165. typename _Rx_traits>
  2166. inline bool
  2167. regex_search(const basic_string<_Ch_type, _Ch_traits, _Ch_alloc>& __s,
  2168. match_results<typename basic_string<_Ch_type,
  2169. _Ch_traits, _Ch_alloc>::const_iterator, _Allocator>& __m,
  2170. const basic_regex<_Ch_type, _Rx_traits>& __e,
  2171. regex_constants::match_flag_type __f
  2172. = regex_constants::match_default)
  2173. { return regex_search(__s.begin(), __s.end(), __m, __e, __f); }
  2174. // tr1 [7.11.4] std [28.11.4] Function template regex_replace
  2175. /**
  2176. * @doctodo
  2177. * @param out
  2178. * @param first
  2179. * @param last
  2180. * @param e
  2181. * @param fmt
  2182. * @param flags
  2183. *
  2184. * @returns out
  2185. * @throws an exception of type regex_error.
  2186. *
  2187. * @todo Implement this function.
  2188. */
  2189. template<typename _Out_iter, typename _Bi_iter,
  2190. typename _Rx_traits, typename _Ch_type>
  2191. inline _Out_iter
  2192. regex_replace(_Out_iter __out, _Bi_iter __first, _Bi_iter __last,
  2193. const basic_regex<_Ch_type, _Rx_traits>& __e,
  2194. const basic_string<_Ch_type>& __fmt,
  2195. regex_constants::match_flag_type __flags
  2196. = regex_constants::match_default);
  2197. /**
  2198. * @doctodo
  2199. * @param s
  2200. * @param e
  2201. * @param fmt
  2202. * @param flags
  2203. *
  2204. * @returns a copy of string @p s with replacements.
  2205. *
  2206. * @throws an exception of type regex_error.
  2207. */
  2208. template<typename _Rx_traits, typename _Ch_type>
  2209. inline basic_string<_Ch_type>
  2210. regex_replace(const basic_string<_Ch_type>& __s,
  2211. const basic_regex<_Ch_type, _Rx_traits>& __e,
  2212. const basic_string<_Ch_type>& __fmt,
  2213. regex_constants::match_flag_type __flags
  2214. = regex_constants::match_default)
  2215. {
  2216. std::string __result;
  2217. regex_replace(std::back_inserter(__result),
  2218. __s.begin(), __s.end(), __e, __fmt, __flags);
  2219. return __result;
  2220. }
  2221. //@}
  2222. // tr1 [7.12.1] std [28.12] Class template regex_iterator
  2223. /**
  2224. * An iterator adaptor that will provide repeated calls of regex_search over
  2225. * a range until no more matches remain.
  2226. */
  2227. template<typename _Bi_iter,
  2228. typename _Ch_type = typename iterator_traits<_Bi_iter>::value_type,
  2229. typename _Rx_traits = regex_traits<_Ch_type> >
  2230. class regex_iterator
  2231. {
  2232. public:
  2233. typedef basic_regex<_Ch_type, _Rx_traits> regex_type;
  2234. typedef match_results<_Bi_iter> value_type;
  2235. typedef std::ptrdiff_t difference_type;
  2236. typedef const value_type* pointer;
  2237. typedef const value_type& reference;
  2238. typedef std::forward_iterator_tag iterator_category;
  2239. public:
  2240. /**
  2241. * @brief Provides a singular iterator, useful for indicating
  2242. * one-past-the-end of a range.
  2243. * @todo Implement this function.
  2244. * @doctodo
  2245. */
  2246. regex_iterator();
  2247. /**
  2248. * Constructs a %regex_iterator...
  2249. * @param a [IN] The start of a text range to search.
  2250. * @param b [IN] One-past-the-end of the text range to search.
  2251. * @param re [IN] The regular expression to match.
  2252. * @param m [IN] Policy flags for match rules.
  2253. * @todo Implement this function.
  2254. * @doctodo
  2255. */
  2256. regex_iterator(_Bi_iter __a, _Bi_iter __b, const regex_type& __re,
  2257. regex_constants::match_flag_type __m
  2258. = regex_constants::match_default);
  2259. /**
  2260. * Copy constructs a %regex_iterator.
  2261. * @todo Implement this function.
  2262. * @doctodo
  2263. */
  2264. regex_iterator(const regex_iterator& __rhs);
  2265. /**
  2266. * @todo Implement this function.
  2267. * @doctodo
  2268. */
  2269. regex_iterator&
  2270. operator=(const regex_iterator& __rhs);
  2271. /**
  2272. * @todo Implement this function.
  2273. * @doctodo
  2274. */
  2275. bool
  2276. operator==(const regex_iterator& __rhs);
  2277. /**
  2278. * @todo Implement this function.
  2279. * @doctodo
  2280. */
  2281. bool
  2282. operator!=(const regex_iterator& __rhs);
  2283. /**
  2284. * @todo Implement this function.
  2285. * @doctodo
  2286. */
  2287. const value_type&
  2288. operator*();
  2289. /**
  2290. * @todo Implement this function.
  2291. * @doctodo
  2292. */
  2293. const value_type*
  2294. operator->();
  2295. /**
  2296. * @todo Implement this function.
  2297. * @doctodo
  2298. */
  2299. regex_iterator&
  2300. operator++();
  2301. /**
  2302. * @todo Implement this function.
  2303. * @doctodo
  2304. */
  2305. regex_iterator
  2306. operator++(int);
  2307. private:
  2308. // these members are shown for exposition only:
  2309. _Bi_iter begin;
  2310. _Bi_iter end;
  2311. const regex_type* pregex;
  2312. regex_constants::match_flag_type flags;
  2313. match_results<_Bi_iter> match;
  2314. };
  2315. typedef regex_iterator<const char*> cregex_iterator;
  2316. typedef regex_iterator<string::const_iterator> sregex_iterator;
  2317. #ifdef _GLIBCXX_USE_WCHAR_T
  2318. typedef regex_iterator<const wchar_t*> wcregex_iterator;
  2319. typedef regex_iterator<wstring::const_iterator> wsregex_iterator;
  2320. #endif
  2321. // [7.12.2] Class template regex_token_iterator
  2322. /**
  2323. * Iterates over submatches in a range (or @a splits a text string).
  2324. *
  2325. * The purpose of this iterator is to enumerate all, or all specified,
  2326. * matches of a regular expression within a text range. The dereferenced
  2327. * value of an iterator of this class is a std::tr1::sub_match object.
  2328. */
  2329. template<typename _Bi_iter,
  2330. typename _Ch_type = typename iterator_traits<_Bi_iter>::value_type,
  2331. typename _Rx_traits = regex_traits<_Ch_type> >
  2332. class regex_token_iterator
  2333. {
  2334. public:
  2335. typedef basic_regex<_Ch_type, _Rx_traits> regex_type;
  2336. typedef sub_match<_Bi_iter> value_type;
  2337. typedef std::ptrdiff_t difference_type;
  2338. typedef const value_type* pointer;
  2339. typedef const value_type& reference;
  2340. typedef std::forward_iterator_tag iterator_category;
  2341. public:
  2342. /**
  2343. * @brief Default constructs a %regex_token_iterator.
  2344. * @todo Implement this function.
  2345. *
  2346. * A default-constructed %regex_token_iterator is a singular iterator
  2347. * that will compare equal to the one-past-the-end value for any
  2348. * iterator of the same type.
  2349. */
  2350. regex_token_iterator();
  2351. /**
  2352. * Constructs a %regex_token_iterator...
  2353. * @param a [IN] The start of the text to search.
  2354. * @param b [IN] One-past-the-end of the text to search.
  2355. * @param re [IN] The regular expression to search for.
  2356. * @param submatch [IN] Which submatch to return. There are some
  2357. * special values for this parameter:
  2358. * - -1 each enumerated subexpression does NOT
  2359. * match the regular expression (aka field
  2360. * splitting)
  2361. * - 0 the entire string matching the
  2362. * subexpression is returned for each match
  2363. * within the text.
  2364. * - >0 enumerates only the indicated
  2365. * subexpression from a match within the text.
  2366. * @param m [IN] Policy flags for match rules.
  2367. *
  2368. * @todo Implement this function.
  2369. * @doctodo
  2370. */
  2371. regex_token_iterator(_Bi_iter __a, _Bi_iter __b, const regex_type& __re,
  2372. int __submatch = 0,
  2373. regex_constants::match_flag_type __m
  2374. = regex_constants::match_default);
  2375. /**
  2376. * Constructs a %regex_token_iterator...
  2377. * @param a [IN] The start of the text to search.
  2378. * @param b [IN] One-past-the-end of the text to search.
  2379. * @param re [IN] The regular expression to search for.
  2380. * @param submatches [IN] A list of subexpressions to return for each
  2381. * regular expression match within the text.
  2382. * @param m [IN] Policy flags for match rules.
  2383. *
  2384. * @todo Implement this function.
  2385. * @doctodo
  2386. */
  2387. regex_token_iterator(_Bi_iter __a, _Bi_iter __b,
  2388. const regex_type& __re,
  2389. const std::vector<int>& __submatches,
  2390. regex_constants::match_flag_type __m
  2391. = regex_constants::match_default);
  2392. /**
  2393. * Constructs a %regex_token_iterator...
  2394. * @param a [IN] The start of the text to search.
  2395. * @param b [IN] One-past-the-end of the text to search.
  2396. * @param re [IN] The regular expression to search for.
  2397. * @param submatches [IN] A list of subexpressions to return for each
  2398. * regular expression match within the text.
  2399. * @param m [IN] Policy flags for match rules.
  2400. * @todo Implement this function.
  2401. * @doctodo
  2402. */
  2403. template<std::size_t _Nm>
  2404. regex_token_iterator(_Bi_iter __a, _Bi_iter __b,
  2405. const regex_type& __re,
  2406. const int (&__submatches)[_Nm],
  2407. regex_constants::match_flag_type __m
  2408. = regex_constants::match_default);
  2409. /**
  2410. * @brief Copy constructs a %regex_token_iterator.
  2411. * @param rhs [IN] A %regex_token_iterator to copy.
  2412. * @todo Implement this function.
  2413. */
  2414. regex_token_iterator(const regex_token_iterator& __rhs);
  2415. /**
  2416. * @brief Assigns a %regex_token_iterator to another.
  2417. * @param rhs [IN] A %regex_token_iterator to copy.
  2418. * @todo Implement this function.
  2419. */
  2420. regex_token_iterator&
  2421. operator=(const regex_token_iterator& __rhs);
  2422. /**
  2423. * @brief Compares a %regex_token_iterator to another for equality.
  2424. * @todo Implement this function.
  2425. */
  2426. bool
  2427. operator==(const regex_token_iterator& __rhs);
  2428. /**
  2429. * @brief Compares a %regex_token_iterator to another for inequality.
  2430. * @todo Implement this function.
  2431. */
  2432. bool
  2433. operator!=(const regex_token_iterator& __rhs);
  2434. /**
  2435. * @brief Dereferences a %regex_token_iterator.
  2436. * @todo Implement this function.
  2437. */
  2438. const value_type&
  2439. operator*();
  2440. /**
  2441. * @brief Selects a %regex_token_iterator member.
  2442. * @todo Implement this function.
  2443. */
  2444. const value_type*
  2445. operator->();
  2446. /**
  2447. * @brief Increments a %regex_token_iterator.
  2448. * @todo Implement this function.
  2449. */
  2450. regex_token_iterator&
  2451. operator++();
  2452. /**
  2453. * @brief Postincrements a %regex_token_iterator.
  2454. * @todo Implement this function.
  2455. */
  2456. regex_token_iterator
  2457. operator++(int);
  2458. private: // data members for exposition only:
  2459. typedef regex_iterator<_Bi_iter, _Ch_type, _Rx_traits> position_iterator;
  2460. position_iterator __position;
  2461. const value_type* __result;
  2462. value_type __suffix;
  2463. std::size_t __n;
  2464. std::vector<int> __subs;
  2465. };
  2466. /** @brief Token iterator for C-style NULL-terminated strings. */
  2467. typedef regex_token_iterator<const char*> cregex_token_iterator;
  2468. /** @brief Token iterator for standard strings. */
  2469. typedef regex_token_iterator<string::const_iterator> sregex_token_iterator;
  2470. #ifdef _GLIBCXX_USE_WCHAR_T
  2471. /** @brief Token iterator for C-style NULL-terminated wide strings. */
  2472. typedef regex_token_iterator<const wchar_t*> wcregex_token_iterator;
  2473. /** @brief Token iterator for standard wide-character strings. */
  2474. typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator;
  2475. #endif
  2476. //@}
  2477. _GLIBCXX_END_NAMESPACE_VERSION
  2478. }
  2479. }
  2480. #endif // _GLIBCXX_TR1_REGEX