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