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