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