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