138fd1498Szrj // class template regex -*- C++ -*-
238fd1498Szrj
338fd1498Szrj // Copyright (C) 2010-2018 Free Software Foundation, Inc.
438fd1498Szrj //
538fd1498Szrj // This file is part of the GNU ISO C++ Library. This library is free
638fd1498Szrj // software; you can redistribute it and/or modify it under the
738fd1498Szrj // terms of the GNU General Public License as published by the
838fd1498Szrj // Free Software Foundation; either version 3, or (at your option)
938fd1498Szrj // any later version.
1038fd1498Szrj
1138fd1498Szrj // This library is distributed in the hope that it will be useful,
1238fd1498Szrj // but WITHOUT ANY WARRANTY; without even the implied warranty of
1338fd1498Szrj // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1438fd1498Szrj // GNU General Public License for more details.
1538fd1498Szrj
1638fd1498Szrj // Under Section 7 of GPL version 3, you are granted additional
1738fd1498Szrj // permissions described in the GCC Runtime Library Exception, version
1838fd1498Szrj // 3.1, as published by the Free Software Foundation.
1938fd1498Szrj
2038fd1498Szrj // You should have received a copy of the GNU General Public License and
2138fd1498Szrj // a copy of the GCC Runtime Library Exception along with this program;
2238fd1498Szrj // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
2338fd1498Szrj // <http://www.gnu.org/licenses/>.
2438fd1498Szrj
2538fd1498Szrj /**
2638fd1498Szrj * @file bits/regex.h
2738fd1498Szrj * This is an internal header file, included by other library headers.
2838fd1498Szrj * Do not attempt to use it directly. @headername{regex}
2938fd1498Szrj */
3038fd1498Szrj
_GLIBCXX_VISIBILITY(default)3138fd1498Szrj namespace std _GLIBCXX_VISIBILITY(default)
3238fd1498Szrj {
3338fd1498Szrj _GLIBCXX_BEGIN_NAMESPACE_VERSION
3438fd1498Szrj _GLIBCXX_BEGIN_NAMESPACE_CXX11
3538fd1498Szrj template<typename, typename>
3638fd1498Szrj class basic_regex;
3738fd1498Szrj
3838fd1498Szrj template<typename, typename>
3938fd1498Szrj class match_results;
4038fd1498Szrj
4138fd1498Szrj _GLIBCXX_END_NAMESPACE_CXX11
4238fd1498Szrj
4338fd1498Szrj namespace __detail
4438fd1498Szrj {
4538fd1498Szrj enum class _RegexExecutorPolicy : int
4638fd1498Szrj { _S_auto, _S_alternate };
4738fd1498Szrj
4838fd1498Szrj template<typename _BiIter, typename _Alloc,
4938fd1498Szrj typename _CharT, typename _TraitsT,
5038fd1498Szrj _RegexExecutorPolicy __policy,
5138fd1498Szrj bool __match_mode>
5238fd1498Szrj bool
5338fd1498Szrj __regex_algo_impl(_BiIter __s,
5438fd1498Szrj _BiIter __e,
5538fd1498Szrj match_results<_BiIter, _Alloc>& __m,
5638fd1498Szrj const basic_regex<_CharT, _TraitsT>& __re,
5738fd1498Szrj regex_constants::match_flag_type __flags);
5838fd1498Szrj
5938fd1498Szrj template<typename, typename, typename, bool>
6038fd1498Szrj class _Executor;
6138fd1498Szrj }
6238fd1498Szrj
6338fd1498Szrj _GLIBCXX_BEGIN_NAMESPACE_CXX11
6438fd1498Szrj
6538fd1498Szrj /**
6638fd1498Szrj * @addtogroup regex
6738fd1498Szrj * @{
6838fd1498Szrj */
6938fd1498Szrj
7038fd1498Szrj /**
7138fd1498Szrj * @brief Describes aspects of a regular expression.
7238fd1498Szrj *
7338fd1498Szrj * A regular expression traits class that satisfies the requirements of
7438fd1498Szrj * section [28.7].
7538fd1498Szrj *
7638fd1498Szrj * The class %regex is parameterized around a set of related types and
7738fd1498Szrj * functions used to complete the definition of its semantics. This class
7838fd1498Szrj * satisfies the requirements of such a traits class.
7938fd1498Szrj */
8038fd1498Szrj template<typename _Ch_type>
8138fd1498Szrj struct regex_traits
8238fd1498Szrj {
8338fd1498Szrj public:
8438fd1498Szrj typedef _Ch_type char_type;
8538fd1498Szrj typedef std::basic_string<char_type> string_type;
8638fd1498Szrj typedef std::locale locale_type;
8738fd1498Szrj private:
8838fd1498Szrj struct _RegexMask
8938fd1498Szrj {
9038fd1498Szrj typedef std::ctype_base::mask _BaseType;
9138fd1498Szrj _BaseType _M_base;
9238fd1498Szrj unsigned char _M_extended;
9338fd1498Szrj static constexpr unsigned char _S_under = 1 << 0;
9438fd1498Szrj static constexpr unsigned char _S_valid_mask = 0x1;
9538fd1498Szrj
9638fd1498Szrj constexpr _RegexMask(_BaseType __base = 0,
9738fd1498Szrj unsigned char __extended = 0)
9838fd1498Szrj : _M_base(__base), _M_extended(__extended)
9938fd1498Szrj { }
10038fd1498Szrj
10138fd1498Szrj constexpr _RegexMask
10238fd1498Szrj operator&(_RegexMask __other) const
10338fd1498Szrj {
10438fd1498Szrj return _RegexMask(_M_base & __other._M_base,
10538fd1498Szrj _M_extended & __other._M_extended);
10638fd1498Szrj }
10738fd1498Szrj
10838fd1498Szrj constexpr _RegexMask
10938fd1498Szrj operator|(_RegexMask __other) const
11038fd1498Szrj {
11138fd1498Szrj return _RegexMask(_M_base | __other._M_base,
11238fd1498Szrj _M_extended | __other._M_extended);
11338fd1498Szrj }
11438fd1498Szrj
11538fd1498Szrj constexpr _RegexMask
11638fd1498Szrj operator^(_RegexMask __other) const
11738fd1498Szrj {
11838fd1498Szrj return _RegexMask(_M_base ^ __other._M_base,
11938fd1498Szrj _M_extended ^ __other._M_extended);
12038fd1498Szrj }
12138fd1498Szrj
12238fd1498Szrj constexpr _RegexMask
12338fd1498Szrj operator~() const
12438fd1498Szrj { return _RegexMask(~_M_base, ~_M_extended); }
12538fd1498Szrj
12638fd1498Szrj _RegexMask&
12738fd1498Szrj operator&=(_RegexMask __other)
12838fd1498Szrj { return *this = (*this) & __other; }
12938fd1498Szrj
13038fd1498Szrj _RegexMask&
13138fd1498Szrj operator|=(_RegexMask __other)
13238fd1498Szrj { return *this = (*this) | __other; }
13338fd1498Szrj
13438fd1498Szrj _RegexMask&
13538fd1498Szrj operator^=(_RegexMask __other)
13638fd1498Szrj { return *this = (*this) ^ __other; }
13738fd1498Szrj
13838fd1498Szrj constexpr bool
13938fd1498Szrj operator==(_RegexMask __other) const
14038fd1498Szrj {
14138fd1498Szrj return (_M_extended & _S_valid_mask)
14238fd1498Szrj == (__other._M_extended & _S_valid_mask)
14338fd1498Szrj && _M_base == __other._M_base;
14438fd1498Szrj }
14538fd1498Szrj
14638fd1498Szrj constexpr bool
14738fd1498Szrj operator!=(_RegexMask __other) const
14838fd1498Szrj { return !((*this) == __other); }
14938fd1498Szrj
15038fd1498Szrj };
15138fd1498Szrj public:
15238fd1498Szrj typedef _RegexMask char_class_type;
15338fd1498Szrj
15438fd1498Szrj public:
15538fd1498Szrj /**
15638fd1498Szrj * @brief Constructs a default traits object.
15738fd1498Szrj */
15838fd1498Szrj regex_traits() { }
15938fd1498Szrj
16038fd1498Szrj /**
16138fd1498Szrj * @brief Gives the length of a C-style string starting at @p __p.
16238fd1498Szrj *
16338fd1498Szrj * @param __p a pointer to the start of a character sequence.
16438fd1498Szrj *
16538fd1498Szrj * @returns the number of characters between @p *__p and the first
16638fd1498Szrj * default-initialized value of type @p char_type. In other words, uses
16738fd1498Szrj * the C-string algorithm for determining the length of a sequence of
16838fd1498Szrj * characters.
16938fd1498Szrj */
17038fd1498Szrj static std::size_t
17138fd1498Szrj length(const char_type* __p)
17238fd1498Szrj { return string_type::traits_type::length(__p); }
17338fd1498Szrj
17438fd1498Szrj /**
17538fd1498Szrj * @brief Performs the identity translation.
17638fd1498Szrj *
17738fd1498Szrj * @param __c A character to the locale-specific character set.
17838fd1498Szrj *
17938fd1498Szrj * @returns __c.
18038fd1498Szrj */
18138fd1498Szrj char_type
18238fd1498Szrj translate(char_type __c) const
18338fd1498Szrj { return __c; }
18438fd1498Szrj
18538fd1498Szrj /**
18638fd1498Szrj * @brief Translates a character into a case-insensitive equivalent.
18738fd1498Szrj *
18838fd1498Szrj * @param __c A character to the locale-specific character set.
18938fd1498Szrj *
19038fd1498Szrj * @returns the locale-specific lower-case equivalent of __c.
19138fd1498Szrj * @throws std::bad_cast if the imbued locale does not support the ctype
19238fd1498Szrj * facet.
19338fd1498Szrj */
19438fd1498Szrj char_type
19538fd1498Szrj translate_nocase(char_type __c) const
19638fd1498Szrj {
19738fd1498Szrj typedef std::ctype<char_type> __ctype_type;
19838fd1498Szrj const __ctype_type& __fctyp(use_facet<__ctype_type>(_M_locale));
19938fd1498Szrj return __fctyp.tolower(__c);
20038fd1498Szrj }
20138fd1498Szrj
20238fd1498Szrj /**
20338fd1498Szrj * @brief Gets a sort key for a character sequence.
20438fd1498Szrj *
20538fd1498Szrj * @param __first beginning of the character sequence.
20638fd1498Szrj * @param __last one-past-the-end of the character sequence.
20738fd1498Szrj *
20838fd1498Szrj * Returns a sort key for the character sequence designated by the
20938fd1498Szrj * iterator range [F1, F2) such that if the character sequence [G1, G2)
21038fd1498Szrj * sorts before the character sequence [H1, H2) then
21138fd1498Szrj * v.transform(G1, G2) < v.transform(H1, H2).
21238fd1498Szrj *
21338fd1498Szrj * What this really does is provide a more efficient way to compare a
21438fd1498Szrj * string to multiple other strings in locales with fancy collation
21538fd1498Szrj * rules and equivalence classes.
21638fd1498Szrj *
21738fd1498Szrj * @returns a locale-specific sort key equivalent to the input range.
21838fd1498Szrj *
21938fd1498Szrj * @throws std::bad_cast if the current locale does not have a collate
22038fd1498Szrj * facet.
22138fd1498Szrj */
22238fd1498Szrj template<typename _Fwd_iter>
22338fd1498Szrj string_type
22438fd1498Szrj transform(_Fwd_iter __first, _Fwd_iter __last) const
22538fd1498Szrj {
22638fd1498Szrj typedef std::collate<char_type> __collate_type;
22738fd1498Szrj const __collate_type& __fclt(use_facet<__collate_type>(_M_locale));
22838fd1498Szrj string_type __s(__first, __last);
22938fd1498Szrj return __fclt.transform(__s.data(), __s.data() + __s.size());
23038fd1498Szrj }
23138fd1498Szrj
23238fd1498Szrj /**
23338fd1498Szrj * @brief Gets a sort key for a character sequence, independent of case.
23438fd1498Szrj *
23538fd1498Szrj * @param __first beginning of the character sequence.
23638fd1498Szrj * @param __last one-past-the-end of the character sequence.
23738fd1498Szrj *
23838fd1498Szrj * Effects: if typeid(use_facet<collate<_Ch_type> >) ==
23938fd1498Szrj * typeid(collate_byname<_Ch_type>) and the form of the sort key
24038fd1498Szrj * returned by collate_byname<_Ch_type>::transform(__first, __last)
24138fd1498Szrj * is known and can be converted into a primary sort key
24238fd1498Szrj * then returns that key, otherwise returns an empty string.
24338fd1498Szrj *
24438fd1498Szrj * @todo Implement this function correctly.
24538fd1498Szrj */
24638fd1498Szrj template<typename _Fwd_iter>
24738fd1498Szrj string_type
24838fd1498Szrj transform_primary(_Fwd_iter __first, _Fwd_iter __last) const
24938fd1498Szrj {
25038fd1498Szrj // TODO : this is not entirely correct.
25138fd1498Szrj // This function requires extra support from the platform.
25238fd1498Szrj //
25338fd1498Szrj // Read http://gcc.gnu.org/ml/libstdc++/2013-09/msg00117.html and
25438fd1498Szrj // http://www.open-std.org/Jtc1/sc22/wg21/docs/papers/2003/n1429.htm
25538fd1498Szrj // for details.
25638fd1498Szrj typedef std::ctype<char_type> __ctype_type;
25738fd1498Szrj const __ctype_type& __fctyp(use_facet<__ctype_type>(_M_locale));
25838fd1498Szrj std::vector<char_type> __s(__first, __last);
25938fd1498Szrj __fctyp.tolower(__s.data(), __s.data() + __s.size());
26038fd1498Szrj return this->transform(__s.data(), __s.data() + __s.size());
26138fd1498Szrj }
26238fd1498Szrj
26338fd1498Szrj /**
26438fd1498Szrj * @brief Gets a collation element by name.
26538fd1498Szrj *
26638fd1498Szrj * @param __first beginning of the collation element name.
26738fd1498Szrj * @param __last one-past-the-end of the collation element name.
26838fd1498Szrj *
26938fd1498Szrj * @returns a sequence of one or more characters that represents the
27038fd1498Szrj * collating element consisting of the character sequence designated by
27138fd1498Szrj * the iterator range [__first, __last). Returns an empty string if the
27238fd1498Szrj * character sequence is not a valid collating element.
27338fd1498Szrj */
27438fd1498Szrj template<typename _Fwd_iter>
27538fd1498Szrj string_type
27638fd1498Szrj lookup_collatename(_Fwd_iter __first, _Fwd_iter __last) const;
27738fd1498Szrj
27838fd1498Szrj /**
27938fd1498Szrj * @brief Maps one or more characters to a named character
28038fd1498Szrj * classification.
28138fd1498Szrj *
28238fd1498Szrj * @param __first beginning of the character sequence.
28338fd1498Szrj * @param __last one-past-the-end of the character sequence.
28438fd1498Szrj * @param __icase ignores the case of the classification name.
28538fd1498Szrj *
28638fd1498Szrj * @returns an unspecified value that represents the character
28738fd1498Szrj * classification named by the character sequence designated by
28838fd1498Szrj * the iterator range [__first, __last). If @p icase is true,
28938fd1498Szrj * the returned mask identifies the classification regardless of
29038fd1498Szrj * the case of the characters to be matched (for example,
29138fd1498Szrj * [[:lower:]] is the same as [[:alpha:]]), otherwise a
29238fd1498Szrj * case-dependent classification is returned. The value
29338fd1498Szrj * returned shall be independent of the case of the characters
29438fd1498Szrj * in the character sequence. If the name is not recognized then
29538fd1498Szrj * returns a value that compares equal to 0.
29638fd1498Szrj *
29738fd1498Szrj * At least the following names (or their wide-character equivalent) are
29838fd1498Szrj * supported.
29938fd1498Szrj * - d
30038fd1498Szrj * - w
30138fd1498Szrj * - s
30238fd1498Szrj * - alnum
30338fd1498Szrj * - alpha
30438fd1498Szrj * - blank
30538fd1498Szrj * - cntrl
30638fd1498Szrj * - digit
30738fd1498Szrj * - graph
30838fd1498Szrj * - lower
30938fd1498Szrj * - print
31038fd1498Szrj * - punct
31138fd1498Szrj * - space
31238fd1498Szrj * - upper
31338fd1498Szrj * - xdigit
31438fd1498Szrj */
31538fd1498Szrj template<typename _Fwd_iter>
31638fd1498Szrj char_class_type
31738fd1498Szrj lookup_classname(_Fwd_iter __first, _Fwd_iter __last,
31838fd1498Szrj bool __icase = false) const;
31938fd1498Szrj
32038fd1498Szrj /**
32138fd1498Szrj * @brief Determines if @p c is a member of an identified class.
32238fd1498Szrj *
32338fd1498Szrj * @param __c a character.
32438fd1498Szrj * @param __f a class type (as returned from lookup_classname).
32538fd1498Szrj *
32638fd1498Szrj * @returns true if the character @p __c is a member of the classification
32738fd1498Szrj * represented by @p __f, false otherwise.
32838fd1498Szrj *
32938fd1498Szrj * @throws std::bad_cast if the current locale does not have a ctype
33038fd1498Szrj * facet.
33138fd1498Szrj */
33238fd1498Szrj bool
33338fd1498Szrj isctype(_Ch_type __c, char_class_type __f) const;
33438fd1498Szrj
33538fd1498Szrj /**
33638fd1498Szrj * @brief Converts a digit to an int.
33738fd1498Szrj *
33838fd1498Szrj * @param __ch a character representing a digit.
33938fd1498Szrj * @param __radix the radix if the numeric conversion (limited to 8, 10,
34038fd1498Szrj * or 16).
34138fd1498Szrj *
34238fd1498Szrj * @returns the value represented by the digit __ch in base radix if the
34338fd1498Szrj * character __ch is a valid digit in base radix; otherwise returns -1.
34438fd1498Szrj */
34538fd1498Szrj int
34638fd1498Szrj value(_Ch_type __ch, int __radix) const;
34738fd1498Szrj
34838fd1498Szrj /**
34938fd1498Szrj * @brief Imbues the regex_traits object with a copy of a new locale.
35038fd1498Szrj *
35138fd1498Szrj * @param __loc A locale.
35238fd1498Szrj *
35338fd1498Szrj * @returns a copy of the previous locale in use by the regex_traits
35438fd1498Szrj * object.
35538fd1498Szrj *
35638fd1498Szrj * @note Calling imbue with a different locale than the one currently in
35738fd1498Szrj * use invalidates all cached data held by *this.
35838fd1498Szrj */
35938fd1498Szrj locale_type
36038fd1498Szrj imbue(locale_type __loc)
36138fd1498Szrj {
36238fd1498Szrj std::swap(_M_locale, __loc);
36338fd1498Szrj return __loc;
36438fd1498Szrj }
36538fd1498Szrj
36638fd1498Szrj /**
36738fd1498Szrj * @brief Gets a copy of the current locale in use by the regex_traits
36838fd1498Szrj * object.
36938fd1498Szrj */
37038fd1498Szrj locale_type
37138fd1498Szrj getloc() const
37238fd1498Szrj { return _M_locale; }
37338fd1498Szrj
37438fd1498Szrj protected:
37538fd1498Szrj locale_type _M_locale;
37638fd1498Szrj };
37738fd1498Szrj
37838fd1498Szrj // [7.8] Class basic_regex
37938fd1498Szrj /**
38038fd1498Szrj * Objects of specializations of this class represent regular expressions
38138fd1498Szrj * constructed from sequences of character type @p _Ch_type.
38238fd1498Szrj *
38338fd1498Szrj * Storage for the regular expression is allocated and deallocated as
38438fd1498Szrj * necessary by the member functions of this class.
38538fd1498Szrj */
38638fd1498Szrj template<typename _Ch_type, typename _Rx_traits = regex_traits<_Ch_type>>
38738fd1498Szrj class basic_regex
38838fd1498Szrj {
38938fd1498Szrj public:
39038fd1498Szrj static_assert(is_same<_Ch_type, typename _Rx_traits::char_type>::value,
39138fd1498Szrj "regex traits class must have the same char_type");
39238fd1498Szrj
39338fd1498Szrj // types:
39438fd1498Szrj typedef _Ch_type value_type;
39538fd1498Szrj typedef _Rx_traits traits_type;
39638fd1498Szrj typedef typename traits_type::string_type string_type;
39738fd1498Szrj typedef regex_constants::syntax_option_type flag_type;
39838fd1498Szrj typedef typename traits_type::locale_type locale_type;
39938fd1498Szrj
40038fd1498Szrj /**
40138fd1498Szrj * @name Constants
40238fd1498Szrj * std [28.8.1](1)
40338fd1498Szrj */
40438fd1498Szrj //@{
40538fd1498Szrj static constexpr flag_type icase = regex_constants::icase;
40638fd1498Szrj static constexpr flag_type nosubs = regex_constants::nosubs;
40738fd1498Szrj static constexpr flag_type optimize = regex_constants::optimize;
40838fd1498Szrj static constexpr flag_type collate = regex_constants::collate;
40938fd1498Szrj static constexpr flag_type ECMAScript = regex_constants::ECMAScript;
41038fd1498Szrj static constexpr flag_type basic = regex_constants::basic;
41138fd1498Szrj static constexpr flag_type extended = regex_constants::extended;
41238fd1498Szrj static constexpr flag_type awk = regex_constants::awk;
41338fd1498Szrj static constexpr flag_type grep = regex_constants::grep;
41438fd1498Szrj static constexpr flag_type egrep = regex_constants::egrep;
41538fd1498Szrj //@}
41638fd1498Szrj
41738fd1498Szrj // [7.8.2] construct/copy/destroy
41838fd1498Szrj /**
41938fd1498Szrj * Constructs a basic regular expression that does not match any
42038fd1498Szrj * character sequence.
42138fd1498Szrj */
42238fd1498Szrj basic_regex()
42338fd1498Szrj : _M_flags(ECMAScript), _M_loc(), _M_automaton(nullptr)
42438fd1498Szrj { }
42538fd1498Szrj
42638fd1498Szrj /**
42738fd1498Szrj * @brief Constructs a basic regular expression from the
42838fd1498Szrj * sequence [__p, __p + char_traits<_Ch_type>::length(__p))
42938fd1498Szrj * interpreted according to the flags in @p __f.
43038fd1498Szrj *
43138fd1498Szrj * @param __p A pointer to the start of a C-style null-terminated string
43238fd1498Szrj * containing a regular expression.
43338fd1498Szrj * @param __f Flags indicating the syntax rules and options.
43438fd1498Szrj *
43538fd1498Szrj * @throws regex_error if @p __p is not a valid regular expression.
43638fd1498Szrj */
43738fd1498Szrj explicit
43838fd1498Szrj basic_regex(const _Ch_type* __p, flag_type __f = ECMAScript)
43938fd1498Szrj : basic_regex(__p, __p + char_traits<_Ch_type>::length(__p), __f)
44038fd1498Szrj { }
44138fd1498Szrj
44238fd1498Szrj /**
44338fd1498Szrj * @brief Constructs a basic regular expression from the sequence
44438fd1498Szrj * [p, p + len) interpreted according to the flags in @p f.
44538fd1498Szrj *
44638fd1498Szrj * @param __p A pointer to the start of a string containing a regular
44738fd1498Szrj * expression.
44838fd1498Szrj * @param __len The length of the string containing the regular
44938fd1498Szrj * expression.
45038fd1498Szrj * @param __f Flags indicating the syntax rules and options.
45138fd1498Szrj *
45238fd1498Szrj * @throws regex_error if @p __p is not a valid regular expression.
45338fd1498Szrj */
45438fd1498Szrj basic_regex(const _Ch_type* __p, std::size_t __len,
45538fd1498Szrj flag_type __f = ECMAScript)
45638fd1498Szrj : basic_regex(__p, __p + __len, __f)
45738fd1498Szrj { }
45838fd1498Szrj
45938fd1498Szrj /**
46038fd1498Szrj * @brief Copy-constructs a basic regular expression.
46138fd1498Szrj *
46238fd1498Szrj * @param __rhs A @p regex object.
46338fd1498Szrj */
46438fd1498Szrj basic_regex(const basic_regex& __rhs) = default;
46538fd1498Szrj
46638fd1498Szrj /**
46738fd1498Szrj * @brief Move-constructs a basic regular expression.
46838fd1498Szrj *
46938fd1498Szrj * @param __rhs A @p regex object.
47038fd1498Szrj */
47138fd1498Szrj basic_regex(basic_regex&& __rhs) noexcept = default;
47238fd1498Szrj
47338fd1498Szrj /**
47438fd1498Szrj * @brief Constructs a basic regular expression from the string
47538fd1498Szrj * @p s interpreted according to the flags in @p f.
47638fd1498Szrj *
47738fd1498Szrj * @param __s A string containing a regular expression.
47838fd1498Szrj * @param __f Flags indicating the syntax rules and options.
47938fd1498Szrj *
48038fd1498Szrj * @throws regex_error if @p __s is not a valid regular expression.
48138fd1498Szrj */
48238fd1498Szrj template<typename _Ch_traits, typename _Ch_alloc>
48338fd1498Szrj explicit
48438fd1498Szrj basic_regex(const std::basic_string<_Ch_type, _Ch_traits,
48538fd1498Szrj _Ch_alloc>& __s,
48638fd1498Szrj flag_type __f = ECMAScript)
48738fd1498Szrj : basic_regex(__s.data(), __s.data() + __s.size(), __f)
48838fd1498Szrj { }
48938fd1498Szrj
49038fd1498Szrj /**
49138fd1498Szrj * @brief Constructs a basic regular expression from the range
49238fd1498Szrj * [first, last) interpreted according to the flags in @p f.
49338fd1498Szrj *
49438fd1498Szrj * @param __first The start of a range containing a valid regular
49538fd1498Szrj * expression.
49638fd1498Szrj * @param __last The end of a range containing a valid regular
49738fd1498Szrj * expression.
49838fd1498Szrj * @param __f The format flags of the regular expression.
49938fd1498Szrj *
50038fd1498Szrj * @throws regex_error if @p [__first, __last) is not a valid regular
50138fd1498Szrj * expression.
50238fd1498Szrj */
50338fd1498Szrj template<typename _FwdIter>
50438fd1498Szrj basic_regex(_FwdIter __first, _FwdIter __last,
50538fd1498Szrj flag_type __f = ECMAScript)
50638fd1498Szrj : basic_regex(std::move(__first), std::move(__last), locale_type(), __f)
50738fd1498Szrj { }
50838fd1498Szrj
50938fd1498Szrj /**
51038fd1498Szrj * @brief Constructs a basic regular expression from an initializer list.
51138fd1498Szrj *
51238fd1498Szrj * @param __l The initializer list.
51338fd1498Szrj * @param __f The format flags of the regular expression.
51438fd1498Szrj *
51538fd1498Szrj * @throws regex_error if @p __l is not a valid regular expression.
51638fd1498Szrj */
51738fd1498Szrj basic_regex(initializer_list<_Ch_type> __l, flag_type __f = ECMAScript)
51838fd1498Szrj : basic_regex(__l.begin(), __l.end(), __f)
51938fd1498Szrj { }
52038fd1498Szrj
52138fd1498Szrj /**
52238fd1498Szrj * @brief Destroys a basic regular expression.
52338fd1498Szrj */
52438fd1498Szrj ~basic_regex()
52538fd1498Szrj { }
52638fd1498Szrj
52738fd1498Szrj /**
52838fd1498Szrj * @brief Assigns one regular expression to another.
52938fd1498Szrj */
53038fd1498Szrj basic_regex&
53138fd1498Szrj operator=(const basic_regex& __rhs)
53238fd1498Szrj { return this->assign(__rhs); }
53338fd1498Szrj
53438fd1498Szrj /**
53538fd1498Szrj * @brief Move-assigns one regular expression to another.
53638fd1498Szrj */
53738fd1498Szrj basic_regex&
53838fd1498Szrj operator=(basic_regex&& __rhs) noexcept
53938fd1498Szrj { return this->assign(std::move(__rhs)); }
54038fd1498Szrj
54138fd1498Szrj /**
54238fd1498Szrj * @brief Replaces a regular expression with a new one constructed from
54338fd1498Szrj * a C-style null-terminated string.
54438fd1498Szrj *
54538fd1498Szrj * @param __p A pointer to the start of a null-terminated C-style string
54638fd1498Szrj * containing a regular expression.
54738fd1498Szrj */
54838fd1498Szrj basic_regex&
54938fd1498Szrj operator=(const _Ch_type* __p)
55038fd1498Szrj { return this->assign(__p); }
55138fd1498Szrj
55238fd1498Szrj /**
55338fd1498Szrj * @brief Replaces a regular expression with a new one constructed from
55438fd1498Szrj * an initializer list.
55538fd1498Szrj *
55638fd1498Szrj * @param __l The initializer list.
55738fd1498Szrj *
55838fd1498Szrj * @throws regex_error if @p __l is not a valid regular expression.
55938fd1498Szrj */
56038fd1498Szrj basic_regex&
56138fd1498Szrj operator=(initializer_list<_Ch_type> __l)
56238fd1498Szrj { return this->assign(__l.begin(), __l.end()); }
56338fd1498Szrj
56438fd1498Szrj /**
56538fd1498Szrj * @brief Replaces a regular expression with a new one constructed from
56638fd1498Szrj * a string.
56738fd1498Szrj *
56838fd1498Szrj * @param __s A pointer to a string containing a regular expression.
56938fd1498Szrj */
57038fd1498Szrj template<typename _Ch_traits, typename _Alloc>
57138fd1498Szrj basic_regex&
57238fd1498Szrj operator=(const basic_string<_Ch_type, _Ch_traits, _Alloc>& __s)
57338fd1498Szrj { return this->assign(__s); }
57438fd1498Szrj
57538fd1498Szrj // [7.8.3] assign
57638fd1498Szrj /**
57738fd1498Szrj * @brief the real assignment operator.
57838fd1498Szrj *
57938fd1498Szrj * @param __rhs Another regular expression object.
58038fd1498Szrj */
58138fd1498Szrj basic_regex&
58238fd1498Szrj assign(const basic_regex& __rhs)
58338fd1498Szrj {
58438fd1498Szrj basic_regex __tmp(__rhs);
58538fd1498Szrj this->swap(__tmp);
58638fd1498Szrj return *this;
58738fd1498Szrj }
58838fd1498Szrj
58938fd1498Szrj /**
59038fd1498Szrj * @brief The move-assignment operator.
59138fd1498Szrj *
59238fd1498Szrj * @param __rhs Another regular expression object.
59338fd1498Szrj */
59438fd1498Szrj basic_regex&
59538fd1498Szrj assign(basic_regex&& __rhs) noexcept
59638fd1498Szrj {
59738fd1498Szrj basic_regex __tmp(std::move(__rhs));
59838fd1498Szrj this->swap(__tmp);
59938fd1498Szrj return *this;
60038fd1498Szrj }
60138fd1498Szrj
60238fd1498Szrj /**
60338fd1498Szrj * @brief Assigns a new regular expression to a regex object from a
60438fd1498Szrj * C-style null-terminated string containing a regular expression
60538fd1498Szrj * pattern.
60638fd1498Szrj *
60738fd1498Szrj * @param __p A pointer to a C-style null-terminated string containing
60838fd1498Szrj * a regular expression pattern.
60938fd1498Szrj * @param __flags Syntax option flags.
61038fd1498Szrj *
61138fd1498Szrj * @throws regex_error if __p does not contain a valid regular
61238fd1498Szrj * expression pattern interpreted according to @p __flags. If
61338fd1498Szrj * regex_error is thrown, *this remains unchanged.
61438fd1498Szrj */
61538fd1498Szrj basic_regex&
61638fd1498Szrj assign(const _Ch_type* __p, flag_type __flags = ECMAScript)
61738fd1498Szrj { return this->assign(string_type(__p), __flags); }
61838fd1498Szrj
61938fd1498Szrj /**
62038fd1498Szrj * @brief Assigns a new regular expression to a regex object from a
62138fd1498Szrj * C-style string containing a regular expression pattern.
62238fd1498Szrj *
62338fd1498Szrj * @param __p A pointer to a C-style string containing a
62438fd1498Szrj * regular expression pattern.
62538fd1498Szrj * @param __len The length of the regular expression pattern string.
62638fd1498Szrj * @param __flags Syntax option flags.
62738fd1498Szrj *
62838fd1498Szrj * @throws regex_error if p does not contain a valid regular
62938fd1498Szrj * expression pattern interpreted according to @p __flags. If
63038fd1498Szrj * regex_error is thrown, *this remains unchanged.
63138fd1498Szrj */
63238fd1498Szrj basic_regex&
63338fd1498Szrj assign(const _Ch_type* __p, std::size_t __len, flag_type __flags)
63438fd1498Szrj { return this->assign(string_type(__p, __len), __flags); }
63538fd1498Szrj
63638fd1498Szrj /**
63738fd1498Szrj * @brief Assigns a new regular expression to a regex object from a
63838fd1498Szrj * string containing a regular expression pattern.
63938fd1498Szrj *
64038fd1498Szrj * @param __s A string containing a regular expression pattern.
64138fd1498Szrj * @param __flags Syntax option flags.
64238fd1498Szrj *
64338fd1498Szrj * @throws regex_error if __s does not contain a valid regular
64438fd1498Szrj * expression pattern interpreted according to @p __flags. If
64538fd1498Szrj * regex_error is thrown, *this remains unchanged.
64638fd1498Szrj */
64738fd1498Szrj template<typename _Ch_traits, typename _Alloc>
64838fd1498Szrj basic_regex&
64938fd1498Szrj assign(const basic_string<_Ch_type, _Ch_traits, _Alloc>& __s,
65038fd1498Szrj flag_type __flags = ECMAScript)
65138fd1498Szrj {
65238fd1498Szrj return this->assign(basic_regex(__s.data(), __s.data() + __s.size(),
65338fd1498Szrj _M_loc, __flags));
65438fd1498Szrj }
65538fd1498Szrj
65638fd1498Szrj /**
65738fd1498Szrj * @brief Assigns a new regular expression to a regex object.
65838fd1498Szrj *
65938fd1498Szrj * @param __first The start of a range containing a valid regular
66038fd1498Szrj * expression.
66138fd1498Szrj * @param __last The end of a range containing a valid regular
66238fd1498Szrj * expression.
66338fd1498Szrj * @param __flags Syntax option flags.
66438fd1498Szrj *
66538fd1498Szrj * @throws regex_error if p does not contain a valid regular
66638fd1498Szrj * expression pattern interpreted according to @p __flags. If
66738fd1498Szrj * regex_error is thrown, the object remains unchanged.
66838fd1498Szrj */
66938fd1498Szrj template<typename _InputIterator>
67038fd1498Szrj basic_regex&
67138fd1498Szrj assign(_InputIterator __first, _InputIterator __last,
67238fd1498Szrj flag_type __flags = ECMAScript)
67338fd1498Szrj { return this->assign(string_type(__first, __last), __flags); }
67438fd1498Szrj
67538fd1498Szrj /**
67638fd1498Szrj * @brief Assigns a new regular expression to a regex object.
67738fd1498Szrj *
67838fd1498Szrj * @param __l An initializer list representing a regular expression.
67938fd1498Szrj * @param __flags Syntax option flags.
68038fd1498Szrj *
68138fd1498Szrj * @throws regex_error if @p __l does not contain a valid
68238fd1498Szrj * regular expression pattern interpreted according to @p
68338fd1498Szrj * __flags. If regex_error is thrown, the object remains
68438fd1498Szrj * unchanged.
68538fd1498Szrj */
68638fd1498Szrj basic_regex&
68738fd1498Szrj assign(initializer_list<_Ch_type> __l, flag_type __flags = ECMAScript)
68838fd1498Szrj { return this->assign(__l.begin(), __l.end(), __flags); }
68938fd1498Szrj
69038fd1498Szrj // [7.8.4] const operations
69138fd1498Szrj /**
69238fd1498Szrj * @brief Gets the number of marked subexpressions within the regular
69338fd1498Szrj * expression.
69438fd1498Szrj */
69538fd1498Szrj unsigned int
69638fd1498Szrj mark_count() const
69738fd1498Szrj {
69838fd1498Szrj if (_M_automaton)
69938fd1498Szrj return _M_automaton->_M_sub_count() - 1;
70038fd1498Szrj return 0;
70138fd1498Szrj }
70238fd1498Szrj
70338fd1498Szrj /**
70438fd1498Szrj * @brief Gets the flags used to construct the regular expression
70538fd1498Szrj * or in the last call to assign().
70638fd1498Szrj */
70738fd1498Szrj flag_type
70838fd1498Szrj flags() const
70938fd1498Szrj { return _M_flags; }
71038fd1498Szrj
71138fd1498Szrj // [7.8.5] locale
71238fd1498Szrj /**
71338fd1498Szrj * @brief Imbues the regular expression object with the given locale.
71438fd1498Szrj *
71538fd1498Szrj * @param __loc A locale.
71638fd1498Szrj */
71738fd1498Szrj locale_type
71838fd1498Szrj imbue(locale_type __loc)
71938fd1498Szrj {
72038fd1498Szrj std::swap(__loc, _M_loc);
72138fd1498Szrj _M_automaton.reset();
72238fd1498Szrj return __loc;
72338fd1498Szrj }
72438fd1498Szrj
72538fd1498Szrj /**
72638fd1498Szrj * @brief Gets the locale currently imbued in the regular expression
72738fd1498Szrj * object.
72838fd1498Szrj */
72938fd1498Szrj locale_type
73038fd1498Szrj getloc() const
73138fd1498Szrj { return _M_loc; }
73238fd1498Szrj
73338fd1498Szrj // [7.8.6] swap
73438fd1498Szrj /**
73538fd1498Szrj * @brief Swaps the contents of two regular expression objects.
73638fd1498Szrj *
73738fd1498Szrj * @param __rhs Another regular expression object.
73838fd1498Szrj */
73938fd1498Szrj void
74038fd1498Szrj swap(basic_regex& __rhs)
74138fd1498Szrj {
74238fd1498Szrj std::swap(_M_flags, __rhs._M_flags);
74338fd1498Szrj std::swap(_M_loc, __rhs._M_loc);
74438fd1498Szrj std::swap(_M_automaton, __rhs._M_automaton);
74538fd1498Szrj }
74638fd1498Szrj
74738fd1498Szrj #ifdef _GLIBCXX_DEBUG
74838fd1498Szrj void
74938fd1498Szrj _M_dot(std::ostream& __ostr)
75038fd1498Szrj { _M_automaton->_M_dot(__ostr); }
75138fd1498Szrj #endif
75238fd1498Szrj
75338fd1498Szrj private:
75438fd1498Szrj typedef std::shared_ptr<const __detail::_NFA<_Rx_traits>> _AutomatonPtr;
75538fd1498Szrj
75638fd1498Szrj template<typename _FwdIter>
75738fd1498Szrj basic_regex(_FwdIter __first, _FwdIter __last, locale_type __loc,
75838fd1498Szrj flag_type __f)
75938fd1498Szrj : _M_flags(__f), _M_loc(std::move(__loc)),
76038fd1498Szrj _M_automaton(__detail::__compile_nfa<_Rx_traits>(
76138fd1498Szrj std::move(__first), std::move(__last), _M_loc, _M_flags))
76238fd1498Szrj { }
76338fd1498Szrj
76438fd1498Szrj template<typename _Bp, typename _Ap, typename _Cp, typename _Rp,
76538fd1498Szrj __detail::_RegexExecutorPolicy, bool>
76638fd1498Szrj friend bool
76738fd1498Szrj __detail::__regex_algo_impl(_Bp, _Bp, match_results<_Bp, _Ap>&,
76838fd1498Szrj const basic_regex<_Cp, _Rp>&,
76938fd1498Szrj regex_constants::match_flag_type);
77038fd1498Szrj
77138fd1498Szrj template<typename, typename, typename, bool>
77238fd1498Szrj friend class __detail::_Executor;
77338fd1498Szrj
77438fd1498Szrj flag_type _M_flags;
77538fd1498Szrj locale_type _M_loc;
77638fd1498Szrj _AutomatonPtr _M_automaton;
77738fd1498Szrj };
77838fd1498Szrj
779*58e805e6Szrj #if __cplusplus < 201703L
780*58e805e6Szrj template<typename _Ch, typename _Tr>
781*58e805e6Szrj constexpr regex_constants::syntax_option_type
782*58e805e6Szrj basic_regex<_Ch, _Tr>::icase;
783*58e805e6Szrj
784*58e805e6Szrj template<typename _Ch, typename _Tr>
785*58e805e6Szrj constexpr regex_constants::syntax_option_type
786*58e805e6Szrj basic_regex<_Ch, _Tr>::nosubs;
787*58e805e6Szrj
788*58e805e6Szrj template<typename _Ch, typename _Tr>
789*58e805e6Szrj constexpr regex_constants::syntax_option_type
790*58e805e6Szrj basic_regex<_Ch, _Tr>::optimize;
791*58e805e6Szrj
792*58e805e6Szrj template<typename _Ch, typename _Tr>
793*58e805e6Szrj constexpr regex_constants::syntax_option_type
794*58e805e6Szrj basic_regex<_Ch, _Tr>::collate;
795*58e805e6Szrj
796*58e805e6Szrj template<typename _Ch, typename _Tr>
797*58e805e6Szrj constexpr regex_constants::syntax_option_type
798*58e805e6Szrj basic_regex<_Ch, _Tr>::ECMAScript;
799*58e805e6Szrj
800*58e805e6Szrj template<typename _Ch, typename _Tr>
801*58e805e6Szrj constexpr regex_constants::syntax_option_type
802*58e805e6Szrj basic_regex<_Ch, _Tr>::basic;
803*58e805e6Szrj
804*58e805e6Szrj template<typename _Ch, typename _Tr>
805*58e805e6Szrj constexpr regex_constants::syntax_option_type
806*58e805e6Szrj basic_regex<_Ch, _Tr>::extended;
807*58e805e6Szrj
808*58e805e6Szrj template<typename _Ch, typename _Tr>
809*58e805e6Szrj constexpr regex_constants::syntax_option_type
810*58e805e6Szrj basic_regex<_Ch, _Tr>::awk;
811*58e805e6Szrj
812*58e805e6Szrj template<typename _Ch, typename _Tr>
813*58e805e6Szrj constexpr regex_constants::syntax_option_type
814*58e805e6Szrj basic_regex<_Ch, _Tr>::grep;
815*58e805e6Szrj
816*58e805e6Szrj template<typename _Ch, typename _Tr>
817*58e805e6Szrj constexpr regex_constants::syntax_option_type
818*58e805e6Szrj basic_regex<_Ch, _Tr>::egrep;
819*58e805e6Szrj #endif // ! C++17
820*58e805e6Szrj
82138fd1498Szrj #if __cpp_deduction_guides >= 201606
82238fd1498Szrj template<typename _ForwardIterator>
82338fd1498Szrj basic_regex(_ForwardIterator, _ForwardIterator,
82438fd1498Szrj regex_constants::syntax_option_type = {})
82538fd1498Szrj -> basic_regex<typename iterator_traits<_ForwardIterator>::value_type>;
82638fd1498Szrj #endif
82738fd1498Szrj
82838fd1498Szrj /** @brief Standard regular expressions. */
82938fd1498Szrj typedef basic_regex<char> regex;
83038fd1498Szrj
83138fd1498Szrj #ifdef _GLIBCXX_USE_WCHAR_T
83238fd1498Szrj /** @brief Standard wide-character regular expressions. */
83338fd1498Szrj typedef basic_regex<wchar_t> wregex;
83438fd1498Szrj #endif
83538fd1498Szrj
83638fd1498Szrj
83738fd1498Szrj // [7.8.6] basic_regex swap
83838fd1498Szrj /**
83938fd1498Szrj * @brief Swaps the contents of two regular expression objects.
84038fd1498Szrj * @param __lhs First regular expression.
84138fd1498Szrj * @param __rhs Second regular expression.
84238fd1498Szrj */
84338fd1498Szrj template<typename _Ch_type, typename _Rx_traits>
84438fd1498Szrj inline void
84538fd1498Szrj swap(basic_regex<_Ch_type, _Rx_traits>& __lhs,
84638fd1498Szrj basic_regex<_Ch_type, _Rx_traits>& __rhs)
84738fd1498Szrj { __lhs.swap(__rhs); }
84838fd1498Szrj
84938fd1498Szrj
85038fd1498Szrj // [7.9] Class template sub_match
85138fd1498Szrj /**
85238fd1498Szrj * A sequence of characters matched by a particular marked sub-expression.
85338fd1498Szrj *
85438fd1498Szrj * An object of this class is essentially a pair of iterators marking a
85538fd1498Szrj * matched subexpression within a regular expression pattern match. Such
85638fd1498Szrj * objects can be converted to and compared with std::basic_string objects
85738fd1498Szrj * of a similar base character type as the pattern matched by the regular
85838fd1498Szrj * expression.
85938fd1498Szrj *
86038fd1498Szrj * The iterators that make up the pair are the usual half-open interval
86138fd1498Szrj * referencing the actual original pattern matched.
86238fd1498Szrj */
86338fd1498Szrj template<typename _BiIter>
86438fd1498Szrj class sub_match : public std::pair<_BiIter, _BiIter>
86538fd1498Szrj {
86638fd1498Szrj typedef iterator_traits<_BiIter> __iter_traits;
86738fd1498Szrj
86838fd1498Szrj public:
86938fd1498Szrj typedef typename __iter_traits::value_type value_type;
87038fd1498Szrj typedef typename __iter_traits::difference_type difference_type;
87138fd1498Szrj typedef _BiIter iterator;
87238fd1498Szrj typedef std::basic_string<value_type> string_type;
87338fd1498Szrj
87438fd1498Szrj bool matched;
87538fd1498Szrj
87638fd1498Szrj constexpr sub_match() : matched() { }
87738fd1498Szrj
87838fd1498Szrj /**
87938fd1498Szrj * Gets the length of the matching sequence.
88038fd1498Szrj */
88138fd1498Szrj difference_type
88238fd1498Szrj length() const
88338fd1498Szrj { return this->matched ? std::distance(this->first, this->second) : 0; }
88438fd1498Szrj
88538fd1498Szrj /**
88638fd1498Szrj * @brief Gets the matching sequence as a string.
88738fd1498Szrj *
88838fd1498Szrj * @returns the matching sequence as a string.
88938fd1498Szrj *
89038fd1498Szrj * This is the implicit conversion operator. It is identical to the
89138fd1498Szrj * str() member function except that it will want to pop up in
89238fd1498Szrj * unexpected places and cause a great deal of confusion and cursing
89338fd1498Szrj * from the unwary.
89438fd1498Szrj */
89538fd1498Szrj operator string_type() const
89638fd1498Szrj {
89738fd1498Szrj return this->matched
89838fd1498Szrj ? string_type(this->first, this->second)
89938fd1498Szrj : string_type();
90038fd1498Szrj }
90138fd1498Szrj
90238fd1498Szrj /**
90338fd1498Szrj * @brief Gets the matching sequence as a string.
90438fd1498Szrj *
90538fd1498Szrj * @returns the matching sequence as a string.
90638fd1498Szrj */
90738fd1498Szrj string_type
90838fd1498Szrj str() const
90938fd1498Szrj {
91038fd1498Szrj return this->matched
91138fd1498Szrj ? string_type(this->first, this->second)
91238fd1498Szrj : string_type();
91338fd1498Szrj }
91438fd1498Szrj
91538fd1498Szrj /**
91638fd1498Szrj * @brief Compares this and another matched sequence.
91738fd1498Szrj *
91838fd1498Szrj * @param __s Another matched sequence to compare to this one.
91938fd1498Szrj *
92038fd1498Szrj * @retval <0 this matched sequence will collate before @p __s.
92138fd1498Szrj * @retval =0 this matched sequence is equivalent to @p __s.
92238fd1498Szrj * @retval <0 this matched sequence will collate after @p __s.
92338fd1498Szrj */
92438fd1498Szrj int
92538fd1498Szrj compare(const sub_match& __s) const
92638fd1498Szrj { return this->str().compare(__s.str()); }
92738fd1498Szrj
92838fd1498Szrj /**
92938fd1498Szrj * @brief Compares this sub_match to a string.
93038fd1498Szrj *
93138fd1498Szrj * @param __s A string to compare to this sub_match.
93238fd1498Szrj *
93338fd1498Szrj * @retval <0 this matched sequence will collate before @p __s.
93438fd1498Szrj * @retval =0 this matched sequence is equivalent to @p __s.
93538fd1498Szrj * @retval <0 this matched sequence will collate after @p __s.
93638fd1498Szrj */
93738fd1498Szrj int
93838fd1498Szrj compare(const string_type& __s) const
93938fd1498Szrj { return this->str().compare(__s); }
94038fd1498Szrj
94138fd1498Szrj /**
94238fd1498Szrj * @brief Compares this sub_match to a C-style string.
94338fd1498Szrj *
94438fd1498Szrj * @param __s A C-style string to compare to this sub_match.
94538fd1498Szrj *
94638fd1498Szrj * @retval <0 this matched sequence will collate before @p __s.
94738fd1498Szrj * @retval =0 this matched sequence is equivalent to @p __s.
94838fd1498Szrj * @retval <0 this matched sequence will collate after @p __s.
94938fd1498Szrj */
95038fd1498Szrj int
95138fd1498Szrj compare(const value_type* __s) const
95238fd1498Szrj { return this->str().compare(__s); }
95338fd1498Szrj };
95438fd1498Szrj
95538fd1498Szrj
95638fd1498Szrj /** @brief Standard regex submatch over a C-style null-terminated string. */
95738fd1498Szrj typedef sub_match<const char*> csub_match;
95838fd1498Szrj
95938fd1498Szrj /** @brief Standard regex submatch over a standard string. */
96038fd1498Szrj typedef sub_match<string::const_iterator> ssub_match;
96138fd1498Szrj
96238fd1498Szrj #ifdef _GLIBCXX_USE_WCHAR_T
96338fd1498Szrj /** @brief Regex submatch over a C-style null-terminated wide string. */
96438fd1498Szrj typedef sub_match<const wchar_t*> wcsub_match;
96538fd1498Szrj
96638fd1498Szrj /** @brief Regex submatch over a standard wide string. */
96738fd1498Szrj typedef sub_match<wstring::const_iterator> wssub_match;
96838fd1498Szrj #endif
96938fd1498Szrj
97038fd1498Szrj // [7.9.2] sub_match non-member operators
97138fd1498Szrj
97238fd1498Szrj /**
97338fd1498Szrj * @brief Tests the equivalence of two regular expression submatches.
97438fd1498Szrj * @param __lhs First regular expression submatch.
97538fd1498Szrj * @param __rhs Second regular expression submatch.
97638fd1498Szrj * @returns true if @a __lhs is equivalent to @a __rhs, false otherwise.
97738fd1498Szrj */
97838fd1498Szrj template<typename _BiIter>
97938fd1498Szrj inline bool
98038fd1498Szrj operator==(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs)
98138fd1498Szrj { return __lhs.compare(__rhs) == 0; }
98238fd1498Szrj
98338fd1498Szrj /**
98438fd1498Szrj * @brief Tests the inequivalence of two regular expression submatches.
98538fd1498Szrj * @param __lhs First regular expression submatch.
98638fd1498Szrj * @param __rhs Second regular expression submatch.
98738fd1498Szrj * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise.
98838fd1498Szrj */
98938fd1498Szrj template<typename _BiIter>
99038fd1498Szrj inline bool
99138fd1498Szrj operator!=(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs)
99238fd1498Szrj { return __lhs.compare(__rhs) != 0; }
99338fd1498Szrj
99438fd1498Szrj /**
99538fd1498Szrj * @brief Tests the ordering of two regular expression submatches.
99638fd1498Szrj * @param __lhs First regular expression submatch.
99738fd1498Szrj * @param __rhs Second regular expression submatch.
99838fd1498Szrj * @returns true if @a __lhs precedes @a __rhs, false otherwise.
99938fd1498Szrj */
100038fd1498Szrj template<typename _BiIter>
100138fd1498Szrj inline bool
100238fd1498Szrj operator<(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs)
100338fd1498Szrj { return __lhs.compare(__rhs) < 0; }
100438fd1498Szrj
100538fd1498Szrj /**
100638fd1498Szrj * @brief Tests the ordering of two regular expression submatches.
100738fd1498Szrj * @param __lhs First regular expression submatch.
100838fd1498Szrj * @param __rhs Second regular expression submatch.
100938fd1498Szrj * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
101038fd1498Szrj */
101138fd1498Szrj template<typename _BiIter>
101238fd1498Szrj inline bool
101338fd1498Szrj operator<=(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs)
101438fd1498Szrj { return __lhs.compare(__rhs) <= 0; }
101538fd1498Szrj
101638fd1498Szrj /**
101738fd1498Szrj * @brief Tests the ordering of two regular expression submatches.
101838fd1498Szrj * @param __lhs First regular expression submatch.
101938fd1498Szrj * @param __rhs Second regular expression submatch.
102038fd1498Szrj * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
102138fd1498Szrj */
102238fd1498Szrj template<typename _BiIter>
102338fd1498Szrj inline bool
102438fd1498Szrj operator>=(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs)
102538fd1498Szrj { return __lhs.compare(__rhs) >= 0; }
102638fd1498Szrj
102738fd1498Szrj /**
102838fd1498Szrj * @brief Tests the ordering of two regular expression submatches.
102938fd1498Szrj * @param __lhs First regular expression submatch.
103038fd1498Szrj * @param __rhs Second regular expression submatch.
103138fd1498Szrj * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
103238fd1498Szrj */
103338fd1498Szrj template<typename _BiIter>
103438fd1498Szrj inline bool
103538fd1498Szrj operator>(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs)
103638fd1498Szrj { return __lhs.compare(__rhs) > 0; }
103738fd1498Szrj
103838fd1498Szrj // Alias for sub_match'd string.
103938fd1498Szrj template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
104038fd1498Szrj using __sub_match_string = basic_string<
104138fd1498Szrj typename iterator_traits<_Bi_iter>::value_type,
104238fd1498Szrj _Ch_traits, _Ch_alloc>;
104338fd1498Szrj
104438fd1498Szrj /**
104538fd1498Szrj * @brief Tests the equivalence of a string and a regular expression
104638fd1498Szrj * submatch.
104738fd1498Szrj * @param __lhs A string.
104838fd1498Szrj * @param __rhs A regular expression submatch.
104938fd1498Szrj * @returns true if @a __lhs is equivalent to @a __rhs, false otherwise.
105038fd1498Szrj */
105138fd1498Szrj template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
105238fd1498Szrj inline bool
105338fd1498Szrj operator==(const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __lhs,
105438fd1498Szrj const sub_match<_Bi_iter>& __rhs)
105538fd1498Szrj {
105638fd1498Szrj typedef typename sub_match<_Bi_iter>::string_type string_type;
105738fd1498Szrj return __rhs.compare(string_type(__lhs.data(), __lhs.size())) == 0;
105838fd1498Szrj }
105938fd1498Szrj
106038fd1498Szrj /**
106138fd1498Szrj * @brief Tests the inequivalence of a string and a regular expression
106238fd1498Szrj * submatch.
106338fd1498Szrj * @param __lhs A string.
106438fd1498Szrj * @param __rhs A regular expression submatch.
106538fd1498Szrj * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise.
106638fd1498Szrj */
106738fd1498Szrj template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
106838fd1498Szrj inline bool
106938fd1498Szrj operator!=(const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __lhs,
107038fd1498Szrj const sub_match<_Bi_iter>& __rhs)
107138fd1498Szrj { return !(__lhs == __rhs); }
107238fd1498Szrj
107338fd1498Szrj /**
107438fd1498Szrj * @brief Tests the ordering of a string and a regular expression submatch.
107538fd1498Szrj * @param __lhs A string.
107638fd1498Szrj * @param __rhs A regular expression submatch.
107738fd1498Szrj * @returns true if @a __lhs precedes @a __rhs, false otherwise.
107838fd1498Szrj */
107938fd1498Szrj template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
108038fd1498Szrj inline bool
108138fd1498Szrj operator<(const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __lhs,
108238fd1498Szrj const sub_match<_Bi_iter>& __rhs)
108338fd1498Szrj {
108438fd1498Szrj typedef typename sub_match<_Bi_iter>::string_type string_type;
108538fd1498Szrj return __rhs.compare(string_type(__lhs.data(), __lhs.size())) > 0;
108638fd1498Szrj }
108738fd1498Szrj
108838fd1498Szrj /**
108938fd1498Szrj * @brief Tests the ordering of a string and a regular expression submatch.
109038fd1498Szrj * @param __lhs A string.
109138fd1498Szrj * @param __rhs A regular expression submatch.
109238fd1498Szrj * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
109338fd1498Szrj */
109438fd1498Szrj template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
109538fd1498Szrj inline bool
109638fd1498Szrj operator>(const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __lhs,
109738fd1498Szrj const sub_match<_Bi_iter>& __rhs)
109838fd1498Szrj { return __rhs < __lhs; }
109938fd1498Szrj
110038fd1498Szrj /**
110138fd1498Szrj * @brief Tests the ordering of a string and a regular expression submatch.
110238fd1498Szrj * @param __lhs A string.
110338fd1498Szrj * @param __rhs A regular expression submatch.
110438fd1498Szrj * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
110538fd1498Szrj */
110638fd1498Szrj template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
110738fd1498Szrj inline bool
110838fd1498Szrj operator>=(const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __lhs,
110938fd1498Szrj const sub_match<_Bi_iter>& __rhs)
111038fd1498Szrj { return !(__lhs < __rhs); }
111138fd1498Szrj
111238fd1498Szrj /**
111338fd1498Szrj * @brief Tests the ordering of a string and a regular expression submatch.
111438fd1498Szrj * @param __lhs A string.
111538fd1498Szrj * @param __rhs A regular expression submatch.
111638fd1498Szrj * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
111738fd1498Szrj */
111838fd1498Szrj template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
111938fd1498Szrj inline bool
112038fd1498Szrj operator<=(const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __lhs,
112138fd1498Szrj const sub_match<_Bi_iter>& __rhs)
112238fd1498Szrj { return !(__rhs < __lhs); }
112338fd1498Szrj
112438fd1498Szrj /**
112538fd1498Szrj * @brief Tests the equivalence of a regular expression submatch and a
112638fd1498Szrj * string.
112738fd1498Szrj * @param __lhs A regular expression submatch.
112838fd1498Szrj * @param __rhs A string.
112938fd1498Szrj * @returns true if @a __lhs is equivalent to @a __rhs, false otherwise.
113038fd1498Szrj */
113138fd1498Szrj template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
113238fd1498Szrj inline bool
113338fd1498Szrj operator==(const sub_match<_Bi_iter>& __lhs,
113438fd1498Szrj const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __rhs)
113538fd1498Szrj {
113638fd1498Szrj typedef typename sub_match<_Bi_iter>::string_type string_type;
113738fd1498Szrj return __lhs.compare(string_type(__rhs.data(), __rhs.size())) == 0;
113838fd1498Szrj }
113938fd1498Szrj
114038fd1498Szrj /**
114138fd1498Szrj * @brief Tests the inequivalence of a regular expression submatch and a
114238fd1498Szrj * string.
114338fd1498Szrj * @param __lhs A regular expression submatch.
114438fd1498Szrj * @param __rhs A string.
114538fd1498Szrj * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise.
114638fd1498Szrj */
114738fd1498Szrj template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
114838fd1498Szrj inline bool
114938fd1498Szrj operator!=(const sub_match<_Bi_iter>& __lhs,
115038fd1498Szrj const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __rhs)
115138fd1498Szrj { return !(__lhs == __rhs); }
115238fd1498Szrj
115338fd1498Szrj /**
115438fd1498Szrj * @brief Tests the ordering of a regular expression submatch and a string.
115538fd1498Szrj * @param __lhs A regular expression submatch.
115638fd1498Szrj * @param __rhs A string.
115738fd1498Szrj * @returns true if @a __lhs precedes @a __rhs, false otherwise.
115838fd1498Szrj */
115938fd1498Szrj template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc>
116038fd1498Szrj inline bool
116138fd1498Szrj operator<(const sub_match<_Bi_iter>& __lhs,
116238fd1498Szrj const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __rhs)
116338fd1498Szrj {
116438fd1498Szrj typedef typename sub_match<_Bi_iter>::string_type string_type;
116538fd1498Szrj return __lhs.compare(string_type(__rhs.data(), __rhs.size())) < 0;
116638fd1498Szrj }
116738fd1498Szrj
116838fd1498Szrj /**
116938fd1498Szrj * @brief Tests the ordering of a regular expression submatch and a string.
117038fd1498Szrj * @param __lhs A regular expression submatch.
117138fd1498Szrj * @param __rhs A string.
117238fd1498Szrj * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
117338fd1498Szrj */
117438fd1498Szrj template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc>
117538fd1498Szrj inline bool
117638fd1498Szrj operator>(const sub_match<_Bi_iter>& __lhs,
117738fd1498Szrj const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __rhs)
117838fd1498Szrj { return __rhs < __lhs; }
117938fd1498Szrj
118038fd1498Szrj /**
118138fd1498Szrj * @brief Tests the ordering of a regular expression submatch and a string.
118238fd1498Szrj * @param __lhs A regular expression submatch.
118338fd1498Szrj * @param __rhs A string.
118438fd1498Szrj * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
118538fd1498Szrj */
118638fd1498Szrj template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc>
118738fd1498Szrj inline bool
118838fd1498Szrj operator>=(const sub_match<_Bi_iter>& __lhs,
118938fd1498Szrj const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __rhs)
119038fd1498Szrj { return !(__lhs < __rhs); }
119138fd1498Szrj
119238fd1498Szrj /**
119338fd1498Szrj * @brief Tests the ordering of a regular expression submatch and a string.
119438fd1498Szrj * @param __lhs A regular expression submatch.
119538fd1498Szrj * @param __rhs A string.
119638fd1498Szrj * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
119738fd1498Szrj */
119838fd1498Szrj template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc>
119938fd1498Szrj inline bool
120038fd1498Szrj operator<=(const sub_match<_Bi_iter>& __lhs,
120138fd1498Szrj const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __rhs)
120238fd1498Szrj { return !(__rhs < __lhs); }
120338fd1498Szrj
120438fd1498Szrj /**
120538fd1498Szrj * @brief Tests the equivalence of a C string and a regular expression
120638fd1498Szrj * submatch.
120738fd1498Szrj * @param __lhs A C string.
120838fd1498Szrj * @param __rhs A regular expression submatch.
120938fd1498Szrj * @returns true if @a __lhs is equivalent to @a __rhs, false otherwise.
121038fd1498Szrj */
121138fd1498Szrj template<typename _Bi_iter>
121238fd1498Szrj inline bool
121338fd1498Szrj operator==(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
121438fd1498Szrj const sub_match<_Bi_iter>& __rhs)
121538fd1498Szrj { return __rhs.compare(__lhs) == 0; }
121638fd1498Szrj
121738fd1498Szrj /**
121838fd1498Szrj * @brief Tests the inequivalence of an iterator value and a regular
121938fd1498Szrj * expression submatch.
122038fd1498Szrj * @param __lhs A regular expression submatch.
122138fd1498Szrj * @param __rhs A string.
122238fd1498Szrj * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise.
122338fd1498Szrj */
122438fd1498Szrj template<typename _Bi_iter>
122538fd1498Szrj inline bool
122638fd1498Szrj operator!=(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
122738fd1498Szrj const sub_match<_Bi_iter>& __rhs)
122838fd1498Szrj { return !(__lhs == __rhs); }
122938fd1498Szrj
123038fd1498Szrj /**
123138fd1498Szrj * @brief Tests the ordering of a string and a regular expression submatch.
123238fd1498Szrj * @param __lhs A string.
123338fd1498Szrj * @param __rhs A regular expression submatch.
123438fd1498Szrj * @returns true if @a __lhs precedes @a __rhs, false otherwise.
123538fd1498Szrj */
123638fd1498Szrj template<typename _Bi_iter>
123738fd1498Szrj inline bool
123838fd1498Szrj operator<(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
123938fd1498Szrj const sub_match<_Bi_iter>& __rhs)
124038fd1498Szrj { return __rhs.compare(__lhs) > 0; }
124138fd1498Szrj
124238fd1498Szrj /**
124338fd1498Szrj * @brief Tests the ordering of a string and a regular expression submatch.
124438fd1498Szrj * @param __lhs A string.
124538fd1498Szrj * @param __rhs A regular expression submatch.
124638fd1498Szrj * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
124738fd1498Szrj */
124838fd1498Szrj template<typename _Bi_iter>
124938fd1498Szrj inline bool
125038fd1498Szrj operator>(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
125138fd1498Szrj const sub_match<_Bi_iter>& __rhs)
125238fd1498Szrj { return __rhs < __lhs; }
125338fd1498Szrj
125438fd1498Szrj /**
125538fd1498Szrj * @brief Tests the ordering of a string and a regular expression submatch.
125638fd1498Szrj * @param __lhs A string.
125738fd1498Szrj * @param __rhs A regular expression submatch.
125838fd1498Szrj * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
125938fd1498Szrj */
126038fd1498Szrj template<typename _Bi_iter>
126138fd1498Szrj inline bool
126238fd1498Szrj operator>=(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
126338fd1498Szrj const sub_match<_Bi_iter>& __rhs)
126438fd1498Szrj { return !(__lhs < __rhs); }
126538fd1498Szrj
126638fd1498Szrj /**
126738fd1498Szrj * @brief Tests the ordering of a string and a regular expression submatch.
126838fd1498Szrj * @param __lhs A string.
126938fd1498Szrj * @param __rhs A regular expression submatch.
127038fd1498Szrj * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
127138fd1498Szrj */
127238fd1498Szrj template<typename _Bi_iter>
127338fd1498Szrj inline bool
127438fd1498Szrj operator<=(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
127538fd1498Szrj const sub_match<_Bi_iter>& __rhs)
127638fd1498Szrj { return !(__rhs < __lhs); }
127738fd1498Szrj
127838fd1498Szrj /**
127938fd1498Szrj * @brief Tests the equivalence of a regular expression submatch and a
128038fd1498Szrj * string.
128138fd1498Szrj * @param __lhs A regular expression submatch.
128238fd1498Szrj * @param __rhs A pointer to a string?
128338fd1498Szrj * @returns true if @a __lhs is equivalent to @a __rhs, false otherwise.
128438fd1498Szrj */
128538fd1498Szrj template<typename _Bi_iter>
128638fd1498Szrj inline bool
128738fd1498Szrj operator==(const sub_match<_Bi_iter>& __lhs,
128838fd1498Szrj typename iterator_traits<_Bi_iter>::value_type const* __rhs)
128938fd1498Szrj { return __lhs.compare(__rhs) == 0; }
129038fd1498Szrj
129138fd1498Szrj /**
129238fd1498Szrj * @brief Tests the inequivalence of a regular expression submatch and a
129338fd1498Szrj * string.
129438fd1498Szrj * @param __lhs A regular expression submatch.
129538fd1498Szrj * @param __rhs A pointer to a string.
129638fd1498Szrj * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise.
129738fd1498Szrj */
129838fd1498Szrj template<typename _Bi_iter>
129938fd1498Szrj inline bool
130038fd1498Szrj operator!=(const sub_match<_Bi_iter>& __lhs,
130138fd1498Szrj typename iterator_traits<_Bi_iter>::value_type const* __rhs)
130238fd1498Szrj { return !(__lhs == __rhs); }
130338fd1498Szrj
130438fd1498Szrj /**
130538fd1498Szrj * @brief Tests the ordering of a regular expression submatch and a string.
130638fd1498Szrj * @param __lhs A regular expression submatch.
130738fd1498Szrj * @param __rhs A string.
130838fd1498Szrj * @returns true if @a __lhs precedes @a __rhs, false otherwise.
130938fd1498Szrj */
131038fd1498Szrj template<typename _Bi_iter>
131138fd1498Szrj inline bool
131238fd1498Szrj operator<(const sub_match<_Bi_iter>& __lhs,
131338fd1498Szrj typename iterator_traits<_Bi_iter>::value_type const* __rhs)
131438fd1498Szrj { return __lhs.compare(__rhs) < 0; }
131538fd1498Szrj
131638fd1498Szrj /**
131738fd1498Szrj * @brief Tests the ordering of a regular expression submatch and a string.
131838fd1498Szrj * @param __lhs A regular expression submatch.
131938fd1498Szrj * @param __rhs A string.
132038fd1498Szrj * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
132138fd1498Szrj */
132238fd1498Szrj template<typename _Bi_iter>
132338fd1498Szrj inline bool
132438fd1498Szrj operator>(const sub_match<_Bi_iter>& __lhs,
132538fd1498Szrj typename iterator_traits<_Bi_iter>::value_type const* __rhs)
132638fd1498Szrj { return __rhs < __lhs; }
132738fd1498Szrj
132838fd1498Szrj /**
132938fd1498Szrj * @brief Tests the ordering of a regular expression submatch and a string.
133038fd1498Szrj * @param __lhs A regular expression submatch.
133138fd1498Szrj * @param __rhs A string.
133238fd1498Szrj * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
133338fd1498Szrj */
133438fd1498Szrj template<typename _Bi_iter>
133538fd1498Szrj inline bool
133638fd1498Szrj operator>=(const sub_match<_Bi_iter>& __lhs,
133738fd1498Szrj typename iterator_traits<_Bi_iter>::value_type const* __rhs)
133838fd1498Szrj { return !(__lhs < __rhs); }
133938fd1498Szrj
134038fd1498Szrj /**
134138fd1498Szrj * @brief Tests the ordering of a regular expression submatch and a string.
134238fd1498Szrj * @param __lhs A regular expression submatch.
134338fd1498Szrj * @param __rhs A string.
134438fd1498Szrj * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
134538fd1498Szrj */
134638fd1498Szrj template<typename _Bi_iter>
134738fd1498Szrj inline bool
134838fd1498Szrj operator<=(const sub_match<_Bi_iter>& __lhs,
134938fd1498Szrj typename iterator_traits<_Bi_iter>::value_type const* __rhs)
135038fd1498Szrj { return !(__rhs < __lhs); }
135138fd1498Szrj
135238fd1498Szrj /**
135338fd1498Szrj * @brief Tests the equivalence of a string and a regular expression
135438fd1498Szrj * submatch.
135538fd1498Szrj * @param __lhs A string.
135638fd1498Szrj * @param __rhs A regular expression submatch.
135738fd1498Szrj * @returns true if @a __lhs is equivalent to @a __rhs, false otherwise.
135838fd1498Szrj */
135938fd1498Szrj template<typename _Bi_iter>
136038fd1498Szrj inline bool
136138fd1498Szrj operator==(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
136238fd1498Szrj const sub_match<_Bi_iter>& __rhs)
136338fd1498Szrj {
136438fd1498Szrj typedef typename sub_match<_Bi_iter>::string_type string_type;
136538fd1498Szrj return __rhs.compare(string_type(1, __lhs)) == 0;
136638fd1498Szrj }
136738fd1498Szrj
136838fd1498Szrj /**
136938fd1498Szrj * @brief Tests the inequivalence of a string and a regular expression
137038fd1498Szrj * submatch.
137138fd1498Szrj * @param __lhs A string.
137238fd1498Szrj * @param __rhs A regular expression submatch.
137338fd1498Szrj * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise.
137438fd1498Szrj */
137538fd1498Szrj template<typename _Bi_iter>
137638fd1498Szrj inline bool
137738fd1498Szrj operator!=(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
137838fd1498Szrj const sub_match<_Bi_iter>& __rhs)
137938fd1498Szrj { return !(__lhs == __rhs); }
138038fd1498Szrj
138138fd1498Szrj /**
138238fd1498Szrj * @brief Tests the ordering of a string and a regular expression submatch.
138338fd1498Szrj * @param __lhs A string.
138438fd1498Szrj * @param __rhs A regular expression submatch.
138538fd1498Szrj * @returns true if @a __lhs precedes @a __rhs, false otherwise.
138638fd1498Szrj */
138738fd1498Szrj template<typename _Bi_iter>
138838fd1498Szrj inline bool
138938fd1498Szrj operator<(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
139038fd1498Szrj const sub_match<_Bi_iter>& __rhs)
139138fd1498Szrj {
139238fd1498Szrj typedef typename sub_match<_Bi_iter>::string_type string_type;
139338fd1498Szrj return __rhs.compare(string_type(1, __lhs)) > 0;
139438fd1498Szrj }
139538fd1498Szrj
139638fd1498Szrj /**
139738fd1498Szrj * @brief Tests the ordering of a string and a regular expression submatch.
139838fd1498Szrj * @param __lhs A string.
139938fd1498Szrj * @param __rhs A regular expression submatch.
140038fd1498Szrj * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
140138fd1498Szrj */
140238fd1498Szrj template<typename _Bi_iter>
140338fd1498Szrj inline bool
140438fd1498Szrj operator>(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
140538fd1498Szrj const sub_match<_Bi_iter>& __rhs)
140638fd1498Szrj { return __rhs < __lhs; }
140738fd1498Szrj
140838fd1498Szrj /**
140938fd1498Szrj * @brief Tests the ordering of a string and a regular expression submatch.
141038fd1498Szrj * @param __lhs A string.
141138fd1498Szrj * @param __rhs A regular expression submatch.
141238fd1498Szrj * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
141338fd1498Szrj */
141438fd1498Szrj template<typename _Bi_iter>
141538fd1498Szrj inline bool
141638fd1498Szrj operator>=(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
141738fd1498Szrj const sub_match<_Bi_iter>& __rhs)
141838fd1498Szrj { return !(__lhs < __rhs); }
141938fd1498Szrj
142038fd1498Szrj /**
142138fd1498Szrj * @brief Tests the ordering of a string and a regular expression submatch.
142238fd1498Szrj * @param __lhs A string.
142338fd1498Szrj * @param __rhs A regular expression submatch.
142438fd1498Szrj * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
142538fd1498Szrj */
142638fd1498Szrj template<typename _Bi_iter>
142738fd1498Szrj inline bool
142838fd1498Szrj operator<=(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
142938fd1498Szrj const sub_match<_Bi_iter>& __rhs)
143038fd1498Szrj { return !(__rhs < __lhs); }
143138fd1498Szrj
143238fd1498Szrj /**
143338fd1498Szrj * @brief Tests the equivalence of a regular expression submatch and a
143438fd1498Szrj * string.
143538fd1498Szrj * @param __lhs A regular expression submatch.
143638fd1498Szrj * @param __rhs A const string reference.
143738fd1498Szrj * @returns true if @a __lhs is equivalent to @a __rhs, false otherwise.
143838fd1498Szrj */
143938fd1498Szrj template<typename _Bi_iter>
144038fd1498Szrj inline bool
144138fd1498Szrj operator==(const sub_match<_Bi_iter>& __lhs,
144238fd1498Szrj typename iterator_traits<_Bi_iter>::value_type const& __rhs)
144338fd1498Szrj {
144438fd1498Szrj typedef typename sub_match<_Bi_iter>::string_type string_type;
144538fd1498Szrj return __lhs.compare(string_type(1, __rhs)) == 0;
144638fd1498Szrj }
144738fd1498Szrj
144838fd1498Szrj /**
144938fd1498Szrj * @brief Tests the inequivalence of a regular expression submatch and a
145038fd1498Szrj * string.
145138fd1498Szrj * @param __lhs A regular expression submatch.
145238fd1498Szrj * @param __rhs A const string reference.
145338fd1498Szrj * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise.
145438fd1498Szrj */
145538fd1498Szrj template<typename _Bi_iter>
145638fd1498Szrj inline bool
145738fd1498Szrj operator!=(const sub_match<_Bi_iter>& __lhs,
145838fd1498Szrj typename iterator_traits<_Bi_iter>::value_type const& __rhs)
145938fd1498Szrj { return !(__lhs == __rhs); }
146038fd1498Szrj
146138fd1498Szrj /**
146238fd1498Szrj * @brief Tests the ordering of a regular expression submatch and a string.
146338fd1498Szrj * @param __lhs A regular expression submatch.
146438fd1498Szrj * @param __rhs A const string reference.
146538fd1498Szrj * @returns true if @a __lhs precedes @a __rhs, false otherwise.
146638fd1498Szrj */
146738fd1498Szrj template<typename _Bi_iter>
146838fd1498Szrj inline bool
146938fd1498Szrj operator<(const sub_match<_Bi_iter>& __lhs,
147038fd1498Szrj typename iterator_traits<_Bi_iter>::value_type const& __rhs)
147138fd1498Szrj {
147238fd1498Szrj typedef typename sub_match<_Bi_iter>::string_type string_type;
147338fd1498Szrj return __lhs.compare(string_type(1, __rhs)) < 0;
147438fd1498Szrj }
147538fd1498Szrj
147638fd1498Szrj /**
147738fd1498Szrj * @brief Tests the ordering of a regular expression submatch and a string.
147838fd1498Szrj * @param __lhs A regular expression submatch.
147938fd1498Szrj * @param __rhs A const string reference.
148038fd1498Szrj * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
148138fd1498Szrj */
148238fd1498Szrj template<typename _Bi_iter>
148338fd1498Szrj inline bool
148438fd1498Szrj operator>(const sub_match<_Bi_iter>& __lhs,
148538fd1498Szrj typename iterator_traits<_Bi_iter>::value_type const& __rhs)
148638fd1498Szrj { return __rhs < __lhs; }
148738fd1498Szrj
148838fd1498Szrj /**
148938fd1498Szrj * @brief Tests the ordering of a regular expression submatch and a string.
149038fd1498Szrj * @param __lhs A regular expression submatch.
149138fd1498Szrj * @param __rhs A const string reference.
149238fd1498Szrj * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
149338fd1498Szrj */
149438fd1498Szrj template<typename _Bi_iter>
149538fd1498Szrj inline bool
149638fd1498Szrj operator>=(const sub_match<_Bi_iter>& __lhs,
149738fd1498Szrj typename iterator_traits<_Bi_iter>::value_type const& __rhs)
149838fd1498Szrj { return !(__lhs < __rhs); }
149938fd1498Szrj
150038fd1498Szrj /**
150138fd1498Szrj * @brief Tests the ordering of a regular expression submatch and a string.
150238fd1498Szrj * @param __lhs A regular expression submatch.
150338fd1498Szrj * @param __rhs A const string reference.
150438fd1498Szrj * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
150538fd1498Szrj */
150638fd1498Szrj template<typename _Bi_iter>
150738fd1498Szrj inline bool
150838fd1498Szrj operator<=(const sub_match<_Bi_iter>& __lhs,
150938fd1498Szrj typename iterator_traits<_Bi_iter>::value_type const& __rhs)
151038fd1498Szrj { return !(__rhs < __lhs); }
151138fd1498Szrj
151238fd1498Szrj /**
151338fd1498Szrj * @brief Inserts a matched string into an output stream.
151438fd1498Szrj *
151538fd1498Szrj * @param __os The output stream.
151638fd1498Szrj * @param __m A submatch string.
151738fd1498Szrj *
151838fd1498Szrj * @returns the output stream with the submatch string inserted.
151938fd1498Szrj */
152038fd1498Szrj template<typename _Ch_type, typename _Ch_traits, typename _Bi_iter>
152138fd1498Szrj inline
152238fd1498Szrj basic_ostream<_Ch_type, _Ch_traits>&
152338fd1498Szrj operator<<(basic_ostream<_Ch_type, _Ch_traits>& __os,
152438fd1498Szrj const sub_match<_Bi_iter>& __m)
152538fd1498Szrj { return __os << __m.str(); }
152638fd1498Szrj
152738fd1498Szrj // [7.10] Class template match_results
152838fd1498Szrj
152938fd1498Szrj /**
153038fd1498Szrj * @brief The results of a match or search operation.
153138fd1498Szrj *
153238fd1498Szrj * A collection of character sequences representing the result of a regular
153338fd1498Szrj * expression match. Storage for the collection is allocated and freed as
153438fd1498Szrj * necessary by the member functions of class template match_results.
153538fd1498Szrj *
153638fd1498Szrj * This class satisfies the Sequence requirements, with the exception that
153738fd1498Szrj * only the operations defined for a const-qualified Sequence are supported.
153838fd1498Szrj *
153938fd1498Szrj * The sub_match object stored at index 0 represents sub-expression 0, i.e.
154038fd1498Szrj * the whole match. In this case the %sub_match member matched is always true.
154138fd1498Szrj * The sub_match object stored at index n denotes what matched the marked
154238fd1498Szrj * sub-expression n within the matched expression. If the sub-expression n
154338fd1498Szrj * participated in a regular expression match then the %sub_match member
154438fd1498Szrj * matched evaluates to true, and members first and second denote the range
154538fd1498Szrj * of characters [first, second) which formed that match. Otherwise matched
154638fd1498Szrj * is false, and members first and second point to the end of the sequence
154738fd1498Szrj * that was searched.
154838fd1498Szrj *
154938fd1498Szrj * @nosubgrouping
155038fd1498Szrj */
155138fd1498Szrj template<typename _Bi_iter,
155238fd1498Szrj typename _Alloc = allocator<sub_match<_Bi_iter> > >
155338fd1498Szrj class match_results
155438fd1498Szrj : private std::vector<sub_match<_Bi_iter>, _Alloc>
155538fd1498Szrj {
155638fd1498Szrj private:
155738fd1498Szrj /*
155838fd1498Szrj * The vector base is empty if this does not represent a match (!ready());
155938fd1498Szrj * Otherwise if it's a match failure, it contains 3 elements:
156038fd1498Szrj * [0] unmatched
156138fd1498Szrj * [1] prefix
156238fd1498Szrj * [2] suffix
156338fd1498Szrj * Otherwise it contains n+4 elements where n is the number of marked
156438fd1498Szrj * sub-expressions:
156538fd1498Szrj * [0] entire match
156638fd1498Szrj * [1] 1st marked subexpression
156738fd1498Szrj * ...
156838fd1498Szrj * [n] nth marked subexpression
156938fd1498Szrj * [n+1] unmatched
157038fd1498Szrj * [n+2] prefix
157138fd1498Szrj * [n+3] suffix
157238fd1498Szrj */
157338fd1498Szrj typedef std::vector<sub_match<_Bi_iter>, _Alloc> _Base_type;
157438fd1498Szrj typedef std::iterator_traits<_Bi_iter> __iter_traits;
157538fd1498Szrj typedef regex_constants::match_flag_type match_flag_type;
157638fd1498Szrj
157738fd1498Szrj public:
157838fd1498Szrj /**
157938fd1498Szrj * @name 10.? Public Types
158038fd1498Szrj */
158138fd1498Szrj //@{
158238fd1498Szrj typedef sub_match<_Bi_iter> value_type;
158338fd1498Szrj typedef const value_type& const_reference;
158438fd1498Szrj typedef value_type& reference;
158538fd1498Szrj typedef typename _Base_type::const_iterator const_iterator;
158638fd1498Szrj typedef const_iterator iterator;
158738fd1498Szrj typedef typename __iter_traits::difference_type difference_type;
158838fd1498Szrj typedef typename allocator_traits<_Alloc>::size_type size_type;
158938fd1498Szrj typedef _Alloc allocator_type;
159038fd1498Szrj typedef typename __iter_traits::value_type char_type;
159138fd1498Szrj typedef std::basic_string<char_type> string_type;
159238fd1498Szrj //@}
159338fd1498Szrj
159438fd1498Szrj public:
159538fd1498Szrj /**
159638fd1498Szrj * @name 28.10.1 Construction, Copying, and Destruction
159738fd1498Szrj */
159838fd1498Szrj //@{
159938fd1498Szrj
160038fd1498Szrj /**
160138fd1498Szrj * @brief Constructs a default %match_results container.
160238fd1498Szrj * @post size() returns 0 and str() returns an empty string.
160338fd1498Szrj */
160438fd1498Szrj explicit
160538fd1498Szrj match_results(const _Alloc& __a = _Alloc())
160638fd1498Szrj : _Base_type(__a)
160738fd1498Szrj { }
160838fd1498Szrj
160938fd1498Szrj /**
161038fd1498Szrj * @brief Copy constructs a %match_results.
161138fd1498Szrj */
161238fd1498Szrj match_results(const match_results& __rhs) = default;
161338fd1498Szrj
161438fd1498Szrj /**
161538fd1498Szrj * @brief Move constructs a %match_results.
161638fd1498Szrj */
161738fd1498Szrj match_results(match_results&& __rhs) noexcept = default;
161838fd1498Szrj
161938fd1498Szrj /**
162038fd1498Szrj * @brief Assigns rhs to *this.
162138fd1498Szrj */
162238fd1498Szrj match_results&
162338fd1498Szrj operator=(const match_results& __rhs) = default;
162438fd1498Szrj
162538fd1498Szrj /**
162638fd1498Szrj * @brief Move-assigns rhs to *this.
162738fd1498Szrj */
162838fd1498Szrj match_results&
162938fd1498Szrj operator=(match_results&& __rhs) = default;
163038fd1498Szrj
163138fd1498Szrj /**
163238fd1498Szrj * @brief Destroys a %match_results object.
163338fd1498Szrj */
163438fd1498Szrj ~match_results()
163538fd1498Szrj { }
163638fd1498Szrj
163738fd1498Szrj //@}
163838fd1498Szrj
163938fd1498Szrj // 28.10.2, state:
164038fd1498Szrj /**
164138fd1498Szrj * @brief Indicates if the %match_results is ready.
164238fd1498Szrj * @retval true The object has a fully-established result state.
164338fd1498Szrj * @retval false The object is not ready.
164438fd1498Szrj */
164538fd1498Szrj bool ready() const { return !_Base_type::empty(); }
164638fd1498Szrj
164738fd1498Szrj /**
164838fd1498Szrj * @name 28.10.2 Size
164938fd1498Szrj */
165038fd1498Szrj //@{
165138fd1498Szrj
165238fd1498Szrj /**
165338fd1498Szrj * @brief Gets the number of matches and submatches.
165438fd1498Szrj *
165538fd1498Szrj * The number of matches for a given regular expression will be either 0
165638fd1498Szrj * if there was no match or mark_count() + 1 if a match was successful.
165738fd1498Szrj * Some matches may be empty.
165838fd1498Szrj *
165938fd1498Szrj * @returns the number of matches found.
166038fd1498Szrj */
166138fd1498Szrj size_type
166238fd1498Szrj size() const
166338fd1498Szrj { return _Base_type::empty() ? 0 : _Base_type::size() - 3; }
166438fd1498Szrj
166538fd1498Szrj size_type
166638fd1498Szrj max_size() const
166738fd1498Szrj { return _Base_type::max_size(); }
166838fd1498Szrj
166938fd1498Szrj /**
167038fd1498Szrj * @brief Indicates if the %match_results contains no results.
167138fd1498Szrj * @retval true The %match_results object is empty.
167238fd1498Szrj * @retval false The %match_results object is not empty.
167338fd1498Szrj */
167438fd1498Szrj bool
167538fd1498Szrj empty() const
167638fd1498Szrj { return size() == 0; }
167738fd1498Szrj
167838fd1498Szrj //@}
167938fd1498Szrj
168038fd1498Szrj /**
168138fd1498Szrj * @name 10.3 Element Access
168238fd1498Szrj */
168338fd1498Szrj //@{
168438fd1498Szrj
168538fd1498Szrj /**
168638fd1498Szrj * @brief Gets the length of the indicated submatch.
168738fd1498Szrj * @param __sub indicates the submatch.
168838fd1498Szrj * @pre ready() == true
168938fd1498Szrj *
169038fd1498Szrj * This function returns the length of the indicated submatch, or the
169138fd1498Szrj * length of the entire match if @p __sub is zero (the default).
169238fd1498Szrj */
169338fd1498Szrj difference_type
169438fd1498Szrj length(size_type __sub = 0) const
169538fd1498Szrj { return (*this)[__sub].length(); }
169638fd1498Szrj
169738fd1498Szrj /**
169838fd1498Szrj * @brief Gets the offset of the beginning of the indicated submatch.
169938fd1498Szrj * @param __sub indicates the submatch.
170038fd1498Szrj * @pre ready() == true
170138fd1498Szrj *
170238fd1498Szrj * This function returns the offset from the beginning of the target
170338fd1498Szrj * sequence to the beginning of the submatch, unless the value of @p __sub
170438fd1498Szrj * is zero (the default), in which case this function returns the offset
170538fd1498Szrj * from the beginning of the target sequence to the beginning of the
170638fd1498Szrj * match.
170738fd1498Szrj */
170838fd1498Szrj difference_type
170938fd1498Szrj position(size_type __sub = 0) const
171038fd1498Szrj { return std::distance(_M_begin, (*this)[__sub].first); }
171138fd1498Szrj
171238fd1498Szrj /**
171338fd1498Szrj * @brief Gets the match or submatch converted to a string type.
171438fd1498Szrj * @param __sub indicates the submatch.
171538fd1498Szrj * @pre ready() == true
171638fd1498Szrj *
171738fd1498Szrj * This function gets the submatch (or match, if @p __sub is
171838fd1498Szrj * zero) extracted from the target range and converted to the
171938fd1498Szrj * associated string type.
172038fd1498Szrj */
172138fd1498Szrj string_type
172238fd1498Szrj str(size_type __sub = 0) const
172338fd1498Szrj { return string_type((*this)[__sub]); }
172438fd1498Szrj
172538fd1498Szrj /**
172638fd1498Szrj * @brief Gets a %sub_match reference for the match or submatch.
172738fd1498Szrj * @param __sub indicates the submatch.
172838fd1498Szrj * @pre ready() == true
172938fd1498Szrj *
173038fd1498Szrj * This function gets a reference to the indicated submatch, or
173138fd1498Szrj * the entire match if @p __sub is zero.
173238fd1498Szrj *
173338fd1498Szrj * If @p __sub >= size() then this function returns a %sub_match with a
173438fd1498Szrj * special value indicating no submatch.
173538fd1498Szrj */
173638fd1498Szrj const_reference
173738fd1498Szrj operator[](size_type __sub) const
173838fd1498Szrj {
173938fd1498Szrj __glibcxx_assert( ready() );
174038fd1498Szrj return __sub < size()
174138fd1498Szrj ? _Base_type::operator[](__sub)
174238fd1498Szrj : _M_unmatched_sub();
174338fd1498Szrj }
174438fd1498Szrj
174538fd1498Szrj /**
174638fd1498Szrj * @brief Gets a %sub_match representing the match prefix.
174738fd1498Szrj * @pre ready() == true
174838fd1498Szrj *
174938fd1498Szrj * This function gets a reference to a %sub_match object representing the
175038fd1498Szrj * part of the target range between the start of the target range and the
175138fd1498Szrj * start of the match.
175238fd1498Szrj */
175338fd1498Szrj const_reference
175438fd1498Szrj prefix() const
175538fd1498Szrj {
175638fd1498Szrj __glibcxx_assert( ready() );
175738fd1498Szrj return !empty() ? _M_prefix() : _M_unmatched_sub();
175838fd1498Szrj }
175938fd1498Szrj
176038fd1498Szrj /**
176138fd1498Szrj * @brief Gets a %sub_match representing the match suffix.
176238fd1498Szrj * @pre ready() == true
176338fd1498Szrj *
176438fd1498Szrj * This function gets a reference to a %sub_match object representing the
176538fd1498Szrj * part of the target range between the end of the match and the end of
176638fd1498Szrj * the target range.
176738fd1498Szrj */
176838fd1498Szrj const_reference
176938fd1498Szrj suffix() const
177038fd1498Szrj {
177138fd1498Szrj __glibcxx_assert( ready() );
177238fd1498Szrj return !empty() ? _M_suffix() : _M_unmatched_sub();
177338fd1498Szrj }
177438fd1498Szrj
177538fd1498Szrj /**
177638fd1498Szrj * @brief Gets an iterator to the start of the %sub_match collection.
177738fd1498Szrj */
177838fd1498Szrj const_iterator
177938fd1498Szrj begin() const
178038fd1498Szrj { return _Base_type::begin(); }
178138fd1498Szrj
178238fd1498Szrj /**
178338fd1498Szrj * @brief Gets an iterator to the start of the %sub_match collection.
178438fd1498Szrj */
178538fd1498Szrj const_iterator
178638fd1498Szrj cbegin() const
178738fd1498Szrj { return this->begin(); }
178838fd1498Szrj
178938fd1498Szrj /**
179038fd1498Szrj * @brief Gets an iterator to one-past-the-end of the collection.
179138fd1498Szrj */
179238fd1498Szrj const_iterator
179338fd1498Szrj end() const
179438fd1498Szrj { return _Base_type::end() - (empty() ? 0 : 3); }
179538fd1498Szrj
179638fd1498Szrj /**
179738fd1498Szrj * @brief Gets an iterator to one-past-the-end of the collection.
179838fd1498Szrj */
179938fd1498Szrj const_iterator
180038fd1498Szrj cend() const
180138fd1498Szrj { return this->end(); }
180238fd1498Szrj
180338fd1498Szrj //@}
180438fd1498Szrj
180538fd1498Szrj /**
180638fd1498Szrj * @name 10.4 Formatting
180738fd1498Szrj *
180838fd1498Szrj * These functions perform formatted substitution of the matched
180938fd1498Szrj * character sequences into their target. The format specifiers and
181038fd1498Szrj * escape sequences accepted by these functions are determined by
181138fd1498Szrj * their @p flags parameter as documented above.
181238fd1498Szrj */
181338fd1498Szrj //@{
181438fd1498Szrj
181538fd1498Szrj /**
181638fd1498Szrj * @pre ready() == true
181738fd1498Szrj */
181838fd1498Szrj template<typename _Out_iter>
181938fd1498Szrj _Out_iter
182038fd1498Szrj format(_Out_iter __out, const char_type* __fmt_first,
182138fd1498Szrj const char_type* __fmt_last,
182238fd1498Szrj match_flag_type __flags = regex_constants::format_default) const;
182338fd1498Szrj
182438fd1498Szrj /**
182538fd1498Szrj * @pre ready() == true
182638fd1498Szrj */
182738fd1498Szrj template<typename _Out_iter, typename _St, typename _Sa>
182838fd1498Szrj _Out_iter
182938fd1498Szrj format(_Out_iter __out, const basic_string<char_type, _St, _Sa>& __fmt,
183038fd1498Szrj match_flag_type __flags = regex_constants::format_default) const
183138fd1498Szrj {
183238fd1498Szrj return format(__out, __fmt.data(), __fmt.data() + __fmt.size(),
183338fd1498Szrj __flags);
183438fd1498Szrj }
183538fd1498Szrj
183638fd1498Szrj /**
183738fd1498Szrj * @pre ready() == true
183838fd1498Szrj */
183938fd1498Szrj template<typename _St, typename _Sa>
184038fd1498Szrj basic_string<char_type, _St, _Sa>
184138fd1498Szrj format(const basic_string<char_type, _St, _Sa>& __fmt,
184238fd1498Szrj match_flag_type __flags = regex_constants::format_default) const
184338fd1498Szrj {
184438fd1498Szrj basic_string<char_type, _St, _Sa> __result;
184538fd1498Szrj format(std::back_inserter(__result), __fmt, __flags);
184638fd1498Szrj return __result;
184738fd1498Szrj }
184838fd1498Szrj
184938fd1498Szrj /**
185038fd1498Szrj * @pre ready() == true
185138fd1498Szrj */
185238fd1498Szrj string_type
185338fd1498Szrj format(const char_type* __fmt,
185438fd1498Szrj match_flag_type __flags = regex_constants::format_default) const
185538fd1498Szrj {
185638fd1498Szrj string_type __result;
185738fd1498Szrj format(std::back_inserter(__result),
185838fd1498Szrj __fmt,
185938fd1498Szrj __fmt + char_traits<char_type>::length(__fmt),
186038fd1498Szrj __flags);
186138fd1498Szrj return __result;
186238fd1498Szrj }
186338fd1498Szrj
186438fd1498Szrj //@}
186538fd1498Szrj
186638fd1498Szrj /**
186738fd1498Szrj * @name 10.5 Allocator
186838fd1498Szrj */
186938fd1498Szrj //@{
187038fd1498Szrj
187138fd1498Szrj /**
187238fd1498Szrj * @brief Gets a copy of the allocator.
187338fd1498Szrj */
187438fd1498Szrj allocator_type
187538fd1498Szrj get_allocator() const
187638fd1498Szrj { return _Base_type::get_allocator(); }
187738fd1498Szrj
187838fd1498Szrj //@}
187938fd1498Szrj
188038fd1498Szrj /**
188138fd1498Szrj * @name 10.6 Swap
188238fd1498Szrj */
188338fd1498Szrj //@{
188438fd1498Szrj
188538fd1498Szrj /**
188638fd1498Szrj * @brief Swaps the contents of two match_results.
188738fd1498Szrj */
188838fd1498Szrj void
188938fd1498Szrj swap(match_results& __that)
189038fd1498Szrj {
189138fd1498Szrj using std::swap;
189238fd1498Szrj _Base_type::swap(__that);
189338fd1498Szrj swap(_M_begin, __that._M_begin);
189438fd1498Szrj }
189538fd1498Szrj //@}
189638fd1498Szrj
189738fd1498Szrj private:
189838fd1498Szrj template<typename, typename, typename, bool>
189938fd1498Szrj friend class __detail::_Executor;
190038fd1498Szrj
190138fd1498Szrj template<typename, typename, typename>
190238fd1498Szrj friend class regex_iterator;
190338fd1498Szrj
190438fd1498Szrj template<typename _Bp, typename _Ap, typename _Cp, typename _Rp,
190538fd1498Szrj __detail::_RegexExecutorPolicy, bool>
190638fd1498Szrj friend bool
190738fd1498Szrj __detail::__regex_algo_impl(_Bp, _Bp, match_results<_Bp, _Ap>&,
190838fd1498Szrj const basic_regex<_Cp, _Rp>&,
190938fd1498Szrj regex_constants::match_flag_type);
191038fd1498Szrj
191138fd1498Szrj void
191238fd1498Szrj _M_resize(unsigned int __size)
191338fd1498Szrj { _Base_type::resize(__size + 3); }
191438fd1498Szrj
191538fd1498Szrj const_reference
191638fd1498Szrj _M_unmatched_sub() const
191738fd1498Szrj { return _Base_type::operator[](_Base_type::size() - 3); }
191838fd1498Szrj
191938fd1498Szrj sub_match<_Bi_iter>&
192038fd1498Szrj _M_unmatched_sub()
192138fd1498Szrj { return _Base_type::operator[](_Base_type::size() - 3); }
192238fd1498Szrj
192338fd1498Szrj const_reference
192438fd1498Szrj _M_prefix() const
192538fd1498Szrj { return _Base_type::operator[](_Base_type::size() - 2); }
192638fd1498Szrj
192738fd1498Szrj sub_match<_Bi_iter>&
192838fd1498Szrj _M_prefix()
192938fd1498Szrj { return _Base_type::operator[](_Base_type::size() - 2); }
193038fd1498Szrj
193138fd1498Szrj const_reference
193238fd1498Szrj _M_suffix() const
193338fd1498Szrj { return _Base_type::operator[](_Base_type::size() - 1); }
193438fd1498Szrj
193538fd1498Szrj sub_match<_Bi_iter>&
193638fd1498Szrj _M_suffix()
193738fd1498Szrj { return _Base_type::operator[](_Base_type::size() - 1); }
193838fd1498Szrj
193938fd1498Szrj _Bi_iter _M_begin;
194038fd1498Szrj };
194138fd1498Szrj
194238fd1498Szrj typedef match_results<const char*> cmatch;
194338fd1498Szrj typedef match_results<string::const_iterator> smatch;
194438fd1498Szrj #ifdef _GLIBCXX_USE_WCHAR_T
194538fd1498Szrj typedef match_results<const wchar_t*> wcmatch;
194638fd1498Szrj typedef match_results<wstring::const_iterator> wsmatch;
194738fd1498Szrj #endif
194838fd1498Szrj
194938fd1498Szrj // match_results comparisons
195038fd1498Szrj /**
195138fd1498Szrj * @brief Compares two match_results for equality.
195238fd1498Szrj * @returns true if the two objects refer to the same match,
195338fd1498Szrj * false otherwise.
195438fd1498Szrj */
195538fd1498Szrj template<typename _Bi_iter, typename _Alloc>
195638fd1498Szrj inline bool
195738fd1498Szrj operator==(const match_results<_Bi_iter, _Alloc>& __m1,
195838fd1498Szrj const match_results<_Bi_iter, _Alloc>& __m2)
195938fd1498Szrj {
196038fd1498Szrj if (__m1.ready() != __m2.ready())
196138fd1498Szrj return false;
196238fd1498Szrj if (!__m1.ready()) // both are not ready
196338fd1498Szrj return true;
196438fd1498Szrj if (__m1.empty() != __m2.empty())
196538fd1498Szrj return false;
196638fd1498Szrj if (__m1.empty()) // both are empty
196738fd1498Szrj return true;
196838fd1498Szrj return __m1.prefix() == __m2.prefix()
196938fd1498Szrj && __m1.size() == __m2.size()
197038fd1498Szrj && std::equal(__m1.begin(), __m1.end(), __m2.begin())
197138fd1498Szrj && __m1.suffix() == __m2.suffix();
197238fd1498Szrj }
197338fd1498Szrj
197438fd1498Szrj /**
197538fd1498Szrj * @brief Compares two match_results for inequality.
197638fd1498Szrj * @returns true if the two objects do not refer to the same match,
197738fd1498Szrj * false otherwise.
197838fd1498Szrj */
197938fd1498Szrj template<typename _Bi_iter, class _Alloc>
198038fd1498Szrj inline bool
198138fd1498Szrj operator!=(const match_results<_Bi_iter, _Alloc>& __m1,
198238fd1498Szrj const match_results<_Bi_iter, _Alloc>& __m2)
198338fd1498Szrj { return !(__m1 == __m2); }
198438fd1498Szrj
198538fd1498Szrj // [7.10.6] match_results swap
198638fd1498Szrj /**
198738fd1498Szrj * @brief Swaps two match results.
198838fd1498Szrj * @param __lhs A match result.
198938fd1498Szrj * @param __rhs A match result.
199038fd1498Szrj *
199138fd1498Szrj * The contents of the two match_results objects are swapped.
199238fd1498Szrj */
199338fd1498Szrj template<typename _Bi_iter, typename _Alloc>
199438fd1498Szrj inline void
199538fd1498Szrj swap(match_results<_Bi_iter, _Alloc>& __lhs,
199638fd1498Szrj match_results<_Bi_iter, _Alloc>& __rhs)
199738fd1498Szrj { __lhs.swap(__rhs); }
199838fd1498Szrj
199938fd1498Szrj _GLIBCXX_END_NAMESPACE_CXX11
200038fd1498Szrj
200138fd1498Szrj // [7.11.2] Function template regex_match
200238fd1498Szrj /**
200338fd1498Szrj * @name Matching, Searching, and Replacing
200438fd1498Szrj */
200538fd1498Szrj //@{
200638fd1498Szrj
200738fd1498Szrj /**
200838fd1498Szrj * @brief Determines if there is a match between the regular expression @p e
200938fd1498Szrj * and all of the character sequence [first, last).
201038fd1498Szrj *
201138fd1498Szrj * @param __s Start of the character sequence to match.
201238fd1498Szrj * @param __e One-past-the-end of the character sequence to match.
201338fd1498Szrj * @param __m The match results.
201438fd1498Szrj * @param __re The regular expression.
201538fd1498Szrj * @param __flags Controls how the regular expression is matched.
201638fd1498Szrj *
201738fd1498Szrj * @retval true A match exists.
201838fd1498Szrj * @retval false Otherwise.
201938fd1498Szrj *
202038fd1498Szrj * @throws an exception of type regex_error.
202138fd1498Szrj */
202238fd1498Szrj template<typename _Bi_iter, typename _Alloc,
202338fd1498Szrj typename _Ch_type, typename _Rx_traits>
202438fd1498Szrj inline bool
202538fd1498Szrj regex_match(_Bi_iter __s,
202638fd1498Szrj _Bi_iter __e,
202738fd1498Szrj match_results<_Bi_iter, _Alloc>& __m,
202838fd1498Szrj const basic_regex<_Ch_type, _Rx_traits>& __re,
202938fd1498Szrj regex_constants::match_flag_type __flags
203038fd1498Szrj = regex_constants::match_default)
203138fd1498Szrj {
203238fd1498Szrj return __detail::__regex_algo_impl<_Bi_iter, _Alloc, _Ch_type, _Rx_traits,
203338fd1498Szrj __detail::_RegexExecutorPolicy::_S_auto, true>
203438fd1498Szrj (__s, __e, __m, __re, __flags);
203538fd1498Szrj }
203638fd1498Szrj
203738fd1498Szrj /**
203838fd1498Szrj * @brief Indicates if there is a match between the regular expression @p e
203938fd1498Szrj * and all of the character sequence [first, last).
204038fd1498Szrj *
204138fd1498Szrj * @param __first Beginning of the character sequence to match.
204238fd1498Szrj * @param __last One-past-the-end of the character sequence to match.
204338fd1498Szrj * @param __re The regular expression.
204438fd1498Szrj * @param __flags Controls how the regular expression is matched.
204538fd1498Szrj *
204638fd1498Szrj * @retval true A match exists.
204738fd1498Szrj * @retval false Otherwise.
204838fd1498Szrj *
204938fd1498Szrj * @throws an exception of type regex_error.
205038fd1498Szrj */
205138fd1498Szrj template<typename _Bi_iter, typename _Ch_type, typename _Rx_traits>
205238fd1498Szrj inline bool
205338fd1498Szrj regex_match(_Bi_iter __first, _Bi_iter __last,
205438fd1498Szrj const basic_regex<_Ch_type, _Rx_traits>& __re,
205538fd1498Szrj regex_constants::match_flag_type __flags
205638fd1498Szrj = regex_constants::match_default)
205738fd1498Szrj {
205838fd1498Szrj match_results<_Bi_iter> __what;
205938fd1498Szrj return regex_match(__first, __last, __what, __re, __flags);
206038fd1498Szrj }
206138fd1498Szrj
206238fd1498Szrj /**
206338fd1498Szrj * @brief Determines if there is a match between the regular expression @p e
206438fd1498Szrj * and a C-style null-terminated string.
206538fd1498Szrj *
206638fd1498Szrj * @param __s The C-style null-terminated string to match.
206738fd1498Szrj * @param __m The match results.
206838fd1498Szrj * @param __re The regular expression.
206938fd1498Szrj * @param __f Controls how the regular expression is matched.
207038fd1498Szrj *
207138fd1498Szrj * @retval true A match exists.
207238fd1498Szrj * @retval false Otherwise.
207338fd1498Szrj *
207438fd1498Szrj * @throws an exception of type regex_error.
207538fd1498Szrj */
207638fd1498Szrj template<typename _Ch_type, typename _Alloc, typename _Rx_traits>
207738fd1498Szrj inline bool
207838fd1498Szrj regex_match(const _Ch_type* __s,
207938fd1498Szrj match_results<const _Ch_type*, _Alloc>& __m,
208038fd1498Szrj const basic_regex<_Ch_type, _Rx_traits>& __re,
208138fd1498Szrj regex_constants::match_flag_type __f
208238fd1498Szrj = regex_constants::match_default)
208338fd1498Szrj { return regex_match(__s, __s + _Rx_traits::length(__s), __m, __re, __f); }
208438fd1498Szrj
208538fd1498Szrj /**
208638fd1498Szrj * @brief Determines if there is a match between the regular expression @p e
208738fd1498Szrj * and a string.
208838fd1498Szrj *
208938fd1498Szrj * @param __s The string to match.
209038fd1498Szrj * @param __m The match results.
209138fd1498Szrj * @param __re The regular expression.
209238fd1498Szrj * @param __flags Controls how the regular expression is matched.
209338fd1498Szrj *
209438fd1498Szrj * @retval true A match exists.
209538fd1498Szrj * @retval false Otherwise.
209638fd1498Szrj *
209738fd1498Szrj * @throws an exception of type regex_error.
209838fd1498Szrj */
209938fd1498Szrj template<typename _Ch_traits, typename _Ch_alloc,
210038fd1498Szrj typename _Alloc, typename _Ch_type, typename _Rx_traits>
210138fd1498Szrj inline bool
210238fd1498Szrj regex_match(const basic_string<_Ch_type, _Ch_traits, _Ch_alloc>& __s,
210338fd1498Szrj match_results<typename basic_string<_Ch_type,
210438fd1498Szrj _Ch_traits, _Ch_alloc>::const_iterator, _Alloc>& __m,
210538fd1498Szrj const basic_regex<_Ch_type, _Rx_traits>& __re,
210638fd1498Szrj regex_constants::match_flag_type __flags
210738fd1498Szrj = regex_constants::match_default)
210838fd1498Szrj { return regex_match(__s.begin(), __s.end(), __m, __re, __flags); }
210938fd1498Szrj
211038fd1498Szrj // _GLIBCXX_RESOLVE_LIB_DEFECTS
211138fd1498Szrj // 2329. regex_match() with match_results should forbid temporary strings
211238fd1498Szrj /// Prevent unsafe attempts to get match_results from a temporary string.
211338fd1498Szrj template<typename _Ch_traits, typename _Ch_alloc,
211438fd1498Szrj typename _Alloc, typename _Ch_type, typename _Rx_traits>
211538fd1498Szrj bool
211638fd1498Szrj regex_match(const basic_string<_Ch_type, _Ch_traits, _Ch_alloc>&&,
211738fd1498Szrj match_results<typename basic_string<_Ch_type,
211838fd1498Szrj _Ch_traits, _Ch_alloc>::const_iterator, _Alloc>&,
211938fd1498Szrj const basic_regex<_Ch_type, _Rx_traits>&,
212038fd1498Szrj regex_constants::match_flag_type
212138fd1498Szrj = regex_constants::match_default) = delete;
212238fd1498Szrj
212338fd1498Szrj /**
212438fd1498Szrj * @brief Indicates if there is a match between the regular expression @p e
212538fd1498Szrj * and a C-style null-terminated string.
212638fd1498Szrj *
212738fd1498Szrj * @param __s The C-style null-terminated string to match.
212838fd1498Szrj * @param __re The regular expression.
212938fd1498Szrj * @param __f Controls how the regular expression is matched.
213038fd1498Szrj *
213138fd1498Szrj * @retval true A match exists.
213238fd1498Szrj * @retval false Otherwise.
213338fd1498Szrj *
213438fd1498Szrj * @throws an exception of type regex_error.
213538fd1498Szrj */
213638fd1498Szrj template<typename _Ch_type, class _Rx_traits>
213738fd1498Szrj inline bool
213838fd1498Szrj regex_match(const _Ch_type* __s,
213938fd1498Szrj const basic_regex<_Ch_type, _Rx_traits>& __re,
214038fd1498Szrj regex_constants::match_flag_type __f
214138fd1498Szrj = regex_constants::match_default)
214238fd1498Szrj { return regex_match(__s, __s + _Rx_traits::length(__s), __re, __f); }
214338fd1498Szrj
214438fd1498Szrj /**
214538fd1498Szrj * @brief Indicates if there is a match between the regular expression @p e
214638fd1498Szrj * and a string.
214738fd1498Szrj *
214838fd1498Szrj * @param __s [IN] The string to match.
214938fd1498Szrj * @param __re [IN] The regular expression.
215038fd1498Szrj * @param __flags [IN] Controls how the regular expression is matched.
215138fd1498Szrj *
215238fd1498Szrj * @retval true A match exists.
215338fd1498Szrj * @retval false Otherwise.
215438fd1498Szrj *
215538fd1498Szrj * @throws an exception of type regex_error.
215638fd1498Szrj */
215738fd1498Szrj template<typename _Ch_traits, typename _Str_allocator,
215838fd1498Szrj typename _Ch_type, typename _Rx_traits>
215938fd1498Szrj inline bool
216038fd1498Szrj regex_match(const basic_string<_Ch_type, _Ch_traits, _Str_allocator>& __s,
216138fd1498Szrj const basic_regex<_Ch_type, _Rx_traits>& __re,
216238fd1498Szrj regex_constants::match_flag_type __flags
216338fd1498Szrj = regex_constants::match_default)
216438fd1498Szrj { return regex_match(__s.begin(), __s.end(), __re, __flags); }
216538fd1498Szrj
216638fd1498Szrj // [7.11.3] Function template regex_search
216738fd1498Szrj /**
216838fd1498Szrj * Searches for a regular expression within a range.
216938fd1498Szrj * @param __s [IN] The start of the string to search.
217038fd1498Szrj * @param __e [IN] One-past-the-end of the string to search.
217138fd1498Szrj * @param __m [OUT] The match results.
217238fd1498Szrj * @param __re [IN] The regular expression to search for.
217338fd1498Szrj * @param __flags [IN] Search policy flags.
217438fd1498Szrj * @retval true A match was found within the string.
217538fd1498Szrj * @retval false No match was found within the string, the content of %m is
217638fd1498Szrj * undefined.
217738fd1498Szrj *
217838fd1498Szrj * @throws an exception of type regex_error.
217938fd1498Szrj */
218038fd1498Szrj template<typename _Bi_iter, typename _Alloc,
218138fd1498Szrj typename _Ch_type, typename _Rx_traits>
218238fd1498Szrj inline bool
218338fd1498Szrj regex_search(_Bi_iter __s, _Bi_iter __e,
218438fd1498Szrj match_results<_Bi_iter, _Alloc>& __m,
218538fd1498Szrj const basic_regex<_Ch_type, _Rx_traits>& __re,
218638fd1498Szrj regex_constants::match_flag_type __flags
218738fd1498Szrj = regex_constants::match_default)
218838fd1498Szrj {
218938fd1498Szrj return __detail::__regex_algo_impl<_Bi_iter, _Alloc, _Ch_type, _Rx_traits,
219038fd1498Szrj __detail::_RegexExecutorPolicy::_S_auto, false>
219138fd1498Szrj (__s, __e, __m, __re, __flags);
219238fd1498Szrj }
219338fd1498Szrj
219438fd1498Szrj /**
219538fd1498Szrj * Searches for a regular expression within a range.
219638fd1498Szrj * @param __first [IN] The start of the string to search.
219738fd1498Szrj * @param __last [IN] One-past-the-end of the string to search.
219838fd1498Szrj * @param __re [IN] The regular expression to search for.
219938fd1498Szrj * @param __flags [IN] Search policy flags.
220038fd1498Szrj * @retval true A match was found within the string.
220138fd1498Szrj * @retval false No match was found within the string.
220238fd1498Szrj *
220338fd1498Szrj * @throws an exception of type regex_error.
220438fd1498Szrj */
220538fd1498Szrj template<typename _Bi_iter, typename _Ch_type, typename _Rx_traits>
220638fd1498Szrj inline bool
220738fd1498Szrj regex_search(_Bi_iter __first, _Bi_iter __last,
220838fd1498Szrj const basic_regex<_Ch_type, _Rx_traits>& __re,
220938fd1498Szrj regex_constants::match_flag_type __flags
221038fd1498Szrj = regex_constants::match_default)
221138fd1498Szrj {
221238fd1498Szrj match_results<_Bi_iter> __what;
221338fd1498Szrj return regex_search(__first, __last, __what, __re, __flags);
221438fd1498Szrj }
221538fd1498Szrj
221638fd1498Szrj /**
221738fd1498Szrj * @brief Searches for a regular expression within a C-string.
221838fd1498Szrj * @param __s [IN] A C-string to search for the regex.
221938fd1498Szrj * @param __m [OUT] The set of regex matches.
222038fd1498Szrj * @param __e [IN] The regex to search for in @p s.
222138fd1498Szrj * @param __f [IN] The search flags.
222238fd1498Szrj * @retval true A match was found within the string.
222338fd1498Szrj * @retval false No match was found within the string, the content of %m is
222438fd1498Szrj * undefined.
222538fd1498Szrj *
222638fd1498Szrj * @throws an exception of type regex_error.
222738fd1498Szrj */
222838fd1498Szrj template<typename _Ch_type, class _Alloc, class _Rx_traits>
222938fd1498Szrj inline bool
223038fd1498Szrj regex_search(const _Ch_type* __s,
223138fd1498Szrj match_results<const _Ch_type*, _Alloc>& __m,
223238fd1498Szrj const basic_regex<_Ch_type, _Rx_traits>& __e,
223338fd1498Szrj regex_constants::match_flag_type __f
223438fd1498Szrj = regex_constants::match_default)
223538fd1498Szrj { return regex_search(__s, __s + _Rx_traits::length(__s), __m, __e, __f); }
223638fd1498Szrj
223738fd1498Szrj /**
223838fd1498Szrj * @brief Searches for a regular expression within a C-string.
223938fd1498Szrj * @param __s [IN] The C-string to search.
224038fd1498Szrj * @param __e [IN] The regular expression to search for.
224138fd1498Szrj * @param __f [IN] Search policy flags.
224238fd1498Szrj * @retval true A match was found within the string.
224338fd1498Szrj * @retval false No match was found within the string.
224438fd1498Szrj *
224538fd1498Szrj * @throws an exception of type regex_error.
224638fd1498Szrj */
224738fd1498Szrj template<typename _Ch_type, typename _Rx_traits>
224838fd1498Szrj inline bool
224938fd1498Szrj regex_search(const _Ch_type* __s,
225038fd1498Szrj const basic_regex<_Ch_type, _Rx_traits>& __e,
225138fd1498Szrj regex_constants::match_flag_type __f
225238fd1498Szrj = regex_constants::match_default)
225338fd1498Szrj { return regex_search(__s, __s + _Rx_traits::length(__s), __e, __f); }
225438fd1498Szrj
225538fd1498Szrj /**
225638fd1498Szrj * @brief Searches for a regular expression within a string.
225738fd1498Szrj * @param __s [IN] The string to search.
225838fd1498Szrj * @param __e [IN] The regular expression to search for.
225938fd1498Szrj * @param __flags [IN] Search policy flags.
226038fd1498Szrj * @retval true A match was found within the string.
226138fd1498Szrj * @retval false No match was found within the string.
226238fd1498Szrj *
226338fd1498Szrj * @throws an exception of type regex_error.
226438fd1498Szrj */
226538fd1498Szrj template<typename _Ch_traits, typename _String_allocator,
226638fd1498Szrj typename _Ch_type, typename _Rx_traits>
226738fd1498Szrj inline bool
226838fd1498Szrj regex_search(const basic_string<_Ch_type, _Ch_traits,
226938fd1498Szrj _String_allocator>& __s,
227038fd1498Szrj const basic_regex<_Ch_type, _Rx_traits>& __e,
227138fd1498Szrj regex_constants::match_flag_type __flags
227238fd1498Szrj = regex_constants::match_default)
227338fd1498Szrj { return regex_search(__s.begin(), __s.end(), __e, __flags); }
227438fd1498Szrj
227538fd1498Szrj /**
227638fd1498Szrj * @brief Searches for a regular expression within a string.
227738fd1498Szrj * @param __s [IN] A C++ string to search for the regex.
227838fd1498Szrj * @param __m [OUT] The set of regex matches.
227938fd1498Szrj * @param __e [IN] The regex to search for in @p s.
228038fd1498Szrj * @param __f [IN] The search flags.
228138fd1498Szrj * @retval true A match was found within the string.
228238fd1498Szrj * @retval false No match was found within the string, the content of %m is
228338fd1498Szrj * undefined.
228438fd1498Szrj *
228538fd1498Szrj * @throws an exception of type regex_error.
228638fd1498Szrj */
228738fd1498Szrj template<typename _Ch_traits, typename _Ch_alloc,
228838fd1498Szrj typename _Alloc, typename _Ch_type,
228938fd1498Szrj typename _Rx_traits>
229038fd1498Szrj inline bool
229138fd1498Szrj regex_search(const basic_string<_Ch_type, _Ch_traits, _Ch_alloc>& __s,
229238fd1498Szrj match_results<typename basic_string<_Ch_type,
229338fd1498Szrj _Ch_traits, _Ch_alloc>::const_iterator, _Alloc>& __m,
229438fd1498Szrj const basic_regex<_Ch_type, _Rx_traits>& __e,
229538fd1498Szrj regex_constants::match_flag_type __f
229638fd1498Szrj = regex_constants::match_default)
229738fd1498Szrj { return regex_search(__s.begin(), __s.end(), __m, __e, __f); }
229838fd1498Szrj
229938fd1498Szrj // _GLIBCXX_RESOLVE_LIB_DEFECTS
230038fd1498Szrj // 2329. regex_search() with match_results should forbid temporary strings
230138fd1498Szrj /// Prevent unsafe attempts to get match_results from a temporary string.
230238fd1498Szrj template<typename _Ch_traits, typename _Ch_alloc,
230338fd1498Szrj typename _Alloc, typename _Ch_type,
230438fd1498Szrj typename _Rx_traits>
230538fd1498Szrj bool
230638fd1498Szrj regex_search(const basic_string<_Ch_type, _Ch_traits, _Ch_alloc>&&,
230738fd1498Szrj match_results<typename basic_string<_Ch_type,
230838fd1498Szrj _Ch_traits, _Ch_alloc>::const_iterator, _Alloc>&,
230938fd1498Szrj const basic_regex<_Ch_type, _Rx_traits>&,
231038fd1498Szrj regex_constants::match_flag_type
231138fd1498Szrj = regex_constants::match_default) = delete;
231238fd1498Szrj
231338fd1498Szrj // std [28.11.4] Function template regex_replace
231438fd1498Szrj /**
231538fd1498Szrj * @brief Search for a regular expression within a range for multiple times,
231638fd1498Szrj and replace the matched parts through filling a format string.
231738fd1498Szrj * @param __out [OUT] The output iterator.
231838fd1498Szrj * @param __first [IN] The start of the string to search.
231938fd1498Szrj * @param __last [IN] One-past-the-end of the string to search.
232038fd1498Szrj * @param __e [IN] The regular expression to search for.
232138fd1498Szrj * @param __fmt [IN] The format string.
232238fd1498Szrj * @param __flags [IN] Search and replace policy flags.
232338fd1498Szrj *
232438fd1498Szrj * @returns __out
232538fd1498Szrj * @throws an exception of type regex_error.
232638fd1498Szrj */
232738fd1498Szrj template<typename _Out_iter, typename _Bi_iter,
232838fd1498Szrj typename _Rx_traits, typename _Ch_type,
232938fd1498Szrj typename _St, typename _Sa>
233038fd1498Szrj inline _Out_iter
233138fd1498Szrj regex_replace(_Out_iter __out, _Bi_iter __first, _Bi_iter __last,
233238fd1498Szrj const basic_regex<_Ch_type, _Rx_traits>& __e,
233338fd1498Szrj const basic_string<_Ch_type, _St, _Sa>& __fmt,
233438fd1498Szrj regex_constants::match_flag_type __flags
233538fd1498Szrj = regex_constants::match_default)
233638fd1498Szrj {
233738fd1498Szrj return regex_replace(__out, __first, __last, __e, __fmt.c_str(), __flags);
233838fd1498Szrj }
233938fd1498Szrj
234038fd1498Szrj /**
234138fd1498Szrj * @brief Search for a regular expression within a range for multiple times,
234238fd1498Szrj and replace the matched parts through filling a format C-string.
234338fd1498Szrj * @param __out [OUT] The output iterator.
234438fd1498Szrj * @param __first [IN] The start of the string to search.
234538fd1498Szrj * @param __last [IN] One-past-the-end of the string to search.
234638fd1498Szrj * @param __e [IN] The regular expression to search for.
234738fd1498Szrj * @param __fmt [IN] The format C-string.
234838fd1498Szrj * @param __flags [IN] Search and replace policy flags.
234938fd1498Szrj *
235038fd1498Szrj * @returns __out
235138fd1498Szrj * @throws an exception of type regex_error.
235238fd1498Szrj */
235338fd1498Szrj template<typename _Out_iter, typename _Bi_iter,
235438fd1498Szrj typename _Rx_traits, typename _Ch_type>
235538fd1498Szrj _Out_iter
235638fd1498Szrj regex_replace(_Out_iter __out, _Bi_iter __first, _Bi_iter __last,
235738fd1498Szrj const basic_regex<_Ch_type, _Rx_traits>& __e,
235838fd1498Szrj const _Ch_type* __fmt,
235938fd1498Szrj regex_constants::match_flag_type __flags
236038fd1498Szrj = regex_constants::match_default);
236138fd1498Szrj
236238fd1498Szrj /**
236338fd1498Szrj * @brief Search for a regular expression within a string for multiple times,
236438fd1498Szrj and replace the matched parts through filling a format string.
236538fd1498Szrj * @param __s [IN] The string to search and replace.
236638fd1498Szrj * @param __e [IN] The regular expression to search for.
236738fd1498Szrj * @param __fmt [IN] The format string.
236838fd1498Szrj * @param __flags [IN] Search and replace policy flags.
236938fd1498Szrj *
237038fd1498Szrj * @returns The string after replacing.
237138fd1498Szrj * @throws an exception of type regex_error.
237238fd1498Szrj */
237338fd1498Szrj template<typename _Rx_traits, typename _Ch_type,
237438fd1498Szrj typename _St, typename _Sa, typename _Fst, typename _Fsa>
237538fd1498Szrj inline basic_string<_Ch_type, _St, _Sa>
237638fd1498Szrj regex_replace(const basic_string<_Ch_type, _St, _Sa>& __s,
237738fd1498Szrj const basic_regex<_Ch_type, _Rx_traits>& __e,
237838fd1498Szrj const basic_string<_Ch_type, _Fst, _Fsa>& __fmt,
237938fd1498Szrj regex_constants::match_flag_type __flags
238038fd1498Szrj = regex_constants::match_default)
238138fd1498Szrj {
238238fd1498Szrj basic_string<_Ch_type, _St, _Sa> __result;
238338fd1498Szrj regex_replace(std::back_inserter(__result),
238438fd1498Szrj __s.begin(), __s.end(), __e, __fmt, __flags);
238538fd1498Szrj return __result;
238638fd1498Szrj }
238738fd1498Szrj
238838fd1498Szrj /**
238938fd1498Szrj * @brief Search for a regular expression within a string for multiple times,
239038fd1498Szrj and replace the matched parts through filling a format C-string.
239138fd1498Szrj * @param __s [IN] The string to search and replace.
239238fd1498Szrj * @param __e [IN] The regular expression to search for.
239338fd1498Szrj * @param __fmt [IN] The format C-string.
239438fd1498Szrj * @param __flags [IN] Search and replace policy flags.
239538fd1498Szrj *
239638fd1498Szrj * @returns The string after replacing.
239738fd1498Szrj * @throws an exception of type regex_error.
239838fd1498Szrj */
239938fd1498Szrj template<typename _Rx_traits, typename _Ch_type,
240038fd1498Szrj typename _St, typename _Sa>
240138fd1498Szrj inline basic_string<_Ch_type, _St, _Sa>
240238fd1498Szrj regex_replace(const basic_string<_Ch_type, _St, _Sa>& __s,
240338fd1498Szrj const basic_regex<_Ch_type, _Rx_traits>& __e,
240438fd1498Szrj const _Ch_type* __fmt,
240538fd1498Szrj regex_constants::match_flag_type __flags
240638fd1498Szrj = regex_constants::match_default)
240738fd1498Szrj {
240838fd1498Szrj basic_string<_Ch_type, _St, _Sa> __result;
240938fd1498Szrj regex_replace(std::back_inserter(__result),
241038fd1498Szrj __s.begin(), __s.end(), __e, __fmt, __flags);
241138fd1498Szrj return __result;
241238fd1498Szrj }
241338fd1498Szrj
241438fd1498Szrj /**
241538fd1498Szrj * @brief Search for a regular expression within a C-string for multiple
241638fd1498Szrj times, and replace the matched parts through filling a format string.
241738fd1498Szrj * @param __s [IN] The C-string to search and replace.
241838fd1498Szrj * @param __e [IN] The regular expression to search for.
241938fd1498Szrj * @param __fmt [IN] The format string.
242038fd1498Szrj * @param __flags [IN] Search and replace policy flags.
242138fd1498Szrj *
242238fd1498Szrj * @returns The string after replacing.
242338fd1498Szrj * @throws an exception of type regex_error.
242438fd1498Szrj */
242538fd1498Szrj template<typename _Rx_traits, typename _Ch_type,
242638fd1498Szrj typename _St, typename _Sa>
242738fd1498Szrj inline basic_string<_Ch_type>
242838fd1498Szrj regex_replace(const _Ch_type* __s,
242938fd1498Szrj const basic_regex<_Ch_type, _Rx_traits>& __e,
243038fd1498Szrj const basic_string<_Ch_type, _St, _Sa>& __fmt,
243138fd1498Szrj regex_constants::match_flag_type __flags
243238fd1498Szrj = regex_constants::match_default)
243338fd1498Szrj {
243438fd1498Szrj basic_string<_Ch_type> __result;
243538fd1498Szrj regex_replace(std::back_inserter(__result), __s,
243638fd1498Szrj __s + char_traits<_Ch_type>::length(__s),
243738fd1498Szrj __e, __fmt, __flags);
243838fd1498Szrj return __result;
243938fd1498Szrj }
244038fd1498Szrj
244138fd1498Szrj /**
244238fd1498Szrj * @brief Search for a regular expression within a C-string for multiple
244338fd1498Szrj times, and replace the matched parts through filling a format C-string.
244438fd1498Szrj * @param __s [IN] The C-string to search and replace.
244538fd1498Szrj * @param __e [IN] The regular expression to search for.
244638fd1498Szrj * @param __fmt [IN] The format C-string.
244738fd1498Szrj * @param __flags [IN] Search and replace policy flags.
244838fd1498Szrj *
244938fd1498Szrj * @returns The string after replacing.
245038fd1498Szrj * @throws an exception of type regex_error.
245138fd1498Szrj */
245238fd1498Szrj template<typename _Rx_traits, typename _Ch_type>
245338fd1498Szrj inline basic_string<_Ch_type>
245438fd1498Szrj regex_replace(const _Ch_type* __s,
245538fd1498Szrj const basic_regex<_Ch_type, _Rx_traits>& __e,
245638fd1498Szrj const _Ch_type* __fmt,
245738fd1498Szrj regex_constants::match_flag_type __flags
245838fd1498Szrj = regex_constants::match_default)
245938fd1498Szrj {
246038fd1498Szrj basic_string<_Ch_type> __result;
246138fd1498Szrj regex_replace(std::back_inserter(__result), __s,
246238fd1498Szrj __s + char_traits<_Ch_type>::length(__s),
246338fd1498Szrj __e, __fmt, __flags);
246438fd1498Szrj return __result;
246538fd1498Szrj }
246638fd1498Szrj
246738fd1498Szrj //@}
246838fd1498Szrj
246938fd1498Szrj _GLIBCXX_BEGIN_NAMESPACE_CXX11
247038fd1498Szrj
247138fd1498Szrj // std [28.12] Class template regex_iterator
247238fd1498Szrj /**
247338fd1498Szrj * An iterator adaptor that will provide repeated calls of regex_search over
247438fd1498Szrj * a range until no more matches remain.
247538fd1498Szrj */
247638fd1498Szrj template<typename _Bi_iter,
247738fd1498Szrj typename _Ch_type = typename iterator_traits<_Bi_iter>::value_type,
247838fd1498Szrj typename _Rx_traits = regex_traits<_Ch_type> >
247938fd1498Szrj class regex_iterator
248038fd1498Szrj {
248138fd1498Szrj public:
248238fd1498Szrj typedef basic_regex<_Ch_type, _Rx_traits> regex_type;
248338fd1498Szrj typedef match_results<_Bi_iter> value_type;
248438fd1498Szrj typedef std::ptrdiff_t difference_type;
248538fd1498Szrj typedef const value_type* pointer;
248638fd1498Szrj typedef const value_type& reference;
248738fd1498Szrj typedef std::forward_iterator_tag iterator_category;
248838fd1498Szrj
248938fd1498Szrj /**
249038fd1498Szrj * @brief Provides a singular iterator, useful for indicating
249138fd1498Szrj * one-past-the-end of a range.
249238fd1498Szrj */
249338fd1498Szrj regex_iterator()
249438fd1498Szrj : _M_pregex()
249538fd1498Szrj { }
249638fd1498Szrj
249738fd1498Szrj /**
249838fd1498Szrj * Constructs a %regex_iterator...
249938fd1498Szrj * @param __a [IN] The start of a text range to search.
250038fd1498Szrj * @param __b [IN] One-past-the-end of the text range to search.
250138fd1498Szrj * @param __re [IN] The regular expression to match.
250238fd1498Szrj * @param __m [IN] Policy flags for match rules.
250338fd1498Szrj */
250438fd1498Szrj regex_iterator(_Bi_iter __a, _Bi_iter __b, const regex_type& __re,
250538fd1498Szrj regex_constants::match_flag_type __m
250638fd1498Szrj = regex_constants::match_default)
250738fd1498Szrj : _M_begin(__a), _M_end(__b), _M_pregex(&__re), _M_flags(__m), _M_match()
250838fd1498Szrj {
250938fd1498Szrj if (!regex_search(_M_begin, _M_end, _M_match, *_M_pregex, _M_flags))
251038fd1498Szrj *this = regex_iterator();
251138fd1498Szrj }
251238fd1498Szrj
251338fd1498Szrj // _GLIBCXX_RESOLVE_LIB_DEFECTS
251438fd1498Szrj // 2332. regex_iterator should forbid temporary regexes
251538fd1498Szrj regex_iterator(_Bi_iter, _Bi_iter, const regex_type&&,
251638fd1498Szrj regex_constants::match_flag_type
251738fd1498Szrj = regex_constants::match_default) = delete;
251838fd1498Szrj /**
251938fd1498Szrj * Copy constructs a %regex_iterator.
252038fd1498Szrj */
252138fd1498Szrj regex_iterator(const regex_iterator& __rhs) = default;
252238fd1498Szrj
252338fd1498Szrj /**
252438fd1498Szrj * @brief Assigns one %regex_iterator to another.
252538fd1498Szrj */
252638fd1498Szrj regex_iterator&
252738fd1498Szrj operator=(const regex_iterator& __rhs) = default;
252838fd1498Szrj
252938fd1498Szrj /**
253038fd1498Szrj * @brief Tests the equivalence of two regex iterators.
253138fd1498Szrj */
253238fd1498Szrj bool
253338fd1498Szrj operator==(const regex_iterator& __rhs) const;
253438fd1498Szrj
253538fd1498Szrj /**
253638fd1498Szrj * @brief Tests the inequivalence of two regex iterators.
253738fd1498Szrj */
253838fd1498Szrj bool
253938fd1498Szrj operator!=(const regex_iterator& __rhs) const
254038fd1498Szrj { return !(*this == __rhs); }
254138fd1498Szrj
254238fd1498Szrj /**
254338fd1498Szrj * @brief Dereferences a %regex_iterator.
254438fd1498Szrj */
254538fd1498Szrj const value_type&
254638fd1498Szrj operator*() const
254738fd1498Szrj { return _M_match; }
254838fd1498Szrj
254938fd1498Szrj /**
255038fd1498Szrj * @brief Selects a %regex_iterator member.
255138fd1498Szrj */
255238fd1498Szrj const value_type*
255338fd1498Szrj operator->() const
255438fd1498Szrj { return &_M_match; }
255538fd1498Szrj
255638fd1498Szrj /**
255738fd1498Szrj * @brief Increments a %regex_iterator.
255838fd1498Szrj */
255938fd1498Szrj regex_iterator&
256038fd1498Szrj operator++();
256138fd1498Szrj
256238fd1498Szrj /**
256338fd1498Szrj * @brief Postincrements a %regex_iterator.
256438fd1498Szrj */
256538fd1498Szrj regex_iterator
256638fd1498Szrj operator++(int)
256738fd1498Szrj {
256838fd1498Szrj auto __tmp = *this;
256938fd1498Szrj ++(*this);
257038fd1498Szrj return __tmp;
257138fd1498Szrj }
257238fd1498Szrj
257338fd1498Szrj private:
257438fd1498Szrj _Bi_iter _M_begin;
257538fd1498Szrj _Bi_iter _M_end;
257638fd1498Szrj const regex_type* _M_pregex;
257738fd1498Szrj regex_constants::match_flag_type _M_flags;
257838fd1498Szrj match_results<_Bi_iter> _M_match;
257938fd1498Szrj };
258038fd1498Szrj
258138fd1498Szrj typedef regex_iterator<const char*> cregex_iterator;
258238fd1498Szrj typedef regex_iterator<string::const_iterator> sregex_iterator;
258338fd1498Szrj #ifdef _GLIBCXX_USE_WCHAR_T
258438fd1498Szrj typedef regex_iterator<const wchar_t*> wcregex_iterator;
258538fd1498Szrj typedef regex_iterator<wstring::const_iterator> wsregex_iterator;
258638fd1498Szrj #endif
258738fd1498Szrj
258838fd1498Szrj // [7.12.2] Class template regex_token_iterator
258938fd1498Szrj /**
259038fd1498Szrj * Iterates over submatches in a range (or @a splits a text string).
259138fd1498Szrj *
259238fd1498Szrj * The purpose of this iterator is to enumerate all, or all specified,
259338fd1498Szrj * matches of a regular expression within a text range. The dereferenced
259438fd1498Szrj * value of an iterator of this class is a std::sub_match object.
259538fd1498Szrj */
259638fd1498Szrj template<typename _Bi_iter,
259738fd1498Szrj typename _Ch_type = typename iterator_traits<_Bi_iter>::value_type,
259838fd1498Szrj typename _Rx_traits = regex_traits<_Ch_type> >
259938fd1498Szrj class regex_token_iterator
260038fd1498Szrj {
260138fd1498Szrj public:
260238fd1498Szrj typedef basic_regex<_Ch_type, _Rx_traits> regex_type;
260338fd1498Szrj typedef sub_match<_Bi_iter> value_type;
260438fd1498Szrj typedef std::ptrdiff_t difference_type;
260538fd1498Szrj typedef const value_type* pointer;
260638fd1498Szrj typedef const value_type& reference;
260738fd1498Szrj typedef std::forward_iterator_tag iterator_category;
260838fd1498Szrj
260938fd1498Szrj public:
261038fd1498Szrj /**
261138fd1498Szrj * @brief Default constructs a %regex_token_iterator.
261238fd1498Szrj *
261338fd1498Szrj * A default-constructed %regex_token_iterator is a singular iterator
261438fd1498Szrj * that will compare equal to the one-past-the-end value for any
261538fd1498Szrj * iterator of the same type.
261638fd1498Szrj */
261738fd1498Szrj regex_token_iterator()
261838fd1498Szrj : _M_position(), _M_subs(), _M_suffix(), _M_n(0), _M_result(nullptr),
261938fd1498Szrj _M_has_m1(false)
262038fd1498Szrj { }
262138fd1498Szrj
262238fd1498Szrj /**
262338fd1498Szrj * Constructs a %regex_token_iterator...
262438fd1498Szrj * @param __a [IN] The start of the text to search.
262538fd1498Szrj * @param __b [IN] One-past-the-end of the text to search.
262638fd1498Szrj * @param __re [IN] The regular expression to search for.
262738fd1498Szrj * @param __submatch [IN] Which submatch to return. There are some
262838fd1498Szrj * special values for this parameter:
262938fd1498Szrj * - -1 each enumerated subexpression does NOT
263038fd1498Szrj * match the regular expression (aka field
263138fd1498Szrj * splitting)
263238fd1498Szrj * - 0 the entire string matching the
263338fd1498Szrj * subexpression is returned for each match
263438fd1498Szrj * within the text.
263538fd1498Szrj * - >0 enumerates only the indicated
263638fd1498Szrj * subexpression from a match within the text.
263738fd1498Szrj * @param __m [IN] Policy flags for match rules.
263838fd1498Szrj */
263938fd1498Szrj regex_token_iterator(_Bi_iter __a, _Bi_iter __b, const regex_type& __re,
264038fd1498Szrj int __submatch = 0,
264138fd1498Szrj regex_constants::match_flag_type __m
264238fd1498Szrj = regex_constants::match_default)
264338fd1498Szrj : _M_position(__a, __b, __re, __m), _M_subs(1, __submatch), _M_n(0)
264438fd1498Szrj { _M_init(__a, __b); }
264538fd1498Szrj
264638fd1498Szrj /**
264738fd1498Szrj * Constructs a %regex_token_iterator...
264838fd1498Szrj * @param __a [IN] The start of the text to search.
264938fd1498Szrj * @param __b [IN] One-past-the-end of the text to search.
265038fd1498Szrj * @param __re [IN] The regular expression to search for.
265138fd1498Szrj * @param __submatches [IN] A list of subexpressions to return for each
265238fd1498Szrj * regular expression match within the text.
265338fd1498Szrj * @param __m [IN] Policy flags for match rules.
265438fd1498Szrj */
265538fd1498Szrj regex_token_iterator(_Bi_iter __a, _Bi_iter __b,
265638fd1498Szrj const regex_type& __re,
265738fd1498Szrj const std::vector<int>& __submatches,
265838fd1498Szrj regex_constants::match_flag_type __m
265938fd1498Szrj = regex_constants::match_default)
266038fd1498Szrj : _M_position(__a, __b, __re, __m), _M_subs(__submatches), _M_n(0)
266138fd1498Szrj { _M_init(__a, __b); }
266238fd1498Szrj
266338fd1498Szrj /**
266438fd1498Szrj * Constructs a %regex_token_iterator...
266538fd1498Szrj * @param __a [IN] The start of the text to search.
266638fd1498Szrj * @param __b [IN] One-past-the-end of the text to search.
266738fd1498Szrj * @param __re [IN] The regular expression to search for.
266838fd1498Szrj * @param __submatches [IN] A list of subexpressions to return for each
266938fd1498Szrj * regular expression match within the text.
267038fd1498Szrj * @param __m [IN] Policy flags for match rules.
267138fd1498Szrj */
267238fd1498Szrj regex_token_iterator(_Bi_iter __a, _Bi_iter __b,
267338fd1498Szrj const regex_type& __re,
267438fd1498Szrj initializer_list<int> __submatches,
267538fd1498Szrj regex_constants::match_flag_type __m
267638fd1498Szrj = regex_constants::match_default)
267738fd1498Szrj : _M_position(__a, __b, __re, __m), _M_subs(__submatches), _M_n(0)
267838fd1498Szrj { _M_init(__a, __b); }
267938fd1498Szrj
268038fd1498Szrj /**
268138fd1498Szrj * Constructs a %regex_token_iterator...
268238fd1498Szrj * @param __a [IN] The start of the text to search.
268338fd1498Szrj * @param __b [IN] One-past-the-end of the text to search.
268438fd1498Szrj * @param __re [IN] The regular expression to search for.
268538fd1498Szrj * @param __submatches [IN] A list of subexpressions to return for each
268638fd1498Szrj * regular expression match within the text.
268738fd1498Szrj * @param __m [IN] Policy flags for match rules.
268838fd1498Szrj */
268938fd1498Szrj template<std::size_t _Nm>
269038fd1498Szrj regex_token_iterator(_Bi_iter __a, _Bi_iter __b,
269138fd1498Szrj const regex_type& __re,
269238fd1498Szrj const int (&__submatches)[_Nm],
269338fd1498Szrj regex_constants::match_flag_type __m
269438fd1498Szrj = regex_constants::match_default)
269538fd1498Szrj : _M_position(__a, __b, __re, __m),
269638fd1498Szrj _M_subs(__submatches, __submatches + _Nm), _M_n(0)
269738fd1498Szrj { _M_init(__a, __b); }
269838fd1498Szrj
269938fd1498Szrj // _GLIBCXX_RESOLVE_LIB_DEFECTS
270038fd1498Szrj // 2332. regex_token_iterator should forbid temporary regexes
270138fd1498Szrj regex_token_iterator(_Bi_iter, _Bi_iter, const regex_type&&, int = 0,
270238fd1498Szrj regex_constants::match_flag_type =
270338fd1498Szrj regex_constants::match_default) = delete;
270438fd1498Szrj regex_token_iterator(_Bi_iter, _Bi_iter, const regex_type&&,
270538fd1498Szrj const std::vector<int>&,
270638fd1498Szrj regex_constants::match_flag_type =
270738fd1498Szrj regex_constants::match_default) = delete;
270838fd1498Szrj regex_token_iterator(_Bi_iter, _Bi_iter, const regex_type&&,
270938fd1498Szrj initializer_list<int>,
271038fd1498Szrj regex_constants::match_flag_type =
271138fd1498Szrj regex_constants::match_default) = delete;
271238fd1498Szrj template <std::size_t _Nm>
271338fd1498Szrj regex_token_iterator(_Bi_iter, _Bi_iter, const regex_type&&,
271438fd1498Szrj const int (&)[_Nm],
271538fd1498Szrj regex_constants::match_flag_type =
271638fd1498Szrj regex_constants::match_default) = delete;
271738fd1498Szrj
271838fd1498Szrj /**
271938fd1498Szrj * @brief Copy constructs a %regex_token_iterator.
272038fd1498Szrj * @param __rhs [IN] A %regex_token_iterator to copy.
272138fd1498Szrj */
272238fd1498Szrj regex_token_iterator(const regex_token_iterator& __rhs)
272338fd1498Szrj : _M_position(__rhs._M_position), _M_subs(__rhs._M_subs),
272438fd1498Szrj _M_suffix(__rhs._M_suffix), _M_n(__rhs._M_n), _M_has_m1(__rhs._M_has_m1)
272538fd1498Szrj { _M_normalize_result(); }
272638fd1498Szrj
272738fd1498Szrj /**
272838fd1498Szrj * @brief Assigns a %regex_token_iterator to another.
272938fd1498Szrj * @param __rhs [IN] A %regex_token_iterator to copy.
273038fd1498Szrj */
273138fd1498Szrj regex_token_iterator&
273238fd1498Szrj operator=(const regex_token_iterator& __rhs);
273338fd1498Szrj
273438fd1498Szrj /**
273538fd1498Szrj * @brief Compares a %regex_token_iterator to another for equality.
273638fd1498Szrj */
273738fd1498Szrj bool
273838fd1498Szrj operator==(const regex_token_iterator& __rhs) const;
273938fd1498Szrj
274038fd1498Szrj /**
274138fd1498Szrj * @brief Compares a %regex_token_iterator to another for inequality.
274238fd1498Szrj */
274338fd1498Szrj bool
274438fd1498Szrj operator!=(const regex_token_iterator& __rhs) const
274538fd1498Szrj { return !(*this == __rhs); }
274638fd1498Szrj
274738fd1498Szrj /**
274838fd1498Szrj * @brief Dereferences a %regex_token_iterator.
274938fd1498Szrj */
275038fd1498Szrj const value_type&
275138fd1498Szrj operator*() const
275238fd1498Szrj { return *_M_result; }
275338fd1498Szrj
275438fd1498Szrj /**
275538fd1498Szrj * @brief Selects a %regex_token_iterator member.
275638fd1498Szrj */
275738fd1498Szrj const value_type*
275838fd1498Szrj operator->() const
275938fd1498Szrj { return _M_result; }
276038fd1498Szrj
276138fd1498Szrj /**
276238fd1498Szrj * @brief Increments a %regex_token_iterator.
276338fd1498Szrj */
276438fd1498Szrj regex_token_iterator&
276538fd1498Szrj operator++();
276638fd1498Szrj
276738fd1498Szrj /**
276838fd1498Szrj * @brief Postincrements a %regex_token_iterator.
276938fd1498Szrj */
277038fd1498Szrj regex_token_iterator
277138fd1498Szrj operator++(int)
277238fd1498Szrj {
277338fd1498Szrj auto __tmp = *this;
277438fd1498Szrj ++(*this);
277538fd1498Szrj return __tmp;
277638fd1498Szrj }
277738fd1498Szrj
277838fd1498Szrj private:
277938fd1498Szrj typedef regex_iterator<_Bi_iter, _Ch_type, _Rx_traits> _Position;
278038fd1498Szrj
278138fd1498Szrj void
278238fd1498Szrj _M_init(_Bi_iter __a, _Bi_iter __b);
278338fd1498Szrj
278438fd1498Szrj const value_type&
278538fd1498Szrj _M_current_match() const
278638fd1498Szrj {
278738fd1498Szrj if (_M_subs[_M_n] == -1)
278838fd1498Szrj return (*_M_position).prefix();
278938fd1498Szrj else
279038fd1498Szrj return (*_M_position)[_M_subs[_M_n]];
279138fd1498Szrj }
279238fd1498Szrj
279338fd1498Szrj constexpr bool
279438fd1498Szrj _M_end_of_seq() const
279538fd1498Szrj { return _M_result == nullptr; }
279638fd1498Szrj
279738fd1498Szrj // [28.12.2.2.4]
279838fd1498Szrj void
279938fd1498Szrj _M_normalize_result()
280038fd1498Szrj {
280138fd1498Szrj if (_M_position != _Position())
280238fd1498Szrj _M_result = &_M_current_match();
280338fd1498Szrj else if (_M_has_m1)
280438fd1498Szrj _M_result = &_M_suffix;
280538fd1498Szrj else
280638fd1498Szrj _M_result = nullptr;
280738fd1498Szrj }
280838fd1498Szrj
280938fd1498Szrj _Position _M_position;
281038fd1498Szrj std::vector<int> _M_subs;
281138fd1498Szrj value_type _M_suffix;
281238fd1498Szrj std::size_t _M_n;
281338fd1498Szrj const value_type* _M_result;
281438fd1498Szrj
281538fd1498Szrj // Show whether _M_subs contains -1
281638fd1498Szrj bool _M_has_m1;
281738fd1498Szrj };
281838fd1498Szrj
281938fd1498Szrj /** @brief Token iterator for C-style NULL-terminated strings. */
282038fd1498Szrj typedef regex_token_iterator<const char*> cregex_token_iterator;
282138fd1498Szrj
282238fd1498Szrj /** @brief Token iterator for standard strings. */
282338fd1498Szrj typedef regex_token_iterator<string::const_iterator> sregex_token_iterator;
282438fd1498Szrj
282538fd1498Szrj #ifdef _GLIBCXX_USE_WCHAR_T
282638fd1498Szrj /** @brief Token iterator for C-style NULL-terminated wide strings. */
282738fd1498Szrj typedef regex_token_iterator<const wchar_t*> wcregex_token_iterator;
282838fd1498Szrj
282938fd1498Szrj /** @brief Token iterator for standard wide-character strings. */
283038fd1498Szrj typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator;
283138fd1498Szrj #endif
283238fd1498Szrj
283338fd1498Szrj //@} // group regex
283438fd1498Szrj
283538fd1498Szrj _GLIBCXX_END_NAMESPACE_CXX11
283638fd1498Szrj _GLIBCXX_END_NAMESPACE_VERSION
283738fd1498Szrj } // namespace
283838fd1498Szrj
283938fd1498Szrj #include <bits/regex.tcc>
2840