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 & (ECMAScript | basic | extended | awk | grep | egrep))
766  ? __f : (__f | ECMAScript)),
767  _M_loc(std::move(__loc)),
768  _M_automaton(__detail::__compile_nfa<_FwdIter, _Rx_traits>(
769  std::move(__first), std::move(__last), _M_loc, _M_flags))
770  { }
771 
772  template<typename _Bp, typename _Ap, typename _Cp, typename _Rp,
773  __detail::_RegexExecutorPolicy, bool>
774  friend bool __detail::
775 #if _GLIBCXX_INLINE_VERSION
776  __7:: // Required due to PR c++/59256
777 #endif
778  __regex_algo_impl(_Bp, _Bp, match_results<_Bp, _Ap>&,
779  const basic_regex<_Cp, _Rp>&,
781 
782  template<typename, typename, typename, bool>
783  friend class __detail::_Executor;
784 
785  flag_type _M_flags;
786  locale_type _M_loc;
787  _AutomatonPtr _M_automaton;
788  };
789 
790  /** @brief Standard regular expressions. */
792 
793 #ifdef _GLIBCXX_USE_WCHAR_T
794  /** @brief Standard wide-character regular expressions. */
796 #endif
797 
798 
799  // [7.8.6] basic_regex swap
800  /**
801  * @brief Swaps the contents of two regular expression objects.
802  * @param __lhs First regular expression.
803  * @param __rhs Second regular expression.
804  */
805  template<typename _Ch_type, typename _Rx_traits>
806  inline void
809  { __lhs.swap(__rhs); }
810 
811 
812  // [7.9] Class template sub_match
813  /**
814  * A sequence of characters matched by a particular marked sub-expression.
815  *
816  * An object of this class is essentially a pair of iterators marking a
817  * matched subexpression within a regular expression pattern match. Such
818  * objects can be converted to and compared with std::basic_string objects
819  * of a similar base character type as the pattern matched by the regular
820  * expression.
821  *
822  * The iterators that make up the pair are the usual half-open interval
823  * referencing the actual original pattern matched.
824  */
825  template<typename _BiIter>
826  class sub_match : public std::pair<_BiIter, _BiIter>
827  {
828  typedef iterator_traits<_BiIter> __iter_traits;
829 
830  public:
831  typedef typename __iter_traits::value_type value_type;
832  typedef typename __iter_traits::difference_type difference_type;
833  typedef _BiIter iterator;
835 
836  bool matched;
837 
838  constexpr sub_match() : matched() { }
839 
840  /**
841  * Gets the length of the matching sequence.
842  */
843  difference_type
844  length() const
845  { return this->matched ? std::distance(this->first, this->second) : 0; }
846 
847  /**
848  * @brief Gets the matching sequence as a string.
849  *
850  * @returns the matching sequence as a string.
851  *
852  * This is the implicit conversion operator. It is identical to the
853  * str() member function except that it will want to pop up in
854  * unexpected places and cause a great deal of confusion and cursing
855  * from the unwary.
856  */
857  operator string_type() const
858  {
859  return this->matched
860  ? string_type(this->first, this->second)
861  : string_type();
862  }
863 
864  /**
865  * @brief Gets the matching sequence as a string.
866  *
867  * @returns the matching sequence as a string.
868  */
869  string_type
870  str() const
871  {
872  return this->matched
873  ? string_type(this->first, this->second)
874  : string_type();
875  }
876 
877  /**
878  * @brief Compares this and another matched sequence.
879  *
880  * @param __s Another matched sequence to compare to this one.
881  *
882  * @retval <0 this matched sequence will collate before @p __s.
883  * @retval =0 this matched sequence is equivalent to @p __s.
884  * @retval <0 this matched sequence will collate after @p __s.
885  */
886  int
887  compare(const sub_match& __s) const
888  { return this->str().compare(__s.str()); }
889 
890  /**
891  * @brief Compares this sub_match to a string.
892  *
893  * @param __s A string to compare to this sub_match.
894  *
895  * @retval <0 this matched sequence will collate before @p __s.
896  * @retval =0 this matched sequence is equivalent to @p __s.
897  * @retval <0 this matched sequence will collate after @p __s.
898  */
899  int
900  compare(const string_type& __s) const
901  { return this->str().compare(__s); }
902 
903  /**
904  * @brief Compares this sub_match to a C-style string.
905  *
906  * @param __s A C-style string to compare to this sub_match.
907  *
908  * @retval <0 this matched sequence will collate before @p __s.
909  * @retval =0 this matched sequence is equivalent to @p __s.
910  * @retval <0 this matched sequence will collate after @p __s.
911  */
912  int
913  compare(const value_type* __s) const
914  { return this->str().compare(__s); }
915  };
916 
917 
918  /** @brief Standard regex submatch over a C-style null-terminated string. */
920 
921  /** @brief Standard regex submatch over a standard string. */
923 
924 #ifdef _GLIBCXX_USE_WCHAR_T
925  /** @brief Regex submatch over a C-style null-terminated wide string. */
927 
928  /** @brief Regex submatch over a standard wide string. */
930 #endif
931 
932  // [7.9.2] sub_match non-member operators
933 
934  /**
935  * @brief Tests the equivalence of two regular expression submatches.
936  * @param __lhs First regular expression submatch.
937  * @param __rhs Second regular expression submatch.
938  * @returns true if @a __lhs is equivalent to @a __rhs, false otherwise.
939  */
940  template<typename _BiIter>
941  inline bool
942  operator==(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs)
943  { return __lhs.compare(__rhs) == 0; }
944 
945  /**
946  * @brief Tests the inequivalence of two regular expression submatches.
947  * @param __lhs First regular expression submatch.
948  * @param __rhs Second regular expression submatch.
949  * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise.
950  */
951  template<typename _BiIter>
952  inline bool
953  operator!=(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs)
954  { return __lhs.compare(__rhs) != 0; }
955 
956  /**
957  * @brief Tests the ordering of two regular expression submatches.
958  * @param __lhs First regular expression submatch.
959  * @param __rhs Second regular expression submatch.
960  * @returns true if @a __lhs precedes @a __rhs, false otherwise.
961  */
962  template<typename _BiIter>
963  inline bool
964  operator<(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs)
965  { return __lhs.compare(__rhs) < 0; }
966 
967  /**
968  * @brief Tests the ordering of two regular expression submatches.
969  * @param __lhs First regular expression submatch.
970  * @param __rhs Second regular expression submatch.
971  * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
972  */
973  template<typename _BiIter>
974  inline bool
975  operator<=(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs)
976  { return __lhs.compare(__rhs) <= 0; }
977 
978  /**
979  * @brief Tests the ordering of two regular expression submatches.
980  * @param __lhs First regular expression submatch.
981  * @param __rhs Second regular expression submatch.
982  * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
983  */
984  template<typename _BiIter>
985  inline bool
986  operator>=(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs)
987  { return __lhs.compare(__rhs) >= 0; }
988 
989  /**
990  * @brief Tests the ordering of two regular expression submatches.
991  * @param __lhs First regular expression submatch.
992  * @param __rhs Second regular expression submatch.
993  * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
994  */
995  template<typename _BiIter>
996  inline bool
997  operator>(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs)
998  { return __lhs.compare(__rhs) > 0; }
999 
1000  // Alias for sub_match'd string.
1001  template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1003  typename iterator_traits<_Bi_iter>::value_type,
1004  _Ch_traits, _Ch_alloc>;
1005 
1006  /**
1007  * @brief Tests the equivalence of a string and a regular expression
1008  * submatch.
1009  * @param __lhs A string.
1010  * @param __rhs A regular expression submatch.
1011  * @returns true if @a __lhs is equivalent to @a __rhs, false otherwise.
1012  */
1013  template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1014  inline bool
1016  const sub_match<_Bi_iter>& __rhs)
1017  {
1018  typedef typename sub_match<_Bi_iter>::string_type string_type;
1019  return __rhs.compare(string_type(__lhs.data(), __lhs.size())) == 0;
1020  }
1021 
1022  /**
1023  * @brief Tests the inequivalence of a string and a regular expression
1024  * submatch.
1025  * @param __lhs A string.
1026  * @param __rhs A regular expression submatch.
1027  * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise.
1028  */
1029  template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1030  inline bool
1032  const sub_match<_Bi_iter>& __rhs)
1033  { return !(__lhs == __rhs); }
1034 
1035  /**
1036  * @brief Tests the ordering of a string and a regular expression submatch.
1037  * @param __lhs A string.
1038  * @param __rhs A regular expression submatch.
1039  * @returns true if @a __lhs precedes @a __rhs, false otherwise.
1040  */
1041  template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1042  inline bool
1043  operator<(const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __lhs,
1044  const sub_match<_Bi_iter>& __rhs)
1045  {
1046  typedef typename sub_match<_Bi_iter>::string_type string_type;
1047  return __rhs.compare(string_type(__lhs.data(), __lhs.size())) > 0;
1048  }
1049 
1050  /**
1051  * @brief Tests the ordering of a string and a regular expression submatch.
1052  * @param __lhs A string.
1053  * @param __rhs A regular expression submatch.
1054  * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
1055  */
1056  template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1057  inline bool
1059  const sub_match<_Bi_iter>& __rhs)
1060  { return __rhs < __lhs; }
1061 
1062  /**
1063  * @brief Tests the ordering of a string and a regular expression submatch.
1064  * @param __lhs A string.
1065  * @param __rhs A regular expression submatch.
1066  * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
1067  */
1068  template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1069  inline bool
1071  const sub_match<_Bi_iter>& __rhs)
1072  { return !(__lhs < __rhs); }
1073 
1074  /**
1075  * @brief Tests the ordering of a string and a regular expression submatch.
1076  * @param __lhs A string.
1077  * @param __rhs A regular expression submatch.
1078  * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
1079  */
1080  template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1081  inline bool
1082  operator<=(const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __lhs,
1083  const sub_match<_Bi_iter>& __rhs)
1084  { return !(__rhs < __lhs); }
1085 
1086  /**
1087  * @brief Tests the equivalence of a regular expression submatch and a
1088  * string.
1089  * @param __lhs A regular expression submatch.
1090  * @param __rhs A string.
1091  * @returns true if @a __lhs is equivalent to @a __rhs, false otherwise.
1092  */
1093  template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1094  inline bool
1095  operator==(const sub_match<_Bi_iter>& __lhs,
1097  {
1098  typedef typename sub_match<_Bi_iter>::string_type string_type;
1099  return __lhs.compare(string_type(__rhs.data(), __rhs.size())) == 0;
1100  }
1101 
1102  /**
1103  * @brief Tests the inequivalence of a regular expression submatch and a
1104  * string.
1105  * @param __lhs A regular expression submatch.
1106  * @param __rhs A string.
1107  * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise.
1108  */
1109  template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1110  inline bool
1111  operator!=(const sub_match<_Bi_iter>& __lhs,
1113  { return !(__lhs == __rhs); }
1114 
1115  /**
1116  * @brief Tests the ordering of a regular expression submatch and a string.
1117  * @param __lhs A regular expression submatch.
1118  * @param __rhs A string.
1119  * @returns true if @a __lhs precedes @a __rhs, false otherwise.
1120  */
1121  template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc>
1122  inline bool
1123  operator<(const sub_match<_Bi_iter>& __lhs,
1125  {
1126  typedef typename sub_match<_Bi_iter>::string_type string_type;
1127  return __lhs.compare(string_type(__rhs.data(), __rhs.size())) < 0;
1128  }
1129 
1130  /**
1131  * @brief Tests the ordering of a regular expression submatch and a string.
1132  * @param __lhs A regular expression submatch.
1133  * @param __rhs A string.
1134  * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
1135  */
1136  template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc>
1137  inline bool
1138  operator>(const sub_match<_Bi_iter>& __lhs,
1140  { return __rhs < __lhs; }
1141 
1142  /**
1143  * @brief Tests the ordering of a regular expression submatch and a string.
1144  * @param __lhs A regular expression submatch.
1145  * @param __rhs A string.
1146  * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
1147  */
1148  template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc>
1149  inline bool
1150  operator>=(const sub_match<_Bi_iter>& __lhs,
1152  { return !(__lhs < __rhs); }
1153 
1154  /**
1155  * @brief Tests the ordering of a regular expression submatch and a string.
1156  * @param __lhs A regular expression submatch.
1157  * @param __rhs A string.
1158  * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
1159  */
1160  template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc>
1161  inline bool
1162  operator<=(const sub_match<_Bi_iter>& __lhs,
1164  { return !(__rhs < __lhs); }
1165 
1166  /**
1167  * @brief Tests the equivalence of a C string and a regular expression
1168  * submatch.
1169  * @param __lhs A C string.
1170  * @param __rhs A regular expression submatch.
1171  * @returns true if @a __lhs is equivalent to @a __rhs, false otherwise.
1172  */
1173  template<typename _Bi_iter>
1174  inline bool
1175  operator==(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
1176  const sub_match<_Bi_iter>& __rhs)
1177  { return __rhs.compare(__lhs) == 0; }
1178 
1179  /**
1180  * @brief Tests the inequivalence of an iterator value and a regular
1181  * expression submatch.
1182  * @param __lhs A regular expression submatch.
1183  * @param __rhs A string.
1184  * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise.
1185  */
1186  template<typename _Bi_iter>
1187  inline bool
1188  operator!=(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
1189  const sub_match<_Bi_iter>& __rhs)
1190  { return !(__lhs == __rhs); }
1191 
1192  /**
1193  * @brief Tests the ordering of a string and a regular expression submatch.
1194  * @param __lhs A string.
1195  * @param __rhs A regular expression submatch.
1196  * @returns true if @a __lhs precedes @a __rhs, false otherwise.
1197  */
1198  template<typename _Bi_iter>
1199  inline bool
1200  operator<(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
1201  const sub_match<_Bi_iter>& __rhs)
1202  { return __rhs.compare(__lhs) > 0; }
1203 
1204  /**
1205  * @brief Tests the ordering of a string and a regular expression submatch.
1206  * @param __lhs A string.
1207  * @param __rhs A regular expression submatch.
1208  * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
1209  */
1210  template<typename _Bi_iter>
1211  inline bool
1212  operator>(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
1213  const sub_match<_Bi_iter>& __rhs)
1214  { return __rhs < __lhs; }
1215 
1216  /**
1217  * @brief Tests the ordering of a string and a regular expression submatch.
1218  * @param __lhs A string.
1219  * @param __rhs A regular expression submatch.
1220  * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
1221  */
1222  template<typename _Bi_iter>
1223  inline bool
1224  operator>=(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
1225  const sub_match<_Bi_iter>& __rhs)
1226  { return !(__lhs < __rhs); }
1227 
1228  /**
1229  * @brief Tests the ordering of a string and a regular expression submatch.
1230  * @param __lhs A string.
1231  * @param __rhs A regular expression submatch.
1232  * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
1233  */
1234  template<typename _Bi_iter>
1235  inline bool
1236  operator<=(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
1237  const sub_match<_Bi_iter>& __rhs)
1238  { return !(__rhs < __lhs); }
1239 
1240  /**
1241  * @brief Tests the equivalence of a regular expression submatch and a
1242  * string.
1243  * @param __lhs A regular expression submatch.
1244  * @param __rhs A pointer to a string?
1245  * @returns true if @a __lhs is equivalent to @a __rhs, false otherwise.
1246  */
1247  template<typename _Bi_iter>
1248  inline bool
1249  operator==(const sub_match<_Bi_iter>& __lhs,
1250  typename iterator_traits<_Bi_iter>::value_type const* __rhs)
1251  { return __lhs.compare(__rhs) == 0; }
1252 
1253  /**
1254  * @brief Tests the inequivalence of a regular expression submatch and a
1255  * string.
1256  * @param __lhs A regular expression submatch.
1257  * @param __rhs A pointer to a string.
1258  * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise.
1259  */
1260  template<typename _Bi_iter>
1261  inline bool
1262  operator!=(const sub_match<_Bi_iter>& __lhs,
1263  typename iterator_traits<_Bi_iter>::value_type const* __rhs)
1264  { return !(__lhs == __rhs); }
1265 
1266  /**
1267  * @brief Tests the ordering of a regular expression submatch and a string.
1268  * @param __lhs A regular expression submatch.
1269  * @param __rhs A string.
1270  * @returns true if @a __lhs precedes @a __rhs, false otherwise.
1271  */
1272  template<typename _Bi_iter>
1273  inline bool
1274  operator<(const sub_match<_Bi_iter>& __lhs,
1275  typename iterator_traits<_Bi_iter>::value_type const* __rhs)
1276  { return __lhs.compare(__rhs) < 0; }
1277 
1278  /**
1279  * @brief Tests the ordering of a regular expression submatch and a string.
1280  * @param __lhs A regular expression submatch.
1281  * @param __rhs A string.
1282  * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
1283  */
1284  template<typename _Bi_iter>
1285  inline bool
1286  operator>(const sub_match<_Bi_iter>& __lhs,
1287  typename iterator_traits<_Bi_iter>::value_type const* __rhs)
1288  { return __rhs < __lhs; }
1289 
1290  /**
1291  * @brief Tests the ordering of a regular expression submatch and a string.
1292  * @param __lhs A regular expression submatch.
1293  * @param __rhs A string.
1294  * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
1295  */
1296  template<typename _Bi_iter>
1297  inline bool
1298  operator>=(const sub_match<_Bi_iter>& __lhs,
1299  typename iterator_traits<_Bi_iter>::value_type const* __rhs)
1300  { return !(__lhs < __rhs); }
1301 
1302  /**
1303  * @brief Tests the ordering of a regular expression submatch and a string.
1304  * @param __lhs A regular expression submatch.
1305  * @param __rhs A string.
1306  * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
1307  */
1308  template<typename _Bi_iter>
1309  inline bool
1310  operator<=(const sub_match<_Bi_iter>& __lhs,
1311  typename iterator_traits<_Bi_iter>::value_type const* __rhs)
1312  { return !(__rhs < __lhs); }
1313 
1314  /**
1315  * @brief Tests the equivalence of a string and a regular expression
1316  * submatch.
1317  * @param __lhs A string.
1318  * @param __rhs A regular expression submatch.
1319  * @returns true if @a __lhs is equivalent to @a __rhs, false otherwise.
1320  */
1321  template<typename _Bi_iter>
1322  inline bool
1323  operator==(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
1324  const sub_match<_Bi_iter>& __rhs)
1325  {
1326  typedef typename sub_match<_Bi_iter>::string_type string_type;
1327  return __rhs.compare(string_type(1, __lhs)) == 0;
1328  }
1329 
1330  /**
1331  * @brief Tests the inequivalence of a string and a regular expression
1332  * submatch.
1333  * @param __lhs A string.
1334  * @param __rhs A regular expression submatch.
1335  * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise.
1336  */
1337  template<typename _Bi_iter>
1338  inline bool
1339  operator!=(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
1340  const sub_match<_Bi_iter>& __rhs)
1341  { return !(__lhs == __rhs); }
1342 
1343  /**
1344  * @brief Tests the ordering of a string and a regular expression submatch.
1345  * @param __lhs A string.
1346  * @param __rhs A regular expression submatch.
1347  * @returns true if @a __lhs precedes @a __rhs, false otherwise.
1348  */
1349  template<typename _Bi_iter>
1350  inline bool
1351  operator<(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
1352  const sub_match<_Bi_iter>& __rhs)
1353  {
1354  typedef typename sub_match<_Bi_iter>::string_type string_type;
1355  return __rhs.compare(string_type(1, __lhs)) > 0;
1356  }
1357 
1358  /**
1359  * @brief Tests the ordering of a string and a regular expression submatch.
1360  * @param __lhs A string.
1361  * @param __rhs A regular expression submatch.
1362  * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
1363  */
1364  template<typename _Bi_iter>
1365  inline bool
1366  operator>(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
1367  const sub_match<_Bi_iter>& __rhs)
1368  { return __rhs < __lhs; }
1369 
1370  /**
1371  * @brief Tests the ordering of a string and a regular expression submatch.
1372  * @param __lhs A string.
1373  * @param __rhs A regular expression submatch.
1374  * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
1375  */
1376  template<typename _Bi_iter>
1377  inline bool
1378  operator>=(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
1379  const sub_match<_Bi_iter>& __rhs)
1380  { return !(__lhs < __rhs); }
1381 
1382  /**
1383  * @brief Tests the ordering of a string and a regular expression submatch.
1384  * @param __lhs A string.
1385  * @param __rhs A regular expression submatch.
1386  * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
1387  */
1388  template<typename _Bi_iter>
1389  inline bool
1390  operator<=(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
1391  const sub_match<_Bi_iter>& __rhs)
1392  { return !(__rhs < __lhs); }
1393 
1394  /**
1395  * @brief Tests the equivalence of a regular expression submatch and a
1396  * string.
1397  * @param __lhs A regular expression submatch.
1398  * @param __rhs A const string reference.
1399  * @returns true if @a __lhs is equivalent to @a __rhs, false otherwise.
1400  */
1401  template<typename _Bi_iter>
1402  inline bool
1403  operator==(const sub_match<_Bi_iter>& __lhs,
1404  typename iterator_traits<_Bi_iter>::value_type const& __rhs)
1405  {
1406  typedef typename sub_match<_Bi_iter>::string_type string_type;
1407  return __lhs.compare(string_type(1, __rhs)) == 0;
1408  }
1409 
1410  /**
1411  * @brief Tests the inequivalence of a regular expression submatch and a
1412  * string.
1413  * @param __lhs A regular expression submatch.
1414  * @param __rhs A const string reference.
1415  * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise.
1416  */
1417  template<typename _Bi_iter>
1418  inline bool
1419  operator!=(const sub_match<_Bi_iter>& __lhs,
1420  typename iterator_traits<_Bi_iter>::value_type const& __rhs)
1421  { return !(__lhs == __rhs); }
1422 
1423  /**
1424  * @brief Tests the ordering of a regular expression submatch and a string.
1425  * @param __lhs A regular expression submatch.
1426  * @param __rhs A const string reference.
1427  * @returns true if @a __lhs precedes @a __rhs, false otherwise.
1428  */
1429  template<typename _Bi_iter>
1430  inline bool
1431  operator<(const sub_match<_Bi_iter>& __lhs,
1432  typename iterator_traits<_Bi_iter>::value_type const& __rhs)
1433  {
1434  typedef typename sub_match<_Bi_iter>::string_type string_type;
1435  return __lhs.compare(string_type(1, __rhs)) < 0;
1436  }
1437 
1438  /**
1439  * @brief Tests the ordering of a regular expression submatch and a string.
1440  * @param __lhs A regular expression submatch.
1441  * @param __rhs A const string reference.
1442  * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
1443  */
1444  template<typename _Bi_iter>
1445  inline bool
1446  operator>(const sub_match<_Bi_iter>& __lhs,
1447  typename iterator_traits<_Bi_iter>::value_type const& __rhs)
1448  { return __rhs < __lhs; }
1449 
1450  /**
1451  * @brief Tests the ordering of a regular expression submatch and a string.
1452  * @param __lhs A regular expression submatch.
1453  * @param __rhs A const string reference.
1454  * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
1455  */
1456  template<typename _Bi_iter>
1457  inline bool
1458  operator>=(const sub_match<_Bi_iter>& __lhs,
1459  typename iterator_traits<_Bi_iter>::value_type const& __rhs)
1460  { return !(__lhs < __rhs); }
1461 
1462  /**
1463  * @brief Tests the ordering of a regular expression submatch and a string.
1464  * @param __lhs A regular expression submatch.
1465  * @param __rhs A const string reference.
1466  * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
1467  */
1468  template<typename _Bi_iter>
1469  inline bool
1470  operator<=(const sub_match<_Bi_iter>& __lhs,
1471  typename iterator_traits<_Bi_iter>::value_type const& __rhs)
1472  { return !(__rhs < __lhs); }
1473 
1474  /**
1475  * @brief Inserts a matched string into an output stream.
1476  *
1477  * @param __os The output stream.
1478  * @param __m A submatch string.
1479  *
1480  * @returns the output stream with the submatch string inserted.
1481  */
1482  template<typename _Ch_type, typename _Ch_traits, typename _Bi_iter>
1483  inline
1485  operator<<(basic_ostream<_Ch_type, _Ch_traits>& __os,
1486  const sub_match<_Bi_iter>& __m)
1487  { return __os << __m.str(); }
1488 
1489  // [7.10] Class template match_results
1490 
1491  /**
1492  * @brief The results of a match or search operation.
1493  *
1494  * A collection of character sequences representing the result of a regular
1495  * expression match. Storage for the collection is allocated and freed as
1496  * necessary by the member functions of class template match_results.
1497  *
1498  * This class satisfies the Sequence requirements, with the exception that
1499  * only the operations defined for a const-qualified Sequence are supported.
1500  *
1501  * The sub_match object stored at index 0 represents sub-expression 0, i.e.
1502  * the whole match. In this case the %sub_match member matched is always true.
1503  * The sub_match object stored at index n denotes what matched the marked
1504  * sub-expression n within the matched expression. If the sub-expression n
1505  * participated in a regular expression match then the %sub_match member
1506  * matched evaluates to true, and members first and second denote the range
1507  * of characters [first, second) which formed that match. Otherwise matched
1508  * is false, and members first and second point to the end of the sequence
1509  * that was searched.
1510  *
1511  * @nosubgrouping
1512  */
1513  template<typename _Bi_iter,
1514  typename _Alloc = allocator<sub_match<_Bi_iter> > >
1515  class match_results
1516  : private std::vector<sub_match<_Bi_iter>, _Alloc>
1517  {
1518  private:
1519  /*
1520  * The vector base is empty if this does not represent a match (!ready());
1521  * Otherwise if it's a match failure, it contains 3 elements:
1522  * [0] unmatched
1523  * [1] prefix
1524  * [2] suffix
1525  * Otherwise it contains n+4 elements where n is the number of marked
1526  * sub-expressions:
1527  * [0] entire match
1528  * [1] 1st marked subexpression
1529  * ...
1530  * [n] nth marked subexpression
1531  * [n+1] unmatched
1532  * [n+2] prefix
1533  * [n+3] suffix
1534  */
1535  typedef std::vector<sub_match<_Bi_iter>, _Alloc> _Base_type;
1536  typedef std::iterator_traits<_Bi_iter> __iter_traits;
1538 
1539  public:
1540  /**
1541  * @name 10.? Public Types
1542  */
1543  //@{
1544  typedef sub_match<_Bi_iter> value_type;
1545  typedef const value_type& const_reference;
1546  typedef const_reference reference;
1547  typedef typename _Base_type::const_iterator const_iterator;
1548  typedef const_iterator iterator;
1549  typedef typename __iter_traits::difference_type difference_type;
1550  typedef typename allocator_traits<_Alloc>::size_type size_type;
1551  typedef _Alloc allocator_type;
1552  typedef typename __iter_traits::value_type char_type;
1553  typedef std::basic_string<char_type> string_type;
1554  //@}
1555 
1556  public:
1557  /**
1558  * @name 28.10.1 Construction, Copying, and Destruction
1559  */
1560  //@{
1561 
1562  /**
1563  * @brief Constructs a default %match_results container.
1564  * @post size() returns 0 and str() returns an empty string.
1565  */
1566  explicit
1567  match_results(const _Alloc& __a = _Alloc())
1568  : _Base_type(__a)
1569  { }
1570 
1571  /**
1572  * @brief Copy constructs a %match_results.
1573  */
1574  match_results(const match_results& __rhs) = default;
1575 
1576  /**
1577  * @brief Move constructs a %match_results.
1578  */
1579  match_results(match_results&& __rhs) noexcept = default;
1580 
1581  /**
1582  * @brief Assigns rhs to *this.
1583  */
1584  match_results&
1585  operator=(const match_results& __rhs) = default;
1586 
1587  /**
1588  * @brief Move-assigns rhs to *this.
1589  */
1590  match_results&
1591  operator=(match_results&& __rhs) = default;
1592 
1593  /**
1594  * @brief Destroys a %match_results object.
1595  */
1597  { }
1598 
1599  //@}
1600 
1601  // 28.10.2, state:
1602  /**
1603  * @brief Indicates if the %match_results is ready.
1604  * @retval true The object has a fully-established result state.
1605  * @retval false The object is not ready.
1606  */
1607  bool ready() const { return !_Base_type::empty(); }
1608 
1609  /**
1610  * @name 28.10.2 Size
1611  */
1612  //@{
1613 
1614  /**
1615  * @brief Gets the number of matches and submatches.
1616  *
1617  * The number of matches for a given regular expression will be either 0
1618  * if there was no match or mark_count() + 1 if a match was successful.
1619  * Some matches may be empty.
1620  *
1621  * @returns the number of matches found.
1622  */
1623  size_type
1624  size() const
1625  { return _Base_type::empty() ? 0 : _Base_type::size() - 3; }
1626 
1627  size_type
1628  max_size() const
1629  { return _Base_type::max_size(); }
1630 
1631  /**
1632  * @brief Indicates if the %match_results contains no results.
1633  * @retval true The %match_results object is empty.
1634  * @retval false The %match_results object is not empty.
1635  */
1636  bool
1637  empty() const
1638  { return size() == 0; }
1639 
1640  //@}
1641 
1642  /**
1643  * @name 10.3 Element Access
1644  */
1645  //@{
1646 
1647  /**
1648  * @brief Gets the length of the indicated submatch.
1649  * @param __sub indicates the submatch.
1650  * @pre ready() == true
1651  *
1652  * This function returns the length of the indicated submatch, or the
1653  * length of the entire match if @p __sub is zero (the default).
1654  */
1655  difference_type
1656  length(size_type __sub = 0) const
1657  { return (*this)[__sub].length(); }
1658 
1659  /**
1660  * @brief Gets the offset of the beginning of the indicated submatch.
1661  * @param __sub indicates the submatch.
1662  * @pre ready() == true
1663  *
1664  * This function returns the offset from the beginning of the target
1665  * sequence to the beginning of the submatch, unless the value of @p __sub
1666  * is zero (the default), in which case this function returns the offset
1667  * from the beginning of the target sequence to the beginning of the
1668  * match.
1669  */
1670  difference_type
1671  position(size_type __sub = 0) const
1672  { return std::distance(_M_begin, (*this)[__sub].first); }
1673 
1674  /**
1675  * @brief Gets the match or submatch converted to a string type.
1676  * @param __sub indicates the submatch.
1677  * @pre ready() == true
1678  *
1679  * This function gets the submatch (or match, if @p __sub is
1680  * zero) extracted from the target range and converted to the
1681  * associated string type.
1682  */
1683  string_type
1684  str(size_type __sub = 0) const
1685  { return string_type((*this)[__sub]); }
1686 
1687  /**
1688  * @brief Gets a %sub_match reference for the match or submatch.
1689  * @param __sub indicates the submatch.
1690  * @pre ready() == true
1691  *
1692  * This function gets a reference to the indicated submatch, or
1693  * the entire match if @p __sub is zero.
1694  *
1695  * If @p __sub >= size() then this function returns a %sub_match with a
1696  * special value indicating no submatch.
1697  */
1698  const_reference
1699  operator[](size_type __sub) const
1700  {
1701  __glibcxx_assert( ready() );
1702  return __sub < size()
1703  ? _Base_type::operator[](__sub)
1704  : _M_unmatched_sub();
1705  }
1706 
1707  /**
1708  * @brief Gets a %sub_match representing the match prefix.
1709  * @pre ready() == true
1710  *
1711  * This function gets a reference to a %sub_match object representing the
1712  * part of the target range between the start of the target range and the
1713  * start of the match.
1714  */
1715  const_reference
1716  prefix() const
1717  {
1718  __glibcxx_assert( ready() );
1719  return !empty() ? _M_prefix() : _M_unmatched_sub();
1720  }
1721 
1722  /**
1723  * @brief Gets a %sub_match representing the match suffix.
1724  * @pre ready() == true
1725  *
1726  * This function gets a reference to a %sub_match object representing the
1727  * part of the target range between the end of the match and the end of
1728  * the target range.
1729  */
1730  const_reference
1731  suffix() const
1732  {
1733  __glibcxx_assert( ready() );
1734  return !empty() ? _M_suffix() : _M_unmatched_sub();
1735  }
1736 
1737  /**
1738  * @brief Gets an iterator to the start of the %sub_match collection.
1739  */
1740  const_iterator
1741  begin() const
1742  { return _Base_type::begin(); }
1743 
1744  /**
1745  * @brief Gets an iterator to the start of the %sub_match collection.
1746  */
1747  const_iterator
1748  cbegin() const
1749  { return this->begin(); }
1750 
1751  /**
1752  * @brief Gets an iterator to one-past-the-end of the collection.
1753  */
1754  const_iterator
1755  end() const
1756  { return _Base_type::end() - 3; }
1757 
1758  /**
1759  * @brief Gets an iterator to one-past-the-end of the collection.
1760  */
1761  const_iterator
1762  cend() const
1763  { return this->end(); }
1764 
1765  //@}
1766 
1767  /**
1768  * @name 10.4 Formatting
1769  *
1770  * These functions perform formatted substitution of the matched
1771  * character sequences into their target. The format specifiers and
1772  * escape sequences accepted by these functions are determined by
1773  * their @p flags parameter as documented above.
1774  */
1775  //@{
1776 
1777  /**
1778  * @pre ready() == true
1779  */
1780  template<typename _Out_iter>
1781  _Out_iter
1782  format(_Out_iter __out, const char_type* __fmt_first,
1783  const char_type* __fmt_last,
1784  match_flag_type __flags = regex_constants::format_default) const;
1785 
1786  /**
1787  * @pre ready() == true
1788  */
1789  template<typename _Out_iter, typename _St, typename _Sa>
1790  _Out_iter
1791  format(_Out_iter __out, const basic_string<char_type, _St, _Sa>& __fmt,
1792  match_flag_type __flags = regex_constants::format_default) const
1793  {
1794  return format(__out, __fmt.data(), __fmt.data() + __fmt.size(),
1795  __flags);
1796  }
1797 
1798  /**
1799  * @pre ready() == true
1800  */
1801  template<typename _St, typename _Sa>
1804  match_flag_type __flags = regex_constants::format_default) const
1805  {
1807  format(std::back_inserter(__result), __fmt, __flags);
1808  return __result;
1809  }
1810 
1811  /**
1812  * @pre ready() == true
1813  */
1814  string_type
1815  format(const char_type* __fmt,
1816  match_flag_type __flags = regex_constants::format_default) const
1817  {
1818  string_type __result;
1819  format(std::back_inserter(__result),
1820  __fmt,
1821  __fmt + char_traits<char_type>::length(__fmt),
1822  __flags);
1823  return __result;
1824  }
1825 
1826  //@}
1827 
1828  /**
1829  * @name 10.5 Allocator
1830  */
1831  //@{
1832 
1833  /**
1834  * @brief Gets a copy of the allocator.
1835  */
1836  allocator_type
1838  { return _Base_type::get_allocator(); }
1839 
1840  //@}
1841 
1842  /**
1843  * @name 10.6 Swap
1844  */
1845  //@{
1846 
1847  /**
1848  * @brief Swaps the contents of two match_results.
1849  */
1850  void
1852  {
1853  using std::swap;
1854  _Base_type::swap(__that);
1855  swap(_M_begin, __that._M_begin);
1856  }
1857  //@}
1858 
1859  private:
1860  template<typename, typename, typename, bool>
1861  friend class __detail::_Executor;
1862 
1863  template<typename, typename, typename>
1864  friend class regex_iterator;
1865 
1866  template<typename _Bp, typename _Ap, typename _Cp, typename _Rp,
1867  __detail::_RegexExecutorPolicy, bool>
1868  friend bool __detail::
1869 #if _GLIBCXX_INLINE_VERSION
1870  __7:: // Required due to PR c++/59256
1871 #endif
1872  __regex_algo_impl(_Bp, _Bp, match_results<_Bp, _Ap>&,
1873  const basic_regex<_Cp, _Rp>&,
1875 
1876  void
1877  _M_resize(unsigned int __size)
1878  { _Base_type::resize(__size + 3); }
1879 
1880  const_reference
1881  _M_unmatched_sub() const
1882  { return _Base_type::operator[](_Base_type::size() - 3); }
1883 
1885  _M_unmatched_sub()
1886  { return _Base_type::operator[](_Base_type::size() - 3); }
1887 
1888  const_reference
1889  _M_prefix() const
1890  { return _Base_type::operator[](_Base_type::size() - 2); }
1891 
1893  _M_prefix()
1894  { return _Base_type::operator[](_Base_type::size() - 2); }
1895 
1896  const_reference
1897  _M_suffix() const
1898  { return _Base_type::operator[](_Base_type::size() - 1); }
1899 
1901  _M_suffix()
1902  { return _Base_type::operator[](_Base_type::size() - 1); }
1903 
1904  _Bi_iter _M_begin;
1905  };
1906 
1909 #ifdef _GLIBCXX_USE_WCHAR_T
1912 #endif
1913 
1914  // match_results comparisons
1915  /**
1916  * @brief Compares two match_results for equality.
1917  * @returns true if the two objects refer to the same match,
1918  * false otherwise.
1919  */
1920  template<typename _Bi_iter, typename _Alloc>
1921  inline bool
1923  const match_results<_Bi_iter, _Alloc>& __m2)
1924  {
1925  if (__m1.ready() != __m2.ready())
1926  return false;
1927  if (!__m1.ready()) // both are not ready
1928  return true;
1929  if (__m1.empty() != __m2.empty())
1930  return false;
1931  if (__m1.empty()) // both are empty
1932  return true;
1933  return __m1.prefix() == __m2.prefix()
1934  && __m1.size() == __m2.size()
1935  && std::equal(__m1.begin(), __m1.end(), __m2.begin())
1936  && __m1.suffix() == __m2.suffix();
1937  }
1938 
1939  /**
1940  * @brief Compares two match_results for inequality.
1941  * @returns true if the two objects do not refer to the same match,
1942  * false otherwise.
1943  */
1944  template<typename _Bi_iter, class _Alloc>
1945  inline bool
1947  const match_results<_Bi_iter, _Alloc>& __m2)
1948  { return !(__m1 == __m2); }
1949 
1950  // [7.10.6] match_results swap
1951  /**
1952  * @brief Swaps two match results.
1953  * @param __lhs A match result.
1954  * @param __rhs A match result.
1955  *
1956  * The contents of the two match_results objects are swapped.
1957  */
1958  template<typename _Bi_iter, typename _Alloc>
1959  inline void
1962  { __lhs.swap(__rhs); }
1963 
1964 _GLIBCXX_END_NAMESPACE_CXX11
1965 
1966  // [7.11.2] Function template regex_match
1967  /**
1968  * @name Matching, Searching, and Replacing
1969  */
1970  //@{
1971 
1972  /**
1973  * @brief Determines if there is a match between the regular expression @p e
1974  * and all of the character sequence [first, last).
1975  *
1976  * @param __s Start of the character sequence to match.
1977  * @param __e One-past-the-end of the character sequence to match.
1978  * @param __m The match results.
1979  * @param __re The regular expression.
1980  * @param __flags Controls how the regular expression is matched.
1981  *
1982  * @retval true A match exists.
1983  * @retval false Otherwise.
1984  *
1985  * @throws an exception of type regex_error.
1986  */
1987  template<typename _Bi_iter, typename _Alloc,
1988  typename _Ch_type, typename _Rx_traits>
1989  inline bool
1990  regex_match(_Bi_iter __s,
1991  _Bi_iter __e,
1996  {
1997  return __detail::__regex_algo_impl<_Bi_iter, _Alloc, _Ch_type, _Rx_traits,
1998  __detail::_RegexExecutorPolicy::_S_auto, true>
1999  (__s, __e, __m, __re, __flags);
2000  }
2001 
2002  /**
2003  * @brief Indicates if there is a match between the regular expression @p e
2004  * and all of the character sequence [first, last).
2005  *
2006  * @param __first Beginning of the character sequence to match.
2007  * @param __last One-past-the-end of the character sequence to match.
2008  * @param __re The regular expression.
2009  * @param __flags Controls how the regular expression is matched.
2010  *
2011  * @retval true A match exists.
2012  * @retval false Otherwise.
2013  *
2014  * @throws an exception of type regex_error.
2015  */
2016  template<typename _Bi_iter, typename _Ch_type, typename _Rx_traits>
2017  inline bool
2018  regex_match(_Bi_iter __first, _Bi_iter __last,
2022  {
2023  match_results<_Bi_iter> __what;
2024  return regex_match(__first, __last, __what, __re, __flags);
2025  }
2026 
2027  /**
2028  * @brief Determines if there is a match between the regular expression @p e
2029  * and a C-style null-terminated string.
2030  *
2031  * @param __s The C-style null-terminated string to match.
2032  * @param __m The match results.
2033  * @param __re The regular expression.
2034  * @param __f Controls how the regular expression is matched.
2035  *
2036  * @retval true A match exists.
2037  * @retval false Otherwise.
2038  *
2039  * @throws an exception of type regex_error.
2040  */
2041  template<typename _Ch_type, typename _Alloc, typename _Rx_traits>
2042  inline bool
2043  regex_match(const _Ch_type* __s,
2048  { return regex_match(__s, __s + _Rx_traits::length(__s), __m, __re, __f); }
2049 
2050  /**
2051  * @brief Determines if there is a match between the regular expression @p e
2052  * and a string.
2053  *
2054  * @param __s The string to match.
2055  * @param __m The match results.
2056  * @param __re The regular expression.
2057  * @param __flags Controls how the regular expression is matched.
2058  *
2059  * @retval true A match exists.
2060  * @retval false Otherwise.
2061  *
2062  * @throws an exception of type regex_error.
2063  */
2064  template<typename _Ch_traits, typename _Ch_alloc,
2065  typename _Alloc, typename _Ch_type, typename _Rx_traits>
2066  inline bool
2068  match_results<typename basic_string<_Ch_type,
2069  _Ch_traits, _Ch_alloc>::const_iterator, _Alloc>& __m,
2073  { return regex_match(__s.begin(), __s.end(), __m, __re, __flags); }
2074 
2075  // _GLIBCXX_RESOLVE_LIB_DEFECTS
2076  // 2329. regex_match() with match_results should forbid temporary strings
2077  /// Prevent unsafe attempts to get match_results from a temporary string.
2078  template<typename _Ch_traits, typename _Ch_alloc,
2079  typename _Alloc, typename _Ch_type, typename _Rx_traits>
2080  bool
2082  match_results<typename basic_string<_Ch_type,
2083  _Ch_traits, _Ch_alloc>::const_iterator, _Alloc>&,
2086  = regex_constants::match_default) = delete;
2087 
2088  /**
2089  * @brief Indicates if there is a match between the regular expression @p e
2090  * and a C-style null-terminated string.
2091  *
2092  * @param __s The C-style null-terminated string to match.
2093  * @param __re The regular expression.
2094  * @param __f Controls how the regular expression is matched.
2095  *
2096  * @retval true A match exists.
2097  * @retval false Otherwise.
2098  *
2099  * @throws an exception of type regex_error.
2100  */
2101  template<typename _Ch_type, class _Rx_traits>
2102  inline bool
2103  regex_match(const _Ch_type* __s,
2107  { return regex_match(__s, __s + _Rx_traits::length(__s), __re, __f); }
2108 
2109  /**
2110  * @brief Indicates if there is a match between the regular expression @p e
2111  * and a string.
2112  *
2113  * @param __s [IN] The string to match.
2114  * @param __re [IN] The regular expression.
2115  * @param __flags [IN] Controls how the regular expression is matched.
2116  *
2117  * @retval true A match exists.
2118  * @retval false Otherwise.
2119  *
2120  * @throws an exception of type regex_error.
2121  */
2122  template<typename _Ch_traits, typename _Str_allocator,
2123  typename _Ch_type, typename _Rx_traits>
2124  inline bool
2129  { return regex_match(__s.begin(), __s.end(), __re, __flags); }
2130 
2131  // [7.11.3] Function template regex_search
2132  /**
2133  * Searches for a regular expression within a range.
2134  * @param __s [IN] The start of the string to search.
2135  * @param __e [IN] One-past-the-end of the string to search.
2136  * @param __m [OUT] The match results.
2137  * @param __re [IN] The regular expression to search for.
2138  * @param __flags [IN] Search policy flags.
2139  * @retval true A match was found within the string.
2140  * @retval false No match was found within the string, the content of %m is
2141  * undefined.
2142  *
2143  * @throws an exception of type regex_error.
2144  */
2145  template<typename _Bi_iter, typename _Alloc,
2146  typename _Ch_type, typename _Rx_traits>
2147  inline bool
2148  regex_search(_Bi_iter __s, _Bi_iter __e,
2153  {
2154  return __detail::__regex_algo_impl<_Bi_iter, _Alloc, _Ch_type, _Rx_traits,
2155  __detail::_RegexExecutorPolicy::_S_auto, false>
2156  (__s, __e, __m, __re, __flags);
2157  }
2158 
2159  /**
2160  * Searches for a regular expression within a range.
2161  * @param __first [IN] The start of the string to search.
2162  * @param __last [IN] One-past-the-end of the string to search.
2163  * @param __re [IN] The regular expression to search for.
2164  * @param __flags [IN] Search policy flags.
2165  * @retval true A match was found within the string.
2166  * @retval false No match was found within the string.
2167  *
2168  * @throws an exception of type regex_error.
2169  */
2170  template<typename _Bi_iter, typename _Ch_type, typename _Rx_traits>
2171  inline bool
2172  regex_search(_Bi_iter __first, _Bi_iter __last,
2176  {
2177  match_results<_Bi_iter> __what;
2178  return regex_search(__first, __last, __what, __re, __flags);
2179  }
2180 
2181  /**
2182  * @brief Searches for a regular expression within a C-string.
2183  * @param __s [IN] A C-string to search for the regex.
2184  * @param __m [OUT] The set of regex matches.
2185  * @param __e [IN] The regex to search for in @p s.
2186  * @param __f [IN] The search flags.
2187  * @retval true A match was found within the string.
2188  * @retval false No match was found within the string, the content of %m is
2189  * undefined.
2190  *
2191  * @throws an exception of type regex_error.
2192  */
2193  template<typename _Ch_type, class _Alloc, class _Rx_traits>
2194  inline bool
2195  regex_search(const _Ch_type* __s,
2200  { return regex_search(__s, __s + _Rx_traits::length(__s), __m, __e, __f); }
2201 
2202  /**
2203  * @brief Searches for a regular expression within a C-string.
2204  * @param __s [IN] The C-string to search.
2205  * @param __e [IN] The regular expression to search for.
2206  * @param __f [IN] Search policy flags.
2207  * @retval true A match was found within the string.
2208  * @retval false No match was found within the string.
2209  *
2210  * @throws an exception of type regex_error.
2211  */
2212  template<typename _Ch_type, typename _Rx_traits>
2213  inline bool
2214  regex_search(const _Ch_type* __s,
2218  { return regex_search(__s, __s + _Rx_traits::length(__s), __e, __f); }
2219 
2220  /**
2221  * @brief Searches for a regular expression within a string.
2222  * @param __s [IN] The string to search.
2223  * @param __e [IN] The regular expression to search for.
2224  * @param __flags [IN] Search policy flags.
2225  * @retval true A match was found within the string.
2226  * @retval false No match was found within the string.
2227  *
2228  * @throws an exception of type regex_error.
2229  */
2230  template<typename _Ch_traits, typename _String_allocator,
2231  typename _Ch_type, typename _Rx_traits>
2232  inline bool
2233  regex_search(const basic_string<_Ch_type, _Ch_traits,
2234  _String_allocator>& __s,
2238  { return regex_search(__s.begin(), __s.end(), __e, __flags); }
2239 
2240  /**
2241  * @brief Searches for a regular expression within a string.
2242  * @param __s [IN] A C++ string to search for the regex.
2243  * @param __m [OUT] The set of regex matches.
2244  * @param __e [IN] The regex to search for in @p s.
2245  * @param __f [IN] The search flags.
2246  * @retval true A match was found within the string.
2247  * @retval false No match was found within the string, the content of %m is
2248  * undefined.
2249  *
2250  * @throws an exception of type regex_error.
2251  */
2252  template<typename _Ch_traits, typename _Ch_alloc,
2253  typename _Alloc, typename _Ch_type,
2254  typename _Rx_traits>
2255  inline bool
2257  match_results<typename basic_string<_Ch_type,
2258  _Ch_traits, _Ch_alloc>::const_iterator, _Alloc>& __m,
2262  { return regex_search(__s.begin(), __s.end(), __m, __e, __f); }
2263 
2264  // _GLIBCXX_RESOLVE_LIB_DEFECTS
2265  // 2329. regex_search() with match_results should forbid temporary strings
2266  /// Prevent unsafe attempts to get match_results from a temporary string.
2267  template<typename _Ch_traits, typename _Ch_alloc,
2268  typename _Alloc, typename _Ch_type,
2269  typename _Rx_traits>
2270  bool
2272  match_results<typename basic_string<_Ch_type,
2273  _Ch_traits, _Ch_alloc>::const_iterator, _Alloc>&,
2276  = regex_constants::match_default) = delete;
2277 
2278  // std [28.11.4] Function template regex_replace
2279  /**
2280  * @brief Search for a regular expression within a range for multiple times,
2281  and replace the matched parts through filling a format string.
2282  * @param __out [OUT] The output iterator.
2283  * @param __first [IN] The start of the string to search.
2284  * @param __last [IN] One-past-the-end of the string to search.
2285  * @param __e [IN] The regular expression to search for.
2286  * @param __fmt [IN] The format string.
2287  * @param __flags [IN] Search and replace policy flags.
2288  *
2289  * @returns __out
2290  * @throws an exception of type regex_error.
2291  */
2292  template<typename _Out_iter, typename _Bi_iter,
2293  typename _Rx_traits, typename _Ch_type,
2294  typename _St, typename _Sa>
2295  inline _Out_iter
2296  regex_replace(_Out_iter __out, _Bi_iter __first, _Bi_iter __last,
2298  const basic_string<_Ch_type, _St, _Sa>& __fmt,
2301  {
2302  return regex_replace(__out, __first, __last, __e, __fmt.c_str(), __flags);
2303  }
2304 
2305  /**
2306  * @brief Search for a regular expression within a range for multiple times,
2307  and replace the matched parts through filling a format C-string.
2308  * @param __out [OUT] The output iterator.
2309  * @param __first [IN] The start of the string to search.
2310  * @param __last [IN] One-past-the-end of the string to search.
2311  * @param __e [IN] The regular expression to search for.
2312  * @param __fmt [IN] The format C-string.
2313  * @param __flags [IN] Search and replace policy flags.
2314  *
2315  * @returns __out
2316  * @throws an exception of type regex_error.
2317  */
2318  template<typename _Out_iter, typename _Bi_iter,
2319  typename _Rx_traits, typename _Ch_type>
2320  _Out_iter
2321  regex_replace(_Out_iter __out, _Bi_iter __first, _Bi_iter __last,
2323  const _Ch_type* __fmt,
2326 
2327  /**
2328  * @brief Search for a regular expression within a string for multiple times,
2329  and replace the matched parts through filling a format string.
2330  * @param __s [IN] The string to search and replace.
2331  * @param __e [IN] The regular expression to search for.
2332  * @param __fmt [IN] The format string.
2333  * @param __flags [IN] Search and replace policy flags.
2334  *
2335  * @returns The string after replacing.
2336  * @throws an exception of type regex_error.
2337  */
2338  template<typename _Rx_traits, typename _Ch_type,
2339  typename _St, typename _Sa, typename _Fst, typename _Fsa>
2346  {
2349  __s.begin(), __s.end(), __e, __fmt, __flags);
2350  return __result;
2351  }
2352 
2353  /**
2354  * @brief Search for a regular expression within a string for multiple times,
2355  and replace the matched parts through filling a format C-string.
2356  * @param __s [IN] The string to search and replace.
2357  * @param __e [IN] The regular expression to search for.
2358  * @param __fmt [IN] The format C-string.
2359  * @param __flags [IN] Search and replace policy flags.
2360  *
2361  * @returns The string after replacing.
2362  * @throws an exception of type regex_error.
2363  */
2364  template<typename _Rx_traits, typename _Ch_type,
2365  typename _St, typename _Sa>
2369  const _Ch_type* __fmt,
2372  {
2375  __s.begin(), __s.end(), __e, __fmt, __flags);
2376  return __result;
2377  }
2378 
2379  /**
2380  * @brief Search for a regular expression within a C-string for multiple
2381  times, and replace the matched parts through filling a format string.
2382  * @param __s [IN] The C-string to search and replace.
2383  * @param __e [IN] The regular expression to search for.
2384  * @param __fmt [IN] The format string.
2385  * @param __flags [IN] Search and replace policy flags.
2386  *
2387  * @returns The string after replacing.
2388  * @throws an exception of type regex_error.
2389  */
2390  template<typename _Rx_traits, typename _Ch_type,
2391  typename _St, typename _Sa>
2392  inline basic_string<_Ch_type>
2393  regex_replace(const _Ch_type* __s,
2395  const basic_string<_Ch_type, _St, _Sa>& __fmt,
2398  {
2399  basic_string<_Ch_type> __result;
2400  regex_replace(std::back_inserter(__result), __s,
2401  __s + char_traits<_Ch_type>::length(__s),
2402  __e, __fmt, __flags);
2403  return __result;
2404  }
2405 
2406  /**
2407  * @brief Search for a regular expression within a C-string for multiple
2408  times, and replace the matched parts through filling a format C-string.
2409  * @param __s [IN] The C-string to search and replace.
2410  * @param __e [IN] The regular expression to search for.
2411  * @param __fmt [IN] The format C-string.
2412  * @param __flags [IN] Search and replace policy flags.
2413  *
2414  * @returns The string after replacing.
2415  * @throws an exception of type regex_error.
2416  */
2417  template<typename _Rx_traits, typename _Ch_type>
2418  inline basic_string<_Ch_type>
2419  regex_replace(const _Ch_type* __s,
2421  const _Ch_type* __fmt,
2424  {
2425  basic_string<_Ch_type> __result;
2426  regex_replace(std::back_inserter(__result), __s,
2427  __s + char_traits<_Ch_type>::length(__s),
2428  __e, __fmt, __flags);
2429  return __result;
2430  }
2431 
2432  //@}
2433 
2434 _GLIBCXX_BEGIN_NAMESPACE_CXX11
2435 
2436  // std [28.12] Class template regex_iterator
2437  /**
2438  * An iterator adaptor that will provide repeated calls of regex_search over
2439  * a range until no more matches remain.
2440  */
2441  template<typename _Bi_iter,
2442  typename _Ch_type = typename iterator_traits<_Bi_iter>::value_type,
2443  typename _Rx_traits = regex_traits<_Ch_type> >
2445  {
2446  public:
2448  typedef match_results<_Bi_iter> value_type;
2449  typedef std::ptrdiff_t difference_type;
2450  typedef const value_type* pointer;
2451  typedef const value_type& reference;
2453 
2454  /**
2455  * @brief Provides a singular iterator, useful for indicating
2456  * one-past-the-end of a range.
2457  */
2459  : _M_pregex()
2460  { }
2461 
2462  /**
2463  * Constructs a %regex_iterator...
2464  * @param __a [IN] The start of a text range to search.
2465  * @param __b [IN] One-past-the-end of the text range to search.
2466  * @param __re [IN] The regular expression to match.
2467  * @param __m [IN] Policy flags for match rules.
2468  */
2469  regex_iterator(_Bi_iter __a, _Bi_iter __b, const regex_type& __re,
2472  : _M_begin(__a), _M_end(__b), _M_pregex(&__re), _M_flags(__m), _M_match()
2473  {
2474  if (!regex_search(_M_begin, _M_end, _M_match, *_M_pregex, _M_flags))
2475  *this = regex_iterator();
2476  }
2477 
2478  // _GLIBCXX_RESOLVE_LIB_DEFECTS
2479  // 2332. regex_iterator should forbid temporary regexes
2480  regex_iterator(_Bi_iter, _Bi_iter, const regex_type&&,
2482  = regex_constants::match_default) = delete;
2483  /**
2484  * Copy constructs a %regex_iterator.
2485  */
2486  regex_iterator(const regex_iterator& __rhs) = default;
2487 
2488  /**
2489  * @brief Assigns one %regex_iterator to another.
2490  */
2492  operator=(const regex_iterator& __rhs) = default;
2493 
2494  /**
2495  * @brief Tests the equivalence of two regex iterators.
2496  */
2497  bool
2498  operator==(const regex_iterator& __rhs) const;
2499 
2500  /**
2501  * @brief Tests the inequivalence of two regex iterators.
2502  */
2503  bool
2504  operator!=(const regex_iterator& __rhs) const
2505  { return !(*this == __rhs); }
2506 
2507  /**
2508  * @brief Dereferences a %regex_iterator.
2509  */
2510  const value_type&
2511  operator*() const
2512  { return _M_match; }
2513 
2514  /**
2515  * @brief Selects a %regex_iterator member.
2516  */
2517  const value_type*
2518  operator->() const
2519  { return &_M_match; }
2520 
2521  /**
2522  * @brief Increments a %regex_iterator.
2523  */
2525  operator++();
2526 
2527  /**
2528  * @brief Postincrements a %regex_iterator.
2529  */
2532  {
2533  auto __tmp = *this;
2534  ++(*this);
2535  return __tmp;
2536  }
2537 
2538  private:
2539  _Bi_iter _M_begin;
2540  _Bi_iter _M_end;
2541  const regex_type* _M_pregex;
2543  match_results<_Bi_iter> _M_match;
2544  };
2545 
2548 #ifdef _GLIBCXX_USE_WCHAR_T
2551 #endif
2552 
2553  // [7.12.2] Class template regex_token_iterator
2554  /**
2555  * Iterates over submatches in a range (or @a splits a text string).
2556  *
2557  * The purpose of this iterator is to enumerate all, or all specified,
2558  * matches of a regular expression within a text range. The dereferenced
2559  * value of an iterator of this class is a std::sub_match object.
2560  */
2561  template<typename _Bi_iter,
2562  typename _Ch_type = typename iterator_traits<_Bi_iter>::value_type,
2563  typename _Rx_traits = regex_traits<_Ch_type> >
2565  {
2566  public:
2568  typedef sub_match<_Bi_iter> value_type;
2569  typedef std::ptrdiff_t difference_type;
2570  typedef const value_type* pointer;
2571  typedef const value_type& reference;
2573 
2574  public:
2575  /**
2576  * @brief Default constructs a %regex_token_iterator.
2577  *
2578  * A default-constructed %regex_token_iterator is a singular iterator
2579  * that will compare equal to the one-past-the-end value for any
2580  * iterator of the same type.
2581  */
2583  : _M_position(), _M_subs(), _M_suffix(), _M_n(0), _M_result(nullptr),
2584  _M_has_m1(false)
2585  { }
2586 
2587  /**
2588  * Constructs a %regex_token_iterator...
2589  * @param __a [IN] The start of the text to search.
2590  * @param __b [IN] One-past-the-end of the text to search.
2591  * @param __re [IN] The regular expression to search for.
2592  * @param __submatch [IN] Which submatch to return. There are some
2593  * special values for this parameter:
2594  * - -1 each enumerated subexpression does NOT
2595  * match the regular expression (aka field
2596  * splitting)
2597  * - 0 the entire string matching the
2598  * subexpression is returned for each match
2599  * within the text.
2600  * - >0 enumerates only the indicated
2601  * subexpression from a match within the text.
2602  * @param __m [IN] Policy flags for match rules.
2603  */
2604  regex_token_iterator(_Bi_iter __a, _Bi_iter __b, const regex_type& __re,
2605  int __submatch = 0,
2608  : _M_position(__a, __b, __re, __m), _M_subs(1, __submatch), _M_n(0)
2609  { _M_init(__a, __b); }
2610 
2611  /**
2612  * Constructs a %regex_token_iterator...
2613  * @param __a [IN] The start of the text to search.
2614  * @param __b [IN] One-past-the-end of the text to search.
2615  * @param __re [IN] The regular expression to search for.
2616  * @param __submatches [IN] A list of subexpressions to return for each
2617  * regular expression match within the text.
2618  * @param __m [IN] Policy flags for match rules.
2619  */
2620  regex_token_iterator(_Bi_iter __a, _Bi_iter __b,
2621  const regex_type& __re,
2622  const std::vector<int>& __submatches,
2625  : _M_position(__a, __b, __re, __m), _M_subs(__submatches), _M_n(0)
2626  { _M_init(__a, __b); }
2627 
2628  /**
2629  * Constructs a %regex_token_iterator...
2630  * @param __a [IN] The start of the text to search.
2631  * @param __b [IN] One-past-the-end of the text to search.
2632  * @param __re [IN] The regular expression to search for.
2633  * @param __submatches [IN] A list of subexpressions to return for each
2634  * regular expression match within the text.
2635  * @param __m [IN] Policy flags for match rules.
2636  */
2637  regex_token_iterator(_Bi_iter __a, _Bi_iter __b,
2638  const regex_type& __re,
2639  initializer_list<int> __submatches,
2642  : _M_position(__a, __b, __re, __m), _M_subs(__submatches), _M_n(0)
2643  { _M_init(__a, __b); }
2644 
2645  /**
2646  * Constructs a %regex_token_iterator...
2647  * @param __a [IN] The start of the text to search.
2648  * @param __b [IN] One-past-the-end of the text to search.
2649  * @param __re [IN] The regular expression to search for.
2650  * @param __submatches [IN] A list of subexpressions to return for each
2651  * regular expression match within the text.
2652  * @param __m [IN] Policy flags for match rules.
2653  */
2654  template<std::size_t _Nm>
2655  regex_token_iterator(_Bi_iter __a, _Bi_iter __b,
2656  const regex_type& __re,
2657  const int (&__submatches)[_Nm],
2660  : _M_position(__a, __b, __re, __m),
2661  _M_subs(__submatches, __submatches + _Nm), _M_n(0)
2662  { _M_init(__a, __b); }
2663 
2664  // _GLIBCXX_RESOLVE_LIB_DEFECTS
2665  // 2332. regex_token_iterator should forbid temporary regexes
2666  regex_token_iterator(_Bi_iter, _Bi_iter, const regex_type&&, int = 0,
2669  regex_token_iterator(_Bi_iter, _Bi_iter, const regex_type&&,
2670  const std::vector<int>&,
2673  regex_token_iterator(_Bi_iter, _Bi_iter, const regex_type&&,
2677  template <std::size_t _Nm>
2678  regex_token_iterator(_Bi_iter, _Bi_iter, const regex_type&&,
2679  const int (&)[_Nm],
2682 
2683  /**
2684  * @brief Copy constructs a %regex_token_iterator.
2685  * @param __rhs [IN] A %regex_token_iterator to copy.
2686  */
2688  : _M_position(__rhs._M_position), _M_subs(__rhs._M_subs),
2689  _M_suffix(__rhs._M_suffix), _M_n(__rhs._M_n), _M_has_m1(__rhs._M_has_m1)
2690  { _M_normalize_result(); }
2691 
2692  /**
2693  * @brief Assigns a %regex_token_iterator to another.
2694  * @param __rhs [IN] A %regex_token_iterator to copy.
2695  */
2697  operator=(const regex_token_iterator& __rhs);
2698 
2699  /**
2700  * @brief Compares a %regex_token_iterator to another for equality.
2701  */
2702  bool
2703  operator==(const regex_token_iterator& __rhs) const;
2704 
2705  /**
2706  * @brief Compares a %regex_token_iterator to another for inequality.
2707  */
2708  bool
2709  operator!=(const regex_token_iterator& __rhs) const
2710  { return !(*this == __rhs); }
2711 
2712  /**
2713  * @brief Dereferences a %regex_token_iterator.
2714  */
2715  const value_type&
2716  operator*() const
2717  { return *_M_result; }
2718 
2719  /**
2720  * @brief Selects a %regex_token_iterator member.
2721  */
2722  const value_type*
2723  operator->() const
2724  { return _M_result; }
2725 
2726  /**
2727  * @brief Increments a %regex_token_iterator.
2728  */
2730  operator++();
2731 
2732  /**
2733  * @brief Postincrements a %regex_token_iterator.
2734  */
2737  {
2738  auto __tmp = *this;
2739  ++(*this);
2740  return __tmp;
2741  }
2742 
2743  private:
2745 
2746  void
2747  _M_init(_Bi_iter __a, _Bi_iter __b);
2748 
2749  const value_type&
2750  _M_current_match() const
2751  {
2752  if (_M_subs[_M_n] == -1)
2753  return (*_M_position).prefix();
2754  else
2755  return (*_M_position)[_M_subs[_M_n]];
2756  }
2757 
2758  constexpr bool
2759  _M_end_of_seq() const
2760  { return _M_result == nullptr; }
2761 
2762  // [28.12.2.2.4]
2763  void
2764  _M_normalize_result()
2765  {
2766  if (_M_position != _Position())
2767  _M_result = &_M_current_match();
2768  else if (_M_has_m1)
2769  _M_result = &_M_suffix;
2770  else
2771  _M_result = nullptr;
2772  }
2773 
2774  _Position _M_position;
2775  std::vector<int> _M_subs;
2776  value_type _M_suffix;
2777  std::size_t _M_n;
2778  const value_type* _M_result;
2779 
2780  // Show whether _M_subs contains -1
2781  bool _M_has_m1;
2782  };
2783 
2784  /** @brief Token iterator for C-style NULL-terminated strings. */
2786 
2787  /** @brief Token iterator for standard strings. */
2789 
2790 #ifdef _GLIBCXX_USE_WCHAR_T
2791  /** @brief Token iterator for C-style NULL-terminated wide strings. */
2793 
2794  /** @brief Token iterator for standard wide-character strings. */
2796 #endif
2797 
2798  //@} // group regex
2799 
2800 _GLIBCXX_END_NAMESPACE_CXX11
2801 _GLIBCXX_END_NAMESPACE_VERSION
2802 } // namespace
2803 
2804 #include <bits/regex.tcc>
regex_traits()
Constructs a default traits object.
Definition: regex.h:164
basic_regex< wchar_t > wregex
Standard wide-character regular expressions.
Definition: regex.h:795
size_type max_size() const
Gets the number of matches and submatches.
Definition: regex.h:1628
sub_match< wstring::const_iterator > wssub_match
Regex submatch over a standard wide string.
Definition: regex.h:929
The standard allocator, as per [20.4].
Definition: allocator.h:108
bool operator!=(const regex_token_iterator &__rhs) const
Compares a regex_token_iterator to another for inequality.
Definition: regex.h:2709
regex_token_iterator(const regex_token_iterator &__rhs)
Copy constructs a regex_token_iterator.
Definition: regex.h:2687
regex_token_iterator< const char * > cregex_token_iterator
Token iterator for C-style NULL-terminated strings.
Definition: regex.h:2785
size_type size() const
Gets the number of matches and submatches.
Definition: regex.h:1624
basic_regex & assign(_InputIterator __first, _InputIterator __last, flag_type __flags=ECMAScript)
Assigns a new regular expression to a regex object.
Definition: regex.h:677
The results of a match or search operation.
Definition: regex.h:39
void swap(basic_regex &__rhs)
Swaps the contents of two regular expression objects.
Definition: regex.h:746
const_reference operator[](size_type __sub) const
Gets a sub_match reference for the match or submatch.
Definition: regex.h:1699
constexpr const _Tp * end(initializer_list< _Tp > __ils) noexcept
Return an iterator pointing to one past the last element of the initializer_list. ...
locale_type imbue(locale_type __loc)
Imbues the regex_traits object with a copy of a new locale.
Definition: regex.h:366
const_iterator cbegin() const
Gets an iterator to the start of the sub_match collection.
Definition: regex.h:1748
difference_type length(size_type __sub=0) const
Gets the length of the indicated submatch.
Definition: regex.h:1656
syntax_option_type
This is a bitmask type indicating how to interpret the regex.
Facet for localized string comparison.
regex_iterator operator++(int)
Postincrements a regex_iterator.
Definition: regex.h:2531
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:1803
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:2637
_GLIBCXX17_INLINE constexpr syntax_option_type grep
_GLIBCXX17_INLINE constexpr match_flag_type match_default
difference_type position(size_type __sub=0) const
Gets the offset of the beginning of the indicated submatch.
Definition: regex.h:1671
initializer_list
sub_match< string::const_iterator > ssub_match
Standard regex submatch over a standard string.
Definition: regex.h:922
constexpr const _Tp * begin(initializer_list< _Tp > __ils) noexcept
Return an iterator pointing to the first element of the initializer_list.
ISO C++ entities toplevel namespace is std.
_GLIBCXX17_INLINE constexpr syntax_option_type optimize
_GLIBCXX17_INLINE constexpr syntax_option_type collate
locale_type getloc() const
Gets the locale currently imbued in the regular expression object.
Definition: regex.h:736
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:1946
unsigned int mark_count() const
Gets the number of marked subexpressions within the regular expression.
Definition: regex.h:702
locale_type imbue(locale_type __loc)
Imbues the regular expression object with the given locale.
Definition: regex.h:724
_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:2296
regex_token_iterator< wstring::const_iterator > wsregex_token_iterator
Token iterator for standard wide-character strings.
Definition: regex.h:2795
_GLIBCXX17_INLINE constexpr syntax_option_type awk
string_type str() const
Gets the matching sequence as a string.
Definition: regex.h:870
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
_GLIBCXX17_INLINE constexpr syntax_option_type extended
regex_token_iterator< const wchar_t * > wcregex_token_iterator
Token iterator for C-style NULL-terminated wide strings.
Definition: regex.h:2792
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
basic_regex & assign(basic_regex &&__rhs) noexcept
The move-assignment operator.
Definition: regex.h:601
sub_match< const wchar_t * > wcsub_match
Regex submatch over a C-style null-terminated wide string.
Definition: regex.h:926
_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.
A standard container which offers fixed time access to individual elements in any order...
Definition: stl_vector.h:216
const value_type * operator->() const
Selects a regex_iterator member.
Definition: regex.h:2518
~match_results()
Destroys a match_results object.
Definition: regex.h:1596
back_insert_iterator< _Container > back_inserter(_Container &__x)
void swap(match_results &__that)
Swaps the contents of two match_results.
Definition: regex.h:1851
regex_iterator()
Provides a singular iterator, useful for indicating one-past-the-end of a range.
Definition: regex.h:2458
int compare(const sub_match &__s) const
Compares this and another matched sequence.
Definition: regex.h:887
char_type translate(char_type __c) const
Performs the identity translation.
Definition: regex.h:188
bool empty() const
Indicates if the match_results contains no results.
Definition: regex.h:1637
const_iterator cend() const
Gets an iterator to one-past-the-end of the collection.
Definition: regex.h:1762
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
string_type str(size_type __sub=0) const
Gets the match or submatch converted to a string type.
Definition: regex.h:1684
const _CharT * data() const noexcept
Return const pointer to contents.
basic_regex & operator=(basic_regex &&__rhs) noexcept
Move-assigns one regular expression to another.
Definition: regex.h:544
const_iterator end() const
Gets an iterator to one-past-the-end of the collection.
Definition: regex.h:1755
basic_regex & operator=(const basic_regex &__rhs)
Assigns one regular expression to another.
Definition: regex.h:537
regex_token_iterator operator++(int)
Postincrements a regex_token_iterator.
Definition: regex.h:2736
_Tp * data() noexcept
Definition: stl_vector.h:920
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_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:2655
~basic_regex()
Destroys a basic regular expression.
Definition: regex.h:530
bitset< _Nb > operator|(const bitset< _Nb > &__x, const bitset< _Nb > &__y) noexcept
Global bitwise operations on bitsets.
Definition: bitset:1434
string_type transform(_Fwd_iter __first, _Fwd_iter __last) const
Gets a sort key for a character sequence.
Definition: regex.h:230
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
basic_regex< char > regex
Standard regular expressions.
Definition: regex.h:791
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
const value_type & operator*() const
Dereferences a regex_token_iterator.
Definition: regex.h:2716
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:2148
bitset< _Nb > operator^(const bitset< _Nb > &__x, const bitset< _Nb > &__y) noexcept
Global bitwise operations on bitsets.
Definition: bitset:1443
locale_type getloc() const
Gets a copy of the current locale in use by the regex_traits object.
Definition: regex.h:377
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:2604
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
const_reference prefix() const
Gets a sub_match representing the match prefix.
Definition: regex.h:1716
basic_regex(initializer_list< _Ch_type > __l, flag_type __f=ECMAScript)
Constructs a basic regular expression from an initializer list.
Definition: regex.h:523
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:1990
int compare(const value_type *__s) const
Compares this sub_match to a C-style string.
Definition: regex.h:913
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
static std::size_t length(const char_type *__p)
Gives the length of a C-style string starting at __p.
Definition: regex.h:177
Managing sequences of characters and character-like objects.
_GLIBCXX17_INLINE constexpr syntax_option_type nosubs
bool ready() const
Indicates if the match_results is ready.
Definition: regex.h:1607
Common iterator class.
Forward iterators support a superset of input iterator operations.
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
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
Describes aspects of a regular expression.
Definition: regex.h:87
_GLIBCXX17_INLINE constexpr syntax_option_type icase
allocator_type get_allocator() const
Gets a copy of the allocator.
Definition: regex.h:1837
_GLIBCXX17_INLINE constexpr syntax_option_type basic
size_type size() const noexcept
Returns the number of characters in the string, not including any null-termination.
int compare(const string_type &__s) const
Compares this sub_match to a string.
Definition: regex.h:900
difference_type length() const
Definition: regex.h:844
const value_type * operator->() const
Selects a regex_token_iterator member.
Definition: regex.h:2723
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:2620
bool operator!=(const regex_iterator &__rhs) const
Tests the inequivalence of two regex iterators.
Definition: regex.h:2504
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
const _CharT * c_str() const noexcept
Return const pointer to null-terminated contents.
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:229
bitset< _Nb > operator &(const bitset< _Nb > &__x, const bitset< _Nb > &__y) noexcept
Global bitwise operations on bitsets.
Definition: bitset:1425
match_flag_type
This is a bitmask type indicating regex matching rules.
const value_type & operator*() const
Dereferences a regex_iterator.
Definition: regex.h:2511
int compare(const basic_string &__str) const
Compare to a string.
string_type format(const char_type *__fmt, match_flag_type __flags=regex_constants::format_default) const
Definition: regex.h:1815
_GLIBCXX17_INLINE constexpr match_flag_type format_default
regex_token_iterator< string::const_iterator > sregex_token_iterator
Token iterator for standard strings.
Definition: regex.h:2788
A smart pointer with reference-counted copy semantics.
_GLIBCXX17_INLINE constexpr syntax_option_type ECMAScript
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:2469
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
size_type size() const noexcept
Definition: stl_vector.h:670
const_iterator begin() const
Gets an iterator to the start of the sub_match collection.
Definition: regex.h:1741
flag_type flags() const
Gets the flags used to construct the regular expression or in the last call to assign().
Definition: regex.h:714
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:1922
Struct holding two objects of arbitrary type.
Definition: stl_pair.h:198
void swap(match_results< _Bi_iter, _Alloc > &__lhs, match_results< _Bi_iter, _Alloc > &__rhs)
Swaps two match results.
Definition: regex.h:1960
regex_token_iterator()
Default constructs a regex_token_iterator.
Definition: regex.h:2582
sub_match< const char * > csub_match
Standard regex submatch over a C-style null-terminated string.
Definition: regex.h:919
basic_regex & assign(const basic_regex &__rhs)
the real assignment operator.
Definition: regex.h:588
bool equal(_IIter1 __first1, _IIter1 __last1, _IIter2 __first2, _IIter2 __last2, _BinaryPredicate __binary_pred)
Tests a range for element-wise equality.
_GLIBCXX17_INLINE constexpr syntax_option_type egrep
match_results(const _Alloc &__a=_Alloc())
Constructs a default match_results container.
Definition: regex.h:1567
_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:1791
Primary class template ctype facet.This template class defines classification and conversion function...
Takes a regex and an input string and does the matching.
Definition: regex.h:63
const_reference suffix() const
Gets a sub_match representing the match suffix.
Definition: regex.h:1731