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