libstdc++
|
00001 // class template regex -*- C++ -*- 00002 00003 // Copyright (C) 2010-2018 Free Software Foundation, Inc. 00004 // 00005 // This file is part of the GNU ISO C++ Library. This library is free 00006 // software; you can redistribute it and/or modify it under the 00007 // terms of the GNU General Public License as published by the 00008 // Free Software Foundation; either version 3, or (at your option) 00009 // any later version. 00010 00011 // This library is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 // GNU General Public License for more details. 00015 00016 // Under Section 7 of GPL version 3, you are granted additional 00017 // permissions described in the GCC Runtime Library Exception, version 00018 // 3.1, as published by the Free Software Foundation. 00019 00020 // You should have received a copy of the GNU General Public License and 00021 // a copy of the GCC Runtime Library Exception along with this program; 00022 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 00023 // <http://www.gnu.org/licenses/>. 00024 00025 /** 00026 * @file bits/regex.h 00027 * This is an internal header file, included by other library headers. 00028 * Do not attempt to use it directly. @headername{regex} 00029 */ 00030 00031 namespace std _GLIBCXX_VISIBILITY(default) 00032 { 00033 _GLIBCXX_BEGIN_NAMESPACE_VERSION 00034 _GLIBCXX_BEGIN_NAMESPACE_CXX11 00035 template<typename, typename> 00036 class basic_regex; 00037 00038 template<typename, typename> 00039 class match_results; 00040 00041 _GLIBCXX_END_NAMESPACE_CXX11 00042 00043 namespace __detail 00044 { 00045 enum class _RegexExecutorPolicy : int 00046 { _S_auto, _S_alternate }; 00047 00048 template<typename _BiIter, typename _Alloc, 00049 typename _CharT, typename _TraitsT, 00050 _RegexExecutorPolicy __policy, 00051 bool __match_mode> 00052 bool 00053 __regex_algo_impl(_BiIter __s, 00054 _BiIter __e, 00055 match_results<_BiIter, _Alloc>& __m, 00056 const basic_regex<_CharT, _TraitsT>& __re, 00057 regex_constants::match_flag_type __flags); 00058 00059 template<typename, typename, typename, bool> 00060 class _Executor; 00061 } 00062 00063 _GLIBCXX_BEGIN_NAMESPACE_CXX11 00064 00065 /** 00066 * @addtogroup regex 00067 * @{ 00068 */ 00069 00070 /** 00071 * @brief Describes aspects of a regular expression. 00072 * 00073 * A regular expression traits class that satisfies the requirements of 00074 * section [28.7]. 00075 * 00076 * The class %regex is parameterized around a set of related types and 00077 * functions used to complete the definition of its semantics. This class 00078 * satisfies the requirements of such a traits class. 00079 */ 00080 template<typename _Ch_type> 00081 struct regex_traits 00082 { 00083 public: 00084 typedef _Ch_type char_type; 00085 typedef std::basic_string<char_type> string_type; 00086 typedef std::locale locale_type; 00087 private: 00088 struct _RegexMask 00089 { 00090 typedef std::ctype_base::mask _BaseType; 00091 _BaseType _M_base; 00092 unsigned char _M_extended; 00093 static constexpr unsigned char _S_under = 1 << 0; 00094 static constexpr unsigned char _S_valid_mask = 0x1; 00095 00096 constexpr _RegexMask(_BaseType __base = 0, 00097 unsigned char __extended = 0) 00098 : _M_base(__base), _M_extended(__extended) 00099 { } 00100 00101 constexpr _RegexMask 00102 operator&(_RegexMask __other) const 00103 { 00104 return _RegexMask(_M_base & __other._M_base, 00105 _M_extended & __other._M_extended); 00106 } 00107 00108 constexpr _RegexMask 00109 operator|(_RegexMask __other) const 00110 { 00111 return _RegexMask(_M_base | __other._M_base, 00112 _M_extended | __other._M_extended); 00113 } 00114 00115 constexpr _RegexMask 00116 operator^(_RegexMask __other) const 00117 { 00118 return _RegexMask(_M_base ^ __other._M_base, 00119 _M_extended ^ __other._M_extended); 00120 } 00121 00122 constexpr _RegexMask 00123 operator~() const 00124 { return _RegexMask(~_M_base, ~_M_extended); } 00125 00126 _RegexMask& 00127 operator&=(_RegexMask __other) 00128 { return *this = (*this) & __other; } 00129 00130 _RegexMask& 00131 operator|=(_RegexMask __other) 00132 { return *this = (*this) | __other; } 00133 00134 _RegexMask& 00135 operator^=(_RegexMask __other) 00136 { return *this = (*this) ^ __other; } 00137 00138 constexpr bool 00139 operator==(_RegexMask __other) const 00140 { 00141 return (_M_extended & _S_valid_mask) 00142 == (__other._M_extended & _S_valid_mask) 00143 && _M_base == __other._M_base; 00144 } 00145 00146 constexpr bool 00147 operator!=(_RegexMask __other) const 00148 { return !((*this) == __other); } 00149 00150 }; 00151 public: 00152 typedef _RegexMask char_class_type; 00153 00154 public: 00155 /** 00156 * @brief Constructs a default traits object. 00157 */ 00158 regex_traits() { } 00159 00160 /** 00161 * @brief Gives the length of a C-style string starting at @p __p. 00162 * 00163 * @param __p a pointer to the start of a character sequence. 00164 * 00165 * @returns the number of characters between @p *__p and the first 00166 * default-initialized value of type @p char_type. In other words, uses 00167 * the C-string algorithm for determining the length of a sequence of 00168 * characters. 00169 */ 00170 static std::size_t 00171 length(const char_type* __p) 00172 { return string_type::traits_type::length(__p); } 00173 00174 /** 00175 * @brief Performs the identity translation. 00176 * 00177 * @param __c A character to the locale-specific character set. 00178 * 00179 * @returns __c. 00180 */ 00181 char_type 00182 translate(char_type __c) const 00183 { return __c; } 00184 00185 /** 00186 * @brief Translates a character into a case-insensitive equivalent. 00187 * 00188 * @param __c A character to the locale-specific character set. 00189 * 00190 * @returns the locale-specific lower-case equivalent of __c. 00191 * @throws std::bad_cast if the imbued locale does not support the ctype 00192 * facet. 00193 */ 00194 char_type 00195 translate_nocase(char_type __c) const 00196 { 00197 typedef std::ctype<char_type> __ctype_type; 00198 const __ctype_type& __fctyp(use_facet<__ctype_type>(_M_locale)); 00199 return __fctyp.tolower(__c); 00200 } 00201 00202 /** 00203 * @brief Gets a sort key for a character sequence. 00204 * 00205 * @param __first beginning of the character sequence. 00206 * @param __last one-past-the-end of the character sequence. 00207 * 00208 * Returns a sort key for the character sequence designated by the 00209 * iterator range [F1, F2) such that if the character sequence [G1, G2) 00210 * sorts before the character sequence [H1, H2) then 00211 * v.transform(G1, G2) < v.transform(H1, H2). 00212 * 00213 * What this really does is provide a more efficient way to compare a 00214 * string to multiple other strings in locales with fancy collation 00215 * rules and equivalence classes. 00216 * 00217 * @returns a locale-specific sort key equivalent to the input range. 00218 * 00219 * @throws std::bad_cast if the current locale does not have a collate 00220 * facet. 00221 */ 00222 template<typename _Fwd_iter> 00223 string_type 00224 transform(_Fwd_iter __first, _Fwd_iter __last) const 00225 { 00226 typedef std::collate<char_type> __collate_type; 00227 const __collate_type& __fclt(use_facet<__collate_type>(_M_locale)); 00228 string_type __s(__first, __last); 00229 return __fclt.transform(__s.data(), __s.data() + __s.size()); 00230 } 00231 00232 /** 00233 * @brief Gets a sort key for a character sequence, independent of case. 00234 * 00235 * @param __first beginning of the character sequence. 00236 * @param __last one-past-the-end of the character sequence. 00237 * 00238 * Effects: if typeid(use_facet<collate<_Ch_type> >) == 00239 * typeid(collate_byname<_Ch_type>) and the form of the sort key 00240 * returned by collate_byname<_Ch_type>::transform(__first, __last) 00241 * is known and can be converted into a primary sort key 00242 * then returns that key, otherwise returns an empty string. 00243 * 00244 * @todo Implement this function correctly. 00245 */ 00246 template<typename _Fwd_iter> 00247 string_type 00248 transform_primary(_Fwd_iter __first, _Fwd_iter __last) const 00249 { 00250 // TODO : this is not entirely correct. 00251 // This function requires extra support from the platform. 00252 // 00253 // Read http://gcc.gnu.org/ml/libstdc++/2013-09/msg00117.html and 00254 // http://www.open-std.org/Jtc1/sc22/wg21/docs/papers/2003/n1429.htm 00255 // for details. 00256 typedef std::ctype<char_type> __ctype_type; 00257 const __ctype_type& __fctyp(use_facet<__ctype_type>(_M_locale)); 00258 std::vector<char_type> __s(__first, __last); 00259 __fctyp.tolower(__s.data(), __s.data() + __s.size()); 00260 return this->transform(__s.data(), __s.data() + __s.size()); 00261 } 00262 00263 /** 00264 * @brief Gets a collation element by name. 00265 * 00266 * @param __first beginning of the collation element name. 00267 * @param __last one-past-the-end of the collation element name. 00268 * 00269 * @returns a sequence of one or more characters that represents the 00270 * collating element consisting of the character sequence designated by 00271 * the iterator range [__first, __last). Returns an empty string if the 00272 * character sequence is not a valid collating element. 00273 */ 00274 template<typename _Fwd_iter> 00275 string_type 00276 lookup_collatename(_Fwd_iter __first, _Fwd_iter __last) const; 00277 00278 /** 00279 * @brief Maps one or more characters to a named character 00280 * classification. 00281 * 00282 * @param __first beginning of the character sequence. 00283 * @param __last one-past-the-end of the character sequence. 00284 * @param __icase ignores the case of the classification name. 00285 * 00286 * @returns an unspecified value that represents the character 00287 * classification named by the character sequence designated by 00288 * the iterator range [__first, __last). If @p icase is true, 00289 * the returned mask identifies the classification regardless of 00290 * the case of the characters to be matched (for example, 00291 * [[:lower:]] is the same as [[:alpha:]]), otherwise a 00292 * case-dependent classification is returned. The value 00293 * returned shall be independent of the case of the characters 00294 * in the character sequence. If the name is not recognized then 00295 * returns a value that compares equal to 0. 00296 * 00297 * At least the following names (or their wide-character equivalent) are 00298 * supported. 00299 * - d 00300 * - w 00301 * - s 00302 * - alnum 00303 * - alpha 00304 * - blank 00305 * - cntrl 00306 * - digit 00307 * - graph 00308 * - lower 00309 * - print 00310 * - punct 00311 * - space 00312 * - upper 00313 * - xdigit 00314 */ 00315 template<typename _Fwd_iter> 00316 char_class_type 00317 lookup_classname(_Fwd_iter __first, _Fwd_iter __last, 00318 bool __icase = false) const; 00319 00320 /** 00321 * @brief Determines if @p c is a member of an identified class. 00322 * 00323 * @param __c a character. 00324 * @param __f a class type (as returned from lookup_classname). 00325 * 00326 * @returns true if the character @p __c is a member of the classification 00327 * represented by @p __f, false otherwise. 00328 * 00329 * @throws std::bad_cast if the current locale does not have a ctype 00330 * facet. 00331 */ 00332 bool 00333 isctype(_Ch_type __c, char_class_type __f) const; 00334 00335 /** 00336 * @brief Converts a digit to an int. 00337 * 00338 * @param __ch a character representing a digit. 00339 * @param __radix the radix if the numeric conversion (limited to 8, 10, 00340 * or 16). 00341 * 00342 * @returns the value represented by the digit __ch in base radix if the 00343 * character __ch is a valid digit in base radix; otherwise returns -1. 00344 */ 00345 int 00346 value(_Ch_type __ch, int __radix) const; 00347 00348 /** 00349 * @brief Imbues the regex_traits object with a copy of a new locale. 00350 * 00351 * @param __loc A locale. 00352 * 00353 * @returns a copy of the previous locale in use by the regex_traits 00354 * object. 00355 * 00356 * @note Calling imbue with a different locale than the one currently in 00357 * use invalidates all cached data held by *this. 00358 */ 00359 locale_type 00360 imbue(locale_type __loc) 00361 { 00362 std::swap(_M_locale, __loc); 00363 return __loc; 00364 } 00365 00366 /** 00367 * @brief Gets a copy of the current locale in use by the regex_traits 00368 * object. 00369 */ 00370 locale_type 00371 getloc() const 00372 { return _M_locale; } 00373 00374 protected: 00375 locale_type _M_locale; 00376 }; 00377 00378 // [7.8] Class basic_regex 00379 /** 00380 * Objects of specializations of this class represent regular expressions 00381 * constructed from sequences of character type @p _Ch_type. 00382 * 00383 * Storage for the regular expression is allocated and deallocated as 00384 * necessary by the member functions of this class. 00385 */ 00386 template<typename _Ch_type, typename _Rx_traits = regex_traits<_Ch_type>> 00387 class basic_regex 00388 { 00389 public: 00390 static_assert(is_same<_Ch_type, typename _Rx_traits::char_type>::value, 00391 "regex traits class must have the same char_type"); 00392 00393 // types: 00394 typedef _Ch_type value_type; 00395 typedef _Rx_traits traits_type; 00396 typedef typename traits_type::string_type string_type; 00397 typedef regex_constants::syntax_option_type flag_type; 00398 typedef typename traits_type::locale_type locale_type; 00399 00400 /** 00401 * @name Constants 00402 * std [28.8.1](1) 00403 */ 00404 //@{ 00405 static constexpr flag_type icase = regex_constants::icase; 00406 static constexpr flag_type nosubs = regex_constants::nosubs; 00407 static constexpr flag_type optimize = regex_constants::optimize; 00408 static constexpr flag_type collate = regex_constants::collate; 00409 static constexpr flag_type ECMAScript = regex_constants::ECMAScript; 00410 static constexpr flag_type basic = regex_constants::basic; 00411 static constexpr flag_type extended = regex_constants::extended; 00412 static constexpr flag_type awk = regex_constants::awk; 00413 static constexpr flag_type grep = regex_constants::grep; 00414 static constexpr flag_type egrep = regex_constants::egrep; 00415 //@} 00416 00417 // [7.8.2] construct/copy/destroy 00418 /** 00419 * Constructs a basic regular expression that does not match any 00420 * character sequence. 00421 */ 00422 basic_regex() 00423 : _M_flags(ECMAScript), _M_loc(), _M_automaton(nullptr) 00424 { } 00425 00426 /** 00427 * @brief Constructs a basic regular expression from the 00428 * sequence [__p, __p + char_traits<_Ch_type>::length(__p)) 00429 * interpreted according to the flags in @p __f. 00430 * 00431 * @param __p A pointer to the start of a C-style null-terminated string 00432 * containing a regular expression. 00433 * @param __f Flags indicating the syntax rules and options. 00434 * 00435 * @throws regex_error if @p __p is not a valid regular expression. 00436 */ 00437 explicit 00438 basic_regex(const _Ch_type* __p, flag_type __f = ECMAScript) 00439 : basic_regex(__p, __p + char_traits<_Ch_type>::length(__p), __f) 00440 { } 00441 00442 /** 00443 * @brief Constructs a basic regular expression from the sequence 00444 * [p, p + len) interpreted according to the flags in @p f. 00445 * 00446 * @param __p A pointer to the start of a string containing a regular 00447 * expression. 00448 * @param __len The length of the string containing the regular 00449 * expression. 00450 * @param __f Flags indicating the syntax rules and options. 00451 * 00452 * @throws regex_error if @p __p is not a valid regular expression. 00453 */ 00454 basic_regex(const _Ch_type* __p, std::size_t __len, 00455 flag_type __f = ECMAScript) 00456 : basic_regex(__p, __p + __len, __f) 00457 { } 00458 00459 /** 00460 * @brief Copy-constructs a basic regular expression. 00461 * 00462 * @param __rhs A @p regex object. 00463 */ 00464 basic_regex(const basic_regex& __rhs) = default; 00465 00466 /** 00467 * @brief Move-constructs a basic regular expression. 00468 * 00469 * @param __rhs A @p regex object. 00470 */ 00471 basic_regex(basic_regex&& __rhs) noexcept = default; 00472 00473 /** 00474 * @brief Constructs a basic regular expression from the string 00475 * @p s interpreted according to the flags in @p f. 00476 * 00477 * @param __s A string containing a regular expression. 00478 * @param __f Flags indicating the syntax rules and options. 00479 * 00480 * @throws regex_error if @p __s is not a valid regular expression. 00481 */ 00482 template<typename _Ch_traits, typename _Ch_alloc> 00483 explicit 00484 basic_regex(const std::basic_string<_Ch_type, _Ch_traits, 00485 _Ch_alloc>& __s, 00486 flag_type __f = ECMAScript) 00487 : basic_regex(__s.data(), __s.data() + __s.size(), __f) 00488 { } 00489 00490 /** 00491 * @brief Constructs a basic regular expression from the range 00492 * [first, last) interpreted according to the flags in @p f. 00493 * 00494 * @param __first The start of a range containing a valid regular 00495 * expression. 00496 * @param __last The end of a range containing a valid regular 00497 * expression. 00498 * @param __f The format flags of the regular expression. 00499 * 00500 * @throws regex_error if @p [__first, __last) is not a valid regular 00501 * expression. 00502 */ 00503 template<typename _FwdIter> 00504 basic_regex(_FwdIter __first, _FwdIter __last, 00505 flag_type __f = ECMAScript) 00506 : basic_regex(std::move(__first), std::move(__last), locale_type(), __f) 00507 { } 00508 00509 /** 00510 * @brief Constructs a basic regular expression from an initializer list. 00511 * 00512 * @param __l The initializer list. 00513 * @param __f The format flags of the regular expression. 00514 * 00515 * @throws regex_error if @p __l is not a valid regular expression. 00516 */ 00517 basic_regex(initializer_list<_Ch_type> __l, flag_type __f = ECMAScript) 00518 : basic_regex(__l.begin(), __l.end(), __f) 00519 { } 00520 00521 /** 00522 * @brief Destroys a basic regular expression. 00523 */ 00524 ~basic_regex() 00525 { } 00526 00527 /** 00528 * @brief Assigns one regular expression to another. 00529 */ 00530 basic_regex& 00531 operator=(const basic_regex& __rhs) 00532 { return this->assign(__rhs); } 00533 00534 /** 00535 * @brief Move-assigns one regular expression to another. 00536 */ 00537 basic_regex& 00538 operator=(basic_regex&& __rhs) noexcept 00539 { return this->assign(std::move(__rhs)); } 00540 00541 /** 00542 * @brief Replaces a regular expression with a new one constructed from 00543 * a C-style null-terminated string. 00544 * 00545 * @param __p A pointer to the start of a null-terminated C-style string 00546 * containing a regular expression. 00547 */ 00548 basic_regex& 00549 operator=(const _Ch_type* __p) 00550 { return this->assign(__p); } 00551 00552 /** 00553 * @brief Replaces a regular expression with a new one constructed from 00554 * an initializer list. 00555 * 00556 * @param __l The initializer list. 00557 * 00558 * @throws regex_error if @p __l is not a valid regular expression. 00559 */ 00560 basic_regex& 00561 operator=(initializer_list<_Ch_type> __l) 00562 { return this->assign(__l.begin(), __l.end()); } 00563 00564 /** 00565 * @brief Replaces a regular expression with a new one constructed from 00566 * a string. 00567 * 00568 * @param __s A pointer to a string containing a regular expression. 00569 */ 00570 template<typename _Ch_traits, typename _Alloc> 00571 basic_regex& 00572 operator=(const basic_string<_Ch_type, _Ch_traits, _Alloc>& __s) 00573 { return this->assign(__s); } 00574 00575 // [7.8.3] assign 00576 /** 00577 * @brief the real assignment operator. 00578 * 00579 * @param __rhs Another regular expression object. 00580 */ 00581 basic_regex& 00582 assign(const basic_regex& __rhs) 00583 { 00584 basic_regex __tmp(__rhs); 00585 this->swap(__tmp); 00586 return *this; 00587 } 00588 00589 /** 00590 * @brief The move-assignment operator. 00591 * 00592 * @param __rhs Another regular expression object. 00593 */ 00594 basic_regex& 00595 assign(basic_regex&& __rhs) noexcept 00596 { 00597 basic_regex __tmp(std::move(__rhs)); 00598 this->swap(__tmp); 00599 return *this; 00600 } 00601 00602 /** 00603 * @brief Assigns a new regular expression to a regex object from a 00604 * C-style null-terminated string containing a regular expression 00605 * pattern. 00606 * 00607 * @param __p A pointer to a C-style null-terminated string containing 00608 * a regular expression pattern. 00609 * @param __flags Syntax option flags. 00610 * 00611 * @throws regex_error if __p does not contain a valid regular 00612 * expression pattern interpreted according to @p __flags. If 00613 * regex_error is thrown, *this remains unchanged. 00614 */ 00615 basic_regex& 00616 assign(const _Ch_type* __p, flag_type __flags = ECMAScript) 00617 { return this->assign(string_type(__p), __flags); } 00618 00619 /** 00620 * @brief Assigns a new regular expression to a regex object from a 00621 * C-style string containing a regular expression pattern. 00622 * 00623 * @param __p A pointer to a C-style string containing a 00624 * regular expression pattern. 00625 * @param __len The length of the regular expression pattern string. 00626 * @param __flags Syntax option flags. 00627 * 00628 * @throws regex_error if p does not contain a valid regular 00629 * expression pattern interpreted according to @p __flags. If 00630 * regex_error is thrown, *this remains unchanged. 00631 */ 00632 basic_regex& 00633 assign(const _Ch_type* __p, std::size_t __len, flag_type __flags) 00634 { return this->assign(string_type(__p, __len), __flags); } 00635 00636 /** 00637 * @brief Assigns a new regular expression to a regex object from a 00638 * string containing a regular expression pattern. 00639 * 00640 * @param __s A string containing a regular expression pattern. 00641 * @param __flags Syntax option flags. 00642 * 00643 * @throws regex_error if __s does not contain a valid regular 00644 * expression pattern interpreted according to @p __flags. If 00645 * regex_error is thrown, *this remains unchanged. 00646 */ 00647 template<typename _Ch_traits, typename _Alloc> 00648 basic_regex& 00649 assign(const basic_string<_Ch_type, _Ch_traits, _Alloc>& __s, 00650 flag_type __flags = ECMAScript) 00651 { 00652 return this->assign(basic_regex(__s.data(), __s.data() + __s.size(), 00653 _M_loc, __flags)); 00654 } 00655 00656 /** 00657 * @brief Assigns a new regular expression to a regex object. 00658 * 00659 * @param __first The start of a range containing a valid regular 00660 * expression. 00661 * @param __last The end of a range containing a valid regular 00662 * expression. 00663 * @param __flags Syntax option flags. 00664 * 00665 * @throws regex_error if p does not contain a valid regular 00666 * expression pattern interpreted according to @p __flags. If 00667 * regex_error is thrown, the object remains unchanged. 00668 */ 00669 template<typename _InputIterator> 00670 basic_regex& 00671 assign(_InputIterator __first, _InputIterator __last, 00672 flag_type __flags = ECMAScript) 00673 { return this->assign(string_type(__first, __last), __flags); } 00674 00675 /** 00676 * @brief Assigns a new regular expression to a regex object. 00677 * 00678 * @param __l An initializer list representing a regular expression. 00679 * @param __flags Syntax option flags. 00680 * 00681 * @throws regex_error if @p __l does not contain a valid 00682 * regular expression pattern interpreted according to @p 00683 * __flags. If regex_error is thrown, the object remains 00684 * unchanged. 00685 */ 00686 basic_regex& 00687 assign(initializer_list<_Ch_type> __l, flag_type __flags = ECMAScript) 00688 { return this->assign(__l.begin(), __l.end(), __flags); } 00689 00690 // [7.8.4] const operations 00691 /** 00692 * @brief Gets the number of marked subexpressions within the regular 00693 * expression. 00694 */ 00695 unsigned int 00696 mark_count() const 00697 { 00698 if (_M_automaton) 00699 return _M_automaton->_M_sub_count() - 1; 00700 return 0; 00701 } 00702 00703 /** 00704 * @brief Gets the flags used to construct the regular expression 00705 * or in the last call to assign(). 00706 */ 00707 flag_type 00708 flags() const 00709 { return _M_flags; } 00710 00711 // [7.8.5] locale 00712 /** 00713 * @brief Imbues the regular expression object with the given locale. 00714 * 00715 * @param __loc A locale. 00716 */ 00717 locale_type 00718 imbue(locale_type __loc) 00719 { 00720 std::swap(__loc, _M_loc); 00721 _M_automaton.reset(); 00722 return __loc; 00723 } 00724 00725 /** 00726 * @brief Gets the locale currently imbued in the regular expression 00727 * object. 00728 */ 00729 locale_type 00730 getloc() const 00731 { return _M_loc; } 00732 00733 // [7.8.6] swap 00734 /** 00735 * @brief Swaps the contents of two regular expression objects. 00736 * 00737 * @param __rhs Another regular expression object. 00738 */ 00739 void 00740 swap(basic_regex& __rhs) 00741 { 00742 std::swap(_M_flags, __rhs._M_flags); 00743 std::swap(_M_loc, __rhs._M_loc); 00744 std::swap(_M_automaton, __rhs._M_automaton); 00745 } 00746 00747 #ifdef _GLIBCXX_DEBUG 00748 void 00749 _M_dot(std::ostream& __ostr) 00750 { _M_automaton->_M_dot(__ostr); } 00751 #endif 00752 00753 private: 00754 typedef std::shared_ptr<const __detail::_NFA<_Rx_traits>> _AutomatonPtr; 00755 00756 template<typename _FwdIter> 00757 basic_regex(_FwdIter __first, _FwdIter __last, locale_type __loc, 00758 flag_type __f) 00759 : _M_flags(__f), _M_loc(std::move(__loc)), 00760 _M_automaton(__detail::__compile_nfa<_Rx_traits>( 00761 std::move(__first), std::move(__last), _M_loc, _M_flags)) 00762 { } 00763 00764 template<typename _Bp, typename _Ap, typename _Cp, typename _Rp, 00765 __detail::_RegexExecutorPolicy, bool> 00766 friend bool 00767 __detail::__regex_algo_impl(_Bp, _Bp, match_results<_Bp, _Ap>&, 00768 const basic_regex<_Cp, _Rp>&, 00769 regex_constants::match_flag_type); 00770 00771 template<typename, typename, typename, bool> 00772 friend class __detail::_Executor; 00773 00774 flag_type _M_flags; 00775 locale_type _M_loc; 00776 _AutomatonPtr _M_automaton; 00777 }; 00778 00779 #if __cplusplus < 201703L 00780 template<typename _Ch, typename _Tr> 00781 constexpr regex_constants::syntax_option_type 00782 basic_regex<_Ch, _Tr>::icase; 00783 00784 template<typename _Ch, typename _Tr> 00785 constexpr regex_constants::syntax_option_type 00786 basic_regex<_Ch, _Tr>::nosubs; 00787 00788 template<typename _Ch, typename _Tr> 00789 constexpr regex_constants::syntax_option_type 00790 basic_regex<_Ch, _Tr>::optimize; 00791 00792 template<typename _Ch, typename _Tr> 00793 constexpr regex_constants::syntax_option_type 00794 basic_regex<_Ch, _Tr>::collate; 00795 00796 template<typename _Ch, typename _Tr> 00797 constexpr regex_constants::syntax_option_type 00798 basic_regex<_Ch, _Tr>::ECMAScript; 00799 00800 template<typename _Ch, typename _Tr> 00801 constexpr regex_constants::syntax_option_type 00802 basic_regex<_Ch, _Tr>::basic; 00803 00804 template<typename _Ch, typename _Tr> 00805 constexpr regex_constants::syntax_option_type 00806 basic_regex<_Ch, _Tr>::extended; 00807 00808 template<typename _Ch, typename _Tr> 00809 constexpr regex_constants::syntax_option_type 00810 basic_regex<_Ch, _Tr>::awk; 00811 00812 template<typename _Ch, typename _Tr> 00813 constexpr regex_constants::syntax_option_type 00814 basic_regex<_Ch, _Tr>::grep; 00815 00816 template<typename _Ch, typename _Tr> 00817 constexpr regex_constants::syntax_option_type 00818 basic_regex<_Ch, _Tr>::egrep; 00819 #endif // ! C++17 00820 00821 #if __cpp_deduction_guides >= 201606 00822 template<typename _ForwardIterator> 00823 basic_regex(_ForwardIterator, _ForwardIterator, 00824 regex_constants::syntax_option_type = {}) 00825 -> basic_regex<typename iterator_traits<_ForwardIterator>::value_type>; 00826 #endif 00827 00828 /** @brief Standard regular expressions. */ 00829 typedef basic_regex<char> regex; 00830 00831 #ifdef _GLIBCXX_USE_WCHAR_T 00832 /** @brief Standard wide-character regular expressions. */ 00833 typedef basic_regex<wchar_t> wregex; 00834 #endif 00835 00836 00837 // [7.8.6] basic_regex swap 00838 /** 00839 * @brief Swaps the contents of two regular expression objects. 00840 * @param __lhs First regular expression. 00841 * @param __rhs Second regular expression. 00842 */ 00843 template<typename _Ch_type, typename _Rx_traits> 00844 inline void 00845 swap(basic_regex<_Ch_type, _Rx_traits>& __lhs, 00846 basic_regex<_Ch_type, _Rx_traits>& __rhs) 00847 { __lhs.swap(__rhs); } 00848 00849 00850 // [7.9] Class template sub_match 00851 /** 00852 * A sequence of characters matched by a particular marked sub-expression. 00853 * 00854 * An object of this class is essentially a pair of iterators marking a 00855 * matched subexpression within a regular expression pattern match. Such 00856 * objects can be converted to and compared with std::basic_string objects 00857 * of a similar base character type as the pattern matched by the regular 00858 * expression. 00859 * 00860 * The iterators that make up the pair are the usual half-open interval 00861 * referencing the actual original pattern matched. 00862 */ 00863 template<typename _BiIter> 00864 class sub_match : public std::pair<_BiIter, _BiIter> 00865 { 00866 typedef iterator_traits<_BiIter> __iter_traits; 00867 00868 public: 00869 typedef typename __iter_traits::value_type value_type; 00870 typedef typename __iter_traits::difference_type difference_type; 00871 typedef _BiIter iterator; 00872 typedef std::basic_string<value_type> string_type; 00873 00874 bool matched; 00875 00876 constexpr sub_match() : matched() { } 00877 00878 /** 00879 * Gets the length of the matching sequence. 00880 */ 00881 difference_type 00882 length() const 00883 { return this->matched ? std::distance(this->first, this->second) : 0; } 00884 00885 /** 00886 * @brief Gets the matching sequence as a string. 00887 * 00888 * @returns the matching sequence as a string. 00889 * 00890 * This is the implicit conversion operator. It is identical to the 00891 * str() member function except that it will want to pop up in 00892 * unexpected places and cause a great deal of confusion and cursing 00893 * from the unwary. 00894 */ 00895 operator string_type() const 00896 { 00897 return this->matched 00898 ? string_type(this->first, this->second) 00899 : string_type(); 00900 } 00901 00902 /** 00903 * @brief Gets the matching sequence as a string. 00904 * 00905 * @returns the matching sequence as a string. 00906 */ 00907 string_type 00908 str() const 00909 { 00910 return this->matched 00911 ? string_type(this->first, this->second) 00912 : string_type(); 00913 } 00914 00915 /** 00916 * @brief Compares this and another matched sequence. 00917 * 00918 * @param __s Another matched sequence to compare to this one. 00919 * 00920 * @retval <0 this matched sequence will collate before @p __s. 00921 * @retval =0 this matched sequence is equivalent to @p __s. 00922 * @retval <0 this matched sequence will collate after @p __s. 00923 */ 00924 int 00925 compare(const sub_match& __s) const 00926 { return this->str().compare(__s.str()); } 00927 00928 /** 00929 * @brief Compares this sub_match to a string. 00930 * 00931 * @param __s A string to compare to this sub_match. 00932 * 00933 * @retval <0 this matched sequence will collate before @p __s. 00934 * @retval =0 this matched sequence is equivalent to @p __s. 00935 * @retval <0 this matched sequence will collate after @p __s. 00936 */ 00937 int 00938 compare(const string_type& __s) const 00939 { return this->str().compare(__s); } 00940 00941 /** 00942 * @brief Compares this sub_match to a C-style string. 00943 * 00944 * @param __s A C-style string to compare to this sub_match. 00945 * 00946 * @retval <0 this matched sequence will collate before @p __s. 00947 * @retval =0 this matched sequence is equivalent to @p __s. 00948 * @retval <0 this matched sequence will collate after @p __s. 00949 */ 00950 int 00951 compare(const value_type* __s) const 00952 { return this->str().compare(__s); } 00953 }; 00954 00955 00956 /** @brief Standard regex submatch over a C-style null-terminated string. */ 00957 typedef sub_match<const char*> csub_match; 00958 00959 /** @brief Standard regex submatch over a standard string. */ 00960 typedef sub_match<string::const_iterator> ssub_match; 00961 00962 #ifdef _GLIBCXX_USE_WCHAR_T 00963 /** @brief Regex submatch over a C-style null-terminated wide string. */ 00964 typedef sub_match<const wchar_t*> wcsub_match; 00965 00966 /** @brief Regex submatch over a standard wide string. */ 00967 typedef sub_match<wstring::const_iterator> wssub_match; 00968 #endif 00969 00970 // [7.9.2] sub_match non-member operators 00971 00972 /** 00973 * @brief Tests the equivalence of two regular expression submatches. 00974 * @param __lhs First regular expression submatch. 00975 * @param __rhs Second regular expression submatch. 00976 * @returns true if @a __lhs is equivalent to @a __rhs, false otherwise. 00977 */ 00978 template<typename _BiIter> 00979 inline bool 00980 operator==(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs) 00981 { return __lhs.compare(__rhs) == 0; } 00982 00983 /** 00984 * @brief Tests the inequivalence of two regular expression submatches. 00985 * @param __lhs First regular expression submatch. 00986 * @param __rhs Second regular expression submatch. 00987 * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise. 00988 */ 00989 template<typename _BiIter> 00990 inline bool 00991 operator!=(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs) 00992 { return __lhs.compare(__rhs) != 0; } 00993 00994 /** 00995 * @brief Tests the ordering of two regular expression submatches. 00996 * @param __lhs First regular expression submatch. 00997 * @param __rhs Second regular expression submatch. 00998 * @returns true if @a __lhs precedes @a __rhs, false otherwise. 00999 */ 01000 template<typename _BiIter> 01001 inline bool 01002 operator<(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs) 01003 { return __lhs.compare(__rhs) < 0; } 01004 01005 /** 01006 * @brief Tests the ordering of two regular expression submatches. 01007 * @param __lhs First regular expression submatch. 01008 * @param __rhs Second regular expression submatch. 01009 * @returns true if @a __lhs does not succeed @a __rhs, false otherwise. 01010 */ 01011 template<typename _BiIter> 01012 inline bool 01013 operator<=(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs) 01014 { return __lhs.compare(__rhs) <= 0; } 01015 01016 /** 01017 * @brief Tests the ordering of two regular expression submatches. 01018 * @param __lhs First regular expression submatch. 01019 * @param __rhs Second regular expression submatch. 01020 * @returns true if @a __lhs does not precede @a __rhs, false otherwise. 01021 */ 01022 template<typename _BiIter> 01023 inline bool 01024 operator>=(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs) 01025 { return __lhs.compare(__rhs) >= 0; } 01026 01027 /** 01028 * @brief Tests the ordering of two regular expression submatches. 01029 * @param __lhs First regular expression submatch. 01030 * @param __rhs Second regular expression submatch. 01031 * @returns true if @a __lhs succeeds @a __rhs, false otherwise. 01032 */ 01033 template<typename _BiIter> 01034 inline bool 01035 operator>(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs) 01036 { return __lhs.compare(__rhs) > 0; } 01037 01038 // Alias for sub_match'd string. 01039 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc> 01040 using __sub_match_string = basic_string< 01041 typename iterator_traits<_Bi_iter>::value_type, 01042 _Ch_traits, _Ch_alloc>; 01043 01044 /** 01045 * @brief Tests the equivalence of a string and a regular expression 01046 * submatch. 01047 * @param __lhs A string. 01048 * @param __rhs A regular expression submatch. 01049 * @returns true if @a __lhs is equivalent to @a __rhs, false otherwise. 01050 */ 01051 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc> 01052 inline bool 01053 operator==(const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __lhs, 01054 const sub_match<_Bi_iter>& __rhs) 01055 { 01056 typedef typename sub_match<_Bi_iter>::string_type string_type; 01057 return __rhs.compare(string_type(__lhs.data(), __lhs.size())) == 0; 01058 } 01059 01060 /** 01061 * @brief Tests the inequivalence of a string and a regular expression 01062 * submatch. 01063 * @param __lhs A string. 01064 * @param __rhs A regular expression submatch. 01065 * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise. 01066 */ 01067 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc> 01068 inline bool 01069 operator!=(const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __lhs, 01070 const sub_match<_Bi_iter>& __rhs) 01071 { return !(__lhs == __rhs); } 01072 01073 /** 01074 * @brief Tests the ordering of a string and a regular expression submatch. 01075 * @param __lhs A string. 01076 * @param __rhs A regular expression submatch. 01077 * @returns true if @a __lhs precedes @a __rhs, false otherwise. 01078 */ 01079 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc> 01080 inline bool 01081 operator<(const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __lhs, 01082 const sub_match<_Bi_iter>& __rhs) 01083 { 01084 typedef typename sub_match<_Bi_iter>::string_type string_type; 01085 return __rhs.compare(string_type(__lhs.data(), __lhs.size())) > 0; 01086 } 01087 01088 /** 01089 * @brief Tests the ordering of a string and a regular expression submatch. 01090 * @param __lhs A string. 01091 * @param __rhs A regular expression submatch. 01092 * @returns true if @a __lhs succeeds @a __rhs, false otherwise. 01093 */ 01094 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc> 01095 inline bool 01096 operator>(const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __lhs, 01097 const sub_match<_Bi_iter>& __rhs) 01098 { return __rhs < __lhs; } 01099 01100 /** 01101 * @brief Tests the ordering of a string and a regular expression submatch. 01102 * @param __lhs A string. 01103 * @param __rhs A regular expression submatch. 01104 * @returns true if @a __lhs does not precede @a __rhs, false otherwise. 01105 */ 01106 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc> 01107 inline bool 01108 operator>=(const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __lhs, 01109 const sub_match<_Bi_iter>& __rhs) 01110 { return !(__lhs < __rhs); } 01111 01112 /** 01113 * @brief Tests the ordering of a string and a regular expression submatch. 01114 * @param __lhs A string. 01115 * @param __rhs A regular expression submatch. 01116 * @returns true if @a __lhs does not succeed @a __rhs, false otherwise. 01117 */ 01118 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc> 01119 inline bool 01120 operator<=(const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __lhs, 01121 const sub_match<_Bi_iter>& __rhs) 01122 { return !(__rhs < __lhs); } 01123 01124 /** 01125 * @brief Tests the equivalence of a regular expression submatch and a 01126 * string. 01127 * @param __lhs A regular expression submatch. 01128 * @param __rhs A string. 01129 * @returns true if @a __lhs is equivalent to @a __rhs, false otherwise. 01130 */ 01131 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc> 01132 inline bool 01133 operator==(const sub_match<_Bi_iter>& __lhs, 01134 const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __rhs) 01135 { 01136 typedef typename sub_match<_Bi_iter>::string_type string_type; 01137 return __lhs.compare(string_type(__rhs.data(), __rhs.size())) == 0; 01138 } 01139 01140 /** 01141 * @brief Tests the inequivalence of a regular expression submatch and a 01142 * string. 01143 * @param __lhs A regular expression submatch. 01144 * @param __rhs A string. 01145 * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise. 01146 */ 01147 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc> 01148 inline bool 01149 operator!=(const sub_match<_Bi_iter>& __lhs, 01150 const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __rhs) 01151 { return !(__lhs == __rhs); } 01152 01153 /** 01154 * @brief Tests the ordering of a regular expression submatch and a string. 01155 * @param __lhs A regular expression submatch. 01156 * @param __rhs A string. 01157 * @returns true if @a __lhs precedes @a __rhs, false otherwise. 01158 */ 01159 template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc> 01160 inline bool 01161 operator<(const sub_match<_Bi_iter>& __lhs, 01162 const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __rhs) 01163 { 01164 typedef typename sub_match<_Bi_iter>::string_type string_type; 01165 return __lhs.compare(string_type(__rhs.data(), __rhs.size())) < 0; 01166 } 01167 01168 /** 01169 * @brief Tests the ordering of a regular expression submatch and a string. 01170 * @param __lhs A regular expression submatch. 01171 * @param __rhs A string. 01172 * @returns true if @a __lhs succeeds @a __rhs, false otherwise. 01173 */ 01174 template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc> 01175 inline bool 01176 operator>(const sub_match<_Bi_iter>& __lhs, 01177 const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __rhs) 01178 { return __rhs < __lhs; } 01179 01180 /** 01181 * @brief Tests the ordering of a regular expression submatch and a string. 01182 * @param __lhs A regular expression submatch. 01183 * @param __rhs A string. 01184 * @returns true if @a __lhs does not precede @a __rhs, false otherwise. 01185 */ 01186 template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc> 01187 inline bool 01188 operator>=(const sub_match<_Bi_iter>& __lhs, 01189 const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __rhs) 01190 { return !(__lhs < __rhs); } 01191 01192 /** 01193 * @brief Tests the ordering of a regular expression submatch and a string. 01194 * @param __lhs A regular expression submatch. 01195 * @param __rhs A string. 01196 * @returns true if @a __lhs does not succeed @a __rhs, false otherwise. 01197 */ 01198 template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc> 01199 inline bool 01200 operator<=(const sub_match<_Bi_iter>& __lhs, 01201 const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __rhs) 01202 { return !(__rhs < __lhs); } 01203 01204 /** 01205 * @brief Tests the equivalence of a C string and a regular expression 01206 * submatch. 01207 * @param __lhs A C string. 01208 * @param __rhs A regular expression submatch. 01209 * @returns true if @a __lhs is equivalent to @a __rhs, false otherwise. 01210 */ 01211 template<typename _Bi_iter> 01212 inline bool 01213 operator==(typename iterator_traits<_Bi_iter>::value_type const* __lhs, 01214 const sub_match<_Bi_iter>& __rhs) 01215 { return __rhs.compare(__lhs) == 0; } 01216 01217 /** 01218 * @brief Tests the inequivalence of an iterator value and a regular 01219 * expression submatch. 01220 * @param __lhs A regular expression submatch. 01221 * @param __rhs A string. 01222 * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise. 01223 */ 01224 template<typename _Bi_iter> 01225 inline bool 01226 operator!=(typename iterator_traits<_Bi_iter>::value_type const* __lhs, 01227 const sub_match<_Bi_iter>& __rhs) 01228 { return !(__lhs == __rhs); } 01229 01230 /** 01231 * @brief Tests the ordering of a string and a regular expression submatch. 01232 * @param __lhs A string. 01233 * @param __rhs A regular expression submatch. 01234 * @returns true if @a __lhs precedes @a __rhs, false otherwise. 01235 */ 01236 template<typename _Bi_iter> 01237 inline bool 01238 operator<(typename iterator_traits<_Bi_iter>::value_type const* __lhs, 01239 const sub_match<_Bi_iter>& __rhs) 01240 { return __rhs.compare(__lhs) > 0; } 01241 01242 /** 01243 * @brief Tests the ordering of a string and a regular expression submatch. 01244 * @param __lhs A string. 01245 * @param __rhs A regular expression submatch. 01246 * @returns true if @a __lhs succeeds @a __rhs, false otherwise. 01247 */ 01248 template<typename _Bi_iter> 01249 inline bool 01250 operator>(typename iterator_traits<_Bi_iter>::value_type const* __lhs, 01251 const sub_match<_Bi_iter>& __rhs) 01252 { return __rhs < __lhs; } 01253 01254 /** 01255 * @brief Tests the ordering of a string and a regular expression submatch. 01256 * @param __lhs A string. 01257 * @param __rhs A regular expression submatch. 01258 * @returns true if @a __lhs does not precede @a __rhs, false otherwise. 01259 */ 01260 template<typename _Bi_iter> 01261 inline bool 01262 operator>=(typename iterator_traits<_Bi_iter>::value_type const* __lhs, 01263 const sub_match<_Bi_iter>& __rhs) 01264 { return !(__lhs < __rhs); } 01265 01266 /** 01267 * @brief Tests the ordering of a string and a regular expression submatch. 01268 * @param __lhs A string. 01269 * @param __rhs A regular expression submatch. 01270 * @returns true if @a __lhs does not succeed @a __rhs, false otherwise. 01271 */ 01272 template<typename _Bi_iter> 01273 inline bool 01274 operator<=(typename iterator_traits<_Bi_iter>::value_type const* __lhs, 01275 const sub_match<_Bi_iter>& __rhs) 01276 { return !(__rhs < __lhs); } 01277 01278 /** 01279 * @brief Tests the equivalence of a regular expression submatch and a 01280 * string. 01281 * @param __lhs A regular expression submatch. 01282 * @param __rhs A pointer to a string? 01283 * @returns true if @a __lhs is equivalent to @a __rhs, false otherwise. 01284 */ 01285 template<typename _Bi_iter> 01286 inline bool 01287 operator==(const sub_match<_Bi_iter>& __lhs, 01288 typename iterator_traits<_Bi_iter>::value_type const* __rhs) 01289 { return __lhs.compare(__rhs) == 0; } 01290 01291 /** 01292 * @brief Tests the inequivalence of a regular expression submatch and a 01293 * string. 01294 * @param __lhs A regular expression submatch. 01295 * @param __rhs A pointer to a string. 01296 * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise. 01297 */ 01298 template<typename _Bi_iter> 01299 inline bool 01300 operator!=(const sub_match<_Bi_iter>& __lhs, 01301 typename iterator_traits<_Bi_iter>::value_type const* __rhs) 01302 { return !(__lhs == __rhs); } 01303 01304 /** 01305 * @brief Tests the ordering of a regular expression submatch and a string. 01306 * @param __lhs A regular expression submatch. 01307 * @param __rhs A string. 01308 * @returns true if @a __lhs precedes @a __rhs, false otherwise. 01309 */ 01310 template<typename _Bi_iter> 01311 inline bool 01312 operator<(const sub_match<_Bi_iter>& __lhs, 01313 typename iterator_traits<_Bi_iter>::value_type const* __rhs) 01314 { return __lhs.compare(__rhs) < 0; } 01315 01316 /** 01317 * @brief Tests the ordering of a regular expression submatch and a string. 01318 * @param __lhs A regular expression submatch. 01319 * @param __rhs A string. 01320 * @returns true if @a __lhs succeeds @a __rhs, false otherwise. 01321 */ 01322 template<typename _Bi_iter> 01323 inline bool 01324 operator>(const sub_match<_Bi_iter>& __lhs, 01325 typename iterator_traits<_Bi_iter>::value_type const* __rhs) 01326 { return __rhs < __lhs; } 01327 01328 /** 01329 * @brief Tests the ordering of a regular expression submatch and a string. 01330 * @param __lhs A regular expression submatch. 01331 * @param __rhs A string. 01332 * @returns true if @a __lhs does not precede @a __rhs, false otherwise. 01333 */ 01334 template<typename _Bi_iter> 01335 inline bool 01336 operator>=(const sub_match<_Bi_iter>& __lhs, 01337 typename iterator_traits<_Bi_iter>::value_type const* __rhs) 01338 { return !(__lhs < __rhs); } 01339 01340 /** 01341 * @brief Tests the ordering of a regular expression submatch and a string. 01342 * @param __lhs A regular expression submatch. 01343 * @param __rhs A string. 01344 * @returns true if @a __lhs does not succeed @a __rhs, false otherwise. 01345 */ 01346 template<typename _Bi_iter> 01347 inline bool 01348 operator<=(const sub_match<_Bi_iter>& __lhs, 01349 typename iterator_traits<_Bi_iter>::value_type const* __rhs) 01350 { return !(__rhs < __lhs); } 01351 01352 /** 01353 * @brief Tests the equivalence of a string and a regular expression 01354 * submatch. 01355 * @param __lhs A string. 01356 * @param __rhs A regular expression submatch. 01357 * @returns true if @a __lhs is equivalent to @a __rhs, false otherwise. 01358 */ 01359 template<typename _Bi_iter> 01360 inline bool 01361 operator==(typename iterator_traits<_Bi_iter>::value_type const& __lhs, 01362 const sub_match<_Bi_iter>& __rhs) 01363 { 01364 typedef typename sub_match<_Bi_iter>::string_type string_type; 01365 return __rhs.compare(string_type(1, __lhs)) == 0; 01366 } 01367 01368 /** 01369 * @brief Tests the inequivalence of a string and a regular expression 01370 * submatch. 01371 * @param __lhs A string. 01372 * @param __rhs A regular expression submatch. 01373 * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise. 01374 */ 01375 template<typename _Bi_iter> 01376 inline bool 01377 operator!=(typename iterator_traits<_Bi_iter>::value_type const& __lhs, 01378 const sub_match<_Bi_iter>& __rhs) 01379 { return !(__lhs == __rhs); } 01380 01381 /** 01382 * @brief Tests the ordering of a string and a regular expression submatch. 01383 * @param __lhs A string. 01384 * @param __rhs A regular expression submatch. 01385 * @returns true if @a __lhs precedes @a __rhs, false otherwise. 01386 */ 01387 template<typename _Bi_iter> 01388 inline bool 01389 operator<(typename iterator_traits<_Bi_iter>::value_type const& __lhs, 01390 const sub_match<_Bi_iter>& __rhs) 01391 { 01392 typedef typename sub_match<_Bi_iter>::string_type string_type; 01393 return __rhs.compare(string_type(1, __lhs)) > 0; 01394 } 01395 01396 /** 01397 * @brief Tests the ordering of a string and a regular expression submatch. 01398 * @param __lhs A string. 01399 * @param __rhs A regular expression submatch. 01400 * @returns true if @a __lhs succeeds @a __rhs, false otherwise. 01401 */ 01402 template<typename _Bi_iter> 01403 inline bool 01404 operator>(typename iterator_traits<_Bi_iter>::value_type const& __lhs, 01405 const sub_match<_Bi_iter>& __rhs) 01406 { return __rhs < __lhs; } 01407 01408 /** 01409 * @brief Tests the ordering of a string and a regular expression submatch. 01410 * @param __lhs A string. 01411 * @param __rhs A regular expression submatch. 01412 * @returns true if @a __lhs does not precede @a __rhs, false otherwise. 01413 */ 01414 template<typename _Bi_iter> 01415 inline bool 01416 operator>=(typename iterator_traits<_Bi_iter>::value_type const& __lhs, 01417 const sub_match<_Bi_iter>& __rhs) 01418 { return !(__lhs < __rhs); } 01419 01420 /** 01421 * @brief Tests the ordering of a string and a regular expression submatch. 01422 * @param __lhs A string. 01423 * @param __rhs A regular expression submatch. 01424 * @returns true if @a __lhs does not succeed @a __rhs, false otherwise. 01425 */ 01426 template<typename _Bi_iter> 01427 inline bool 01428 operator<=(typename iterator_traits<_Bi_iter>::value_type const& __lhs, 01429 const sub_match<_Bi_iter>& __rhs) 01430 { return !(__rhs < __lhs); } 01431 01432 /** 01433 * @brief Tests the equivalence of a regular expression submatch and a 01434 * string. 01435 * @param __lhs A regular expression submatch. 01436 * @param __rhs A const string reference. 01437 * @returns true if @a __lhs is equivalent to @a __rhs, false otherwise. 01438 */ 01439 template<typename _Bi_iter> 01440 inline bool 01441 operator==(const sub_match<_Bi_iter>& __lhs, 01442 typename iterator_traits<_Bi_iter>::value_type const& __rhs) 01443 { 01444 typedef typename sub_match<_Bi_iter>::string_type string_type; 01445 return __lhs.compare(string_type(1, __rhs)) == 0; 01446 } 01447 01448 /** 01449 * @brief Tests the inequivalence of a regular expression submatch and a 01450 * string. 01451 * @param __lhs A regular expression submatch. 01452 * @param __rhs A const string reference. 01453 * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise. 01454 */ 01455 template<typename _Bi_iter> 01456 inline bool 01457 operator!=(const sub_match<_Bi_iter>& __lhs, 01458 typename iterator_traits<_Bi_iter>::value_type const& __rhs) 01459 { return !(__lhs == __rhs); } 01460 01461 /** 01462 * @brief Tests the ordering of a regular expression submatch and a string. 01463 * @param __lhs A regular expression submatch. 01464 * @param __rhs A const string reference. 01465 * @returns true if @a __lhs precedes @a __rhs, false otherwise. 01466 */ 01467 template<typename _Bi_iter> 01468 inline bool 01469 operator<(const sub_match<_Bi_iter>& __lhs, 01470 typename iterator_traits<_Bi_iter>::value_type const& __rhs) 01471 { 01472 typedef typename sub_match<_Bi_iter>::string_type string_type; 01473 return __lhs.compare(string_type(1, __rhs)) < 0; 01474 } 01475 01476 /** 01477 * @brief Tests the ordering of a regular expression submatch and a string. 01478 * @param __lhs A regular expression submatch. 01479 * @param __rhs A const string reference. 01480 * @returns true if @a __lhs succeeds @a __rhs, false otherwise. 01481 */ 01482 template<typename _Bi_iter> 01483 inline bool 01484 operator>(const sub_match<_Bi_iter>& __lhs, 01485 typename iterator_traits<_Bi_iter>::value_type const& __rhs) 01486 { return __rhs < __lhs; } 01487 01488 /** 01489 * @brief Tests the ordering of a regular expression submatch and a string. 01490 * @param __lhs A regular expression submatch. 01491 * @param __rhs A const string reference. 01492 * @returns true if @a __lhs does not precede @a __rhs, false otherwise. 01493 */ 01494 template<typename _Bi_iter> 01495 inline bool 01496 operator>=(const sub_match<_Bi_iter>& __lhs, 01497 typename iterator_traits<_Bi_iter>::value_type const& __rhs) 01498 { return !(__lhs < __rhs); } 01499 01500 /** 01501 * @brief Tests the ordering of a regular expression submatch and a string. 01502 * @param __lhs A regular expression submatch. 01503 * @param __rhs A const string reference. 01504 * @returns true if @a __lhs does not succeed @a __rhs, false otherwise. 01505 */ 01506 template<typename _Bi_iter> 01507 inline bool 01508 operator<=(const sub_match<_Bi_iter>& __lhs, 01509 typename iterator_traits<_Bi_iter>::value_type const& __rhs) 01510 { return !(__rhs < __lhs); } 01511 01512 /** 01513 * @brief Inserts a matched string into an output stream. 01514 * 01515 * @param __os The output stream. 01516 * @param __m A submatch string. 01517 * 01518 * @returns the output stream with the submatch string inserted. 01519 */ 01520 template<typename _Ch_type, typename _Ch_traits, typename _Bi_iter> 01521 inline 01522 basic_ostream<_Ch_type, _Ch_traits>& 01523 operator<<(basic_ostream<_Ch_type, _Ch_traits>& __os, 01524 const sub_match<_Bi_iter>& __m) 01525 { return __os << __m.str(); } 01526 01527 // [7.10] Class template match_results 01528 01529 /** 01530 * @brief The results of a match or search operation. 01531 * 01532 * A collection of character sequences representing the result of a regular 01533 * expression match. Storage for the collection is allocated and freed as 01534 * necessary by the member functions of class template match_results. 01535 * 01536 * This class satisfies the Sequence requirements, with the exception that 01537 * only the operations defined for a const-qualified Sequence are supported. 01538 * 01539 * The sub_match object stored at index 0 represents sub-expression 0, i.e. 01540 * the whole match. In this case the %sub_match member matched is always true. 01541 * The sub_match object stored at index n denotes what matched the marked 01542 * sub-expression n within the matched expression. If the sub-expression n 01543 * participated in a regular expression match then the %sub_match member 01544 * matched evaluates to true, and members first and second denote the range 01545 * of characters [first, second) which formed that match. Otherwise matched 01546 * is false, and members first and second point to the end of the sequence 01547 * that was searched. 01548 * 01549 * @nosubgrouping 01550 */ 01551 template<typename _Bi_iter, 01552 typename _Alloc = allocator<sub_match<_Bi_iter> > > 01553 class match_results 01554 : private std::vector<sub_match<_Bi_iter>, _Alloc> 01555 { 01556 private: 01557 /* 01558 * The vector base is empty if this does not represent a match (!ready()); 01559 * Otherwise if it's a match failure, it contains 3 elements: 01560 * [0] unmatched 01561 * [1] prefix 01562 * [2] suffix 01563 * Otherwise it contains n+4 elements where n is the number of marked 01564 * sub-expressions: 01565 * [0] entire match 01566 * [1] 1st marked subexpression 01567 * ... 01568 * [n] nth marked subexpression 01569 * [n+1] unmatched 01570 * [n+2] prefix 01571 * [n+3] suffix 01572 */ 01573 typedef std::vector<sub_match<_Bi_iter>, _Alloc> _Base_type; 01574 typedef std::iterator_traits<_Bi_iter> __iter_traits; 01575 typedef regex_constants::match_flag_type match_flag_type; 01576 01577 public: 01578 /** 01579 * @name 10.? Public Types 01580 */ 01581 //@{ 01582 typedef sub_match<_Bi_iter> value_type; 01583 typedef const value_type& const_reference; 01584 typedef value_type& reference; 01585 typedef typename _Base_type::const_iterator const_iterator; 01586 typedef const_iterator iterator; 01587 typedef typename __iter_traits::difference_type difference_type; 01588 typedef typename allocator_traits<_Alloc>::size_type size_type; 01589 typedef _Alloc allocator_type; 01590 typedef typename __iter_traits::value_type char_type; 01591 typedef std::basic_string<char_type> string_type; 01592 //@} 01593 01594 public: 01595 /** 01596 * @name 28.10.1 Construction, Copying, and Destruction 01597 */ 01598 //@{ 01599 01600 /** 01601 * @brief Constructs a default %match_results container. 01602 * @post size() returns 0 and str() returns an empty string. 01603 */ 01604 explicit 01605 match_results(const _Alloc& __a = _Alloc()) 01606 : _Base_type(__a) 01607 { } 01608 01609 /** 01610 * @brief Copy constructs a %match_results. 01611 */ 01612 match_results(const match_results& __rhs) = default; 01613 01614 /** 01615 * @brief Move constructs a %match_results. 01616 */ 01617 match_results(match_results&& __rhs) noexcept = default; 01618 01619 /** 01620 * @brief Assigns rhs to *this. 01621 */ 01622 match_results& 01623 operator=(const match_results& __rhs) = default; 01624 01625 /** 01626 * @brief Move-assigns rhs to *this. 01627 */ 01628 match_results& 01629 operator=(match_results&& __rhs) = default; 01630 01631 /** 01632 * @brief Destroys a %match_results object. 01633 */ 01634 ~match_results() 01635 { } 01636 01637 //@} 01638 01639 // 28.10.2, state: 01640 /** 01641 * @brief Indicates if the %match_results is ready. 01642 * @retval true The object has a fully-established result state. 01643 * @retval false The object is not ready. 01644 */ 01645 bool ready() const { return !_Base_type::empty(); } 01646 01647 /** 01648 * @name 28.10.2 Size 01649 */ 01650 //@{ 01651 01652 /** 01653 * @brief Gets the number of matches and submatches. 01654 * 01655 * The number of matches for a given regular expression will be either 0 01656 * if there was no match or mark_count() + 1 if a match was successful. 01657 * Some matches may be empty. 01658 * 01659 * @returns the number of matches found. 01660 */ 01661 size_type 01662 size() const 01663 { return _Base_type::empty() ? 0 : _Base_type::size() - 3; } 01664 01665 size_type 01666 max_size() const 01667 { return _Base_type::max_size(); } 01668 01669 /** 01670 * @brief Indicates if the %match_results contains no results. 01671 * @retval true The %match_results object is empty. 01672 * @retval false The %match_results object is not empty. 01673 */ 01674 bool 01675 empty() const 01676 { return size() == 0; } 01677 01678 //@} 01679 01680 /** 01681 * @name 10.3 Element Access 01682 */ 01683 //@{ 01684 01685 /** 01686 * @brief Gets the length of the indicated submatch. 01687 * @param __sub indicates the submatch. 01688 * @pre ready() == true 01689 * 01690 * This function returns the length of the indicated submatch, or the 01691 * length of the entire match if @p __sub is zero (the default). 01692 */ 01693 difference_type 01694 length(size_type __sub = 0) const 01695 { return (*this)[__sub].length(); } 01696 01697 /** 01698 * @brief Gets the offset of the beginning of the indicated submatch. 01699 * @param __sub indicates the submatch. 01700 * @pre ready() == true 01701 * 01702 * This function returns the offset from the beginning of the target 01703 * sequence to the beginning of the submatch, unless the value of @p __sub 01704 * is zero (the default), in which case this function returns the offset 01705 * from the beginning of the target sequence to the beginning of the 01706 * match. 01707 */ 01708 difference_type 01709 position(size_type __sub = 0) const 01710 { return std::distance(_M_begin, (*this)[__sub].first); } 01711 01712 /** 01713 * @brief Gets the match or submatch converted to a string type. 01714 * @param __sub indicates the submatch. 01715 * @pre ready() == true 01716 * 01717 * This function gets the submatch (or match, if @p __sub is 01718 * zero) extracted from the target range and converted to the 01719 * associated string type. 01720 */ 01721 string_type 01722 str(size_type __sub = 0) const 01723 { return string_type((*this)[__sub]); } 01724 01725 /** 01726 * @brief Gets a %sub_match reference for the match or submatch. 01727 * @param __sub indicates the submatch. 01728 * @pre ready() == true 01729 * 01730 * This function gets a reference to the indicated submatch, or 01731 * the entire match if @p __sub is zero. 01732 * 01733 * If @p __sub >= size() then this function returns a %sub_match with a 01734 * special value indicating no submatch. 01735 */ 01736 const_reference 01737 operator[](size_type __sub) const 01738 { 01739 __glibcxx_assert( ready() ); 01740 return __sub < size() 01741 ? _Base_type::operator[](__sub) 01742 : _M_unmatched_sub(); 01743 } 01744 01745 /** 01746 * @brief Gets a %sub_match representing the match prefix. 01747 * @pre ready() == true 01748 * 01749 * This function gets a reference to a %sub_match object representing the 01750 * part of the target range between the start of the target range and the 01751 * start of the match. 01752 */ 01753 const_reference 01754 prefix() const 01755 { 01756 __glibcxx_assert( ready() ); 01757 return !empty() ? _M_prefix() : _M_unmatched_sub(); 01758 } 01759 01760 /** 01761 * @brief Gets a %sub_match representing the match suffix. 01762 * @pre ready() == true 01763 * 01764 * This function gets a reference to a %sub_match object representing the 01765 * part of the target range between the end of the match and the end of 01766 * the target range. 01767 */ 01768 const_reference 01769 suffix() const 01770 { 01771 __glibcxx_assert( ready() ); 01772 return !empty() ? _M_suffix() : _M_unmatched_sub(); 01773 } 01774 01775 /** 01776 * @brief Gets an iterator to the start of the %sub_match collection. 01777 */ 01778 const_iterator 01779 begin() const 01780 { return _Base_type::begin(); } 01781 01782 /** 01783 * @brief Gets an iterator to the start of the %sub_match collection. 01784 */ 01785 const_iterator 01786 cbegin() const 01787 { return this->begin(); } 01788 01789 /** 01790 * @brief Gets an iterator to one-past-the-end of the collection. 01791 */ 01792 const_iterator 01793 end() const 01794 { return _Base_type::end() - (empty() ? 0 : 3); } 01795 01796 /** 01797 * @brief Gets an iterator to one-past-the-end of the collection. 01798 */ 01799 const_iterator 01800 cend() const 01801 { return this->end(); } 01802 01803 //@} 01804 01805 /** 01806 * @name 10.4 Formatting 01807 * 01808 * These functions perform formatted substitution of the matched 01809 * character sequences into their target. The format specifiers and 01810 * escape sequences accepted by these functions are determined by 01811 * their @p flags parameter as documented above. 01812 */ 01813 //@{ 01814 01815 /** 01816 * @pre ready() == true 01817 */ 01818 template<typename _Out_iter> 01819 _Out_iter 01820 format(_Out_iter __out, const char_type* __fmt_first, 01821 const char_type* __fmt_last, 01822 match_flag_type __flags = regex_constants::format_default) const; 01823 01824 /** 01825 * @pre ready() == true 01826 */ 01827 template<typename _Out_iter, typename _St, typename _Sa> 01828 _Out_iter 01829 format(_Out_iter __out, const basic_string<char_type, _St, _Sa>& __fmt, 01830 match_flag_type __flags = regex_constants::format_default) const 01831 { 01832 return format(__out, __fmt.data(), __fmt.data() + __fmt.size(), 01833 __flags); 01834 } 01835 01836 /** 01837 * @pre ready() == true 01838 */ 01839 template<typename _St, typename _Sa> 01840 basic_string<char_type, _St, _Sa> 01841 format(const basic_string<char_type, _St, _Sa>& __fmt, 01842 match_flag_type __flags = regex_constants::format_default) const 01843 { 01844 basic_string<char_type, _St, _Sa> __result; 01845 format(std::back_inserter(__result), __fmt, __flags); 01846 return __result; 01847 } 01848 01849 /** 01850 * @pre ready() == true 01851 */ 01852 string_type 01853 format(const char_type* __fmt, 01854 match_flag_type __flags = regex_constants::format_default) const 01855 { 01856 string_type __result; 01857 format(std::back_inserter(__result), 01858 __fmt, 01859 __fmt + char_traits<char_type>::length(__fmt), 01860 __flags); 01861 return __result; 01862 } 01863 01864 //@} 01865 01866 /** 01867 * @name 10.5 Allocator 01868 */ 01869 //@{ 01870 01871 /** 01872 * @brief Gets a copy of the allocator. 01873 */ 01874 allocator_type 01875 get_allocator() const 01876 { return _Base_type::get_allocator(); } 01877 01878 //@} 01879 01880 /** 01881 * @name 10.6 Swap 01882 */ 01883 //@{ 01884 01885 /** 01886 * @brief Swaps the contents of two match_results. 01887 */ 01888 void 01889 swap(match_results& __that) 01890 { 01891 using std::swap; 01892 _Base_type::swap(__that); 01893 swap(_M_begin, __that._M_begin); 01894 } 01895 //@} 01896 01897 private: 01898 template<typename, typename, typename, bool> 01899 friend class __detail::_Executor; 01900 01901 template<typename, typename, typename> 01902 friend class regex_iterator; 01903 01904 template<typename _Bp, typename _Ap, typename _Cp, typename _Rp, 01905 __detail::_RegexExecutorPolicy, bool> 01906 friend bool 01907 __detail::__regex_algo_impl(_Bp, _Bp, match_results<_Bp, _Ap>&, 01908 const basic_regex<_Cp, _Rp>&, 01909 regex_constants::match_flag_type); 01910 01911 void 01912 _M_resize(unsigned int __size) 01913 { _Base_type::resize(__size + 3); } 01914 01915 const_reference 01916 _M_unmatched_sub() const 01917 { return _Base_type::operator[](_Base_type::size() - 3); } 01918 01919 sub_match<_Bi_iter>& 01920 _M_unmatched_sub() 01921 { return _Base_type::operator[](_Base_type::size() - 3); } 01922 01923 const_reference 01924 _M_prefix() const 01925 { return _Base_type::operator[](_Base_type::size() - 2); } 01926 01927 sub_match<_Bi_iter>& 01928 _M_prefix() 01929 { return _Base_type::operator[](_Base_type::size() - 2); } 01930 01931 const_reference 01932 _M_suffix() const 01933 { return _Base_type::operator[](_Base_type::size() - 1); } 01934 01935 sub_match<_Bi_iter>& 01936 _M_suffix() 01937 { return _Base_type::operator[](_Base_type::size() - 1); } 01938 01939 _Bi_iter _M_begin; 01940 }; 01941 01942 typedef match_results<const char*> cmatch; 01943 typedef match_results<string::const_iterator> smatch; 01944 #ifdef _GLIBCXX_USE_WCHAR_T 01945 typedef match_results<const wchar_t*> wcmatch; 01946 typedef match_results<wstring::const_iterator> wsmatch; 01947 #endif 01948 01949 // match_results comparisons 01950 /** 01951 * @brief Compares two match_results for equality. 01952 * @returns true if the two objects refer to the same match, 01953 * false otherwise. 01954 */ 01955 template<typename _Bi_iter, typename _Alloc> 01956 inline bool 01957 operator==(const match_results<_Bi_iter, _Alloc>& __m1, 01958 const match_results<_Bi_iter, _Alloc>& __m2) 01959 { 01960 if (__m1.ready() != __m2.ready()) 01961 return false; 01962 if (!__m1.ready()) // both are not ready 01963 return true; 01964 if (__m1.empty() != __m2.empty()) 01965 return false; 01966 if (__m1.empty()) // both are empty 01967 return true; 01968 return __m1.prefix() == __m2.prefix() 01969 && __m1.size() == __m2.size() 01970 && std::equal(__m1.begin(), __m1.end(), __m2.begin()) 01971 && __m1.suffix() == __m2.suffix(); 01972 } 01973 01974 /** 01975 * @brief Compares two match_results for inequality. 01976 * @returns true if the two objects do not refer to the same match, 01977 * false otherwise. 01978 */ 01979 template<typename _Bi_iter, class _Alloc> 01980 inline bool 01981 operator!=(const match_results<_Bi_iter, _Alloc>& __m1, 01982 const match_results<_Bi_iter, _Alloc>& __m2) 01983 { return !(__m1 == __m2); } 01984 01985 // [7.10.6] match_results swap 01986 /** 01987 * @brief Swaps two match results. 01988 * @param __lhs A match result. 01989 * @param __rhs A match result. 01990 * 01991 * The contents of the two match_results objects are swapped. 01992 */ 01993 template<typename _Bi_iter, typename _Alloc> 01994 inline void 01995 swap(match_results<_Bi_iter, _Alloc>& __lhs, 01996 match_results<_Bi_iter, _Alloc>& __rhs) 01997 { __lhs.swap(__rhs); } 01998 01999 _GLIBCXX_END_NAMESPACE_CXX11 02000 02001 // [7.11.2] Function template regex_match 02002 /** 02003 * @name Matching, Searching, and Replacing 02004 */ 02005 //@{ 02006 02007 /** 02008 * @brief Determines if there is a match between the regular expression @p e 02009 * and all of the character sequence [first, last). 02010 * 02011 * @param __s Start of the character sequence to match. 02012 * @param __e One-past-the-end of the character sequence to match. 02013 * @param __m The match results. 02014 * @param __re The regular expression. 02015 * @param __flags Controls how the regular expression is matched. 02016 * 02017 * @retval true A match exists. 02018 * @retval false Otherwise. 02019 * 02020 * @throws an exception of type regex_error. 02021 */ 02022 template<typename _Bi_iter, typename _Alloc, 02023 typename _Ch_type, typename _Rx_traits> 02024 inline bool 02025 regex_match(_Bi_iter __s, 02026 _Bi_iter __e, 02027 match_results<_Bi_iter, _Alloc>& __m, 02028 const basic_regex<_Ch_type, _Rx_traits>& __re, 02029 regex_constants::match_flag_type __flags 02030 = regex_constants::match_default) 02031 { 02032 return __detail::__regex_algo_impl<_Bi_iter, _Alloc, _Ch_type, _Rx_traits, 02033 __detail::_RegexExecutorPolicy::_S_auto, true> 02034 (__s, __e, __m, __re, __flags); 02035 } 02036 02037 /** 02038 * @brief Indicates if there is a match between the regular expression @p e 02039 * and all of the character sequence [first, last). 02040 * 02041 * @param __first Beginning of the character sequence to match. 02042 * @param __last One-past-the-end of the character sequence to match. 02043 * @param __re The regular expression. 02044 * @param __flags Controls how the regular expression is matched. 02045 * 02046 * @retval true A match exists. 02047 * @retval false Otherwise. 02048 * 02049 * @throws an exception of type regex_error. 02050 */ 02051 template<typename _Bi_iter, typename _Ch_type, typename _Rx_traits> 02052 inline bool 02053 regex_match(_Bi_iter __first, _Bi_iter __last, 02054 const basic_regex<_Ch_type, _Rx_traits>& __re, 02055 regex_constants::match_flag_type __flags 02056 = regex_constants::match_default) 02057 { 02058 match_results<_Bi_iter> __what; 02059 return regex_match(__first, __last, __what, __re, __flags); 02060 } 02061 02062 /** 02063 * @brief Determines if there is a match between the regular expression @p e 02064 * and a C-style null-terminated string. 02065 * 02066 * @param __s The C-style null-terminated string to match. 02067 * @param __m The match results. 02068 * @param __re The regular expression. 02069 * @param __f Controls how the regular expression is matched. 02070 * 02071 * @retval true A match exists. 02072 * @retval false Otherwise. 02073 * 02074 * @throws an exception of type regex_error. 02075 */ 02076 template<typename _Ch_type, typename _Alloc, typename _Rx_traits> 02077 inline bool 02078 regex_match(const _Ch_type* __s, 02079 match_results<const _Ch_type*, _Alloc>& __m, 02080 const basic_regex<_Ch_type, _Rx_traits>& __re, 02081 regex_constants::match_flag_type __f 02082 = regex_constants::match_default) 02083 { return regex_match(__s, __s + _Rx_traits::length(__s), __m, __re, __f); } 02084 02085 /** 02086 * @brief Determines if there is a match between the regular expression @p e 02087 * and a string. 02088 * 02089 * @param __s The string to match. 02090 * @param __m The match results. 02091 * @param __re The regular expression. 02092 * @param __flags Controls how the regular expression is matched. 02093 * 02094 * @retval true A match exists. 02095 * @retval false Otherwise. 02096 * 02097 * @throws an exception of type regex_error. 02098 */ 02099 template<typename _Ch_traits, typename _Ch_alloc, 02100 typename _Alloc, typename _Ch_type, typename _Rx_traits> 02101 inline bool 02102 regex_match(const basic_string<_Ch_type, _Ch_traits, _Ch_alloc>& __s, 02103 match_results<typename basic_string<_Ch_type, 02104 _Ch_traits, _Ch_alloc>::const_iterator, _Alloc>& __m, 02105 const basic_regex<_Ch_type, _Rx_traits>& __re, 02106 regex_constants::match_flag_type __flags 02107 = regex_constants::match_default) 02108 { return regex_match(__s.begin(), __s.end(), __m, __re, __flags); } 02109 02110 // _GLIBCXX_RESOLVE_LIB_DEFECTS 02111 // 2329. regex_match() with match_results should forbid temporary strings 02112 /// Prevent unsafe attempts to get match_results from a temporary string. 02113 template<typename _Ch_traits, typename _Ch_alloc, 02114 typename _Alloc, typename _Ch_type, typename _Rx_traits> 02115 bool 02116 regex_match(const basic_string<_Ch_type, _Ch_traits, _Ch_alloc>&&, 02117 match_results<typename basic_string<_Ch_type, 02118 _Ch_traits, _Ch_alloc>::const_iterator, _Alloc>&, 02119 const basic_regex<_Ch_type, _Rx_traits>&, 02120 regex_constants::match_flag_type 02121 = regex_constants::match_default) = delete; 02122 02123 /** 02124 * @brief Indicates if there is a match between the regular expression @p e 02125 * and a C-style null-terminated string. 02126 * 02127 * @param __s The C-style null-terminated string to match. 02128 * @param __re The regular expression. 02129 * @param __f Controls how the regular expression is matched. 02130 * 02131 * @retval true A match exists. 02132 * @retval false Otherwise. 02133 * 02134 * @throws an exception of type regex_error. 02135 */ 02136 template<typename _Ch_type, class _Rx_traits> 02137 inline bool 02138 regex_match(const _Ch_type* __s, 02139 const basic_regex<_Ch_type, _Rx_traits>& __re, 02140 regex_constants::match_flag_type __f 02141 = regex_constants::match_default) 02142 { return regex_match(__s, __s + _Rx_traits::length(__s), __re, __f); } 02143 02144 /** 02145 * @brief Indicates if there is a match between the regular expression @p e 02146 * and a string. 02147 * 02148 * @param __s [IN] The string to match. 02149 * @param __re [IN] The regular expression. 02150 * @param __flags [IN] Controls how the regular expression is matched. 02151 * 02152 * @retval true A match exists. 02153 * @retval false Otherwise. 02154 * 02155 * @throws an exception of type regex_error. 02156 */ 02157 template<typename _Ch_traits, typename _Str_allocator, 02158 typename _Ch_type, typename _Rx_traits> 02159 inline bool 02160 regex_match(const basic_string<_Ch_type, _Ch_traits, _Str_allocator>& __s, 02161 const basic_regex<_Ch_type, _Rx_traits>& __re, 02162 regex_constants::match_flag_type __flags 02163 = regex_constants::match_default) 02164 { return regex_match(__s.begin(), __s.end(), __re, __flags); } 02165 02166 // [7.11.3] Function template regex_search 02167 /** 02168 * Searches for a regular expression within a range. 02169 * @param __s [IN] The start of the string to search. 02170 * @param __e [IN] One-past-the-end of the string to search. 02171 * @param __m [OUT] The match results. 02172 * @param __re [IN] The regular expression to search for. 02173 * @param __flags [IN] Search policy flags. 02174 * @retval true A match was found within the string. 02175 * @retval false No match was found within the string, the content of %m is 02176 * undefined. 02177 * 02178 * @throws an exception of type regex_error. 02179 */ 02180 template<typename _Bi_iter, typename _Alloc, 02181 typename _Ch_type, typename _Rx_traits> 02182 inline bool 02183 regex_search(_Bi_iter __s, _Bi_iter __e, 02184 match_results<_Bi_iter, _Alloc>& __m, 02185 const basic_regex<_Ch_type, _Rx_traits>& __re, 02186 regex_constants::match_flag_type __flags 02187 = regex_constants::match_default) 02188 { 02189 return __detail::__regex_algo_impl<_Bi_iter, _Alloc, _Ch_type, _Rx_traits, 02190 __detail::_RegexExecutorPolicy::_S_auto, false> 02191 (__s, __e, __m, __re, __flags); 02192 } 02193 02194 /** 02195 * Searches for a regular expression within a range. 02196 * @param __first [IN] The start of the string to search. 02197 * @param __last [IN] One-past-the-end of the string to search. 02198 * @param __re [IN] The regular expression to search for. 02199 * @param __flags [IN] Search policy flags. 02200 * @retval true A match was found within the string. 02201 * @retval false No match was found within the string. 02202 * 02203 * @throws an exception of type regex_error. 02204 */ 02205 template<typename _Bi_iter, typename _Ch_type, typename _Rx_traits> 02206 inline bool 02207 regex_search(_Bi_iter __first, _Bi_iter __last, 02208 const basic_regex<_Ch_type, _Rx_traits>& __re, 02209 regex_constants::match_flag_type __flags 02210 = regex_constants::match_default) 02211 { 02212 match_results<_Bi_iter> __what; 02213 return regex_search(__first, __last, __what, __re, __flags); 02214 } 02215 02216 /** 02217 * @brief Searches for a regular expression within a C-string. 02218 * @param __s [IN] A C-string to search for the regex. 02219 * @param __m [OUT] The set of regex matches. 02220 * @param __e [IN] The regex to search for in @p s. 02221 * @param __f [IN] The search flags. 02222 * @retval true A match was found within the string. 02223 * @retval false No match was found within the string, the content of %m is 02224 * undefined. 02225 * 02226 * @throws an exception of type regex_error. 02227 */ 02228 template<typename _Ch_type, class _Alloc, class _Rx_traits> 02229 inline bool 02230 regex_search(const _Ch_type* __s, 02231 match_results<const _Ch_type*, _Alloc>& __m, 02232 const basic_regex<_Ch_type, _Rx_traits>& __e, 02233 regex_constants::match_flag_type __f 02234 = regex_constants::match_default) 02235 { return regex_search(__s, __s + _Rx_traits::length(__s), __m, __e, __f); } 02236 02237 /** 02238 * @brief Searches for a regular expression within a C-string. 02239 * @param __s [IN] The C-string to search. 02240 * @param __e [IN] The regular expression to search for. 02241 * @param __f [IN] Search policy flags. 02242 * @retval true A match was found within the string. 02243 * @retval false No match was found within the string. 02244 * 02245 * @throws an exception of type regex_error. 02246 */ 02247 template<typename _Ch_type, typename _Rx_traits> 02248 inline bool 02249 regex_search(const _Ch_type* __s, 02250 const basic_regex<_Ch_type, _Rx_traits>& __e, 02251 regex_constants::match_flag_type __f 02252 = regex_constants::match_default) 02253 { return regex_search(__s, __s + _Rx_traits::length(__s), __e, __f); } 02254 02255 /** 02256 * @brief Searches for a regular expression within a string. 02257 * @param __s [IN] The string to search. 02258 * @param __e [IN] The regular expression to search for. 02259 * @param __flags [IN] Search policy flags. 02260 * @retval true A match was found within the string. 02261 * @retval false No match was found within the string. 02262 * 02263 * @throws an exception of type regex_error. 02264 */ 02265 template<typename _Ch_traits, typename _String_allocator, 02266 typename _Ch_type, typename _Rx_traits> 02267 inline bool 02268 regex_search(const basic_string<_Ch_type, _Ch_traits, 02269 _String_allocator>& __s, 02270 const basic_regex<_Ch_type, _Rx_traits>& __e, 02271 regex_constants::match_flag_type __flags 02272 = regex_constants::match_default) 02273 { return regex_search(__s.begin(), __s.end(), __e, __flags); } 02274 02275 /** 02276 * @brief Searches for a regular expression within a string. 02277 * @param __s [IN] A C++ string to search for the regex. 02278 * @param __m [OUT] The set of regex matches. 02279 * @param __e [IN] The regex to search for in @p s. 02280 * @param __f [IN] The search flags. 02281 * @retval true A match was found within the string. 02282 * @retval false No match was found within the string, the content of %m is 02283 * undefined. 02284 * 02285 * @throws an exception of type regex_error. 02286 */ 02287 template<typename _Ch_traits, typename _Ch_alloc, 02288 typename _Alloc, typename _Ch_type, 02289 typename _Rx_traits> 02290 inline bool 02291 regex_search(const basic_string<_Ch_type, _Ch_traits, _Ch_alloc>& __s, 02292 match_results<typename basic_string<_Ch_type, 02293 _Ch_traits, _Ch_alloc>::const_iterator, _Alloc>& __m, 02294 const basic_regex<_Ch_type, _Rx_traits>& __e, 02295 regex_constants::match_flag_type __f 02296 = regex_constants::match_default) 02297 { return regex_search(__s.begin(), __s.end(), __m, __e, __f); } 02298 02299 // _GLIBCXX_RESOLVE_LIB_DEFECTS 02300 // 2329. regex_search() with match_results should forbid temporary strings 02301 /// Prevent unsafe attempts to get match_results from a temporary string. 02302 template<typename _Ch_traits, typename _Ch_alloc, 02303 typename _Alloc, typename _Ch_type, 02304 typename _Rx_traits> 02305 bool 02306 regex_search(const basic_string<_Ch_type, _Ch_traits, _Ch_alloc>&&, 02307 match_results<typename basic_string<_Ch_type, 02308 _Ch_traits, _Ch_alloc>::const_iterator, _Alloc>&, 02309 const basic_regex<_Ch_type, _Rx_traits>&, 02310 regex_constants::match_flag_type 02311 = regex_constants::match_default) = delete; 02312 02313 // std [28.11.4] Function template regex_replace 02314 /** 02315 * @brief Search for a regular expression within a range for multiple times, 02316 and replace the matched parts through filling a format string. 02317 * @param __out [OUT] The output iterator. 02318 * @param __first [IN] The start of the string to search. 02319 * @param __last [IN] One-past-the-end of the string to search. 02320 * @param __e [IN] The regular expression to search for. 02321 * @param __fmt [IN] The format string. 02322 * @param __flags [IN] Search and replace policy flags. 02323 * 02324 * @returns __out 02325 * @throws an exception of type regex_error. 02326 */ 02327 template<typename _Out_iter, typename _Bi_iter, 02328 typename _Rx_traits, typename _Ch_type, 02329 typename _St, typename _Sa> 02330 inline _Out_iter 02331 regex_replace(_Out_iter __out, _Bi_iter __first, _Bi_iter __last, 02332 const basic_regex<_Ch_type, _Rx_traits>& __e, 02333 const basic_string<_Ch_type, _St, _Sa>& __fmt, 02334 regex_constants::match_flag_type __flags 02335 = regex_constants::match_default) 02336 { 02337 return regex_replace(__out, __first, __last, __e, __fmt.c_str(), __flags); 02338 } 02339 02340 /** 02341 * @brief Search for a regular expression within a range for multiple times, 02342 and replace the matched parts through filling a format C-string. 02343 * @param __out [OUT] The output iterator. 02344 * @param __first [IN] The start of the string to search. 02345 * @param __last [IN] One-past-the-end of the string to search. 02346 * @param __e [IN] The regular expression to search for. 02347 * @param __fmt [IN] The format C-string. 02348 * @param __flags [IN] Search and replace policy flags. 02349 * 02350 * @returns __out 02351 * @throws an exception of type regex_error. 02352 */ 02353 template<typename _Out_iter, typename _Bi_iter, 02354 typename _Rx_traits, typename _Ch_type> 02355 _Out_iter 02356 regex_replace(_Out_iter __out, _Bi_iter __first, _Bi_iter __last, 02357 const basic_regex<_Ch_type, _Rx_traits>& __e, 02358 const _Ch_type* __fmt, 02359 regex_constants::match_flag_type __flags 02360 = regex_constants::match_default); 02361 02362 /** 02363 * @brief Search for a regular expression within a string for multiple times, 02364 and replace the matched parts through filling a format string. 02365 * @param __s [IN] The string to search and replace. 02366 * @param __e [IN] The regular expression to search for. 02367 * @param __fmt [IN] The format string. 02368 * @param __flags [IN] Search and replace policy flags. 02369 * 02370 * @returns The string after replacing. 02371 * @throws an exception of type regex_error. 02372 */ 02373 template<typename _Rx_traits, typename _Ch_type, 02374 typename _St, typename _Sa, typename _Fst, typename _Fsa> 02375 inline basic_string<_Ch_type, _St, _Sa> 02376 regex_replace(const basic_string<_Ch_type, _St, _Sa>& __s, 02377 const basic_regex<_Ch_type, _Rx_traits>& __e, 02378 const basic_string<_Ch_type, _Fst, _Fsa>& __fmt, 02379 regex_constants::match_flag_type __flags 02380 = regex_constants::match_default) 02381 { 02382 basic_string<_Ch_type, _St, _Sa> __result; 02383 regex_replace(std::back_inserter(__result), 02384 __s.begin(), __s.end(), __e, __fmt, __flags); 02385 return __result; 02386 } 02387 02388 /** 02389 * @brief Search for a regular expression within a string for multiple times, 02390 and replace the matched parts through filling a format C-string. 02391 * @param __s [IN] The string to search and replace. 02392 * @param __e [IN] The regular expression to search for. 02393 * @param __fmt [IN] The format C-string. 02394 * @param __flags [IN] Search and replace policy flags. 02395 * 02396 * @returns The string after replacing. 02397 * @throws an exception of type regex_error. 02398 */ 02399 template<typename _Rx_traits, typename _Ch_type, 02400 typename _St, typename _Sa> 02401 inline basic_string<_Ch_type, _St, _Sa> 02402 regex_replace(const basic_string<_Ch_type, _St, _Sa>& __s, 02403 const basic_regex<_Ch_type, _Rx_traits>& __e, 02404 const _Ch_type* __fmt, 02405 regex_constants::match_flag_type __flags 02406 = regex_constants::match_default) 02407 { 02408 basic_string<_Ch_type, _St, _Sa> __result; 02409 regex_replace(std::back_inserter(__result), 02410 __s.begin(), __s.end(), __e, __fmt, __flags); 02411 return __result; 02412 } 02413 02414 /** 02415 * @brief Search for a regular expression within a C-string for multiple 02416 times, and replace the matched parts through filling a format string. 02417 * @param __s [IN] The C-string to search and replace. 02418 * @param __e [IN] The regular expression to search for. 02419 * @param __fmt [IN] The format string. 02420 * @param __flags [IN] Search and replace policy flags. 02421 * 02422 * @returns The string after replacing. 02423 * @throws an exception of type regex_error. 02424 */ 02425 template<typename _Rx_traits, typename _Ch_type, 02426 typename _St, typename _Sa> 02427 inline basic_string<_Ch_type> 02428 regex_replace(const _Ch_type* __s, 02429 const basic_regex<_Ch_type, _Rx_traits>& __e, 02430 const basic_string<_Ch_type, _St, _Sa>& __fmt, 02431 regex_constants::match_flag_type __flags 02432 = regex_constants::match_default) 02433 { 02434 basic_string<_Ch_type> __result; 02435 regex_replace(std::back_inserter(__result), __s, 02436 __s + char_traits<_Ch_type>::length(__s), 02437 __e, __fmt, __flags); 02438 return __result; 02439 } 02440 02441 /** 02442 * @brief Search for a regular expression within a C-string for multiple 02443 times, and replace the matched parts through filling a format C-string. 02444 * @param __s [IN] The C-string to search and replace. 02445 * @param __e [IN] The regular expression to search for. 02446 * @param __fmt [IN] The format C-string. 02447 * @param __flags [IN] Search and replace policy flags. 02448 * 02449 * @returns The string after replacing. 02450 * @throws an exception of type regex_error. 02451 */ 02452 template<typename _Rx_traits, typename _Ch_type> 02453 inline basic_string<_Ch_type> 02454 regex_replace(const _Ch_type* __s, 02455 const basic_regex<_Ch_type, _Rx_traits>& __e, 02456 const _Ch_type* __fmt, 02457 regex_constants::match_flag_type __flags 02458 = regex_constants::match_default) 02459 { 02460 basic_string<_Ch_type> __result; 02461 regex_replace(std::back_inserter(__result), __s, 02462 __s + char_traits<_Ch_type>::length(__s), 02463 __e, __fmt, __flags); 02464 return __result; 02465 } 02466 02467 //@} 02468 02469 _GLIBCXX_BEGIN_NAMESPACE_CXX11 02470 02471 // std [28.12] Class template regex_iterator 02472 /** 02473 * An iterator adaptor that will provide repeated calls of regex_search over 02474 * a range until no more matches remain. 02475 */ 02476 template<typename _Bi_iter, 02477 typename _Ch_type = typename iterator_traits<_Bi_iter>::value_type, 02478 typename _Rx_traits = regex_traits<_Ch_type> > 02479 class regex_iterator 02480 { 02481 public: 02482 typedef basic_regex<_Ch_type, _Rx_traits> regex_type; 02483 typedef match_results<_Bi_iter> value_type; 02484 typedef std::ptrdiff_t difference_type; 02485 typedef const value_type* pointer; 02486 typedef const value_type& reference; 02487 typedef std::forward_iterator_tag iterator_category; 02488 02489 /** 02490 * @brief Provides a singular iterator, useful for indicating 02491 * one-past-the-end of a range. 02492 */ 02493 regex_iterator() 02494 : _M_pregex() 02495 { } 02496 02497 /** 02498 * Constructs a %regex_iterator... 02499 * @param __a [IN] The start of a text range to search. 02500 * @param __b [IN] One-past-the-end of the text range to search. 02501 * @param __re [IN] The regular expression to match. 02502 * @param __m [IN] Policy flags for match rules. 02503 */ 02504 regex_iterator(_Bi_iter __a, _Bi_iter __b, const regex_type& __re, 02505 regex_constants::match_flag_type __m 02506 = regex_constants::match_default) 02507 : _M_begin(__a), _M_end(__b), _M_pregex(&__re), _M_flags(__m), _M_match() 02508 { 02509 if (!regex_search(_M_begin, _M_end, _M_match, *_M_pregex, _M_flags)) 02510 *this = regex_iterator(); 02511 } 02512 02513 // _GLIBCXX_RESOLVE_LIB_DEFECTS 02514 // 2332. regex_iterator should forbid temporary regexes 02515 regex_iterator(_Bi_iter, _Bi_iter, const regex_type&&, 02516 regex_constants::match_flag_type 02517 = regex_constants::match_default) = delete; 02518 /** 02519 * Copy constructs a %regex_iterator. 02520 */ 02521 regex_iterator(const regex_iterator& __rhs) = default; 02522 02523 /** 02524 * @brief Assigns one %regex_iterator to another. 02525 */ 02526 regex_iterator& 02527 operator=(const regex_iterator& __rhs) = default; 02528 02529 /** 02530 * @brief Tests the equivalence of two regex iterators. 02531 */ 02532 bool 02533 operator==(const regex_iterator& __rhs) const; 02534 02535 /** 02536 * @brief Tests the inequivalence of two regex iterators. 02537 */ 02538 bool 02539 operator!=(const regex_iterator& __rhs) const 02540 { return !(*this == __rhs); } 02541 02542 /** 02543 * @brief Dereferences a %regex_iterator. 02544 */ 02545 const value_type& 02546 operator*() const 02547 { return _M_match; } 02548 02549 /** 02550 * @brief Selects a %regex_iterator member. 02551 */ 02552 const value_type* 02553 operator->() const 02554 { return &_M_match; } 02555 02556 /** 02557 * @brief Increments a %regex_iterator. 02558 */ 02559 regex_iterator& 02560 operator++(); 02561 02562 /** 02563 * @brief Postincrements a %regex_iterator. 02564 */ 02565 regex_iterator 02566 operator++(int) 02567 { 02568 auto __tmp = *this; 02569 ++(*this); 02570 return __tmp; 02571 } 02572 02573 private: 02574 _Bi_iter _M_begin; 02575 _Bi_iter _M_end; 02576 const regex_type* _M_pregex; 02577 regex_constants::match_flag_type _M_flags; 02578 match_results<_Bi_iter> _M_match; 02579 }; 02580 02581 typedef regex_iterator<const char*> cregex_iterator; 02582 typedef regex_iterator<string::const_iterator> sregex_iterator; 02583 #ifdef _GLIBCXX_USE_WCHAR_T 02584 typedef regex_iterator<const wchar_t*> wcregex_iterator; 02585 typedef regex_iterator<wstring::const_iterator> wsregex_iterator; 02586 #endif 02587 02588 // [7.12.2] Class template regex_token_iterator 02589 /** 02590 * Iterates over submatches in a range (or @a splits a text string). 02591 * 02592 * The purpose of this iterator is to enumerate all, or all specified, 02593 * matches of a regular expression within a text range. The dereferenced 02594 * value of an iterator of this class is a std::sub_match object. 02595 */ 02596 template<typename _Bi_iter, 02597 typename _Ch_type = typename iterator_traits<_Bi_iter>::value_type, 02598 typename _Rx_traits = regex_traits<_Ch_type> > 02599 class regex_token_iterator 02600 { 02601 public: 02602 typedef basic_regex<_Ch_type, _Rx_traits> regex_type; 02603 typedef sub_match<_Bi_iter> value_type; 02604 typedef std::ptrdiff_t difference_type; 02605 typedef const value_type* pointer; 02606 typedef const value_type& reference; 02607 typedef std::forward_iterator_tag iterator_category; 02608 02609 public: 02610 /** 02611 * @brief Default constructs a %regex_token_iterator. 02612 * 02613 * A default-constructed %regex_token_iterator is a singular iterator 02614 * that will compare equal to the one-past-the-end value for any 02615 * iterator of the same type. 02616 */ 02617 regex_token_iterator() 02618 : _M_position(), _M_subs(), _M_suffix(), _M_n(0), _M_result(nullptr), 02619 _M_has_m1(false) 02620 { } 02621 02622 /** 02623 * Constructs a %regex_token_iterator... 02624 * @param __a [IN] The start of the text to search. 02625 * @param __b [IN] One-past-the-end of the text to search. 02626 * @param __re [IN] The regular expression to search for. 02627 * @param __submatch [IN] Which submatch to return. There are some 02628 * special values for this parameter: 02629 * - -1 each enumerated subexpression does NOT 02630 * match the regular expression (aka field 02631 * splitting) 02632 * - 0 the entire string matching the 02633 * subexpression is returned for each match 02634 * within the text. 02635 * - >0 enumerates only the indicated 02636 * subexpression from a match within the text. 02637 * @param __m [IN] Policy flags for match rules. 02638 */ 02639 regex_token_iterator(_Bi_iter __a, _Bi_iter __b, const regex_type& __re, 02640 int __submatch = 0, 02641 regex_constants::match_flag_type __m 02642 = regex_constants::match_default) 02643 : _M_position(__a, __b, __re, __m), _M_subs(1, __submatch), _M_n(0) 02644 { _M_init(__a, __b); } 02645 02646 /** 02647 * Constructs a %regex_token_iterator... 02648 * @param __a [IN] The start of the text to search. 02649 * @param __b [IN] One-past-the-end of the text to search. 02650 * @param __re [IN] The regular expression to search for. 02651 * @param __submatches [IN] A list of subexpressions to return for each 02652 * regular expression match within the text. 02653 * @param __m [IN] Policy flags for match rules. 02654 */ 02655 regex_token_iterator(_Bi_iter __a, _Bi_iter __b, 02656 const regex_type& __re, 02657 const std::vector<int>& __submatches, 02658 regex_constants::match_flag_type __m 02659 = regex_constants::match_default) 02660 : _M_position(__a, __b, __re, __m), _M_subs(__submatches), _M_n(0) 02661 { _M_init(__a, __b); } 02662 02663 /** 02664 * Constructs a %regex_token_iterator... 02665 * @param __a [IN] The start of the text to search. 02666 * @param __b [IN] One-past-the-end of the text to search. 02667 * @param __re [IN] The regular expression to search for. 02668 * @param __submatches [IN] A list of subexpressions to return for each 02669 * regular expression match within the text. 02670 * @param __m [IN] Policy flags for match rules. 02671 */ 02672 regex_token_iterator(_Bi_iter __a, _Bi_iter __b, 02673 const regex_type& __re, 02674 initializer_list<int> __submatches, 02675 regex_constants::match_flag_type __m 02676 = regex_constants::match_default) 02677 : _M_position(__a, __b, __re, __m), _M_subs(__submatches), _M_n(0) 02678 { _M_init(__a, __b); } 02679 02680 /** 02681 * Constructs a %regex_token_iterator... 02682 * @param __a [IN] The start of the text to search. 02683 * @param __b [IN] One-past-the-end of the text to search. 02684 * @param __re [IN] The regular expression to search for. 02685 * @param __submatches [IN] A list of subexpressions to return for each 02686 * regular expression match within the text. 02687 * @param __m [IN] Policy flags for match rules. 02688 */ 02689 template<std::size_t _Nm> 02690 regex_token_iterator(_Bi_iter __a, _Bi_iter __b, 02691 const regex_type& __re, 02692 const int (&__submatches)[_Nm], 02693 regex_constants::match_flag_type __m 02694 = regex_constants::match_default) 02695 : _M_position(__a, __b, __re, __m), 02696 _M_subs(__submatches, __submatches + _Nm), _M_n(0) 02697 { _M_init(__a, __b); } 02698 02699 // _GLIBCXX_RESOLVE_LIB_DEFECTS 02700 // 2332. regex_token_iterator should forbid temporary regexes 02701 regex_token_iterator(_Bi_iter, _Bi_iter, const regex_type&&, int = 0, 02702 regex_constants::match_flag_type = 02703 regex_constants::match_default) = delete; 02704 regex_token_iterator(_Bi_iter, _Bi_iter, const regex_type&&, 02705 const std::vector<int>&, 02706 regex_constants::match_flag_type = 02707 regex_constants::match_default) = delete; 02708 regex_token_iterator(_Bi_iter, _Bi_iter, const regex_type&&, 02709 initializer_list<int>, 02710 regex_constants::match_flag_type = 02711 regex_constants::match_default) = delete; 02712 template <std::size_t _Nm> 02713 regex_token_iterator(_Bi_iter, _Bi_iter, const regex_type&&, 02714 const int (&)[_Nm], 02715 regex_constants::match_flag_type = 02716 regex_constants::match_default) = delete; 02717 02718 /** 02719 * @brief Copy constructs a %regex_token_iterator. 02720 * @param __rhs [IN] A %regex_token_iterator to copy. 02721 */ 02722 regex_token_iterator(const regex_token_iterator& __rhs) 02723 : _M_position(__rhs._M_position), _M_subs(__rhs._M_subs), 02724 _M_suffix(__rhs._M_suffix), _M_n(__rhs._M_n), _M_has_m1(__rhs._M_has_m1) 02725 { _M_normalize_result(); } 02726 02727 /** 02728 * @brief Assigns a %regex_token_iterator to another. 02729 * @param __rhs [IN] A %regex_token_iterator to copy. 02730 */ 02731 regex_token_iterator& 02732 operator=(const regex_token_iterator& __rhs); 02733 02734 /** 02735 * @brief Compares a %regex_token_iterator to another for equality. 02736 */ 02737 bool 02738 operator==(const regex_token_iterator& __rhs) const; 02739 02740 /** 02741 * @brief Compares a %regex_token_iterator to another for inequality. 02742 */ 02743 bool 02744 operator!=(const regex_token_iterator& __rhs) const 02745 { return !(*this == __rhs); } 02746 02747 /** 02748 * @brief Dereferences a %regex_token_iterator. 02749 */ 02750 const value_type& 02751 operator*() const 02752 { return *_M_result; } 02753 02754 /** 02755 * @brief Selects a %regex_token_iterator member. 02756 */ 02757 const value_type* 02758 operator->() const 02759 { return _M_result; } 02760 02761 /** 02762 * @brief Increments a %regex_token_iterator. 02763 */ 02764 regex_token_iterator& 02765 operator++(); 02766 02767 /** 02768 * @brief Postincrements a %regex_token_iterator. 02769 */ 02770 regex_token_iterator 02771 operator++(int) 02772 { 02773 auto __tmp = *this; 02774 ++(*this); 02775 return __tmp; 02776 } 02777 02778 private: 02779 typedef regex_iterator<_Bi_iter, _Ch_type, _Rx_traits> _Position; 02780 02781 void 02782 _M_init(_Bi_iter __a, _Bi_iter __b); 02783 02784 const value_type& 02785 _M_current_match() const 02786 { 02787 if (_M_subs[_M_n] == -1) 02788 return (*_M_position).prefix(); 02789 else 02790 return (*_M_position)[_M_subs[_M_n]]; 02791 } 02792 02793 constexpr bool 02794 _M_end_of_seq() const 02795 { return _M_result == nullptr; } 02796 02797 // [28.12.2.2.4] 02798 void 02799 _M_normalize_result() 02800 { 02801 if (_M_position != _Position()) 02802 _M_result = &_M_current_match(); 02803 else if (_M_has_m1) 02804 _M_result = &_M_suffix; 02805 else 02806 _M_result = nullptr; 02807 } 02808 02809 _Position _M_position; 02810 std::vector<int> _M_subs; 02811 value_type _M_suffix; 02812 std::size_t _M_n; 02813 const value_type* _M_result; 02814 02815 // Show whether _M_subs contains -1 02816 bool _M_has_m1; 02817 }; 02818 02819 /** @brief Token iterator for C-style NULL-terminated strings. */ 02820 typedef regex_token_iterator<const char*> cregex_token_iterator; 02821 02822 /** @brief Token iterator for standard strings. */ 02823 typedef regex_token_iterator<string::const_iterator> sregex_token_iterator; 02824 02825 #ifdef _GLIBCXX_USE_WCHAR_T 02826 /** @brief Token iterator for C-style NULL-terminated wide strings. */ 02827 typedef regex_token_iterator<const wchar_t*> wcregex_token_iterator; 02828 02829 /** @brief Token iterator for standard wide-character strings. */ 02830 typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator; 02831 #endif 02832 02833 //@} // group regex 02834 02835 _GLIBCXX_END_NAMESPACE_CXX11 02836 _GLIBCXX_END_NAMESPACE_VERSION 02837 } // namespace 02838 02839 #include <bits/regex.tcc>