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