You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2728 lines
91KB

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