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