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