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