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