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