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  */
435  basic_regex()
436  : _M_flags(ECMAScript), _M_automaton(nullptr)
437  { }
438 
439  /**
440  * @brief Constructs a basic regular expression from the
441  * sequence [__p, __p + char_traits<_Ch_type>::length(__p))
442  * interpreted according to the flags in @p __f.
443  *
444  * @param __p A pointer to the start of a C-style null-terminated string
445  * containing a regular expression.
446  * @param __f Flags indicating the syntax rules and options.
447  *
448  * @throws regex_error if @p __p is not a valid regular expression.
449  */
450  explicit
451  basic_regex(const _Ch_type* __p, flag_type __f = ECMAScript)
452  : basic_regex(__p, __p + _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  { this->imbue(__rhs.getloc()); }
480 
481  /**
482  * @brief Move-constructs a basic regular expression.
483  *
484  * @param __rhs A @p regex object.
485  *
486  * The implementation is a workaround concerning ABI compatibility. See:
487  * https://gcc.gnu.org/ml/libstdc++/2014-09/msg00067.html
488  */
489  basic_regex(basic_regex&& __rhs)
490  : _M_flags(__rhs._M_flags),
491  _M_original_str(std::move(__rhs._M_original_str))
492  {
493  this->imbue(__rhs.getloc());
494  __rhs._M_automaton.reset();
495  }
496 
497  /**
498  * @brief Constructs a basic regular expression from the string
499  * @p s interpreted according to the flags in @p f.
500  *
501  * @param __s A string containing a regular expression.
502  * @param __f Flags indicating the syntax rules and options.
503  *
504  * @throws regex_error if @p __s is not a valid regular expression.
505  */
506  template<typename _Ch_traits, typename _Ch_alloc>
507  explicit
508  basic_regex(const std::basic_string<_Ch_type, _Ch_traits,
509  _Ch_alloc>& __s,
510  flag_type __f = ECMAScript)
511  : basic_regex(__s.begin(), __s.end(), __f)
512  { }
513 
514  /**
515  * @brief Constructs a basic regular expression from the range
516  * [first, last) interpreted according to the flags in @p f.
517  *
518  * @param __first The start of a range containing a valid regular
519  * expression.
520  * @param __last The end of a range containing a valid regular
521  * expression.
522  * @param __f The format flags of the regular expression.
523  *
524  * @throws regex_error if @p [__first, __last) is not a valid regular
525  * expression.
526  */
527  template<typename _FwdIter>
528  basic_regex(_FwdIter __first, _FwdIter __last,
529  flag_type __f = ECMAScript)
530  : _M_flags(__f),
531  _M_original_str(__first, __last),
532  _M_automaton(__detail::__compile_nfa(_M_original_str.c_str(),
533  _M_original_str.c_str()
534  + _M_original_str.size(),
535  _M_traits,
536  _M_flags))
537  { }
538 
539  /**
540  * @brief Constructs a basic regular expression from an initializer list.
541  *
542  * @param __l The initializer list.
543  * @param __f The format flags of the regular expression.
544  *
545  * @throws regex_error if @p __l is not a valid regular expression.
546  */
547  basic_regex(initializer_list<_Ch_type> __l, flag_type __f = ECMAScript)
548  : basic_regex(__l.begin(), __l.end(), __f)
549  { }
550 
551  /**
552  * @brief Destroys a basic regular expression.
553  */
554  ~basic_regex()
555  { }
556 
557  /**
558  * @brief Assigns one regular expression to another.
559  */
560  basic_regex&
561  operator=(const basic_regex& __rhs)
562  { return this->assign(__rhs); }
563 
564  /**
565  * @brief Move-assigns one regular expression to another.
566  *
567  * The implementation is a workaround concerning ABI compatibility. See:
568  * https://gcc.gnu.org/ml/libstdc++/2014-09/msg00067.html
569  */
570  basic_regex&
571  operator=(basic_regex&& __rhs)
572  { return this->assign(std::move(__rhs)); }
573 
574  /**
575  * @brief Replaces a regular expression with a new one constructed from
576  * a C-style null-terminated string.
577  *
578  * @param __p A pointer to the start of a null-terminated C-style string
579  * containing a regular expression.
580  */
581  basic_regex&
582  operator=(const _Ch_type* __p)
583  { return this->assign(__p, flags()); }
584 
585  /**
586  * @brief Replaces a regular expression with a new one constructed from
587  * a string.
588  *
589  * @param __s A pointer to a string containing a regular expression.
590  */
591  template<typename _Ch_typeraits, typename _Alloc>
592  basic_regex&
593  operator=(const basic_string<_Ch_type, _Ch_typeraits, _Alloc>& __s)
594  { return this->assign(__s, flags()); }
595 
596  // [7.8.3] assign
597  /**
598  * @brief the real assignment operator.
599  *
600  * @param __rhs Another regular expression object.
601  */
602  basic_regex&
603  assign(const basic_regex& __rhs)
604  {
605  _M_flags = __rhs._M_flags;
606  _M_original_str = __rhs._M_original_str;
607  this->imbue(__rhs.getloc());
608  return *this;
609  }
610 
611  /**
612  * @brief The move-assignment operator.
613  *
614  * @param __rhs Another regular expression object.
615  *
616  * The implementation is a workaround concerning ABI compatibility. See:
617  * https://gcc.gnu.org/ml/libstdc++/2014-09/msg00067.html
618  */
619  basic_regex&
620  assign(basic_regex&& __rhs)
621  {
622  _M_flags = __rhs._M_flags;
623  _M_original_str = std::move(__rhs._M_original_str);
624  __rhs._M_automaton.reset();
625  this->imbue(__rhs.getloc());
626  }
627 
628  /**
629  * @brief Assigns a new regular expression to a regex object from a
630  * C-style null-terminated string containing a regular expression
631  * pattern.
632  *
633  * @param __p A pointer to a C-style null-terminated string containing
634  * a regular expression pattern.
635  * @param __flags Syntax option flags.
636  *
637  * @throws regex_error if __p does not contain a valid regular
638  * expression pattern interpreted according to @p __flags. If
639  * regex_error is thrown, *this remains unchanged.
640  */
641  basic_regex&
642  assign(const _Ch_type* __p, flag_type __flags = ECMAScript)
643  { return this->assign(string_type(__p), __flags); }
644 
645  /**
646  * @brief Assigns a new regular expression to a regex object from a
647  * C-style string containing a regular expression pattern.
648  *
649  * @param __p A pointer to a C-style string containing a
650  * regular expression pattern.
651  * @param __len The length of the regular expression pattern string.
652  * @param __flags Syntax option flags.
653  *
654  * @throws regex_error if p does not contain a valid regular
655  * expression pattern interpreted according to @p __flags. If
656  * regex_error is thrown, *this remains unchanged.
657  */
658  basic_regex&
659  assign(const _Ch_type* __p, std::size_t __len, flag_type __flags)
660  { return this->assign(string_type(__p, __len), __flags); }
661 
662  /**
663  * @brief Assigns a new regular expression to a regex object from a
664  * string containing a regular expression pattern.
665  *
666  * @param __s A string containing a regular expression pattern.
667  * @param __flags Syntax option flags.
668  *
669  * @throws regex_error if __s does not contain a valid regular
670  * expression pattern interpreted according to @p __flags. If
671  * regex_error is thrown, *this remains unchanged.
672  */
673  template<typename _Ch_typeraits, typename _Alloc>
674  basic_regex&
675  assign(const basic_string<_Ch_type, _Ch_typeraits, _Alloc>& __s,
676  flag_type __flags = ECMAScript)
677  {
678  _M_flags = __flags;
679  _M_original_str.assign(__s.begin(), __s.end());
680  auto __p = _M_original_str.c_str();
681  _M_automaton = __detail::__compile_nfa(__p,
682  __p + _M_original_str.size(),
683  _M_traits, _M_flags);
684  return *this;
685  }
686 
687  /**
688  * @brief Assigns a new regular expression to a regex object.
689  *
690  * @param __first The start of a range containing a valid regular
691  * expression.
692  * @param __last The end of a range containing a valid regular
693  * expression.
694  * @param __flags Syntax option flags.
695  *
696  * @throws regex_error if p does not contain a valid regular
697  * expression pattern interpreted according to @p __flags. If
698  * regex_error is thrown, the object remains unchanged.
699  */
700  template<typename _InputIterator>
701  basic_regex&
702  assign(_InputIterator __first, _InputIterator __last,
703  flag_type __flags = ECMAScript)
704  { return this->assign(string_type(__first, __last), __flags); }
705 
706  /**
707  * @brief Assigns a new regular expression to a regex object.
708  *
709  * @param __l An initializer list representing a regular expression.
710  * @param __flags Syntax option flags.
711  *
712  * @throws regex_error if @p __l does not contain a valid
713  * regular expression pattern interpreted according to @p
714  * __flags. If regex_error is thrown, the object remains
715  * unchanged.
716  */
717  basic_regex&
718  assign(initializer_list<_Ch_type> __l, flag_type __flags = ECMAScript)
719  { return this->assign(__l.begin(), __l.end(), __flags); }
720 
721  // [7.8.4] const operations
722  /**
723  * @brief Gets the number of marked subexpressions within the regular
724  * expression.
725  */
726  unsigned int
727  mark_count() const
728  { return _M_automaton->_M_sub_count() - 1; }
729 
730  /**
731  * @brief Gets the flags used to construct the regular expression
732  * or in the last call to assign().
733  */
734  flag_type
735  flags() const
736  { return _M_flags; }
737 
738  // [7.8.5] locale
739  /**
740  * @brief Imbues the regular expression object with the given locale.
741  *
742  * @param __loc A locale.
743  */
744  locale_type
745  imbue(locale_type __loc)
746  {
747  auto __ret = _M_traits.imbue(__loc);
748  this->assign(_M_original_str, _M_flags);
749  return __ret;
750  }
751 
752  /**
753  * @brief Gets the locale currently imbued in the regular expression
754  * object.
755  */
756  locale_type
757  getloc() const
758  { return _M_traits.getloc(); }
759 
760  // [7.8.6] swap
761  /**
762  * @brief Swaps the contents of two regular expression objects.
763  *
764  * @param __rhs Another regular expression object.
765  */
766  void
767  swap(basic_regex& __rhs)
768  {
769  std::swap(_M_flags, __rhs._M_flags);
770  std::swap(_M_original_str, __rhs._M_original_str);
771  this->imbue(__rhs.imbue(this->getloc()));
772  }
773 
774 #ifdef _GLIBCXX_DEBUG
775  void
776  _M_dot(std::ostream& __ostr)
777  { _M_automaton->_M_dot(__ostr); }
778 #endif
779 
780  protected:
781  typedef std::shared_ptr<__detail::_NFA<_Rx_traits>> _AutomatonPtr;
782 
783  template<typename _Bp, typename _Ap, typename _Cp, typename _Rp,
784  __detail::_RegexExecutorPolicy, bool>
785  friend bool
786  __detail::__regex_algo_impl(_Bp, _Bp, match_results<_Bp, _Ap>&,
787  const basic_regex<_Cp, _Rp>&,
789 
790  template<typename, typename, typename, bool>
791  friend class __detail::_Executor;
792 
793  flag_type _M_flags;
794  _Rx_traits _M_traits;
795  basic_string<_Ch_type> _M_original_str;
796  _AutomatonPtr _M_automaton;
797  };
798 
799  /** @brief Standard regular expressions. */
801 
802 #ifdef _GLIBCXX_USE_WCHAR_T
803  /** @brief Standard wide-character regular expressions. */
805 #endif
806 
807 
808  // [7.8.6] basic_regex swap
809  /**
810  * @brief Swaps the contents of two regular expression objects.
811  * @param __lhs First regular expression.
812  * @param __rhs Second regular expression.
813  */
814  template<typename _Ch_type, typename _Rx_traits>
815  inline void
818  { __lhs.swap(__rhs); }
819 
820 
821  // [7.9] Class template sub_match
822  /**
823  * A sequence of characters matched by a particular marked sub-expression.
824  *
825  * An object of this class is essentially a pair of iterators marking a
826  * matched subexpression within a regular expression pattern match. Such
827  * objects can be converted to and compared with std::basic_string objects
828  * of a similar base character type as the pattern matched by the regular
829  * expression.
830  *
831  * The iterators that make up the pair are the usual half-open interval
832  * referencing the actual original pattern matched.
833  */
834  template<typename _BiIter>
835  class sub_match : public std::pair<_BiIter, _BiIter>
836  {
837  typedef iterator_traits<_BiIter> __iter_traits;
838 
839  public:
840  typedef typename __iter_traits::value_type value_type;
841  typedef typename __iter_traits::difference_type difference_type;
842  typedef _BiIter iterator;
843  typedef std::basic_string<value_type> string_type;
844 
845  bool matched;
846 
847  constexpr sub_match() : matched() { }
848 
849  /**
850  * Gets the length of the matching sequence.
851  */
852  difference_type
853  length() const
854  { return this->matched ? std::distance(this->first, this->second) : 0; }
855 
856  /**
857  * @brief Gets the matching sequence as a string.
858  *
859  * @returns the matching sequence as a string.
860  *
861  * This is the implicit conversion operator. It is identical to the
862  * str() member function except that it will want to pop up in
863  * unexpected places and cause a great deal of confusion and cursing
864  * from the unwary.
865  */
866  operator string_type() const
867  {
868  return this->matched
869  ? string_type(this->first, this->second)
870  : string_type();
871  }
872 
873  /**
874  * @brief Gets the matching sequence as a string.
875  *
876  * @returns the matching sequence as a string.
877  */
878  string_type
879  str() const
880  {
881  return this->matched
882  ? string_type(this->first, this->second)
883  : string_type();
884  }
885 
886  /**
887  * @brief Compares this and another matched sequence.
888  *
889  * @param __s Another matched sequence to compare to this one.
890  *
891  * @retval <0 this matched sequence will collate before @p __s.
892  * @retval =0 this matched sequence is equivalent to @p __s.
893  * @retval <0 this matched sequence will collate after @p __s.
894  */
895  int
896  compare(const sub_match& __s) const
897  { return this->str().compare(__s.str()); }
898 
899  /**
900  * @brief Compares this sub_match to a string.
901  *
902  * @param __s A string to compare to this sub_match.
903  *
904  * @retval <0 this matched sequence will collate before @p __s.
905  * @retval =0 this matched sequence is equivalent to @p __s.
906  * @retval <0 this matched sequence will collate after @p __s.
907  */
908  int
909  compare(const string_type& __s) const
910  { return this->str().compare(__s); }
911 
912  /**
913  * @brief Compares this sub_match to a C-style string.
914  *
915  * @param __s A C-style string to compare to this sub_match.
916  *
917  * @retval <0 this matched sequence will collate before @p __s.
918  * @retval =0 this matched sequence is equivalent to @p __s.
919  * @retval <0 this matched sequence will collate after @p __s.
920  */
921  int
922  compare(const value_type* __s) const
923  { return this->str().compare(__s); }
924  };
925 
926 
927  /** @brief Standard regex submatch over a C-style null-terminated string. */
929 
930  /** @brief Standard regex submatch over a standard string. */
932 
933 #ifdef _GLIBCXX_USE_WCHAR_T
934  /** @brief Regex submatch over a C-style null-terminated wide string. */
936 
937  /** @brief Regex submatch over a standard wide string. */
939 #endif
940 
941  // [7.9.2] sub_match non-member operators
942 
943  /**
944  * @brief Tests the equivalence of two regular expression submatches.
945  * @param __lhs First regular expression submatch.
946  * @param __rhs Second regular expression submatch.
947  * @returns true if @a __lhs is equivalent to @a __rhs, false otherwise.
948  */
949  template<typename _BiIter>
950  inline bool
951  operator==(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs)
952  { return __lhs.compare(__rhs) == 0; }
953 
954  /**
955  * @brief Tests the inequivalence of two regular expression submatches.
956  * @param __lhs First regular expression submatch.
957  * @param __rhs Second regular expression submatch.
958  * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise.
959  */
960  template<typename _BiIter>
961  inline bool
962  operator!=(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs)
963  { return __lhs.compare(__rhs) != 0; }
964 
965  /**
966  * @brief Tests the ordering of two regular expression submatches.
967  * @param __lhs First regular expression submatch.
968  * @param __rhs Second regular expression submatch.
969  * @returns true if @a __lhs precedes @a __rhs, false otherwise.
970  */
971  template<typename _BiIter>
972  inline bool
973  operator<(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs)
974  { return __lhs.compare(__rhs) < 0; }
975 
976  /**
977  * @brief Tests the ordering of two regular expression submatches.
978  * @param __lhs First regular expression submatch.
979  * @param __rhs Second regular expression submatch.
980  * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
981  */
982  template<typename _BiIter>
983  inline bool
984  operator<=(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs)
985  { return __lhs.compare(__rhs) <= 0; }
986 
987  /**
988  * @brief Tests the ordering of two regular expression submatches.
989  * @param __lhs First regular expression submatch.
990  * @param __rhs Second regular expression submatch.
991  * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
992  */
993  template<typename _BiIter>
994  inline bool
996  { return __lhs.compare(__rhs) >= 0; }
997 
998  /**
999  * @brief Tests the ordering of two regular expression submatches.
1000  * @param __lhs First regular expression submatch.
1001  * @param __rhs Second regular expression submatch.
1002  * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
1003  */
1004  template<typename _BiIter>
1005  inline bool
1007  { return __lhs.compare(__rhs) > 0; }
1008 
1009  // Alias for sub_match'd string.
1010  template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1011  using __sub_match_string = basic_string<
1012  typename iterator_traits<_Bi_iter>::value_type,
1013  _Ch_traits, _Ch_alloc>;
1014 
1015  /**
1016  * @brief Tests the equivalence of a string and a regular expression
1017  * submatch.
1018  * @param __lhs A string.
1019  * @param __rhs A regular expression submatch.
1020  * @returns true if @a __lhs is equivalent to @a __rhs, false otherwise.
1021  */
1022  template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1023  inline bool
1025  const sub_match<_Bi_iter>& __rhs)
1026  { return __rhs.compare(__lhs.c_str()) == 0; }
1027 
1028  /**
1029  * @brief Tests the inequivalence of a string and a regular expression
1030  * submatch.
1031  * @param __lhs A string.
1032  * @param __rhs A regular expression submatch.
1033  * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise.
1034  */
1035  template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1036  inline bool
1038  const sub_match<_Bi_iter>& __rhs)
1039  { return !(__lhs == __rhs); }
1040 
1041  /**
1042  * @brief Tests the ordering of a string and a regular expression submatch.
1043  * @param __lhs A string.
1044  * @param __rhs A regular expression submatch.
1045  * @returns true if @a __lhs precedes @a __rhs, false otherwise.
1046  */
1047  template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1048  inline bool
1049  operator<(const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __lhs,
1050  const sub_match<_Bi_iter>& __rhs)
1051  { return __rhs.compare(__lhs.c_str()) > 0; }
1052 
1053  /**
1054  * @brief Tests the ordering of a string and a regular expression submatch.
1055  * @param __lhs A string.
1056  * @param __rhs A regular expression submatch.
1057  * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
1058  */
1059  template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1060  inline bool
1062  const sub_match<_Bi_iter>& __rhs)
1063  { return __rhs < __lhs; }
1064 
1065  /**
1066  * @brief Tests the ordering of a string and a regular expression submatch.
1067  * @param __lhs A string.
1068  * @param __rhs A regular expression submatch.
1069  * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
1070  */
1071  template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1072  inline bool
1074  const sub_match<_Bi_iter>& __rhs)
1075  { return !(__lhs < __rhs); }
1076 
1077  /**
1078  * @brief Tests the ordering of a string and a regular expression submatch.
1079  * @param __lhs A string.
1080  * @param __rhs A regular expression submatch.
1081  * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
1082  */
1083  template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1084  inline bool
1085  operator<=(const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __lhs,
1086  const sub_match<_Bi_iter>& __rhs)
1087  { return !(__rhs < __lhs); }
1088 
1089  /**
1090  * @brief Tests the equivalence of a regular expression submatch and a
1091  * string.
1092  * @param __lhs A regular expression submatch.
1093  * @param __rhs A string.
1094  * @returns true if @a __lhs is equivalent to @a __rhs, false otherwise.
1095  */
1096  template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1097  inline bool
1098  operator==(const sub_match<_Bi_iter>& __lhs,
1100  { return __lhs.compare(__rhs.c_str()) == 0; }
1101 
1102  /**
1103  * @brief Tests the inequivalence of a regular expression submatch and a
1104  * string.
1105  * @param __lhs A regular expression submatch.
1106  * @param __rhs A string.
1107  * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise.
1108  */
1109  template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1110  inline bool
1111  operator!=(const sub_match<_Bi_iter>& __lhs,
1113  { return !(__lhs == __rhs); }
1114 
1115  /**
1116  * @brief Tests the ordering of a regular expression submatch and a string.
1117  * @param __lhs A regular expression submatch.
1118  * @param __rhs A string.
1119  * @returns true if @a __lhs precedes @a __rhs, false otherwise.
1120  */
1121  template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc>
1122  inline bool
1123  operator<(const sub_match<_Bi_iter>& __lhs,
1125  { return __lhs.compare(__rhs.c_str()) < 0; }
1126 
1127  /**
1128  * @brief Tests the ordering of a regular expression submatch and a string.
1129  * @param __lhs A regular expression submatch.
1130  * @param __rhs A string.
1131  * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
1132  */
1133  template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc>
1134  inline bool
1137  { return __rhs < __lhs; }
1138 
1139  /**
1140  * @brief Tests the ordering of a regular expression submatch and a string.
1141  * @param __lhs A regular expression submatch.
1142  * @param __rhs A string.
1143  * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
1144  */
1145  template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc>
1146  inline bool
1149  { return !(__lhs < __rhs); }
1150 
1151  /**
1152  * @brief Tests the ordering of a regular expression submatch and a string.
1153  * @param __lhs A regular expression submatch.
1154  * @param __rhs A string.
1155  * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
1156  */
1157  template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc>
1158  inline bool
1159  operator<=(const sub_match<_Bi_iter>& __lhs,
1161  { return !(__rhs < __lhs); }
1162 
1163  /**
1164  * @brief Tests the equivalence of a C string and a regular expression
1165  * submatch.
1166  * @param __lhs A C string.
1167  * @param __rhs A regular expression submatch.
1168  * @returns true if @a __lhs is equivalent to @a __rhs, false otherwise.
1169  */
1170  template<typename _Bi_iter>
1171  inline bool
1172  operator==(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
1173  const sub_match<_Bi_iter>& __rhs)
1174  { return __rhs.compare(__lhs) == 0; }
1175 
1176  /**
1177  * @brief Tests the inequivalence of an iterator value and a regular
1178  * expression submatch.
1179  * @param __lhs A regular expression submatch.
1180  * @param __rhs A string.
1181  * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise.
1182  */
1183  template<typename _Bi_iter>
1184  inline bool
1185  operator!=(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
1186  const sub_match<_Bi_iter>& __rhs)
1187  { return !(__lhs == __rhs); }
1188 
1189  /**
1190  * @brief Tests the ordering of a string and a regular expression submatch.
1191  * @param __lhs A string.
1192  * @param __rhs A regular expression submatch.
1193  * @returns true if @a __lhs precedes @a __rhs, false otherwise.
1194  */
1195  template<typename _Bi_iter>
1196  inline bool
1197  operator<(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
1198  const sub_match<_Bi_iter>& __rhs)
1199  { return __rhs.compare(__lhs) > 0; }
1200 
1201  /**
1202  * @brief Tests the ordering of a string and a regular expression submatch.
1203  * @param __lhs A string.
1204  * @param __rhs A regular expression submatch.
1205  * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
1206  */
1207  template<typename _Bi_iter>
1208  inline bool
1209  operator>(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
1210  const sub_match<_Bi_iter>& __rhs)
1211  { return __rhs < __lhs; }
1212 
1213  /**
1214  * @brief Tests the ordering of a string and a regular expression submatch.
1215  * @param __lhs A string.
1216  * @param __rhs A regular expression submatch.
1217  * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
1218  */
1219  template<typename _Bi_iter>
1220  inline bool
1221  operator>=(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
1222  const sub_match<_Bi_iter>& __rhs)
1223  { return !(__lhs < __rhs); }
1224 
1225  /**
1226  * @brief Tests the ordering of a string and a regular expression submatch.
1227  * @param __lhs A string.
1228  * @param __rhs A regular expression submatch.
1229  * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
1230  */
1231  template<typename _Bi_iter>
1232  inline bool
1233  operator<=(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
1234  const sub_match<_Bi_iter>& __rhs)
1235  { return !(__rhs < __lhs); }
1236 
1237  /**
1238  * @brief Tests the equivalence of a regular expression submatch and a
1239  * string.
1240  * @param __lhs A regular expression submatch.
1241  * @param __rhs A pointer to a string?
1242  * @returns true if @a __lhs is equivalent to @a __rhs, false otherwise.
1243  */
1244  template<typename _Bi_iter>
1245  inline bool
1246  operator==(const sub_match<_Bi_iter>& __lhs,
1247  typename iterator_traits<_Bi_iter>::value_type const* __rhs)
1248  { return __lhs.compare(__rhs) == 0; }
1249 
1250  /**
1251  * @brief Tests the inequivalence of a regular expression submatch and a
1252  * string.
1253  * @param __lhs A regular expression submatch.
1254  * @param __rhs A pointer to a string.
1255  * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise.
1256  */
1257  template<typename _Bi_iter>
1258  inline bool
1259  operator!=(const sub_match<_Bi_iter>& __lhs,
1260  typename iterator_traits<_Bi_iter>::value_type const* __rhs)
1261  { return !(__lhs == __rhs); }
1262 
1263  /**
1264  * @brief Tests the ordering of a regular expression submatch and a string.
1265  * @param __lhs A regular expression submatch.
1266  * @param __rhs A string.
1267  * @returns true if @a __lhs precedes @a __rhs, false otherwise.
1268  */
1269  template<typename _Bi_iter>
1270  inline bool
1271  operator<(const sub_match<_Bi_iter>& __lhs,
1272  typename iterator_traits<_Bi_iter>::value_type const* __rhs)
1273  { return __lhs.compare(__rhs) < 0; }
1274 
1275  /**
1276  * @brief Tests the ordering of a regular expression submatch and a string.
1277  * @param __lhs A regular expression submatch.
1278  * @param __rhs A string.
1279  * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
1280  */
1281  template<typename _Bi_iter>
1282  inline bool
1284  typename iterator_traits<_Bi_iter>::value_type const* __rhs)
1285  { return __rhs < __lhs; }
1286 
1287  /**
1288  * @brief Tests the ordering of a regular expression submatch and a string.
1289  * @param __lhs A regular expression submatch.
1290  * @param __rhs A string.
1291  * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
1292  */
1293  template<typename _Bi_iter>
1294  inline bool
1296  typename iterator_traits<_Bi_iter>::value_type const* __rhs)
1297  { return !(__lhs < __rhs); }
1298 
1299  /**
1300  * @brief Tests the ordering of a regular expression submatch and a string.
1301  * @param __lhs A regular expression submatch.
1302  * @param __rhs A string.
1303  * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
1304  */
1305  template<typename _Bi_iter>
1306  inline bool
1307  operator<=(const sub_match<_Bi_iter>& __lhs,
1308  typename iterator_traits<_Bi_iter>::value_type const* __rhs)
1309  { return !(__rhs < __lhs); }
1310 
1311  /**
1312  * @brief Tests the equivalence of a string and a regular expression
1313  * submatch.
1314  * @param __lhs A string.
1315  * @param __rhs A regular expression submatch.
1316  * @returns true if @a __lhs is equivalent to @a __rhs, false otherwise.
1317  */
1318  template<typename _Bi_iter>
1319  inline bool
1320  operator==(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
1321  const sub_match<_Bi_iter>& __rhs)
1322  {
1323  typedef typename sub_match<_Bi_iter>::string_type string_type;
1324  return __rhs.compare(string_type(1, __lhs)) == 0;
1325  }
1326 
1327  /**
1328  * @brief Tests the inequivalence of a string and a regular expression
1329  * submatch.
1330  * @param __lhs A string.
1331  * @param __rhs A regular expression submatch.
1332  * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise.
1333  */
1334  template<typename _Bi_iter>
1335  inline bool
1336  operator!=(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
1337  const sub_match<_Bi_iter>& __rhs)
1338  { return !(__lhs == __rhs); }
1339 
1340  /**
1341  * @brief Tests the ordering of a string and a regular expression submatch.
1342  * @param __lhs A string.
1343  * @param __rhs A regular expression submatch.
1344  * @returns true if @a __lhs precedes @a __rhs, false otherwise.
1345  */
1346  template<typename _Bi_iter>
1347  inline bool
1348  operator<(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
1349  const sub_match<_Bi_iter>& __rhs)
1350  {
1351  typedef typename sub_match<_Bi_iter>::string_type string_type;
1352  return __rhs.compare(string_type(1, __lhs)) > 0;
1353  }
1354 
1355  /**
1356  * @brief Tests the ordering of a string and a regular expression submatch.
1357  * @param __lhs A string.
1358  * @param __rhs A regular expression submatch.
1359  * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
1360  */
1361  template<typename _Bi_iter>
1362  inline bool
1363  operator>(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
1364  const sub_match<_Bi_iter>& __rhs)
1365  { return __rhs < __lhs; }
1366 
1367  /**
1368  * @brief Tests the ordering of a string and a regular expression submatch.
1369  * @param __lhs A string.
1370  * @param __rhs A regular expression submatch.
1371  * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
1372  */
1373  template<typename _Bi_iter>
1374  inline bool
1375  operator>=(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
1376  const sub_match<_Bi_iter>& __rhs)
1377  { return !(__lhs < __rhs); }
1378 
1379  /**
1380  * @brief Tests the ordering of a string and a regular expression submatch.
1381  * @param __lhs A string.
1382  * @param __rhs A regular expression submatch.
1383  * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
1384  */
1385  template<typename _Bi_iter>
1386  inline bool
1387  operator<=(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
1388  const sub_match<_Bi_iter>& __rhs)
1389  { return !(__rhs < __lhs); }
1390 
1391  /**
1392  * @brief Tests the equivalence of a regular expression submatch and a
1393  * string.
1394  * @param __lhs A regular expression submatch.
1395  * @param __rhs A const string reference.
1396  * @returns true if @a __lhs is equivalent to @a __rhs, false otherwise.
1397  */
1398  template<typename _Bi_iter>
1399  inline bool
1400  operator==(const sub_match<_Bi_iter>& __lhs,
1401  typename iterator_traits<_Bi_iter>::value_type const& __rhs)
1402  {
1403  typedef typename sub_match<_Bi_iter>::string_type string_type;
1404  return __lhs.compare(string_type(1, __rhs)) == 0;
1405  }
1406 
1407  /**
1408  * @brief Tests the inequivalence of a regular expression submatch and a
1409  * string.
1410  * @param __lhs A regular expression submatch.
1411  * @param __rhs A const string reference.
1412  * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise.
1413  */
1414  template<typename _Bi_iter>
1415  inline bool
1416  operator!=(const sub_match<_Bi_iter>& __lhs,
1417  typename iterator_traits<_Bi_iter>::value_type const& __rhs)
1418  { return !(__lhs == __rhs); }
1419 
1420  /**
1421  * @brief Tests the ordering of a regular expression submatch and a string.
1422  * @param __lhs A regular expression submatch.
1423  * @param __rhs A const string reference.
1424  * @returns true if @a __lhs precedes @a __rhs, false otherwise.
1425  */
1426  template<typename _Bi_iter>
1427  inline bool
1428  operator<(const sub_match<_Bi_iter>& __lhs,
1429  typename iterator_traits<_Bi_iter>::value_type const& __rhs)
1430  {
1431  typedef typename sub_match<_Bi_iter>::string_type string_type;
1432  return __lhs.compare(string_type(1, __rhs)) < 0;
1433  }
1434 
1435  /**
1436  * @brief Tests the ordering of a regular expression submatch and a string.
1437  * @param __lhs A regular expression submatch.
1438  * @param __rhs A const string reference.
1439  * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
1440  */
1441  template<typename _Bi_iter>
1442  inline bool
1444  typename iterator_traits<_Bi_iter>::value_type const& __rhs)
1445  { return __rhs < __lhs; }
1446 
1447  /**
1448  * @brief Tests the ordering of a regular expression submatch and a string.
1449  * @param __lhs A regular expression submatch.
1450  * @param __rhs A const string reference.
1451  * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
1452  */
1453  template<typename _Bi_iter>
1454  inline bool
1456  typename iterator_traits<_Bi_iter>::value_type const& __rhs)
1457  { return !(__lhs < __rhs); }
1458 
1459  /**
1460  * @brief Tests the ordering of a regular expression submatch and a string.
1461  * @param __lhs A regular expression submatch.
1462  * @param __rhs A const string reference.
1463  * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
1464  */
1465  template<typename _Bi_iter>
1466  inline bool
1467  operator<=(const sub_match<_Bi_iter>& __lhs,
1468  typename iterator_traits<_Bi_iter>::value_type const& __rhs)
1469  { return !(__rhs < __lhs); }
1470 
1471  /**
1472  * @brief Inserts a matched string into an output stream.
1473  *
1474  * @param __os The output stream.
1475  * @param __m A submatch string.
1476  *
1477  * @returns the output stream with the submatch string inserted.
1478  */
1479  template<typename _Ch_type, typename _Ch_traits, typename _Bi_iter>
1480  inline
1481  basic_ostream<_Ch_type, _Ch_traits>&
1482  operator<<(basic_ostream<_Ch_type, _Ch_traits>& __os,
1483  const sub_match<_Bi_iter>& __m)
1484  { return __os << __m.str(); }
1485 
1486  // [7.10] Class template match_results
1487 
1488  /*
1489  * Special sub_match object representing an unmatched sub-expression.
1490  */
1491  template<typename _Bi_iter>
1492  inline const sub_match<_Bi_iter>&
1493  __unmatched_sub()
1494  {
1495  static const sub_match<_Bi_iter> __unmatched = sub_match<_Bi_iter>();
1496  return __unmatched;
1497  }
1498 
1499  /**
1500  * @brief The results of a match or search operation.
1501  *
1502  * A collection of character sequences representing the result of a regular
1503  * expression match. Storage for the collection is allocated and freed as
1504  * necessary by the member functions of class template match_results.
1505  *
1506  * This class satisfies the Sequence requirements, with the exception that
1507  * only the operations defined for a const-qualified Sequence are supported.
1508  *
1509  * The sub_match object stored at index 0 represents sub-expression 0, i.e.
1510  * the whole match. In this case the %sub_match member matched is always true.
1511  * The sub_match object stored at index n denotes what matched the marked
1512  * sub-expression n within the matched expression. If the sub-expression n
1513  * participated in a regular expression match then the %sub_match member
1514  * matched evaluates to true, and members first and second denote the range
1515  * of characters [first, second) which formed that match. Otherwise matched
1516  * is false, and members first and second point to the end of the sequence
1517  * that was searched.
1518  *
1519  * @nosubgrouping
1520  */
1521  template<typename _Bi_iter,
1522  typename _Alloc = allocator<sub_match<_Bi_iter> > >
1523  class match_results
1524  : private std::vector<sub_match<_Bi_iter>, _Alloc>
1525  {
1526  private:
1527  /*
1528  * The vector base is empty if this does not represent a successful match.
1529  * Otherwise it contains n+3 elements where n is the number of marked
1530  * sub-expressions:
1531  * [0] entire match
1532  * [1] 1st marked subexpression
1533  * ...
1534  * [n] nth marked subexpression
1535  * [n+1] prefix
1536  * [n+2] suffix
1537  */
1538  typedef std::vector<sub_match<_Bi_iter>, _Alloc> _Base_type;
1539  typedef std::iterator_traits<_Bi_iter> __iter_traits;
1540  typedef regex_constants::match_flag_type match_flag_type;
1541 
1542  public:
1543  /**
1544  * @name 10.? Public Types
1545  */
1546  //@{
1547  typedef sub_match<_Bi_iter> value_type;
1548  typedef const value_type& const_reference;
1549  typedef const_reference reference;
1550  typedef typename _Base_type::const_iterator const_iterator;
1551  typedef const_iterator iterator;
1552  typedef typename __iter_traits::difference_type difference_type;
1553  typedef typename allocator_traits<_Alloc>::size_type size_type;
1554  typedef _Alloc allocator_type;
1555  typedef typename __iter_traits::value_type char_type;
1556  typedef std::basic_string<char_type> string_type;
1557  //@}
1558 
1559  public:
1560  /**
1561  * @name 28.10.1 Construction, Copying, and Destruction
1562  */
1563  //@{
1564 
1565  /**
1566  * @brief Constructs a default %match_results container.
1567  * @post size() returns 0 and str() returns an empty string.
1568  */
1569  explicit
1570  match_results(const _Alloc& __a = _Alloc())
1571  : _Base_type(__a), _M_in_iterator(false)
1572  { }
1573 
1574  /**
1575  * @brief Copy constructs a %match_results.
1576  */
1578  : _Base_type(__rhs), _M_in_iterator(false)
1579  { }
1580 
1581  /**
1582  * @brief Move constructs a %match_results.
1583  */
1584  match_results(match_results&& __rhs) noexcept
1585  : _Base_type(std::move(__rhs)), _M_in_iterator(false)
1586  { }
1587 
1588  /**
1589  * @brief Assigns rhs to *this.
1590  */
1591  match_results&
1592  operator=(const match_results& __rhs)
1593  {
1594  match_results(__rhs).swap(*this);
1595  return *this;
1596  }
1597 
1598  /**
1599  * @brief Move-assigns rhs to *this.
1600  */
1601  match_results&
1603  {
1604  match_results(std::move(__rhs)).swap(*this);
1605  return *this;
1606  }
1607 
1608  /**
1609  * @brief Destroys a %match_results object.
1610  */
1612  { }
1613 
1614  //@}
1615 
1616  // 28.10.2, state:
1617  /**
1618  * @brief Indicates if the %match_results is ready.
1619  * @retval true The object has a fully-established result state.
1620  * @retval false The object is not ready.
1621  */
1622  bool ready() const { return !_Base_type::empty(); }
1623 
1624  /**
1625  * @name 28.10.2 Size
1626  */
1627  //@{
1628 
1629  /**
1630  * @brief Gets the number of matches and submatches.
1631  *
1632  * The number of matches for a given regular expression will be either 0
1633  * if there was no match or mark_count() + 1 if a match was successful.
1634  * Some matches may be empty.
1635  *
1636  * @returns the number of matches found.
1637  */
1638  size_type
1639  size() const
1640  {
1641  size_type __size = _Base_type::size();
1642  return (__size && _Base_type::operator[](0).matched) ? __size - 2 : 0;
1643  }
1644 
1645  size_type
1646  max_size() const
1647  { return _Base_type::max_size(); }
1648 
1649  /**
1650  * @brief Indicates if the %match_results contains no results.
1651  * @retval true The %match_results object is empty.
1652  * @retval false The %match_results object is not empty.
1653  */
1654  bool
1655  empty() const
1656  { return size() == 0; }
1657 
1658  //@}
1659 
1660  /**
1661  * @name 10.3 Element Access
1662  */
1663  //@{
1664 
1665  /**
1666  * @brief Gets the length of the indicated submatch.
1667  * @param __sub indicates the submatch.
1668  * @pre ready() == true
1669  *
1670  * This function returns the length of the indicated submatch, or the
1671  * length of the entire match if @p __sub is zero (the default).
1672  */
1673  difference_type
1674  length(size_type __sub = 0) const
1675  { return (*this)[__sub].length(); }
1676 
1677  /**
1678  * @brief Gets the offset of the beginning of the indicated submatch.
1679  * @param __sub indicates the submatch.
1680  * @pre ready() == true
1681  *
1682  * This function returns the offset from the beginning of the target
1683  * sequence to the beginning of the submatch, unless the value of @p __sub
1684  * is zero (the default), in which case this function returns the offset
1685  * from the beginning of the target sequence to the beginning of the
1686  * match.
1687  *
1688  * Returns -1 if @p __sub is out of range.
1689  */
1690  difference_type
1691  position(size_type __sub = 0) const
1692  {
1693  // [28.12.1.4.5]
1694  if (_M_in_iterator)
1695  return __sub < size() ? std::distance(_M_begin,
1696  (*this)[__sub].first) : -1;
1697  else
1698  return __sub < size() ? std::distance(this->prefix().first,
1699  (*this)[__sub].first) : -1;
1700  }
1701 
1702  /**
1703  * @brief Gets the match or submatch converted to a string type.
1704  * @param __sub indicates the submatch.
1705  * @pre ready() == true
1706  *
1707  * This function gets the submatch (or match, if @p __sub is
1708  * zero) extracted from the target range and converted to the
1709  * associated string type.
1710  */
1711  string_type
1712  str(size_type __sub = 0) const
1713  { return (*this)[__sub].str(); }
1714 
1715  /**
1716  * @brief Gets a %sub_match reference for the match or submatch.
1717  * @param __sub indicates the submatch.
1718  * @pre ready() == true
1719  *
1720  * This function gets a reference to the indicated submatch, or
1721  * the entire match if @p __sub is zero.
1722  *
1723  * If @p __sub >= size() then this function returns a %sub_match with a
1724  * special value indicating no submatch.
1725  */
1726  const_reference
1727  operator[](size_type __sub) const
1728  {
1729  _GLIBCXX_DEBUG_ASSERT( ready() );
1730  return __sub < size()
1731  ? _Base_type::operator[](__sub)
1732  : __unmatched_sub<_Bi_iter>();
1733  }
1734 
1735  /**
1736  * @brief Gets a %sub_match representing the match prefix.
1737  * @pre ready() == true
1738  *
1739  * This function gets a reference to a %sub_match object representing the
1740  * part of the target range between the start of the target range and the
1741  * start of the match.
1742  */
1743  const_reference
1744  prefix() const
1745  {
1746  _GLIBCXX_DEBUG_ASSERT( ready() );
1747  return !empty()
1749  : __unmatched_sub<_Bi_iter>();
1750  }
1751 
1752  /**
1753  * @brief Gets a %sub_match representing the match suffix.
1754  * @pre ready() == true
1755  *
1756  * This function gets a reference to a %sub_match object representing the
1757  * part of the target range between the end of the match and the end of
1758  * the target range.
1759  */
1760  const_reference
1761  suffix() const
1762  {
1763  _GLIBCXX_DEBUG_ASSERT( ready() );
1764  return !empty()
1766  : __unmatched_sub<_Bi_iter>();
1767  }
1768 
1769  /**
1770  * @brief Gets an iterator to the start of the %sub_match collection.
1771  */
1772  const_iterator
1773  begin() const
1774  { return _Base_type::begin(); }
1775 
1776  /**
1777  * @brief Gets an iterator to the start of the %sub_match collection.
1778  */
1779  const_iterator
1780  cbegin() const
1781  { return _Base_type::cbegin() + 2; }
1782 
1783  /**
1784  * @brief Gets an iterator to one-past-the-end of the collection.
1785  */
1786  const_iterator
1787  end() const
1788  { return _Base_type::end() - 2; }
1789 
1790  /**
1791  * @brief Gets an iterator to one-past-the-end of the collection.
1792  */
1793  const_iterator
1794  cend() const
1795  { return _Base_type::cend(); }
1796 
1797  //@}
1798 
1799  /**
1800  * @name 10.4 Formatting
1801  *
1802  * These functions perform formatted substitution of the matched
1803  * character sequences into their target. The format specifiers and
1804  * escape sequences accepted by these functions are determined by
1805  * their @p flags parameter as documented above.
1806  */
1807  //@{
1808 
1809  /**
1810  * @pre ready() == true
1811  */
1812  template<typename _Out_iter>
1813  _Out_iter
1814  format(_Out_iter __out, const char_type* __fmt_first,
1815  const char_type* __fmt_last,
1816  match_flag_type __flags = regex_constants::format_default) const;
1817 
1818  /**
1819  * @pre ready() == true
1820  */
1821  template<typename _Out_iter, typename _St, typename _Sa>
1822  _Out_iter
1823  format(_Out_iter __out, const basic_string<char_type, _St, _Sa>& __fmt,
1824  match_flag_type __flags = regex_constants::format_default) const
1825  {
1826  return format(__out, __fmt.data(), __fmt.data() + __fmt.size(),
1827  __flags);
1828  }
1829 
1830  /**
1831  * @pre ready() == true
1832  */
1833  template<typename _St, typename _Sa>
1836  match_flag_type __flags = regex_constants::format_default) const
1837  {
1839  format(std::back_inserter(__result), __fmt, __flags);
1840  return __result;
1841  }
1842 
1843  /**
1844  * @pre ready() == true
1845  */
1846  string_type
1847  format(const char_type* __fmt,
1848  match_flag_type __flags = regex_constants::format_default) const
1849  {
1850  string_type __result;
1851  format(std::back_inserter(__result),
1852  __fmt,
1853  __fmt + char_traits<char_type>::length(__fmt),
1854  __flags);
1855  return __result;
1856  }
1857 
1858  //@}
1859 
1860  /**
1861  * @name 10.5 Allocator
1862  */
1863  //@{
1864 
1865  /**
1866  * @brief Gets a copy of the allocator.
1867  */
1868  allocator_type
1870  { return _Base_type::get_allocator(); }
1871 
1872  //@}
1873 
1874  /**
1875  * @name 10.6 Swap
1876  */
1877  //@{
1878 
1879  /**
1880  * @brief Swaps the contents of two match_results.
1881  */
1882  void
1884  { _Base_type::swap(__that); }
1885  //@}
1886 
1887  private:
1888  template<typename, typename, typename, bool>
1889  friend class __detail::_Executor;
1890 
1891  template<typename, typename, typename>
1892  friend class regex_iterator;
1893 
1894  template<typename _Bp, typename _Ap, typename _Cp, typename _Rp,
1895  __detail::_RegexExecutorPolicy, bool>
1896  friend bool
1897  __detail::__regex_algo_impl(_Bp, _Bp, match_results<_Bp, _Ap>&,
1898  const basic_regex<_Cp, _Rp>&,
1900 
1901  _Bi_iter _M_begin;
1902  bool _M_in_iterator;
1903  };
1904 
1905  typedef match_results<const char*> cmatch;
1906  typedef match_results<string::const_iterator> smatch;
1907 #ifdef _GLIBCXX_USE_WCHAR_T
1908  typedef match_results<const wchar_t*> wcmatch;
1909  typedef match_results<wstring::const_iterator> wsmatch;
1910 #endif
1911 
1912  // match_results comparisons
1913  /**
1914  * @brief Compares two match_results for equality.
1915  * @returns true if the two objects refer to the same match,
1916  * false otherwise.
1917  */
1918  template<typename _Bi_iter, typename _Alloc>
1919  inline bool
1921  const match_results<_Bi_iter, _Alloc>& __m2)
1922  {
1923  if (__m1.ready() != __m2.ready())
1924  return false;
1925  if (!__m1.ready()) // both are not ready
1926  return true;
1927  if (__m1.empty() != __m2.empty())
1928  return false;
1929  if (__m1.empty()) // both are empty
1930  return true;
1931  return __m1.prefix() == __m2.prefix()
1932  && __m1.size() == __m2.size()
1933  && std::equal(__m1.begin(), __m1.end(), __m2.begin())
1934  && __m1.suffix() == __m2.suffix();
1935  }
1936 
1937  /**
1938  * @brief Compares two match_results for inequality.
1939  * @returns true if the two objects do not refer to the same match,
1940  * false otherwise.
1941  */
1942  template<typename _Bi_iter, class _Alloc>
1943  inline bool
1945  const match_results<_Bi_iter, _Alloc>& __m2)
1946  { return !(__m1 == __m2); }
1947 
1948  // [7.10.6] match_results swap
1949  /**
1950  * @brief Swaps two match results.
1951  * @param __lhs A match result.
1952  * @param __rhs A match result.
1953  *
1954  * The contents of the two match_results objects are swapped.
1955  */
1956  template<typename _Bi_iter, typename _Alloc>
1957  inline void
1960  { __lhs.swap(__rhs); }
1961 
1962  // [7.11.2] Function template regex_match
1963  /**
1964  * @name Matching, Searching, and Replacing
1965  */
1966  //@{
1967 
1968  /**
1969  * @brief Determines if there is a match between the regular expression @p e
1970  * and all of the character sequence [first, last).
1971  *
1972  * @param __s Start of the character sequence to match.
1973  * @param __e One-past-the-end of the character sequence to match.
1974  * @param __m The match results.
1975  * @param __re The regular expression.
1976  * @param __flags Controls how the regular expression is matched.
1977  *
1978  * @retval true A match exists.
1979  * @retval false Otherwise.
1980  *
1981  * @throws an exception of type regex_error.
1982  */
1983  template<typename _Bi_iter, typename _Alloc,
1984  typename _Ch_type, typename _Rx_traits>
1985  inline bool
1986  regex_match(_Bi_iter __s,
1987  _Bi_iter __e,
1992  {
1993  return __detail::__regex_algo_impl<_Bi_iter, _Alloc, _Ch_type, _Rx_traits,
1994  __detail::_RegexExecutorPolicy::_S_auto, true>
1995  (__s, __e, __m, __re, __flags);
1996  }
1997 
1998  /**
1999  * @brief Indicates if there is a match between the regular expression @p e
2000  * and all of the character sequence [first, last).
2001  *
2002  * @param __first Beginning of the character sequence to match.
2003  * @param __last One-past-the-end of the character sequence to match.
2004  * @param __re The regular expression.
2005  * @param __flags Controls how the regular expression is matched.
2006  *
2007  * @retval true A match exists.
2008  * @retval false Otherwise.
2009  *
2010  * @throws an exception of type regex_error.
2011  */
2012  template<typename _Bi_iter, typename _Ch_type, typename _Rx_traits>
2013  inline bool
2014  regex_match(_Bi_iter __first, _Bi_iter __last,
2018  {
2019  match_results<_Bi_iter> __what;
2020  return regex_match(__first, __last, __what, __re, __flags);
2021  }
2022 
2023  /**
2024  * @brief Determines if there is a match between the regular expression @p e
2025  * and a C-style null-terminated string.
2026  *
2027  * @param __s The C-style null-terminated string to match.
2028  * @param __m The match results.
2029  * @param __re The regular expression.
2030  * @param __f Controls how the regular expression is matched.
2031  *
2032  * @retval true A match exists.
2033  * @retval false Otherwise.
2034  *
2035  * @throws an exception of type regex_error.
2036  */
2037  template<typename _Ch_type, typename _Alloc, typename _Rx_traits>
2038  inline bool
2039  regex_match(const _Ch_type* __s,
2044  { return regex_match(__s, __s + _Rx_traits::length(__s), __m, __re, __f); }
2045 
2046  /**
2047  * @brief Determines if there is a match between the regular expression @p e
2048  * and a string.
2049  *
2050  * @param __s The string to match.
2051  * @param __m The match results.
2052  * @param __re The regular expression.
2053  * @param __flags Controls how the regular expression is matched.
2054  *
2055  * @retval true A match exists.
2056  * @retval false Otherwise.
2057  *
2058  * @throws an exception of type regex_error.
2059  */
2060  template<typename _Ch_traits, typename _Ch_alloc,
2061  typename _Alloc, typename _Ch_type, typename _Rx_traits>
2062  inline bool
2064  match_results<typename basic_string<_Ch_type,
2065  _Ch_traits, _Ch_alloc>::const_iterator, _Alloc>& __m,
2069  { return regex_match(__s.begin(), __s.end(), __m, __re, __flags); }
2070 
2071  /**
2072  * @brief Indicates if there is a match between the regular expression @p e
2073  * and a C-style null-terminated string.
2074  *
2075  * @param __s The C-style null-terminated string to match.
2076  * @param __re The regular expression.
2077  * @param __f Controls how the regular expression is matched.
2078  *
2079  * @retval true A match exists.
2080  * @retval false Otherwise.
2081  *
2082  * @throws an exception of type regex_error.
2083  */
2084  template<typename _Ch_type, class _Rx_traits>
2085  inline bool
2086  regex_match(const _Ch_type* __s,
2090  { return regex_match(__s, __s + _Rx_traits::length(__s), __re, __f); }
2091 
2092  /**
2093  * @brief Indicates if there is a match between the regular expression @p e
2094  * and a string.
2095  *
2096  * @param __s [IN] The string to match.
2097  * @param __re [IN] The regular expression.
2098  * @param __flags [IN] Controls how the regular expression is matched.
2099  *
2100  * @retval true A match exists.
2101  * @retval false Otherwise.
2102  *
2103  * @throws an exception of type regex_error.
2104  */
2105  template<typename _Ch_traits, typename _Str_allocator,
2106  typename _Ch_type, typename _Rx_traits>
2107  inline bool
2112  { return regex_match(__s.begin(), __s.end(), __re, __flags); }
2113 
2114  // [7.11.3] Function template regex_search
2115  /**
2116  * Searches for a regular expression within a range.
2117  * @param __s [IN] The start of the string to search.
2118  * @param __e [IN] One-past-the-end of the string to search.
2119  * @param __m [OUT] The match results.
2120  * @param __re [IN] The regular expression to search for.
2121  * @param __flags [IN] Search policy flags.
2122  * @retval true A match was found within the string.
2123  * @retval false No match was found within the string, the content of %m is
2124  * undefined.
2125  *
2126  * @throws an exception of type regex_error.
2127  */
2128  template<typename _Bi_iter, typename _Alloc,
2129  typename _Ch_type, typename _Rx_traits>
2130  inline bool
2131  regex_search(_Bi_iter __s, _Bi_iter __e,
2136  {
2137  return __detail::__regex_algo_impl<_Bi_iter, _Alloc, _Ch_type, _Rx_traits,
2138  __detail::_RegexExecutorPolicy::_S_auto, false>
2139  (__s, __e, __m, __re, __flags);
2140  }
2141 
2142  /**
2143  * Searches for a regular expression within a range.
2144  * @param __first [IN] The start of the string to search.
2145  * @param __last [IN] One-past-the-end of the string to search.
2146  * @param __re [IN] The regular expression to search for.
2147  * @param __flags [IN] Search policy flags.
2148  * @retval true A match was found within the string.
2149  * @retval false No match was found within the string.
2150  *
2151  * @throws an exception of type regex_error.
2152  */
2153  template<typename _Bi_iter, typename _Ch_type, typename _Rx_traits>
2154  inline bool
2155  regex_search(_Bi_iter __first, _Bi_iter __last,
2159  {
2160  match_results<_Bi_iter> __what;
2161  return regex_search(__first, __last, __what, __re, __flags);
2162  }
2163 
2164  /**
2165  * @brief Searches for a regular expression within a C-string.
2166  * @param __s [IN] A C-string to search for the regex.
2167  * @param __m [OUT] The set of regex matches.
2168  * @param __e [IN] The regex to search for in @p s.
2169  * @param __f [IN] The search flags.
2170  * @retval true A match was found within the string.
2171  * @retval false No match was found within the string, the content of %m is
2172  * undefined.
2173  *
2174  * @throws an exception of type regex_error.
2175  */
2176  template<typename _Ch_type, class _Alloc, class _Rx_traits>
2177  inline bool
2178  regex_search(const _Ch_type* __s,
2183  { return regex_search(__s, __s + _Rx_traits::length(__s), __m, __e, __f); }
2184 
2185  /**
2186  * @brief Searches for a regular expression within a C-string.
2187  * @param __s [IN] The C-string to search.
2188  * @param __e [IN] The regular expression to search for.
2189  * @param __f [IN] Search policy flags.
2190  * @retval true A match was found within the string.
2191  * @retval false No match was found within the string.
2192  *
2193  * @throws an exception of type regex_error.
2194  */
2195  template<typename _Ch_type, typename _Rx_traits>
2196  inline bool
2197  regex_search(const _Ch_type* __s,
2201  { return regex_search(__s, __s + _Rx_traits::length(__s), __e, __f); }
2202 
2203  /**
2204  * @brief Searches for a regular expression within a string.
2205  * @param __s [IN] The string to search.
2206  * @param __e [IN] The regular expression to search for.
2207  * @param __flags [IN] Search policy flags.
2208  * @retval true A match was found within the string.
2209  * @retval false No match was found within the string.
2210  *
2211  * @throws an exception of type regex_error.
2212  */
2213  template<typename _Ch_traits, typename _String_allocator,
2214  typename _Ch_type, typename _Rx_traits>
2215  inline bool
2216  regex_search(const basic_string<_Ch_type, _Ch_traits,
2217  _String_allocator>& __s,
2221  { return regex_search(__s.begin(), __s.end(), __e, __flags); }
2222 
2223  /**
2224  * @brief Searches for a regular expression within a string.
2225  * @param __s [IN] A C++ string to search for the regex.
2226  * @param __m [OUT] The set of regex matches.
2227  * @param __e [IN] The regex to search for in @p s.
2228  * @param __f [IN] The search flags.
2229  * @retval true A match was found within the string.
2230  * @retval false No match was found within the string, the content of %m is
2231  * undefined.
2232  *
2233  * @throws an exception of type regex_error.
2234  */
2235  template<typename _Ch_traits, typename _Ch_alloc,
2236  typename _Alloc, typename _Ch_type,
2237  typename _Rx_traits>
2238  inline bool
2240  match_results<typename basic_string<_Ch_type,
2241  _Ch_traits, _Ch_alloc>::const_iterator, _Alloc>& __m,
2245  { return regex_search(__s.begin(), __s.end(), __m, __e, __f); }
2246 
2247  // std [28.11.4] Function template regex_replace
2248  /**
2249  * @brief Search for a regular expression within a range for multiple times,
2250  and replace the matched parts through filling a format string.
2251  * @param __out [OUT] The output iterator.
2252  * @param __first [IN] The start of the string to search.
2253  * @param __last [IN] One-past-the-end of the string to search.
2254  * @param __e [IN] The regular expression to search for.
2255  * @param __fmt [IN] The format string.
2256  * @param __flags [IN] Search and replace policy flags.
2257  *
2258  * @returns __out
2259  * @throws an exception of type regex_error.
2260  */
2261  template<typename _Out_iter, typename _Bi_iter,
2262  typename _Rx_traits, typename _Ch_type,
2263  typename _St, typename _Sa>
2264  inline _Out_iter
2265  regex_replace(_Out_iter __out, _Bi_iter __first, _Bi_iter __last,
2267  const basic_string<_Ch_type, _St, _Sa>& __fmt,
2270  {
2271  return regex_replace(__out, __first, __last, __e, __fmt.c_str(), __flags);
2272  }
2273 
2274  /**
2275  * @brief Search for a regular expression within a range for multiple times,
2276  and replace the matched parts through filling a format C-string.
2277  * @param __out [OUT] The output iterator.
2278  * @param __first [IN] The start of the string to search.
2279  * @param __last [IN] One-past-the-end of the string to search.
2280  * @param __e [IN] The regular expression to search for.
2281  * @param __fmt [IN] The format C-string.
2282  * @param __flags [IN] Search and replace policy flags.
2283  *
2284  * @returns __out
2285  * @throws an exception of type regex_error.
2286  */
2287  template<typename _Out_iter, typename _Bi_iter,
2288  typename _Rx_traits, typename _Ch_type>
2289  _Out_iter
2290  regex_replace(_Out_iter __out, _Bi_iter __first, _Bi_iter __last,
2291  const basic_regex<_Ch_type, _Rx_traits>& __e,
2292  const _Ch_type* __fmt,
2295 
2296  /**
2297  * @brief Search for a regular expression within a string for multiple times,
2298  and replace the matched parts through filling a format string.
2299  * @param __s [IN] The string to search and replace.
2300  * @param __e [IN] The regular expression to search for.
2301  * @param __fmt [IN] The format string.
2302  * @param __flags [IN] Search and replace policy flags.
2303  *
2304  * @returns The string after replacing.
2305  * @throws an exception of type regex_error.
2306  */
2307  template<typename _Rx_traits, typename _Ch_type,
2308  typename _St, typename _Sa, typename _Fst, typename _Fsa>
2309  inline basic_string<_Ch_type, _St, _Sa>
2315  {
2318  __s.begin(), __s.end(), __e, __fmt, __flags);
2319  return __result;
2320  }
2321 
2322  /**
2323  * @brief Search for a regular expression within a string for multiple times,
2324  and replace the matched parts through filling a format C-string.
2325  * @param __s [IN] The string to search and replace.
2326  * @param __e [IN] The regular expression to search for.
2327  * @param __fmt [IN] The format C-string.
2328  * @param __flags [IN] Search and replace policy flags.
2329  *
2330  * @returns The string after replacing.
2331  * @throws an exception of type regex_error.
2332  */
2333  template<typename _Rx_traits, typename _Ch_type,
2334  typename _St, typename _Sa>
2335  inline basic_string<_Ch_type, _St, _Sa>
2338  const _Ch_type* __fmt,
2341  {
2344  __s.begin(), __s.end(), __e, __fmt, __flags);
2345  return __result;
2346  }
2347 
2348  /**
2349  * @brief Search for a regular expression within a C-string for multiple
2350  times, and replace the matched parts through filling a format string.
2351  * @param __s [IN] The C-string to search and replace.
2352  * @param __e [IN] The regular expression to search for.
2353  * @param __fmt [IN] The format string.
2354  * @param __flags [IN] Search and replace policy flags.
2355  *
2356  * @returns The string after replacing.
2357  * @throws an exception of type regex_error.
2358  */
2359  template<typename _Rx_traits, typename _Ch_type,
2360  typename _St, typename _Sa>
2361  inline basic_string<_Ch_type>
2362  regex_replace(const _Ch_type* __s,
2364  const basic_string<_Ch_type, _St, _Sa>& __fmt,
2367  {
2368  basic_string<_Ch_type> __result;
2369  regex_replace(std::back_inserter(__result), __s,
2370  __s + char_traits<_Ch_type>::length(__s),
2371  __e, __fmt, __flags);
2372  return __result;
2373  }
2374 
2375  /**
2376  * @brief Search for a regular expression within a C-string for multiple
2377  times, and replace the matched parts through filling a format C-string.
2378  * @param __s [IN] The C-string to search and replace.
2379  * @param __e [IN] The regular expression to search for.
2380  * @param __fmt [IN] The format C-string.
2381  * @param __flags [IN] Search and replace policy flags.
2382  *
2383  * @returns The string after replacing.
2384  * @throws an exception of type regex_error.
2385  */
2386  template<typename _Rx_traits, typename _Ch_type>
2387  inline basic_string<_Ch_type>
2388  regex_replace(const _Ch_type* __s,
2390  const _Ch_type* __fmt,
2393  {
2394  basic_string<_Ch_type> __result;
2395  regex_replace(std::back_inserter(__result), __s,
2396  __s + char_traits<_Ch_type>::length(__s),
2397  __e, __fmt, __flags);
2398  return __result;
2399  }
2400 
2401  //@}
2402 
2403  // std [28.12] Class template regex_iterator
2404  /**
2405  * An iterator adaptor that will provide repeated calls of regex_search over
2406  * a range until no more matches remain.
2407  */
2408  template<typename _Bi_iter,
2409  typename _Ch_type = typename iterator_traits<_Bi_iter>::value_type,
2410  typename _Rx_traits = regex_traits<_Ch_type> >
2412  {
2413  public:
2415  typedef match_results<_Bi_iter> value_type;
2416  typedef std::ptrdiff_t difference_type;
2417  typedef const value_type* pointer;
2418  typedef const value_type& reference;
2420 
2421  /**
2422  * @brief Provides a singular iterator, useful for indicating
2423  * one-past-the-end of a range.
2424  */
2426  : _M_match()
2427  { }
2428 
2429  /**
2430  * Constructs a %regex_iterator...
2431  * @param __a [IN] The start of a text range to search.
2432  * @param __b [IN] One-past-the-end of the text range to search.
2433  * @param __re [IN] The regular expression to match.
2434  * @param __m [IN] Policy flags for match rules.
2435  */
2436  regex_iterator(_Bi_iter __a, _Bi_iter __b, const regex_type& __re,
2439  : _M_begin(__a), _M_end(__b), _M_pregex(&__re), _M_flags(__m), _M_match()
2440  {
2441  if (!regex_search(_M_begin, _M_end, _M_match, *_M_pregex, _M_flags))
2442  *this = regex_iterator();
2443  }
2444 
2445  /**
2446  * Copy constructs a %regex_iterator.
2447  */
2448  regex_iterator(const regex_iterator& __rhs) = default;
2449 
2450  /**
2451  * @brief Assigns one %regex_iterator to another.
2452  */
2454  operator=(const regex_iterator& __rhs) = default;
2455 
2456  /**
2457  * @brief Tests the equivalence of two regex iterators.
2458  */
2459  bool
2460  operator==(const regex_iterator& __rhs) const;
2461 
2462  /**
2463  * @brief Tests the inequivalence of two regex iterators.
2464  */
2465  bool
2466  operator!=(const regex_iterator& __rhs) const
2467  { return !(*this == __rhs); }
2468 
2469  /**
2470  * @brief Dereferences a %regex_iterator.
2471  */
2472  const value_type&
2473  operator*() const
2474  { return _M_match; }
2475 
2476  /**
2477  * @brief Selects a %regex_iterator member.
2478  */
2479  const value_type*
2480  operator->() const
2481  { return &_M_match; }
2482 
2483  /**
2484  * @brief Increments a %regex_iterator.
2485  */
2487  operator++();
2488 
2489  /**
2490  * @brief Postincrements a %regex_iterator.
2491  */
2494  {
2495  auto __tmp = *this;
2496  ++(*this);
2497  return __tmp;
2498  }
2499 
2500  private:
2501  _Bi_iter _M_begin;
2502  _Bi_iter _M_end;
2503  const regex_type* _M_pregex;
2505  match_results<_Bi_iter> _M_match;
2506  };
2507 
2508  typedef regex_iterator<const char*> cregex_iterator;
2509  typedef regex_iterator<string::const_iterator> sregex_iterator;
2510 #ifdef _GLIBCXX_USE_WCHAR_T
2511  typedef regex_iterator<const wchar_t*> wcregex_iterator;
2512  typedef regex_iterator<wstring::const_iterator> wsregex_iterator;
2513 #endif
2514 
2515  // [7.12.2] Class template regex_token_iterator
2516  /**
2517  * Iterates over submatches in a range (or @a splits a text string).
2518  *
2519  * The purpose of this iterator is to enumerate all, or all specified,
2520  * matches of a regular expression within a text range. The dereferenced
2521  * value of an iterator of this class is a std::sub_match object.
2522  */
2523  template<typename _Bi_iter,
2524  typename _Ch_type = typename iterator_traits<_Bi_iter>::value_type,
2525  typename _Rx_traits = regex_traits<_Ch_type> >
2527  {
2528  public:
2530  typedef sub_match<_Bi_iter> value_type;
2531  typedef std::ptrdiff_t difference_type;
2532  typedef const value_type* pointer;
2533  typedef const value_type& reference;
2535 
2536  public:
2537  /**
2538  * @brief Default constructs a %regex_token_iterator.
2539  *
2540  * A default-constructed %regex_token_iterator is a singular iterator
2541  * that will compare equal to the one-past-the-end value for any
2542  * iterator of the same type.
2543  */
2545  : _M_position(), _M_subs(), _M_suffix(), _M_n(0), _M_result(nullptr),
2546  _M_has_m1(false)
2547  { }
2548 
2549  /**
2550  * Constructs a %regex_token_iterator...
2551  * @param __a [IN] The start of the text to search.
2552  * @param __b [IN] One-past-the-end of the text to search.
2553  * @param __re [IN] The regular expression to search for.
2554  * @param __submatch [IN] Which submatch to return. There are some
2555  * special values for this parameter:
2556  * - -1 each enumerated subexpression does NOT
2557  * match the regular expression (aka field
2558  * splitting)
2559  * - 0 the entire string matching the
2560  * subexpression is returned for each match
2561  * within the text.
2562  * - >0 enumerates only the indicated
2563  * subexpression from a match within the text.
2564  * @param __m [IN] Policy flags for match rules.
2565  */
2566  regex_token_iterator(_Bi_iter __a, _Bi_iter __b, const regex_type& __re,
2567  int __submatch = 0,
2570  : _M_position(__a, __b, __re, __m), _M_subs(1, __submatch), _M_n(0)
2571  { _M_init(__a, __b); }
2572 
2573  /**
2574  * Constructs a %regex_token_iterator...
2575  * @param __a [IN] The start of the text to search.
2576  * @param __b [IN] One-past-the-end of the text to search.
2577  * @param __re [IN] The regular expression to search for.
2578  * @param __submatches [IN] A list of subexpressions to return for each
2579  * regular expression match within the text.
2580  * @param __m [IN] Policy flags for match rules.
2581  */
2582  regex_token_iterator(_Bi_iter __a, _Bi_iter __b,
2583  const regex_type& __re,
2584  const std::vector<int>& __submatches,
2587  : _M_position(__a, __b, __re, __m), _M_subs(__submatches), _M_n(0)
2588  { _M_init(__a, __b); }
2589 
2590  /**
2591  * Constructs a %regex_token_iterator...
2592  * @param __a [IN] The start of the text to search.
2593  * @param __b [IN] One-past-the-end of the text to search.
2594  * @param __re [IN] The regular expression to search for.
2595  * @param __submatches [IN] A list of subexpressions to return for each
2596  * regular expression match within the text.
2597  * @param __m [IN] Policy flags for match rules.
2598  */
2599  regex_token_iterator(_Bi_iter __a, _Bi_iter __b,
2600  const regex_type& __re,
2601  initializer_list<int> __submatches,
2604  : _M_position(__a, __b, __re, __m), _M_subs(__submatches), _M_n(0)
2605  { _M_init(__a, __b); }
2606 
2607  /**
2608  * Constructs a %regex_token_iterator...
2609  * @param __a [IN] The start of the text to search.
2610  * @param __b [IN] One-past-the-end of the text to search.
2611  * @param __re [IN] The regular expression to search for.
2612  * @param __submatches [IN] A list of subexpressions to return for each
2613  * regular expression match within the text.
2614  * @param __m [IN] Policy flags for match rules.
2615  */
2616  template<std::size_t _Nm>
2617  regex_token_iterator(_Bi_iter __a, _Bi_iter __b,
2618  const regex_type& __re,
2619  const int (&__submatches)[_Nm],
2622  : _M_position(__a, __b, __re, __m),
2623  _M_subs(__submatches, *(&__submatches+1)), _M_n(0)
2624  { _M_init(__a, __b); }
2625 
2626  /**
2627  * @brief Copy constructs a %regex_token_iterator.
2628  * @param __rhs [IN] A %regex_token_iterator to copy.
2629  */
2631  : _M_position(__rhs._M_position), _M_subs(__rhs._M_subs),
2632  _M_suffix(__rhs._M_suffix), _M_n(__rhs._M_n), _M_result(__rhs._M_result),
2633  _M_has_m1(__rhs._M_has_m1)
2634  {
2635  if (__rhs._M_result == &__rhs._M_suffix)
2636  _M_result = &_M_suffix;
2637  }
2638 
2639  /**
2640  * @brief Assigns a %regex_token_iterator to another.
2641  * @param __rhs [IN] A %regex_token_iterator to copy.
2642  */
2644  operator=(const regex_token_iterator& __rhs);
2645 
2646  /**
2647  * @brief Compares a %regex_token_iterator to another for equality.
2648  */
2649  bool
2650  operator==(const regex_token_iterator& __rhs) const;
2651 
2652  /**
2653  * @brief Compares a %regex_token_iterator to another for inequality.
2654  */
2655  bool
2656  operator!=(const regex_token_iterator& __rhs) const
2657  { return !(*this == __rhs); }
2658 
2659  /**
2660  * @brief Dereferences a %regex_token_iterator.
2661  */
2662  const value_type&
2663  operator*() const
2664  { return *_M_result; }
2665 
2666  /**
2667  * @brief Selects a %regex_token_iterator member.
2668  */
2669  const value_type*
2670  operator->() const
2671  { return _M_result; }
2672 
2673  /**
2674  * @brief Increments a %regex_token_iterator.
2675  */
2677  operator++();
2678 
2679  /**
2680  * @brief Postincrements a %regex_token_iterator.
2681  */
2684  {
2685  auto __tmp = *this;
2686  ++(*this);
2687  return __tmp;
2688  }
2689 
2690  private:
2692 
2693  void
2694  _M_init(_Bi_iter __a, _Bi_iter __b);
2695 
2696  const value_type&
2697  _M_current_match() const
2698  {
2699  if (_M_subs[_M_n] == -1)
2700  return (*_M_position).prefix();
2701  else
2702  return (*_M_position)[_M_subs[_M_n]];
2703  }
2704 
2705  constexpr bool
2706  _M_end_of_seq() const
2707  { return _M_result == nullptr; }
2708 
2709  _Position _M_position;
2710  std::vector<int> _M_subs;
2711  value_type _M_suffix;
2712  std::size_t _M_n;
2713  const value_type* _M_result;
2714 
2715  // Show whether _M_subs contains -1
2716  bool _M_has_m1;
2717  };
2718 
2719  /** @brief Token iterator for C-style NULL-terminated strings. */
2721 
2722  /** @brief Token iterator for standard strings. */
2724 
2725 #ifdef _GLIBCXX_USE_WCHAR_T
2726  /** @brief Token iterator for C-style NULL-terminated wide strings. */
2728 
2729  /** @brief Token iterator for standard wide-character strings. */
2731 #endif
2732 
2733  //@} // group regex
2734 _GLIBCXX_END_NAMESPACE_VERSION
2735 } // namespace
2736 
2737 #include <bits/regex.tcc>
Container class for localization functionality.The locale class is first a class wrapper for C librar...
const_iterator cbegin() const
Gets an iterator to the start of the sub_match collection.
Definition: regex.h:1780
int compare(const value_type *__s) const
Compares this sub_match to a C-style string.
Definition: regex.h:922
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:2617
bool isctype(_Ch_type __c, char_class_type __f) const
Determines if c is a member of an identified class.
const _CharT * data() const noexcept
Return const pointer to contents.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
Definition: move.h:101
int value(_Ch_type __ch, int __radix) const
Converts a digit to an int.
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:2566
size_type max_size() const noexcept
Definition: stl_vector.h:659
difference_type position(size_type __sub=0) const
Gets the offset of the beginning of the indicated submatch.
Definition: regex.h:1691
string_type lookup_collatename(_Fwd_iter __first, _Fwd_iter __last) const
Gets a collation element by name.
locale_type getloc() const
Gets a copy of the current locale in use by the regex_traits object.
Definition: regex.h:384
basic_regex< char > regex
Standard regular expressions.
Definition: regex.h:800
regex_traits()
Constructs a default traits object.
Definition: regex.h:171
regex_iterator operator++(int)
Postincrements a regex_iterator.
Definition: regex.h:2493
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
sub_match< wstring::const_iterator > wssub_match
Regex submatch over a standard wide 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:2582
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:1944
reference operator[](size_type __n) noexcept
Subscript access to the data contained in the vector.
Definition: stl_vector.h:779
regex_token_iterator< string::const_iterator > sregex_token_iterator
Token iterator for standard strings.
Definition: regex.h:2723
string_type str() const
Gets the matching sequence as a string.
Definition: regex.h:879
Forward iterators support a superset of input iterator operations.
bool operator!=(const regex_token_iterator &__rhs) const
Compares a regex_token_iterator to another for inequality.
Definition: regex.h:2656
const_reference suffix() const
Gets a sub_match representing the match suffix.
Definition: regex.h:1761
regex_iterator & operator=(const regex_iterator &__rhs)=default
Assigns one regex_iterator to another.
iterator begin()
Definition: basic_string.h:614
char_type translate_nocase(char_type __c) const
Translates a character into a case-insensitive equivalent.
Definition: regex.h:208
sub_match< const wchar_t * > wcsub_match
Regex submatch over a C-style null-terminated wide string.
Definition: regex.h:935
regex_iterator & operator++()
Increments a regex_iterator.
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
regex_token_iterator & operator++()
Increments a regex_token_iterator.
size_type max_size() const
Gets the number of matches and submatches.
Definition: regex.h:1646
size_type size() const noexcept
Returns the number of characters in the string, not including any null-termination.
Definition: basic_string.h:724
A smart pointer with reference-counted copy semantics.
Definition: shared_ptr.h:93
bool operator==(const regex_iterator &__rhs) const
Tests the equivalence of two regex iterators.
const _CharT * c_str() const noexcept
Return const pointer to null-terminated contents.
syntax_option_type
This is a bitmask type indicating how to interpret the regex.
regex_token_iterator()
Default constructs a regex_token_iterator.
Definition: regex.h:2544
auto begin(_Container &__cont) -> decltype(__cont.begin())
Return an iterator pointing to the first element of the container.
Definition: range_access.h:48
match_flag_type
This is a bitmask type indicating regex matching rules.
const_reference prefix() const
Gets a sub_match representing the match prefix.
Definition: regex.h:1744
const_iterator cbegin() const noexcept
Definition: stl_vector.h:620
void swap(vector &__x) noexcept(_Alloc_traits::_S_nothrow_swap())
Swaps data with another vector.
Definition: stl_vector.h:1194
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:1986
_Siter_base< _Iterator >::iterator_type __base(_Iterator __it)
Definition: functions.h:558
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:2131
regex_token_iterator(const regex_token_iterator &__rhs)
Copy constructs a regex_token_iterator.
Definition: regex.h:2630
int compare(const basic_string &__str) const
Compare to a string.
back_insert_iterator< _Container > back_inserter(_Container &__x)
Definition: stl_iterator.h:480
string_type format(const char_type *__fmt, match_flag_type __flags=regex_constants::format_default) const
Definition: regex.h:1847
iterator_traits< _InputIterator >::difference_type distance(_InputIterator __first, _InputIterator __last)
A generalization of pointer arithmetic.
const_reference operator[](size_type __sub) const
Gets a sub_match reference for the match or submatch.
Definition: regex.h:1727
The results of a match or search operation.
Definition: regex.h:38
_BiIter first
second_type is the second bound type
Definition: stl_pair.h:101
match_results & operator=(match_results &&__rhs)
Move-assigns rhs to *this.
Definition: regex.h:1602
regex_token_iterator< const char * > cregex_token_iterator
Token iterator for C-style NULL-terminated strings.
Definition: regex.h:2720
int compare(const string_type &__s) const
Compares this sub_match to a string.
Definition: regex.h:909
regex_iterator()
Provides a singular iterator, useful for indicating one-past-the-end of a range.
Definition: regex.h:2425
ISO C++ entities toplevel namespace is std.
char_type translate(char_type __c) const
Performs the identity translation.
Definition: regex.h:195
const value_type * operator->() const
Selects a regex_iterator member.
Definition: regex.h:2480
bool equal(_II1 __first1, _II1 __last1, _II2 __first2)
Tests a range for element-wise equality.
match_results(match_results &&__rhs) noexcept
Move constructs a match_results.
Definition: regex.h:1584
bool operator!=(const regex_iterator &__rhs) const
Tests the inequivalence of two regex iterators.
Definition: regex.h:2466
regex_token_iterator & operator=(const regex_token_iterator &__rhs)
Assigns a regex_token_iterator to another.
Basis for explicit traits specializations.
Definition: char_traits.h:227
bool operator==(const regex_token_iterator &__rhs) const
Compares a regex_token_iterator to another for equality.
const_iterator begin() const
Gets an iterator to the start of the sub_match collection.
Definition: regex.h:1773
difference_type length() const
Definition: regex.h:853
const value_type * operator->() const
Selects a regex_token_iterator member.
Definition: regex.h:2670
_Tp * data() noexcept
Definition: stl_vector.h:890
match_results(const _Alloc &__a=_Alloc())
Constructs a default match_results container.
Definition: regex.h:1570
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:2436
regex_token_iterator< const wchar_t * > wcregex_token_iterator
Token iterator for C-style NULL-terminated wide strings.
Definition: regex.h:2727
Describes aspects of a regular expression.
Definition: regex.h:91
_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
_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:2265
basic_regex< wchar_t > wregex
Standard wide-character regular expressions.
Definition: regex.h:804
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:1920
const value_type & operator*() const
Dereferences a regex_iterator.
Definition: regex.h:2473
locale_type imbue(locale_type __loc)
Imbues the regex_traits object with a copy of a new locale.
Definition: regex.h:373
sub_match< string::const_iterator > ssub_match
Standard regex submatch over a standard string.
Definition: regex.h:931
bool empty() const
Indicates if the match_results contains no results.
Definition: regex.h:1655
bool operator>=(const basic_string< _CharT, _Traits, _Alloc > &__lhs, const basic_string< _CharT, _Traits, _Alloc > &__rhs)
Test if string doesn't precede string.
match_results(const match_results &__rhs)
Copy constructs a match_results.
Definition: regex.h:1577
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:2599
string_type str(size_type __sub=0) const
Gets the match or submatch converted to a string type.
Definition: regex.h:1712
_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:1823
~match_results()
Destroys a match_results object.
Definition: regex.h:1611
const_iterator cend() const
Gets an iterator to one-past-the-end of the collection.
Definition: regex.h:1794
bool operator>(const basic_string< _CharT, _Traits, _Alloc > &__lhs, const basic_string< _CharT, _Traits, _Alloc > &__rhs)
Test if string follows string.
size_type size() const noexcept
Definition: stl_vector.h:654
void swap(match_results &__that)
Swaps the contents of two match_results.
Definition: regex.h:1883
size_type size() const
Gets the number of matches and submatches.
Definition: regex.h:1639
static std::size_t length(const char_type *__p)
Gives the length of a C-style string starting at __p.
Definition: regex.h:184
regex_token_iterator operator++(int)
Postincrements a regex_token_iterator.
Definition: regex.h:2683
Struct holding two objects of arbitrary type.
Definition: stl_pair.h:96
A standard container which offers fixed time access to individual elements in any order...
Definition: stl_vector.h:214
void swap(_Tp &, _Tp &) noexcept(__and_< is_nothrow_move_constructible< _Tp >, is_nothrow_move_assignable< _Tp >>::value)
Swaps two values.
Definition: move.h:166
allocator_type get_allocator() const
Gets a copy of the allocator.
Definition: regex.h:1869
Facet for localized string comparison.
int compare(const sub_match &__s) const
Compares this and another matched sequence.
Definition: regex.h:896
string_type transform(_Fwd_iter __first, _Fwd_iter __last) const
Gets a sort key for a character sequence.
Definition: regex.h:237
const value_type & operator*() const
Dereferences a regex_token_iterator.
Definition: regex.h:2663
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:1835
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.
_BiIter second
first is a copy of the first object
Definition: stl_pair.h:102
regex_token_iterator< wstring::const_iterator > wsregex_token_iterator
Token iterator for standard wide-character strings.
Definition: regex.h:2730
match_results & operator=(const match_results &__rhs)
Assigns rhs to *this.
Definition: regex.h:1592
Takes a regex and an input string in and do the matching.
Definition: regex.h:61
Managing sequences of characters and character-like objects.
Definition: basic_string.h:112
difference_type length(size_type __sub=0) const
Gets the length of the indicated submatch.
Definition: regex.h:1674
bool ready() const
Indicates if the match_results is ready.
Definition: regex.h:1622
const_iterator cend() const noexcept
Definition: stl_vector.h:629
const_iterator end() const
Gets an iterator to one-past-the-end of the collection.
Definition: regex.h:1787
sub_match< const char * > csub_match
Standard regex submatch over a C-style null-terminated string.
Definition: regex.h:928