xref: /freebsd/contrib/llvm-project/libcxx/include/regex (revision a4a491e2238b12ccd64d3faf9e6401487f6f1f1b)
10b57cec5SDimitry Andric// -*- C++ -*-
2349cc55cSDimitry Andric//===----------------------------------------------------------------------===//
30b57cec5SDimitry Andric//
40b57cec5SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
50b57cec5SDimitry Andric// See https://llvm.org/LICENSE.txt for license information.
60b57cec5SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
70b57cec5SDimitry Andric//
80b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
90b57cec5SDimitry Andric
100b57cec5SDimitry Andric#ifndef _LIBCPP_REGEX
110b57cec5SDimitry Andric#define _LIBCPP_REGEX
120b57cec5SDimitry Andric
130b57cec5SDimitry Andric/*
140b57cec5SDimitry Andric    regex synopsis
150b57cec5SDimitry Andric
160b57cec5SDimitry Andric#include <initializer_list>
170b57cec5SDimitry Andric
180b57cec5SDimitry Andricnamespace std
190b57cec5SDimitry Andric{
200b57cec5SDimitry Andric
210b57cec5SDimitry Andricnamespace regex_constants
220b57cec5SDimitry Andric{
230b57cec5SDimitry Andric
245ffd83dbSDimitry Andricenum syntax_option_type
250b57cec5SDimitry Andric{
260b57cec5SDimitry Andric    icase      = unspecified,
270b57cec5SDimitry Andric    nosubs     = unspecified,
280b57cec5SDimitry Andric    optimize   = unspecified,
290b57cec5SDimitry Andric    collate    = unspecified,
300b57cec5SDimitry Andric    ECMAScript = unspecified,
310b57cec5SDimitry Andric    basic      = unspecified,
320b57cec5SDimitry Andric    extended   = unspecified,
330b57cec5SDimitry Andric    awk        = unspecified,
340b57cec5SDimitry Andric    grep       = unspecified,
35e8d8bef9SDimitry Andric    egrep      = unspecified,
36e8d8bef9SDimitry Andric    multiline  = unspecified
370b57cec5SDimitry Andric};
380b57cec5SDimitry Andric
390b57cec5SDimitry Andricconstexpr syntax_option_type operator~(syntax_option_type f);
400b57cec5SDimitry Andricconstexpr syntax_option_type operator&(syntax_option_type lhs, syntax_option_type rhs);
410b57cec5SDimitry Andricconstexpr syntax_option_type operator|(syntax_option_type lhs, syntax_option_type rhs);
420b57cec5SDimitry Andric
430b57cec5SDimitry Andricenum match_flag_type
440b57cec5SDimitry Andric{
450b57cec5SDimitry Andric    match_default     = 0,
460b57cec5SDimitry Andric    match_not_bol     = unspecified,
470b57cec5SDimitry Andric    match_not_eol     = unspecified,
480b57cec5SDimitry Andric    match_not_bow     = unspecified,
490b57cec5SDimitry Andric    match_not_eow     = unspecified,
500b57cec5SDimitry Andric    match_any         = unspecified,
510b57cec5SDimitry Andric    match_not_null    = unspecified,
520b57cec5SDimitry Andric    match_continuous  = unspecified,
530b57cec5SDimitry Andric    match_prev_avail  = unspecified,
540b57cec5SDimitry Andric    format_default    = 0,
550b57cec5SDimitry Andric    format_sed        = unspecified,
560b57cec5SDimitry Andric    format_no_copy    = unspecified,
570b57cec5SDimitry Andric    format_first_only = unspecified
580b57cec5SDimitry Andric};
590b57cec5SDimitry Andric
600b57cec5SDimitry Andricconstexpr match_flag_type operator~(match_flag_type f);
610b57cec5SDimitry Andricconstexpr match_flag_type operator&(match_flag_type lhs, match_flag_type rhs);
620b57cec5SDimitry Andricconstexpr match_flag_type operator|(match_flag_type lhs, match_flag_type rhs);
630b57cec5SDimitry Andric
640b57cec5SDimitry Andricenum error_type
650b57cec5SDimitry Andric{
660b57cec5SDimitry Andric    error_collate    = unspecified,
670b57cec5SDimitry Andric    error_ctype      = unspecified,
680b57cec5SDimitry Andric    error_escape     = unspecified,
690b57cec5SDimitry Andric    error_backref    = unspecified,
700b57cec5SDimitry Andric    error_brack      = unspecified,
710b57cec5SDimitry Andric    error_paren      = unspecified,
720b57cec5SDimitry Andric    error_brace      = unspecified,
730b57cec5SDimitry Andric    error_badbrace   = unspecified,
740b57cec5SDimitry Andric    error_range      = unspecified,
750b57cec5SDimitry Andric    error_space      = unspecified,
760b57cec5SDimitry Andric    error_badrepeat  = unspecified,
770b57cec5SDimitry Andric    error_complexity = unspecified,
780b57cec5SDimitry Andric    error_stack      = unspecified
790b57cec5SDimitry Andric};
800b57cec5SDimitry Andric
810b57cec5SDimitry Andric}  // regex_constants
820b57cec5SDimitry Andric
830b57cec5SDimitry Andricclass regex_error
840b57cec5SDimitry Andric    : public runtime_error
850b57cec5SDimitry Andric{
860b57cec5SDimitry Andricpublic:
870b57cec5SDimitry Andric    explicit regex_error(regex_constants::error_type ecode);
880b57cec5SDimitry Andric    regex_constants::error_type code() const;
890b57cec5SDimitry Andric};
900b57cec5SDimitry Andric
910b57cec5SDimitry Andrictemplate <class charT>
920b57cec5SDimitry Andricstruct regex_traits
930b57cec5SDimitry Andric{
940b57cec5SDimitry Andricpublic:
950b57cec5SDimitry Andric    typedef charT                   char_type;
960b57cec5SDimitry Andric    typedef basic_string<char_type> string_type;
970b57cec5SDimitry Andric    typedef locale                  locale_type;
980b57cec5SDimitry Andric    typedef /bitmask_type/          char_class_type;
990b57cec5SDimitry Andric
1000b57cec5SDimitry Andric    regex_traits();
1010b57cec5SDimitry Andric
1020b57cec5SDimitry Andric    static size_t length(const char_type* p);
1030b57cec5SDimitry Andric    charT translate(charT c) const;
1040b57cec5SDimitry Andric    charT translate_nocase(charT c) const;
1050b57cec5SDimitry Andric    template <class ForwardIterator>
1060b57cec5SDimitry Andric        string_type
1070b57cec5SDimitry Andric        transform(ForwardIterator first, ForwardIterator last) const;
1080b57cec5SDimitry Andric    template <class ForwardIterator>
1090b57cec5SDimitry Andric        string_type
1100b57cec5SDimitry Andric        transform_primary( ForwardIterator first, ForwardIterator last) const;
1110b57cec5SDimitry Andric    template <class ForwardIterator>
1120b57cec5SDimitry Andric        string_type
1130b57cec5SDimitry Andric        lookup_collatename(ForwardIterator first, ForwardIterator last) const;
1140b57cec5SDimitry Andric    template <class ForwardIterator>
1150b57cec5SDimitry Andric        char_class_type
1160b57cec5SDimitry Andric        lookup_classname(ForwardIterator first, ForwardIterator last,
1170b57cec5SDimitry Andric                         bool icase = false) const;
1180b57cec5SDimitry Andric    bool isctype(charT c, char_class_type f) const;
1190b57cec5SDimitry Andric    int value(charT ch, int radix) const;
1200b57cec5SDimitry Andric    locale_type imbue(locale_type l);
1210b57cec5SDimitry Andric    locale_type getloc()const;
1220b57cec5SDimitry Andric};
1230b57cec5SDimitry Andric
1240b57cec5SDimitry Andrictemplate <class charT, class traits = regex_traits<charT>>
1250b57cec5SDimitry Andricclass basic_regex
1260b57cec5SDimitry Andric{
1270b57cec5SDimitry Andricpublic:
1280b57cec5SDimitry Andric    // types:
1290b57cec5SDimitry Andric    typedef charT                               value_type;
1300b57cec5SDimitry Andric    typedef traits                              traits_type;
1310b57cec5SDimitry Andric    typedef typename traits::string_type        string_type;
1320b57cec5SDimitry Andric    typedef regex_constants::syntax_option_type flag_type;
1330b57cec5SDimitry Andric    typedef typename traits::locale_type        locale_type;
1340b57cec5SDimitry Andric
1350b57cec5SDimitry Andric    // constants:
1360b57cec5SDimitry Andric    static constexpr regex_constants::syntax_option_type icase = regex_constants::icase;
1370b57cec5SDimitry Andric    static constexpr regex_constants::syntax_option_type nosubs = regex_constants::nosubs;
1380b57cec5SDimitry Andric    static constexpr regex_constants::syntax_option_type optimize = regex_constants::optimize;
1390b57cec5SDimitry Andric    static constexpr regex_constants::syntax_option_type collate = regex_constants::collate;
1400b57cec5SDimitry Andric    static constexpr regex_constants::syntax_option_type ECMAScript = regex_constants::ECMAScript;
1410b57cec5SDimitry Andric    static constexpr regex_constants::syntax_option_type basic = regex_constants::basic;
1420b57cec5SDimitry Andric    static constexpr regex_constants::syntax_option_type extended = regex_constants::extended;
1430b57cec5SDimitry Andric    static constexpr regex_constants::syntax_option_type awk = regex_constants::awk;
1440b57cec5SDimitry Andric    static constexpr regex_constants::syntax_option_type grep = regex_constants::grep;
1450b57cec5SDimitry Andric    static constexpr regex_constants::syntax_option_type egrep = regex_constants::egrep;
146e8d8bef9SDimitry Andric    static constexpr regex_constants::syntax_option_type multiline = regex_constants::multiline;
1470b57cec5SDimitry Andric
1480b57cec5SDimitry Andric    // construct/copy/destroy:
1490b57cec5SDimitry Andric    basic_regex();
1500b57cec5SDimitry Andric    explicit basic_regex(const charT* p, flag_type f = regex_constants::ECMAScript);
1510b57cec5SDimitry Andric    basic_regex(const charT* p, size_t len, flag_type f = regex_constants::ECMAScript);
1520b57cec5SDimitry Andric    basic_regex(const basic_regex&);
1530b57cec5SDimitry Andric    basic_regex(basic_regex&&) noexcept;
1540b57cec5SDimitry Andric    template <class ST, class SA>
1550b57cec5SDimitry Andric        explicit basic_regex(const basic_string<charT, ST, SA>& p,
1560b57cec5SDimitry Andric                             flag_type f = regex_constants::ECMAScript);
1570b57cec5SDimitry Andric    template <class ForwardIterator>
1580b57cec5SDimitry Andric        basic_regex(ForwardIterator first, ForwardIterator last,
1590b57cec5SDimitry Andric                    flag_type f = regex_constants::ECMAScript);
1600b57cec5SDimitry Andric    basic_regex(initializer_list<charT>, flag_type = regex_constants::ECMAScript);
1610b57cec5SDimitry Andric
1620b57cec5SDimitry Andric    ~basic_regex();
1630b57cec5SDimitry Andric
1640b57cec5SDimitry Andric    basic_regex& operator=(const basic_regex&);
1650b57cec5SDimitry Andric    basic_regex& operator=(basic_regex&&) noexcept;
1660b57cec5SDimitry Andric    basic_regex& operator=(const charT* ptr);
1670b57cec5SDimitry Andric    basic_regex& operator=(initializer_list<charT> il);
1680b57cec5SDimitry Andric    template <class ST, class SA>
1690b57cec5SDimitry Andric        basic_regex& operator=(const basic_string<charT, ST, SA>& p);
1700b57cec5SDimitry Andric
1710b57cec5SDimitry Andric    // assign:
1720b57cec5SDimitry Andric    basic_regex& assign(const basic_regex& that);
1730b57cec5SDimitry Andric    basic_regex& assign(basic_regex&& that) noexcept;
1740b57cec5SDimitry Andric    basic_regex& assign(const charT* ptr,           flag_type f = regex_constants::ECMAScript);
175e40139ffSDimitry Andric    basic_regex& assign(const charT* p, size_t len, flag_type f = regex_constants::ECMAScript);
1760b57cec5SDimitry Andric    template <class string_traits, class A>
1770b57cec5SDimitry Andric        basic_regex& assign(const basic_string<charT, string_traits, A>& s,
1780b57cec5SDimitry Andric                                                    flag_type f = regex_constants::ECMAScript);
1790b57cec5SDimitry Andric    template <class InputIterator>
1800b57cec5SDimitry Andric        basic_regex& assign(InputIterator first, InputIterator last,
1810b57cec5SDimitry Andric                                                    flag_type f = regex_constants::ECMAScript);
182e40139ffSDimitry Andric    basic_regex& assign(initializer_list<charT>,    flag_type f = regex_constants::ECMAScript);
1830b57cec5SDimitry Andric
1840b57cec5SDimitry Andric    // const operations:
1850b57cec5SDimitry Andric    unsigned mark_count() const;
1860b57cec5SDimitry Andric    flag_type flags() const;
1870b57cec5SDimitry Andric
1880b57cec5SDimitry Andric    // locale:
1890b57cec5SDimitry Andric    locale_type imbue(locale_type loc);
1900b57cec5SDimitry Andric    locale_type getloc() const;
1910b57cec5SDimitry Andric
1920b57cec5SDimitry Andric    // swap:
1930b57cec5SDimitry Andric    void swap(basic_regex&);
1940b57cec5SDimitry Andric};
1950b57cec5SDimitry Andric
1960b57cec5SDimitry Andrictemplate<class ForwardIterator>
1970b57cec5SDimitry Andricbasic_regex(ForwardIterator, ForwardIterator,
1980b57cec5SDimitry Andric            regex_constants::syntax_option_type = regex_constants::ECMAScript)
1990b57cec5SDimitry Andric    -> basic_regex<typename iterator_traits<ForwardIterator>::value_type>; // C++17
2000b57cec5SDimitry Andric
2010b57cec5SDimitry Andrictypedef basic_regex<char>    regex;
2020b57cec5SDimitry Andrictypedef basic_regex<wchar_t> wregex;
2030b57cec5SDimitry Andric
2040b57cec5SDimitry Andrictemplate <class charT, class traits>
2050b57cec5SDimitry Andric    void swap(basic_regex<charT, traits>& e1, basic_regex<charT, traits>& e2);
2060b57cec5SDimitry Andric
2070b57cec5SDimitry Andrictemplate <class BidirectionalIterator>
2080b57cec5SDimitry Andricclass sub_match
2090b57cec5SDimitry Andric    : public pair<BidirectionalIterator, BidirectionalIterator>
2100b57cec5SDimitry Andric{
2110b57cec5SDimitry Andricpublic:
2120b57cec5SDimitry Andric    typedef typename iterator_traits<BidirectionalIterator>::value_type value_type;
2130b57cec5SDimitry Andric    typedef typename iterator_traits<BidirectionalIterator>::difference_type difference_type;
2140b57cec5SDimitry Andric    typedef BidirectionalIterator                                      iterator;
2150b57cec5SDimitry Andric    typedef basic_string<value_type>                                string_type;
2160b57cec5SDimitry Andric
2170b57cec5SDimitry Andric    bool matched;
2180b57cec5SDimitry Andric
2190b57cec5SDimitry Andric    constexpr sub_match();
2200b57cec5SDimitry Andric
2210b57cec5SDimitry Andric    difference_type length() const;
2220b57cec5SDimitry Andric    operator string_type() const;
2230b57cec5SDimitry Andric    string_type str() const;
2240b57cec5SDimitry Andric
2250b57cec5SDimitry Andric    int compare(const sub_match& s) const;
2260b57cec5SDimitry Andric    int compare(const string_type& s) const;
2270b57cec5SDimitry Andric    int compare(const value_type* s) const;
2280b57cec5SDimitry Andric};
2290b57cec5SDimitry Andric
2300b57cec5SDimitry Andrictypedef sub_match<const char*>             csub_match;
2310b57cec5SDimitry Andrictypedef sub_match<const wchar_t*>          wcsub_match;
2320b57cec5SDimitry Andrictypedef sub_match<string::const_iterator>  ssub_match;
2330b57cec5SDimitry Andrictypedef sub_match<wstring::const_iterator> wssub_match;
2340b57cec5SDimitry Andric
2350b57cec5SDimitry Andrictemplate <class BiIter>
2360b57cec5SDimitry Andric    bool
2370b57cec5SDimitry Andric    operator==(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
2380b57cec5SDimitry Andric
2390b57cec5SDimitry Andrictemplate <class BiIter>
2400b57cec5SDimitry Andric    bool
2410b57cec5SDimitry Andric    operator!=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
2420b57cec5SDimitry Andric
2430b57cec5SDimitry Andrictemplate <class BiIter>
2440b57cec5SDimitry Andric    bool
2450b57cec5SDimitry Andric    operator<(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
2460b57cec5SDimitry Andric
2470b57cec5SDimitry Andrictemplate <class BiIter>
2480b57cec5SDimitry Andric    bool
2490b57cec5SDimitry Andric    operator<=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
2500b57cec5SDimitry Andric
2510b57cec5SDimitry Andrictemplate <class BiIter>
2520b57cec5SDimitry Andric    bool
2530b57cec5SDimitry Andric    operator>=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
2540b57cec5SDimitry Andric
2550b57cec5SDimitry Andrictemplate <class BiIter>
2560b57cec5SDimitry Andric    bool
2570b57cec5SDimitry Andric    operator>(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
2580b57cec5SDimitry Andric
2590b57cec5SDimitry Andrictemplate <class BiIter, class ST, class SA>
2600b57cec5SDimitry Andric    bool
2610b57cec5SDimitry Andric    operator==(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
2620b57cec5SDimitry Andric               const sub_match<BiIter>& rhs);
2630b57cec5SDimitry Andric
2640b57cec5SDimitry Andrictemplate <class BiIter, class ST, class SA>
2650b57cec5SDimitry Andric    bool
2660b57cec5SDimitry Andric    operator!=(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
2670b57cec5SDimitry Andric               const sub_match<BiIter>& rhs);
2680b57cec5SDimitry Andric
2690b57cec5SDimitry Andrictemplate <class BiIter, class ST, class SA>
2700b57cec5SDimitry Andric    bool
2710b57cec5SDimitry Andric    operator<(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
2720b57cec5SDimitry Andric              const sub_match<BiIter>& rhs);
2730b57cec5SDimitry Andric
2740b57cec5SDimitry Andrictemplate <class BiIter, class ST, class SA>
2750b57cec5SDimitry Andric    bool
2760b57cec5SDimitry Andric    operator>(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
2770b57cec5SDimitry Andric              const sub_match<BiIter>& rhs);
2780b57cec5SDimitry Andric
2790b57cec5SDimitry Andrictemplate <class BiIter, class ST, class SA>
2800b57cec5SDimitry Andric    bool operator>=(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
2810b57cec5SDimitry Andric                    const sub_match<BiIter>& rhs);
2820b57cec5SDimitry Andric
2830b57cec5SDimitry Andrictemplate <class BiIter, class ST, class SA>
2840b57cec5SDimitry Andric    bool
2850b57cec5SDimitry Andric    operator<=(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
2860b57cec5SDimitry Andric               const sub_match<BiIter>& rhs);
2870b57cec5SDimitry Andric
2880b57cec5SDimitry Andrictemplate <class BiIter, class ST, class SA>
2890b57cec5SDimitry Andric    bool
2900b57cec5SDimitry Andric    operator==(const sub_match<BiIter>& lhs,
2910b57cec5SDimitry Andric               const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
2920b57cec5SDimitry Andric
2930b57cec5SDimitry Andrictemplate <class BiIter, class ST, class SA>
2940b57cec5SDimitry Andric    bool
2950b57cec5SDimitry Andric    operator!=(const sub_match<BiIter>& lhs,
2960b57cec5SDimitry Andric               const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
2970b57cec5SDimitry Andric
2980b57cec5SDimitry Andrictemplate <class BiIter, class ST, class SA>
2990b57cec5SDimitry Andric    bool
3000b57cec5SDimitry Andric    operator<(const sub_match<BiIter>& lhs,
3010b57cec5SDimitry Andric              const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
3020b57cec5SDimitry Andric
3030b57cec5SDimitry Andrictemplate <class BiIter, class ST, class SA>
3040b57cec5SDimitry Andric    bool operator>(const sub_match<BiIter>& lhs,
3050b57cec5SDimitry Andric                   const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
3060b57cec5SDimitry Andric
3070b57cec5SDimitry Andrictemplate <class BiIter, class ST, class SA>
3080b57cec5SDimitry Andric    bool
3090b57cec5SDimitry Andric    operator>=(const sub_match<BiIter>& lhs,
3100b57cec5SDimitry Andric               const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
3110b57cec5SDimitry Andric
3120b57cec5SDimitry Andrictemplate <class BiIter, class ST, class SA>
3130b57cec5SDimitry Andric    bool
3140b57cec5SDimitry Andric    operator<=(const sub_match<BiIter>& lhs,
3150b57cec5SDimitry Andric               const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
3160b57cec5SDimitry Andric
3170b57cec5SDimitry Andrictemplate <class BiIter>
3180b57cec5SDimitry Andric    bool
3190b57cec5SDimitry Andric    operator==(typename iterator_traits<BiIter>::value_type const* lhs,
3200b57cec5SDimitry Andric               const sub_match<BiIter>& rhs);
3210b57cec5SDimitry Andric
3220b57cec5SDimitry Andrictemplate <class BiIter>
3230b57cec5SDimitry Andric    bool
3240b57cec5SDimitry Andric    operator!=(typename iterator_traits<BiIter>::value_type const* lhs,
3250b57cec5SDimitry Andric               const sub_match<BiIter>& rhs);
3260b57cec5SDimitry Andric
3270b57cec5SDimitry Andrictemplate <class BiIter>
3280b57cec5SDimitry Andric    bool
3290b57cec5SDimitry Andric    operator<(typename iterator_traits<BiIter>::value_type const* lhs,
3300b57cec5SDimitry Andric              const sub_match<BiIter>& rhs);
3310b57cec5SDimitry Andric
3320b57cec5SDimitry Andrictemplate <class BiIter>
3330b57cec5SDimitry Andric    bool
3340b57cec5SDimitry Andric    operator>(typename iterator_traits<BiIter>::value_type const* lhs,
3350b57cec5SDimitry Andric              const sub_match<BiIter>& rhs);
3360b57cec5SDimitry Andric
3370b57cec5SDimitry Andrictemplate <class BiIter>
3380b57cec5SDimitry Andric    bool
3390b57cec5SDimitry Andric    operator>=(typename iterator_traits<BiIter>::value_type const* lhs,
3400b57cec5SDimitry Andric               const sub_match<BiIter>& rhs);
3410b57cec5SDimitry Andric
3420b57cec5SDimitry Andrictemplate <class BiIter>
3430b57cec5SDimitry Andric    bool
3440b57cec5SDimitry Andric    operator<=(typename iterator_traits<BiIter>::value_type const* lhs,
3450b57cec5SDimitry Andric               const sub_match<BiIter>& rhs);
3460b57cec5SDimitry Andric
3470b57cec5SDimitry Andrictemplate <class BiIter>
3480b57cec5SDimitry Andric    bool
3490b57cec5SDimitry Andric    operator==(const sub_match<BiIter>& lhs,
3500b57cec5SDimitry Andric               typename iterator_traits<BiIter>::value_type const* rhs);
3510b57cec5SDimitry Andric
3520b57cec5SDimitry Andrictemplate <class BiIter>
3530b57cec5SDimitry Andric    bool
3540b57cec5SDimitry Andric    operator!=(const sub_match<BiIter>& lhs,
3550b57cec5SDimitry Andric               typename iterator_traits<BiIter>::value_type const* rhs);
3560b57cec5SDimitry Andric
3570b57cec5SDimitry Andrictemplate <class BiIter>
3580b57cec5SDimitry Andric    bool
3590b57cec5SDimitry Andric    operator<(const sub_match<BiIter>& lhs,
3600b57cec5SDimitry Andric              typename iterator_traits<BiIter>::value_type const* rhs);
3610b57cec5SDimitry Andric
3620b57cec5SDimitry Andrictemplate <class BiIter>
3630b57cec5SDimitry Andric    bool
3640b57cec5SDimitry Andric    operator>(const sub_match<BiIter>& lhs,
3650b57cec5SDimitry Andric              typename iterator_traits<BiIter>::value_type const* rhs);
3660b57cec5SDimitry Andric
3670b57cec5SDimitry Andrictemplate <class BiIter>
3680b57cec5SDimitry Andric    bool
3690b57cec5SDimitry Andric    operator>=(const sub_match<BiIter>& lhs,
3700b57cec5SDimitry Andric               typename iterator_traits<BiIter>::value_type const* rhs);
3710b57cec5SDimitry Andric
3720b57cec5SDimitry Andrictemplate <class BiIter>
3730b57cec5SDimitry Andric    bool
3740b57cec5SDimitry Andric    operator<=(const sub_match<BiIter>& lhs,
3750b57cec5SDimitry Andric               typename iterator_traits<BiIter>::value_type const* rhs);
3760b57cec5SDimitry Andric
3770b57cec5SDimitry Andrictemplate <class BiIter>
3780b57cec5SDimitry Andric    bool
3790b57cec5SDimitry Andric    operator==(typename iterator_traits<BiIter>::value_type const& lhs,
3800b57cec5SDimitry Andric               const sub_match<BiIter>& rhs);
3810b57cec5SDimitry Andric
3820b57cec5SDimitry Andrictemplate <class BiIter>
3830b57cec5SDimitry Andric    bool
3840b57cec5SDimitry Andric    operator!=(typename iterator_traits<BiIter>::value_type const& lhs,
3850b57cec5SDimitry Andric               const sub_match<BiIter>& rhs);
3860b57cec5SDimitry Andric
3870b57cec5SDimitry Andrictemplate <class BiIter>
3880b57cec5SDimitry Andric    bool
3890b57cec5SDimitry Andric    operator<(typename iterator_traits<BiIter>::value_type const& lhs,
3900b57cec5SDimitry Andric              const sub_match<BiIter>& rhs);
3910b57cec5SDimitry Andric
3920b57cec5SDimitry Andrictemplate <class BiIter>
3930b57cec5SDimitry Andric    bool
3940b57cec5SDimitry Andric    operator>(typename iterator_traits<BiIter>::value_type const& lhs,
3950b57cec5SDimitry Andric              const sub_match<BiIter>& rhs);
3960b57cec5SDimitry Andric
3970b57cec5SDimitry Andrictemplate <class BiIter>
3980b57cec5SDimitry Andric    bool
3990b57cec5SDimitry Andric    operator>=(typename iterator_traits<BiIter>::value_type const& lhs,
4000b57cec5SDimitry Andric               const sub_match<BiIter>& rhs);
4010b57cec5SDimitry Andric
4020b57cec5SDimitry Andrictemplate <class BiIter>
4030b57cec5SDimitry Andric    bool
4040b57cec5SDimitry Andric    operator<=(typename iterator_traits<BiIter>::value_type const& lhs,
4050b57cec5SDimitry Andric               const sub_match<BiIter>& rhs);
4060b57cec5SDimitry Andric
4070b57cec5SDimitry Andrictemplate <class BiIter>
4080b57cec5SDimitry Andric    bool
4090b57cec5SDimitry Andric    operator==(const sub_match<BiIter>& lhs,
4100b57cec5SDimitry Andric               typename iterator_traits<BiIter>::value_type const& rhs);
4110b57cec5SDimitry Andric
4120b57cec5SDimitry Andrictemplate <class BiIter>
4130b57cec5SDimitry Andric    bool
4140b57cec5SDimitry Andric    operator!=(const sub_match<BiIter>& lhs,
4150b57cec5SDimitry Andric               typename iterator_traits<BiIter>::value_type const& rhs);
4160b57cec5SDimitry Andric
4170b57cec5SDimitry Andrictemplate <class BiIter>
4180b57cec5SDimitry Andric    bool
4190b57cec5SDimitry Andric    operator<(const sub_match<BiIter>& lhs,
4200b57cec5SDimitry Andric              typename iterator_traits<BiIter>::value_type const& rhs);
4210b57cec5SDimitry Andric
4220b57cec5SDimitry Andrictemplate <class BiIter>
4230b57cec5SDimitry Andric    bool
4240b57cec5SDimitry Andric    operator>(const sub_match<BiIter>& lhs,
4250b57cec5SDimitry Andric              typename iterator_traits<BiIter>::value_type const& rhs);
4260b57cec5SDimitry Andric
4270b57cec5SDimitry Andrictemplate <class BiIter>
4280b57cec5SDimitry Andric    bool
4290b57cec5SDimitry Andric    operator>=(const sub_match<BiIter>& lhs,
4300b57cec5SDimitry Andric               typename iterator_traits<BiIter>::value_type const& rhs);
4310b57cec5SDimitry Andric
4320b57cec5SDimitry Andrictemplate <class BiIter>
4330b57cec5SDimitry Andric    bool
4340b57cec5SDimitry Andric    operator<=(const sub_match<BiIter>& lhs,
4350b57cec5SDimitry Andric               typename iterator_traits<BiIter>::value_type const& rhs);
4360b57cec5SDimitry Andric
4370b57cec5SDimitry Andrictemplate <class charT, class ST, class BiIter>
4380b57cec5SDimitry Andric    basic_ostream<charT, ST>&
4390b57cec5SDimitry Andric    operator<<(basic_ostream<charT, ST>& os, const sub_match<BiIter>& m);
4400b57cec5SDimitry Andric
4410b57cec5SDimitry Andrictemplate <class BidirectionalIterator,
4420b57cec5SDimitry Andric          class Allocator = allocator<sub_match<BidirectionalIterator>>>
4430b57cec5SDimitry Andricclass match_results
4440b57cec5SDimitry Andric{
4450b57cec5SDimitry Andricpublic:
4460b57cec5SDimitry Andric    typedef sub_match<BidirectionalIterator>                  value_type;
4470b57cec5SDimitry Andric    typedef const value_type&                                 const_reference;
4480b57cec5SDimitry Andric    typedef value_type&                                       reference;
4490b57cec5SDimitry Andric    typedef /implementation-defined/                          const_iterator;
4500b57cec5SDimitry Andric    typedef const_iterator                                    iterator;
4510b57cec5SDimitry Andric    typedef typename iterator_traits<BidirectionalIterator>::difference_type difference_type;
4520b57cec5SDimitry Andric    typedef typename allocator_traits<Allocator>::size_type   size_type;
4530b57cec5SDimitry Andric    typedef Allocator                                         allocator_type;
4540b57cec5SDimitry Andric    typedef typename iterator_traits<BidirectionalIterator>::value_type char_type;
4550b57cec5SDimitry Andric    typedef basic_string<char_type>                           string_type;
4560b57cec5SDimitry Andric
4570b57cec5SDimitry Andric    // construct/copy/destroy:
458e8d8bef9SDimitry Andric    explicit match_results(const Allocator& a = Allocator()); // before C++20
459e8d8bef9SDimitry Andric    match_results() : match_results(Allocator()) {}           // C++20
460e8d8bef9SDimitry Andric    explicit match_results(const Allocator& a);               // C++20
4610b57cec5SDimitry Andric    match_results(const match_results& m);
4620b57cec5SDimitry Andric    match_results(match_results&& m) noexcept;
4630b57cec5SDimitry Andric    match_results& operator=(const match_results& m);
4640b57cec5SDimitry Andric    match_results& operator=(match_results&& m);
4650b57cec5SDimitry Andric    ~match_results();
4660b57cec5SDimitry Andric
4670b57cec5SDimitry Andric    bool ready() const;
4680b57cec5SDimitry Andric
4690b57cec5SDimitry Andric    // size:
4700b57cec5SDimitry Andric    size_type size() const;
4710b57cec5SDimitry Andric    size_type max_size() const;
4720b57cec5SDimitry Andric    bool empty() const;
4730b57cec5SDimitry Andric
4740b57cec5SDimitry Andric    // element access:
4750b57cec5SDimitry Andric    difference_type length(size_type sub = 0) const;
4760b57cec5SDimitry Andric    difference_type position(size_type sub = 0) const;
4770b57cec5SDimitry Andric    string_type str(size_type sub = 0) const;
4780b57cec5SDimitry Andric    const_reference operator[](size_type n) const;
4790b57cec5SDimitry Andric
4800b57cec5SDimitry Andric    const_reference prefix() const;
4810b57cec5SDimitry Andric    const_reference suffix() const;
4820b57cec5SDimitry Andric
4830b57cec5SDimitry Andric    const_iterator begin() const;
4840b57cec5SDimitry Andric    const_iterator end() const;
4850b57cec5SDimitry Andric    const_iterator cbegin() const;
4860b57cec5SDimitry Andric    const_iterator cend() const;
4870b57cec5SDimitry Andric
4880b57cec5SDimitry Andric    // format:
4890b57cec5SDimitry Andric    template <class OutputIter>
4900b57cec5SDimitry Andric        OutputIter
4910b57cec5SDimitry Andric        format(OutputIter out, const char_type* fmt_first,
4920b57cec5SDimitry Andric               const char_type* fmt_last,
4930b57cec5SDimitry Andric               regex_constants::match_flag_type flags = regex_constants::format_default) const;
4940b57cec5SDimitry Andric    template <class OutputIter, class ST, class SA>
4950b57cec5SDimitry Andric        OutputIter
4960b57cec5SDimitry Andric        format(OutputIter out, const basic_string<char_type, ST, SA>& fmt,
4970b57cec5SDimitry Andric               regex_constants::match_flag_type flags = regex_constants::format_default) const;
4980b57cec5SDimitry Andric    template <class ST, class SA>
4990b57cec5SDimitry Andric        basic_string<char_type, ST, SA>
5000b57cec5SDimitry Andric        format(const basic_string<char_type, ST, SA>& fmt,
5010b57cec5SDimitry Andric               regex_constants::match_flag_type flags = regex_constants::format_default) const;
5020b57cec5SDimitry Andric    string_type
5030b57cec5SDimitry Andric        format(const char_type* fmt,
5040b57cec5SDimitry Andric               regex_constants::match_flag_type flags = regex_constants::format_default) const;
5050b57cec5SDimitry Andric
5060b57cec5SDimitry Andric    // allocator:
5070b57cec5SDimitry Andric    allocator_type get_allocator() const;
5080b57cec5SDimitry Andric
5090b57cec5SDimitry Andric    // swap:
5100b57cec5SDimitry Andric    void swap(match_results& that);
5110b57cec5SDimitry Andric};
5120b57cec5SDimitry Andric
5130b57cec5SDimitry Andrictypedef match_results<const char*>             cmatch;
5140b57cec5SDimitry Andrictypedef match_results<const wchar_t*>          wcmatch;
5150b57cec5SDimitry Andrictypedef match_results<string::const_iterator>  smatch;
5160b57cec5SDimitry Andrictypedef match_results<wstring::const_iterator> wsmatch;
5170b57cec5SDimitry Andric
5180b57cec5SDimitry Andrictemplate <class BidirectionalIterator, class Allocator>
5190b57cec5SDimitry Andric    bool
5200b57cec5SDimitry Andric    operator==(const match_results<BidirectionalIterator, Allocator>& m1,
5210b57cec5SDimitry Andric               const match_results<BidirectionalIterator, Allocator>& m2);
5220b57cec5SDimitry Andric
5230b57cec5SDimitry Andrictemplate <class BidirectionalIterator, class Allocator>
5240b57cec5SDimitry Andric    bool
5250b57cec5SDimitry Andric    operator!=(const match_results<BidirectionalIterator, Allocator>& m1,
5260b57cec5SDimitry Andric               const match_results<BidirectionalIterator, Allocator>& m2);
5270b57cec5SDimitry Andric
5280b57cec5SDimitry Andrictemplate <class BidirectionalIterator, class Allocator>
5290b57cec5SDimitry Andric    void
5300b57cec5SDimitry Andric    swap(match_results<BidirectionalIterator, Allocator>& m1,
5310b57cec5SDimitry Andric         match_results<BidirectionalIterator, Allocator>& m2);
5320b57cec5SDimitry Andric
5330b57cec5SDimitry Andrictemplate <class BidirectionalIterator, class Allocator, class charT, class traits>
5340b57cec5SDimitry Andric    bool
5350b57cec5SDimitry Andric    regex_match(BidirectionalIterator first, BidirectionalIterator last,
5360b57cec5SDimitry Andric                match_results<BidirectionalIterator, Allocator>& m,
5370b57cec5SDimitry Andric                const basic_regex<charT, traits>& e,
5380b57cec5SDimitry Andric                regex_constants::match_flag_type flags = regex_constants::match_default);
5390b57cec5SDimitry Andric
5400b57cec5SDimitry Andrictemplate <class BidirectionalIterator, class charT, class traits>
5410b57cec5SDimitry Andric    bool
5420b57cec5SDimitry Andric    regex_match(BidirectionalIterator first, BidirectionalIterator last,
5430b57cec5SDimitry Andric                const basic_regex<charT, traits>& e,
5440b57cec5SDimitry Andric                regex_constants::match_flag_type flags = regex_constants::match_default);
5450b57cec5SDimitry Andric
5460b57cec5SDimitry Andrictemplate <class charT, class Allocator, class traits>
5470b57cec5SDimitry Andric    bool
5480b57cec5SDimitry Andric    regex_match(const charT* str, match_results<const charT*, Allocator>& m,
5490b57cec5SDimitry Andric                const basic_regex<charT, traits>& e,
5500b57cec5SDimitry Andric                regex_constants::match_flag_type flags = regex_constants::match_default);
5510b57cec5SDimitry Andric
5520b57cec5SDimitry Andrictemplate <class ST, class SA, class Allocator, class charT, class traits>
5530b57cec5SDimitry Andric    bool
5540b57cec5SDimitry Andric    regex_match(const basic_string<charT, ST, SA>& s,
5550b57cec5SDimitry Andric                match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m,
5560b57cec5SDimitry Andric                const basic_regex<charT, traits>& e,
5570b57cec5SDimitry Andric                regex_constants::match_flag_type flags = regex_constants::match_default);
5580b57cec5SDimitry Andric
5590b57cec5SDimitry Andrictemplate <class ST, class SA, class Allocator, class charT, class traits>
5600b57cec5SDimitry Andric    bool
5610b57cec5SDimitry Andric    regex_match(const basic_string<charT, ST, SA>&& s,
5620b57cec5SDimitry Andric                match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m,
5630b57cec5SDimitry Andric                const basic_regex<charT, traits>& e,
5640b57cec5SDimitry Andric                regex_constants::match_flag_type flags = regex_constants::match_default) = delete; // C++14
5650b57cec5SDimitry Andric
5660b57cec5SDimitry Andrictemplate <class charT, class traits>
5670b57cec5SDimitry Andric    bool
5680b57cec5SDimitry Andric    regex_match(const charT* str, const basic_regex<charT, traits>& e,
5690b57cec5SDimitry Andric                regex_constants::match_flag_type flags = regex_constants::match_default);
5700b57cec5SDimitry Andric
5710b57cec5SDimitry Andrictemplate <class ST, class SA, class charT, class traits>
5720b57cec5SDimitry Andric    bool
5730b57cec5SDimitry Andric    regex_match(const basic_string<charT, ST, SA>& s,
5740b57cec5SDimitry Andric                const basic_regex<charT, traits>& e,
5750b57cec5SDimitry Andric                regex_constants::match_flag_type flags = regex_constants::match_default);
5760b57cec5SDimitry Andric
5770b57cec5SDimitry Andrictemplate <class BidirectionalIterator, class Allocator, class charT, class traits>
5780b57cec5SDimitry Andric    bool
5790b57cec5SDimitry Andric    regex_search(BidirectionalIterator first, BidirectionalIterator last,
5800b57cec5SDimitry Andric                 match_results<BidirectionalIterator, Allocator>& m,
5810b57cec5SDimitry Andric                 const basic_regex<charT, traits>& e,
5820b57cec5SDimitry Andric                 regex_constants::match_flag_type flags = regex_constants::match_default);
5830b57cec5SDimitry Andric
5840b57cec5SDimitry Andrictemplate <class BidirectionalIterator, class charT, class traits>
5850b57cec5SDimitry Andric    bool
5860b57cec5SDimitry Andric    regex_search(BidirectionalIterator first, BidirectionalIterator last,
5870b57cec5SDimitry Andric                 const basic_regex<charT, traits>& e,
5880b57cec5SDimitry Andric                 regex_constants::match_flag_type flags = regex_constants::match_default);
5890b57cec5SDimitry Andric
5900b57cec5SDimitry Andrictemplate <class charT, class Allocator, class traits>
5910b57cec5SDimitry Andric    bool
5920b57cec5SDimitry Andric    regex_search(const charT* str, match_results<const charT*, Allocator>& m,
5930b57cec5SDimitry Andric                 const basic_regex<charT, traits>& e,
5940b57cec5SDimitry Andric                 regex_constants::match_flag_type flags = regex_constants::match_default);
5950b57cec5SDimitry Andric
5960b57cec5SDimitry Andrictemplate <class charT, class traits>
5970b57cec5SDimitry Andric    bool
5980b57cec5SDimitry Andric    regex_search(const charT* str, const basic_regex<charT, traits>& e,
5990b57cec5SDimitry Andric                 regex_constants::match_flag_type flags = regex_constants::match_default);
6000b57cec5SDimitry Andric
6010b57cec5SDimitry Andrictemplate <class ST, class SA, class charT, class traits>
6020b57cec5SDimitry Andric    bool
6030b57cec5SDimitry Andric    regex_search(const basic_string<charT, ST, SA>& s,
6040b57cec5SDimitry Andric                 const basic_regex<charT, traits>& e,
6050b57cec5SDimitry Andric                 regex_constants::match_flag_type flags = regex_constants::match_default);
6060b57cec5SDimitry Andric
6070b57cec5SDimitry Andrictemplate <class ST, class SA, class Allocator, class charT, class traits>
6080b57cec5SDimitry Andric    bool
6090b57cec5SDimitry Andric    regex_search(const basic_string<charT, ST, SA>& s,
6100b57cec5SDimitry Andric                 match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m,
6110b57cec5SDimitry Andric                 const basic_regex<charT, traits>& e,
6120b57cec5SDimitry Andric                 regex_constants::match_flag_type flags = regex_constants::match_default);
6130b57cec5SDimitry Andric
6140b57cec5SDimitry Andrictemplate <class ST, class SA, class Allocator, class charT, class traits>
6150b57cec5SDimitry Andric    bool
6160b57cec5SDimitry Andric    regex_search(const basic_string<charT, ST, SA>&& s,
6170b57cec5SDimitry Andric                 match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m,
6180b57cec5SDimitry Andric                 const basic_regex<charT, traits>& e,
6190b57cec5SDimitry Andric                 regex_constants::match_flag_type flags = regex_constants::match_default) = delete; // C++14
6200b57cec5SDimitry Andric
6210b57cec5SDimitry Andrictemplate <class OutputIterator, class BidirectionalIterator,
6220b57cec5SDimitry Andric          class traits, class charT, class ST, class SA>
6230b57cec5SDimitry Andric    OutputIterator
6240b57cec5SDimitry Andric    regex_replace(OutputIterator out,
6250b57cec5SDimitry Andric                  BidirectionalIterator first, BidirectionalIterator last,
6260b57cec5SDimitry Andric                  const basic_regex<charT, traits>& e,
6270b57cec5SDimitry Andric                  const basic_string<charT, ST, SA>& fmt,
6280b57cec5SDimitry Andric                  regex_constants::match_flag_type flags = regex_constants::match_default);
6290b57cec5SDimitry Andric
6300b57cec5SDimitry Andrictemplate <class OutputIterator, class BidirectionalIterator,
6310b57cec5SDimitry Andric          class traits, class charT>
6320b57cec5SDimitry Andric    OutputIterator
6330b57cec5SDimitry Andric    regex_replace(OutputIterator out,
6340b57cec5SDimitry Andric                  BidirectionalIterator first, BidirectionalIterator last,
6350b57cec5SDimitry Andric                  const basic_regex<charT, traits>& e, const charT* fmt,
6360b57cec5SDimitry Andric                  regex_constants::match_flag_type flags = regex_constants::match_default);
6370b57cec5SDimitry Andric
6385ffd83dbSDimitry Andrictemplate <class traits, class charT, class ST, class SA, class FST, class FSA>
6390b57cec5SDimitry Andric    basic_string<charT, ST, SA>
6400b57cec5SDimitry Andric    regex_replace(const basic_string<charT, ST, SA>& s,
6410b57cec5SDimitry Andric                  const basic_regex<charT, traits>& e,
6420b57cec5SDimitry Andric                  const basic_string<charT, FST, FSA>& fmt,
6430b57cec5SDimitry Andric                  regex_constants::match_flag_type flags = regex_constants::match_default);
6440b57cec5SDimitry Andric
6450b57cec5SDimitry Andrictemplate <class traits, class charT, class ST, class SA>
6460b57cec5SDimitry Andric    basic_string<charT, ST, SA>
6470b57cec5SDimitry Andric    regex_replace(const basic_string<charT, ST, SA>& s,
6480b57cec5SDimitry Andric                  const basic_regex<charT, traits>& e, const charT* fmt,
6490b57cec5SDimitry Andric                  regex_constants::match_flag_type flags = regex_constants::match_default);
6500b57cec5SDimitry Andric
6510b57cec5SDimitry Andrictemplate <class traits, class charT, class ST, class SA>
6520b57cec5SDimitry Andric    basic_string<charT>
6530b57cec5SDimitry Andric    regex_replace(const charT* s,
6540b57cec5SDimitry Andric                  const basic_regex<charT, traits>& e,
6550b57cec5SDimitry Andric                  const basic_string<charT, ST, SA>& fmt,
6560b57cec5SDimitry Andric                  regex_constants::match_flag_type flags = regex_constants::match_default);
6570b57cec5SDimitry Andric
6580b57cec5SDimitry Andrictemplate <class traits, class charT>
6590b57cec5SDimitry Andric    basic_string<charT>
6600b57cec5SDimitry Andric    regex_replace(const charT* s,
6610b57cec5SDimitry Andric                  const basic_regex<charT, traits>& e,
6620b57cec5SDimitry Andric                  const charT* fmt,
6630b57cec5SDimitry Andric                  regex_constants::match_flag_type flags = regex_constants::match_default);
6640b57cec5SDimitry Andric
6650b57cec5SDimitry Andrictemplate <class BidirectionalIterator,
6660b57cec5SDimitry Andric          class charT = typename iterator_traits< BidirectionalIterator>::value_type,
6670b57cec5SDimitry Andric          class traits = regex_traits<charT>>
6680b57cec5SDimitry Andricclass regex_iterator
6690b57cec5SDimitry Andric{
6700b57cec5SDimitry Andricpublic:
6710b57cec5SDimitry Andric    typedef basic_regex<charT, traits>           regex_type;
6720b57cec5SDimitry Andric    typedef match_results<BidirectionalIterator> value_type;
6730b57cec5SDimitry Andric    typedef ptrdiff_t                            difference_type;
6740b57cec5SDimitry Andric    typedef const value_type*                    pointer;
6750b57cec5SDimitry Andric    typedef const value_type&                    reference;
6760b57cec5SDimitry Andric    typedef forward_iterator_tag                 iterator_category;
6770b57cec5SDimitry Andric
6780b57cec5SDimitry Andric    regex_iterator();
6790b57cec5SDimitry Andric    regex_iterator(BidirectionalIterator a, BidirectionalIterator b,
6800b57cec5SDimitry Andric                   const regex_type& re,
6810b57cec5SDimitry Andric                   regex_constants::match_flag_type m = regex_constants::match_default);
6825ffd83dbSDimitry Andric    regex_iterator(BidirectionalIterator a, BidirectionalIterator b,
6835ffd83dbSDimitry Andric                   const regex_type&& re,
6845ffd83dbSDimitry Andric                   regex_constants::match_flag_type m
6850b57cec5SDimitry Andric                                     = regex_constants::match_default) = delete; // C++14
6860b57cec5SDimitry Andric    regex_iterator(const regex_iterator&);
6870b57cec5SDimitry Andric    regex_iterator& operator=(const regex_iterator&);
6880b57cec5SDimitry Andric
6890b57cec5SDimitry Andric    bool operator==(const regex_iterator&) const;
6900b57cec5SDimitry Andric    bool operator!=(const regex_iterator&) const;
6910b57cec5SDimitry Andric
6920b57cec5SDimitry Andric    const value_type& operator*() const;
6930b57cec5SDimitry Andric    const value_type* operator->() const;
6940b57cec5SDimitry Andric
6950b57cec5SDimitry Andric    regex_iterator& operator++();
6960b57cec5SDimitry Andric    regex_iterator operator++(int);
6970b57cec5SDimitry Andric};
6980b57cec5SDimitry Andric
6990b57cec5SDimitry Andrictypedef regex_iterator<const char*>             cregex_iterator;
7000b57cec5SDimitry Andrictypedef regex_iterator<const wchar_t*>          wcregex_iterator;
7010b57cec5SDimitry Andrictypedef regex_iterator<string::const_iterator>  sregex_iterator;
7020b57cec5SDimitry Andrictypedef regex_iterator<wstring::const_iterator> wsregex_iterator;
7030b57cec5SDimitry Andric
7040b57cec5SDimitry Andrictemplate <class BidirectionalIterator,
7050b57cec5SDimitry Andric          class charT = typename iterator_traits<BidirectionalIterator>::value_type,
7060b57cec5SDimitry Andric          class traits = regex_traits<charT>>
7070b57cec5SDimitry Andricclass regex_token_iterator
7080b57cec5SDimitry Andric{
7090b57cec5SDimitry Andricpublic:
7100b57cec5SDimitry Andric    typedef basic_regex<charT, traits>       regex_type;
7110b57cec5SDimitry Andric    typedef sub_match<BidirectionalIterator> value_type;
7120b57cec5SDimitry Andric    typedef ptrdiff_t                        difference_type;
7130b57cec5SDimitry Andric    typedef const value_type*                pointer;
7140b57cec5SDimitry Andric    typedef const value_type&                reference;
7150b57cec5SDimitry Andric    typedef forward_iterator_tag             iterator_category;
7160b57cec5SDimitry Andric
7170b57cec5SDimitry Andric    regex_token_iterator();
7180b57cec5SDimitry Andric    regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
7190b57cec5SDimitry Andric                         const regex_type& re, int submatch = 0,
7200b57cec5SDimitry Andric                         regex_constants::match_flag_type m = regex_constants::match_default);
7210b57cec5SDimitry Andric    regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
7220b57cec5SDimitry Andric                         const regex_type&& re, int submatch = 0,
7230b57cec5SDimitry Andric                         regex_constants::match_flag_type m = regex_constants::match_default) = delete; // C++14
7240b57cec5SDimitry Andric    regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
7250b57cec5SDimitry Andric                         const regex_type& re, const vector<int>& submatches,
7260b57cec5SDimitry Andric                         regex_constants::match_flag_type m = regex_constants::match_default);
7270b57cec5SDimitry Andric    regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
7280b57cec5SDimitry Andric                         const regex_type&& re, const vector<int>& submatches,
7290b57cec5SDimitry Andric                         regex_constants::match_flag_type m = regex_constants::match_default) = delete; // C++14
7300b57cec5SDimitry Andric    regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
7310b57cec5SDimitry Andric                         const regex_type& re, initializer_list<int> submatches,
7320b57cec5SDimitry Andric                         regex_constants::match_flag_type m = regex_constants::match_default);
7330b57cec5SDimitry Andric    regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
7340b57cec5SDimitry Andric                         const regex_type&& re, initializer_list<int> submatches,
7350b57cec5SDimitry Andric                         regex_constants::match_flag_type m = regex_constants::match_default) = delete; // C++14
7360b57cec5SDimitry Andric    template <size_t N>
7370b57cec5SDimitry Andric        regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
7380b57cec5SDimitry Andric                             const regex_type& re, const int (&submatches)[N],
7390b57cec5SDimitry Andric                             regex_constants::match_flag_type m = regex_constants::match_default);
7400b57cec5SDimitry Andric    template <size_t N>
7410b57cec5SDimitry Andric        regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
7425ffd83dbSDimitry Andric                             const regex_type&& re, const int (&submatches)[N],
7435ffd83dbSDimitry Andric                             regex_constants::match_flag_type m = regex_constants::match_default) = delete; // C++14
7440b57cec5SDimitry Andric    regex_token_iterator(const regex_token_iterator&);
7450b57cec5SDimitry Andric    regex_token_iterator& operator=(const regex_token_iterator&);
7460b57cec5SDimitry Andric
7470b57cec5SDimitry Andric    bool operator==(const regex_token_iterator&) const;
7480b57cec5SDimitry Andric    bool operator!=(const regex_token_iterator&) const;
7490b57cec5SDimitry Andric
7500b57cec5SDimitry Andric    const value_type& operator*() const;
7510b57cec5SDimitry Andric    const value_type* operator->() const;
7520b57cec5SDimitry Andric
7530b57cec5SDimitry Andric    regex_token_iterator& operator++();
7540b57cec5SDimitry Andric    regex_token_iterator operator++(int);
7550b57cec5SDimitry Andric};
7560b57cec5SDimitry Andric
7570b57cec5SDimitry Andrictypedef regex_token_iterator<const char*>             cregex_token_iterator;
7580b57cec5SDimitry Andrictypedef regex_token_iterator<const wchar_t*>          wcregex_token_iterator;
7590b57cec5SDimitry Andrictypedef regex_token_iterator<string::const_iterator>  sregex_token_iterator;
7600b57cec5SDimitry Andrictypedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator;
7610b57cec5SDimitry Andric
7620b57cec5SDimitry Andric} // std
7630b57cec5SDimitry Andric*/
7640b57cec5SDimitry Andric
76581ad6265SDimitry Andric#include <__algorithm/find.h>
76681ad6265SDimitry Andric#include <__algorithm/search.h>
76781ad6265SDimitry Andric#include <__assert> // all public C++ headers provide the assertion handler
7680b57cec5SDimitry Andric#include <__config>
76981ad6265SDimitry Andric#include <__iterator/back_insert_iterator.h>
770fe6060f1SDimitry Andric#include <__iterator/wrap_iter.h>
7710b57cec5SDimitry Andric#include <__locale>
77281ad6265SDimitry Andric#include <__utility/move.h>
77381ad6265SDimitry Andric#include <__utility/swap.h>
7740b57cec5SDimitry Andric#include <deque>
775fe6060f1SDimitry Andric#include <memory>
776fe6060f1SDimitry Andric#include <stdexcept>
777fe6060f1SDimitry Andric#include <string>
778fe6060f1SDimitry Andric#include <vector>
7790b57cec5SDimitry Andric#include <version>
7800b57cec5SDimitry Andric
78181ad6265SDimitry Andric#ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES
78281ad6265SDimitry Andric#  include <iterator>
78381ad6265SDimitry Andric#  include <utility>
78481ad6265SDimitry Andric#endif
78581ad6265SDimitry Andric
78681ad6265SDimitry Andric// standard-mandated includes
78781ad6265SDimitry Andric
78881ad6265SDimitry Andric// [iterator.range]
78981ad6265SDimitry Andric#include <__iterator/access.h>
79081ad6265SDimitry Andric#include <__iterator/data.h>
79181ad6265SDimitry Andric#include <__iterator/empty.h>
79281ad6265SDimitry Andric#include <__iterator/reverse_access.h>
79381ad6265SDimitry Andric#include <__iterator/size.h>
79481ad6265SDimitry Andric
79581ad6265SDimitry Andric// [re.syn]
79681ad6265SDimitry Andric#include <compare>
79781ad6265SDimitry Andric#include <initializer_list>
79881ad6265SDimitry Andric
7990b57cec5SDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
8000b57cec5SDimitry Andric#  pragma GCC system_header
8010b57cec5SDimitry Andric#endif
8020b57cec5SDimitry Andric
8030b57cec5SDimitry Andric_LIBCPP_PUSH_MACROS
8040b57cec5SDimitry Andric#include <__undef_macros>
8050b57cec5SDimitry Andric
8060b57cec5SDimitry Andric
8070b57cec5SDimitry Andric#define _LIBCPP_REGEX_COMPLEXITY_FACTOR 4096
8080b57cec5SDimitry Andric
8090b57cec5SDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD
8100b57cec5SDimitry Andric
8110b57cec5SDimitry Andricnamespace regex_constants
8120b57cec5SDimitry Andric{
8130b57cec5SDimitry Andric
8140b57cec5SDimitry Andric// syntax_option_type
8150b57cec5SDimitry Andric
8160b57cec5SDimitry Andricenum syntax_option_type
8170b57cec5SDimitry Andric{
8180b57cec5SDimitry Andric    icase      = 1 << 0,
8190b57cec5SDimitry Andric    nosubs     = 1 << 1,
8200b57cec5SDimitry Andric    optimize   = 1 << 2,
8210b57cec5SDimitry Andric    collate    = 1 << 3,
8220b57cec5SDimitry Andric#ifdef _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO
8230b57cec5SDimitry Andric    ECMAScript = 1 << 9,
8240b57cec5SDimitry Andric#else
8250b57cec5SDimitry Andric    ECMAScript = 0,
8260b57cec5SDimitry Andric#endif
8270b57cec5SDimitry Andric    basic      = 1 << 4,
8280b57cec5SDimitry Andric    extended   = 1 << 5,
8290b57cec5SDimitry Andric    awk        = 1 << 6,
8300b57cec5SDimitry Andric    grep       = 1 << 7,
831e8d8bef9SDimitry Andric    egrep      = 1 << 8,
832e8d8bef9SDimitry Andric    // 1 << 9 may be used by ECMAScript
833e8d8bef9SDimitry Andric    multiline  = 1 << 10
8340b57cec5SDimitry Andric};
8350b57cec5SDimitry Andric
8360b57cec5SDimitry Andricinline _LIBCPP_CONSTEXPR
8370b57cec5SDimitry Andricsyntax_option_type __get_grammar(syntax_option_type __g)
8380b57cec5SDimitry Andric{
8390b57cec5SDimitry Andric#ifdef _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO
8400b57cec5SDimitry Andric    return static_cast<syntax_option_type>(__g & 0x3F0);
8410b57cec5SDimitry Andric#else
8420b57cec5SDimitry Andric    return static_cast<syntax_option_type>(__g & 0x1F0);
8430b57cec5SDimitry Andric#endif
8440b57cec5SDimitry Andric}
8450b57cec5SDimitry Andric
8460b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
8470b57cec5SDimitry Andric_LIBCPP_CONSTEXPR
8480b57cec5SDimitry Andricsyntax_option_type
8490b57cec5SDimitry Andricoperator~(syntax_option_type __x)
8500b57cec5SDimitry Andric{
8510b57cec5SDimitry Andric    return syntax_option_type(~int(__x) & 0x1FF);
8520b57cec5SDimitry Andric}
8530b57cec5SDimitry Andric
8540b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
8550b57cec5SDimitry Andric_LIBCPP_CONSTEXPR
8560b57cec5SDimitry Andricsyntax_option_type
8570b57cec5SDimitry Andricoperator&(syntax_option_type __x, syntax_option_type __y)
8580b57cec5SDimitry Andric{
8590b57cec5SDimitry Andric    return syntax_option_type(int(__x) & int(__y));
8600b57cec5SDimitry Andric}
8610b57cec5SDimitry Andric
8620b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
8630b57cec5SDimitry Andric_LIBCPP_CONSTEXPR
8640b57cec5SDimitry Andricsyntax_option_type
8650b57cec5SDimitry Andricoperator|(syntax_option_type __x, syntax_option_type __y)
8660b57cec5SDimitry Andric{
8670b57cec5SDimitry Andric    return syntax_option_type(int(__x) | int(__y));
8680b57cec5SDimitry Andric}
8690b57cec5SDimitry Andric
8700b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
8710b57cec5SDimitry Andric_LIBCPP_CONSTEXPR
8720b57cec5SDimitry Andricsyntax_option_type
8730b57cec5SDimitry Andricoperator^(syntax_option_type __x, syntax_option_type __y)
8740b57cec5SDimitry Andric{
8750b57cec5SDimitry Andric    return syntax_option_type(int(__x) ^ int(__y));
8760b57cec5SDimitry Andric}
8770b57cec5SDimitry Andric
8780b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
8790b57cec5SDimitry Andricsyntax_option_type&
8800b57cec5SDimitry Andricoperator&=(syntax_option_type& __x, syntax_option_type __y)
8810b57cec5SDimitry Andric{
8820b57cec5SDimitry Andric    __x = __x & __y;
8830b57cec5SDimitry Andric    return __x;
8840b57cec5SDimitry Andric}
8850b57cec5SDimitry Andric
8860b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
8870b57cec5SDimitry Andricsyntax_option_type&
8880b57cec5SDimitry Andricoperator|=(syntax_option_type& __x, syntax_option_type __y)
8890b57cec5SDimitry Andric{
8900b57cec5SDimitry Andric    __x = __x | __y;
8910b57cec5SDimitry Andric    return __x;
8920b57cec5SDimitry Andric}
8930b57cec5SDimitry Andric
8940b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
8950b57cec5SDimitry Andricsyntax_option_type&
8960b57cec5SDimitry Andricoperator^=(syntax_option_type& __x, syntax_option_type __y)
8970b57cec5SDimitry Andric{
8980b57cec5SDimitry Andric    __x = __x ^ __y;
8990b57cec5SDimitry Andric    return __x;
9000b57cec5SDimitry Andric}
9010b57cec5SDimitry Andric
9020b57cec5SDimitry Andric// match_flag_type
9030b57cec5SDimitry Andric
9040b57cec5SDimitry Andricenum match_flag_type
9050b57cec5SDimitry Andric{
9060b57cec5SDimitry Andric    match_default     = 0,
9070b57cec5SDimitry Andric    match_not_bol     = 1 << 0,
9080b57cec5SDimitry Andric    match_not_eol     = 1 << 1,
9090b57cec5SDimitry Andric    match_not_bow     = 1 << 2,
9100b57cec5SDimitry Andric    match_not_eow     = 1 << 3,
9110b57cec5SDimitry Andric    match_any         = 1 << 4,
9120b57cec5SDimitry Andric    match_not_null    = 1 << 5,
9130b57cec5SDimitry Andric    match_continuous  = 1 << 6,
9140b57cec5SDimitry Andric    match_prev_avail  = 1 << 7,
9150b57cec5SDimitry Andric    format_default    = 0,
9160b57cec5SDimitry Andric    format_sed        = 1 << 8,
9170b57cec5SDimitry Andric    format_no_copy    = 1 << 9,
9180b57cec5SDimitry Andric    format_first_only = 1 << 10,
9190b57cec5SDimitry Andric    __no_update_pos   = 1 << 11,
9200b57cec5SDimitry Andric    __full_match      = 1 << 12
9210b57cec5SDimitry Andric};
9220b57cec5SDimitry Andric
9230b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
9240b57cec5SDimitry Andric_LIBCPP_CONSTEXPR
9250b57cec5SDimitry Andricmatch_flag_type
9260b57cec5SDimitry Andricoperator~(match_flag_type __x)
9270b57cec5SDimitry Andric{
9280b57cec5SDimitry Andric    return match_flag_type(~int(__x) & 0x0FFF);
9290b57cec5SDimitry Andric}
9300b57cec5SDimitry Andric
9310b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
9320b57cec5SDimitry Andric_LIBCPP_CONSTEXPR
9330b57cec5SDimitry Andricmatch_flag_type
9340b57cec5SDimitry Andricoperator&(match_flag_type __x, match_flag_type __y)
9350b57cec5SDimitry Andric{
9360b57cec5SDimitry Andric    return match_flag_type(int(__x) & int(__y));
9370b57cec5SDimitry Andric}
9380b57cec5SDimitry Andric
9390b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
9400b57cec5SDimitry Andric_LIBCPP_CONSTEXPR
9410b57cec5SDimitry Andricmatch_flag_type
9420b57cec5SDimitry Andricoperator|(match_flag_type __x, match_flag_type __y)
9430b57cec5SDimitry Andric{
9440b57cec5SDimitry Andric    return match_flag_type(int(__x) | int(__y));
9450b57cec5SDimitry Andric}
9460b57cec5SDimitry Andric
9470b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
9480b57cec5SDimitry Andric_LIBCPP_CONSTEXPR
9490b57cec5SDimitry Andricmatch_flag_type
9500b57cec5SDimitry Andricoperator^(match_flag_type __x, match_flag_type __y)
9510b57cec5SDimitry Andric{
9520b57cec5SDimitry Andric    return match_flag_type(int(__x) ^ int(__y));
9530b57cec5SDimitry Andric}
9540b57cec5SDimitry Andric
9550b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
9560b57cec5SDimitry Andricmatch_flag_type&
9570b57cec5SDimitry Andricoperator&=(match_flag_type& __x, match_flag_type __y)
9580b57cec5SDimitry Andric{
9590b57cec5SDimitry Andric    __x = __x & __y;
9600b57cec5SDimitry Andric    return __x;
9610b57cec5SDimitry Andric}
9620b57cec5SDimitry Andric
9630b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
9640b57cec5SDimitry Andricmatch_flag_type&
9650b57cec5SDimitry Andricoperator|=(match_flag_type& __x, match_flag_type __y)
9660b57cec5SDimitry Andric{
9670b57cec5SDimitry Andric    __x = __x | __y;
9680b57cec5SDimitry Andric    return __x;
9690b57cec5SDimitry Andric}
9700b57cec5SDimitry Andric
9710b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
9720b57cec5SDimitry Andricmatch_flag_type&
9730b57cec5SDimitry Andricoperator^=(match_flag_type& __x, match_flag_type __y)
9740b57cec5SDimitry Andric{
9750b57cec5SDimitry Andric    __x = __x ^ __y;
9760b57cec5SDimitry Andric    return __x;
9770b57cec5SDimitry Andric}
9780b57cec5SDimitry Andric
9790b57cec5SDimitry Andricenum error_type
9800b57cec5SDimitry Andric{
9810b57cec5SDimitry Andric    error_collate = 1,
9820b57cec5SDimitry Andric    error_ctype,
9830b57cec5SDimitry Andric    error_escape,
9840b57cec5SDimitry Andric    error_backref,
9850b57cec5SDimitry Andric    error_brack,
9860b57cec5SDimitry Andric    error_paren,
9870b57cec5SDimitry Andric    error_brace,
9880b57cec5SDimitry Andric    error_badbrace,
9890b57cec5SDimitry Andric    error_range,
9900b57cec5SDimitry Andric    error_space,
9910b57cec5SDimitry Andric    error_badrepeat,
9920b57cec5SDimitry Andric    error_complexity,
9930b57cec5SDimitry Andric    error_stack,
9940b57cec5SDimitry Andric    __re_err_grammar,
9950b57cec5SDimitry Andric    __re_err_empty,
996480093f4SDimitry Andric    __re_err_unknown,
997480093f4SDimitry Andric    __re_err_parse
9980b57cec5SDimitry Andric};
9990b57cec5SDimitry Andric
10000eae32dcSDimitry Andric} // namespace regex_constants
10010b57cec5SDimitry Andric
10020b57cec5SDimitry Andricclass _LIBCPP_EXCEPTION_ABI regex_error
10030b57cec5SDimitry Andric    : public runtime_error
10040b57cec5SDimitry Andric{
10050b57cec5SDimitry Andric    regex_constants::error_type __code_;
10060b57cec5SDimitry Andricpublic:
10070b57cec5SDimitry Andric    explicit regex_error(regex_constants::error_type __ecode);
10089ec406dcSDimitry Andric    regex_error(const regex_error&) _NOEXCEPT = default;
10099ec406dcSDimitry Andric    virtual ~regex_error() _NOEXCEPT;
10100b57cec5SDimitry Andric     _LIBCPP_INLINE_VISIBILITY
10110b57cec5SDimitry Andric    regex_constants::error_type code() const {return __code_;}
10120b57cec5SDimitry Andric};
10130b57cec5SDimitry Andric
10140b57cec5SDimitry Andrictemplate <regex_constants::error_type _Ev>
10150b57cec5SDimitry Andric_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
10160b57cec5SDimitry Andricvoid __throw_regex_error()
10170b57cec5SDimitry Andric{
10180b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS
10190b57cec5SDimitry Andric    throw regex_error(_Ev);
10200b57cec5SDimitry Andric#else
10210b57cec5SDimitry Andric    _VSTD::abort();
10220b57cec5SDimitry Andric#endif
10230b57cec5SDimitry Andric}
10240b57cec5SDimitry Andric
10250b57cec5SDimitry Andrictemplate <class _CharT>
10260b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS regex_traits
10270b57cec5SDimitry Andric{
10280b57cec5SDimitry Andricpublic:
10290b57cec5SDimitry Andric    typedef _CharT                  char_type;
10300b57cec5SDimitry Andric    typedef basic_string<char_type> string_type;
10310b57cec5SDimitry Andric    typedef locale                  locale_type;
10325ffd83dbSDimitry Andric#ifdef __BIONIC__
10335ffd83dbSDimitry Andric    // Originally bionic's ctype_base used its own ctype masks because the
10345ffd83dbSDimitry Andric    // builtin ctype implementation wasn't in libc++ yet. Bionic's ctype mask
10355ffd83dbSDimitry Andric    // was only 8 bits wide and already saturated, so it used a wider type here
10365ffd83dbSDimitry Andric    // to make room for __regex_word (then a part of this class rather than
10375ffd83dbSDimitry Andric    // ctype_base). Bionic has since moved to the builtin ctype_base
10385ffd83dbSDimitry Andric    // implementation, but this was not updated to match. Since then Android has
10395ffd83dbSDimitry Andric    // needed to maintain a stable libc++ ABI, and this can't be changed without
10405ffd83dbSDimitry Andric    // an ABI break.
10415ffd83dbSDimitry Andric    typedef uint16_t char_class_type;
10425ffd83dbSDimitry Andric#else
10430b57cec5SDimitry Andric    typedef ctype_base::mask        char_class_type;
10445ffd83dbSDimitry Andric#endif
10450b57cec5SDimitry Andric
10460b57cec5SDimitry Andric    static const char_class_type __regex_word = ctype_base::__regex_word;
10470b57cec5SDimitry Andricprivate:
10480b57cec5SDimitry Andric    locale __loc_;
10490b57cec5SDimitry Andric    const ctype<char_type>* __ct_;
10500b57cec5SDimitry Andric    const collate<char_type>* __col_;
10510b57cec5SDimitry Andric
10520b57cec5SDimitry Andricpublic:
10530b57cec5SDimitry Andric    regex_traits();
10540b57cec5SDimitry Andric
10550b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
10560b57cec5SDimitry Andric    static size_t length(const char_type* __p)
10570b57cec5SDimitry Andric        {return char_traits<char_type>::length(__p);}
10580b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
10590b57cec5SDimitry Andric    char_type translate(char_type __c) const {return __c;}
10600b57cec5SDimitry Andric    char_type translate_nocase(char_type __c) const;
10610b57cec5SDimitry Andric    template <class _ForwardIterator>
10620b57cec5SDimitry Andric        string_type
10630b57cec5SDimitry Andric        transform(_ForwardIterator __f, _ForwardIterator __l) const;
10640b57cec5SDimitry Andric    template <class _ForwardIterator>
10650b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
10660b57cec5SDimitry Andric        string_type
10670b57cec5SDimitry Andric        transform_primary( _ForwardIterator __f, _ForwardIterator __l) const
10680b57cec5SDimitry Andric            {return __transform_primary(__f, __l, char_type());}
10690b57cec5SDimitry Andric    template <class _ForwardIterator>
10700b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
10710b57cec5SDimitry Andric        string_type
10720b57cec5SDimitry Andric        lookup_collatename(_ForwardIterator __f, _ForwardIterator __l) const
10730b57cec5SDimitry Andric            {return __lookup_collatename(__f, __l, char_type());}
10740b57cec5SDimitry Andric    template <class _ForwardIterator>
10750b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
10760b57cec5SDimitry Andric        char_class_type
10770b57cec5SDimitry Andric        lookup_classname(_ForwardIterator __f, _ForwardIterator __l,
10780b57cec5SDimitry Andric                         bool __icase = false) const
10790b57cec5SDimitry Andric            {return __lookup_classname(__f, __l, __icase, char_type());}
10800b57cec5SDimitry Andric    bool isctype(char_type __c, char_class_type __m) const;
10810b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
10820b57cec5SDimitry Andric    int value(char_type __ch, int __radix) const
10830b57cec5SDimitry Andric        {return __regex_traits_value(__ch, __radix);}
10840b57cec5SDimitry Andric    locale_type imbue(locale_type __l);
10850b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
10860b57cec5SDimitry Andric    locale_type getloc()const {return __loc_;}
10870b57cec5SDimitry Andric
10880b57cec5SDimitry Andricprivate:
10890b57cec5SDimitry Andric    void __init();
10900b57cec5SDimitry Andric
10910b57cec5SDimitry Andric    template <class _ForwardIterator>
10920b57cec5SDimitry Andric        string_type
10930b57cec5SDimitry Andric        __transform_primary(_ForwardIterator __f, _ForwardIterator __l, char) const;
1094349cc55cSDimitry Andric#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
10950b57cec5SDimitry Andric    template <class _ForwardIterator>
10960b57cec5SDimitry Andric        string_type
10970b57cec5SDimitry Andric        __transform_primary(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const;
1098349cc55cSDimitry Andric#endif
10990b57cec5SDimitry Andric    template <class _ForwardIterator>
11000b57cec5SDimitry Andric        string_type
11010b57cec5SDimitry Andric        __lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, char) const;
1102349cc55cSDimitry Andric#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
11030b57cec5SDimitry Andric    template <class _ForwardIterator>
11040b57cec5SDimitry Andric        string_type
11050b57cec5SDimitry Andric        __lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const;
1106349cc55cSDimitry Andric#endif
11070b57cec5SDimitry Andric    template <class _ForwardIterator>
11080b57cec5SDimitry Andric        char_class_type
11090b57cec5SDimitry Andric        __lookup_classname(_ForwardIterator __f, _ForwardIterator __l,
11100b57cec5SDimitry Andric                           bool __icase, char) const;
1111349cc55cSDimitry Andric#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
11120b57cec5SDimitry Andric    template <class _ForwardIterator>
11130b57cec5SDimitry Andric        char_class_type
11140b57cec5SDimitry Andric        __lookup_classname(_ForwardIterator __f, _ForwardIterator __l,
11150b57cec5SDimitry Andric                           bool __icase, wchar_t) const;
1116349cc55cSDimitry Andric#endif
11170b57cec5SDimitry Andric
11180b57cec5SDimitry Andric    static int __regex_traits_value(unsigned char __ch, int __radix);
11190b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11200b57cec5SDimitry Andric    int __regex_traits_value(char __ch, int __radix) const
11210b57cec5SDimitry Andric        {return __regex_traits_value(static_cast<unsigned char>(__ch), __radix);}
1122349cc55cSDimitry Andric#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
11230b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11240b57cec5SDimitry Andric    int __regex_traits_value(wchar_t __ch, int __radix) const;
1125349cc55cSDimitry Andric#endif
11260b57cec5SDimitry Andric};
11270b57cec5SDimitry Andric
11280b57cec5SDimitry Andrictemplate <class _CharT>
11290b57cec5SDimitry Andricconst typename regex_traits<_CharT>::char_class_type
11300b57cec5SDimitry Andricregex_traits<_CharT>::__regex_word;
11310b57cec5SDimitry Andric
11320b57cec5SDimitry Andrictemplate <class _CharT>
11330b57cec5SDimitry Andricregex_traits<_CharT>::regex_traits()
11340b57cec5SDimitry Andric{
11350b57cec5SDimitry Andric    __init();
11360b57cec5SDimitry Andric}
11370b57cec5SDimitry Andric
11380b57cec5SDimitry Andrictemplate <class _CharT>
11390b57cec5SDimitry Andrictypename regex_traits<_CharT>::char_type
11400b57cec5SDimitry Andricregex_traits<_CharT>::translate_nocase(char_type __c) const
11410b57cec5SDimitry Andric{
11420b57cec5SDimitry Andric    return __ct_->tolower(__c);
11430b57cec5SDimitry Andric}
11440b57cec5SDimitry Andric
11450b57cec5SDimitry Andrictemplate <class _CharT>
11460b57cec5SDimitry Andrictemplate <class _ForwardIterator>
11470b57cec5SDimitry Andrictypename regex_traits<_CharT>::string_type
11480b57cec5SDimitry Andricregex_traits<_CharT>::transform(_ForwardIterator __f, _ForwardIterator __l) const
11490b57cec5SDimitry Andric{
11500b57cec5SDimitry Andric    string_type __s(__f, __l);
11510b57cec5SDimitry Andric    return __col_->transform(__s.data(), __s.data() + __s.size());
11520b57cec5SDimitry Andric}
11530b57cec5SDimitry Andric
11540b57cec5SDimitry Andrictemplate <class _CharT>
11550b57cec5SDimitry Andricvoid
11560b57cec5SDimitry Andricregex_traits<_CharT>::__init()
11570b57cec5SDimitry Andric{
11580b57cec5SDimitry Andric    __ct_ = &use_facet<ctype<char_type> >(__loc_);
11590b57cec5SDimitry Andric    __col_ = &use_facet<collate<char_type> >(__loc_);
11600b57cec5SDimitry Andric}
11610b57cec5SDimitry Andric
11620b57cec5SDimitry Andrictemplate <class _CharT>
11630b57cec5SDimitry Andrictypename regex_traits<_CharT>::locale_type
11640b57cec5SDimitry Andricregex_traits<_CharT>::imbue(locale_type __l)
11650b57cec5SDimitry Andric{
11660b57cec5SDimitry Andric    locale __r = __loc_;
11670b57cec5SDimitry Andric    __loc_ = __l;
11680b57cec5SDimitry Andric    __init();
11690b57cec5SDimitry Andric    return __r;
11700b57cec5SDimitry Andric}
11710b57cec5SDimitry Andric
11720b57cec5SDimitry Andric// transform_primary is very FreeBSD-specific
11730b57cec5SDimitry Andric
11740b57cec5SDimitry Andrictemplate <class _CharT>
11750b57cec5SDimitry Andrictemplate <class _ForwardIterator>
11760b57cec5SDimitry Andrictypename regex_traits<_CharT>::string_type
11770b57cec5SDimitry Andricregex_traits<_CharT>::__transform_primary(_ForwardIterator __f,
11780b57cec5SDimitry Andric                                          _ForwardIterator __l, char) const
11790b57cec5SDimitry Andric{
11800b57cec5SDimitry Andric    const string_type __s(__f, __l);
11810b57cec5SDimitry Andric    string_type __d = __col_->transform(__s.data(), __s.data() + __s.size());
11820b57cec5SDimitry Andric    switch (__d.size())
11830b57cec5SDimitry Andric    {
11840b57cec5SDimitry Andric    case 1:
11850b57cec5SDimitry Andric        break;
11860b57cec5SDimitry Andric    case 12:
11870b57cec5SDimitry Andric        __d[11] = __d[3];
11880b57cec5SDimitry Andric        break;
11890b57cec5SDimitry Andric    default:
11900b57cec5SDimitry Andric        __d.clear();
11910b57cec5SDimitry Andric        break;
11920b57cec5SDimitry Andric    }
11930b57cec5SDimitry Andric    return __d;
11940b57cec5SDimitry Andric}
11950b57cec5SDimitry Andric
1196349cc55cSDimitry Andric#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
11970b57cec5SDimitry Andrictemplate <class _CharT>
11980b57cec5SDimitry Andrictemplate <class _ForwardIterator>
11990b57cec5SDimitry Andrictypename regex_traits<_CharT>::string_type
12000b57cec5SDimitry Andricregex_traits<_CharT>::__transform_primary(_ForwardIterator __f,
12010b57cec5SDimitry Andric                                          _ForwardIterator __l, wchar_t) const
12020b57cec5SDimitry Andric{
12030b57cec5SDimitry Andric    const string_type __s(__f, __l);
12040b57cec5SDimitry Andric    string_type __d = __col_->transform(__s.data(), __s.data() + __s.size());
12050b57cec5SDimitry Andric    switch (__d.size())
12060b57cec5SDimitry Andric    {
12070b57cec5SDimitry Andric    case 1:
12080b57cec5SDimitry Andric        break;
12090b57cec5SDimitry Andric    case 3:
12100b57cec5SDimitry Andric        __d[2] = __d[0];
12110b57cec5SDimitry Andric        break;
12120b57cec5SDimitry Andric    default:
12130b57cec5SDimitry Andric        __d.clear();
12140b57cec5SDimitry Andric        break;
12150b57cec5SDimitry Andric    }
12160b57cec5SDimitry Andric    return __d;
12170b57cec5SDimitry Andric}
1218349cc55cSDimitry Andric#endif
12190b57cec5SDimitry Andric
12200b57cec5SDimitry Andric// lookup_collatename is very FreeBSD-specific
12210b57cec5SDimitry Andric
12220b57cec5SDimitry Andric_LIBCPP_FUNC_VIS string __get_collation_name(const char* __s);
12230b57cec5SDimitry Andric
12240b57cec5SDimitry Andrictemplate <class _CharT>
12250b57cec5SDimitry Andrictemplate <class _ForwardIterator>
12260b57cec5SDimitry Andrictypename regex_traits<_CharT>::string_type
12270b57cec5SDimitry Andricregex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f,
12280b57cec5SDimitry Andric                                           _ForwardIterator __l, char) const
12290b57cec5SDimitry Andric{
12300b57cec5SDimitry Andric    string_type __s(__f, __l);
12310b57cec5SDimitry Andric    string_type __r;
12320b57cec5SDimitry Andric    if (!__s.empty())
12330b57cec5SDimitry Andric    {
12340b57cec5SDimitry Andric        __r = __get_collation_name(__s.c_str());
12350b57cec5SDimitry Andric        if (__r.empty() && __s.size() <= 2)
12360b57cec5SDimitry Andric        {
12370b57cec5SDimitry Andric            __r = __col_->transform(__s.data(), __s.data() + __s.size());
12380b57cec5SDimitry Andric            if (__r.size() == 1 || __r.size() == 12)
12390b57cec5SDimitry Andric                __r = __s;
12400b57cec5SDimitry Andric            else
12410b57cec5SDimitry Andric                __r.clear();
12420b57cec5SDimitry Andric        }
12430b57cec5SDimitry Andric    }
12440b57cec5SDimitry Andric    return __r;
12450b57cec5SDimitry Andric}
12460b57cec5SDimitry Andric
1247349cc55cSDimitry Andric#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
12480b57cec5SDimitry Andrictemplate <class _CharT>
12490b57cec5SDimitry Andrictemplate <class _ForwardIterator>
12500b57cec5SDimitry Andrictypename regex_traits<_CharT>::string_type
12510b57cec5SDimitry Andricregex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f,
12520b57cec5SDimitry Andric                                           _ForwardIterator __l, wchar_t) const
12530b57cec5SDimitry Andric{
12540b57cec5SDimitry Andric    string_type __s(__f, __l);
12550b57cec5SDimitry Andric    string __n;
12560b57cec5SDimitry Andric    __n.reserve(__s.size());
12570b57cec5SDimitry Andric    for (typename string_type::const_iterator __i = __s.begin(), __e = __s.end();
12580b57cec5SDimitry Andric                                                              __i != __e; ++__i)
12590b57cec5SDimitry Andric    {
12600b57cec5SDimitry Andric        if (static_cast<unsigned>(*__i) >= 127)
12610b57cec5SDimitry Andric            return string_type();
12620b57cec5SDimitry Andric        __n.push_back(char(*__i));
12630b57cec5SDimitry Andric    }
12640b57cec5SDimitry Andric    string_type __r;
12650b57cec5SDimitry Andric    if (!__s.empty())
12660b57cec5SDimitry Andric    {
12670b57cec5SDimitry Andric        __n = __get_collation_name(__n.c_str());
12680b57cec5SDimitry Andric        if (!__n.empty())
12690b57cec5SDimitry Andric            __r.assign(__n.begin(), __n.end());
12700b57cec5SDimitry Andric        else if (__s.size() <= 2)
12710b57cec5SDimitry Andric        {
12720b57cec5SDimitry Andric            __r = __col_->transform(__s.data(), __s.data() + __s.size());
12730b57cec5SDimitry Andric            if (__r.size() == 1 || __r.size() == 3)
12740b57cec5SDimitry Andric                __r = __s;
12750b57cec5SDimitry Andric            else
12760b57cec5SDimitry Andric                __r.clear();
12770b57cec5SDimitry Andric        }
12780b57cec5SDimitry Andric    }
12790b57cec5SDimitry Andric    return __r;
12800b57cec5SDimitry Andric}
1281349cc55cSDimitry Andric#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
12820b57cec5SDimitry Andric
12830b57cec5SDimitry Andric// lookup_classname
12840b57cec5SDimitry Andric
12850b57cec5SDimitry Andricregex_traits<char>::char_class_type _LIBCPP_FUNC_VIS
12860b57cec5SDimitry Andric__get_classname(const char* __s, bool __icase);
12870b57cec5SDimitry Andric
12880b57cec5SDimitry Andrictemplate <class _CharT>
12890b57cec5SDimitry Andrictemplate <class _ForwardIterator>
12900b57cec5SDimitry Andrictypename regex_traits<_CharT>::char_class_type
12910b57cec5SDimitry Andricregex_traits<_CharT>::__lookup_classname(_ForwardIterator __f,
12920b57cec5SDimitry Andric                                         _ForwardIterator __l,
12930b57cec5SDimitry Andric                                         bool __icase, char) const
12940b57cec5SDimitry Andric{
12950b57cec5SDimitry Andric    string_type __s(__f, __l);
12960b57cec5SDimitry Andric    __ct_->tolower(&__s[0], &__s[0] + __s.size());
12970b57cec5SDimitry Andric    return __get_classname(__s.c_str(), __icase);
12980b57cec5SDimitry Andric}
12990b57cec5SDimitry Andric
1300349cc55cSDimitry Andric#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
13010b57cec5SDimitry Andrictemplate <class _CharT>
13020b57cec5SDimitry Andrictemplate <class _ForwardIterator>
13030b57cec5SDimitry Andrictypename regex_traits<_CharT>::char_class_type
13040b57cec5SDimitry Andricregex_traits<_CharT>::__lookup_classname(_ForwardIterator __f,
13050b57cec5SDimitry Andric                                         _ForwardIterator __l,
13060b57cec5SDimitry Andric                                         bool __icase, wchar_t) const
13070b57cec5SDimitry Andric{
13080b57cec5SDimitry Andric    string_type __s(__f, __l);
13090b57cec5SDimitry Andric    __ct_->tolower(&__s[0], &__s[0] + __s.size());
13100b57cec5SDimitry Andric    string __n;
13110b57cec5SDimitry Andric    __n.reserve(__s.size());
13120b57cec5SDimitry Andric    for (typename string_type::const_iterator __i = __s.begin(), __e = __s.end();
13130b57cec5SDimitry Andric                                                              __i != __e; ++__i)
13140b57cec5SDimitry Andric    {
13150b57cec5SDimitry Andric        if (static_cast<unsigned>(*__i) >= 127)
13160b57cec5SDimitry Andric            return char_class_type();
13170b57cec5SDimitry Andric        __n.push_back(char(*__i));
13180b57cec5SDimitry Andric    }
13190b57cec5SDimitry Andric    return __get_classname(__n.c_str(), __icase);
13200b57cec5SDimitry Andric}
1321349cc55cSDimitry Andric#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
13220b57cec5SDimitry Andric
13230b57cec5SDimitry Andrictemplate <class _CharT>
13240b57cec5SDimitry Andricbool
13250b57cec5SDimitry Andricregex_traits<_CharT>::isctype(char_type __c, char_class_type __m) const
13260b57cec5SDimitry Andric{
13270b57cec5SDimitry Andric    if (__ct_->is(__m, __c))
13280b57cec5SDimitry Andric        return true;
13290b57cec5SDimitry Andric    return (__c == '_' && (__m & __regex_word));
13300b57cec5SDimitry Andric}
13310b57cec5SDimitry Andric
133204eeddc0SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
1333753f127fSDimitry Andricbool __is_07(unsigned char __c)
133404eeddc0SDimitry Andric{
1335753f127fSDimitry Andric    return (__c & 0xF8u) ==
133604eeddc0SDimitry Andric#if defined(__MVS__) && !defined(__NATIVE_ASCII_F)
133704eeddc0SDimitry Andric        0xF0;
133804eeddc0SDimitry Andric#else
133904eeddc0SDimitry Andric        0x30;
134004eeddc0SDimitry Andric#endif
134104eeddc0SDimitry Andric}
134204eeddc0SDimitry Andric
134304eeddc0SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
1344753f127fSDimitry Andricbool __is_89(unsigned char __c)
134504eeddc0SDimitry Andric{
1346753f127fSDimitry Andric    return (__c & 0xFEu) ==
134704eeddc0SDimitry Andric#if defined(__MVS__) && !defined(__NATIVE_ASCII_F)
134804eeddc0SDimitry Andric        0xF8;
134904eeddc0SDimitry Andric#else
135004eeddc0SDimitry Andric        0x38;
135104eeddc0SDimitry Andric#endif
135204eeddc0SDimitry Andric}
135304eeddc0SDimitry Andric
135404eeddc0SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
1355753f127fSDimitry Andricunsigned char __to_lower(unsigned char __c)
135604eeddc0SDimitry Andric{
135704eeddc0SDimitry Andric#if defined(__MVS__) && !defined(__NATIVE_ASCII_F)
1358*a4a491e2SDimitry Andric    return __c & 0xBF;
135904eeddc0SDimitry Andric#else
1360753f127fSDimitry Andric    return __c | 0x20;
136104eeddc0SDimitry Andric#endif
136204eeddc0SDimitry Andric}
136304eeddc0SDimitry Andric
13640b57cec5SDimitry Andrictemplate <class _CharT>
13650b57cec5SDimitry Andricint
13660b57cec5SDimitry Andricregex_traits<_CharT>::__regex_traits_value(unsigned char __ch, int __radix)
13670b57cec5SDimitry Andric{
136804eeddc0SDimitry Andric    if (__is_07(__ch))  // '0' <= __ch && __ch <= '7'
13690b57cec5SDimitry Andric        return __ch - '0';
13700b57cec5SDimitry Andric    if (__radix != 8)
13710b57cec5SDimitry Andric    {
137204eeddc0SDimitry Andric        if (__is_89(__ch))  // '8' <= __ch && __ch <= '9'
13730b57cec5SDimitry Andric            return __ch - '0';
13740b57cec5SDimitry Andric        if (__radix == 16)
13750b57cec5SDimitry Andric        {
137604eeddc0SDimitry Andric            __ch = __to_lower(__ch);  // tolower
13770b57cec5SDimitry Andric            if ('a' <= __ch && __ch <= 'f')
13780b57cec5SDimitry Andric                return __ch - ('a' - 10);
13790b57cec5SDimitry Andric        }
13800b57cec5SDimitry Andric    }
13810b57cec5SDimitry Andric    return -1;
13820b57cec5SDimitry Andric}
13830b57cec5SDimitry Andric
1384349cc55cSDimitry Andric#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
13850b57cec5SDimitry Andrictemplate <class _CharT>
13860b57cec5SDimitry Andricinline
13870b57cec5SDimitry Andricint
13880b57cec5SDimitry Andricregex_traits<_CharT>::__regex_traits_value(wchar_t __ch, int __radix) const
13890b57cec5SDimitry Andric{
13900b57cec5SDimitry Andric    return __regex_traits_value(static_cast<unsigned char>(__ct_->narrow(__ch, char_type())), __radix);
13910b57cec5SDimitry Andric}
1392349cc55cSDimitry Andric#endif
13930b57cec5SDimitry Andric
13940b57cec5SDimitry Andrictemplate <class _CharT> class __node;
13950b57cec5SDimitry Andric
13960b57cec5SDimitry Andrictemplate <class _BidirectionalIterator> class _LIBCPP_TEMPLATE_VIS sub_match;
13970b57cec5SDimitry Andric
13980b57cec5SDimitry Andrictemplate <class _BidirectionalIterator,
13990b57cec5SDimitry Andric          class _Allocator = allocator<sub_match<_BidirectionalIterator> > >
14000b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS match_results;
14010b57cec5SDimitry Andric
14020b57cec5SDimitry Andrictemplate <class _CharT>
14030b57cec5SDimitry Andricstruct __state
14040b57cec5SDimitry Andric{
14050b57cec5SDimitry Andric    enum
14060b57cec5SDimitry Andric    {
14070b57cec5SDimitry Andric        __end_state = -1000,
14080b57cec5SDimitry Andric        __consume_input,  // -999
14090b57cec5SDimitry Andric        __begin_marked_expr, // -998
14100b57cec5SDimitry Andric        __end_marked_expr,   // -997
14110b57cec5SDimitry Andric        __pop_state,           // -996
14120b57cec5SDimitry Andric        __accept_and_consume,  // -995
14130b57cec5SDimitry Andric        __accept_but_not_consume,  // -994
14140b57cec5SDimitry Andric        __reject,                  // -993
14150b57cec5SDimitry Andric        __split,
14160b57cec5SDimitry Andric        __repeat
14170b57cec5SDimitry Andric    };
14180b57cec5SDimitry Andric
14190b57cec5SDimitry Andric    int __do_;
14200b57cec5SDimitry Andric    const _CharT* __first_;
14210b57cec5SDimitry Andric    const _CharT* __current_;
14220b57cec5SDimitry Andric    const _CharT* __last_;
14230b57cec5SDimitry Andric    vector<sub_match<const _CharT*> > __sub_matches_;
14240b57cec5SDimitry Andric    vector<pair<size_t, const _CharT*> > __loop_data_;
14250b57cec5SDimitry Andric    const __node<_CharT>* __node_;
14260b57cec5SDimitry Andric    regex_constants::match_flag_type __flags_;
14270b57cec5SDimitry Andric    bool __at_first_;
14280b57cec5SDimitry Andric
14290b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
14300b57cec5SDimitry Andric    __state()
14310b57cec5SDimitry Andric        : __do_(0), __first_(nullptr), __current_(nullptr), __last_(nullptr),
14320b57cec5SDimitry Andric          __node_(nullptr), __flags_() {}
14330b57cec5SDimitry Andric};
14340b57cec5SDimitry Andric
14350b57cec5SDimitry Andric// __node
14360b57cec5SDimitry Andric
14370b57cec5SDimitry Andrictemplate <class _CharT>
14380b57cec5SDimitry Andricclass __node
14390b57cec5SDimitry Andric{
14400b57cec5SDimitry Andric    __node(const __node&);
14410b57cec5SDimitry Andric    __node& operator=(const __node&);
14420b57cec5SDimitry Andricpublic:
14430b57cec5SDimitry Andric    typedef _VSTD::__state<_CharT> __state;
14440b57cec5SDimitry Andric
14450b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
14460b57cec5SDimitry Andric    __node() {}
14470b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
14480b57cec5SDimitry Andric    virtual ~__node() {}
14490b57cec5SDimitry Andric
14500b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
14510b57cec5SDimitry Andric    virtual void __exec(__state&) const {}
14520b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
14530b57cec5SDimitry Andric    virtual void __exec_split(bool, __state&) const {}
14540b57cec5SDimitry Andric};
14550b57cec5SDimitry Andric
14560b57cec5SDimitry Andric// __end_state
14570b57cec5SDimitry Andric
14580b57cec5SDimitry Andrictemplate <class _CharT>
14590b57cec5SDimitry Andricclass __end_state
14600b57cec5SDimitry Andric    : public __node<_CharT>
14610b57cec5SDimitry Andric{
14620b57cec5SDimitry Andricpublic:
14630b57cec5SDimitry Andric    typedef _VSTD::__state<_CharT> __state;
14640b57cec5SDimitry Andric
14650b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
14660b57cec5SDimitry Andric    __end_state() {}
14670b57cec5SDimitry Andric
14680b57cec5SDimitry Andric    virtual void __exec(__state&) const;
14690b57cec5SDimitry Andric};
14700b57cec5SDimitry Andric
14710b57cec5SDimitry Andrictemplate <class _CharT>
14720b57cec5SDimitry Andricvoid
14730b57cec5SDimitry Andric__end_state<_CharT>::__exec(__state& __s) const
14740b57cec5SDimitry Andric{
14750b57cec5SDimitry Andric    __s.__do_ = __state::__end_state;
14760b57cec5SDimitry Andric}
14770b57cec5SDimitry Andric
14780b57cec5SDimitry Andric// __has_one_state
14790b57cec5SDimitry Andric
14800b57cec5SDimitry Andrictemplate <class _CharT>
14810b57cec5SDimitry Andricclass __has_one_state
14820b57cec5SDimitry Andric    : public __node<_CharT>
14830b57cec5SDimitry Andric{
14840b57cec5SDimitry Andric    __node<_CharT>* __first_;
14850b57cec5SDimitry Andric
14860b57cec5SDimitry Andricpublic:
14870b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
14880b57cec5SDimitry Andric    explicit __has_one_state(__node<_CharT>* __s)
14890b57cec5SDimitry Andric        : __first_(__s) {}
14900b57cec5SDimitry Andric
14910b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
14920b57cec5SDimitry Andric    __node<_CharT>*  first() const {return __first_;}
14930b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
14940b57cec5SDimitry Andric    __node<_CharT>*& first()       {return __first_;}
14950b57cec5SDimitry Andric};
14960b57cec5SDimitry Andric
14970b57cec5SDimitry Andric// __owns_one_state
14980b57cec5SDimitry Andric
14990b57cec5SDimitry Andrictemplate <class _CharT>
15000b57cec5SDimitry Andricclass __owns_one_state
15010b57cec5SDimitry Andric    : public __has_one_state<_CharT>
15020b57cec5SDimitry Andric{
15030b57cec5SDimitry Andric    typedef __has_one_state<_CharT> base;
15040b57cec5SDimitry Andric
15050b57cec5SDimitry Andricpublic:
15060b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
15070b57cec5SDimitry Andric    explicit __owns_one_state(__node<_CharT>* __s)
15080b57cec5SDimitry Andric        : base(__s) {}
15090b57cec5SDimitry Andric
15100b57cec5SDimitry Andric    virtual ~__owns_one_state();
15110b57cec5SDimitry Andric};
15120b57cec5SDimitry Andric
15130b57cec5SDimitry Andrictemplate <class _CharT>
15140b57cec5SDimitry Andric__owns_one_state<_CharT>::~__owns_one_state()
15150b57cec5SDimitry Andric{
15160b57cec5SDimitry Andric    delete this->first();
15170b57cec5SDimitry Andric}
15180b57cec5SDimitry Andric
15190b57cec5SDimitry Andric// __empty_state
15200b57cec5SDimitry Andric
15210b57cec5SDimitry Andrictemplate <class _CharT>
15220b57cec5SDimitry Andricclass __empty_state
15230b57cec5SDimitry Andric    : public __owns_one_state<_CharT>
15240b57cec5SDimitry Andric{
15250b57cec5SDimitry Andric    typedef __owns_one_state<_CharT> base;
15260b57cec5SDimitry Andric
15270b57cec5SDimitry Andricpublic:
15280b57cec5SDimitry Andric    typedef _VSTD::__state<_CharT> __state;
15290b57cec5SDimitry Andric
15300b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
15310b57cec5SDimitry Andric    explicit __empty_state(__node<_CharT>* __s)
15320b57cec5SDimitry Andric        : base(__s) {}
15330b57cec5SDimitry Andric
15340b57cec5SDimitry Andric    virtual void __exec(__state&) const;
15350b57cec5SDimitry Andric};
15360b57cec5SDimitry Andric
15370b57cec5SDimitry Andrictemplate <class _CharT>
15380b57cec5SDimitry Andricvoid
15390b57cec5SDimitry Andric__empty_state<_CharT>::__exec(__state& __s) const
15400b57cec5SDimitry Andric{
15410b57cec5SDimitry Andric    __s.__do_ = __state::__accept_but_not_consume;
15420b57cec5SDimitry Andric    __s.__node_ = this->first();
15430b57cec5SDimitry Andric}
15440b57cec5SDimitry Andric
15450b57cec5SDimitry Andric// __empty_non_own_state
15460b57cec5SDimitry Andric
15470b57cec5SDimitry Andrictemplate <class _CharT>
15480b57cec5SDimitry Andricclass __empty_non_own_state
15490b57cec5SDimitry Andric    : public __has_one_state<_CharT>
15500b57cec5SDimitry Andric{
15510b57cec5SDimitry Andric    typedef __has_one_state<_CharT> base;
15520b57cec5SDimitry Andric
15530b57cec5SDimitry Andricpublic:
15540b57cec5SDimitry Andric    typedef _VSTD::__state<_CharT> __state;
15550b57cec5SDimitry Andric
15560b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
15570b57cec5SDimitry Andric    explicit __empty_non_own_state(__node<_CharT>* __s)
15580b57cec5SDimitry Andric        : base(__s) {}
15590b57cec5SDimitry Andric
15600b57cec5SDimitry Andric    virtual void __exec(__state&) const;
15610b57cec5SDimitry Andric};
15620b57cec5SDimitry Andric
15630b57cec5SDimitry Andrictemplate <class _CharT>
15640b57cec5SDimitry Andricvoid
15650b57cec5SDimitry Andric__empty_non_own_state<_CharT>::__exec(__state& __s) const
15660b57cec5SDimitry Andric{
15670b57cec5SDimitry Andric    __s.__do_ = __state::__accept_but_not_consume;
15680b57cec5SDimitry Andric    __s.__node_ = this->first();
15690b57cec5SDimitry Andric}
15700b57cec5SDimitry Andric
15710b57cec5SDimitry Andric// __repeat_one_loop
15720b57cec5SDimitry Andric
15730b57cec5SDimitry Andrictemplate <class _CharT>
15740b57cec5SDimitry Andricclass __repeat_one_loop
15750b57cec5SDimitry Andric    : public __has_one_state<_CharT>
15760b57cec5SDimitry Andric{
15770b57cec5SDimitry Andric    typedef __has_one_state<_CharT> base;
15780b57cec5SDimitry Andric
15790b57cec5SDimitry Andricpublic:
15800b57cec5SDimitry Andric    typedef _VSTD::__state<_CharT> __state;
15810b57cec5SDimitry Andric
15820b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
15830b57cec5SDimitry Andric    explicit __repeat_one_loop(__node<_CharT>* __s)
15840b57cec5SDimitry Andric        : base(__s) {}
15850b57cec5SDimitry Andric
15860b57cec5SDimitry Andric    virtual void __exec(__state&) const;
15870b57cec5SDimitry Andric};
15880b57cec5SDimitry Andric
15890b57cec5SDimitry Andrictemplate <class _CharT>
15900b57cec5SDimitry Andricvoid
15910b57cec5SDimitry Andric__repeat_one_loop<_CharT>::__exec(__state& __s) const
15920b57cec5SDimitry Andric{
15930b57cec5SDimitry Andric    __s.__do_ = __state::__repeat;
15940b57cec5SDimitry Andric    __s.__node_ = this->first();
15950b57cec5SDimitry Andric}
15960b57cec5SDimitry Andric
15970b57cec5SDimitry Andric// __owns_two_states
15980b57cec5SDimitry Andric
15990b57cec5SDimitry Andrictemplate <class _CharT>
16000b57cec5SDimitry Andricclass __owns_two_states
16010b57cec5SDimitry Andric    : public __owns_one_state<_CharT>
16020b57cec5SDimitry Andric{
16030b57cec5SDimitry Andric    typedef __owns_one_state<_CharT> base;
16040b57cec5SDimitry Andric
16050b57cec5SDimitry Andric    base* __second_;
16060b57cec5SDimitry Andric
16070b57cec5SDimitry Andricpublic:
16080b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
16090b57cec5SDimitry Andric    explicit __owns_two_states(__node<_CharT>* __s1, base* __s2)
16100b57cec5SDimitry Andric        : base(__s1), __second_(__s2) {}
16110b57cec5SDimitry Andric
16120b57cec5SDimitry Andric    virtual ~__owns_two_states();
16130b57cec5SDimitry Andric
16140b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
16150b57cec5SDimitry Andric    base*  second() const {return __second_;}
16160b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
16170b57cec5SDimitry Andric    base*& second()       {return __second_;}
16180b57cec5SDimitry Andric};
16190b57cec5SDimitry Andric
16200b57cec5SDimitry Andrictemplate <class _CharT>
16210b57cec5SDimitry Andric__owns_two_states<_CharT>::~__owns_two_states()
16220b57cec5SDimitry Andric{
16230b57cec5SDimitry Andric    delete __second_;
16240b57cec5SDimitry Andric}
16250b57cec5SDimitry Andric
16260b57cec5SDimitry Andric// __loop
16270b57cec5SDimitry Andric
16280b57cec5SDimitry Andrictemplate <class _CharT>
16290b57cec5SDimitry Andricclass __loop
16300b57cec5SDimitry Andric    : public __owns_two_states<_CharT>
16310b57cec5SDimitry Andric{
16320b57cec5SDimitry Andric    typedef __owns_two_states<_CharT> base;
16330b57cec5SDimitry Andric
16340b57cec5SDimitry Andric    size_t __min_;
16350b57cec5SDimitry Andric    size_t __max_;
16360b57cec5SDimitry Andric    unsigned __loop_id_;
16370b57cec5SDimitry Andric    unsigned __mexp_begin_;
16380b57cec5SDimitry Andric    unsigned __mexp_end_;
16390b57cec5SDimitry Andric    bool __greedy_;
16400b57cec5SDimitry Andric
16410b57cec5SDimitry Andricpublic:
16420b57cec5SDimitry Andric    typedef _VSTD::__state<_CharT> __state;
16430b57cec5SDimitry Andric
16440b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
16450b57cec5SDimitry Andric    explicit __loop(unsigned __loop_id,
16460b57cec5SDimitry Andric                          __node<_CharT>* __s1, __owns_one_state<_CharT>* __s2,
16470b57cec5SDimitry Andric                          unsigned __mexp_begin, unsigned __mexp_end,
16480b57cec5SDimitry Andric                          bool __greedy = true,
16490b57cec5SDimitry Andric                          size_t __min = 0,
16500b57cec5SDimitry Andric                          size_t __max = numeric_limits<size_t>::max())
16510b57cec5SDimitry Andric        : base(__s1, __s2), __min_(__min), __max_(__max), __loop_id_(__loop_id),
16520b57cec5SDimitry Andric          __mexp_begin_(__mexp_begin), __mexp_end_(__mexp_end),
16530b57cec5SDimitry Andric          __greedy_(__greedy) {}
16540b57cec5SDimitry Andric
16550b57cec5SDimitry Andric    virtual void __exec(__state& __s) const;
16560b57cec5SDimitry Andric    virtual void __exec_split(bool __second, __state& __s) const;
16570b57cec5SDimitry Andric
16580b57cec5SDimitry Andricprivate:
16590b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
16600b57cec5SDimitry Andric    void __init_repeat(__state& __s) const
16610b57cec5SDimitry Andric    {
16620b57cec5SDimitry Andric        __s.__loop_data_[__loop_id_].second = __s.__current_;
16630b57cec5SDimitry Andric        for (size_t __i = __mexp_begin_-1; __i != __mexp_end_-1; ++__i)
16640b57cec5SDimitry Andric        {
16650b57cec5SDimitry Andric            __s.__sub_matches_[__i].first = __s.__last_;
16660b57cec5SDimitry Andric            __s.__sub_matches_[__i].second = __s.__last_;
16670b57cec5SDimitry Andric            __s.__sub_matches_[__i].matched = false;
16680b57cec5SDimitry Andric        }
16690b57cec5SDimitry Andric    }
16700b57cec5SDimitry Andric};
16710b57cec5SDimitry Andric
16720b57cec5SDimitry Andrictemplate <class _CharT>
16730b57cec5SDimitry Andricvoid
16740b57cec5SDimitry Andric__loop<_CharT>::__exec(__state& __s) const
16750b57cec5SDimitry Andric{
16760b57cec5SDimitry Andric    if (__s.__do_ == __state::__repeat)
16770b57cec5SDimitry Andric    {
16780b57cec5SDimitry Andric        bool __do_repeat = ++__s.__loop_data_[__loop_id_].first < __max_;
16790b57cec5SDimitry Andric        bool __do_alt = __s.__loop_data_[__loop_id_].first >= __min_;
16800b57cec5SDimitry Andric        if (__do_repeat && __do_alt &&
16810b57cec5SDimitry Andric                               __s.__loop_data_[__loop_id_].second == __s.__current_)
16820b57cec5SDimitry Andric            __do_repeat = false;
16830b57cec5SDimitry Andric        if (__do_repeat && __do_alt)
16840b57cec5SDimitry Andric            __s.__do_ = __state::__split;
16850b57cec5SDimitry Andric        else if (__do_repeat)
16860b57cec5SDimitry Andric        {
16870b57cec5SDimitry Andric            __s.__do_ = __state::__accept_but_not_consume;
16880b57cec5SDimitry Andric            __s.__node_ = this->first();
16890b57cec5SDimitry Andric            __init_repeat(__s);
16900b57cec5SDimitry Andric        }
16910b57cec5SDimitry Andric        else
16920b57cec5SDimitry Andric        {
16930b57cec5SDimitry Andric            __s.__do_ = __state::__accept_but_not_consume;
16940b57cec5SDimitry Andric            __s.__node_ = this->second();
16950b57cec5SDimitry Andric        }
16960b57cec5SDimitry Andric    }
16970b57cec5SDimitry Andric    else
16980b57cec5SDimitry Andric    {
16990b57cec5SDimitry Andric        __s.__loop_data_[__loop_id_].first = 0;
17000b57cec5SDimitry Andric        bool __do_repeat = 0 < __max_;
17010b57cec5SDimitry Andric        bool __do_alt = 0 >= __min_;
17020b57cec5SDimitry Andric        if (__do_repeat && __do_alt)
17030b57cec5SDimitry Andric            __s.__do_ = __state::__split;
17040b57cec5SDimitry Andric        else if (__do_repeat)
17050b57cec5SDimitry Andric        {
17060b57cec5SDimitry Andric            __s.__do_ = __state::__accept_but_not_consume;
17070b57cec5SDimitry Andric            __s.__node_ = this->first();
17080b57cec5SDimitry Andric            __init_repeat(__s);
17090b57cec5SDimitry Andric        }
17100b57cec5SDimitry Andric        else
17110b57cec5SDimitry Andric        {
17120b57cec5SDimitry Andric            __s.__do_ = __state::__accept_but_not_consume;
17130b57cec5SDimitry Andric            __s.__node_ = this->second();
17140b57cec5SDimitry Andric        }
17150b57cec5SDimitry Andric    }
17160b57cec5SDimitry Andric}
17170b57cec5SDimitry Andric
17180b57cec5SDimitry Andrictemplate <class _CharT>
17190b57cec5SDimitry Andricvoid
17200b57cec5SDimitry Andric__loop<_CharT>::__exec_split(bool __second, __state& __s) const
17210b57cec5SDimitry Andric{
17220b57cec5SDimitry Andric    __s.__do_ = __state::__accept_but_not_consume;
17230b57cec5SDimitry Andric    if (__greedy_ != __second)
17240b57cec5SDimitry Andric    {
17250b57cec5SDimitry Andric        __s.__node_ = this->first();
17260b57cec5SDimitry Andric        __init_repeat(__s);
17270b57cec5SDimitry Andric    }
17280b57cec5SDimitry Andric    else
17290b57cec5SDimitry Andric        __s.__node_ = this->second();
17300b57cec5SDimitry Andric}
17310b57cec5SDimitry Andric
17320b57cec5SDimitry Andric// __alternate
17330b57cec5SDimitry Andric
17340b57cec5SDimitry Andrictemplate <class _CharT>
17350b57cec5SDimitry Andricclass __alternate
17360b57cec5SDimitry Andric    : public __owns_two_states<_CharT>
17370b57cec5SDimitry Andric{
17380b57cec5SDimitry Andric    typedef __owns_two_states<_CharT> base;
17390b57cec5SDimitry Andric
17400b57cec5SDimitry Andricpublic:
17410b57cec5SDimitry Andric    typedef _VSTD::__state<_CharT> __state;
17420b57cec5SDimitry Andric
17430b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
17440b57cec5SDimitry Andric    explicit __alternate(__owns_one_state<_CharT>* __s1,
17450b57cec5SDimitry Andric                         __owns_one_state<_CharT>* __s2)
17460b57cec5SDimitry Andric        : base(__s1, __s2) {}
17470b57cec5SDimitry Andric
17480b57cec5SDimitry Andric    virtual void __exec(__state& __s) const;
17490b57cec5SDimitry Andric    virtual void __exec_split(bool __second, __state& __s) const;
17500b57cec5SDimitry Andric};
17510b57cec5SDimitry Andric
17520b57cec5SDimitry Andrictemplate <class _CharT>
17530b57cec5SDimitry Andricvoid
17540b57cec5SDimitry Andric__alternate<_CharT>::__exec(__state& __s) const
17550b57cec5SDimitry Andric{
17560b57cec5SDimitry Andric    __s.__do_ = __state::__split;
17570b57cec5SDimitry Andric}
17580b57cec5SDimitry Andric
17590b57cec5SDimitry Andrictemplate <class _CharT>
17600b57cec5SDimitry Andricvoid
17610b57cec5SDimitry Andric__alternate<_CharT>::__exec_split(bool __second, __state& __s) const
17620b57cec5SDimitry Andric{
17630b57cec5SDimitry Andric    __s.__do_ = __state::__accept_but_not_consume;
17640b57cec5SDimitry Andric    if (__second)
17650b57cec5SDimitry Andric        __s.__node_ = this->second();
17660b57cec5SDimitry Andric    else
17670b57cec5SDimitry Andric        __s.__node_ = this->first();
17680b57cec5SDimitry Andric}
17690b57cec5SDimitry Andric
17700b57cec5SDimitry Andric// __begin_marked_subexpression
17710b57cec5SDimitry Andric
17720b57cec5SDimitry Andrictemplate <class _CharT>
17730b57cec5SDimitry Andricclass __begin_marked_subexpression
17740b57cec5SDimitry Andric    : public __owns_one_state<_CharT>
17750b57cec5SDimitry Andric{
17760b57cec5SDimitry Andric    typedef __owns_one_state<_CharT> base;
17770b57cec5SDimitry Andric
17780b57cec5SDimitry Andric    unsigned __mexp_;
17790b57cec5SDimitry Andricpublic:
17800b57cec5SDimitry Andric    typedef _VSTD::__state<_CharT> __state;
17810b57cec5SDimitry Andric
17820b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
17830b57cec5SDimitry Andric    explicit __begin_marked_subexpression(unsigned __mexp, __node<_CharT>* __s)
17840b57cec5SDimitry Andric        : base(__s), __mexp_(__mexp) {}
17850b57cec5SDimitry Andric
17860b57cec5SDimitry Andric    virtual void __exec(__state&) const;
17870b57cec5SDimitry Andric};
17880b57cec5SDimitry Andric
17890b57cec5SDimitry Andrictemplate <class _CharT>
17900b57cec5SDimitry Andricvoid
17910b57cec5SDimitry Andric__begin_marked_subexpression<_CharT>::__exec(__state& __s) const
17920b57cec5SDimitry Andric{
17930b57cec5SDimitry Andric    __s.__do_ = __state::__accept_but_not_consume;
17940b57cec5SDimitry Andric    __s.__sub_matches_[__mexp_-1].first = __s.__current_;
17950b57cec5SDimitry Andric    __s.__node_ = this->first();
17960b57cec5SDimitry Andric}
17970b57cec5SDimitry Andric
17980b57cec5SDimitry Andric// __end_marked_subexpression
17990b57cec5SDimitry Andric
18000b57cec5SDimitry Andrictemplate <class _CharT>
18010b57cec5SDimitry Andricclass __end_marked_subexpression
18020b57cec5SDimitry Andric    : public __owns_one_state<_CharT>
18030b57cec5SDimitry Andric{
18040b57cec5SDimitry Andric    typedef __owns_one_state<_CharT> base;
18050b57cec5SDimitry Andric
18060b57cec5SDimitry Andric    unsigned __mexp_;
18070b57cec5SDimitry Andricpublic:
18080b57cec5SDimitry Andric    typedef _VSTD::__state<_CharT> __state;
18090b57cec5SDimitry Andric
18100b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
18110b57cec5SDimitry Andric    explicit __end_marked_subexpression(unsigned __mexp, __node<_CharT>* __s)
18120b57cec5SDimitry Andric        : base(__s), __mexp_(__mexp) {}
18130b57cec5SDimitry Andric
18140b57cec5SDimitry Andric    virtual void __exec(__state&) const;
18150b57cec5SDimitry Andric};
18160b57cec5SDimitry Andric
18170b57cec5SDimitry Andrictemplate <class _CharT>
18180b57cec5SDimitry Andricvoid
18190b57cec5SDimitry Andric__end_marked_subexpression<_CharT>::__exec(__state& __s) const
18200b57cec5SDimitry Andric{
18210b57cec5SDimitry Andric    __s.__do_ = __state::__accept_but_not_consume;
18220b57cec5SDimitry Andric    __s.__sub_matches_[__mexp_-1].second = __s.__current_;
18230b57cec5SDimitry Andric    __s.__sub_matches_[__mexp_-1].matched = true;
18240b57cec5SDimitry Andric    __s.__node_ = this->first();
18250b57cec5SDimitry Andric}
18260b57cec5SDimitry Andric
18270b57cec5SDimitry Andric// __back_ref
18280b57cec5SDimitry Andric
18290b57cec5SDimitry Andrictemplate <class _CharT>
18300b57cec5SDimitry Andricclass __back_ref
18310b57cec5SDimitry Andric    : public __owns_one_state<_CharT>
18320b57cec5SDimitry Andric{
18330b57cec5SDimitry Andric    typedef __owns_one_state<_CharT> base;
18340b57cec5SDimitry Andric
18350b57cec5SDimitry Andric    unsigned __mexp_;
18360b57cec5SDimitry Andricpublic:
18370b57cec5SDimitry Andric    typedef _VSTD::__state<_CharT> __state;
18380b57cec5SDimitry Andric
18390b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
18400b57cec5SDimitry Andric    explicit __back_ref(unsigned __mexp, __node<_CharT>* __s)
18410b57cec5SDimitry Andric        : base(__s), __mexp_(__mexp) {}
18420b57cec5SDimitry Andric
18430b57cec5SDimitry Andric    virtual void __exec(__state&) const;
18440b57cec5SDimitry Andric};
18450b57cec5SDimitry Andric
18460b57cec5SDimitry Andrictemplate <class _CharT>
18470b57cec5SDimitry Andricvoid
18480b57cec5SDimitry Andric__back_ref<_CharT>::__exec(__state& __s) const
18490b57cec5SDimitry Andric{
18500b57cec5SDimitry Andric    if (__mexp_ > __s.__sub_matches_.size())
18510b57cec5SDimitry Andric        __throw_regex_error<regex_constants::error_backref>();
18520b57cec5SDimitry Andric    sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1];
18530b57cec5SDimitry Andric    if (__sm.matched)
18540b57cec5SDimitry Andric    {
18550b57cec5SDimitry Andric        ptrdiff_t __len = __sm.second - __sm.first;
18560b57cec5SDimitry Andric        if (__s.__last_ - __s.__current_ >= __len &&
18570b57cec5SDimitry Andric            _VSTD::equal(__sm.first, __sm.second, __s.__current_))
18580b57cec5SDimitry Andric        {
18590b57cec5SDimitry Andric            __s.__do_ = __state::__accept_but_not_consume;
18600b57cec5SDimitry Andric            __s.__current_ += __len;
18610b57cec5SDimitry Andric            __s.__node_ = this->first();
18620b57cec5SDimitry Andric        }
18630b57cec5SDimitry Andric        else
18640b57cec5SDimitry Andric        {
18650b57cec5SDimitry Andric            __s.__do_ = __state::__reject;
18660b57cec5SDimitry Andric            __s.__node_ = nullptr;
18670b57cec5SDimitry Andric        }
18680b57cec5SDimitry Andric    }
18690b57cec5SDimitry Andric    else
18700b57cec5SDimitry Andric    {
18710b57cec5SDimitry Andric        __s.__do_ = __state::__reject;
18720b57cec5SDimitry Andric        __s.__node_ = nullptr;
18730b57cec5SDimitry Andric    }
18740b57cec5SDimitry Andric}
18750b57cec5SDimitry Andric
18760b57cec5SDimitry Andric// __back_ref_icase
18770b57cec5SDimitry Andric
18780b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
18790b57cec5SDimitry Andricclass __back_ref_icase
18800b57cec5SDimitry Andric    : public __owns_one_state<_CharT>
18810b57cec5SDimitry Andric{
18820b57cec5SDimitry Andric    typedef __owns_one_state<_CharT> base;
18830b57cec5SDimitry Andric
18840b57cec5SDimitry Andric    _Traits __traits_;
18850b57cec5SDimitry Andric    unsigned __mexp_;
18860b57cec5SDimitry Andricpublic:
18870b57cec5SDimitry Andric    typedef _VSTD::__state<_CharT> __state;
18880b57cec5SDimitry Andric
18890b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
18900b57cec5SDimitry Andric    explicit __back_ref_icase(const _Traits& __traits, unsigned __mexp,
18910b57cec5SDimitry Andric                              __node<_CharT>* __s)
18920b57cec5SDimitry Andric        : base(__s), __traits_(__traits), __mexp_(__mexp) {}
18930b57cec5SDimitry Andric
18940b57cec5SDimitry Andric    virtual void __exec(__state&) const;
18950b57cec5SDimitry Andric};
18960b57cec5SDimitry Andric
18970b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
18980b57cec5SDimitry Andricvoid
18990b57cec5SDimitry Andric__back_ref_icase<_CharT, _Traits>::__exec(__state& __s) const
19000b57cec5SDimitry Andric{
19010b57cec5SDimitry Andric    sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1];
19020b57cec5SDimitry Andric    if (__sm.matched)
19030b57cec5SDimitry Andric    {
19040b57cec5SDimitry Andric        ptrdiff_t __len = __sm.second - __sm.first;
19050b57cec5SDimitry Andric        if (__s.__last_ - __s.__current_ >= __len)
19060b57cec5SDimitry Andric        {
19070b57cec5SDimitry Andric            for (ptrdiff_t __i = 0; __i < __len; ++__i)
19080b57cec5SDimitry Andric            {
19090b57cec5SDimitry Andric                if (__traits_.translate_nocase(__sm.first[__i]) !=
19100b57cec5SDimitry Andric                                __traits_.translate_nocase(__s.__current_[__i]))
19110b57cec5SDimitry Andric                    goto __not_equal;
19120b57cec5SDimitry Andric            }
19130b57cec5SDimitry Andric            __s.__do_ = __state::__accept_but_not_consume;
19140b57cec5SDimitry Andric            __s.__current_ += __len;
19150b57cec5SDimitry Andric            __s.__node_ = this->first();
19160b57cec5SDimitry Andric        }
19170b57cec5SDimitry Andric        else
19180b57cec5SDimitry Andric        {
19190b57cec5SDimitry Andric            __s.__do_ = __state::__reject;
19200b57cec5SDimitry Andric            __s.__node_ = nullptr;
19210b57cec5SDimitry Andric        }
19220b57cec5SDimitry Andric    }
19230b57cec5SDimitry Andric    else
19240b57cec5SDimitry Andric    {
19250b57cec5SDimitry Andric__not_equal:
19260b57cec5SDimitry Andric        __s.__do_ = __state::__reject;
19270b57cec5SDimitry Andric        __s.__node_ = nullptr;
19280b57cec5SDimitry Andric    }
19290b57cec5SDimitry Andric}
19300b57cec5SDimitry Andric
19310b57cec5SDimitry Andric// __back_ref_collate
19320b57cec5SDimitry Andric
19330b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
19340b57cec5SDimitry Andricclass __back_ref_collate
19350b57cec5SDimitry Andric    : public __owns_one_state<_CharT>
19360b57cec5SDimitry Andric{
19370b57cec5SDimitry Andric    typedef __owns_one_state<_CharT> base;
19380b57cec5SDimitry Andric
19390b57cec5SDimitry Andric    _Traits __traits_;
19400b57cec5SDimitry Andric    unsigned __mexp_;
19410b57cec5SDimitry Andricpublic:
19420b57cec5SDimitry Andric    typedef _VSTD::__state<_CharT> __state;
19430b57cec5SDimitry Andric
19440b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
19450b57cec5SDimitry Andric    explicit __back_ref_collate(const _Traits& __traits, unsigned __mexp,
19460b57cec5SDimitry Andric                              __node<_CharT>* __s)
19470b57cec5SDimitry Andric        : base(__s), __traits_(__traits), __mexp_(__mexp) {}
19480b57cec5SDimitry Andric
19490b57cec5SDimitry Andric    virtual void __exec(__state&) const;
19500b57cec5SDimitry Andric};
19510b57cec5SDimitry Andric
19520b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
19530b57cec5SDimitry Andricvoid
19540b57cec5SDimitry Andric__back_ref_collate<_CharT, _Traits>::__exec(__state& __s) const
19550b57cec5SDimitry Andric{
19560b57cec5SDimitry Andric    sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1];
19570b57cec5SDimitry Andric    if (__sm.matched)
19580b57cec5SDimitry Andric    {
19590b57cec5SDimitry Andric        ptrdiff_t __len = __sm.second - __sm.first;
19600b57cec5SDimitry Andric        if (__s.__last_ - __s.__current_ >= __len)
19610b57cec5SDimitry Andric        {
19620b57cec5SDimitry Andric            for (ptrdiff_t __i = 0; __i < __len; ++__i)
19630b57cec5SDimitry Andric            {
19640b57cec5SDimitry Andric                if (__traits_.translate(__sm.first[__i]) !=
19650b57cec5SDimitry Andric                                       __traits_.translate(__s.__current_[__i]))
19660b57cec5SDimitry Andric                    goto __not_equal;
19670b57cec5SDimitry Andric            }
19680b57cec5SDimitry Andric            __s.__do_ = __state::__accept_but_not_consume;
19690b57cec5SDimitry Andric            __s.__current_ += __len;
19700b57cec5SDimitry Andric            __s.__node_ = this->first();
19710b57cec5SDimitry Andric        }
19720b57cec5SDimitry Andric        else
19730b57cec5SDimitry Andric        {
19740b57cec5SDimitry Andric            __s.__do_ = __state::__reject;
19750b57cec5SDimitry Andric            __s.__node_ = nullptr;
19760b57cec5SDimitry Andric        }
19770b57cec5SDimitry Andric    }
19780b57cec5SDimitry Andric    else
19790b57cec5SDimitry Andric    {
19800b57cec5SDimitry Andric__not_equal:
19810b57cec5SDimitry Andric        __s.__do_ = __state::__reject;
19820b57cec5SDimitry Andric        __s.__node_ = nullptr;
19830b57cec5SDimitry Andric    }
19840b57cec5SDimitry Andric}
19850b57cec5SDimitry Andric
19860b57cec5SDimitry Andric// __word_boundary
19870b57cec5SDimitry Andric
19880b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
19890b57cec5SDimitry Andricclass __word_boundary
19900b57cec5SDimitry Andric    : public __owns_one_state<_CharT>
19910b57cec5SDimitry Andric{
19920b57cec5SDimitry Andric    typedef __owns_one_state<_CharT> base;
19930b57cec5SDimitry Andric
19940b57cec5SDimitry Andric    _Traits __traits_;
19950b57cec5SDimitry Andric    bool __invert_;
19960b57cec5SDimitry Andricpublic:
19970b57cec5SDimitry Andric    typedef _VSTD::__state<_CharT> __state;
19980b57cec5SDimitry Andric
19990b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
20000b57cec5SDimitry Andric    explicit __word_boundary(const _Traits& __traits, bool __invert,
20010b57cec5SDimitry Andric                             __node<_CharT>* __s)
20020b57cec5SDimitry Andric        : base(__s), __traits_(__traits), __invert_(__invert) {}
20030b57cec5SDimitry Andric
20040b57cec5SDimitry Andric    virtual void __exec(__state&) const;
20050b57cec5SDimitry Andric};
20060b57cec5SDimitry Andric
20070b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
20080b57cec5SDimitry Andricvoid
20090b57cec5SDimitry Andric__word_boundary<_CharT, _Traits>::__exec(__state& __s) const
20100b57cec5SDimitry Andric{
20110b57cec5SDimitry Andric    bool __is_word_b = false;
20120b57cec5SDimitry Andric    if (__s.__first_ != __s.__last_)
20130b57cec5SDimitry Andric    {
20140b57cec5SDimitry Andric        if (__s.__current_ == __s.__last_)
20150b57cec5SDimitry Andric        {
20160b57cec5SDimitry Andric            if (!(__s.__flags_ & regex_constants::match_not_eow))
20170b57cec5SDimitry Andric            {
20180b57cec5SDimitry Andric                _CharT __c = __s.__current_[-1];
20190b57cec5SDimitry Andric                __is_word_b = __c == '_' ||
20200b57cec5SDimitry Andric                              __traits_.isctype(__c, ctype_base::alnum);
20210b57cec5SDimitry Andric            }
20220b57cec5SDimitry Andric        }
20230b57cec5SDimitry Andric        else if (__s.__current_ == __s.__first_ &&
20240b57cec5SDimitry Andric                !(__s.__flags_ & regex_constants::match_prev_avail))
20250b57cec5SDimitry Andric        {
20260b57cec5SDimitry Andric            if (!(__s.__flags_ & regex_constants::match_not_bow))
20270b57cec5SDimitry Andric            {
20280b57cec5SDimitry Andric                _CharT __c = *__s.__current_;
20290b57cec5SDimitry Andric                __is_word_b = __c == '_' ||
20300b57cec5SDimitry Andric                              __traits_.isctype(__c, ctype_base::alnum);
20310b57cec5SDimitry Andric            }
20320b57cec5SDimitry Andric        }
20330b57cec5SDimitry Andric        else
20340b57cec5SDimitry Andric        {
20350b57cec5SDimitry Andric            _CharT __c1 = __s.__current_[-1];
20360b57cec5SDimitry Andric            _CharT __c2 = *__s.__current_;
20370b57cec5SDimitry Andric            bool __is_c1_b = __c1 == '_' ||
20380b57cec5SDimitry Andric                             __traits_.isctype(__c1, ctype_base::alnum);
20390b57cec5SDimitry Andric            bool __is_c2_b = __c2 == '_' ||
20400b57cec5SDimitry Andric                             __traits_.isctype(__c2, ctype_base::alnum);
20410b57cec5SDimitry Andric            __is_word_b = __is_c1_b != __is_c2_b;
20420b57cec5SDimitry Andric        }
20430b57cec5SDimitry Andric    }
20440b57cec5SDimitry Andric    if (__is_word_b != __invert_)
20450b57cec5SDimitry Andric    {
20460b57cec5SDimitry Andric        __s.__do_ = __state::__accept_but_not_consume;
20470b57cec5SDimitry Andric        __s.__node_ = this->first();
20480b57cec5SDimitry Andric    }
20490b57cec5SDimitry Andric    else
20500b57cec5SDimitry Andric    {
20510b57cec5SDimitry Andric        __s.__do_ = __state::__reject;
20520b57cec5SDimitry Andric        __s.__node_ = nullptr;
20530b57cec5SDimitry Andric    }
20540b57cec5SDimitry Andric}
20550b57cec5SDimitry Andric
20560b57cec5SDimitry Andric// __l_anchor
20570b57cec5SDimitry Andric
20580b57cec5SDimitry Andrictemplate <class _CharT>
2059e8d8bef9SDimitry Andric_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
2060753f127fSDimitry Andricbool __is_eol(_CharT __c)
2061e8d8bef9SDimitry Andric{
2062753f127fSDimitry Andric    return __c == '\r' || __c == '\n';
2063e8d8bef9SDimitry Andric}
2064e8d8bef9SDimitry Andric
2065e8d8bef9SDimitry Andrictemplate <class _CharT>
2066e8d8bef9SDimitry Andricclass __l_anchor_multiline
20670b57cec5SDimitry Andric    : public __owns_one_state<_CharT>
20680b57cec5SDimitry Andric{
20690b57cec5SDimitry Andric    typedef __owns_one_state<_CharT> base;
20700b57cec5SDimitry Andric
2071fe6060f1SDimitry Andric    bool __multiline_;
2072e8d8bef9SDimitry Andric
20730b57cec5SDimitry Andricpublic:
20740b57cec5SDimitry Andric    typedef _VSTD::__state<_CharT> __state;
20750b57cec5SDimitry Andric
20760b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
2077e8d8bef9SDimitry Andric    __l_anchor_multiline(bool __multiline, __node<_CharT>* __s)
2078fe6060f1SDimitry Andric        : base(__s), __multiline_(__multiline) {}
20790b57cec5SDimitry Andric
20800b57cec5SDimitry Andric    virtual void __exec(__state&) const;
20810b57cec5SDimitry Andric};
20820b57cec5SDimitry Andric
20830b57cec5SDimitry Andrictemplate <class _CharT>
20840b57cec5SDimitry Andricvoid
2085e8d8bef9SDimitry Andric__l_anchor_multiline<_CharT>::__exec(__state& __s) const
20860b57cec5SDimitry Andric{
20870b57cec5SDimitry Andric    if (__s.__at_first_ && __s.__current_ == __s.__first_ &&
20880b57cec5SDimitry Andric        !(__s.__flags_ & regex_constants::match_not_bol))
20890b57cec5SDimitry Andric    {
20900b57cec5SDimitry Andric        __s.__do_ = __state::__accept_but_not_consume;
20910b57cec5SDimitry Andric        __s.__node_ = this->first();
20920b57cec5SDimitry Andric    }
2093fe6060f1SDimitry Andric    else if (__multiline_ &&
2094e8d8bef9SDimitry Andric             !__s.__at_first_ &&
2095e8d8bef9SDimitry Andric             __is_eol(*_VSTD::prev(__s.__current_)))
2096e8d8bef9SDimitry Andric    {
2097e8d8bef9SDimitry Andric        __s.__do_ = __state::__accept_but_not_consume;
2098e8d8bef9SDimitry Andric        __s.__node_ = this->first();
2099e8d8bef9SDimitry Andric    }
21000b57cec5SDimitry Andric    else
21010b57cec5SDimitry Andric    {
21020b57cec5SDimitry Andric        __s.__do_ = __state::__reject;
21030b57cec5SDimitry Andric        __s.__node_ = nullptr;
21040b57cec5SDimitry Andric    }
21050b57cec5SDimitry Andric}
21060b57cec5SDimitry Andric
21070b57cec5SDimitry Andric// __r_anchor
21080b57cec5SDimitry Andric
21090b57cec5SDimitry Andrictemplate <class _CharT>
2110e8d8bef9SDimitry Andricclass __r_anchor_multiline
21110b57cec5SDimitry Andric    : public __owns_one_state<_CharT>
21120b57cec5SDimitry Andric{
21130b57cec5SDimitry Andric    typedef __owns_one_state<_CharT> base;
21140b57cec5SDimitry Andric
211581ad6265SDimitry Andric    bool __multiline_;
2116e8d8bef9SDimitry Andric
21170b57cec5SDimitry Andricpublic:
21180b57cec5SDimitry Andric    typedef _VSTD::__state<_CharT> __state;
21190b57cec5SDimitry Andric
21200b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
2121e8d8bef9SDimitry Andric    __r_anchor_multiline(bool __multiline, __node<_CharT>* __s)
212281ad6265SDimitry Andric        : base(__s), __multiline_(__multiline) {}
21230b57cec5SDimitry Andric
21240b57cec5SDimitry Andric    virtual void __exec(__state&) const;
21250b57cec5SDimitry Andric};
21260b57cec5SDimitry Andric
21270b57cec5SDimitry Andrictemplate <class _CharT>
21280b57cec5SDimitry Andricvoid
2129e8d8bef9SDimitry Andric__r_anchor_multiline<_CharT>::__exec(__state& __s) const
21300b57cec5SDimitry Andric{
21310b57cec5SDimitry Andric    if (__s.__current_ == __s.__last_ &&
21320b57cec5SDimitry Andric        !(__s.__flags_ & regex_constants::match_not_eol))
21330b57cec5SDimitry Andric    {
21340b57cec5SDimitry Andric        __s.__do_ = __state::__accept_but_not_consume;
21350b57cec5SDimitry Andric        __s.__node_ = this->first();
21360b57cec5SDimitry Andric    }
213781ad6265SDimitry Andric    else if (__multiline_ && __is_eol(*__s.__current_))
2138e8d8bef9SDimitry Andric    {
2139e8d8bef9SDimitry Andric        __s.__do_ = __state::__accept_but_not_consume;
2140e8d8bef9SDimitry Andric        __s.__node_ = this->first();
2141e8d8bef9SDimitry Andric    }
21420b57cec5SDimitry Andric    else
21430b57cec5SDimitry Andric    {
21440b57cec5SDimitry Andric        __s.__do_ = __state::__reject;
21450b57cec5SDimitry Andric        __s.__node_ = nullptr;
21460b57cec5SDimitry Andric    }
21470b57cec5SDimitry Andric}
21480b57cec5SDimitry Andric
21490b57cec5SDimitry Andric// __match_any
21500b57cec5SDimitry Andric
21510b57cec5SDimitry Andrictemplate <class _CharT>
21520b57cec5SDimitry Andricclass __match_any
21530b57cec5SDimitry Andric    : public __owns_one_state<_CharT>
21540b57cec5SDimitry Andric{
21550b57cec5SDimitry Andric    typedef __owns_one_state<_CharT> base;
21560b57cec5SDimitry Andric
21570b57cec5SDimitry Andricpublic:
21580b57cec5SDimitry Andric    typedef _VSTD::__state<_CharT> __state;
21590b57cec5SDimitry Andric
21600b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
21610b57cec5SDimitry Andric    __match_any(__node<_CharT>* __s)
21620b57cec5SDimitry Andric        : base(__s) {}
21630b57cec5SDimitry Andric
21640b57cec5SDimitry Andric    virtual void __exec(__state&) const;
21650b57cec5SDimitry Andric};
21660b57cec5SDimitry Andric
21670b57cec5SDimitry Andrictemplate <class _CharT>
21680b57cec5SDimitry Andricvoid
21690b57cec5SDimitry Andric__match_any<_CharT>::__exec(__state& __s) const
21700b57cec5SDimitry Andric{
21710b57cec5SDimitry Andric    if (__s.__current_ != __s.__last_ && *__s.__current_ != 0)
21720b57cec5SDimitry Andric    {
21730b57cec5SDimitry Andric        __s.__do_ = __state::__accept_and_consume;
21740b57cec5SDimitry Andric        ++__s.__current_;
21750b57cec5SDimitry Andric        __s.__node_ = this->first();
21760b57cec5SDimitry Andric    }
21770b57cec5SDimitry Andric    else
21780b57cec5SDimitry Andric    {
21790b57cec5SDimitry Andric        __s.__do_ = __state::__reject;
21800b57cec5SDimitry Andric        __s.__node_ = nullptr;
21810b57cec5SDimitry Andric    }
21820b57cec5SDimitry Andric}
21830b57cec5SDimitry Andric
21840b57cec5SDimitry Andric// __match_any_but_newline
21850b57cec5SDimitry Andric
21860b57cec5SDimitry Andrictemplate <class _CharT>
21870b57cec5SDimitry Andricclass __match_any_but_newline
21880b57cec5SDimitry Andric    : public __owns_one_state<_CharT>
21890b57cec5SDimitry Andric{
21900b57cec5SDimitry Andric    typedef __owns_one_state<_CharT> base;
21910b57cec5SDimitry Andric
21920b57cec5SDimitry Andricpublic:
21930b57cec5SDimitry Andric    typedef _VSTD::__state<_CharT> __state;
21940b57cec5SDimitry Andric
21950b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
21960b57cec5SDimitry Andric    __match_any_but_newline(__node<_CharT>* __s)
21970b57cec5SDimitry Andric        : base(__s) {}
21980b57cec5SDimitry Andric
21990b57cec5SDimitry Andric    virtual void __exec(__state&) const;
22000b57cec5SDimitry Andric};
22010b57cec5SDimitry Andric
22020b57cec5SDimitry Andrictemplate <> _LIBCPP_FUNC_VIS void __match_any_but_newline<char>::__exec(__state&) const;
2203349cc55cSDimitry Andric#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
22040b57cec5SDimitry Andrictemplate <> _LIBCPP_FUNC_VIS void __match_any_but_newline<wchar_t>::__exec(__state&) const;
2205349cc55cSDimitry Andric#endif
22060b57cec5SDimitry Andric
22070b57cec5SDimitry Andric// __match_char
22080b57cec5SDimitry Andric
22090b57cec5SDimitry Andrictemplate <class _CharT>
22100b57cec5SDimitry Andricclass __match_char
22110b57cec5SDimitry Andric    : public __owns_one_state<_CharT>
22120b57cec5SDimitry Andric{
22130b57cec5SDimitry Andric    typedef __owns_one_state<_CharT> base;
22140b57cec5SDimitry Andric
22150b57cec5SDimitry Andric    _CharT __c_;
22160b57cec5SDimitry Andric
22170b57cec5SDimitry Andric    __match_char(const __match_char&);
22180b57cec5SDimitry Andric    __match_char& operator=(const __match_char&);
22190b57cec5SDimitry Andricpublic:
22200b57cec5SDimitry Andric    typedef _VSTD::__state<_CharT> __state;
22210b57cec5SDimitry Andric
22220b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
22230b57cec5SDimitry Andric    __match_char(_CharT __c, __node<_CharT>* __s)
22240b57cec5SDimitry Andric        : base(__s), __c_(__c) {}
22250b57cec5SDimitry Andric
22260b57cec5SDimitry Andric    virtual void __exec(__state&) const;
22270b57cec5SDimitry Andric};
22280b57cec5SDimitry Andric
22290b57cec5SDimitry Andrictemplate <class _CharT>
22300b57cec5SDimitry Andricvoid
22310b57cec5SDimitry Andric__match_char<_CharT>::__exec(__state& __s) const
22320b57cec5SDimitry Andric{
22330b57cec5SDimitry Andric    if (__s.__current_ != __s.__last_ && *__s.__current_ == __c_)
22340b57cec5SDimitry Andric    {
22350b57cec5SDimitry Andric        __s.__do_ = __state::__accept_and_consume;
22360b57cec5SDimitry Andric        ++__s.__current_;
22370b57cec5SDimitry Andric        __s.__node_ = this->first();
22380b57cec5SDimitry Andric    }
22390b57cec5SDimitry Andric    else
22400b57cec5SDimitry Andric    {
22410b57cec5SDimitry Andric        __s.__do_ = __state::__reject;
22420b57cec5SDimitry Andric        __s.__node_ = nullptr;
22430b57cec5SDimitry Andric    }
22440b57cec5SDimitry Andric}
22450b57cec5SDimitry Andric
22460b57cec5SDimitry Andric// __match_char_icase
22470b57cec5SDimitry Andric
22480b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
22490b57cec5SDimitry Andricclass __match_char_icase
22500b57cec5SDimitry Andric    : public __owns_one_state<_CharT>
22510b57cec5SDimitry Andric{
22520b57cec5SDimitry Andric    typedef __owns_one_state<_CharT> base;
22530b57cec5SDimitry Andric
22540b57cec5SDimitry Andric    _Traits __traits_;
22550b57cec5SDimitry Andric    _CharT __c_;
22560b57cec5SDimitry Andric
22570b57cec5SDimitry Andric    __match_char_icase(const __match_char_icase&);
22580b57cec5SDimitry Andric    __match_char_icase& operator=(const __match_char_icase&);
22590b57cec5SDimitry Andricpublic:
22600b57cec5SDimitry Andric    typedef _VSTD::__state<_CharT> __state;
22610b57cec5SDimitry Andric
22620b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
22630b57cec5SDimitry Andric    __match_char_icase(const _Traits& __traits, _CharT __c, __node<_CharT>* __s)
22640b57cec5SDimitry Andric        : base(__s), __traits_(__traits), __c_(__traits.translate_nocase(__c)) {}
22650b57cec5SDimitry Andric
22660b57cec5SDimitry Andric    virtual void __exec(__state&) const;
22670b57cec5SDimitry Andric};
22680b57cec5SDimitry Andric
22690b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
22700b57cec5SDimitry Andricvoid
22710b57cec5SDimitry Andric__match_char_icase<_CharT, _Traits>::__exec(__state& __s) const
22720b57cec5SDimitry Andric{
22730b57cec5SDimitry Andric    if (__s.__current_ != __s.__last_ &&
22740b57cec5SDimitry Andric        __traits_.translate_nocase(*__s.__current_) == __c_)
22750b57cec5SDimitry Andric    {
22760b57cec5SDimitry Andric        __s.__do_ = __state::__accept_and_consume;
22770b57cec5SDimitry Andric        ++__s.__current_;
22780b57cec5SDimitry Andric        __s.__node_ = this->first();
22790b57cec5SDimitry Andric    }
22800b57cec5SDimitry Andric    else
22810b57cec5SDimitry Andric    {
22820b57cec5SDimitry Andric        __s.__do_ = __state::__reject;
22830b57cec5SDimitry Andric        __s.__node_ = nullptr;
22840b57cec5SDimitry Andric    }
22850b57cec5SDimitry Andric}
22860b57cec5SDimitry Andric
22870b57cec5SDimitry Andric// __match_char_collate
22880b57cec5SDimitry Andric
22890b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
22900b57cec5SDimitry Andricclass __match_char_collate
22910b57cec5SDimitry Andric    : public __owns_one_state<_CharT>
22920b57cec5SDimitry Andric{
22930b57cec5SDimitry Andric    typedef __owns_one_state<_CharT> base;
22940b57cec5SDimitry Andric
22950b57cec5SDimitry Andric    _Traits __traits_;
22960b57cec5SDimitry Andric    _CharT __c_;
22970b57cec5SDimitry Andric
22980b57cec5SDimitry Andric    __match_char_collate(const __match_char_collate&);
22990b57cec5SDimitry Andric    __match_char_collate& operator=(const __match_char_collate&);
23000b57cec5SDimitry Andricpublic:
23010b57cec5SDimitry Andric    typedef _VSTD::__state<_CharT> __state;
23020b57cec5SDimitry Andric
23030b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
23040b57cec5SDimitry Andric    __match_char_collate(const _Traits& __traits, _CharT __c, __node<_CharT>* __s)
23050b57cec5SDimitry Andric        : base(__s), __traits_(__traits), __c_(__traits.translate(__c)) {}
23060b57cec5SDimitry Andric
23070b57cec5SDimitry Andric    virtual void __exec(__state&) const;
23080b57cec5SDimitry Andric};
23090b57cec5SDimitry Andric
23100b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
23110b57cec5SDimitry Andricvoid
23120b57cec5SDimitry Andric__match_char_collate<_CharT, _Traits>::__exec(__state& __s) const
23130b57cec5SDimitry Andric{
23140b57cec5SDimitry Andric    if (__s.__current_ != __s.__last_ &&
23150b57cec5SDimitry Andric        __traits_.translate(*__s.__current_) == __c_)
23160b57cec5SDimitry Andric    {
23170b57cec5SDimitry Andric        __s.__do_ = __state::__accept_and_consume;
23180b57cec5SDimitry Andric        ++__s.__current_;
23190b57cec5SDimitry Andric        __s.__node_ = this->first();
23200b57cec5SDimitry Andric    }
23210b57cec5SDimitry Andric    else
23220b57cec5SDimitry Andric    {
23230b57cec5SDimitry Andric        __s.__do_ = __state::__reject;
23240b57cec5SDimitry Andric        __s.__node_ = nullptr;
23250b57cec5SDimitry Andric    }
23260b57cec5SDimitry Andric}
23270b57cec5SDimitry Andric
23280b57cec5SDimitry Andric// __bracket_expression
23290b57cec5SDimitry Andric
23300b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
23310b57cec5SDimitry Andricclass __bracket_expression
23320b57cec5SDimitry Andric    : public __owns_one_state<_CharT>
23330b57cec5SDimitry Andric{
23340b57cec5SDimitry Andric    typedef __owns_one_state<_CharT> base;
23350b57cec5SDimitry Andric    typedef typename _Traits::string_type string_type;
23360b57cec5SDimitry Andric
23370b57cec5SDimitry Andric    _Traits __traits_;
23380b57cec5SDimitry Andric    vector<_CharT> __chars_;
23390b57cec5SDimitry Andric    vector<_CharT> __neg_chars_;
23400b57cec5SDimitry Andric    vector<pair<string_type, string_type> > __ranges_;
23410b57cec5SDimitry Andric    vector<pair<_CharT, _CharT> > __digraphs_;
23420b57cec5SDimitry Andric    vector<string_type> __equivalences_;
23430b57cec5SDimitry Andric    typename regex_traits<_CharT>::char_class_type __mask_;
23440b57cec5SDimitry Andric    typename regex_traits<_CharT>::char_class_type __neg_mask_;
23450b57cec5SDimitry Andric    bool __negate_;
23460b57cec5SDimitry Andric    bool __icase_;
23470b57cec5SDimitry Andric    bool __collate_;
23480b57cec5SDimitry Andric    bool __might_have_digraph_;
23490b57cec5SDimitry Andric
23500b57cec5SDimitry Andric    __bracket_expression(const __bracket_expression&);
23510b57cec5SDimitry Andric    __bracket_expression& operator=(const __bracket_expression&);
23520b57cec5SDimitry Andricpublic:
23530b57cec5SDimitry Andric    typedef _VSTD::__state<_CharT> __state;
23540b57cec5SDimitry Andric
23550b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
23560b57cec5SDimitry Andric    __bracket_expression(const _Traits& __traits, __node<_CharT>* __s,
23570b57cec5SDimitry Andric                                 bool __negate, bool __icase, bool __collate)
23580b57cec5SDimitry Andric        : base(__s), __traits_(__traits), __mask_(), __neg_mask_(),
23590b57cec5SDimitry Andric          __negate_(__negate), __icase_(__icase), __collate_(__collate),
23600b57cec5SDimitry Andric          __might_have_digraph_(__traits_.getloc().name() != "C") {}
23610b57cec5SDimitry Andric
23620b57cec5SDimitry Andric    virtual void __exec(__state&) const;
23630b57cec5SDimitry Andric
23640b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
23650b57cec5SDimitry Andric    bool __negated() const {return __negate_;}
23660b57cec5SDimitry Andric
23670b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
23680b57cec5SDimitry Andric    void __add_char(_CharT __c)
23690b57cec5SDimitry Andric        {
23700b57cec5SDimitry Andric            if (__icase_)
23710b57cec5SDimitry Andric                __chars_.push_back(__traits_.translate_nocase(__c));
23720b57cec5SDimitry Andric            else if (__collate_)
23730b57cec5SDimitry Andric                __chars_.push_back(__traits_.translate(__c));
23740b57cec5SDimitry Andric            else
23750b57cec5SDimitry Andric                __chars_.push_back(__c);
23760b57cec5SDimitry Andric        }
23770b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
23780b57cec5SDimitry Andric    void __add_neg_char(_CharT __c)
23790b57cec5SDimitry Andric        {
23800b57cec5SDimitry Andric            if (__icase_)
23810b57cec5SDimitry Andric                __neg_chars_.push_back(__traits_.translate_nocase(__c));
23820b57cec5SDimitry Andric            else if (__collate_)
23830b57cec5SDimitry Andric                __neg_chars_.push_back(__traits_.translate(__c));
23840b57cec5SDimitry Andric            else
23850b57cec5SDimitry Andric                __neg_chars_.push_back(__c);
23860b57cec5SDimitry Andric        }
23870b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
23880b57cec5SDimitry Andric    void __add_range(string_type __b, string_type __e)
23890b57cec5SDimitry Andric        {
23900b57cec5SDimitry Andric            if (__collate_)
23910b57cec5SDimitry Andric            {
23920b57cec5SDimitry Andric                if (__icase_)
23930b57cec5SDimitry Andric                {
23940b57cec5SDimitry Andric                    for (size_t __i = 0; __i < __b.size(); ++__i)
23950b57cec5SDimitry Andric                        __b[__i] = __traits_.translate_nocase(__b[__i]);
23960b57cec5SDimitry Andric                    for (size_t __i = 0; __i < __e.size(); ++__i)
23970b57cec5SDimitry Andric                        __e[__i] = __traits_.translate_nocase(__e[__i]);
23980b57cec5SDimitry Andric                }
23990b57cec5SDimitry Andric                else
24000b57cec5SDimitry Andric                {
24010b57cec5SDimitry Andric                    for (size_t __i = 0; __i < __b.size(); ++__i)
24020b57cec5SDimitry Andric                        __b[__i] = __traits_.translate(__b[__i]);
24030b57cec5SDimitry Andric                    for (size_t __i = 0; __i < __e.size(); ++__i)
24040b57cec5SDimitry Andric                        __e[__i] = __traits_.translate(__e[__i]);
24050b57cec5SDimitry Andric                }
24060b57cec5SDimitry Andric                __ranges_.push_back(make_pair(
24070b57cec5SDimitry Andric                                  __traits_.transform(__b.begin(), __b.end()),
24080b57cec5SDimitry Andric                                  __traits_.transform(__e.begin(), __e.end())));
24090b57cec5SDimitry Andric            }
24100b57cec5SDimitry Andric            else
24110b57cec5SDimitry Andric            {
24120b57cec5SDimitry Andric                if (__b.size() != 1 || __e.size() != 1)
24130b57cec5SDimitry Andric                    __throw_regex_error<regex_constants::error_range>();
24140b57cec5SDimitry Andric                if (__icase_)
24150b57cec5SDimitry Andric                {
24160b57cec5SDimitry Andric                    __b[0] = __traits_.translate_nocase(__b[0]);
24170b57cec5SDimitry Andric                    __e[0] = __traits_.translate_nocase(__e[0]);
24180b57cec5SDimitry Andric                }
24190b57cec5SDimitry Andric                __ranges_.push_back(make_pair(_VSTD::move(__b), _VSTD::move(__e)));
24200b57cec5SDimitry Andric            }
24210b57cec5SDimitry Andric        }
24220b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
24230b57cec5SDimitry Andric    void __add_digraph(_CharT __c1, _CharT __c2)
24240b57cec5SDimitry Andric        {
24250b57cec5SDimitry Andric            if (__icase_)
24260b57cec5SDimitry Andric                __digraphs_.push_back(make_pair(__traits_.translate_nocase(__c1),
24270b57cec5SDimitry Andric                                                __traits_.translate_nocase(__c2)));
24280b57cec5SDimitry Andric            else if (__collate_)
24290b57cec5SDimitry Andric                __digraphs_.push_back(make_pair(__traits_.translate(__c1),
24300b57cec5SDimitry Andric                                                __traits_.translate(__c2)));
24310b57cec5SDimitry Andric            else
24320b57cec5SDimitry Andric                __digraphs_.push_back(make_pair(__c1, __c2));
24330b57cec5SDimitry Andric        }
24340b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
24350b57cec5SDimitry Andric    void __add_equivalence(const string_type& __s)
24360b57cec5SDimitry Andric        {__equivalences_.push_back(__s);}
24370b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
24380b57cec5SDimitry Andric    void __add_class(typename regex_traits<_CharT>::char_class_type __mask)
24390b57cec5SDimitry Andric        {__mask_ |= __mask;}
24400b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
24410b57cec5SDimitry Andric    void __add_neg_class(typename regex_traits<_CharT>::char_class_type __mask)
24420b57cec5SDimitry Andric        {__neg_mask_ |= __mask;}
24430b57cec5SDimitry Andric};
24440b57cec5SDimitry Andric
24450b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
24460b57cec5SDimitry Andricvoid
24470b57cec5SDimitry Andric__bracket_expression<_CharT, _Traits>::__exec(__state& __s) const
24480b57cec5SDimitry Andric{
24490b57cec5SDimitry Andric    bool __found = false;
24500b57cec5SDimitry Andric    unsigned __consumed = 0;
24510b57cec5SDimitry Andric    if (__s.__current_ != __s.__last_)
24520b57cec5SDimitry Andric    {
24530b57cec5SDimitry Andric        ++__consumed;
24540b57cec5SDimitry Andric        if (__might_have_digraph_)
24550b57cec5SDimitry Andric        {
24560b57cec5SDimitry Andric            const _CharT* __next = _VSTD::next(__s.__current_);
24570b57cec5SDimitry Andric            if (__next != __s.__last_)
24580b57cec5SDimitry Andric            {
24590b57cec5SDimitry Andric                pair<_CharT, _CharT> __ch2(*__s.__current_, *__next);
24600b57cec5SDimitry Andric                if (__icase_)
24610b57cec5SDimitry Andric                {
24620b57cec5SDimitry Andric                    __ch2.first = __traits_.translate_nocase(__ch2.first);
24630b57cec5SDimitry Andric                    __ch2.second = __traits_.translate_nocase(__ch2.second);
24640b57cec5SDimitry Andric                }
24650b57cec5SDimitry Andric                else if (__collate_)
24660b57cec5SDimitry Andric                {
24670b57cec5SDimitry Andric                    __ch2.first = __traits_.translate(__ch2.first);
24680b57cec5SDimitry Andric                    __ch2.second = __traits_.translate(__ch2.second);
24690b57cec5SDimitry Andric                }
24700b57cec5SDimitry Andric                if (!__traits_.lookup_collatename(&__ch2.first, &__ch2.first+2).empty())
24710b57cec5SDimitry Andric                {
24720b57cec5SDimitry Andric                    // __ch2 is a digraph in this locale
24730b57cec5SDimitry Andric                    ++__consumed;
24740b57cec5SDimitry Andric                    for (size_t __i = 0; __i < __digraphs_.size(); ++__i)
24750b57cec5SDimitry Andric                    {
24760b57cec5SDimitry Andric                        if (__ch2 == __digraphs_[__i])
24770b57cec5SDimitry Andric                        {
24780b57cec5SDimitry Andric                            __found = true;
24790b57cec5SDimitry Andric                            goto __exit;
24800b57cec5SDimitry Andric                        }
24810b57cec5SDimitry Andric                    }
24820b57cec5SDimitry Andric                    if (__collate_ && !__ranges_.empty())
24830b57cec5SDimitry Andric                    {
24840b57cec5SDimitry Andric                        string_type __s2 = __traits_.transform(&__ch2.first,
24850b57cec5SDimitry Andric                                                               &__ch2.first + 2);
24860b57cec5SDimitry Andric                        for (size_t __i = 0; __i < __ranges_.size(); ++__i)
24870b57cec5SDimitry Andric                        {
24880b57cec5SDimitry Andric                            if (__ranges_[__i].first <= __s2 &&
24890b57cec5SDimitry Andric                                __s2 <= __ranges_[__i].second)
24900b57cec5SDimitry Andric                            {
24910b57cec5SDimitry Andric                                __found = true;
24920b57cec5SDimitry Andric                                goto __exit;
24930b57cec5SDimitry Andric                            }
24940b57cec5SDimitry Andric                        }
24950b57cec5SDimitry Andric                    }
24960b57cec5SDimitry Andric                    if (!__equivalences_.empty())
24970b57cec5SDimitry Andric                    {
24980b57cec5SDimitry Andric                        string_type __s2 = __traits_.transform_primary(&__ch2.first,
24990b57cec5SDimitry Andric                                                                       &__ch2.first + 2);
25000b57cec5SDimitry Andric                        for (size_t __i = 0; __i < __equivalences_.size(); ++__i)
25010b57cec5SDimitry Andric                        {
25020b57cec5SDimitry Andric                            if (__s2 == __equivalences_[__i])
25030b57cec5SDimitry Andric                            {
25040b57cec5SDimitry Andric                                __found = true;
25050b57cec5SDimitry Andric                                goto __exit;
25060b57cec5SDimitry Andric                            }
25070b57cec5SDimitry Andric                        }
25080b57cec5SDimitry Andric                    }
25090b57cec5SDimitry Andric                    if (__traits_.isctype(__ch2.first, __mask_) &&
25100b57cec5SDimitry Andric                        __traits_.isctype(__ch2.second, __mask_))
25110b57cec5SDimitry Andric                    {
25120b57cec5SDimitry Andric                        __found = true;
25130b57cec5SDimitry Andric                        goto __exit;
25140b57cec5SDimitry Andric                    }
25150b57cec5SDimitry Andric                    if (!__traits_.isctype(__ch2.first, __neg_mask_) &&
25160b57cec5SDimitry Andric                        !__traits_.isctype(__ch2.second, __neg_mask_))
25170b57cec5SDimitry Andric                    {
25180b57cec5SDimitry Andric                        __found = true;
25190b57cec5SDimitry Andric                        goto __exit;
25200b57cec5SDimitry Andric                    }
25210b57cec5SDimitry Andric                    goto __exit;
25220b57cec5SDimitry Andric                }
25230b57cec5SDimitry Andric            }
25240b57cec5SDimitry Andric        }
25250b57cec5SDimitry Andric        // test *__s.__current_ as not a digraph
25260b57cec5SDimitry Andric        _CharT __ch = *__s.__current_;
25270b57cec5SDimitry Andric        if (__icase_)
25280b57cec5SDimitry Andric            __ch = __traits_.translate_nocase(__ch);
25290b57cec5SDimitry Andric        else if (__collate_)
25300b57cec5SDimitry Andric            __ch = __traits_.translate(__ch);
25310b57cec5SDimitry Andric        for (size_t __i = 0; __i < __chars_.size(); ++__i)
25320b57cec5SDimitry Andric        {
25330b57cec5SDimitry Andric            if (__ch == __chars_[__i])
25340b57cec5SDimitry Andric            {
25350b57cec5SDimitry Andric                __found = true;
25360b57cec5SDimitry Andric                goto __exit;
25370b57cec5SDimitry Andric            }
25380b57cec5SDimitry Andric        }
25390b57cec5SDimitry Andric        // When there's at least one of __neg_chars_ and __neg_mask_, the set
25400b57cec5SDimitry Andric        // of "__found" chars is
25410b57cec5SDimitry Andric        //   union(complement(union(__neg_chars_, __neg_mask_)),
25420b57cec5SDimitry Andric        //         other cases...)
25430b57cec5SDimitry Andric        //
25440b57cec5SDimitry Andric        // It doesn't make sense to check this when there are no __neg_chars_
25450b57cec5SDimitry Andric        // and no __neg_mask_.
25460b57cec5SDimitry Andric        if (!(__neg_mask_ == 0 && __neg_chars_.empty()))
25470b57cec5SDimitry Andric        {
25480b57cec5SDimitry Andric            const bool __in_neg_mask = __traits_.isctype(__ch, __neg_mask_);
25490b57cec5SDimitry Andric          const bool __in_neg_chars =
2550e8d8bef9SDimitry Andric              _VSTD::find(__neg_chars_.begin(), __neg_chars_.end(), __ch) !=
25510b57cec5SDimitry Andric              __neg_chars_.end();
25520b57cec5SDimitry Andric          if (!(__in_neg_mask || __in_neg_chars))
25530b57cec5SDimitry Andric          {
25540b57cec5SDimitry Andric            __found = true;
25550b57cec5SDimitry Andric            goto __exit;
25560b57cec5SDimitry Andric          }
25570b57cec5SDimitry Andric        }
25580b57cec5SDimitry Andric        if (!__ranges_.empty())
25590b57cec5SDimitry Andric        {
25600b57cec5SDimitry Andric            string_type __s2 = __collate_ ?
25610b57cec5SDimitry Andric                                   __traits_.transform(&__ch, &__ch + 1) :
25620b57cec5SDimitry Andric                                   string_type(1, __ch);
25630b57cec5SDimitry Andric            for (size_t __i = 0; __i < __ranges_.size(); ++__i)
25640b57cec5SDimitry Andric            {
25650b57cec5SDimitry Andric                if (__ranges_[__i].first <= __s2 && __s2 <= __ranges_[__i].second)
25660b57cec5SDimitry Andric                {
25670b57cec5SDimitry Andric                    __found = true;
25680b57cec5SDimitry Andric                    goto __exit;
25690b57cec5SDimitry Andric                }
25700b57cec5SDimitry Andric            }
25710b57cec5SDimitry Andric        }
25720b57cec5SDimitry Andric        if (!__equivalences_.empty())
25730b57cec5SDimitry Andric        {
25740b57cec5SDimitry Andric            string_type __s2 = __traits_.transform_primary(&__ch, &__ch + 1);
25750b57cec5SDimitry Andric            for (size_t __i = 0; __i < __equivalences_.size(); ++__i)
25760b57cec5SDimitry Andric            {
25770b57cec5SDimitry Andric                if (__s2 == __equivalences_[__i])
25780b57cec5SDimitry Andric                {
25790b57cec5SDimitry Andric                    __found = true;
25800b57cec5SDimitry Andric                    goto __exit;
25810b57cec5SDimitry Andric                }
25820b57cec5SDimitry Andric            }
25830b57cec5SDimitry Andric        }
25840b57cec5SDimitry Andric        if (__traits_.isctype(__ch, __mask_))
25850b57cec5SDimitry Andric        {
25860b57cec5SDimitry Andric            __found = true;
25870b57cec5SDimitry Andric            goto __exit;
25880b57cec5SDimitry Andric        }
25890b57cec5SDimitry Andric    }
25900b57cec5SDimitry Andric    else
25910b57cec5SDimitry Andric        __found = __negate_;  // force reject
25920b57cec5SDimitry Andric__exit:
25930b57cec5SDimitry Andric    if (__found != __negate_)
25940b57cec5SDimitry Andric    {
25950b57cec5SDimitry Andric        __s.__do_ = __state::__accept_and_consume;
25960b57cec5SDimitry Andric        __s.__current_ += __consumed;
25970b57cec5SDimitry Andric        __s.__node_ = this->first();
25980b57cec5SDimitry Andric    }
25990b57cec5SDimitry Andric    else
26000b57cec5SDimitry Andric    {
26010b57cec5SDimitry Andric        __s.__do_ = __state::__reject;
26020b57cec5SDimitry Andric        __s.__node_ = nullptr;
26030b57cec5SDimitry Andric    }
26040b57cec5SDimitry Andric}
26050b57cec5SDimitry Andric
26060b57cec5SDimitry Andrictemplate <class _CharT, class _Traits> class __lookahead;
26070b57cec5SDimitry Andric
26080b57cec5SDimitry Andrictemplate <class _CharT, class _Traits = regex_traits<_CharT> >
2609e8d8bef9SDimitry Andric    class _LIBCPP_TEMPLATE_VIS basic_regex;
2610e8d8bef9SDimitry Andric
2611e8d8bef9SDimitry Andrictypedef basic_regex<char>    regex;
2612349cc55cSDimitry Andric#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
2613e8d8bef9SDimitry Andrictypedef basic_regex<wchar_t> wregex;
2614349cc55cSDimitry Andric#endif
2615e8d8bef9SDimitry Andric
2616e8d8bef9SDimitry Andrictemplate <class _CharT, class _Traits>
2617e8d8bef9SDimitry Andricclass
2618e8d8bef9SDimitry Andric    _LIBCPP_TEMPLATE_VIS
2619e8d8bef9SDimitry Andric    _LIBCPP_PREFERRED_NAME(regex)
2620349cc55cSDimitry Andric    _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wregex))
2621e8d8bef9SDimitry Andric    basic_regex
26220b57cec5SDimitry Andric{
26230b57cec5SDimitry Andricpublic:
26240b57cec5SDimitry Andric    // types:
26250b57cec5SDimitry Andric    typedef _CharT                              value_type;
26260b57cec5SDimitry Andric    typedef _Traits                             traits_type;
26270b57cec5SDimitry Andric    typedef typename _Traits::string_type       string_type;
26280b57cec5SDimitry Andric    typedef regex_constants::syntax_option_type flag_type;
26290b57cec5SDimitry Andric    typedef typename _Traits::locale_type       locale_type;
26300b57cec5SDimitry Andric
26310b57cec5SDimitry Andricprivate:
26320b57cec5SDimitry Andric    _Traits   __traits_;
26330b57cec5SDimitry Andric    flag_type __flags_;
26340b57cec5SDimitry Andric    unsigned __marked_count_;
26350b57cec5SDimitry Andric    unsigned __loop_count_;
26360b57cec5SDimitry Andric    int __open_count_;
26370b57cec5SDimitry Andric    shared_ptr<__empty_state<_CharT> > __start_;
26380b57cec5SDimitry Andric    __owns_one_state<_CharT>* __end_;
26390b57cec5SDimitry Andric
26400b57cec5SDimitry Andric    typedef _VSTD::__state<_CharT> __state;
26410b57cec5SDimitry Andric    typedef _VSTD::__node<_CharT> __node;
26420b57cec5SDimitry Andric
26430b57cec5SDimitry Andricpublic:
26440b57cec5SDimitry Andric    // constants:
26450b57cec5SDimitry Andric    static const regex_constants::syntax_option_type icase = regex_constants::icase;
26460b57cec5SDimitry Andric    static const regex_constants::syntax_option_type nosubs = regex_constants::nosubs;
26470b57cec5SDimitry Andric    static const regex_constants::syntax_option_type optimize = regex_constants::optimize;
26480b57cec5SDimitry Andric    static const regex_constants::syntax_option_type collate = regex_constants::collate;
26490b57cec5SDimitry Andric    static const regex_constants::syntax_option_type ECMAScript = regex_constants::ECMAScript;
26500b57cec5SDimitry Andric    static const regex_constants::syntax_option_type basic = regex_constants::basic;
26510b57cec5SDimitry Andric    static const regex_constants::syntax_option_type extended = regex_constants::extended;
26520b57cec5SDimitry Andric    static const regex_constants::syntax_option_type awk = regex_constants::awk;
26530b57cec5SDimitry Andric    static const regex_constants::syntax_option_type grep = regex_constants::grep;
26540b57cec5SDimitry Andric    static const regex_constants::syntax_option_type egrep = regex_constants::egrep;
2655e8d8bef9SDimitry Andric    static const regex_constants::syntax_option_type multiline = regex_constants::multiline;
26560b57cec5SDimitry Andric
26570b57cec5SDimitry Andric    // construct/copy/destroy:
26580b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
26590b57cec5SDimitry Andric    basic_regex()
26600b57cec5SDimitry Andric        : __flags_(regex_constants::ECMAScript), __marked_count_(0), __loop_count_(0), __open_count_(0),
2661e8d8bef9SDimitry Andric          __end_(nullptr)
26620b57cec5SDimitry Andric        {}
26630b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
26640b57cec5SDimitry Andric    explicit basic_regex(const value_type* __p, flag_type __f = regex_constants::ECMAScript)
26650b57cec5SDimitry Andric        : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0),
2666e8d8bef9SDimitry Andric          __end_(nullptr)
26670b57cec5SDimitry Andric        {
2668480093f4SDimitry Andric        __init(__p, __p + __traits_.length(__p));
26690b57cec5SDimitry Andric        }
26700b57cec5SDimitry Andric
26710b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
26720b57cec5SDimitry Andric    basic_regex(const value_type* __p, size_t __len, flag_type __f = regex_constants::ECMAScript)
26730b57cec5SDimitry Andric        : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0),
2674e8d8bef9SDimitry Andric          __end_(nullptr)
26750b57cec5SDimitry Andric        {
2676480093f4SDimitry Andric        __init(__p, __p + __len);
26770b57cec5SDimitry Andric        }
26780b57cec5SDimitry Andric
26790b57cec5SDimitry Andric//     basic_regex(const basic_regex&) = default;
26800b57cec5SDimitry Andric//     basic_regex(basic_regex&&) = default;
26810b57cec5SDimitry Andric    template <class _ST, class _SA>
26820b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
26830b57cec5SDimitry Andric        explicit basic_regex(const basic_string<value_type, _ST, _SA>& __p,
26840b57cec5SDimitry Andric                             flag_type __f = regex_constants::ECMAScript)
26850b57cec5SDimitry Andric        : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0),
2686e8d8bef9SDimitry Andric          __end_(nullptr)
26870b57cec5SDimitry Andric        {
2688480093f4SDimitry Andric        __init(__p.begin(), __p.end());
26890b57cec5SDimitry Andric        }
26900b57cec5SDimitry Andric
26910b57cec5SDimitry Andric    template <class _ForwardIterator>
26920b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
26930b57cec5SDimitry Andric        basic_regex(_ForwardIterator __first, _ForwardIterator __last,
26940b57cec5SDimitry Andric                    flag_type __f = regex_constants::ECMAScript)
26950b57cec5SDimitry Andric        : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0),
2696e8d8bef9SDimitry Andric          __end_(nullptr)
26970b57cec5SDimitry Andric        {
2698480093f4SDimitry Andric        __init(__first, __last);
26990b57cec5SDimitry Andric        }
27000b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
27010b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
27020b57cec5SDimitry Andric    basic_regex(initializer_list<value_type> __il,
27030b57cec5SDimitry Andric                flag_type __f = regex_constants::ECMAScript)
27040b57cec5SDimitry Andric        : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0),
2705e8d8bef9SDimitry Andric          __end_(nullptr)
27060b57cec5SDimitry Andric        {
2707480093f4SDimitry Andric        __init(__il.begin(), __il.end());
27080b57cec5SDimitry Andric        }
27090b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG
27100b57cec5SDimitry Andric
27110b57cec5SDimitry Andric//    ~basic_regex() = default;
27120b57cec5SDimitry Andric
27130b57cec5SDimitry Andric//     basic_regex& operator=(const basic_regex&) = default;
27140b57cec5SDimitry Andric//     basic_regex& operator=(basic_regex&&) = default;
27150b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
27160b57cec5SDimitry Andric    basic_regex& operator=(const value_type* __p)
27170b57cec5SDimitry Andric        {return assign(__p);}
27180b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
27190b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
27200b57cec5SDimitry Andric    basic_regex& operator=(initializer_list<value_type> __il)
27210b57cec5SDimitry Andric        {return assign(__il);}
27220b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG
27230b57cec5SDimitry Andric    template <class _ST, class _SA>
27240b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
27250b57cec5SDimitry Andric        basic_regex& operator=(const basic_string<value_type, _ST, _SA>& __p)
27260b57cec5SDimitry Andric        {return assign(__p);}
27270b57cec5SDimitry Andric
27280b57cec5SDimitry Andric    // assign:
27290b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
27300b57cec5SDimitry Andric    basic_regex& assign(const basic_regex& __that)
27310b57cec5SDimitry Andric        {return *this = __that;}
27320b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
27330b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
27340b57cec5SDimitry Andric    basic_regex& assign(basic_regex&& __that) _NOEXCEPT
27350b57cec5SDimitry Andric        {return *this = _VSTD::move(__that);}
27360b57cec5SDimitry Andric#endif
27370b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
27380b57cec5SDimitry Andric    basic_regex& assign(const value_type* __p, flag_type __f = regex_constants::ECMAScript)
27390b57cec5SDimitry Andric        {return assign(__p, __p + __traits_.length(__p), __f);}
27400b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
2741e40139ffSDimitry Andric    basic_regex& assign(const value_type* __p, size_t __len, flag_type __f = regex_constants::ECMAScript)
27420b57cec5SDimitry Andric        {return assign(__p, __p + __len, __f);}
27430b57cec5SDimitry Andric    template <class _ST, class _SA>
27440b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
27450b57cec5SDimitry Andric        basic_regex& assign(const basic_string<value_type, _ST, _SA>& __s,
27460b57cec5SDimitry Andric                            flag_type __f = regex_constants::ECMAScript)
27470b57cec5SDimitry Andric            {return assign(__s.begin(), __s.end(), __f);}
27480b57cec5SDimitry Andric
27490b57cec5SDimitry Andric    template <class _InputIterator>
27500b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
2751753f127fSDimitry Andric        typename enable_if<__is_exactly_cpp17_input_iterator<_InputIterator>::value, basic_regex&>::type
27520b57cec5SDimitry Andric        assign(_InputIterator __first, _InputIterator __last,
27530b57cec5SDimitry Andric                            flag_type __f = regex_constants::ECMAScript)
27540b57cec5SDimitry Andric        {
27550b57cec5SDimitry Andric            basic_string<_CharT> __t(__first, __last);
27560b57cec5SDimitry Andric            return assign(__t.begin(), __t.end(), __f);
27570b57cec5SDimitry Andric        }
27580b57cec5SDimitry Andric
27590b57cec5SDimitry Andricprivate:
27600b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
27610b57cec5SDimitry Andric    void __member_init(flag_type __f)
27620b57cec5SDimitry Andric    {
27630b57cec5SDimitry Andric        __flags_ = __f;
27640b57cec5SDimitry Andric        __marked_count_ = 0;
27650b57cec5SDimitry Andric        __loop_count_ = 0;
27660b57cec5SDimitry Andric        __open_count_ = 0;
27670b57cec5SDimitry Andric        __end_ = nullptr;
27680b57cec5SDimitry Andric    }
27690b57cec5SDimitry Andricpublic:
27700b57cec5SDimitry Andric
27710b57cec5SDimitry Andric    template <class _ForwardIterator>
27720b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
27730b57cec5SDimitry Andric        typename enable_if
27740b57cec5SDimitry Andric        <
2775480093f4SDimitry Andric            __is_cpp17_forward_iterator<_ForwardIterator>::value,
27760b57cec5SDimitry Andric            basic_regex&
27770b57cec5SDimitry Andric        >::type
27780b57cec5SDimitry Andric        assign(_ForwardIterator __first, _ForwardIterator __last,
27790b57cec5SDimitry Andric                            flag_type __f = regex_constants::ECMAScript)
27800b57cec5SDimitry Andric        {
27810b57cec5SDimitry Andric            return assign(basic_regex(__first, __last, __f));
27820b57cec5SDimitry Andric        }
27830b57cec5SDimitry Andric
27840b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
27850b57cec5SDimitry Andric
27860b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
27870b57cec5SDimitry Andric    basic_regex& assign(initializer_list<value_type> __il,
27880b57cec5SDimitry Andric                        flag_type __f = regex_constants::ECMAScript)
27890b57cec5SDimitry Andric        {return assign(__il.begin(), __il.end(), __f);}
27900b57cec5SDimitry Andric
27910b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG
27920b57cec5SDimitry Andric
27930b57cec5SDimitry Andric    // const operations:
27940b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
27950b57cec5SDimitry Andric    unsigned mark_count() const {return __marked_count_;}
27960b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
27970b57cec5SDimitry Andric    flag_type flags() const {return __flags_;}
27980b57cec5SDimitry Andric
27990b57cec5SDimitry Andric    // locale:
28000b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
28010b57cec5SDimitry Andric    locale_type imbue(locale_type __loc)
28020b57cec5SDimitry Andric    {
28030b57cec5SDimitry Andric        __member_init(ECMAScript);
28040b57cec5SDimitry Andric        __start_.reset();
28050b57cec5SDimitry Andric        return __traits_.imbue(__loc);
28060b57cec5SDimitry Andric    }
28070b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
28080b57cec5SDimitry Andric    locale_type getloc() const {return __traits_.getloc();}
28090b57cec5SDimitry Andric
28100b57cec5SDimitry Andric    // swap:
28110b57cec5SDimitry Andric    void swap(basic_regex& __r);
28120b57cec5SDimitry Andric
28130b57cec5SDimitry Andricprivate:
28140b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
28150b57cec5SDimitry Andric    unsigned __loop_count() const {return __loop_count_;}
28160b57cec5SDimitry Andric
2817e8d8bef9SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
2818e8d8bef9SDimitry Andric    bool __use_multiline() const
2819e8d8bef9SDimitry Andric    {
2820e8d8bef9SDimitry Andric        return __get_grammar(__flags_) == ECMAScript && (__flags_ & multiline);
2821e8d8bef9SDimitry Andric    }
2822e8d8bef9SDimitry Andric
28230b57cec5SDimitry Andric    template <class _ForwardIterator>
2824480093f4SDimitry Andric        void
2825480093f4SDimitry Andric        __init(_ForwardIterator __first, _ForwardIterator __last);
2826480093f4SDimitry Andric    template <class _ForwardIterator>
28270b57cec5SDimitry Andric        _ForwardIterator
28280b57cec5SDimitry Andric        __parse(_ForwardIterator __first, _ForwardIterator __last);
28290b57cec5SDimitry Andric    template <class _ForwardIterator>
28300b57cec5SDimitry Andric        _ForwardIterator
28310b57cec5SDimitry Andric        __parse_basic_reg_exp(_ForwardIterator __first, _ForwardIterator __last);
28320b57cec5SDimitry Andric    template <class _ForwardIterator>
28330b57cec5SDimitry Andric        _ForwardIterator
28340b57cec5SDimitry Andric        __parse_RE_expression(_ForwardIterator __first, _ForwardIterator __last);
28350b57cec5SDimitry Andric    template <class _ForwardIterator>
28360b57cec5SDimitry Andric        _ForwardIterator
28370b57cec5SDimitry Andric        __parse_simple_RE(_ForwardIterator __first, _ForwardIterator __last);
28380b57cec5SDimitry Andric    template <class _ForwardIterator>
28390b57cec5SDimitry Andric        _ForwardIterator
28400b57cec5SDimitry Andric        __parse_nondupl_RE(_ForwardIterator __first, _ForwardIterator __last);
28410b57cec5SDimitry Andric    template <class _ForwardIterator>
28420b57cec5SDimitry Andric        _ForwardIterator
28430b57cec5SDimitry Andric        __parse_one_char_or_coll_elem_RE(_ForwardIterator __first, _ForwardIterator __last);
28440b57cec5SDimitry Andric    template <class _ForwardIterator>
28450b57cec5SDimitry Andric        _ForwardIterator
28460b57cec5SDimitry Andric        __parse_Back_open_paren(_ForwardIterator __first, _ForwardIterator __last);
28470b57cec5SDimitry Andric    template <class _ForwardIterator>
28480b57cec5SDimitry Andric        _ForwardIterator
28490b57cec5SDimitry Andric        __parse_Back_close_paren(_ForwardIterator __first, _ForwardIterator __last);
28500b57cec5SDimitry Andric    template <class _ForwardIterator>
28510b57cec5SDimitry Andric        _ForwardIterator
28520b57cec5SDimitry Andric        __parse_Back_open_brace(_ForwardIterator __first, _ForwardIterator __last);
28530b57cec5SDimitry Andric    template <class _ForwardIterator>
28540b57cec5SDimitry Andric        _ForwardIterator
28550b57cec5SDimitry Andric        __parse_Back_close_brace(_ForwardIterator __first, _ForwardIterator __last);
28560b57cec5SDimitry Andric    template <class _ForwardIterator>
28570b57cec5SDimitry Andric        _ForwardIterator
28580b57cec5SDimitry Andric        __parse_BACKREF(_ForwardIterator __first, _ForwardIterator __last);
28590b57cec5SDimitry Andric    template <class _ForwardIterator>
28600b57cec5SDimitry Andric        _ForwardIterator
28610b57cec5SDimitry Andric        __parse_ORD_CHAR(_ForwardIterator __first, _ForwardIterator __last);
28620b57cec5SDimitry Andric    template <class _ForwardIterator>
28630b57cec5SDimitry Andric        _ForwardIterator
28640b57cec5SDimitry Andric        __parse_QUOTED_CHAR(_ForwardIterator __first, _ForwardIterator __last);
28650b57cec5SDimitry Andric    template <class _ForwardIterator>
28660b57cec5SDimitry Andric        _ForwardIterator
28670b57cec5SDimitry Andric        __parse_RE_dupl_symbol(_ForwardIterator __first, _ForwardIterator __last,
28680b57cec5SDimitry Andric                               __owns_one_state<_CharT>* __s,
28690b57cec5SDimitry Andric                               unsigned __mexp_begin, unsigned __mexp_end);
28700b57cec5SDimitry Andric    template <class _ForwardIterator>
28710b57cec5SDimitry Andric        _ForwardIterator
28720b57cec5SDimitry Andric        __parse_ERE_dupl_symbol(_ForwardIterator __first, _ForwardIterator __last,
28730b57cec5SDimitry Andric                                __owns_one_state<_CharT>* __s,
28740b57cec5SDimitry Andric                                unsigned __mexp_begin, unsigned __mexp_end);
28750b57cec5SDimitry Andric    template <class _ForwardIterator>
28760b57cec5SDimitry Andric        _ForwardIterator
28770b57cec5SDimitry Andric        __parse_bracket_expression(_ForwardIterator __first, _ForwardIterator __last);
28780b57cec5SDimitry Andric    template <class _ForwardIterator>
28790b57cec5SDimitry Andric        _ForwardIterator
28800b57cec5SDimitry Andric        __parse_follow_list(_ForwardIterator __first, _ForwardIterator __last,
28810b57cec5SDimitry Andric                            __bracket_expression<_CharT, _Traits>* __ml);
28820b57cec5SDimitry Andric    template <class _ForwardIterator>
28830b57cec5SDimitry Andric        _ForwardIterator
28840b57cec5SDimitry Andric        __parse_expression_term(_ForwardIterator __first, _ForwardIterator __last,
28850b57cec5SDimitry Andric                                __bracket_expression<_CharT, _Traits>* __ml);
28860b57cec5SDimitry Andric    template <class _ForwardIterator>
28870b57cec5SDimitry Andric        _ForwardIterator
28880b57cec5SDimitry Andric        __parse_equivalence_class(_ForwardIterator __first, _ForwardIterator __last,
28890b57cec5SDimitry Andric                                  __bracket_expression<_CharT, _Traits>* __ml);
28900b57cec5SDimitry Andric    template <class _ForwardIterator>
28910b57cec5SDimitry Andric        _ForwardIterator
28920b57cec5SDimitry Andric        __parse_character_class(_ForwardIterator __first, _ForwardIterator __last,
28930b57cec5SDimitry Andric                                __bracket_expression<_CharT, _Traits>* __ml);
28940b57cec5SDimitry Andric    template <class _ForwardIterator>
28950b57cec5SDimitry Andric        _ForwardIterator
28960b57cec5SDimitry Andric        __parse_collating_symbol(_ForwardIterator __first, _ForwardIterator __last,
28970b57cec5SDimitry Andric                                 basic_string<_CharT>& __col_sym);
28980b57cec5SDimitry Andric    template <class _ForwardIterator>
28990b57cec5SDimitry Andric        _ForwardIterator
29000b57cec5SDimitry Andric        __parse_DUP_COUNT(_ForwardIterator __first, _ForwardIterator __last, int& __c);
29010b57cec5SDimitry Andric    template <class _ForwardIterator>
29020b57cec5SDimitry Andric        _ForwardIterator
29030b57cec5SDimitry Andric        __parse_extended_reg_exp(_ForwardIterator __first, _ForwardIterator __last);
29040b57cec5SDimitry Andric    template <class _ForwardIterator>
29050b57cec5SDimitry Andric        _ForwardIterator
29060b57cec5SDimitry Andric        __parse_ERE_branch(_ForwardIterator __first, _ForwardIterator __last);
29070b57cec5SDimitry Andric    template <class _ForwardIterator>
29080b57cec5SDimitry Andric        _ForwardIterator
29090b57cec5SDimitry Andric        __parse_ERE_expression(_ForwardIterator __first, _ForwardIterator __last);
29100b57cec5SDimitry Andric    template <class _ForwardIterator>
29110b57cec5SDimitry Andric        _ForwardIterator
29120b57cec5SDimitry Andric        __parse_one_char_or_coll_elem_ERE(_ForwardIterator __first, _ForwardIterator __last);
29130b57cec5SDimitry Andric    template <class _ForwardIterator>
29140b57cec5SDimitry Andric        _ForwardIterator
29150b57cec5SDimitry Andric        __parse_ORD_CHAR_ERE(_ForwardIterator __first, _ForwardIterator __last);
29160b57cec5SDimitry Andric    template <class _ForwardIterator>
29170b57cec5SDimitry Andric        _ForwardIterator
29180b57cec5SDimitry Andric        __parse_QUOTED_CHAR_ERE(_ForwardIterator __first, _ForwardIterator __last);
29190b57cec5SDimitry Andric    template <class _ForwardIterator>
29200b57cec5SDimitry Andric        _ForwardIterator
29210b57cec5SDimitry Andric        __parse_ecma_exp(_ForwardIterator __first, _ForwardIterator __last);
29220b57cec5SDimitry Andric    template <class _ForwardIterator>
29230b57cec5SDimitry Andric        _ForwardIterator
29240b57cec5SDimitry Andric        __parse_alternative(_ForwardIterator __first, _ForwardIterator __last);
29250b57cec5SDimitry Andric    template <class _ForwardIterator>
29260b57cec5SDimitry Andric        _ForwardIterator
29270b57cec5SDimitry Andric        __parse_term(_ForwardIterator __first, _ForwardIterator __last);
29280b57cec5SDimitry Andric    template <class _ForwardIterator>
29290b57cec5SDimitry Andric        _ForwardIterator
29300b57cec5SDimitry Andric        __parse_assertion(_ForwardIterator __first, _ForwardIterator __last);
29310b57cec5SDimitry Andric    template <class _ForwardIterator>
29320b57cec5SDimitry Andric        _ForwardIterator
29330b57cec5SDimitry Andric        __parse_atom(_ForwardIterator __first, _ForwardIterator __last);
29340b57cec5SDimitry Andric    template <class _ForwardIterator>
29350b57cec5SDimitry Andric        _ForwardIterator
29360b57cec5SDimitry Andric        __parse_atom_escape(_ForwardIterator __first, _ForwardIterator __last);
29370b57cec5SDimitry Andric    template <class _ForwardIterator>
29380b57cec5SDimitry Andric        _ForwardIterator
29390b57cec5SDimitry Andric        __parse_decimal_escape(_ForwardIterator __first, _ForwardIterator __last);
29400b57cec5SDimitry Andric    template <class _ForwardIterator>
29410b57cec5SDimitry Andric        _ForwardIterator
29420b57cec5SDimitry Andric        __parse_character_class_escape(_ForwardIterator __first, _ForwardIterator __last);
29430b57cec5SDimitry Andric    template <class _ForwardIterator>
29440b57cec5SDimitry Andric        _ForwardIterator
29450b57cec5SDimitry Andric        __parse_character_escape(_ForwardIterator __first, _ForwardIterator __last,
29460b57cec5SDimitry Andric                                 basic_string<_CharT>* __str = nullptr);
29470b57cec5SDimitry Andric    template <class _ForwardIterator>
29480b57cec5SDimitry Andric        _ForwardIterator
29490b57cec5SDimitry Andric        __parse_pattern_character(_ForwardIterator __first, _ForwardIterator __last);
29500b57cec5SDimitry Andric    template <class _ForwardIterator>
29510b57cec5SDimitry Andric        _ForwardIterator
29520b57cec5SDimitry Andric        __parse_grep(_ForwardIterator __first, _ForwardIterator __last);
29530b57cec5SDimitry Andric    template <class _ForwardIterator>
29540b57cec5SDimitry Andric        _ForwardIterator
29550b57cec5SDimitry Andric        __parse_egrep(_ForwardIterator __first, _ForwardIterator __last);
29560b57cec5SDimitry Andric    template <class _ForwardIterator>
29570b57cec5SDimitry Andric        _ForwardIterator
29580b57cec5SDimitry Andric        __parse_class_escape(_ForwardIterator __first, _ForwardIterator __last,
29590b57cec5SDimitry Andric                          basic_string<_CharT>& __str,
29600b57cec5SDimitry Andric                          __bracket_expression<_CharT, _Traits>* __ml);
29610b57cec5SDimitry Andric    template <class _ForwardIterator>
29620b57cec5SDimitry Andric        _ForwardIterator
29630b57cec5SDimitry Andric        __parse_awk_escape(_ForwardIterator __first, _ForwardIterator __last,
29640b57cec5SDimitry Andric                          basic_string<_CharT>* __str = nullptr);
29650b57cec5SDimitry Andric
2966753f127fSDimitry Andric    bool __test_back_ref(_CharT);
29675ffd83dbSDimitry Andric
29680b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
29690b57cec5SDimitry Andric    void __push_l_anchor();
29700b57cec5SDimitry Andric    void __push_r_anchor();
29710b57cec5SDimitry Andric    void __push_match_any();
29720b57cec5SDimitry Andric    void __push_match_any_but_newline();
29730b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
29740b57cec5SDimitry Andric    void __push_greedy_inf_repeat(size_t __min, __owns_one_state<_CharT>* __s,
29750b57cec5SDimitry Andric                                  unsigned __mexp_begin = 0, unsigned __mexp_end = 0)
29760b57cec5SDimitry Andric        {__push_loop(__min, numeric_limits<size_t>::max(), __s,
29770b57cec5SDimitry Andric                     __mexp_begin, __mexp_end);}
29780b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
29790b57cec5SDimitry Andric    void __push_nongreedy_inf_repeat(size_t __min, __owns_one_state<_CharT>* __s,
29800b57cec5SDimitry Andric                                  unsigned __mexp_begin = 0, unsigned __mexp_end = 0)
29810b57cec5SDimitry Andric        {__push_loop(__min, numeric_limits<size_t>::max(), __s,
29820b57cec5SDimitry Andric                     __mexp_begin, __mexp_end, false);}
29830b57cec5SDimitry Andric    void __push_loop(size_t __min, size_t __max, __owns_one_state<_CharT>* __s,
29840b57cec5SDimitry Andric                     size_t __mexp_begin = 0, size_t __mexp_end = 0,
29850b57cec5SDimitry Andric                     bool __greedy = true);
29860b57cec5SDimitry Andric    __bracket_expression<_CharT, _Traits>* __start_matching_list(bool __negate);
29870b57cec5SDimitry Andric    void __push_char(value_type __c);
29880b57cec5SDimitry Andric    void __push_back_ref(int __i);
29890b57cec5SDimitry Andric    void __push_alternation(__owns_one_state<_CharT>* __sa,
29900b57cec5SDimitry Andric                            __owns_one_state<_CharT>* __sb);
29910b57cec5SDimitry Andric    void __push_begin_marked_subexpression();
29920b57cec5SDimitry Andric    void __push_end_marked_subexpression(unsigned);
29930b57cec5SDimitry Andric    void __push_empty();
29940b57cec5SDimitry Andric    void __push_word_boundary(bool);
29950b57cec5SDimitry Andric    void __push_lookahead(const basic_regex&, bool, unsigned);
29960b57cec5SDimitry Andric
29970b57cec5SDimitry Andric    template <class _Allocator>
29980b57cec5SDimitry Andric        bool
29990b57cec5SDimitry Andric        __search(const _CharT* __first, const _CharT* __last,
30000b57cec5SDimitry Andric                 match_results<const _CharT*, _Allocator>& __m,
30010b57cec5SDimitry Andric                 regex_constants::match_flag_type __flags) const;
30020b57cec5SDimitry Andric
30030b57cec5SDimitry Andric    template <class _Allocator>
30040b57cec5SDimitry Andric        bool
30050b57cec5SDimitry Andric        __match_at_start(const _CharT* __first, const _CharT* __last,
30060b57cec5SDimitry Andric                 match_results<const _CharT*, _Allocator>& __m,
30070b57cec5SDimitry Andric                 regex_constants::match_flag_type __flags, bool) const;
30080b57cec5SDimitry Andric    template <class _Allocator>
30090b57cec5SDimitry Andric        bool
30100b57cec5SDimitry Andric        __match_at_start_ecma(const _CharT* __first, const _CharT* __last,
30110b57cec5SDimitry Andric                 match_results<const _CharT*, _Allocator>& __m,
30120b57cec5SDimitry Andric                 regex_constants::match_flag_type __flags, bool) const;
30130b57cec5SDimitry Andric    template <class _Allocator>
30140b57cec5SDimitry Andric        bool
30150b57cec5SDimitry Andric        __match_at_start_posix_nosubs(const _CharT* __first, const _CharT* __last,
30160b57cec5SDimitry Andric                 match_results<const _CharT*, _Allocator>& __m,
30170b57cec5SDimitry Andric                 regex_constants::match_flag_type __flags, bool) const;
30180b57cec5SDimitry Andric    template <class _Allocator>
30190b57cec5SDimitry Andric        bool
30200b57cec5SDimitry Andric        __match_at_start_posix_subs(const _CharT* __first, const _CharT* __last,
30210b57cec5SDimitry Andric                 match_results<const _CharT*, _Allocator>& __m,
30220b57cec5SDimitry Andric                 regex_constants::match_flag_type __flags, bool) const;
30230b57cec5SDimitry Andric
30240b57cec5SDimitry Andric    template <class _Bp, class _Ap, class _Cp, class _Tp>
30250b57cec5SDimitry Andric    friend
30260b57cec5SDimitry Andric    bool
30270b57cec5SDimitry Andric    regex_search(_Bp, _Bp, match_results<_Bp, _Ap>&, const basic_regex<_Cp, _Tp>&,
30280b57cec5SDimitry Andric                 regex_constants::match_flag_type);
30290b57cec5SDimitry Andric
30300b57cec5SDimitry Andric    template <class _Ap, class _Cp, class _Tp>
30310b57cec5SDimitry Andric    friend
30320b57cec5SDimitry Andric    bool
30330b57cec5SDimitry Andric    regex_search(const _Cp*, const _Cp*, match_results<const _Cp*, _Ap>&,
30340b57cec5SDimitry Andric                 const basic_regex<_Cp, _Tp>&, regex_constants::match_flag_type);
30350b57cec5SDimitry Andric
30360b57cec5SDimitry Andric    template <class _Bp, class _Cp, class _Tp>
30370b57cec5SDimitry Andric    friend
30380b57cec5SDimitry Andric    bool
30390b57cec5SDimitry Andric    regex_search(_Bp, _Bp, const basic_regex<_Cp, _Tp>&,
30400b57cec5SDimitry Andric                 regex_constants::match_flag_type);
30410b57cec5SDimitry Andric
30420b57cec5SDimitry Andric    template <class _Cp, class _Tp>
30430b57cec5SDimitry Andric    friend
30440b57cec5SDimitry Andric    bool
30450b57cec5SDimitry Andric    regex_search(const _Cp*, const _Cp*,
30460b57cec5SDimitry Andric                 const basic_regex<_Cp, _Tp>&, regex_constants::match_flag_type);
30470b57cec5SDimitry Andric
30480b57cec5SDimitry Andric    template <class _Cp, class _Ap, class _Tp>
30490b57cec5SDimitry Andric    friend
30500b57cec5SDimitry Andric    bool
30510b57cec5SDimitry Andric    regex_search(const _Cp*, match_results<const _Cp*, _Ap>&, const basic_regex<_Cp, _Tp>&,
30520b57cec5SDimitry Andric                 regex_constants::match_flag_type);
30530b57cec5SDimitry Andric
30540b57cec5SDimitry Andric    template <class _ST, class _SA, class _Cp, class _Tp>
30550b57cec5SDimitry Andric    friend
30560b57cec5SDimitry Andric    bool
30570b57cec5SDimitry Andric    regex_search(const basic_string<_Cp, _ST, _SA>& __s,
30580b57cec5SDimitry Andric                 const basic_regex<_Cp, _Tp>& __e,
30590b57cec5SDimitry Andric                 regex_constants::match_flag_type __flags);
30600b57cec5SDimitry Andric
30610b57cec5SDimitry Andric    template <class _ST, class _SA, class _Ap, class _Cp, class _Tp>
30620b57cec5SDimitry Andric    friend
30630b57cec5SDimitry Andric    bool
30640b57cec5SDimitry Andric    regex_search(const basic_string<_Cp, _ST, _SA>& __s,
30650b57cec5SDimitry Andric                 match_results<typename basic_string<_Cp, _ST, _SA>::const_iterator, _Ap>&,
30660b57cec5SDimitry Andric                 const basic_regex<_Cp, _Tp>& __e,
30670b57cec5SDimitry Andric                 regex_constants::match_flag_type __flags);
30680b57cec5SDimitry Andric
30690b57cec5SDimitry Andric    template <class _Iter, class _Ap, class _Cp, class _Tp>
30700b57cec5SDimitry Andric    friend
30710b57cec5SDimitry Andric    bool
30720b57cec5SDimitry Andric    regex_search(__wrap_iter<_Iter> __first,
30730b57cec5SDimitry Andric                 __wrap_iter<_Iter> __last,
30740b57cec5SDimitry Andric                 match_results<__wrap_iter<_Iter>, _Ap>& __m,
30750b57cec5SDimitry Andric                 const basic_regex<_Cp, _Tp>& __e,
30760b57cec5SDimitry Andric                 regex_constants::match_flag_type __flags);
30770b57cec5SDimitry Andric
30780b57cec5SDimitry Andric    template <class, class> friend class __lookahead;
30790b57cec5SDimitry Andric};
30800b57cec5SDimitry Andric
3081349cc55cSDimitry Andric#if _LIBCPP_STD_VER >= 17
30820b57cec5SDimitry Andrictemplate <class _ForwardIterator,
3083480093f4SDimitry Andric          class = typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value, nullptr_t>::type
30840b57cec5SDimitry Andric>
30850b57cec5SDimitry Andricbasic_regex(_ForwardIterator, _ForwardIterator,
30860b57cec5SDimitry Andric            regex_constants::syntax_option_type = regex_constants::ECMAScript)
30870b57cec5SDimitry Andric    -> basic_regex<typename iterator_traits<_ForwardIterator>::value_type>;
30880b57cec5SDimitry Andric#endif
30890b57cec5SDimitry Andric
30900b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
30910b57cec5SDimitry Andric    const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::icase;
30920b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
30930b57cec5SDimitry Andric    const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::nosubs;
30940b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
30950b57cec5SDimitry Andric    const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::optimize;
30960b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
30970b57cec5SDimitry Andric    const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::collate;
30980b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
30990b57cec5SDimitry Andric    const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::ECMAScript;
31000b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
31010b57cec5SDimitry Andric    const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::basic;
31020b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
31030b57cec5SDimitry Andric    const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::extended;
31040b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
31050b57cec5SDimitry Andric    const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::awk;
31060b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
31070b57cec5SDimitry Andric    const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::grep;
31080b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
31090b57cec5SDimitry Andric    const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::egrep;
31100b57cec5SDimitry Andric
31110b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
31120b57cec5SDimitry Andricvoid
31130b57cec5SDimitry Andricbasic_regex<_CharT, _Traits>::swap(basic_regex& __r)
31140b57cec5SDimitry Andric{
31150b57cec5SDimitry Andric    using _VSTD::swap;
31160b57cec5SDimitry Andric    swap(__traits_, __r.__traits_);
31170b57cec5SDimitry Andric    swap(__flags_, __r.__flags_);
31180b57cec5SDimitry Andric    swap(__marked_count_, __r.__marked_count_);
31190b57cec5SDimitry Andric    swap(__loop_count_, __r.__loop_count_);
31200b57cec5SDimitry Andric    swap(__open_count_, __r.__open_count_);
31210b57cec5SDimitry Andric    swap(__start_, __r.__start_);
31220b57cec5SDimitry Andric    swap(__end_, __r.__end_);
31230b57cec5SDimitry Andric}
31240b57cec5SDimitry Andric
31250b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
31260b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
31270b57cec5SDimitry Andricvoid
31280b57cec5SDimitry Andricswap(basic_regex<_CharT, _Traits>& __x, basic_regex<_CharT, _Traits>& __y)
31290b57cec5SDimitry Andric{
31300b57cec5SDimitry Andric    return __x.swap(__y);
31310b57cec5SDimitry Andric}
31320b57cec5SDimitry Andric
31330b57cec5SDimitry Andric// __lookahead
31340b57cec5SDimitry Andric
31350b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
31360b57cec5SDimitry Andricclass __lookahead
31370b57cec5SDimitry Andric    : public __owns_one_state<_CharT>
31380b57cec5SDimitry Andric{
31390b57cec5SDimitry Andric    typedef __owns_one_state<_CharT> base;
31400b57cec5SDimitry Andric
31410b57cec5SDimitry Andric    basic_regex<_CharT, _Traits> __exp_;
31420b57cec5SDimitry Andric    unsigned __mexp_;
31430b57cec5SDimitry Andric    bool __invert_;
31440b57cec5SDimitry Andric
31450b57cec5SDimitry Andric    __lookahead(const __lookahead&);
31460b57cec5SDimitry Andric    __lookahead& operator=(const __lookahead&);
31470b57cec5SDimitry Andricpublic:
31480b57cec5SDimitry Andric    typedef _VSTD::__state<_CharT> __state;
31490b57cec5SDimitry Andric
31500b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
31510b57cec5SDimitry Andric    __lookahead(const basic_regex<_CharT, _Traits>& __exp, bool __invert, __node<_CharT>* __s, unsigned __mexp)
31520b57cec5SDimitry Andric        : base(__s), __exp_(__exp), __mexp_(__mexp), __invert_(__invert) {}
31530b57cec5SDimitry Andric
31540b57cec5SDimitry Andric    virtual void __exec(__state&) const;
31550b57cec5SDimitry Andric};
31560b57cec5SDimitry Andric
31570b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
31580b57cec5SDimitry Andricvoid
31590b57cec5SDimitry Andric__lookahead<_CharT, _Traits>::__exec(__state& __s) const
31600b57cec5SDimitry Andric{
31610b57cec5SDimitry Andric    match_results<const _CharT*> __m;
31620b57cec5SDimitry Andric    __m.__init(1 + __exp_.mark_count(), __s.__current_, __s.__last_);
31630b57cec5SDimitry Andric    bool __matched = __exp_.__match_at_start_ecma(
31640b57cec5SDimitry Andric        __s.__current_, __s.__last_,
31650b57cec5SDimitry Andric        __m,
31660b57cec5SDimitry Andric        (__s.__flags_ | regex_constants::match_continuous) &
31670b57cec5SDimitry Andric        ~regex_constants::__full_match,
31680b57cec5SDimitry Andric        __s.__at_first_ && __s.__current_ == __s.__first_);
31690b57cec5SDimitry Andric    if (__matched != __invert_)
31700b57cec5SDimitry Andric    {
31710b57cec5SDimitry Andric        __s.__do_ = __state::__accept_but_not_consume;
31720b57cec5SDimitry Andric        __s.__node_ = this->first();
31730b57cec5SDimitry Andric        for (unsigned __i = 1; __i < __m.size(); ++__i) {
31740b57cec5SDimitry Andric            __s.__sub_matches_[__mexp_ + __i - 1] = __m.__matches_[__i];
31750b57cec5SDimitry Andric        }
31760b57cec5SDimitry Andric    }
31770b57cec5SDimitry Andric    else
31780b57cec5SDimitry Andric    {
31790b57cec5SDimitry Andric        __s.__do_ = __state::__reject;
31800b57cec5SDimitry Andric        __s.__node_ = nullptr;
31810b57cec5SDimitry Andric    }
31820b57cec5SDimitry Andric}
31830b57cec5SDimitry Andric
31840b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
31850b57cec5SDimitry Andrictemplate <class _ForwardIterator>
3186480093f4SDimitry Andricvoid
3187480093f4SDimitry Andricbasic_regex<_CharT, _Traits>::__init(_ForwardIterator __first, _ForwardIterator __last)
3188480093f4SDimitry Andric{
3189480093f4SDimitry Andric    if (__get_grammar(__flags_) == 0) __flags_ |= regex_constants::ECMAScript;
3190480093f4SDimitry Andric    _ForwardIterator __temp = __parse(__first, __last);
3191480093f4SDimitry Andric    if ( __temp != __last)
3192480093f4SDimitry Andric        __throw_regex_error<regex_constants::__re_err_parse>();
3193480093f4SDimitry Andric}
3194480093f4SDimitry Andric
3195480093f4SDimitry Andrictemplate <class _CharT, class _Traits>
3196480093f4SDimitry Andrictemplate <class _ForwardIterator>
31970b57cec5SDimitry Andric_ForwardIterator
31980b57cec5SDimitry Andricbasic_regex<_CharT, _Traits>::__parse(_ForwardIterator __first,
31990b57cec5SDimitry Andric                                      _ForwardIterator __last)
32000b57cec5SDimitry Andric{
32010b57cec5SDimitry Andric    {
32020b57cec5SDimitry Andric        unique_ptr<__node> __h(new __end_state<_CharT>);
32030b57cec5SDimitry Andric        __start_.reset(new __empty_state<_CharT>(__h.get()));
32040b57cec5SDimitry Andric        __h.release();
32050b57cec5SDimitry Andric        __end_ = __start_.get();
32060b57cec5SDimitry Andric    }
32070b57cec5SDimitry Andric    switch (__get_grammar(__flags_))
32080b57cec5SDimitry Andric    {
32090b57cec5SDimitry Andric    case ECMAScript:
32100b57cec5SDimitry Andric        __first = __parse_ecma_exp(__first, __last);
32110b57cec5SDimitry Andric        break;
32120b57cec5SDimitry Andric    case basic:
32130b57cec5SDimitry Andric        __first = __parse_basic_reg_exp(__first, __last);
32140b57cec5SDimitry Andric        break;
32150b57cec5SDimitry Andric    case extended:
32160b57cec5SDimitry Andric    case awk:
32170b57cec5SDimitry Andric        __first = __parse_extended_reg_exp(__first, __last);
32180b57cec5SDimitry Andric        break;
32190b57cec5SDimitry Andric    case grep:
32200b57cec5SDimitry Andric        __first = __parse_grep(__first, __last);
32210b57cec5SDimitry Andric        break;
32220b57cec5SDimitry Andric    case egrep:
32230b57cec5SDimitry Andric        __first = __parse_egrep(__first, __last);
32240b57cec5SDimitry Andric        break;
32250b57cec5SDimitry Andric    default:
32260b57cec5SDimitry Andric        __throw_regex_error<regex_constants::__re_err_grammar>();
32270b57cec5SDimitry Andric    }
32280b57cec5SDimitry Andric    return __first;
32290b57cec5SDimitry Andric}
32300b57cec5SDimitry Andric
32310b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
32320b57cec5SDimitry Andrictemplate <class _ForwardIterator>
32330b57cec5SDimitry Andric_ForwardIterator
32340b57cec5SDimitry Andricbasic_regex<_CharT, _Traits>::__parse_basic_reg_exp(_ForwardIterator __first,
32350b57cec5SDimitry Andric                                                    _ForwardIterator __last)
32360b57cec5SDimitry Andric{
32370b57cec5SDimitry Andric    if (__first != __last)
32380b57cec5SDimitry Andric    {
32390b57cec5SDimitry Andric        if (*__first == '^')
32400b57cec5SDimitry Andric        {
32410b57cec5SDimitry Andric            __push_l_anchor();
32420b57cec5SDimitry Andric            ++__first;
32430b57cec5SDimitry Andric        }
32440b57cec5SDimitry Andric        if (__first != __last)
32450b57cec5SDimitry Andric        {
32460b57cec5SDimitry Andric            __first = __parse_RE_expression(__first, __last);
32470b57cec5SDimitry Andric            if (__first != __last)
32480b57cec5SDimitry Andric            {
32490b57cec5SDimitry Andric                _ForwardIterator __temp = _VSTD::next(__first);
32500b57cec5SDimitry Andric                if (__temp == __last && *__first == '$')
32510b57cec5SDimitry Andric                {
32520b57cec5SDimitry Andric                    __push_r_anchor();
32530b57cec5SDimitry Andric                    ++__first;
32540b57cec5SDimitry Andric                }
32550b57cec5SDimitry Andric            }
32560b57cec5SDimitry Andric        }
32570b57cec5SDimitry Andric        if (__first != __last)
32580b57cec5SDimitry Andric            __throw_regex_error<regex_constants::__re_err_empty>();
32590b57cec5SDimitry Andric    }
32600b57cec5SDimitry Andric    return __first;
32610b57cec5SDimitry Andric}
32620b57cec5SDimitry Andric
32630b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
32640b57cec5SDimitry Andrictemplate <class _ForwardIterator>
32650b57cec5SDimitry Andric_ForwardIterator
32660b57cec5SDimitry Andricbasic_regex<_CharT, _Traits>::__parse_extended_reg_exp(_ForwardIterator __first,
32670b57cec5SDimitry Andric                                                       _ForwardIterator __last)
32680b57cec5SDimitry Andric{
32690b57cec5SDimitry Andric    __owns_one_state<_CharT>* __sa = __end_;
32700b57cec5SDimitry Andric    _ForwardIterator __temp = __parse_ERE_branch(__first, __last);
32710b57cec5SDimitry Andric    if (__temp == __first)
32720b57cec5SDimitry Andric        __throw_regex_error<regex_constants::__re_err_empty>();
32730b57cec5SDimitry Andric    __first = __temp;
32740b57cec5SDimitry Andric    while (__first != __last && *__first == '|')
32750b57cec5SDimitry Andric    {
32760b57cec5SDimitry Andric        __owns_one_state<_CharT>* __sb = __end_;
32770b57cec5SDimitry Andric        __temp = __parse_ERE_branch(++__first, __last);
32780b57cec5SDimitry Andric        if (__temp == __first)
32790b57cec5SDimitry Andric            __throw_regex_error<regex_constants::__re_err_empty>();
32800b57cec5SDimitry Andric        __push_alternation(__sa, __sb);
32810b57cec5SDimitry Andric        __first = __temp;
32820b57cec5SDimitry Andric    }
32830b57cec5SDimitry Andric    return __first;
32840b57cec5SDimitry Andric}
32850b57cec5SDimitry Andric
32860b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
32870b57cec5SDimitry Andrictemplate <class _ForwardIterator>
32880b57cec5SDimitry Andric_ForwardIterator
32890b57cec5SDimitry Andricbasic_regex<_CharT, _Traits>::__parse_ERE_branch(_ForwardIterator __first,
32900b57cec5SDimitry Andric                                                 _ForwardIterator __last)
32910b57cec5SDimitry Andric{
32920b57cec5SDimitry Andric    _ForwardIterator __temp = __parse_ERE_expression(__first, __last);
32930b57cec5SDimitry Andric    if (__temp == __first)
32940b57cec5SDimitry Andric        __throw_regex_error<regex_constants::__re_err_empty>();
32950b57cec5SDimitry Andric    do
32960b57cec5SDimitry Andric    {
32970b57cec5SDimitry Andric        __first = __temp;
32980b57cec5SDimitry Andric        __temp = __parse_ERE_expression(__first, __last);
32990b57cec5SDimitry Andric    } while (__temp != __first);
33000b57cec5SDimitry Andric    return __first;
33010b57cec5SDimitry Andric}
33020b57cec5SDimitry Andric
33030b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
33040b57cec5SDimitry Andrictemplate <class _ForwardIterator>
33050b57cec5SDimitry Andric_ForwardIterator
33060b57cec5SDimitry Andricbasic_regex<_CharT, _Traits>::__parse_ERE_expression(_ForwardIterator __first,
33070b57cec5SDimitry Andric                                                     _ForwardIterator __last)
33080b57cec5SDimitry Andric{
33090b57cec5SDimitry Andric    __owns_one_state<_CharT>* __e = __end_;
33100b57cec5SDimitry Andric    unsigned __mexp_begin = __marked_count_;
33110b57cec5SDimitry Andric    _ForwardIterator __temp = __parse_one_char_or_coll_elem_ERE(__first, __last);
33120b57cec5SDimitry Andric    if (__temp == __first && __temp != __last)
33130b57cec5SDimitry Andric    {
33140b57cec5SDimitry Andric        switch (*__temp)
33150b57cec5SDimitry Andric        {
33160b57cec5SDimitry Andric        case '^':
33170b57cec5SDimitry Andric            __push_l_anchor();
33180b57cec5SDimitry Andric            ++__temp;
33190b57cec5SDimitry Andric            break;
33200b57cec5SDimitry Andric        case '$':
33210b57cec5SDimitry Andric            __push_r_anchor();
33220b57cec5SDimitry Andric            ++__temp;
33230b57cec5SDimitry Andric            break;
33240b57cec5SDimitry Andric        case '(':
33250b57cec5SDimitry Andric            __push_begin_marked_subexpression();
33260b57cec5SDimitry Andric            unsigned __temp_count = __marked_count_;
33270b57cec5SDimitry Andric            ++__open_count_;
33280b57cec5SDimitry Andric            __temp = __parse_extended_reg_exp(++__temp, __last);
33290b57cec5SDimitry Andric            if (__temp == __last || *__temp != ')')
33300b57cec5SDimitry Andric                __throw_regex_error<regex_constants::error_paren>();
33310b57cec5SDimitry Andric            __push_end_marked_subexpression(__temp_count);
33320b57cec5SDimitry Andric            --__open_count_;
33330b57cec5SDimitry Andric            ++__temp;
33340b57cec5SDimitry Andric            break;
33350b57cec5SDimitry Andric        }
33360b57cec5SDimitry Andric    }
33370b57cec5SDimitry Andric    if (__temp != __first)
33380b57cec5SDimitry Andric        __temp = __parse_ERE_dupl_symbol(__temp, __last, __e, __mexp_begin+1,
33390b57cec5SDimitry Andric                                         __marked_count_+1);
33400b57cec5SDimitry Andric    __first = __temp;
33410b57cec5SDimitry Andric    return __first;
33420b57cec5SDimitry Andric}
33430b57cec5SDimitry Andric
33440b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
33450b57cec5SDimitry Andrictemplate <class _ForwardIterator>
33460b57cec5SDimitry Andric_ForwardIterator
33470b57cec5SDimitry Andricbasic_regex<_CharT, _Traits>::__parse_RE_expression(_ForwardIterator __first,
33480b57cec5SDimitry Andric                                                    _ForwardIterator __last)
33490b57cec5SDimitry Andric{
33500b57cec5SDimitry Andric    while (true)
33510b57cec5SDimitry Andric    {
33520b57cec5SDimitry Andric        _ForwardIterator __temp = __parse_simple_RE(__first, __last);
33530b57cec5SDimitry Andric        if (__temp == __first)
33540b57cec5SDimitry Andric            break;
33550b57cec5SDimitry Andric        __first = __temp;
33560b57cec5SDimitry Andric    }
33570b57cec5SDimitry Andric    return __first;
33580b57cec5SDimitry Andric}
33590b57cec5SDimitry Andric
33600b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
33610b57cec5SDimitry Andrictemplate <class _ForwardIterator>
33620b57cec5SDimitry Andric_ForwardIterator
33630b57cec5SDimitry Andricbasic_regex<_CharT, _Traits>::__parse_simple_RE(_ForwardIterator __first,
33640b57cec5SDimitry Andric                                                _ForwardIterator __last)
33650b57cec5SDimitry Andric{
33660b57cec5SDimitry Andric    if (__first != __last)
33670b57cec5SDimitry Andric    {
33680b57cec5SDimitry Andric        __owns_one_state<_CharT>* __e = __end_;
33690b57cec5SDimitry Andric        unsigned __mexp_begin = __marked_count_;
33700b57cec5SDimitry Andric        _ForwardIterator __temp = __parse_nondupl_RE(__first, __last);
33710b57cec5SDimitry Andric        if (__temp != __first)
33720b57cec5SDimitry Andric            __first = __parse_RE_dupl_symbol(__temp, __last, __e,
33730b57cec5SDimitry Andric                                             __mexp_begin+1, __marked_count_+1);
33740b57cec5SDimitry Andric    }
33750b57cec5SDimitry Andric    return __first;
33760b57cec5SDimitry Andric}
33770b57cec5SDimitry Andric
33780b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
33790b57cec5SDimitry Andrictemplate <class _ForwardIterator>
33800b57cec5SDimitry Andric_ForwardIterator
33810b57cec5SDimitry Andricbasic_regex<_CharT, _Traits>::__parse_nondupl_RE(_ForwardIterator __first,
33820b57cec5SDimitry Andric                                                 _ForwardIterator __last)
33830b57cec5SDimitry Andric{
33840b57cec5SDimitry Andric    _ForwardIterator __temp = __first;
33850b57cec5SDimitry Andric    __first = __parse_one_char_or_coll_elem_RE(__first, __last);
33860b57cec5SDimitry Andric    if (__temp == __first)
33870b57cec5SDimitry Andric    {
33880b57cec5SDimitry Andric        __temp = __parse_Back_open_paren(__first, __last);
33890b57cec5SDimitry Andric        if (__temp != __first)
33900b57cec5SDimitry Andric        {
33910b57cec5SDimitry Andric            __push_begin_marked_subexpression();
33920b57cec5SDimitry Andric            unsigned __temp_count = __marked_count_;
33930b57cec5SDimitry Andric            __first = __parse_RE_expression(__temp, __last);
33940b57cec5SDimitry Andric            __temp = __parse_Back_close_paren(__first, __last);
33950b57cec5SDimitry Andric            if (__temp == __first)
33960b57cec5SDimitry Andric                __throw_regex_error<regex_constants::error_paren>();
33970b57cec5SDimitry Andric            __push_end_marked_subexpression(__temp_count);
33980b57cec5SDimitry Andric            __first = __temp;
33990b57cec5SDimitry Andric        }
34000b57cec5SDimitry Andric        else
34010b57cec5SDimitry Andric            __first = __parse_BACKREF(__first, __last);
34020b57cec5SDimitry Andric    }
34030b57cec5SDimitry Andric    return __first;
34040b57cec5SDimitry Andric}
34050b57cec5SDimitry Andric
34060b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
34070b57cec5SDimitry Andrictemplate <class _ForwardIterator>
34080b57cec5SDimitry Andric_ForwardIterator
34090b57cec5SDimitry Andricbasic_regex<_CharT, _Traits>::__parse_one_char_or_coll_elem_RE(
34100b57cec5SDimitry Andric                                                       _ForwardIterator __first,
34110b57cec5SDimitry Andric                                                       _ForwardIterator __last)
34120b57cec5SDimitry Andric{
34130b57cec5SDimitry Andric    _ForwardIterator __temp = __parse_ORD_CHAR(__first, __last);
34140b57cec5SDimitry Andric    if (__temp == __first)
34150b57cec5SDimitry Andric    {
34160b57cec5SDimitry Andric        __temp = __parse_QUOTED_CHAR(__first, __last);
34170b57cec5SDimitry Andric        if (__temp == __first)
34180b57cec5SDimitry Andric        {
34190b57cec5SDimitry Andric            if (__temp != __last && *__temp == '.')
34200b57cec5SDimitry Andric            {
34210b57cec5SDimitry Andric                __push_match_any();
34220b57cec5SDimitry Andric                ++__temp;
34230b57cec5SDimitry Andric            }
34240b57cec5SDimitry Andric            else
34250b57cec5SDimitry Andric                __temp = __parse_bracket_expression(__first, __last);
34260b57cec5SDimitry Andric        }
34270b57cec5SDimitry Andric    }
34280b57cec5SDimitry Andric    __first = __temp;
34290b57cec5SDimitry Andric    return __first;
34300b57cec5SDimitry Andric}
34310b57cec5SDimitry Andric
34320b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
34330b57cec5SDimitry Andrictemplate <class _ForwardIterator>
34340b57cec5SDimitry Andric_ForwardIterator
34350b57cec5SDimitry Andricbasic_regex<_CharT, _Traits>::__parse_one_char_or_coll_elem_ERE(
34360b57cec5SDimitry Andric                                                       _ForwardIterator __first,
34370b57cec5SDimitry Andric                                                       _ForwardIterator __last)
34380b57cec5SDimitry Andric{
34390b57cec5SDimitry Andric    _ForwardIterator __temp = __parse_ORD_CHAR_ERE(__first, __last);
34400b57cec5SDimitry Andric    if (__temp == __first)
34410b57cec5SDimitry Andric    {
34420b57cec5SDimitry Andric        __temp = __parse_QUOTED_CHAR_ERE(__first, __last);
34430b57cec5SDimitry Andric        if (__temp == __first)
34440b57cec5SDimitry Andric        {
34450b57cec5SDimitry Andric            if (__temp != __last && *__temp == '.')
34460b57cec5SDimitry Andric            {
34470b57cec5SDimitry Andric                __push_match_any();
34480b57cec5SDimitry Andric                ++__temp;
34490b57cec5SDimitry Andric            }
34500b57cec5SDimitry Andric            else
34510b57cec5SDimitry Andric                __temp = __parse_bracket_expression(__first, __last);
34520b57cec5SDimitry Andric        }
34530b57cec5SDimitry Andric    }
34540b57cec5SDimitry Andric    __first = __temp;
34550b57cec5SDimitry Andric    return __first;
34560b57cec5SDimitry Andric}
34570b57cec5SDimitry Andric
34580b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
34590b57cec5SDimitry Andrictemplate <class _ForwardIterator>
34600b57cec5SDimitry Andric_ForwardIterator
34610b57cec5SDimitry Andricbasic_regex<_CharT, _Traits>::__parse_Back_open_paren(_ForwardIterator __first,
34620b57cec5SDimitry Andric                                                      _ForwardIterator __last)
34630b57cec5SDimitry Andric{
34640b57cec5SDimitry Andric    if (__first != __last)
34650b57cec5SDimitry Andric    {
34660b57cec5SDimitry Andric        _ForwardIterator __temp = _VSTD::next(__first);
34670b57cec5SDimitry Andric        if (__temp != __last)
34680b57cec5SDimitry Andric        {
34690b57cec5SDimitry Andric            if (*__first == '\\' && *__temp == '(')
34700b57cec5SDimitry Andric                __first = ++__temp;
34710b57cec5SDimitry Andric        }
34720b57cec5SDimitry Andric    }
34730b57cec5SDimitry Andric    return __first;
34740b57cec5SDimitry Andric}
34750b57cec5SDimitry Andric
34760b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
34770b57cec5SDimitry Andrictemplate <class _ForwardIterator>
34780b57cec5SDimitry Andric_ForwardIterator
34790b57cec5SDimitry Andricbasic_regex<_CharT, _Traits>::__parse_Back_close_paren(_ForwardIterator __first,
34800b57cec5SDimitry Andric                                                       _ForwardIterator __last)
34810b57cec5SDimitry Andric{
34820b57cec5SDimitry Andric    if (__first != __last)
34830b57cec5SDimitry Andric    {
34840b57cec5SDimitry Andric        _ForwardIterator __temp = _VSTD::next(__first);
34850b57cec5SDimitry Andric        if (__temp != __last)
34860b57cec5SDimitry Andric        {
34870b57cec5SDimitry Andric            if (*__first == '\\' && *__temp == ')')
34880b57cec5SDimitry Andric                __first = ++__temp;
34890b57cec5SDimitry Andric        }
34900b57cec5SDimitry Andric    }
34910b57cec5SDimitry Andric    return __first;
34920b57cec5SDimitry Andric}
34930b57cec5SDimitry Andric
34940b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
34950b57cec5SDimitry Andrictemplate <class _ForwardIterator>
34960b57cec5SDimitry Andric_ForwardIterator
34970b57cec5SDimitry Andricbasic_regex<_CharT, _Traits>::__parse_Back_open_brace(_ForwardIterator __first,
34980b57cec5SDimitry Andric                                                      _ForwardIterator __last)
34990b57cec5SDimitry Andric{
35000b57cec5SDimitry Andric    if (__first != __last)
35010b57cec5SDimitry Andric    {
35020b57cec5SDimitry Andric        _ForwardIterator __temp = _VSTD::next(__first);
35030b57cec5SDimitry Andric        if (__temp != __last)
35040b57cec5SDimitry Andric        {
35050b57cec5SDimitry Andric            if (*__first == '\\' && *__temp == '{')
35060b57cec5SDimitry Andric                __first = ++__temp;
35070b57cec5SDimitry Andric        }
35080b57cec5SDimitry Andric    }
35090b57cec5SDimitry Andric    return __first;
35100b57cec5SDimitry Andric}
35110b57cec5SDimitry Andric
35120b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
35130b57cec5SDimitry Andrictemplate <class _ForwardIterator>
35140b57cec5SDimitry Andric_ForwardIterator
35150b57cec5SDimitry Andricbasic_regex<_CharT, _Traits>::__parse_Back_close_brace(_ForwardIterator __first,
35160b57cec5SDimitry Andric                                                       _ForwardIterator __last)
35170b57cec5SDimitry Andric{
35180b57cec5SDimitry Andric    if (__first != __last)
35190b57cec5SDimitry Andric    {
35200b57cec5SDimitry Andric        _ForwardIterator __temp = _VSTD::next(__first);
35210b57cec5SDimitry Andric        if (__temp != __last)
35220b57cec5SDimitry Andric        {
35230b57cec5SDimitry Andric            if (*__first == '\\' && *__temp == '}')
35240b57cec5SDimitry Andric                __first = ++__temp;
35250b57cec5SDimitry Andric        }
35260b57cec5SDimitry Andric    }
35270b57cec5SDimitry Andric    return __first;
35280b57cec5SDimitry Andric}
35290b57cec5SDimitry Andric
35300b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
35310b57cec5SDimitry Andrictemplate <class _ForwardIterator>
35320b57cec5SDimitry Andric_ForwardIterator
35330b57cec5SDimitry Andricbasic_regex<_CharT, _Traits>::__parse_BACKREF(_ForwardIterator __first,
35340b57cec5SDimitry Andric                                              _ForwardIterator __last)
35350b57cec5SDimitry Andric{
35360b57cec5SDimitry Andric    if (__first != __last)
35370b57cec5SDimitry Andric    {
35380b57cec5SDimitry Andric        _ForwardIterator __temp = _VSTD::next(__first);
35395ffd83dbSDimitry Andric        if (__temp != __last && *__first == '\\' && __test_back_ref(*__temp))
35400b57cec5SDimitry Andric            __first = ++__temp;
35410b57cec5SDimitry Andric    }
35420b57cec5SDimitry Andric    return __first;
35430b57cec5SDimitry Andric}
35440b57cec5SDimitry Andric
35450b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
35460b57cec5SDimitry Andrictemplate <class _ForwardIterator>
35470b57cec5SDimitry Andric_ForwardIterator
35480b57cec5SDimitry Andricbasic_regex<_CharT, _Traits>::__parse_ORD_CHAR(_ForwardIterator __first,
35490b57cec5SDimitry Andric                                               _ForwardIterator __last)
35500b57cec5SDimitry Andric{
35510b57cec5SDimitry Andric    if (__first != __last)
35520b57cec5SDimitry Andric    {
35530b57cec5SDimitry Andric        _ForwardIterator __temp = _VSTD::next(__first);
35540b57cec5SDimitry Andric        if (__temp == __last && *__first == '$')
35550b57cec5SDimitry Andric            return __first;
35560b57cec5SDimitry Andric        // Not called inside a bracket
35570b57cec5SDimitry Andric        if (*__first == '.' || *__first == '\\' || *__first == '[')
35580b57cec5SDimitry Andric            return __first;
35590b57cec5SDimitry Andric        __push_char(*__first);
35600b57cec5SDimitry Andric        ++__first;
35610b57cec5SDimitry Andric    }
35620b57cec5SDimitry Andric    return __first;
35630b57cec5SDimitry Andric}
35640b57cec5SDimitry Andric
35650b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
35660b57cec5SDimitry Andrictemplate <class _ForwardIterator>
35670b57cec5SDimitry Andric_ForwardIterator
35680b57cec5SDimitry Andricbasic_regex<_CharT, _Traits>::__parse_ORD_CHAR_ERE(_ForwardIterator __first,
35690b57cec5SDimitry Andric                                                   _ForwardIterator __last)
35700b57cec5SDimitry Andric{
35710b57cec5SDimitry Andric    if (__first != __last)
35720b57cec5SDimitry Andric    {
35730b57cec5SDimitry Andric        switch (*__first)
35740b57cec5SDimitry Andric        {
35750b57cec5SDimitry Andric        case '^':
35760b57cec5SDimitry Andric        case '.':
35770b57cec5SDimitry Andric        case '[':
35780b57cec5SDimitry Andric        case '$':
35790b57cec5SDimitry Andric        case '(':
35800b57cec5SDimitry Andric        case '|':
35810b57cec5SDimitry Andric        case '*':
35820b57cec5SDimitry Andric        case '+':
35830b57cec5SDimitry Andric        case '?':
35840b57cec5SDimitry Andric        case '{':
35850b57cec5SDimitry Andric        case '\\':
35860b57cec5SDimitry Andric            break;
35870b57cec5SDimitry Andric        case ')':
35880b57cec5SDimitry Andric            if (__open_count_ == 0)
35890b57cec5SDimitry Andric            {
35900b57cec5SDimitry Andric                __push_char(*__first);
35910b57cec5SDimitry Andric                ++__first;
35920b57cec5SDimitry Andric            }
35930b57cec5SDimitry Andric            break;
35940b57cec5SDimitry Andric        default:
35950b57cec5SDimitry Andric            __push_char(*__first);
35960b57cec5SDimitry Andric            ++__first;
35970b57cec5SDimitry Andric            break;
35980b57cec5SDimitry Andric        }
35990b57cec5SDimitry Andric    }
36000b57cec5SDimitry Andric    return __first;
36010b57cec5SDimitry Andric}
36020b57cec5SDimitry Andric
36030b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
36040b57cec5SDimitry Andrictemplate <class _ForwardIterator>
36050b57cec5SDimitry Andric_ForwardIterator
36060b57cec5SDimitry Andricbasic_regex<_CharT, _Traits>::__parse_QUOTED_CHAR(_ForwardIterator __first,
36070b57cec5SDimitry Andric                                                  _ForwardIterator __last)
36080b57cec5SDimitry Andric{
36090b57cec5SDimitry Andric    if (__first != __last)
36100b57cec5SDimitry Andric    {
36110b57cec5SDimitry Andric        _ForwardIterator __temp = _VSTD::next(__first);
36120b57cec5SDimitry Andric        if (__temp != __last)
36130b57cec5SDimitry Andric        {
36140b57cec5SDimitry Andric            if (*__first == '\\')
36150b57cec5SDimitry Andric            {
36160b57cec5SDimitry Andric                switch (*__temp)
36170b57cec5SDimitry Andric                {
36180b57cec5SDimitry Andric                case '^':
36190b57cec5SDimitry Andric                case '.':
36200b57cec5SDimitry Andric                case '*':
36210b57cec5SDimitry Andric                case '[':
36220b57cec5SDimitry Andric                case '$':
36230b57cec5SDimitry Andric                case '\\':
36240b57cec5SDimitry Andric                    __push_char(*__temp);
36250b57cec5SDimitry Andric                    __first = ++__temp;
36260b57cec5SDimitry Andric                    break;
36270b57cec5SDimitry Andric                }
36280b57cec5SDimitry Andric            }
36290b57cec5SDimitry Andric        }
36300b57cec5SDimitry Andric    }
36310b57cec5SDimitry Andric    return __first;
36320b57cec5SDimitry Andric}
36330b57cec5SDimitry Andric
36340b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
36350b57cec5SDimitry Andrictemplate <class _ForwardIterator>
36360b57cec5SDimitry Andric_ForwardIterator
36370b57cec5SDimitry Andricbasic_regex<_CharT, _Traits>::__parse_QUOTED_CHAR_ERE(_ForwardIterator __first,
36380b57cec5SDimitry Andric                                                      _ForwardIterator __last)
36390b57cec5SDimitry Andric{
36400b57cec5SDimitry Andric    if (__first != __last)
36410b57cec5SDimitry Andric    {
36420b57cec5SDimitry Andric        _ForwardIterator __temp = _VSTD::next(__first);
36430b57cec5SDimitry Andric        if (__temp != __last)
36440b57cec5SDimitry Andric        {
36450b57cec5SDimitry Andric            if (*__first == '\\')
36460b57cec5SDimitry Andric            {
36470b57cec5SDimitry Andric                switch (*__temp)
36480b57cec5SDimitry Andric                {
36490b57cec5SDimitry Andric                case '^':
36500b57cec5SDimitry Andric                case '.':
36510b57cec5SDimitry Andric                case '*':
36520b57cec5SDimitry Andric                case '[':
36530b57cec5SDimitry Andric                case '$':
36540b57cec5SDimitry Andric                case '\\':
36550b57cec5SDimitry Andric                case '(':
36560b57cec5SDimitry Andric                case ')':
36570b57cec5SDimitry Andric                case '|':
36580b57cec5SDimitry Andric                case '+':
36590b57cec5SDimitry Andric                case '?':
36600b57cec5SDimitry Andric                case '{':
36610b57cec5SDimitry Andric                case '}':
36620b57cec5SDimitry Andric                    __push_char(*__temp);
36630b57cec5SDimitry Andric                    __first = ++__temp;
36640b57cec5SDimitry Andric                    break;
36650b57cec5SDimitry Andric                default:
36660b57cec5SDimitry Andric                    if (__get_grammar(__flags_) == awk)
36670b57cec5SDimitry Andric                        __first = __parse_awk_escape(++__first, __last);
36685ffd83dbSDimitry Andric                    else if(__test_back_ref(*__temp))
36695ffd83dbSDimitry Andric                        __first = ++__temp;
36700b57cec5SDimitry Andric                    break;
36710b57cec5SDimitry Andric                }
36720b57cec5SDimitry Andric            }
36730b57cec5SDimitry Andric        }
36740b57cec5SDimitry Andric    }
36750b57cec5SDimitry Andric    return __first;
36760b57cec5SDimitry Andric}
36770b57cec5SDimitry Andric
36780b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
36790b57cec5SDimitry Andrictemplate <class _ForwardIterator>
36800b57cec5SDimitry Andric_ForwardIterator
36810b57cec5SDimitry Andricbasic_regex<_CharT, _Traits>::__parse_RE_dupl_symbol(_ForwardIterator __first,
36820b57cec5SDimitry Andric                                                     _ForwardIterator __last,
36830b57cec5SDimitry Andric                                                     __owns_one_state<_CharT>* __s,
36840b57cec5SDimitry Andric                                                     unsigned __mexp_begin,
36850b57cec5SDimitry Andric                                                     unsigned __mexp_end)
36860b57cec5SDimitry Andric{
36870b57cec5SDimitry Andric    if (__first != __last)
36880b57cec5SDimitry Andric    {
36890b57cec5SDimitry Andric        if (*__first == '*')
36900b57cec5SDimitry Andric        {
36910b57cec5SDimitry Andric            __push_greedy_inf_repeat(0, __s, __mexp_begin, __mexp_end);
36920b57cec5SDimitry Andric            ++__first;
36930b57cec5SDimitry Andric        }
36940b57cec5SDimitry Andric        else
36950b57cec5SDimitry Andric        {
36960b57cec5SDimitry Andric            _ForwardIterator __temp = __parse_Back_open_brace(__first, __last);
36970b57cec5SDimitry Andric            if (__temp != __first)
36980b57cec5SDimitry Andric            {
36990b57cec5SDimitry Andric                int __min = 0;
37000b57cec5SDimitry Andric                __first = __temp;
37010b57cec5SDimitry Andric                __temp = __parse_DUP_COUNT(__first, __last, __min);
37020b57cec5SDimitry Andric                if (__temp == __first)
37030b57cec5SDimitry Andric                    __throw_regex_error<regex_constants::error_badbrace>();
37040b57cec5SDimitry Andric                __first = __temp;
37050b57cec5SDimitry Andric                if (__first == __last)
37060b57cec5SDimitry Andric                    __throw_regex_error<regex_constants::error_brace>();
37070b57cec5SDimitry Andric                if (*__first != ',')
37080b57cec5SDimitry Andric                {
37090b57cec5SDimitry Andric                    __temp = __parse_Back_close_brace(__first, __last);
37100b57cec5SDimitry Andric                    if (__temp == __first)
37110b57cec5SDimitry Andric                        __throw_regex_error<regex_constants::error_brace>();
37120b57cec5SDimitry Andric                    __push_loop(__min, __min, __s, __mexp_begin, __mexp_end,
37130b57cec5SDimitry Andric                                    true);
37140b57cec5SDimitry Andric                    __first = __temp;
37150b57cec5SDimitry Andric                }
37160b57cec5SDimitry Andric                else
37170b57cec5SDimitry Andric                {
37180b57cec5SDimitry Andric                    ++__first;  // consume ','
37190b57cec5SDimitry Andric                    int __max = -1;
37200b57cec5SDimitry Andric                    __first = __parse_DUP_COUNT(__first, __last, __max);
37210b57cec5SDimitry Andric                    __temp = __parse_Back_close_brace(__first, __last);
37220b57cec5SDimitry Andric                    if (__temp == __first)
37230b57cec5SDimitry Andric                        __throw_regex_error<regex_constants::error_brace>();
37240b57cec5SDimitry Andric                    if (__max == -1)
37250b57cec5SDimitry Andric                        __push_greedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end);
37260b57cec5SDimitry Andric                    else
37270b57cec5SDimitry Andric                    {
37280b57cec5SDimitry Andric                        if (__max < __min)
37290b57cec5SDimitry Andric                            __throw_regex_error<regex_constants::error_badbrace>();
37300b57cec5SDimitry Andric                        __push_loop(__min, __max, __s, __mexp_begin, __mexp_end,
37310b57cec5SDimitry Andric                                    true);
37320b57cec5SDimitry Andric                    }
37330b57cec5SDimitry Andric                    __first = __temp;
37340b57cec5SDimitry Andric                }
37350b57cec5SDimitry Andric            }
37360b57cec5SDimitry Andric        }
37370b57cec5SDimitry Andric    }
37380b57cec5SDimitry Andric    return __first;
37390b57cec5SDimitry Andric}
37400b57cec5SDimitry Andric
37410b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
37420b57cec5SDimitry Andrictemplate <class _ForwardIterator>
37430b57cec5SDimitry Andric_ForwardIterator
37440b57cec5SDimitry Andricbasic_regex<_CharT, _Traits>::__parse_ERE_dupl_symbol(_ForwardIterator __first,
37450b57cec5SDimitry Andric                                                      _ForwardIterator __last,
37460b57cec5SDimitry Andric                                                      __owns_one_state<_CharT>* __s,
37470b57cec5SDimitry Andric                                                      unsigned __mexp_begin,
37480b57cec5SDimitry Andric                                                      unsigned __mexp_end)
37490b57cec5SDimitry Andric{
37500b57cec5SDimitry Andric    if (__first != __last)
37510b57cec5SDimitry Andric    {
37520b57cec5SDimitry Andric        unsigned __grammar = __get_grammar(__flags_);
37530b57cec5SDimitry Andric        switch (*__first)
37540b57cec5SDimitry Andric        {
37550b57cec5SDimitry Andric        case '*':
37560b57cec5SDimitry Andric            ++__first;
37570b57cec5SDimitry Andric            if (__grammar == ECMAScript && __first != __last && *__first == '?')
37580b57cec5SDimitry Andric            {
37590b57cec5SDimitry Andric                ++__first;
37600b57cec5SDimitry Andric                __push_nongreedy_inf_repeat(0, __s, __mexp_begin, __mexp_end);
37610b57cec5SDimitry Andric            }
37620b57cec5SDimitry Andric            else
37630b57cec5SDimitry Andric                __push_greedy_inf_repeat(0, __s, __mexp_begin, __mexp_end);
37640b57cec5SDimitry Andric            break;
37650b57cec5SDimitry Andric        case '+':
37660b57cec5SDimitry Andric            ++__first;
37670b57cec5SDimitry Andric            if (__grammar == ECMAScript && __first != __last && *__first == '?')
37680b57cec5SDimitry Andric            {
37690b57cec5SDimitry Andric                ++__first;
37700b57cec5SDimitry Andric                __push_nongreedy_inf_repeat(1, __s, __mexp_begin, __mexp_end);
37710b57cec5SDimitry Andric            }
37720b57cec5SDimitry Andric            else
37730b57cec5SDimitry Andric                __push_greedy_inf_repeat(1, __s, __mexp_begin, __mexp_end);
37740b57cec5SDimitry Andric            break;
37750b57cec5SDimitry Andric        case '?':
37760b57cec5SDimitry Andric            ++__first;
37770b57cec5SDimitry Andric            if (__grammar == ECMAScript && __first != __last && *__first == '?')
37780b57cec5SDimitry Andric            {
37790b57cec5SDimitry Andric                ++__first;
37800b57cec5SDimitry Andric                __push_loop(0, 1, __s, __mexp_begin, __mexp_end, false);
37810b57cec5SDimitry Andric            }
37820b57cec5SDimitry Andric            else
37830b57cec5SDimitry Andric                __push_loop(0, 1, __s, __mexp_begin, __mexp_end);
37840b57cec5SDimitry Andric            break;
37850b57cec5SDimitry Andric        case '{':
37860b57cec5SDimitry Andric            {
37870b57cec5SDimitry Andric                int __min;
37880b57cec5SDimitry Andric                _ForwardIterator __temp = __parse_DUP_COUNT(++__first, __last, __min);
37890b57cec5SDimitry Andric                if (__temp == __first)
37900b57cec5SDimitry Andric                    __throw_regex_error<regex_constants::error_badbrace>();
37910b57cec5SDimitry Andric                __first = __temp;
37920b57cec5SDimitry Andric                if (__first == __last)
37930b57cec5SDimitry Andric                    __throw_regex_error<regex_constants::error_brace>();
37940b57cec5SDimitry Andric                switch (*__first)
37950b57cec5SDimitry Andric                {
37960b57cec5SDimitry Andric                case '}':
37970b57cec5SDimitry Andric                    ++__first;
37980b57cec5SDimitry Andric                    if (__grammar == ECMAScript && __first != __last && *__first == '?')
37990b57cec5SDimitry Andric                    {
38000b57cec5SDimitry Andric                        ++__first;
38010b57cec5SDimitry Andric                        __push_loop(__min, __min, __s, __mexp_begin, __mexp_end, false);
38020b57cec5SDimitry Andric                    }
38030b57cec5SDimitry Andric                    else
38040b57cec5SDimitry Andric                        __push_loop(__min, __min, __s, __mexp_begin, __mexp_end);
38050b57cec5SDimitry Andric                    break;
38060b57cec5SDimitry Andric                case ',':
38070b57cec5SDimitry Andric                    ++__first;
38080b57cec5SDimitry Andric                    if (__first == __last)
38090b57cec5SDimitry Andric                        __throw_regex_error<regex_constants::error_badbrace>();
38100b57cec5SDimitry Andric                    if (*__first == '}')
38110b57cec5SDimitry Andric                    {
38120b57cec5SDimitry Andric                        ++__first;
38130b57cec5SDimitry Andric                        if (__grammar == ECMAScript && __first != __last && *__first == '?')
38140b57cec5SDimitry Andric                        {
38150b57cec5SDimitry Andric                            ++__first;
38160b57cec5SDimitry Andric                            __push_nongreedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end);
38170b57cec5SDimitry Andric                        }
38180b57cec5SDimitry Andric                        else
38190b57cec5SDimitry Andric                            __push_greedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end);
38200b57cec5SDimitry Andric                    }
38210b57cec5SDimitry Andric                    else
38220b57cec5SDimitry Andric                    {
38230b57cec5SDimitry Andric                        int __max = -1;
38240b57cec5SDimitry Andric                        __temp = __parse_DUP_COUNT(__first, __last, __max);
38250b57cec5SDimitry Andric                        if (__temp == __first)
38260b57cec5SDimitry Andric                            __throw_regex_error<regex_constants::error_brace>();
38270b57cec5SDimitry Andric                        __first = __temp;
38280b57cec5SDimitry Andric                        if (__first == __last || *__first != '}')
38290b57cec5SDimitry Andric                            __throw_regex_error<regex_constants::error_brace>();
38300b57cec5SDimitry Andric                        ++__first;
38310b57cec5SDimitry Andric                        if (__max < __min)
38320b57cec5SDimitry Andric                            __throw_regex_error<regex_constants::error_badbrace>();
38330b57cec5SDimitry Andric                        if (__grammar == ECMAScript && __first != __last && *__first == '?')
38340b57cec5SDimitry Andric                        {
38350b57cec5SDimitry Andric                            ++__first;
38360b57cec5SDimitry Andric                            __push_loop(__min, __max, __s, __mexp_begin, __mexp_end, false);
38370b57cec5SDimitry Andric                        }
38380b57cec5SDimitry Andric                        else
38390b57cec5SDimitry Andric                            __push_loop(__min, __max, __s, __mexp_begin, __mexp_end);
38400b57cec5SDimitry Andric                    }
38410b57cec5SDimitry Andric                    break;
38420b57cec5SDimitry Andric                default:
38430b57cec5SDimitry Andric                    __throw_regex_error<regex_constants::error_badbrace>();
38440b57cec5SDimitry Andric                }
38450b57cec5SDimitry Andric            }
38460b57cec5SDimitry Andric            break;
38470b57cec5SDimitry Andric        }
38480b57cec5SDimitry Andric    }
38490b57cec5SDimitry Andric    return __first;
38500b57cec5SDimitry Andric}
38510b57cec5SDimitry Andric
38520b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
38530b57cec5SDimitry Andrictemplate <class _ForwardIterator>
38540b57cec5SDimitry Andric_ForwardIterator
38550b57cec5SDimitry Andricbasic_regex<_CharT, _Traits>::__parse_bracket_expression(_ForwardIterator __first,
38560b57cec5SDimitry Andric                                                         _ForwardIterator __last)
38570b57cec5SDimitry Andric{
38580b57cec5SDimitry Andric    if (__first != __last && *__first == '[')
38590b57cec5SDimitry Andric    {
38600b57cec5SDimitry Andric        ++__first;
38610b57cec5SDimitry Andric        if (__first == __last)
38620b57cec5SDimitry Andric            __throw_regex_error<regex_constants::error_brack>();
38630b57cec5SDimitry Andric        bool __negate = false;
38640b57cec5SDimitry Andric        if (*__first == '^')
38650b57cec5SDimitry Andric        {
38660b57cec5SDimitry Andric            ++__first;
38670b57cec5SDimitry Andric            __negate = true;
38680b57cec5SDimitry Andric        }
38690b57cec5SDimitry Andric        __bracket_expression<_CharT, _Traits>* __ml = __start_matching_list(__negate);
38700b57cec5SDimitry Andric        // __ml owned by *this
38710b57cec5SDimitry Andric        if (__first == __last)
38720b57cec5SDimitry Andric            __throw_regex_error<regex_constants::error_brack>();
38730b57cec5SDimitry Andric        if (__get_grammar(__flags_) != ECMAScript && *__first == ']')
38740b57cec5SDimitry Andric        {
38750b57cec5SDimitry Andric            __ml->__add_char(']');
38760b57cec5SDimitry Andric            ++__first;
38770b57cec5SDimitry Andric        }
38780b57cec5SDimitry Andric        __first = __parse_follow_list(__first, __last, __ml);
38790b57cec5SDimitry Andric        if (__first == __last)
38800b57cec5SDimitry Andric            __throw_regex_error<regex_constants::error_brack>();
38810b57cec5SDimitry Andric        if (*__first == '-')
38820b57cec5SDimitry Andric        {
38830b57cec5SDimitry Andric            __ml->__add_char('-');
38840b57cec5SDimitry Andric            ++__first;
38850b57cec5SDimitry Andric        }
38860b57cec5SDimitry Andric        if (__first == __last || *__first != ']')
38870b57cec5SDimitry Andric            __throw_regex_error<regex_constants::error_brack>();
38880b57cec5SDimitry Andric        ++__first;
38890b57cec5SDimitry Andric    }
38900b57cec5SDimitry Andric    return __first;
38910b57cec5SDimitry Andric}
38920b57cec5SDimitry Andric
38930b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
38940b57cec5SDimitry Andrictemplate <class _ForwardIterator>
38950b57cec5SDimitry Andric_ForwardIterator
38960b57cec5SDimitry Andricbasic_regex<_CharT, _Traits>::__parse_follow_list(_ForwardIterator __first,
38970b57cec5SDimitry Andric                                    _ForwardIterator __last,
38980b57cec5SDimitry Andric                                    __bracket_expression<_CharT, _Traits>* __ml)
38990b57cec5SDimitry Andric{
39000b57cec5SDimitry Andric    if (__first != __last)
39010b57cec5SDimitry Andric    {
39020b57cec5SDimitry Andric        while (true)
39030b57cec5SDimitry Andric        {
39040b57cec5SDimitry Andric            _ForwardIterator __temp = __parse_expression_term(__first, __last,
39050b57cec5SDimitry Andric                                                              __ml);
39060b57cec5SDimitry Andric            if (__temp == __first)
39070b57cec5SDimitry Andric                break;
39080b57cec5SDimitry Andric            __first = __temp;
39090b57cec5SDimitry Andric        }
39100b57cec5SDimitry Andric    }
39110b57cec5SDimitry Andric    return __first;
39120b57cec5SDimitry Andric}
39130b57cec5SDimitry Andric
39140b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
39150b57cec5SDimitry Andrictemplate <class _ForwardIterator>
39160b57cec5SDimitry Andric_ForwardIterator
39170b57cec5SDimitry Andricbasic_regex<_CharT, _Traits>::__parse_expression_term(_ForwardIterator __first,
39180b57cec5SDimitry Andric                                    _ForwardIterator __last,
39190b57cec5SDimitry Andric                                    __bracket_expression<_CharT, _Traits>* __ml)
39200b57cec5SDimitry Andric{
39210b57cec5SDimitry Andric    if (__first != __last && *__first != ']')
39220b57cec5SDimitry Andric    {
39230b57cec5SDimitry Andric        _ForwardIterator __temp = _VSTD::next(__first);
39240b57cec5SDimitry Andric        basic_string<_CharT> __start_range;
39250b57cec5SDimitry Andric        if (__temp != __last && *__first == '[')
39260b57cec5SDimitry Andric        {
39270b57cec5SDimitry Andric            if (*__temp == '=')
39280b57cec5SDimitry Andric                return __parse_equivalence_class(++__temp, __last, __ml);
39290b57cec5SDimitry Andric            else if (*__temp == ':')
39300b57cec5SDimitry Andric                return __parse_character_class(++__temp, __last, __ml);
39310b57cec5SDimitry Andric            else if (*__temp == '.')
39320b57cec5SDimitry Andric                __first = __parse_collating_symbol(++__temp, __last, __start_range);
39330b57cec5SDimitry Andric        }
39340b57cec5SDimitry Andric        unsigned __grammar = __get_grammar(__flags_);
39350b57cec5SDimitry Andric        if (__start_range.empty())
39360b57cec5SDimitry Andric        {
39370b57cec5SDimitry Andric            if ((__grammar == ECMAScript || __grammar == awk) && *__first == '\\')
39380b57cec5SDimitry Andric            {
39390b57cec5SDimitry Andric                if (__grammar == ECMAScript)
39400b57cec5SDimitry Andric                    __first = __parse_class_escape(++__first, __last, __start_range, __ml);
39410b57cec5SDimitry Andric                else
39420b57cec5SDimitry Andric                    __first = __parse_awk_escape(++__first, __last, &__start_range);
39430b57cec5SDimitry Andric            }
39440b57cec5SDimitry Andric            else
39450b57cec5SDimitry Andric            {
39460b57cec5SDimitry Andric                __start_range = *__first;
39470b57cec5SDimitry Andric                ++__first;
39480b57cec5SDimitry Andric            }
39490b57cec5SDimitry Andric        }
39500b57cec5SDimitry Andric        if (__first != __last && *__first != ']')
39510b57cec5SDimitry Andric        {
39520b57cec5SDimitry Andric            __temp = _VSTD::next(__first);
39530b57cec5SDimitry Andric            if (__temp != __last && *__first == '-' && *__temp != ']')
39540b57cec5SDimitry Andric            {
39550b57cec5SDimitry Andric                // parse a range
39560b57cec5SDimitry Andric                basic_string<_CharT> __end_range;
39570b57cec5SDimitry Andric                __first = __temp;
39580b57cec5SDimitry Andric                ++__temp;
39590b57cec5SDimitry Andric                if (__temp != __last && *__first == '[' && *__temp == '.')
39600b57cec5SDimitry Andric                    __first = __parse_collating_symbol(++__temp, __last, __end_range);
39610b57cec5SDimitry Andric                else
39620b57cec5SDimitry Andric                {
39630b57cec5SDimitry Andric                    if ((__grammar == ECMAScript || __grammar == awk) && *__first == '\\')
39640b57cec5SDimitry Andric                    {
39650b57cec5SDimitry Andric                        if (__grammar == ECMAScript)
39660b57cec5SDimitry Andric                            __first = __parse_class_escape(++__first, __last,
39670b57cec5SDimitry Andric                                                           __end_range, __ml);
39680b57cec5SDimitry Andric                        else
39690b57cec5SDimitry Andric                            __first = __parse_awk_escape(++__first, __last,
39700b57cec5SDimitry Andric                                                         &__end_range);
39710b57cec5SDimitry Andric                    }
39720b57cec5SDimitry Andric                    else
39730b57cec5SDimitry Andric                    {
39740b57cec5SDimitry Andric                        __end_range = *__first;
39750b57cec5SDimitry Andric                        ++__first;
39760b57cec5SDimitry Andric                    }
39770b57cec5SDimitry Andric                }
39780b57cec5SDimitry Andric                __ml->__add_range(_VSTD::move(__start_range), _VSTD::move(__end_range));
39790b57cec5SDimitry Andric            }
39800b57cec5SDimitry Andric            else if (!__start_range.empty())
39810b57cec5SDimitry Andric            {
39820b57cec5SDimitry Andric                if (__start_range.size() == 1)
39830b57cec5SDimitry Andric                    __ml->__add_char(__start_range[0]);
39840b57cec5SDimitry Andric                else
39850b57cec5SDimitry Andric                    __ml->__add_digraph(__start_range[0], __start_range[1]);
39860b57cec5SDimitry Andric            }
39870b57cec5SDimitry Andric        }
39880b57cec5SDimitry Andric        else if (!__start_range.empty())
39890b57cec5SDimitry Andric        {
39900b57cec5SDimitry Andric            if (__start_range.size() == 1)
39910b57cec5SDimitry Andric                __ml->__add_char(__start_range[0]);
39920b57cec5SDimitry Andric            else
39930b57cec5SDimitry Andric                __ml->__add_digraph(__start_range[0], __start_range[1]);
39940b57cec5SDimitry Andric        }
39950b57cec5SDimitry Andric    }
39960b57cec5SDimitry Andric    return __first;
39970b57cec5SDimitry Andric}
39980b57cec5SDimitry Andric
39990b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
40000b57cec5SDimitry Andrictemplate <class _ForwardIterator>
40010b57cec5SDimitry Andric_ForwardIterator
40020b57cec5SDimitry Andricbasic_regex<_CharT, _Traits>::__parse_class_escape(_ForwardIterator __first,
40030b57cec5SDimitry Andric                          _ForwardIterator __last,
40040b57cec5SDimitry Andric                          basic_string<_CharT>& __str,
40050b57cec5SDimitry Andric                          __bracket_expression<_CharT, _Traits>* __ml)
40060b57cec5SDimitry Andric{
40070b57cec5SDimitry Andric    if (__first == __last)
40080b57cec5SDimitry Andric        __throw_regex_error<regex_constants::error_escape>();
40090b57cec5SDimitry Andric    switch (*__first)
40100b57cec5SDimitry Andric    {
40110b57cec5SDimitry Andric    case 0:
40120b57cec5SDimitry Andric        __str = *__first;
40130b57cec5SDimitry Andric        return ++__first;
40140b57cec5SDimitry Andric    case 'b':
40150b57cec5SDimitry Andric        __str = _CharT(8);
40160b57cec5SDimitry Andric        return ++__first;
40170b57cec5SDimitry Andric    case 'd':
40180b57cec5SDimitry Andric        __ml->__add_class(ctype_base::digit);
40190b57cec5SDimitry Andric        return ++__first;
40200b57cec5SDimitry Andric    case 'D':
40210b57cec5SDimitry Andric        __ml->__add_neg_class(ctype_base::digit);
40220b57cec5SDimitry Andric        return ++__first;
40230b57cec5SDimitry Andric    case 's':
40240b57cec5SDimitry Andric        __ml->__add_class(ctype_base::space);
40250b57cec5SDimitry Andric        return ++__first;
40260b57cec5SDimitry Andric    case 'S':
40270b57cec5SDimitry Andric        __ml->__add_neg_class(ctype_base::space);
40280b57cec5SDimitry Andric        return ++__first;
40290b57cec5SDimitry Andric    case 'w':
40300b57cec5SDimitry Andric        __ml->__add_class(ctype_base::alnum);
40310b57cec5SDimitry Andric        __ml->__add_char('_');
40320b57cec5SDimitry Andric        return ++__first;
40330b57cec5SDimitry Andric    case 'W':
40340b57cec5SDimitry Andric        __ml->__add_neg_class(ctype_base::alnum);
40350b57cec5SDimitry Andric        __ml->__add_neg_char('_');
40360b57cec5SDimitry Andric        return ++__first;
40370b57cec5SDimitry Andric    }
40380b57cec5SDimitry Andric    __first = __parse_character_escape(__first, __last, &__str);
40390b57cec5SDimitry Andric    return __first;
40400b57cec5SDimitry Andric}
40410b57cec5SDimitry Andric
40420b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
40430b57cec5SDimitry Andrictemplate <class _ForwardIterator>
40440b57cec5SDimitry Andric_ForwardIterator
40450b57cec5SDimitry Andricbasic_regex<_CharT, _Traits>::__parse_awk_escape(_ForwardIterator __first,
40460b57cec5SDimitry Andric                          _ForwardIterator __last,
40470b57cec5SDimitry Andric                          basic_string<_CharT>* __str)
40480b57cec5SDimitry Andric{
40490b57cec5SDimitry Andric    if (__first == __last)
40500b57cec5SDimitry Andric        __throw_regex_error<regex_constants::error_escape>();
40510b57cec5SDimitry Andric    switch (*__first)
40520b57cec5SDimitry Andric    {
40530b57cec5SDimitry Andric    case '\\':
40540b57cec5SDimitry Andric    case '"':
40550b57cec5SDimitry Andric    case '/':
40560b57cec5SDimitry Andric        if (__str)
40570b57cec5SDimitry Andric            *__str = *__first;
40580b57cec5SDimitry Andric        else
40590b57cec5SDimitry Andric            __push_char(*__first);
40600b57cec5SDimitry Andric        return ++__first;
40610b57cec5SDimitry Andric    case 'a':
40620b57cec5SDimitry Andric        if (__str)
40630b57cec5SDimitry Andric            *__str = _CharT(7);
40640b57cec5SDimitry Andric        else
40650b57cec5SDimitry Andric            __push_char(_CharT(7));
40660b57cec5SDimitry Andric        return ++__first;
40670b57cec5SDimitry Andric    case 'b':
40680b57cec5SDimitry Andric        if (__str)
40690b57cec5SDimitry Andric            *__str = _CharT(8);
40700b57cec5SDimitry Andric        else
40710b57cec5SDimitry Andric            __push_char(_CharT(8));
40720b57cec5SDimitry Andric        return ++__first;
40730b57cec5SDimitry Andric    case 'f':
40740b57cec5SDimitry Andric        if (__str)
40750b57cec5SDimitry Andric            *__str = _CharT(0xC);
40760b57cec5SDimitry Andric        else
40770b57cec5SDimitry Andric            __push_char(_CharT(0xC));
40780b57cec5SDimitry Andric        return ++__first;
40790b57cec5SDimitry Andric    case 'n':
40800b57cec5SDimitry Andric        if (__str)
40810b57cec5SDimitry Andric            *__str = _CharT(0xA);
40820b57cec5SDimitry Andric        else
40830b57cec5SDimitry Andric            __push_char(_CharT(0xA));
40840b57cec5SDimitry Andric        return ++__first;
40850b57cec5SDimitry Andric    case 'r':
40860b57cec5SDimitry Andric        if (__str)
40870b57cec5SDimitry Andric            *__str = _CharT(0xD);
40880b57cec5SDimitry Andric        else
40890b57cec5SDimitry Andric            __push_char(_CharT(0xD));
40900b57cec5SDimitry Andric        return ++__first;
40910b57cec5SDimitry Andric    case 't':
40920b57cec5SDimitry Andric        if (__str)
40930b57cec5SDimitry Andric            *__str = _CharT(0x9);
40940b57cec5SDimitry Andric        else
40950b57cec5SDimitry Andric            __push_char(_CharT(0x9));
40960b57cec5SDimitry Andric        return ++__first;
40970b57cec5SDimitry Andric    case 'v':
40980b57cec5SDimitry Andric        if (__str)
40990b57cec5SDimitry Andric            *__str = _CharT(0xB);
41000b57cec5SDimitry Andric        else
41010b57cec5SDimitry Andric            __push_char(_CharT(0xB));
41020b57cec5SDimitry Andric        return ++__first;
41030b57cec5SDimitry Andric    }
41040b57cec5SDimitry Andric    if ('0' <= *__first && *__first <= '7')
41050b57cec5SDimitry Andric    {
41060b57cec5SDimitry Andric        unsigned __val = *__first - '0';
41070b57cec5SDimitry Andric        if (++__first != __last && ('0' <= *__first && *__first <= '7'))
41080b57cec5SDimitry Andric        {
41090b57cec5SDimitry Andric            __val = 8 * __val + *__first - '0';
41100b57cec5SDimitry Andric            if (++__first != __last && ('0' <= *__first && *__first <= '7'))
41110b57cec5SDimitry Andric                __val = 8 * __val + *__first++ - '0';
41120b57cec5SDimitry Andric        }
41130b57cec5SDimitry Andric        if (__str)
41140b57cec5SDimitry Andric            *__str = _CharT(__val);
41150b57cec5SDimitry Andric        else
41160b57cec5SDimitry Andric            __push_char(_CharT(__val));
41170b57cec5SDimitry Andric    }
41180b57cec5SDimitry Andric    else
41190b57cec5SDimitry Andric        __throw_regex_error<regex_constants::error_escape>();
41200b57cec5SDimitry Andric    return __first;
41210b57cec5SDimitry Andric}
41220b57cec5SDimitry Andric
41230b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
41240b57cec5SDimitry Andrictemplate <class _ForwardIterator>
41250b57cec5SDimitry Andric_ForwardIterator
41260b57cec5SDimitry Andricbasic_regex<_CharT, _Traits>::__parse_equivalence_class(_ForwardIterator __first,
41270b57cec5SDimitry Andric                                    _ForwardIterator __last,
41280b57cec5SDimitry Andric                                    __bracket_expression<_CharT, _Traits>* __ml)
41290b57cec5SDimitry Andric{
41300b57cec5SDimitry Andric    // Found [=
41310b57cec5SDimitry Andric    //   This means =] must exist
41320b57cec5SDimitry Andric    value_type _Equal_close[2] = {'=', ']'};
41330b57cec5SDimitry Andric    _ForwardIterator __temp = _VSTD::search(__first, __last, _Equal_close,
41340b57cec5SDimitry Andric                                                            _Equal_close+2);
41350b57cec5SDimitry Andric    if (__temp == __last)
41360b57cec5SDimitry Andric        __throw_regex_error<regex_constants::error_brack>();
41370b57cec5SDimitry Andric    // [__first, __temp) contains all text in [= ... =]
41380b57cec5SDimitry Andric    string_type __collate_name =
41390b57cec5SDimitry Andric        __traits_.lookup_collatename(__first, __temp);
41400b57cec5SDimitry Andric    if (__collate_name.empty())
41410b57cec5SDimitry Andric        __throw_regex_error<regex_constants::error_collate>();
41420b57cec5SDimitry Andric    string_type __equiv_name =
41430b57cec5SDimitry Andric        __traits_.transform_primary(__collate_name.begin(),
41440b57cec5SDimitry Andric                                    __collate_name.end());
41450b57cec5SDimitry Andric    if (!__equiv_name.empty())
41460b57cec5SDimitry Andric        __ml->__add_equivalence(__equiv_name);
41470b57cec5SDimitry Andric    else
41480b57cec5SDimitry Andric    {
41490b57cec5SDimitry Andric        switch (__collate_name.size())
41500b57cec5SDimitry Andric        {
41510b57cec5SDimitry Andric        case 1:
41520b57cec5SDimitry Andric            __ml->__add_char(__collate_name[0]);
41530b57cec5SDimitry Andric            break;
41540b57cec5SDimitry Andric        case 2:
41550b57cec5SDimitry Andric            __ml->__add_digraph(__collate_name[0], __collate_name[1]);
41560b57cec5SDimitry Andric            break;
41570b57cec5SDimitry Andric        default:
41580b57cec5SDimitry Andric            __throw_regex_error<regex_constants::error_collate>();
41590b57cec5SDimitry Andric        }
41600b57cec5SDimitry Andric    }
41610b57cec5SDimitry Andric    __first = _VSTD::next(__temp, 2);
41620b57cec5SDimitry Andric    return __first;
41630b57cec5SDimitry Andric}
41640b57cec5SDimitry Andric
41650b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
41660b57cec5SDimitry Andrictemplate <class _ForwardIterator>
41670b57cec5SDimitry Andric_ForwardIterator
41680b57cec5SDimitry Andricbasic_regex<_CharT, _Traits>::__parse_character_class(_ForwardIterator __first,
41690b57cec5SDimitry Andric                                    _ForwardIterator __last,
41700b57cec5SDimitry Andric                                    __bracket_expression<_CharT, _Traits>* __ml)
41710b57cec5SDimitry Andric{
41720b57cec5SDimitry Andric    // Found [:
41730b57cec5SDimitry Andric    //   This means :] must exist
41740b57cec5SDimitry Andric    value_type _Colon_close[2] = {':', ']'};
41750b57cec5SDimitry Andric    _ForwardIterator __temp = _VSTD::search(__first, __last, _Colon_close,
41760b57cec5SDimitry Andric                                                            _Colon_close+2);
41770b57cec5SDimitry Andric    if (__temp == __last)
41780b57cec5SDimitry Andric        __throw_regex_error<regex_constants::error_brack>();
41790b57cec5SDimitry Andric    // [__first, __temp) contains all text in [: ... :]
41800b57cec5SDimitry Andric    typedef typename _Traits::char_class_type char_class_type;
41810b57cec5SDimitry Andric    char_class_type __class_type =
41820b57cec5SDimitry Andric        __traits_.lookup_classname(__first, __temp, __flags_ & icase);
41830b57cec5SDimitry Andric    if (__class_type == 0)
41840b57cec5SDimitry Andric        __throw_regex_error<regex_constants::error_ctype>();
41850b57cec5SDimitry Andric    __ml->__add_class(__class_type);
41860b57cec5SDimitry Andric    __first = _VSTD::next(__temp, 2);
41870b57cec5SDimitry Andric    return __first;
41880b57cec5SDimitry Andric}
41890b57cec5SDimitry Andric
41900b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
41910b57cec5SDimitry Andrictemplate <class _ForwardIterator>
41920b57cec5SDimitry Andric_ForwardIterator
41930b57cec5SDimitry Andricbasic_regex<_CharT, _Traits>::__parse_collating_symbol(_ForwardIterator __first,
41940b57cec5SDimitry Andric                                                _ForwardIterator __last,
41950b57cec5SDimitry Andric                                                basic_string<_CharT>& __col_sym)
41960b57cec5SDimitry Andric{
41970b57cec5SDimitry Andric    // Found [.
41980b57cec5SDimitry Andric    //   This means .] must exist
41990b57cec5SDimitry Andric    value_type _Dot_close[2] = {'.', ']'};
42000b57cec5SDimitry Andric    _ForwardIterator __temp = _VSTD::search(__first, __last, _Dot_close,
42010b57cec5SDimitry Andric                                                            _Dot_close+2);
42020b57cec5SDimitry Andric    if (__temp == __last)
42030b57cec5SDimitry Andric        __throw_regex_error<regex_constants::error_brack>();
42040b57cec5SDimitry Andric    // [__first, __temp) contains all text in [. ... .]
42050b57cec5SDimitry Andric    __col_sym = __traits_.lookup_collatename(__first, __temp);
42060b57cec5SDimitry Andric    switch (__col_sym.size())
42070b57cec5SDimitry Andric    {
42080b57cec5SDimitry Andric    case 1:
42090b57cec5SDimitry Andric    case 2:
42100b57cec5SDimitry Andric        break;
42110b57cec5SDimitry Andric    default:
42120b57cec5SDimitry Andric        __throw_regex_error<regex_constants::error_collate>();
42130b57cec5SDimitry Andric    }
42140b57cec5SDimitry Andric    __first = _VSTD::next(__temp, 2);
42150b57cec5SDimitry Andric    return __first;
42160b57cec5SDimitry Andric}
42170b57cec5SDimitry Andric
42180b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
42190b57cec5SDimitry Andrictemplate <class _ForwardIterator>
42200b57cec5SDimitry Andric_ForwardIterator
42210b57cec5SDimitry Andricbasic_regex<_CharT, _Traits>::__parse_DUP_COUNT(_ForwardIterator __first,
42220b57cec5SDimitry Andric                                                _ForwardIterator __last,
42230b57cec5SDimitry Andric                                                int& __c)
42240b57cec5SDimitry Andric{
42250b57cec5SDimitry Andric    if (__first != __last )
42260b57cec5SDimitry Andric    {
42270b57cec5SDimitry Andric        int __val = __traits_.value(*__first, 10);
42280b57cec5SDimitry Andric        if ( __val != -1 )
42290b57cec5SDimitry Andric        {
42300b57cec5SDimitry Andric            __c = __val;
42310b57cec5SDimitry Andric            for (++__first;
42320b57cec5SDimitry Andric                 __first != __last && ( __val = __traits_.value(*__first, 10)) != -1;
42330b57cec5SDimitry Andric                 ++__first)
42340b57cec5SDimitry Andric            {
4235e8d8bef9SDimitry Andric                if (__c >= numeric_limits<int>::max() / 10)
42360b57cec5SDimitry Andric                    __throw_regex_error<regex_constants::error_badbrace>();
42370b57cec5SDimitry Andric                __c *= 10;
42380b57cec5SDimitry Andric                __c += __val;
42390b57cec5SDimitry Andric            }
42400b57cec5SDimitry Andric        }
42410b57cec5SDimitry Andric    }
42420b57cec5SDimitry Andric    return __first;
42430b57cec5SDimitry Andric}
42440b57cec5SDimitry Andric
42450b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
42460b57cec5SDimitry Andrictemplate <class _ForwardIterator>
42470b57cec5SDimitry Andric_ForwardIterator
42480b57cec5SDimitry Andricbasic_regex<_CharT, _Traits>::__parse_ecma_exp(_ForwardIterator __first,
42490b57cec5SDimitry Andric                                               _ForwardIterator __last)
42500b57cec5SDimitry Andric{
42510b57cec5SDimitry Andric    __owns_one_state<_CharT>* __sa = __end_;
42520b57cec5SDimitry Andric    _ForwardIterator __temp = __parse_alternative(__first, __last);
42530b57cec5SDimitry Andric    if (__temp == __first)
42540b57cec5SDimitry Andric        __push_empty();
42550b57cec5SDimitry Andric    __first = __temp;
42560b57cec5SDimitry Andric    while (__first != __last && *__first == '|')
42570b57cec5SDimitry Andric    {
42580b57cec5SDimitry Andric        __owns_one_state<_CharT>* __sb = __end_;
42590b57cec5SDimitry Andric        __temp = __parse_alternative(++__first, __last);
42600b57cec5SDimitry Andric        if (__temp == __first)
42610b57cec5SDimitry Andric            __push_empty();
42620b57cec5SDimitry Andric        __push_alternation(__sa, __sb);
42630b57cec5SDimitry Andric        __first = __temp;
42640b57cec5SDimitry Andric    }
42650b57cec5SDimitry Andric    return __first;
42660b57cec5SDimitry Andric}
42670b57cec5SDimitry Andric
42680b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
42690b57cec5SDimitry Andrictemplate <class _ForwardIterator>
42700b57cec5SDimitry Andric_ForwardIterator
42710b57cec5SDimitry Andricbasic_regex<_CharT, _Traits>::__parse_alternative(_ForwardIterator __first,
42720b57cec5SDimitry Andric                                                  _ForwardIterator __last)
42730b57cec5SDimitry Andric{
42740b57cec5SDimitry Andric    while (true)
42750b57cec5SDimitry Andric    {
42760b57cec5SDimitry Andric        _ForwardIterator __temp = __parse_term(__first, __last);
42770b57cec5SDimitry Andric        if (__temp == __first)
42780b57cec5SDimitry Andric            break;
42790b57cec5SDimitry Andric        __first = __temp;
42800b57cec5SDimitry Andric    }
42810b57cec5SDimitry Andric    return __first;
42820b57cec5SDimitry Andric}
42830b57cec5SDimitry Andric
42840b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
42850b57cec5SDimitry Andrictemplate <class _ForwardIterator>
42860b57cec5SDimitry Andric_ForwardIterator
42870b57cec5SDimitry Andricbasic_regex<_CharT, _Traits>::__parse_term(_ForwardIterator __first,
42880b57cec5SDimitry Andric                                           _ForwardIterator __last)
42890b57cec5SDimitry Andric{
42900b57cec5SDimitry Andric    _ForwardIterator __temp = __parse_assertion(__first, __last);
42910b57cec5SDimitry Andric    if (__temp == __first)
42920b57cec5SDimitry Andric    {
42930b57cec5SDimitry Andric        __owns_one_state<_CharT>* __e = __end_;
42940b57cec5SDimitry Andric        unsigned __mexp_begin = __marked_count_;
42950b57cec5SDimitry Andric        __temp = __parse_atom(__first, __last);
42960b57cec5SDimitry Andric        if (__temp != __first)
42970b57cec5SDimitry Andric            __first = __parse_ERE_dupl_symbol(__temp, __last, __e,
42980b57cec5SDimitry Andric                                              __mexp_begin+1, __marked_count_+1);
42990b57cec5SDimitry Andric    }
43000b57cec5SDimitry Andric    else
43010b57cec5SDimitry Andric        __first = __temp;
43020b57cec5SDimitry Andric    return __first;
43030b57cec5SDimitry Andric}
43040b57cec5SDimitry Andric
43050b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
43060b57cec5SDimitry Andrictemplate <class _ForwardIterator>
43070b57cec5SDimitry Andric_ForwardIterator
43080b57cec5SDimitry Andricbasic_regex<_CharT, _Traits>::__parse_assertion(_ForwardIterator __first,
43090b57cec5SDimitry Andric                                                _ForwardIterator __last)
43100b57cec5SDimitry Andric{
43110b57cec5SDimitry Andric    if (__first != __last)
43120b57cec5SDimitry Andric    {
43130b57cec5SDimitry Andric        switch (*__first)
43140b57cec5SDimitry Andric        {
43150b57cec5SDimitry Andric        case '^':
43160b57cec5SDimitry Andric            __push_l_anchor();
43170b57cec5SDimitry Andric            ++__first;
43180b57cec5SDimitry Andric            break;
43190b57cec5SDimitry Andric        case '$':
43200b57cec5SDimitry Andric            __push_r_anchor();
43210b57cec5SDimitry Andric            ++__first;
43220b57cec5SDimitry Andric            break;
43230b57cec5SDimitry Andric        case '\\':
43240b57cec5SDimitry Andric            {
43250b57cec5SDimitry Andric                _ForwardIterator __temp = _VSTD::next(__first);
43260b57cec5SDimitry Andric                if (__temp != __last)
43270b57cec5SDimitry Andric                {
43280b57cec5SDimitry Andric                    if (*__temp == 'b')
43290b57cec5SDimitry Andric                    {
43300b57cec5SDimitry Andric                        __push_word_boundary(false);
43310b57cec5SDimitry Andric                        __first = ++__temp;
43320b57cec5SDimitry Andric                    }
43330b57cec5SDimitry Andric                    else if (*__temp == 'B')
43340b57cec5SDimitry Andric                    {
43350b57cec5SDimitry Andric                        __push_word_boundary(true);
43360b57cec5SDimitry Andric                        __first = ++__temp;
43370b57cec5SDimitry Andric                    }
43380b57cec5SDimitry Andric                }
43390b57cec5SDimitry Andric            }
43400b57cec5SDimitry Andric            break;
43410b57cec5SDimitry Andric        case '(':
43420b57cec5SDimitry Andric            {
43430b57cec5SDimitry Andric                _ForwardIterator __temp = _VSTD::next(__first);
43440b57cec5SDimitry Andric                if (__temp != __last && *__temp == '?')
43450b57cec5SDimitry Andric                {
43460b57cec5SDimitry Andric                    if (++__temp != __last)
43470b57cec5SDimitry Andric                    {
43480b57cec5SDimitry Andric                        switch (*__temp)
43490b57cec5SDimitry Andric                        {
43500b57cec5SDimitry Andric                        case '=':
43510b57cec5SDimitry Andric                            {
43520b57cec5SDimitry Andric                                basic_regex __exp;
43530b57cec5SDimitry Andric                                __exp.__flags_ = __flags_;
43540b57cec5SDimitry Andric                                __temp = __exp.__parse(++__temp, __last);
43550b57cec5SDimitry Andric                                unsigned __mexp = __exp.__marked_count_;
43560b57cec5SDimitry Andric                                __push_lookahead(_VSTD::move(__exp), false, __marked_count_);
43570b57cec5SDimitry Andric                                __marked_count_ += __mexp;
43580b57cec5SDimitry Andric                                if (__temp == __last || *__temp != ')')
43590b57cec5SDimitry Andric                                    __throw_regex_error<regex_constants::error_paren>();
43600b57cec5SDimitry Andric                                __first = ++__temp;
43610b57cec5SDimitry Andric                            }
43620b57cec5SDimitry Andric                            break;
43630b57cec5SDimitry Andric                        case '!':
43640b57cec5SDimitry Andric                            {
43650b57cec5SDimitry Andric                                basic_regex __exp;
43660b57cec5SDimitry Andric                                __exp.__flags_ = __flags_;
43670b57cec5SDimitry Andric                                __temp = __exp.__parse(++__temp, __last);
43680b57cec5SDimitry Andric                                unsigned __mexp = __exp.__marked_count_;
43690b57cec5SDimitry Andric                                __push_lookahead(_VSTD::move(__exp), true, __marked_count_);
43700b57cec5SDimitry Andric                                __marked_count_ += __mexp;
43710b57cec5SDimitry Andric                                if (__temp == __last || *__temp != ')')
43720b57cec5SDimitry Andric                                    __throw_regex_error<regex_constants::error_paren>();
43730b57cec5SDimitry Andric                                __first = ++__temp;
43740b57cec5SDimitry Andric                            }
43750b57cec5SDimitry Andric                            break;
43760b57cec5SDimitry Andric                        }
43770b57cec5SDimitry Andric                    }
43780b57cec5SDimitry Andric                }
43790b57cec5SDimitry Andric            }
43800b57cec5SDimitry Andric            break;
43810b57cec5SDimitry Andric        }
43820b57cec5SDimitry Andric    }
43830b57cec5SDimitry Andric    return __first;
43840b57cec5SDimitry Andric}
43850b57cec5SDimitry Andric
43860b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
43870b57cec5SDimitry Andrictemplate <class _ForwardIterator>
43880b57cec5SDimitry Andric_ForwardIterator
43890b57cec5SDimitry Andricbasic_regex<_CharT, _Traits>::__parse_atom(_ForwardIterator __first,
43900b57cec5SDimitry Andric                                           _ForwardIterator __last)
43910b57cec5SDimitry Andric{
43920b57cec5SDimitry Andric    if (__first != __last)
43930b57cec5SDimitry Andric    {
43940b57cec5SDimitry Andric        switch (*__first)
43950b57cec5SDimitry Andric        {
43960b57cec5SDimitry Andric        case '.':
43970b57cec5SDimitry Andric            __push_match_any_but_newline();
43980b57cec5SDimitry Andric            ++__first;
43990b57cec5SDimitry Andric            break;
44000b57cec5SDimitry Andric        case '\\':
44010b57cec5SDimitry Andric            __first = __parse_atom_escape(__first, __last);
44020b57cec5SDimitry Andric            break;
44030b57cec5SDimitry Andric        case '[':
44040b57cec5SDimitry Andric            __first = __parse_bracket_expression(__first, __last);
44050b57cec5SDimitry Andric            break;
44060b57cec5SDimitry Andric        case '(':
44070b57cec5SDimitry Andric            {
44080b57cec5SDimitry Andric                ++__first;
44090b57cec5SDimitry Andric                if (__first == __last)
44100b57cec5SDimitry Andric                    __throw_regex_error<regex_constants::error_paren>();
44110b57cec5SDimitry Andric                _ForwardIterator __temp = _VSTD::next(__first);
44120b57cec5SDimitry Andric                if (__temp != __last && *__first == '?' && *__temp == ':')
44130b57cec5SDimitry Andric                {
44140b57cec5SDimitry Andric                    ++__open_count_;
44150b57cec5SDimitry Andric                    __first = __parse_ecma_exp(++__temp, __last);
44160b57cec5SDimitry Andric                    if (__first == __last || *__first != ')')
44170b57cec5SDimitry Andric                        __throw_regex_error<regex_constants::error_paren>();
44180b57cec5SDimitry Andric                    --__open_count_;
44190b57cec5SDimitry Andric                    ++__first;
44200b57cec5SDimitry Andric                }
44210b57cec5SDimitry Andric                else
44220b57cec5SDimitry Andric                {
44230b57cec5SDimitry Andric                    __push_begin_marked_subexpression();
44240b57cec5SDimitry Andric                    unsigned __temp_count = __marked_count_;
44250b57cec5SDimitry Andric                    ++__open_count_;
44260b57cec5SDimitry Andric                    __first = __parse_ecma_exp(__first, __last);
44270b57cec5SDimitry Andric                    if (__first == __last || *__first != ')')
44280b57cec5SDimitry Andric                        __throw_regex_error<regex_constants::error_paren>();
44290b57cec5SDimitry Andric                    __push_end_marked_subexpression(__temp_count);
44300b57cec5SDimitry Andric                    --__open_count_;
44310b57cec5SDimitry Andric                    ++__first;
44320b57cec5SDimitry Andric                }
44330b57cec5SDimitry Andric            }
44340b57cec5SDimitry Andric            break;
44350b57cec5SDimitry Andric        case '*':
44360b57cec5SDimitry Andric        case '+':
44370b57cec5SDimitry Andric        case '?':
44380b57cec5SDimitry Andric        case '{':
44390b57cec5SDimitry Andric            __throw_regex_error<regex_constants::error_badrepeat>();
44400b57cec5SDimitry Andric            break;
44410b57cec5SDimitry Andric        default:
44420b57cec5SDimitry Andric            __first = __parse_pattern_character(__first, __last);
44430b57cec5SDimitry Andric            break;
44440b57cec5SDimitry Andric        }
44450b57cec5SDimitry Andric    }
44460b57cec5SDimitry Andric    return __first;
44470b57cec5SDimitry Andric}
44480b57cec5SDimitry Andric
44490b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
44500b57cec5SDimitry Andrictemplate <class _ForwardIterator>
44510b57cec5SDimitry Andric_ForwardIterator
44520b57cec5SDimitry Andricbasic_regex<_CharT, _Traits>::__parse_atom_escape(_ForwardIterator __first,
44530b57cec5SDimitry Andric                                                  _ForwardIterator __last)
44540b57cec5SDimitry Andric{
44550b57cec5SDimitry Andric    if (__first != __last && *__first == '\\')
44560b57cec5SDimitry Andric    {
44570b57cec5SDimitry Andric        _ForwardIterator __t1 = _VSTD::next(__first);
44580b57cec5SDimitry Andric        if (__t1 == __last)
44590b57cec5SDimitry Andric            __throw_regex_error<regex_constants::error_escape>();
44600b57cec5SDimitry Andric
44610b57cec5SDimitry Andric        _ForwardIterator __t2 = __parse_decimal_escape(__t1, __last);
44620b57cec5SDimitry Andric        if (__t2 != __t1)
44630b57cec5SDimitry Andric            __first = __t2;
44640b57cec5SDimitry Andric        else
44650b57cec5SDimitry Andric        {
44660b57cec5SDimitry Andric            __t2 = __parse_character_class_escape(__t1, __last);
44670b57cec5SDimitry Andric            if (__t2 != __t1)
44680b57cec5SDimitry Andric                __first = __t2;
44690b57cec5SDimitry Andric            else
44700b57cec5SDimitry Andric            {
44710b57cec5SDimitry Andric                __t2 = __parse_character_escape(__t1, __last);
44720b57cec5SDimitry Andric                if (__t2 != __t1)
44730b57cec5SDimitry Andric                    __first = __t2;
44740b57cec5SDimitry Andric            }
44750b57cec5SDimitry Andric        }
44760b57cec5SDimitry Andric    }
44770b57cec5SDimitry Andric    return __first;
44780b57cec5SDimitry Andric}
44790b57cec5SDimitry Andric
44800b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
44810b57cec5SDimitry Andrictemplate <class _ForwardIterator>
44820b57cec5SDimitry Andric_ForwardIterator
44830b57cec5SDimitry Andricbasic_regex<_CharT, _Traits>::__parse_decimal_escape(_ForwardIterator __first,
44840b57cec5SDimitry Andric                                                     _ForwardIterator __last)
44850b57cec5SDimitry Andric{
44860b57cec5SDimitry Andric    if (__first != __last)
44870b57cec5SDimitry Andric    {
44880b57cec5SDimitry Andric        if (*__first == '0')
44890b57cec5SDimitry Andric        {
44900b57cec5SDimitry Andric            __push_char(_CharT());
44910b57cec5SDimitry Andric            ++__first;
44920b57cec5SDimitry Andric        }
44930b57cec5SDimitry Andric        else if ('1' <= *__first && *__first <= '9')
44940b57cec5SDimitry Andric        {
44950b57cec5SDimitry Andric            unsigned __v = *__first - '0';
44960b57cec5SDimitry Andric            for (++__first;
44970b57cec5SDimitry Andric                    __first != __last && '0' <= *__first && *__first <= '9'; ++__first)
44980b57cec5SDimitry Andric                {
4499e8d8bef9SDimitry Andric                if (__v >= numeric_limits<unsigned>::max() / 10)
45000b57cec5SDimitry Andric                    __throw_regex_error<regex_constants::error_backref>();
45010b57cec5SDimitry Andric                __v = 10 * __v + *__first - '0';
45020b57cec5SDimitry Andric                }
45030b57cec5SDimitry Andric            if (__v == 0 || __v > mark_count())
45040b57cec5SDimitry Andric                __throw_regex_error<regex_constants::error_backref>();
45050b57cec5SDimitry Andric            __push_back_ref(__v);
45060b57cec5SDimitry Andric        }
45070b57cec5SDimitry Andric    }
45080b57cec5SDimitry Andric    return __first;
45090b57cec5SDimitry Andric}
45100b57cec5SDimitry Andric
45110b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
45120b57cec5SDimitry Andrictemplate <class _ForwardIterator>
45130b57cec5SDimitry Andric_ForwardIterator
45140b57cec5SDimitry Andricbasic_regex<_CharT, _Traits>::__parse_character_class_escape(_ForwardIterator __first,
45150b57cec5SDimitry Andric                                                             _ForwardIterator __last)
45160b57cec5SDimitry Andric{
45170b57cec5SDimitry Andric    if (__first != __last)
45180b57cec5SDimitry Andric    {
45190b57cec5SDimitry Andric        __bracket_expression<_CharT, _Traits>* __ml;
45200b57cec5SDimitry Andric        switch (*__first)
45210b57cec5SDimitry Andric        {
45220b57cec5SDimitry Andric        case 'd':
45230b57cec5SDimitry Andric            __ml = __start_matching_list(false);
45240b57cec5SDimitry Andric            __ml->__add_class(ctype_base::digit);
45250b57cec5SDimitry Andric            ++__first;
45260b57cec5SDimitry Andric            break;
45270b57cec5SDimitry Andric        case 'D':
45280b57cec5SDimitry Andric            __ml = __start_matching_list(true);
45290b57cec5SDimitry Andric            __ml->__add_class(ctype_base::digit);
45300b57cec5SDimitry Andric            ++__first;
45310b57cec5SDimitry Andric            break;
45320b57cec5SDimitry Andric        case 's':
45330b57cec5SDimitry Andric            __ml = __start_matching_list(false);
45340b57cec5SDimitry Andric            __ml->__add_class(ctype_base::space);
45350b57cec5SDimitry Andric            ++__first;
45360b57cec5SDimitry Andric            break;
45370b57cec5SDimitry Andric        case 'S':
45380b57cec5SDimitry Andric            __ml = __start_matching_list(true);
45390b57cec5SDimitry Andric            __ml->__add_class(ctype_base::space);
45400b57cec5SDimitry Andric            ++__first;
45410b57cec5SDimitry Andric            break;
45420b57cec5SDimitry Andric        case 'w':
45430b57cec5SDimitry Andric            __ml = __start_matching_list(false);
45440b57cec5SDimitry Andric            __ml->__add_class(ctype_base::alnum);
45450b57cec5SDimitry Andric            __ml->__add_char('_');
45460b57cec5SDimitry Andric            ++__first;
45470b57cec5SDimitry Andric            break;
45480b57cec5SDimitry Andric        case 'W':
45490b57cec5SDimitry Andric            __ml = __start_matching_list(true);
45500b57cec5SDimitry Andric            __ml->__add_class(ctype_base::alnum);
45510b57cec5SDimitry Andric            __ml->__add_char('_');
45520b57cec5SDimitry Andric            ++__first;
45530b57cec5SDimitry Andric            break;
45540b57cec5SDimitry Andric        }
45550b57cec5SDimitry Andric    }
45560b57cec5SDimitry Andric    return __first;
45570b57cec5SDimitry Andric}
45580b57cec5SDimitry Andric
45590b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
45600b57cec5SDimitry Andrictemplate <class _ForwardIterator>
45610b57cec5SDimitry Andric_ForwardIterator
45620b57cec5SDimitry Andricbasic_regex<_CharT, _Traits>::__parse_character_escape(_ForwardIterator __first,
45630b57cec5SDimitry Andric                                                    _ForwardIterator __last,
45640b57cec5SDimitry Andric                                                    basic_string<_CharT>* __str)
45650b57cec5SDimitry Andric{
45660b57cec5SDimitry Andric    if (__first != __last)
45670b57cec5SDimitry Andric    {
45680b57cec5SDimitry Andric        _ForwardIterator __t;
45690b57cec5SDimitry Andric        unsigned __sum = 0;
45700b57cec5SDimitry Andric        int __hd;
45710b57cec5SDimitry Andric        switch (*__first)
45720b57cec5SDimitry Andric        {
45730b57cec5SDimitry Andric        case 'f':
45740b57cec5SDimitry Andric            if (__str)
45750b57cec5SDimitry Andric                *__str = _CharT(0xC);
45760b57cec5SDimitry Andric            else
45770b57cec5SDimitry Andric                __push_char(_CharT(0xC));
45780b57cec5SDimitry Andric            ++__first;
45790b57cec5SDimitry Andric            break;
45800b57cec5SDimitry Andric        case 'n':
45810b57cec5SDimitry Andric            if (__str)
45820b57cec5SDimitry Andric                *__str = _CharT(0xA);
45830b57cec5SDimitry Andric            else
45840b57cec5SDimitry Andric                __push_char(_CharT(0xA));
45850b57cec5SDimitry Andric            ++__first;
45860b57cec5SDimitry Andric            break;
45870b57cec5SDimitry Andric        case 'r':
45880b57cec5SDimitry Andric            if (__str)
45890b57cec5SDimitry Andric                *__str = _CharT(0xD);
45900b57cec5SDimitry Andric            else
45910b57cec5SDimitry Andric                __push_char(_CharT(0xD));
45920b57cec5SDimitry Andric            ++__first;
45930b57cec5SDimitry Andric            break;
45940b57cec5SDimitry Andric        case 't':
45950b57cec5SDimitry Andric            if (__str)
45960b57cec5SDimitry Andric                *__str = _CharT(0x9);
45970b57cec5SDimitry Andric            else
45980b57cec5SDimitry Andric                __push_char(_CharT(0x9));
45990b57cec5SDimitry Andric            ++__first;
46000b57cec5SDimitry Andric            break;
46010b57cec5SDimitry Andric        case 'v':
46020b57cec5SDimitry Andric            if (__str)
46030b57cec5SDimitry Andric                *__str = _CharT(0xB);
46040b57cec5SDimitry Andric            else
46050b57cec5SDimitry Andric                __push_char(_CharT(0xB));
46060b57cec5SDimitry Andric            ++__first;
46070b57cec5SDimitry Andric            break;
46080b57cec5SDimitry Andric        case 'c':
46090b57cec5SDimitry Andric            if ((__t = _VSTD::next(__first)) != __last)
46100b57cec5SDimitry Andric            {
46110b57cec5SDimitry Andric                if (('A' <= *__t && *__t <= 'Z') ||
46120b57cec5SDimitry Andric                    ('a' <= *__t && *__t <= 'z'))
46130b57cec5SDimitry Andric                {
46140b57cec5SDimitry Andric                    if (__str)
46150b57cec5SDimitry Andric                        *__str = _CharT(*__t % 32);
46160b57cec5SDimitry Andric                    else
46170b57cec5SDimitry Andric                        __push_char(_CharT(*__t % 32));
46180b57cec5SDimitry Andric                    __first = ++__t;
46190b57cec5SDimitry Andric                }
46200b57cec5SDimitry Andric                else
46210b57cec5SDimitry Andric                    __throw_regex_error<regex_constants::error_escape>();
46220b57cec5SDimitry Andric            }
46230b57cec5SDimitry Andric            else
46240b57cec5SDimitry Andric                __throw_regex_error<regex_constants::error_escape>();
46250b57cec5SDimitry Andric            break;
46260b57cec5SDimitry Andric        case 'u':
46270b57cec5SDimitry Andric            ++__first;
46280b57cec5SDimitry Andric            if (__first == __last)
46290b57cec5SDimitry Andric                __throw_regex_error<regex_constants::error_escape>();
46300b57cec5SDimitry Andric            __hd = __traits_.value(*__first, 16);
46310b57cec5SDimitry Andric            if (__hd == -1)
46320b57cec5SDimitry Andric                __throw_regex_error<regex_constants::error_escape>();
46330b57cec5SDimitry Andric            __sum = 16 * __sum + static_cast<unsigned>(__hd);
46340b57cec5SDimitry Andric            ++__first;
46350b57cec5SDimitry Andric            if (__first == __last)
46360b57cec5SDimitry Andric                __throw_regex_error<regex_constants::error_escape>();
46370b57cec5SDimitry Andric            __hd = __traits_.value(*__first, 16);
46380b57cec5SDimitry Andric            if (__hd == -1)
46390b57cec5SDimitry Andric                __throw_regex_error<regex_constants::error_escape>();
46400b57cec5SDimitry Andric            __sum = 16 * __sum + static_cast<unsigned>(__hd);
4641fe6060f1SDimitry Andric            // fallthrough
46420b57cec5SDimitry Andric        case 'x':
46430b57cec5SDimitry Andric            ++__first;
46440b57cec5SDimitry Andric            if (__first == __last)
46450b57cec5SDimitry Andric                __throw_regex_error<regex_constants::error_escape>();
46460b57cec5SDimitry Andric            __hd = __traits_.value(*__first, 16);
46470b57cec5SDimitry Andric            if (__hd == -1)
46480b57cec5SDimitry Andric                __throw_regex_error<regex_constants::error_escape>();
46490b57cec5SDimitry Andric            __sum = 16 * __sum + static_cast<unsigned>(__hd);
46500b57cec5SDimitry Andric            ++__first;
46510b57cec5SDimitry Andric            if (__first == __last)
46520b57cec5SDimitry Andric                __throw_regex_error<regex_constants::error_escape>();
46530b57cec5SDimitry Andric            __hd = __traits_.value(*__first, 16);
46540b57cec5SDimitry Andric            if (__hd == -1)
46550b57cec5SDimitry Andric                __throw_regex_error<regex_constants::error_escape>();
46560b57cec5SDimitry Andric            __sum = 16 * __sum + static_cast<unsigned>(__hd);
46570b57cec5SDimitry Andric            if (__str)
46580b57cec5SDimitry Andric                *__str = _CharT(__sum);
46590b57cec5SDimitry Andric            else
46600b57cec5SDimitry Andric                __push_char(_CharT(__sum));
46610b57cec5SDimitry Andric            ++__first;
46620b57cec5SDimitry Andric            break;
46630b57cec5SDimitry Andric        case '0':
46640b57cec5SDimitry Andric            if (__str)
46650b57cec5SDimitry Andric                *__str = _CharT(0);
46660b57cec5SDimitry Andric            else
46670b57cec5SDimitry Andric                __push_char(_CharT(0));
46680b57cec5SDimitry Andric            ++__first;
46690b57cec5SDimitry Andric            break;
46700b57cec5SDimitry Andric        default:
46710b57cec5SDimitry Andric            if (*__first != '_' && !__traits_.isctype(*__first, ctype_base::alnum))
46720b57cec5SDimitry Andric            {
46730b57cec5SDimitry Andric                if (__str)
46740b57cec5SDimitry Andric                    *__str = *__first;
46750b57cec5SDimitry Andric                else
46760b57cec5SDimitry Andric                    __push_char(*__first);
46770b57cec5SDimitry Andric                ++__first;
46780b57cec5SDimitry Andric            }
46790b57cec5SDimitry Andric            else
46800b57cec5SDimitry Andric                __throw_regex_error<regex_constants::error_escape>();
46810b57cec5SDimitry Andric            break;
46820b57cec5SDimitry Andric        }
46830b57cec5SDimitry Andric    }
46840b57cec5SDimitry Andric    return __first;
46850b57cec5SDimitry Andric}
46860b57cec5SDimitry Andric
46870b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
46880b57cec5SDimitry Andrictemplate <class _ForwardIterator>
46890b57cec5SDimitry Andric_ForwardIterator
46900b57cec5SDimitry Andricbasic_regex<_CharT, _Traits>::__parse_pattern_character(_ForwardIterator __first,
46910b57cec5SDimitry Andric                                                        _ForwardIterator __last)
46920b57cec5SDimitry Andric{
46930b57cec5SDimitry Andric    if (__first != __last)
46940b57cec5SDimitry Andric    {
46950b57cec5SDimitry Andric        switch (*__first)
46960b57cec5SDimitry Andric        {
46970b57cec5SDimitry Andric        case '^':
46980b57cec5SDimitry Andric        case '$':
46990b57cec5SDimitry Andric        case '\\':
47000b57cec5SDimitry Andric        case '.':
47010b57cec5SDimitry Andric        case '*':
47020b57cec5SDimitry Andric        case '+':
47030b57cec5SDimitry Andric        case '?':
47040b57cec5SDimitry Andric        case '(':
47050b57cec5SDimitry Andric        case ')':
47060b57cec5SDimitry Andric        case '[':
47070b57cec5SDimitry Andric        case ']':
47080b57cec5SDimitry Andric        case '{':
47090b57cec5SDimitry Andric        case '}':
47100b57cec5SDimitry Andric        case '|':
47110b57cec5SDimitry Andric            break;
47120b57cec5SDimitry Andric        default:
47130b57cec5SDimitry Andric            __push_char(*__first);
47140b57cec5SDimitry Andric            ++__first;
47150b57cec5SDimitry Andric            break;
47160b57cec5SDimitry Andric        }
47170b57cec5SDimitry Andric    }
47180b57cec5SDimitry Andric    return __first;
47190b57cec5SDimitry Andric}
47200b57cec5SDimitry Andric
47210b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
47220b57cec5SDimitry Andrictemplate <class _ForwardIterator>
47230b57cec5SDimitry Andric_ForwardIterator
47240b57cec5SDimitry Andricbasic_regex<_CharT, _Traits>::__parse_grep(_ForwardIterator __first,
47250b57cec5SDimitry Andric                                           _ForwardIterator __last)
47260b57cec5SDimitry Andric{
47270b57cec5SDimitry Andric    __owns_one_state<_CharT>* __sa = __end_;
47280b57cec5SDimitry Andric    _ForwardIterator __t1 = _VSTD::find(__first, __last, _CharT('\n'));
47290b57cec5SDimitry Andric    if (__t1 != __first)
47300b57cec5SDimitry Andric        __parse_basic_reg_exp(__first, __t1);
47310b57cec5SDimitry Andric    else
47320b57cec5SDimitry Andric        __push_empty();
47330b57cec5SDimitry Andric    __first = __t1;
47340b57cec5SDimitry Andric    if (__first != __last)
47350b57cec5SDimitry Andric        ++__first;
47360b57cec5SDimitry Andric    while (__first != __last)
47370b57cec5SDimitry Andric    {
47380b57cec5SDimitry Andric        __t1 = _VSTD::find(__first, __last, _CharT('\n'));
47390b57cec5SDimitry Andric        __owns_one_state<_CharT>* __sb = __end_;
47400b57cec5SDimitry Andric        if (__t1 != __first)
47410b57cec5SDimitry Andric            __parse_basic_reg_exp(__first, __t1);
47420b57cec5SDimitry Andric        else
47430b57cec5SDimitry Andric            __push_empty();
47440b57cec5SDimitry Andric        __push_alternation(__sa, __sb);
47450b57cec5SDimitry Andric        __first = __t1;
47460b57cec5SDimitry Andric        if (__first != __last)
47470b57cec5SDimitry Andric            ++__first;
47480b57cec5SDimitry Andric    }
47490b57cec5SDimitry Andric    return __first;
47500b57cec5SDimitry Andric}
47510b57cec5SDimitry Andric
47520b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
47530b57cec5SDimitry Andrictemplate <class _ForwardIterator>
47540b57cec5SDimitry Andric_ForwardIterator
47550b57cec5SDimitry Andricbasic_regex<_CharT, _Traits>::__parse_egrep(_ForwardIterator __first,
47560b57cec5SDimitry Andric                                            _ForwardIterator __last)
47570b57cec5SDimitry Andric{
47580b57cec5SDimitry Andric    __owns_one_state<_CharT>* __sa = __end_;
47590b57cec5SDimitry Andric    _ForwardIterator __t1 = _VSTD::find(__first, __last, _CharT('\n'));
47600b57cec5SDimitry Andric    if (__t1 != __first)
47610b57cec5SDimitry Andric        __parse_extended_reg_exp(__first, __t1);
47620b57cec5SDimitry Andric    else
47630b57cec5SDimitry Andric        __push_empty();
47640b57cec5SDimitry Andric    __first = __t1;
47650b57cec5SDimitry Andric    if (__first != __last)
47660b57cec5SDimitry Andric        ++__first;
47670b57cec5SDimitry Andric    while (__first != __last)
47680b57cec5SDimitry Andric    {
47690b57cec5SDimitry Andric        __t1 = _VSTD::find(__first, __last, _CharT('\n'));
47700b57cec5SDimitry Andric        __owns_one_state<_CharT>* __sb = __end_;
47710b57cec5SDimitry Andric        if (__t1 != __first)
47720b57cec5SDimitry Andric            __parse_extended_reg_exp(__first, __t1);
47730b57cec5SDimitry Andric        else
47740b57cec5SDimitry Andric            __push_empty();
47750b57cec5SDimitry Andric        __push_alternation(__sa, __sb);
47760b57cec5SDimitry Andric        __first = __t1;
47770b57cec5SDimitry Andric        if (__first != __last)
47780b57cec5SDimitry Andric            ++__first;
47790b57cec5SDimitry Andric    }
47800b57cec5SDimitry Andric    return __first;
47810b57cec5SDimitry Andric}
47820b57cec5SDimitry Andric
47830b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
47845ffd83dbSDimitry Andricbool
4785753f127fSDimitry Andricbasic_regex<_CharT, _Traits>::__test_back_ref(_CharT __c)
47865ffd83dbSDimitry Andric{
4787753f127fSDimitry Andric    unsigned __val = __traits_.value(__c, 10);
47885ffd83dbSDimitry Andric    if (__val >= 1 && __val <= 9)
47895ffd83dbSDimitry Andric    {
47905ffd83dbSDimitry Andric        if (__val > mark_count())
47915ffd83dbSDimitry Andric            __throw_regex_error<regex_constants::error_backref>();
47925ffd83dbSDimitry Andric        __push_back_ref(__val);
47935ffd83dbSDimitry Andric        return true;
47945ffd83dbSDimitry Andric    }
47955ffd83dbSDimitry Andric
47965ffd83dbSDimitry Andric    return false;
47975ffd83dbSDimitry Andric}
47985ffd83dbSDimitry Andric
47995ffd83dbSDimitry Andrictemplate <class _CharT, class _Traits>
48000b57cec5SDimitry Andricvoid
48010b57cec5SDimitry Andricbasic_regex<_CharT, _Traits>::__push_loop(size_t __min, size_t __max,
48020b57cec5SDimitry Andric        __owns_one_state<_CharT>* __s, size_t __mexp_begin, size_t __mexp_end,
48030b57cec5SDimitry Andric        bool __greedy)
48040b57cec5SDimitry Andric{
48050b57cec5SDimitry Andric    unique_ptr<__empty_state<_CharT> > __e1(new __empty_state<_CharT>(__end_->first()));
48060b57cec5SDimitry Andric    __end_->first() = nullptr;
48070b57cec5SDimitry Andric    unique_ptr<__loop<_CharT> > __e2(new __loop<_CharT>(__loop_count_,
48080b57cec5SDimitry Andric                __s->first(), __e1.get(), __mexp_begin, __mexp_end, __greedy,
48090b57cec5SDimitry Andric                __min, __max));
48100b57cec5SDimitry Andric    __s->first() = nullptr;
48110b57cec5SDimitry Andric    __e1.release();
48120b57cec5SDimitry Andric    __end_->first() = new __repeat_one_loop<_CharT>(__e2.get());
48130b57cec5SDimitry Andric    __end_ = __e2->second();
48140b57cec5SDimitry Andric    __s->first() = __e2.release();
48150b57cec5SDimitry Andric    ++__loop_count_;
48160b57cec5SDimitry Andric}
48170b57cec5SDimitry Andric
48180b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
48190b57cec5SDimitry Andricvoid
48200b57cec5SDimitry Andricbasic_regex<_CharT, _Traits>::__push_char(value_type __c)
48210b57cec5SDimitry Andric{
48220b57cec5SDimitry Andric    if (flags() & icase)
48230b57cec5SDimitry Andric        __end_->first() = new __match_char_icase<_CharT, _Traits>
48240b57cec5SDimitry Andric                                              (__traits_, __c, __end_->first());
48250b57cec5SDimitry Andric    else if (flags() & collate)
48260b57cec5SDimitry Andric        __end_->first() = new __match_char_collate<_CharT, _Traits>
48270b57cec5SDimitry Andric                                              (__traits_, __c, __end_->first());
48280b57cec5SDimitry Andric    else
48290b57cec5SDimitry Andric        __end_->first() = new __match_char<_CharT>(__c, __end_->first());
48300b57cec5SDimitry Andric    __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
48310b57cec5SDimitry Andric}
48320b57cec5SDimitry Andric
48330b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
48340b57cec5SDimitry Andricvoid
48350b57cec5SDimitry Andricbasic_regex<_CharT, _Traits>::__push_begin_marked_subexpression()
48360b57cec5SDimitry Andric{
48370b57cec5SDimitry Andric    if (!(__flags_ & nosubs))
48380b57cec5SDimitry Andric    {
48390b57cec5SDimitry Andric        __end_->first() =
48400b57cec5SDimitry Andric                new __begin_marked_subexpression<_CharT>(++__marked_count_,
48410b57cec5SDimitry Andric                                                         __end_->first());
48420b57cec5SDimitry Andric        __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
48430b57cec5SDimitry Andric    }
48440b57cec5SDimitry Andric}
48450b57cec5SDimitry Andric
48460b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
48470b57cec5SDimitry Andricvoid
48480b57cec5SDimitry Andricbasic_regex<_CharT, _Traits>::__push_end_marked_subexpression(unsigned __sub)
48490b57cec5SDimitry Andric{
48500b57cec5SDimitry Andric    if (!(__flags_ & nosubs))
48510b57cec5SDimitry Andric    {
48520b57cec5SDimitry Andric        __end_->first() =
48530b57cec5SDimitry Andric                new __end_marked_subexpression<_CharT>(__sub, __end_->first());
48540b57cec5SDimitry Andric        __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
48550b57cec5SDimitry Andric    }
48560b57cec5SDimitry Andric}
48570b57cec5SDimitry Andric
48580b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
48590b57cec5SDimitry Andricvoid
48600b57cec5SDimitry Andricbasic_regex<_CharT, _Traits>::__push_l_anchor()
48610b57cec5SDimitry Andric{
4862e8d8bef9SDimitry Andric    __end_->first() = new __l_anchor_multiline<_CharT>(__use_multiline(), __end_->first());
48630b57cec5SDimitry Andric    __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
48640b57cec5SDimitry Andric}
48650b57cec5SDimitry Andric
48660b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
48670b57cec5SDimitry Andricvoid
48680b57cec5SDimitry Andricbasic_regex<_CharT, _Traits>::__push_r_anchor()
48690b57cec5SDimitry Andric{
4870e8d8bef9SDimitry Andric    __end_->first() = new __r_anchor_multiline<_CharT>(__use_multiline(), __end_->first());
48710b57cec5SDimitry Andric    __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
48720b57cec5SDimitry Andric}
48730b57cec5SDimitry Andric
48740b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
48750b57cec5SDimitry Andricvoid
48760b57cec5SDimitry Andricbasic_regex<_CharT, _Traits>::__push_match_any()
48770b57cec5SDimitry Andric{
48780b57cec5SDimitry Andric    __end_->first() = new __match_any<_CharT>(__end_->first());
48790b57cec5SDimitry Andric    __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
48800b57cec5SDimitry Andric}
48810b57cec5SDimitry Andric
48820b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
48830b57cec5SDimitry Andricvoid
48840b57cec5SDimitry Andricbasic_regex<_CharT, _Traits>::__push_match_any_but_newline()
48850b57cec5SDimitry Andric{
48860b57cec5SDimitry Andric    __end_->first() = new __match_any_but_newline<_CharT>(__end_->first());
48870b57cec5SDimitry Andric    __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
48880b57cec5SDimitry Andric}
48890b57cec5SDimitry Andric
48900b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
48910b57cec5SDimitry Andricvoid
48920b57cec5SDimitry Andricbasic_regex<_CharT, _Traits>::__push_empty()
48930b57cec5SDimitry Andric{
48940b57cec5SDimitry Andric    __end_->first() = new __empty_state<_CharT>(__end_->first());
48950b57cec5SDimitry Andric    __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
48960b57cec5SDimitry Andric}
48970b57cec5SDimitry Andric
48980b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
48990b57cec5SDimitry Andricvoid
49000b57cec5SDimitry Andricbasic_regex<_CharT, _Traits>::__push_word_boundary(bool __invert)
49010b57cec5SDimitry Andric{
49020b57cec5SDimitry Andric    __end_->first() = new __word_boundary<_CharT, _Traits>(__traits_, __invert,
49030b57cec5SDimitry Andric                                                           __end_->first());
49040b57cec5SDimitry Andric    __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
49050b57cec5SDimitry Andric}
49060b57cec5SDimitry Andric
49070b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
49080b57cec5SDimitry Andricvoid
49090b57cec5SDimitry Andricbasic_regex<_CharT, _Traits>::__push_back_ref(int __i)
49100b57cec5SDimitry Andric{
49110b57cec5SDimitry Andric    if (flags() & icase)
49120b57cec5SDimitry Andric        __end_->first() = new __back_ref_icase<_CharT, _Traits>
49130b57cec5SDimitry Andric                                              (__traits_, __i, __end_->first());
49140b57cec5SDimitry Andric    else if (flags() & collate)
49150b57cec5SDimitry Andric        __end_->first() = new __back_ref_collate<_CharT, _Traits>
49160b57cec5SDimitry Andric                                              (__traits_, __i, __end_->first());
49170b57cec5SDimitry Andric    else
49180b57cec5SDimitry Andric        __end_->first() = new __back_ref<_CharT>(__i, __end_->first());
49190b57cec5SDimitry Andric    __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
49200b57cec5SDimitry Andric}
49210b57cec5SDimitry Andric
49220b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
49230b57cec5SDimitry Andricvoid
49240b57cec5SDimitry Andricbasic_regex<_CharT, _Traits>::__push_alternation(__owns_one_state<_CharT>* __sa,
49250b57cec5SDimitry Andric                                                 __owns_one_state<_CharT>* __ea)
49260b57cec5SDimitry Andric{
49270b57cec5SDimitry Andric    __sa->first() = new __alternate<_CharT>(
49280b57cec5SDimitry Andric                         static_cast<__owns_one_state<_CharT>*>(__sa->first()),
49290b57cec5SDimitry Andric                         static_cast<__owns_one_state<_CharT>*>(__ea->first()));
49300b57cec5SDimitry Andric    __ea->first() = nullptr;
49310b57cec5SDimitry Andric    __ea->first() = new __empty_state<_CharT>(__end_->first());
49320b57cec5SDimitry Andric    __end_->first() = nullptr;
49330b57cec5SDimitry Andric    __end_->first() = new __empty_non_own_state<_CharT>(__ea->first());
49340b57cec5SDimitry Andric    __end_ = static_cast<__owns_one_state<_CharT>*>(__ea->first());
49350b57cec5SDimitry Andric}
49360b57cec5SDimitry Andric
49370b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
49380b57cec5SDimitry Andric__bracket_expression<_CharT, _Traits>*
49390b57cec5SDimitry Andricbasic_regex<_CharT, _Traits>::__start_matching_list(bool __negate)
49400b57cec5SDimitry Andric{
49410b57cec5SDimitry Andric    __bracket_expression<_CharT, _Traits>* __r =
49420b57cec5SDimitry Andric        new __bracket_expression<_CharT, _Traits>(__traits_, __end_->first(),
49430b57cec5SDimitry Andric                                                  __negate, __flags_ & icase,
49440b57cec5SDimitry Andric                                                  __flags_ & collate);
49450b57cec5SDimitry Andric    __end_->first() = __r;
49460b57cec5SDimitry Andric    __end_ = __r;
49470b57cec5SDimitry Andric    return __r;
49480b57cec5SDimitry Andric}
49490b57cec5SDimitry Andric
49500b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
49510b57cec5SDimitry Andricvoid
49520b57cec5SDimitry Andricbasic_regex<_CharT, _Traits>::__push_lookahead(const basic_regex& __exp,
49530b57cec5SDimitry Andric                                               bool __invert,
49540b57cec5SDimitry Andric                                               unsigned __mexp)
49550b57cec5SDimitry Andric{
49560b57cec5SDimitry Andric    __end_->first() = new __lookahead<_CharT, _Traits>(__exp, __invert,
49570b57cec5SDimitry Andric                                                           __end_->first(), __mexp);
49580b57cec5SDimitry Andric    __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
49590b57cec5SDimitry Andric}
49600b57cec5SDimitry Andric
49610b57cec5SDimitry Andric// sub_match
49620b57cec5SDimitry Andric
4963e8d8bef9SDimitry Andrictypedef sub_match<const char*>             csub_match;
4964e8d8bef9SDimitry Andrictypedef sub_match<string::const_iterator>  ssub_match;
4965349cc55cSDimitry Andric#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
4966349cc55cSDimitry Andrictypedef sub_match<const wchar_t*>          wcsub_match;
4967e8d8bef9SDimitry Andrictypedef sub_match<wstring::const_iterator> wssub_match;
4968349cc55cSDimitry Andric#endif
4969e8d8bef9SDimitry Andric
49700b57cec5SDimitry Andrictemplate <class _BidirectionalIterator>
4971e8d8bef9SDimitry Andricclass
4972e8d8bef9SDimitry Andric    _LIBCPP_TEMPLATE_VIS
4973e8d8bef9SDimitry Andric    _LIBCPP_PREFERRED_NAME(csub_match)
4974349cc55cSDimitry Andric    _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wcsub_match))
4975e8d8bef9SDimitry Andric    _LIBCPP_PREFERRED_NAME(ssub_match)
4976349cc55cSDimitry Andric    _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wssub_match))
4977e8d8bef9SDimitry Andric    sub_match
49780b57cec5SDimitry Andric    : public pair<_BidirectionalIterator, _BidirectionalIterator>
49790b57cec5SDimitry Andric{
49800b57cec5SDimitry Andricpublic:
49810b57cec5SDimitry Andric    typedef _BidirectionalIterator                              iterator;
49820b57cec5SDimitry Andric    typedef typename iterator_traits<iterator>::value_type      value_type;
49830b57cec5SDimitry Andric    typedef typename iterator_traits<iterator>::difference_type difference_type;
49840b57cec5SDimitry Andric    typedef basic_string<value_type>                            string_type;
49850b57cec5SDimitry Andric
49860b57cec5SDimitry Andric    bool matched;
49870b57cec5SDimitry Andric
49880b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
49890b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR sub_match() : matched() {}
49900b57cec5SDimitry Andric
49910b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
49920b57cec5SDimitry Andric    difference_type length() const
49930b57cec5SDimitry Andric        {return matched ? _VSTD::distance(this->first, this->second) : 0;}
49940b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
49950b57cec5SDimitry Andric    string_type str() const
49960b57cec5SDimitry Andric        {return matched ? string_type(this->first, this->second) : string_type();}
49970b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
49980b57cec5SDimitry Andric    operator string_type() const
49990b57cec5SDimitry Andric        {return str();}
50000b57cec5SDimitry Andric
50010b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
50020b57cec5SDimitry Andric    int compare(const sub_match& __s) const
50030b57cec5SDimitry Andric        {return str().compare(__s.str());}
50040b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
50050b57cec5SDimitry Andric    int compare(const string_type& __s) const
50060b57cec5SDimitry Andric        {return str().compare(__s);}
50070b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
50080b57cec5SDimitry Andric    int compare(const value_type* __s) const
50090b57cec5SDimitry Andric        {return str().compare(__s);}
50100b57cec5SDimitry Andric};
50110b57cec5SDimitry Andric
50120b57cec5SDimitry Andrictemplate <class _BiIter>
50130b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
50140b57cec5SDimitry Andricbool
50150b57cec5SDimitry Andricoperator==(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
50160b57cec5SDimitry Andric{
50170b57cec5SDimitry Andric    return __x.compare(__y) == 0;
50180b57cec5SDimitry Andric}
50190b57cec5SDimitry Andric
50200b57cec5SDimitry Andrictemplate <class _BiIter>
50210b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
50220b57cec5SDimitry Andricbool
50230b57cec5SDimitry Andricoperator!=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
50240b57cec5SDimitry Andric{
50250b57cec5SDimitry Andric    return !(__x == __y);
50260b57cec5SDimitry Andric}
50270b57cec5SDimitry Andric
50280b57cec5SDimitry Andrictemplate <class _BiIter>
50290b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
50300b57cec5SDimitry Andricbool
50310b57cec5SDimitry Andricoperator<(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
50320b57cec5SDimitry Andric{
50330b57cec5SDimitry Andric    return __x.compare(__y) < 0;
50340b57cec5SDimitry Andric}
50350b57cec5SDimitry Andric
50360b57cec5SDimitry Andrictemplate <class _BiIter>
50370b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
50380b57cec5SDimitry Andricbool
50390b57cec5SDimitry Andricoperator<=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
50400b57cec5SDimitry Andric{
50410b57cec5SDimitry Andric    return !(__y < __x);
50420b57cec5SDimitry Andric}
50430b57cec5SDimitry Andric
50440b57cec5SDimitry Andrictemplate <class _BiIter>
50450b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
50460b57cec5SDimitry Andricbool
50470b57cec5SDimitry Andricoperator>=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
50480b57cec5SDimitry Andric{
50490b57cec5SDimitry Andric    return !(__x < __y);
50500b57cec5SDimitry Andric}
50510b57cec5SDimitry Andric
50520b57cec5SDimitry Andrictemplate <class _BiIter>
50530b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
50540b57cec5SDimitry Andricbool
50550b57cec5SDimitry Andricoperator>(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
50560b57cec5SDimitry Andric{
50570b57cec5SDimitry Andric    return __y < __x;
50580b57cec5SDimitry Andric}
50590b57cec5SDimitry Andric
50600b57cec5SDimitry Andrictemplate <class _BiIter, class _ST, class _SA>
50610b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
50620b57cec5SDimitry Andricbool
50630b57cec5SDimitry Andricoperator==(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
50640b57cec5SDimitry Andric           const sub_match<_BiIter>& __y)
50650b57cec5SDimitry Andric{
50660b57cec5SDimitry Andric    return __y.compare(typename sub_match<_BiIter>::string_type(__x.data(), __x.size())) == 0;
50670b57cec5SDimitry Andric}
50680b57cec5SDimitry Andric
50690b57cec5SDimitry Andrictemplate <class _BiIter, class _ST, class _SA>
50700b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
50710b57cec5SDimitry Andricbool
50720b57cec5SDimitry Andricoperator!=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
50730b57cec5SDimitry Andric           const sub_match<_BiIter>& __y)
50740b57cec5SDimitry Andric{
50750b57cec5SDimitry Andric    return !(__x == __y);
50760b57cec5SDimitry Andric}
50770b57cec5SDimitry Andric
50780b57cec5SDimitry Andrictemplate <class _BiIter, class _ST, class _SA>
50790b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
50800b57cec5SDimitry Andricbool
50810b57cec5SDimitry Andricoperator<(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
50820b57cec5SDimitry Andric          const sub_match<_BiIter>& __y)
50830b57cec5SDimitry Andric{
50840b57cec5SDimitry Andric    return __y.compare(typename sub_match<_BiIter>::string_type(__x.data(), __x.size())) > 0;
50850b57cec5SDimitry Andric}
50860b57cec5SDimitry Andric
50870b57cec5SDimitry Andrictemplate <class _BiIter, class _ST, class _SA>
50880b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
50890b57cec5SDimitry Andricbool
50900b57cec5SDimitry Andricoperator>(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
50910b57cec5SDimitry Andric          const sub_match<_BiIter>& __y)
50920b57cec5SDimitry Andric{
50930b57cec5SDimitry Andric    return __y < __x;
50940b57cec5SDimitry Andric}
50950b57cec5SDimitry Andric
50960b57cec5SDimitry Andrictemplate <class _BiIter, class _ST, class _SA>
50970b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
50980b57cec5SDimitry Andricbool operator>=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
50990b57cec5SDimitry Andric                const sub_match<_BiIter>& __y)
51000b57cec5SDimitry Andric{
51010b57cec5SDimitry Andric    return !(__x < __y);
51020b57cec5SDimitry Andric}
51030b57cec5SDimitry Andric
51040b57cec5SDimitry Andrictemplate <class _BiIter, class _ST, class _SA>
51050b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
51060b57cec5SDimitry Andricbool
51070b57cec5SDimitry Andricoperator<=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
51080b57cec5SDimitry Andric           const sub_match<_BiIter>& __y)
51090b57cec5SDimitry Andric{
51100b57cec5SDimitry Andric    return !(__y < __x);
51110b57cec5SDimitry Andric}
51120b57cec5SDimitry Andric
51130b57cec5SDimitry Andrictemplate <class _BiIter, class _ST, class _SA>
51140b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
51150b57cec5SDimitry Andricbool
51160b57cec5SDimitry Andricoperator==(const sub_match<_BiIter>& __x,
51170b57cec5SDimitry Andric           const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
51180b57cec5SDimitry Andric{
51190b57cec5SDimitry Andric    return __x.compare(typename sub_match<_BiIter>::string_type(__y.data(), __y.size())) == 0;
51200b57cec5SDimitry Andric}
51210b57cec5SDimitry Andric
51220b57cec5SDimitry Andrictemplate <class _BiIter, class _ST, class _SA>
51230b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
51240b57cec5SDimitry Andricbool
51250b57cec5SDimitry Andricoperator!=(const sub_match<_BiIter>& __x,
51260b57cec5SDimitry Andric           const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
51270b57cec5SDimitry Andric{
51280b57cec5SDimitry Andric    return !(__x == __y);
51290b57cec5SDimitry Andric}
51300b57cec5SDimitry Andric
51310b57cec5SDimitry Andrictemplate <class _BiIter, class _ST, class _SA>
51320b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
51330b57cec5SDimitry Andricbool
51340b57cec5SDimitry Andricoperator<(const sub_match<_BiIter>& __x,
51350b57cec5SDimitry Andric          const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
51360b57cec5SDimitry Andric{
51370b57cec5SDimitry Andric    return __x.compare(typename sub_match<_BiIter>::string_type(__y.data(), __y.size())) < 0;
51380b57cec5SDimitry Andric}
51390b57cec5SDimitry Andric
51400b57cec5SDimitry Andrictemplate <class _BiIter, class _ST, class _SA>
51410b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
51420b57cec5SDimitry Andricbool operator>(const sub_match<_BiIter>& __x,
51430b57cec5SDimitry Andric               const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
51440b57cec5SDimitry Andric{
51450b57cec5SDimitry Andric    return __y < __x;
51460b57cec5SDimitry Andric}
51470b57cec5SDimitry Andric
51480b57cec5SDimitry Andrictemplate <class _BiIter, class _ST, class _SA>
51490b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
51500b57cec5SDimitry Andricbool
51510b57cec5SDimitry Andricoperator>=(const sub_match<_BiIter>& __x,
51520b57cec5SDimitry Andric           const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
51530b57cec5SDimitry Andric{
51540b57cec5SDimitry Andric    return !(__x < __y);
51550b57cec5SDimitry Andric}
51560b57cec5SDimitry Andric
51570b57cec5SDimitry Andrictemplate <class _BiIter, class _ST, class _SA>
51580b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
51590b57cec5SDimitry Andricbool
51600b57cec5SDimitry Andricoperator<=(const sub_match<_BiIter>& __x,
51610b57cec5SDimitry Andric           const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
51620b57cec5SDimitry Andric{
51630b57cec5SDimitry Andric    return !(__y < __x);
51640b57cec5SDimitry Andric}
51650b57cec5SDimitry Andric
51660b57cec5SDimitry Andrictemplate <class _BiIter>
51670b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
51680b57cec5SDimitry Andricbool
51690b57cec5SDimitry Andricoperator==(typename iterator_traits<_BiIter>::value_type const* __x,
51700b57cec5SDimitry Andric           const sub_match<_BiIter>& __y)
51710b57cec5SDimitry Andric{
51720b57cec5SDimitry Andric    return __y.compare(__x) == 0;
51730b57cec5SDimitry Andric}
51740b57cec5SDimitry Andric
51750b57cec5SDimitry Andrictemplate <class _BiIter>
51760b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
51770b57cec5SDimitry Andricbool
51780b57cec5SDimitry Andricoperator!=(typename iterator_traits<_BiIter>::value_type const* __x,
51790b57cec5SDimitry Andric           const sub_match<_BiIter>& __y)
51800b57cec5SDimitry Andric{
51810b57cec5SDimitry Andric    return !(__x == __y);
51820b57cec5SDimitry Andric}
51830b57cec5SDimitry Andric
51840b57cec5SDimitry Andrictemplate <class _BiIter>
51850b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
51860b57cec5SDimitry Andricbool
51870b57cec5SDimitry Andricoperator<(typename iterator_traits<_BiIter>::value_type const* __x,
51880b57cec5SDimitry Andric          const sub_match<_BiIter>& __y)
51890b57cec5SDimitry Andric{
51900b57cec5SDimitry Andric    return __y.compare(__x) > 0;
51910b57cec5SDimitry Andric}
51920b57cec5SDimitry Andric
51930b57cec5SDimitry Andrictemplate <class _BiIter>
51940b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
51950b57cec5SDimitry Andricbool
51960b57cec5SDimitry Andricoperator>(typename iterator_traits<_BiIter>::value_type const* __x,
51970b57cec5SDimitry Andric          const sub_match<_BiIter>& __y)
51980b57cec5SDimitry Andric{
51990b57cec5SDimitry Andric    return __y < __x;
52000b57cec5SDimitry Andric}
52010b57cec5SDimitry Andric
52020b57cec5SDimitry Andrictemplate <class _BiIter>
52030b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
52040b57cec5SDimitry Andricbool
52050b57cec5SDimitry Andricoperator>=(typename iterator_traits<_BiIter>::value_type const* __x,
52060b57cec5SDimitry Andric           const sub_match<_BiIter>& __y)
52070b57cec5SDimitry Andric{
52080b57cec5SDimitry Andric    return !(__x < __y);
52090b57cec5SDimitry Andric}
52100b57cec5SDimitry Andric
52110b57cec5SDimitry Andrictemplate <class _BiIter>
52120b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
52130b57cec5SDimitry Andricbool
52140b57cec5SDimitry Andricoperator<=(typename iterator_traits<_BiIter>::value_type const* __x,
52150b57cec5SDimitry Andric           const sub_match<_BiIter>& __y)
52160b57cec5SDimitry Andric{
52170b57cec5SDimitry Andric    return !(__y < __x);
52180b57cec5SDimitry Andric}
52190b57cec5SDimitry Andric
52200b57cec5SDimitry Andrictemplate <class _BiIter>
52210b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
52220b57cec5SDimitry Andricbool
52230b57cec5SDimitry Andricoperator==(const sub_match<_BiIter>& __x,
52240b57cec5SDimitry Andric           typename iterator_traits<_BiIter>::value_type const* __y)
52250b57cec5SDimitry Andric{
52260b57cec5SDimitry Andric    return __x.compare(__y) == 0;
52270b57cec5SDimitry Andric}
52280b57cec5SDimitry Andric
52290b57cec5SDimitry Andrictemplate <class _BiIter>
52300b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
52310b57cec5SDimitry Andricbool
52320b57cec5SDimitry Andricoperator!=(const sub_match<_BiIter>& __x,
52330b57cec5SDimitry Andric           typename iterator_traits<_BiIter>::value_type const* __y)
52340b57cec5SDimitry Andric{
52350b57cec5SDimitry Andric    return !(__x == __y);
52360b57cec5SDimitry Andric}
52370b57cec5SDimitry Andric
52380b57cec5SDimitry Andrictemplate <class _BiIter>
52390b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
52400b57cec5SDimitry Andricbool
52410b57cec5SDimitry Andricoperator<(const sub_match<_BiIter>& __x,
52420b57cec5SDimitry Andric          typename iterator_traits<_BiIter>::value_type const* __y)
52430b57cec5SDimitry Andric{
52440b57cec5SDimitry Andric    return __x.compare(__y) < 0;
52450b57cec5SDimitry Andric}
52460b57cec5SDimitry Andric
52470b57cec5SDimitry Andrictemplate <class _BiIter>
52480b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
52490b57cec5SDimitry Andricbool
52500b57cec5SDimitry Andricoperator>(const sub_match<_BiIter>& __x,
52510b57cec5SDimitry Andric          typename iterator_traits<_BiIter>::value_type const* __y)
52520b57cec5SDimitry Andric{
52530b57cec5SDimitry Andric    return __y < __x;
52540b57cec5SDimitry Andric}
52550b57cec5SDimitry Andric
52560b57cec5SDimitry Andrictemplate <class _BiIter>
52570b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
52580b57cec5SDimitry Andricbool
52590b57cec5SDimitry Andricoperator>=(const sub_match<_BiIter>& __x,
52600b57cec5SDimitry Andric           typename iterator_traits<_BiIter>::value_type const* __y)
52610b57cec5SDimitry Andric{
52620b57cec5SDimitry Andric    return !(__x < __y);
52630b57cec5SDimitry Andric}
52640b57cec5SDimitry Andric
52650b57cec5SDimitry Andrictemplate <class _BiIter>
52660b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
52670b57cec5SDimitry Andricbool
52680b57cec5SDimitry Andricoperator<=(const sub_match<_BiIter>& __x,
52690b57cec5SDimitry Andric           typename iterator_traits<_BiIter>::value_type const* __y)
52700b57cec5SDimitry Andric{
52710b57cec5SDimitry Andric    return !(__y < __x);
52720b57cec5SDimitry Andric}
52730b57cec5SDimitry Andric
52740b57cec5SDimitry Andrictemplate <class _BiIter>
52750b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
52760b57cec5SDimitry Andricbool
52770b57cec5SDimitry Andricoperator==(typename iterator_traits<_BiIter>::value_type const& __x,
52780b57cec5SDimitry Andric           const sub_match<_BiIter>& __y)
52790b57cec5SDimitry Andric{
52800b57cec5SDimitry Andric    typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
52810b57cec5SDimitry Andric    return __y.compare(string_type(1, __x)) == 0;
52820b57cec5SDimitry Andric}
52830b57cec5SDimitry Andric
52840b57cec5SDimitry Andrictemplate <class _BiIter>
52850b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
52860b57cec5SDimitry Andricbool
52870b57cec5SDimitry Andricoperator!=(typename iterator_traits<_BiIter>::value_type const& __x,
52880b57cec5SDimitry Andric           const sub_match<_BiIter>& __y)
52890b57cec5SDimitry Andric{
52900b57cec5SDimitry Andric    return !(__x == __y);
52910b57cec5SDimitry Andric}
52920b57cec5SDimitry Andric
52930b57cec5SDimitry Andrictemplate <class _BiIter>
52940b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
52950b57cec5SDimitry Andricbool
52960b57cec5SDimitry Andricoperator<(typename iterator_traits<_BiIter>::value_type const& __x,
52970b57cec5SDimitry Andric          const sub_match<_BiIter>& __y)
52980b57cec5SDimitry Andric{
52990b57cec5SDimitry Andric    typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
53000b57cec5SDimitry Andric    return __y.compare(string_type(1, __x)) > 0;
53010b57cec5SDimitry Andric}
53020b57cec5SDimitry Andric
53030b57cec5SDimitry Andrictemplate <class _BiIter>
53040b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
53050b57cec5SDimitry Andricbool
53060b57cec5SDimitry Andricoperator>(typename iterator_traits<_BiIter>::value_type const& __x,
53070b57cec5SDimitry Andric          const sub_match<_BiIter>& __y)
53080b57cec5SDimitry Andric{
53090b57cec5SDimitry Andric    return __y < __x;
53100b57cec5SDimitry Andric}
53110b57cec5SDimitry Andric
53120b57cec5SDimitry Andrictemplate <class _BiIter>
53130b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
53140b57cec5SDimitry Andricbool
53150b57cec5SDimitry Andricoperator>=(typename iterator_traits<_BiIter>::value_type const& __x,
53160b57cec5SDimitry Andric           const sub_match<_BiIter>& __y)
53170b57cec5SDimitry Andric{
53180b57cec5SDimitry Andric    return !(__x < __y);
53190b57cec5SDimitry Andric}
53200b57cec5SDimitry Andric
53210b57cec5SDimitry Andrictemplate <class _BiIter>
53220b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
53230b57cec5SDimitry Andricbool
53240b57cec5SDimitry Andricoperator<=(typename iterator_traits<_BiIter>::value_type const& __x,
53250b57cec5SDimitry Andric           const sub_match<_BiIter>& __y)
53260b57cec5SDimitry Andric{
53270b57cec5SDimitry Andric    return !(__y < __x);
53280b57cec5SDimitry Andric}
53290b57cec5SDimitry Andric
53300b57cec5SDimitry Andrictemplate <class _BiIter>
53310b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
53320b57cec5SDimitry Andricbool
53330b57cec5SDimitry Andricoperator==(const sub_match<_BiIter>& __x,
53340b57cec5SDimitry Andric           typename iterator_traits<_BiIter>::value_type const& __y)
53350b57cec5SDimitry Andric{
53360b57cec5SDimitry Andric    typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
53370b57cec5SDimitry Andric    return __x.compare(string_type(1, __y)) == 0;
53380b57cec5SDimitry Andric}
53390b57cec5SDimitry Andric
53400b57cec5SDimitry Andrictemplate <class _BiIter>
53410b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
53420b57cec5SDimitry Andricbool
53430b57cec5SDimitry Andricoperator!=(const sub_match<_BiIter>& __x,
53440b57cec5SDimitry Andric           typename iterator_traits<_BiIter>::value_type const& __y)
53450b57cec5SDimitry Andric{
53460b57cec5SDimitry Andric    return !(__x == __y);
53470b57cec5SDimitry Andric}
53480b57cec5SDimitry Andric
53490b57cec5SDimitry Andrictemplate <class _BiIter>
53500b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
53510b57cec5SDimitry Andricbool
53520b57cec5SDimitry Andricoperator<(const sub_match<_BiIter>& __x,
53530b57cec5SDimitry Andric          typename iterator_traits<_BiIter>::value_type const& __y)
53540b57cec5SDimitry Andric{
53550b57cec5SDimitry Andric    typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
53560b57cec5SDimitry Andric    return __x.compare(string_type(1, __y)) < 0;
53570b57cec5SDimitry Andric}
53580b57cec5SDimitry Andric
53590b57cec5SDimitry Andrictemplate <class _BiIter>
53600b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
53610b57cec5SDimitry Andricbool
53620b57cec5SDimitry Andricoperator>(const sub_match<_BiIter>& __x,
53630b57cec5SDimitry Andric          typename iterator_traits<_BiIter>::value_type const& __y)
53640b57cec5SDimitry Andric{
53650b57cec5SDimitry Andric    return __y < __x;
53660b57cec5SDimitry Andric}
53670b57cec5SDimitry Andric
53680b57cec5SDimitry Andrictemplate <class _BiIter>
53690b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
53700b57cec5SDimitry Andricbool
53710b57cec5SDimitry Andricoperator>=(const sub_match<_BiIter>& __x,
53720b57cec5SDimitry Andric           typename iterator_traits<_BiIter>::value_type const& __y)
53730b57cec5SDimitry Andric{
53740b57cec5SDimitry Andric    return !(__x < __y);
53750b57cec5SDimitry Andric}
53760b57cec5SDimitry Andric
53770b57cec5SDimitry Andrictemplate <class _BiIter>
53780b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
53790b57cec5SDimitry Andricbool
53800b57cec5SDimitry Andricoperator<=(const sub_match<_BiIter>& __x,
53810b57cec5SDimitry Andric           typename iterator_traits<_BiIter>::value_type const& __y)
53820b57cec5SDimitry Andric{
53830b57cec5SDimitry Andric    return !(__y < __x);
53840b57cec5SDimitry Andric}
53850b57cec5SDimitry Andric
53860b57cec5SDimitry Andrictemplate <class _CharT, class _ST, class _BiIter>
53870b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
53880b57cec5SDimitry Andricbasic_ostream<_CharT, _ST>&
53890b57cec5SDimitry Andricoperator<<(basic_ostream<_CharT, _ST>& __os, const sub_match<_BiIter>& __m)
53900b57cec5SDimitry Andric{
53910b57cec5SDimitry Andric    return __os << __m.str();
53920b57cec5SDimitry Andric}
53930b57cec5SDimitry Andric
5394e8d8bef9SDimitry Andrictypedef match_results<const char*>             cmatch;
5395e8d8bef9SDimitry Andrictypedef match_results<string::const_iterator>  smatch;
5396349cc55cSDimitry Andric#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
5397349cc55cSDimitry Andrictypedef match_results<const wchar_t*>          wcmatch;
5398e8d8bef9SDimitry Andrictypedef match_results<wstring::const_iterator> wsmatch;
5399349cc55cSDimitry Andric#endif
5400e8d8bef9SDimitry Andric
54010b57cec5SDimitry Andrictemplate <class _BidirectionalIterator, class _Allocator>
5402e8d8bef9SDimitry Andricclass
5403e8d8bef9SDimitry Andric    _LIBCPP_TEMPLATE_VIS
5404e8d8bef9SDimitry Andric    _LIBCPP_PREFERRED_NAME(cmatch)
5405349cc55cSDimitry Andric    _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wcmatch))
5406e8d8bef9SDimitry Andric    _LIBCPP_PREFERRED_NAME(smatch)
5407349cc55cSDimitry Andric    _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wsmatch))
5408e8d8bef9SDimitry Andric    match_results
54090b57cec5SDimitry Andric{
54100b57cec5SDimitry Andricpublic:
54110b57cec5SDimitry Andric    typedef _Allocator                                        allocator_type;
54120b57cec5SDimitry Andric    typedef sub_match<_BidirectionalIterator>                 value_type;
54130b57cec5SDimitry Andricprivate:
54140b57cec5SDimitry Andric    typedef vector<value_type, allocator_type>                __container_type;
54150b57cec5SDimitry Andric
54160b57cec5SDimitry Andric    __container_type  __matches_;
54170b57cec5SDimitry Andric    value_type __unmatched_;
54180b57cec5SDimitry Andric    value_type __prefix_;
54190b57cec5SDimitry Andric    value_type __suffix_;
54200b57cec5SDimitry Andric    bool       __ready_;
54210b57cec5SDimitry Andricpublic:
54220b57cec5SDimitry Andric    _BidirectionalIterator __position_start_;
54230b57cec5SDimitry Andric    typedef const value_type&                                 const_reference;
54240b57cec5SDimitry Andric    typedef value_type&                                       reference;
54250b57cec5SDimitry Andric    typedef typename __container_type::const_iterator         const_iterator;
54260b57cec5SDimitry Andric    typedef const_iterator                                    iterator;
54270b57cec5SDimitry Andric    typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type;
54280b57cec5SDimitry Andric    typedef typename allocator_traits<allocator_type>::size_type size_type;
54290b57cec5SDimitry Andric    typedef typename iterator_traits<_BidirectionalIterator>::value_type char_type;
54300b57cec5SDimitry Andric    typedef basic_string<char_type>                           string_type;
54310b57cec5SDimitry Andric
54320b57cec5SDimitry Andric    // construct/copy/destroy:
5433e8d8bef9SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
5434e8d8bef9SDimitry Andric    match_results() : match_results(allocator_type()) {}
5435e8d8bef9SDimitry Andric    explicit match_results(const allocator_type& __a);
5436e8d8bef9SDimitry Andric#else
54370b57cec5SDimitry Andric    explicit match_results(const allocator_type& __a = allocator_type());
5438e8d8bef9SDimitry Andric#endif
5439e8d8bef9SDimitry Andric
54400b57cec5SDimitry Andric//    match_results(const match_results&) = default;
54410b57cec5SDimitry Andric//    match_results& operator=(const match_results&) = default;
54420b57cec5SDimitry Andric//    match_results(match_results&& __m) = default;
54430b57cec5SDimitry Andric//    match_results& operator=(match_results&& __m) = default;
54440b57cec5SDimitry Andric//    ~match_results() = default;
54450b57cec5SDimitry Andric
54460b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
54470b57cec5SDimitry Andric    bool ready() const {return __ready_;}
54480b57cec5SDimitry Andric
54490b57cec5SDimitry Andric    // size:
54500b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
54510b57cec5SDimitry Andric    size_type size() const _NOEXCEPT {return __matches_.size();}
54520b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
54530b57cec5SDimitry Andric    size_type max_size() const _NOEXCEPT {return __matches_.max_size();}
54540b57cec5SDimitry Andric    _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
54550b57cec5SDimitry Andric    bool empty() const _NOEXCEPT {return size() == 0;}
54560b57cec5SDimitry Andric
54570b57cec5SDimitry Andric    // element access:
54580b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
54590b57cec5SDimitry Andric    difference_type length(size_type __sub = 0) const
54600b57cec5SDimitry Andric        {
54610b57cec5SDimitry Andric        _LIBCPP_ASSERT(ready(), "match_results::length() called when not ready");
54620b57cec5SDimitry Andric        return (*this)[__sub].length();
54630b57cec5SDimitry Andric        }
54640b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
54650b57cec5SDimitry Andric    difference_type position(size_type __sub = 0) const
54660b57cec5SDimitry Andric        {
54670b57cec5SDimitry Andric        _LIBCPP_ASSERT(ready(), "match_results::position() called when not ready");
54680b57cec5SDimitry Andric        return _VSTD::distance(__position_start_, (*this)[__sub].first);
54690b57cec5SDimitry Andric        }
54700b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
54710b57cec5SDimitry Andric    string_type str(size_type __sub = 0) const
54720b57cec5SDimitry Andric        {
54730b57cec5SDimitry Andric        _LIBCPP_ASSERT(ready(), "match_results::str() called when not ready");
54740b57cec5SDimitry Andric        return (*this)[__sub].str();
54750b57cec5SDimitry Andric        }
54760b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
54770b57cec5SDimitry Andric    const_reference operator[](size_type __n) const
54780b57cec5SDimitry Andric        {
54790b57cec5SDimitry Andric        _LIBCPP_ASSERT(ready(), "match_results::operator[]() called when not ready");
54800b57cec5SDimitry Andric        return __n < __matches_.size() ? __matches_[__n] : __unmatched_;
54810b57cec5SDimitry Andric        }
54820b57cec5SDimitry Andric
54830b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
54840b57cec5SDimitry Andric    const_reference prefix() const
54850b57cec5SDimitry Andric        {
54860b57cec5SDimitry Andric        _LIBCPP_ASSERT(ready(), "match_results::prefix() called when not ready");
54870b57cec5SDimitry Andric        return __prefix_;
54880b57cec5SDimitry Andric        }
54890b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
54900b57cec5SDimitry Andric    const_reference suffix() const
54910b57cec5SDimitry Andric        {
54920b57cec5SDimitry Andric        _LIBCPP_ASSERT(ready(), "match_results::suffix() called when not ready");
54930b57cec5SDimitry Andric        return __suffix_;
54940b57cec5SDimitry Andric        }
54950b57cec5SDimitry Andric
54960b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
54970b57cec5SDimitry Andric    const_iterator begin() const {return empty() ? __matches_.end() : __matches_.begin();}
54980b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
54990b57cec5SDimitry Andric    const_iterator end() const {return __matches_.end();}
55000b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
55010b57cec5SDimitry Andric    const_iterator cbegin() const {return empty() ? __matches_.end() : __matches_.begin();}
55020b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
55030b57cec5SDimitry Andric    const_iterator cend() const {return __matches_.end();}
55040b57cec5SDimitry Andric
55050b57cec5SDimitry Andric    // format:
55060b57cec5SDimitry Andric    template <class _OutputIter>
55070b57cec5SDimitry Andric        _OutputIter
55080b57cec5SDimitry Andric        format(_OutputIter __output_iter, const char_type* __fmt_first,
55090b57cec5SDimitry Andric               const char_type* __fmt_last,
55100b57cec5SDimitry Andric               regex_constants::match_flag_type __flags = regex_constants::format_default) const;
55110b57cec5SDimitry Andric    template <class _OutputIter, class _ST, class _SA>
55120b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
55130b57cec5SDimitry Andric        _OutputIter
55140b57cec5SDimitry Andric        format(_OutputIter __output_iter, const basic_string<char_type, _ST, _SA>& __fmt,
55150b57cec5SDimitry Andric               regex_constants::match_flag_type __flags = regex_constants::format_default) const
55160b57cec5SDimitry Andric            {return format(__output_iter, __fmt.data(), __fmt.data() + __fmt.size(), __flags);}
55170b57cec5SDimitry Andric    template <class _ST, class _SA>
55180b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
55190b57cec5SDimitry Andric        basic_string<char_type, _ST, _SA>
55200b57cec5SDimitry Andric        format(const basic_string<char_type, _ST, _SA>& __fmt,
55210b57cec5SDimitry Andric               regex_constants::match_flag_type __flags = regex_constants::format_default) const
55220b57cec5SDimitry Andric        {
55230b57cec5SDimitry Andric            basic_string<char_type, _ST, _SA> __r;
55240b57cec5SDimitry Andric            format(back_inserter(__r), __fmt.data(), __fmt.data() + __fmt.size(),
55250b57cec5SDimitry Andric                   __flags);
55260b57cec5SDimitry Andric            return __r;
55270b57cec5SDimitry Andric        }
55280b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
55290b57cec5SDimitry Andric    string_type
55300b57cec5SDimitry Andric        format(const char_type* __fmt,
55310b57cec5SDimitry Andric               regex_constants::match_flag_type __flags = regex_constants::format_default) const
55320b57cec5SDimitry Andric        {
55330b57cec5SDimitry Andric            string_type __r;
55340b57cec5SDimitry Andric            format(back_inserter(__r), __fmt,
55350b57cec5SDimitry Andric                   __fmt + char_traits<char_type>::length(__fmt), __flags);
55360b57cec5SDimitry Andric            return __r;
55370b57cec5SDimitry Andric        }
55380b57cec5SDimitry Andric
55390b57cec5SDimitry Andric    // allocator:
55400b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
55410b57cec5SDimitry Andric    allocator_type get_allocator() const {return __matches_.get_allocator();}
55420b57cec5SDimitry Andric
55430b57cec5SDimitry Andric    // swap:
55440b57cec5SDimitry Andric    void swap(match_results& __m);
55450b57cec5SDimitry Andric
55460b57cec5SDimitry Andric    template <class _Bp, class _Ap>
55470b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
55480b57cec5SDimitry Andric        void __assign(_BidirectionalIterator __f, _BidirectionalIterator __l,
55490b57cec5SDimitry Andric                      const match_results<_Bp, _Ap>& __m, bool __no_update_pos)
55500b57cec5SDimitry Andric    {
55510b57cec5SDimitry Andric        _Bp __mf = __m.prefix().first;
55520b57cec5SDimitry Andric        __matches_.resize(__m.size());
55530b57cec5SDimitry Andric        for (size_type __i = 0; __i < __matches_.size(); ++__i)
55540b57cec5SDimitry Andric        {
55550b57cec5SDimitry Andric            __matches_[__i].first = _VSTD::next(__f, _VSTD::distance(__mf, __m[__i].first));
55560b57cec5SDimitry Andric            __matches_[__i].second = _VSTD::next(__f, _VSTD::distance(__mf, __m[__i].second));
55570b57cec5SDimitry Andric            __matches_[__i].matched = __m[__i].matched;
55580b57cec5SDimitry Andric        }
55590b57cec5SDimitry Andric        __unmatched_.first   = __l;
55600b57cec5SDimitry Andric        __unmatched_.second  = __l;
55610b57cec5SDimitry Andric        __unmatched_.matched = false;
55620b57cec5SDimitry Andric        __prefix_.first = _VSTD::next(__f, _VSTD::distance(__mf, __m.prefix().first));
55630b57cec5SDimitry Andric        __prefix_.second = _VSTD::next(__f, _VSTD::distance(__mf, __m.prefix().second));
55640b57cec5SDimitry Andric        __prefix_.matched = __m.prefix().matched;
55650b57cec5SDimitry Andric        __suffix_.first = _VSTD::next(__f, _VSTD::distance(__mf, __m.suffix().first));
55660b57cec5SDimitry Andric        __suffix_.second = _VSTD::next(__f, _VSTD::distance(__mf, __m.suffix().second));
55670b57cec5SDimitry Andric        __suffix_.matched = __m.suffix().matched;
55680b57cec5SDimitry Andric        if (!__no_update_pos)
55690b57cec5SDimitry Andric            __position_start_ = __prefix_.first;
55700b57cec5SDimitry Andric        __ready_ = __m.ready();
55710b57cec5SDimitry Andric    }
55720b57cec5SDimitry Andric
55730b57cec5SDimitry Andricprivate:
55740b57cec5SDimitry Andric    void __init(unsigned __s,
55750b57cec5SDimitry Andric                _BidirectionalIterator __f, _BidirectionalIterator __l,
55760b57cec5SDimitry Andric                bool __no_update_pos = false);
55770b57cec5SDimitry Andric
55780b57cec5SDimitry Andric    template <class, class> friend class basic_regex;
55790b57cec5SDimitry Andric
55800b57cec5SDimitry Andric    template <class _Bp, class _Ap, class _Cp, class _Tp>
55810b57cec5SDimitry Andric    friend
55820b57cec5SDimitry Andric    bool
55830b57cec5SDimitry Andric    regex_match(_Bp, _Bp, match_results<_Bp, _Ap>&, const basic_regex<_Cp, _Tp>&,
55840b57cec5SDimitry Andric                regex_constants::match_flag_type);
55850b57cec5SDimitry Andric
55860b57cec5SDimitry Andric    template <class _Bp, class _Ap>
55870b57cec5SDimitry Andric    friend
55880b57cec5SDimitry Andric    bool
55890b57cec5SDimitry Andric    operator==(const match_results<_Bp, _Ap>&, const match_results<_Bp, _Ap>&);
55900b57cec5SDimitry Andric
55910b57cec5SDimitry Andric    template <class, class> friend class __lookahead;
55920b57cec5SDimitry Andric};
55930b57cec5SDimitry Andric
55940b57cec5SDimitry Andrictemplate <class _BidirectionalIterator, class _Allocator>
55950b57cec5SDimitry Andricmatch_results<_BidirectionalIterator, _Allocator>::match_results(
55960b57cec5SDimitry Andric        const allocator_type& __a)
55970b57cec5SDimitry Andric    : __matches_(__a),
55980b57cec5SDimitry Andric      __unmatched_(),
55990b57cec5SDimitry Andric      __prefix_(),
56000b57cec5SDimitry Andric      __suffix_(),
56010b57cec5SDimitry Andric      __ready_(false),
56020b57cec5SDimitry Andric      __position_start_()
56030b57cec5SDimitry Andric{
56040b57cec5SDimitry Andric}
56050b57cec5SDimitry Andric
56060b57cec5SDimitry Andrictemplate <class _BidirectionalIterator, class _Allocator>
56070b57cec5SDimitry Andricvoid
56080b57cec5SDimitry Andricmatch_results<_BidirectionalIterator, _Allocator>::__init(unsigned __s,
56090b57cec5SDimitry Andric                         _BidirectionalIterator __f, _BidirectionalIterator __l,
56100b57cec5SDimitry Andric                         bool __no_update_pos)
56110b57cec5SDimitry Andric{
56120b57cec5SDimitry Andric    __unmatched_.first   = __l;
56130b57cec5SDimitry Andric    __unmatched_.second  = __l;
56140b57cec5SDimitry Andric    __unmatched_.matched = false;
56150b57cec5SDimitry Andric    __matches_.assign(__s, __unmatched_);
56160b57cec5SDimitry Andric    __prefix_.first      = __f;
56170b57cec5SDimitry Andric    __prefix_.second     = __f;
56180b57cec5SDimitry Andric    __prefix_.matched    = false;
56190b57cec5SDimitry Andric    __suffix_ = __unmatched_;
56200b57cec5SDimitry Andric    if (!__no_update_pos)
56210b57cec5SDimitry Andric        __position_start_ = __prefix_.first;
56220b57cec5SDimitry Andric    __ready_ = true;
56230b57cec5SDimitry Andric}
56240b57cec5SDimitry Andric
56250b57cec5SDimitry Andrictemplate <class _BidirectionalIterator, class _Allocator>
56260b57cec5SDimitry Andrictemplate <class _OutputIter>
56270b57cec5SDimitry Andric_OutputIter
56280b57cec5SDimitry Andricmatch_results<_BidirectionalIterator, _Allocator>::format(_OutputIter __output_iter,
56290b57cec5SDimitry Andric        const char_type* __fmt_first, const char_type* __fmt_last,
56300b57cec5SDimitry Andric        regex_constants::match_flag_type __flags) const
56310b57cec5SDimitry Andric{
56320b57cec5SDimitry Andric    _LIBCPP_ASSERT(ready(), "match_results::format() called when not ready");
56330b57cec5SDimitry Andric    if (__flags & regex_constants::format_sed)
56340b57cec5SDimitry Andric    {
56350b57cec5SDimitry Andric        for (; __fmt_first != __fmt_last; ++__fmt_first)
56360b57cec5SDimitry Andric        {
56370b57cec5SDimitry Andric            if (*__fmt_first == '&')
56380b57cec5SDimitry Andric                __output_iter = _VSTD::copy(__matches_[0].first, __matches_[0].second,
56390b57cec5SDimitry Andric                                   __output_iter);
56400b57cec5SDimitry Andric            else if (*__fmt_first == '\\' && __fmt_first + 1 != __fmt_last)
56410b57cec5SDimitry Andric            {
56420b57cec5SDimitry Andric                ++__fmt_first;
56430b57cec5SDimitry Andric                if ('0' <= *__fmt_first && *__fmt_first <= '9')
56440b57cec5SDimitry Andric                {
56450b57cec5SDimitry Andric                    size_t __i = *__fmt_first - '0';
56460b57cec5SDimitry Andric                    __output_iter = _VSTD::copy((*this)[__i].first,
56470b57cec5SDimitry Andric                                        (*this)[__i].second, __output_iter);
56480b57cec5SDimitry Andric                }
56490b57cec5SDimitry Andric                else
56500b57cec5SDimitry Andric                {
56510b57cec5SDimitry Andric                    *__output_iter = *__fmt_first;
56520b57cec5SDimitry Andric                    ++__output_iter;
56530b57cec5SDimitry Andric                }
56540b57cec5SDimitry Andric            }
56550b57cec5SDimitry Andric            else
56560b57cec5SDimitry Andric            {
56570b57cec5SDimitry Andric                *__output_iter = *__fmt_first;
56580b57cec5SDimitry Andric                ++__output_iter;
56590b57cec5SDimitry Andric            }
56600b57cec5SDimitry Andric        }
56610b57cec5SDimitry Andric    }
56620b57cec5SDimitry Andric    else
56630b57cec5SDimitry Andric    {
56640b57cec5SDimitry Andric        for (; __fmt_first != __fmt_last; ++__fmt_first)
56650b57cec5SDimitry Andric        {
56660b57cec5SDimitry Andric            if (*__fmt_first == '$' && __fmt_first + 1 != __fmt_last)
56670b57cec5SDimitry Andric            {
56680b57cec5SDimitry Andric                switch (__fmt_first[1])
56690b57cec5SDimitry Andric                {
56700b57cec5SDimitry Andric                case '$':
56710b57cec5SDimitry Andric                    *__output_iter = *++__fmt_first;
56720b57cec5SDimitry Andric                    ++__output_iter;
56730b57cec5SDimitry Andric                    break;
56740b57cec5SDimitry Andric                case '&':
56750b57cec5SDimitry Andric                    ++__fmt_first;
56760b57cec5SDimitry Andric                    __output_iter = _VSTD::copy(__matches_[0].first, __matches_[0].second,
56770b57cec5SDimitry Andric                                       __output_iter);
56780b57cec5SDimitry Andric                    break;
56790b57cec5SDimitry Andric                case '`':
56800b57cec5SDimitry Andric                    ++__fmt_first;
56810b57cec5SDimitry Andric                    __output_iter = _VSTD::copy(__prefix_.first, __prefix_.second, __output_iter);
56820b57cec5SDimitry Andric                    break;
56830b57cec5SDimitry Andric                case '\'':
56840b57cec5SDimitry Andric                    ++__fmt_first;
56850b57cec5SDimitry Andric                    __output_iter = _VSTD::copy(__suffix_.first, __suffix_.second, __output_iter);
56860b57cec5SDimitry Andric                    break;
56870b57cec5SDimitry Andric                default:
56880b57cec5SDimitry Andric                    if ('0' <= __fmt_first[1] && __fmt_first[1] <= '9')
56890b57cec5SDimitry Andric                    {
56900b57cec5SDimitry Andric                        ++__fmt_first;
56910b57cec5SDimitry Andric                        size_t __idx = *__fmt_first - '0';
56920b57cec5SDimitry Andric                        if (__fmt_first + 1 != __fmt_last &&
56930b57cec5SDimitry Andric                            '0' <= __fmt_first[1] && __fmt_first[1] <= '9')
56940b57cec5SDimitry Andric                        {
56950b57cec5SDimitry Andric                            ++__fmt_first;
5696e8d8bef9SDimitry Andric                            if (__idx >= numeric_limits<size_t>::max() / 10)
56970b57cec5SDimitry Andric                                __throw_regex_error<regex_constants::error_escape>();
56980b57cec5SDimitry Andric                            __idx = 10 * __idx + *__fmt_first - '0';
56990b57cec5SDimitry Andric                        }
57000b57cec5SDimitry Andric                        __output_iter = _VSTD::copy((*this)[__idx].first,
57010b57cec5SDimitry Andric                                            (*this)[__idx].second, __output_iter);
57020b57cec5SDimitry Andric                    }
57030b57cec5SDimitry Andric                    else
57040b57cec5SDimitry Andric                    {
57050b57cec5SDimitry Andric                        *__output_iter = *__fmt_first;
57060b57cec5SDimitry Andric                        ++__output_iter;
57070b57cec5SDimitry Andric                    }
57080b57cec5SDimitry Andric                    break;
57090b57cec5SDimitry Andric                }
57100b57cec5SDimitry Andric            }
57110b57cec5SDimitry Andric            else
57120b57cec5SDimitry Andric            {
57130b57cec5SDimitry Andric                *__output_iter = *__fmt_first;
57140b57cec5SDimitry Andric                ++__output_iter;
57150b57cec5SDimitry Andric            }
57160b57cec5SDimitry Andric        }
57170b57cec5SDimitry Andric    }
57180b57cec5SDimitry Andric    return __output_iter;
57190b57cec5SDimitry Andric}
57200b57cec5SDimitry Andric
57210b57cec5SDimitry Andrictemplate <class _BidirectionalIterator, class _Allocator>
57220b57cec5SDimitry Andricvoid
57230b57cec5SDimitry Andricmatch_results<_BidirectionalIterator, _Allocator>::swap(match_results& __m)
57240b57cec5SDimitry Andric{
57250b57cec5SDimitry Andric    using _VSTD::swap;
57260b57cec5SDimitry Andric    swap(__matches_, __m.__matches_);
57270b57cec5SDimitry Andric    swap(__unmatched_, __m.__unmatched_);
57280b57cec5SDimitry Andric    swap(__prefix_, __m.__prefix_);
57290b57cec5SDimitry Andric    swap(__suffix_, __m.__suffix_);
57300b57cec5SDimitry Andric    swap(__position_start_, __m.__position_start_);
57310b57cec5SDimitry Andric    swap(__ready_, __m.__ready_);
57320b57cec5SDimitry Andric}
57330b57cec5SDimitry Andric
57340b57cec5SDimitry Andrictemplate <class _BidirectionalIterator, class _Allocator>
57350b57cec5SDimitry Andricbool
57360b57cec5SDimitry Andricoperator==(const match_results<_BidirectionalIterator, _Allocator>& __x,
57370b57cec5SDimitry Andric           const match_results<_BidirectionalIterator, _Allocator>& __y)
57380b57cec5SDimitry Andric{
57390b57cec5SDimitry Andric    if (__x.__ready_ != __y.__ready_)
57400b57cec5SDimitry Andric        return false;
57410b57cec5SDimitry Andric    if (!__x.__ready_)
57420b57cec5SDimitry Andric        return true;
57430b57cec5SDimitry Andric    return __x.__matches_ == __y.__matches_ &&
57440b57cec5SDimitry Andric           __x.__prefix_ == __y.__prefix_ &&
57450b57cec5SDimitry Andric           __x.__suffix_ == __y.__suffix_;
57460b57cec5SDimitry Andric}
57470b57cec5SDimitry Andric
57480b57cec5SDimitry Andrictemplate <class _BidirectionalIterator, class _Allocator>
57490b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
57500b57cec5SDimitry Andricbool
57510b57cec5SDimitry Andricoperator!=(const match_results<_BidirectionalIterator, _Allocator>& __x,
57520b57cec5SDimitry Andric           const match_results<_BidirectionalIterator, _Allocator>& __y)
57530b57cec5SDimitry Andric{
57540b57cec5SDimitry Andric    return !(__x == __y);
57550b57cec5SDimitry Andric}
57560b57cec5SDimitry Andric
57570b57cec5SDimitry Andrictemplate <class _BidirectionalIterator, class _Allocator>
57580b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
57590b57cec5SDimitry Andricvoid
57600b57cec5SDimitry Andricswap(match_results<_BidirectionalIterator, _Allocator>& __x,
57610b57cec5SDimitry Andric     match_results<_BidirectionalIterator, _Allocator>& __y)
57620b57cec5SDimitry Andric{
57630b57cec5SDimitry Andric    __x.swap(__y);
57640b57cec5SDimitry Andric}
57650b57cec5SDimitry Andric
57660b57cec5SDimitry Andric// regex_search
57670b57cec5SDimitry Andric
57680b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
57690b57cec5SDimitry Andrictemplate <class _Allocator>
57700b57cec5SDimitry Andricbool
57710b57cec5SDimitry Andricbasic_regex<_CharT, _Traits>::__match_at_start_ecma(
57720b57cec5SDimitry Andric        const _CharT* __first, const _CharT* __last,
57730b57cec5SDimitry Andric        match_results<const _CharT*, _Allocator>& __m,
57740b57cec5SDimitry Andric        regex_constants::match_flag_type __flags, bool __at_first) const
57750b57cec5SDimitry Andric{
57760b57cec5SDimitry Andric    vector<__state> __states;
57770b57cec5SDimitry Andric    __node* __st = __start_.get();
57780b57cec5SDimitry Andric    if (__st)
57790b57cec5SDimitry Andric    {
57800b57cec5SDimitry Andric        sub_match<const _CharT*> __unmatched;
57810b57cec5SDimitry Andric        __unmatched.first   = __last;
57820b57cec5SDimitry Andric        __unmatched.second  = __last;
57830b57cec5SDimitry Andric        __unmatched.matched = false;
57840b57cec5SDimitry Andric
57850b57cec5SDimitry Andric        __states.push_back(__state());
57860b57cec5SDimitry Andric        __states.back().__do_ = 0;
57870b57cec5SDimitry Andric        __states.back().__first_ = __first;
57880b57cec5SDimitry Andric        __states.back().__current_ = __first;
57890b57cec5SDimitry Andric        __states.back().__last_ = __last;
57900b57cec5SDimitry Andric        __states.back().__sub_matches_.resize(mark_count(), __unmatched);
57910b57cec5SDimitry Andric        __states.back().__loop_data_.resize(__loop_count());
57920b57cec5SDimitry Andric        __states.back().__node_ = __st;
57930b57cec5SDimitry Andric        __states.back().__flags_ = __flags;
57940b57cec5SDimitry Andric        __states.back().__at_first_ = __at_first;
57950b57cec5SDimitry Andric        int __counter = 0;
57960b57cec5SDimitry Andric        int __length = __last - __first;
57970b57cec5SDimitry Andric        do
57980b57cec5SDimitry Andric        {
57990b57cec5SDimitry Andric            ++__counter;
58000b57cec5SDimitry Andric            if (__counter % _LIBCPP_REGEX_COMPLEXITY_FACTOR == 0 &&
58010b57cec5SDimitry Andric                __counter / _LIBCPP_REGEX_COMPLEXITY_FACTOR >= __length)
58020b57cec5SDimitry Andric              __throw_regex_error<regex_constants::error_complexity>();
58030b57cec5SDimitry Andric            __state& __s = __states.back();
58040b57cec5SDimitry Andric            if (__s.__node_)
58050b57cec5SDimitry Andric                __s.__node_->__exec(__s);
58060b57cec5SDimitry Andric            switch (__s.__do_)
58070b57cec5SDimitry Andric            {
58080b57cec5SDimitry Andric            case __state::__end_state:
58090b57cec5SDimitry Andric                if ((__flags & regex_constants::match_not_null) &&
58100b57cec5SDimitry Andric                    __s.__current_ == __first)
58110b57cec5SDimitry Andric                {
58120b57cec5SDimitry Andric                  __states.pop_back();
58130b57cec5SDimitry Andric                  break;
58140b57cec5SDimitry Andric                }
58150b57cec5SDimitry Andric                if ((__flags & regex_constants::__full_match) &&
58160b57cec5SDimitry Andric                    __s.__current_ != __last)
58170b57cec5SDimitry Andric                {
58180b57cec5SDimitry Andric                  __states.pop_back();
58190b57cec5SDimitry Andric                  break;
58200b57cec5SDimitry Andric                }
58210b57cec5SDimitry Andric                __m.__matches_[0].first = __first;
58220b57cec5SDimitry Andric                __m.__matches_[0].second = _VSTD::next(__first, __s.__current_ - __first);
58230b57cec5SDimitry Andric                __m.__matches_[0].matched = true;
58240b57cec5SDimitry Andric                for (unsigned __i = 0; __i < __s.__sub_matches_.size(); ++__i)
58250b57cec5SDimitry Andric                    __m.__matches_[__i+1] = __s.__sub_matches_[__i];
58260b57cec5SDimitry Andric                return true;
58270b57cec5SDimitry Andric            case __state::__accept_and_consume:
58280b57cec5SDimitry Andric            case __state::__repeat:
58290b57cec5SDimitry Andric            case __state::__accept_but_not_consume:
58300b57cec5SDimitry Andric                break;
58310b57cec5SDimitry Andric            case __state::__split:
58320b57cec5SDimitry Andric                {
58330b57cec5SDimitry Andric                __state __snext = __s;
58340b57cec5SDimitry Andric                __s.__node_->__exec_split(true, __s);
58350b57cec5SDimitry Andric                __snext.__node_->__exec_split(false, __snext);
58360b57cec5SDimitry Andric                __states.push_back(_VSTD::move(__snext));
58370b57cec5SDimitry Andric                }
58380b57cec5SDimitry Andric                break;
58390b57cec5SDimitry Andric            case __state::__reject:
58400b57cec5SDimitry Andric                __states.pop_back();
58410b57cec5SDimitry Andric                break;
58420b57cec5SDimitry Andric            default:
58430b57cec5SDimitry Andric                __throw_regex_error<regex_constants::__re_err_unknown>();
58440b57cec5SDimitry Andric                break;
58450b57cec5SDimitry Andric
58460b57cec5SDimitry Andric            }
58470b57cec5SDimitry Andric        } while (!__states.empty());
58480b57cec5SDimitry Andric    }
58490b57cec5SDimitry Andric    return false;
58500b57cec5SDimitry Andric}
58510b57cec5SDimitry Andric
58520b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
58530b57cec5SDimitry Andrictemplate <class _Allocator>
58540b57cec5SDimitry Andricbool
58550b57cec5SDimitry Andricbasic_regex<_CharT, _Traits>::__match_at_start_posix_nosubs(
58560b57cec5SDimitry Andric        const _CharT* __first, const _CharT* __last,
58570b57cec5SDimitry Andric        match_results<const _CharT*, _Allocator>& __m,
58580b57cec5SDimitry Andric        regex_constants::match_flag_type __flags, bool __at_first) const
58590b57cec5SDimitry Andric{
58600b57cec5SDimitry Andric    deque<__state> __states;
58610b57cec5SDimitry Andric    ptrdiff_t __highest_j = 0;
58620b57cec5SDimitry Andric    ptrdiff_t _Np = _VSTD::distance(__first, __last);
58630b57cec5SDimitry Andric    __node* __st = __start_.get();
58640b57cec5SDimitry Andric    if (__st)
58650b57cec5SDimitry Andric    {
58660b57cec5SDimitry Andric        __states.push_back(__state());
58670b57cec5SDimitry Andric        __states.back().__do_ = 0;
58680b57cec5SDimitry Andric        __states.back().__first_ = __first;
58690b57cec5SDimitry Andric        __states.back().__current_ = __first;
58700b57cec5SDimitry Andric        __states.back().__last_ = __last;
58710b57cec5SDimitry Andric        __states.back().__loop_data_.resize(__loop_count());
58720b57cec5SDimitry Andric        __states.back().__node_ = __st;
58730b57cec5SDimitry Andric        __states.back().__flags_ = __flags;
58740b57cec5SDimitry Andric        __states.back().__at_first_ = __at_first;
58750b57cec5SDimitry Andric        bool __matched = false;
58760b57cec5SDimitry Andric        int __counter = 0;
58770b57cec5SDimitry Andric        int __length = __last - __first;
58780b57cec5SDimitry Andric        do
58790b57cec5SDimitry Andric        {
58800b57cec5SDimitry Andric            ++__counter;
58810b57cec5SDimitry Andric            if (__counter % _LIBCPP_REGEX_COMPLEXITY_FACTOR == 0 &&
58820b57cec5SDimitry Andric                __counter / _LIBCPP_REGEX_COMPLEXITY_FACTOR >= __length)
58830b57cec5SDimitry Andric              __throw_regex_error<regex_constants::error_complexity>();
58840b57cec5SDimitry Andric            __state& __s = __states.back();
58850b57cec5SDimitry Andric            if (__s.__node_)
58860b57cec5SDimitry Andric                __s.__node_->__exec(__s);
58870b57cec5SDimitry Andric            switch (__s.__do_)
58880b57cec5SDimitry Andric            {
58890b57cec5SDimitry Andric            case __state::__end_state:
58900b57cec5SDimitry Andric                if ((__flags & regex_constants::match_not_null) &&
58910b57cec5SDimitry Andric                    __s.__current_ == __first)
58920b57cec5SDimitry Andric                {
58930b57cec5SDimitry Andric                  __states.pop_back();
58940b57cec5SDimitry Andric                  break;
58950b57cec5SDimitry Andric                }
58960b57cec5SDimitry Andric                if ((__flags & regex_constants::__full_match) &&
58970b57cec5SDimitry Andric                    __s.__current_ != __last)
58980b57cec5SDimitry Andric                {
58990b57cec5SDimitry Andric                  __states.pop_back();
59000b57cec5SDimitry Andric                  break;
59010b57cec5SDimitry Andric                }
59020b57cec5SDimitry Andric                if (!__matched || __highest_j < __s.__current_ - __s.__first_)
59030b57cec5SDimitry Andric                    __highest_j = __s.__current_ - __s.__first_;
59040b57cec5SDimitry Andric                __matched = true;
59050b57cec5SDimitry Andric                if (__highest_j == _Np)
59060b57cec5SDimitry Andric                    __states.clear();
59070b57cec5SDimitry Andric                else
59080b57cec5SDimitry Andric                    __states.pop_back();
59090b57cec5SDimitry Andric                break;
59100b57cec5SDimitry Andric            case __state::__consume_input:
59110b57cec5SDimitry Andric                break;
59120b57cec5SDimitry Andric            case __state::__accept_and_consume:
59130b57cec5SDimitry Andric                __states.push_front(_VSTD::move(__s));
59140b57cec5SDimitry Andric                __states.pop_back();
59150b57cec5SDimitry Andric                break;
59160b57cec5SDimitry Andric            case __state::__repeat:
59170b57cec5SDimitry Andric            case __state::__accept_but_not_consume:
59180b57cec5SDimitry Andric                break;
59190b57cec5SDimitry Andric            case __state::__split:
59200b57cec5SDimitry Andric                {
59210b57cec5SDimitry Andric                __state __snext = __s;
59220b57cec5SDimitry Andric                __s.__node_->__exec_split(true, __s);
59230b57cec5SDimitry Andric                __snext.__node_->__exec_split(false, __snext);
59240b57cec5SDimitry Andric                __states.push_back(_VSTD::move(__snext));
59250b57cec5SDimitry Andric                }
59260b57cec5SDimitry Andric                break;
59270b57cec5SDimitry Andric            case __state::__reject:
59280b57cec5SDimitry Andric                __states.pop_back();
59290b57cec5SDimitry Andric                break;
59300b57cec5SDimitry Andric            default:
59310b57cec5SDimitry Andric                __throw_regex_error<regex_constants::__re_err_unknown>();
59320b57cec5SDimitry Andric                break;
59330b57cec5SDimitry Andric            }
59340b57cec5SDimitry Andric        } while (!__states.empty());
59350b57cec5SDimitry Andric        if (__matched)
59360b57cec5SDimitry Andric        {
59370b57cec5SDimitry Andric            __m.__matches_[0].first = __first;
59380b57cec5SDimitry Andric            __m.__matches_[0].second = _VSTD::next(__first, __highest_j);
59390b57cec5SDimitry Andric            __m.__matches_[0].matched = true;
59400b57cec5SDimitry Andric            return true;
59410b57cec5SDimitry Andric        }
59420b57cec5SDimitry Andric    }
59430b57cec5SDimitry Andric    return false;
59440b57cec5SDimitry Andric}
59450b57cec5SDimitry Andric
59460b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
59470b57cec5SDimitry Andrictemplate <class _Allocator>
59480b57cec5SDimitry Andricbool
59490b57cec5SDimitry Andricbasic_regex<_CharT, _Traits>::__match_at_start_posix_subs(
59500b57cec5SDimitry Andric        const _CharT* __first, const _CharT* __last,
59510b57cec5SDimitry Andric        match_results<const _CharT*, _Allocator>& __m,
59520b57cec5SDimitry Andric        regex_constants::match_flag_type __flags, bool __at_first) const
59530b57cec5SDimitry Andric{
59540b57cec5SDimitry Andric    vector<__state> __states;
59550b57cec5SDimitry Andric    __state __best_state;
59560b57cec5SDimitry Andric    ptrdiff_t __highest_j = 0;
59570b57cec5SDimitry Andric    ptrdiff_t _Np = _VSTD::distance(__first, __last);
59580b57cec5SDimitry Andric    __node* __st = __start_.get();
59590b57cec5SDimitry Andric    if (__st)
59600b57cec5SDimitry Andric    {
59610b57cec5SDimitry Andric        sub_match<const _CharT*> __unmatched;
59620b57cec5SDimitry Andric        __unmatched.first   = __last;
59630b57cec5SDimitry Andric        __unmatched.second  = __last;
59640b57cec5SDimitry Andric        __unmatched.matched = false;
59650b57cec5SDimitry Andric
59660b57cec5SDimitry Andric        __states.push_back(__state());
59670b57cec5SDimitry Andric        __states.back().__do_ = 0;
59680b57cec5SDimitry Andric        __states.back().__first_ = __first;
59690b57cec5SDimitry Andric        __states.back().__current_ = __first;
59700b57cec5SDimitry Andric        __states.back().__last_ = __last;
59710b57cec5SDimitry Andric        __states.back().__sub_matches_.resize(mark_count(), __unmatched);
59720b57cec5SDimitry Andric        __states.back().__loop_data_.resize(__loop_count());
59730b57cec5SDimitry Andric        __states.back().__node_ = __st;
59740b57cec5SDimitry Andric        __states.back().__flags_ = __flags;
59750b57cec5SDimitry Andric        __states.back().__at_first_ = __at_first;
59760b57cec5SDimitry Andric        bool __matched = false;
59770b57cec5SDimitry Andric        int __counter = 0;
59780b57cec5SDimitry Andric        int __length = __last - __first;
59790b57cec5SDimitry Andric        do
59800b57cec5SDimitry Andric        {
59810b57cec5SDimitry Andric            ++__counter;
59820b57cec5SDimitry Andric            if (__counter % _LIBCPP_REGEX_COMPLEXITY_FACTOR == 0 &&
59830b57cec5SDimitry Andric                __counter / _LIBCPP_REGEX_COMPLEXITY_FACTOR >= __length)
59840b57cec5SDimitry Andric              __throw_regex_error<regex_constants::error_complexity>();
59850b57cec5SDimitry Andric            __state& __s = __states.back();
59860b57cec5SDimitry Andric            if (__s.__node_)
59870b57cec5SDimitry Andric                __s.__node_->__exec(__s);
59880b57cec5SDimitry Andric            switch (__s.__do_)
59890b57cec5SDimitry Andric            {
59900b57cec5SDimitry Andric            case __state::__end_state:
59910b57cec5SDimitry Andric                if ((__flags & regex_constants::match_not_null) &&
59920b57cec5SDimitry Andric                    __s.__current_ == __first)
59930b57cec5SDimitry Andric                {
59940b57cec5SDimitry Andric                  __states.pop_back();
59950b57cec5SDimitry Andric                  break;
59960b57cec5SDimitry Andric                }
59970b57cec5SDimitry Andric                if ((__flags & regex_constants::__full_match) &&
59980b57cec5SDimitry Andric                    __s.__current_ != __last)
59990b57cec5SDimitry Andric                {
60000b57cec5SDimitry Andric                  __states.pop_back();
60010b57cec5SDimitry Andric                  break;
60020b57cec5SDimitry Andric                }
60030b57cec5SDimitry Andric                if (!__matched || __highest_j < __s.__current_ - __s.__first_)
60040b57cec5SDimitry Andric                {
60050b57cec5SDimitry Andric                    __highest_j = __s.__current_ - __s.__first_;
60060b57cec5SDimitry Andric                    __best_state = __s;
60070b57cec5SDimitry Andric                }
60080b57cec5SDimitry Andric                __matched = true;
60090b57cec5SDimitry Andric                if (__highest_j == _Np)
60100b57cec5SDimitry Andric                    __states.clear();
60110b57cec5SDimitry Andric                else
60120b57cec5SDimitry Andric                    __states.pop_back();
60130b57cec5SDimitry Andric                break;
60140b57cec5SDimitry Andric            case __state::__accept_and_consume:
60150b57cec5SDimitry Andric            case __state::__repeat:
60160b57cec5SDimitry Andric            case __state::__accept_but_not_consume:
60170b57cec5SDimitry Andric                break;
60180b57cec5SDimitry Andric            case __state::__split:
60190b57cec5SDimitry Andric                {
60200b57cec5SDimitry Andric                __state __snext = __s;
60210b57cec5SDimitry Andric                __s.__node_->__exec_split(true, __s);
60220b57cec5SDimitry Andric                __snext.__node_->__exec_split(false, __snext);
60230b57cec5SDimitry Andric                __states.push_back(_VSTD::move(__snext));
60240b57cec5SDimitry Andric                }
60250b57cec5SDimitry Andric                break;
60260b57cec5SDimitry Andric            case __state::__reject:
60270b57cec5SDimitry Andric                __states.pop_back();
60280b57cec5SDimitry Andric                break;
60290b57cec5SDimitry Andric            default:
60300b57cec5SDimitry Andric                __throw_regex_error<regex_constants::__re_err_unknown>();
60310b57cec5SDimitry Andric                break;
60320b57cec5SDimitry Andric            }
60330b57cec5SDimitry Andric        } while (!__states.empty());
60340b57cec5SDimitry Andric        if (__matched)
60350b57cec5SDimitry Andric        {
60360b57cec5SDimitry Andric            __m.__matches_[0].first = __first;
60370b57cec5SDimitry Andric            __m.__matches_[0].second = _VSTD::next(__first, __highest_j);
60380b57cec5SDimitry Andric            __m.__matches_[0].matched = true;
60390b57cec5SDimitry Andric            for (unsigned __i = 0; __i < __best_state.__sub_matches_.size(); ++__i)
60400b57cec5SDimitry Andric                __m.__matches_[__i+1] = __best_state.__sub_matches_[__i];
60410b57cec5SDimitry Andric            return true;
60420b57cec5SDimitry Andric        }
60430b57cec5SDimitry Andric    }
60440b57cec5SDimitry Andric    return false;
60450b57cec5SDimitry Andric}
60460b57cec5SDimitry Andric
60470b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
60480b57cec5SDimitry Andrictemplate <class _Allocator>
60490b57cec5SDimitry Andricbool
60500b57cec5SDimitry Andricbasic_regex<_CharT, _Traits>::__match_at_start(
60510b57cec5SDimitry Andric        const _CharT* __first, const _CharT* __last,
60520b57cec5SDimitry Andric        match_results<const _CharT*, _Allocator>& __m,
60530b57cec5SDimitry Andric        regex_constants::match_flag_type __flags, bool __at_first) const
60540b57cec5SDimitry Andric{
60550b57cec5SDimitry Andric    if (__get_grammar(__flags_) == ECMAScript)
60560b57cec5SDimitry Andric        return __match_at_start_ecma(__first, __last, __m, __flags, __at_first);
60570b57cec5SDimitry Andric    if (mark_count() == 0)
60580b57cec5SDimitry Andric        return __match_at_start_posix_nosubs(__first, __last, __m, __flags, __at_first);
60590b57cec5SDimitry Andric    return __match_at_start_posix_subs(__first, __last, __m, __flags, __at_first);
60600b57cec5SDimitry Andric}
60610b57cec5SDimitry Andric
60620b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
60630b57cec5SDimitry Andrictemplate <class _Allocator>
60640b57cec5SDimitry Andricbool
60650b57cec5SDimitry Andricbasic_regex<_CharT, _Traits>::__search(
60660b57cec5SDimitry Andric        const _CharT* __first, const _CharT* __last,
60670b57cec5SDimitry Andric        match_results<const _CharT*, _Allocator>& __m,
60680b57cec5SDimitry Andric        regex_constants::match_flag_type __flags) const
60690b57cec5SDimitry Andric{
60705ffd83dbSDimitry Andric    if (__flags & regex_constants::match_prev_avail)
60715ffd83dbSDimitry Andric        __flags &= ~(regex_constants::match_not_bol | regex_constants::match_not_bow);
60725ffd83dbSDimitry Andric
60730b57cec5SDimitry Andric    __m.__init(1 + mark_count(), __first, __last,
60740b57cec5SDimitry Andric                                    __flags & regex_constants::__no_update_pos);
60750b57cec5SDimitry Andric    if (__match_at_start(__first, __last, __m, __flags,
60760b57cec5SDimitry Andric                                    !(__flags & regex_constants::__no_update_pos)))
60770b57cec5SDimitry Andric    {
60780b57cec5SDimitry Andric        __m.__prefix_.second = __m[0].first;
60790b57cec5SDimitry Andric        __m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second;
60800b57cec5SDimitry Andric        __m.__suffix_.first = __m[0].second;
60810b57cec5SDimitry Andric        __m.__suffix_.matched = __m.__suffix_.first != __m.__suffix_.second;
60820b57cec5SDimitry Andric        return true;
60830b57cec5SDimitry Andric    }
60840b57cec5SDimitry Andric    if (__first != __last && !(__flags & regex_constants::match_continuous))
60850b57cec5SDimitry Andric    {
60860b57cec5SDimitry Andric        __flags |= regex_constants::match_prev_avail;
60870b57cec5SDimitry Andric        for (++__first; __first != __last; ++__first)
60880b57cec5SDimitry Andric        {
60890b57cec5SDimitry Andric            __m.__matches_.assign(__m.size(), __m.__unmatched_);
60900b57cec5SDimitry Andric            if (__match_at_start(__first, __last, __m, __flags, false))
60910b57cec5SDimitry Andric            {
60920b57cec5SDimitry Andric                __m.__prefix_.second = __m[0].first;
60930b57cec5SDimitry Andric                __m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second;
60940b57cec5SDimitry Andric                __m.__suffix_.first = __m[0].second;
60950b57cec5SDimitry Andric                __m.__suffix_.matched = __m.__suffix_.first != __m.__suffix_.second;
60960b57cec5SDimitry Andric                return true;
60970b57cec5SDimitry Andric            }
60980b57cec5SDimitry Andric            __m.__matches_.assign(__m.size(), __m.__unmatched_);
60990b57cec5SDimitry Andric        }
61000b57cec5SDimitry Andric    }
61010b57cec5SDimitry Andric    __m.__matches_.clear();
61020b57cec5SDimitry Andric    return false;
61030b57cec5SDimitry Andric}
61040b57cec5SDimitry Andric
61050b57cec5SDimitry Andrictemplate <class _BidirectionalIterator, class _Allocator, class _CharT, class _Traits>
61060b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
61070b57cec5SDimitry Andricbool
61080b57cec5SDimitry Andricregex_search(_BidirectionalIterator __first, _BidirectionalIterator __last,
61090b57cec5SDimitry Andric             match_results<_BidirectionalIterator, _Allocator>& __m,
61100b57cec5SDimitry Andric             const basic_regex<_CharT, _Traits>& __e,
61110b57cec5SDimitry Andric             regex_constants::match_flag_type __flags = regex_constants::match_default)
61120b57cec5SDimitry Andric{
61130b57cec5SDimitry Andric    int __offset = (__flags & regex_constants::match_prev_avail) ? 1 : 0;
61140b57cec5SDimitry Andric    basic_string<_CharT> __s(_VSTD::prev(__first, __offset), __last);
61150b57cec5SDimitry Andric    match_results<const _CharT*> __mc;
61160b57cec5SDimitry Andric    bool __r = __e.__search(__s.data() + __offset, __s.data() + __s.size(), __mc, __flags);
61170b57cec5SDimitry Andric    __m.__assign(__first, __last, __mc, __flags & regex_constants::__no_update_pos);
61180b57cec5SDimitry Andric    return __r;
61190b57cec5SDimitry Andric}
61200b57cec5SDimitry Andric
61210b57cec5SDimitry Andrictemplate <class _Iter, class _Allocator, class _CharT, class _Traits>
61220b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
61230b57cec5SDimitry Andricbool
61240b57cec5SDimitry Andricregex_search(__wrap_iter<_Iter> __first,
61250b57cec5SDimitry Andric             __wrap_iter<_Iter> __last,
61260b57cec5SDimitry Andric             match_results<__wrap_iter<_Iter>, _Allocator>& __m,
61270b57cec5SDimitry Andric             const basic_regex<_CharT, _Traits>& __e,
61280b57cec5SDimitry Andric             regex_constants::match_flag_type __flags = regex_constants::match_default)
61290b57cec5SDimitry Andric{
61300b57cec5SDimitry Andric    match_results<const _CharT*> __mc;
61310b57cec5SDimitry Andric    bool __r = __e.__search(__first.base(), __last.base(), __mc, __flags);
61320b57cec5SDimitry Andric    __m.__assign(__first, __last, __mc, __flags & regex_constants::__no_update_pos);
61330b57cec5SDimitry Andric    return __r;
61340b57cec5SDimitry Andric}
61350b57cec5SDimitry Andric
61360b57cec5SDimitry Andrictemplate <class _Allocator, class _CharT, class _Traits>
61370b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
61380b57cec5SDimitry Andricbool
61390b57cec5SDimitry Andricregex_search(const _CharT* __first, const _CharT* __last,
61400b57cec5SDimitry Andric             match_results<const _CharT*, _Allocator>& __m,
61410b57cec5SDimitry Andric             const basic_regex<_CharT, _Traits>& __e,
61420b57cec5SDimitry Andric             regex_constants::match_flag_type __flags = regex_constants::match_default)
61430b57cec5SDimitry Andric{
61440b57cec5SDimitry Andric    return __e.__search(__first, __last, __m, __flags);
61450b57cec5SDimitry Andric}
61460b57cec5SDimitry Andric
61470b57cec5SDimitry Andrictemplate <class _BidirectionalIterator, class _CharT, class _Traits>
61480b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
61490b57cec5SDimitry Andricbool
61500b57cec5SDimitry Andricregex_search(_BidirectionalIterator __first, _BidirectionalIterator __last,
61510b57cec5SDimitry Andric             const basic_regex<_CharT, _Traits>& __e,
61520b57cec5SDimitry Andric             regex_constants::match_flag_type __flags = regex_constants::match_default)
61530b57cec5SDimitry Andric{
61540b57cec5SDimitry Andric    basic_string<_CharT> __s(__first, __last);
61550b57cec5SDimitry Andric    match_results<const _CharT*> __mc;
61560b57cec5SDimitry Andric    return __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags);
61570b57cec5SDimitry Andric}
61580b57cec5SDimitry Andric
61590b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
61600b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
61610b57cec5SDimitry Andricbool
61620b57cec5SDimitry Andricregex_search(const _CharT* __first, const _CharT* __last,
61630b57cec5SDimitry Andric             const basic_regex<_CharT, _Traits>& __e,
61640b57cec5SDimitry Andric             regex_constants::match_flag_type __flags = regex_constants::match_default)
61650b57cec5SDimitry Andric{
61660b57cec5SDimitry Andric    match_results<const _CharT*> __mc;
61670b57cec5SDimitry Andric    return __e.__search(__first, __last, __mc, __flags);
61680b57cec5SDimitry Andric}
61690b57cec5SDimitry Andric
61700b57cec5SDimitry Andrictemplate <class _CharT, class _Allocator, class _Traits>
61710b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
61720b57cec5SDimitry Andricbool
61730b57cec5SDimitry Andricregex_search(const _CharT* __str, match_results<const _CharT*, _Allocator>& __m,
61740b57cec5SDimitry Andric             const basic_regex<_CharT, _Traits>& __e,
61750b57cec5SDimitry Andric             regex_constants::match_flag_type __flags = regex_constants::match_default)
61760b57cec5SDimitry Andric{
61770b57cec5SDimitry Andric    return __e.__search(__str, __str + _Traits::length(__str), __m, __flags);
61780b57cec5SDimitry Andric}
61790b57cec5SDimitry Andric
61800b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
61810b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
61820b57cec5SDimitry Andricbool
61830b57cec5SDimitry Andricregex_search(const _CharT* __str, const basic_regex<_CharT, _Traits>& __e,
61840b57cec5SDimitry Andric             regex_constants::match_flag_type __flags = regex_constants::match_default)
61850b57cec5SDimitry Andric{
61860b57cec5SDimitry Andric    match_results<const _CharT*> __m;
61870b57cec5SDimitry Andric    return _VSTD::regex_search(__str, __m, __e, __flags);
61880b57cec5SDimitry Andric}
61890b57cec5SDimitry Andric
61900b57cec5SDimitry Andrictemplate <class _ST, class _SA, class _CharT, class _Traits>
61910b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
61920b57cec5SDimitry Andricbool
61930b57cec5SDimitry Andricregex_search(const basic_string<_CharT, _ST, _SA>& __s,
61940b57cec5SDimitry Andric             const basic_regex<_CharT, _Traits>& __e,
61950b57cec5SDimitry Andric             regex_constants::match_flag_type __flags = regex_constants::match_default)
61960b57cec5SDimitry Andric{
61970b57cec5SDimitry Andric    match_results<const _CharT*> __mc;
61980b57cec5SDimitry Andric    return __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags);
61990b57cec5SDimitry Andric}
62000b57cec5SDimitry Andric
62010b57cec5SDimitry Andrictemplate <class _ST, class _SA, class _Allocator, class _CharT, class _Traits>
62020b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
62030b57cec5SDimitry Andricbool
62040b57cec5SDimitry Andricregex_search(const basic_string<_CharT, _ST, _SA>& __s,
62050b57cec5SDimitry Andric             match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m,
62060b57cec5SDimitry Andric             const basic_regex<_CharT, _Traits>& __e,
62070b57cec5SDimitry Andric             regex_constants::match_flag_type __flags = regex_constants::match_default)
62080b57cec5SDimitry Andric{
62090b57cec5SDimitry Andric    match_results<const _CharT*> __mc;
62100b57cec5SDimitry Andric    bool __r = __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags);
62110b57cec5SDimitry Andric    __m.__assign(__s.begin(), __s.end(), __mc, __flags & regex_constants::__no_update_pos);
62120b57cec5SDimitry Andric    return __r;
62130b57cec5SDimitry Andric}
62140b57cec5SDimitry Andric
62150b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11
62160b57cec5SDimitry Andrictemplate <class _ST, class _SA, class _Ap, class _Cp, class _Tp>
62170b57cec5SDimitry Andricbool
62180b57cec5SDimitry Andricregex_search(const basic_string<_Cp, _ST, _SA>&& __s,
62190b57cec5SDimitry Andric             match_results<typename basic_string<_Cp, _ST, _SA>::const_iterator, _Ap>&,
62200b57cec5SDimitry Andric             const basic_regex<_Cp, _Tp>& __e,
62210b57cec5SDimitry Andric             regex_constants::match_flag_type __flags = regex_constants::match_default) = delete;
62220b57cec5SDimitry Andric#endif
62230b57cec5SDimitry Andric
62240b57cec5SDimitry Andric// regex_match
62250b57cec5SDimitry Andric
62260b57cec5SDimitry Andrictemplate <class _BidirectionalIterator, class _Allocator, class _CharT, class _Traits>
62270b57cec5SDimitry Andricbool
62280b57cec5SDimitry Andricregex_match(_BidirectionalIterator __first, _BidirectionalIterator __last,
62290b57cec5SDimitry Andric            match_results<_BidirectionalIterator, _Allocator>& __m,
62300b57cec5SDimitry Andric            const basic_regex<_CharT, _Traits>& __e,
62310b57cec5SDimitry Andric            regex_constants::match_flag_type __flags = regex_constants::match_default)
62320b57cec5SDimitry Andric{
62330b57cec5SDimitry Andric    bool __r = _VSTD::regex_search(
62340b57cec5SDimitry Andric        __first, __last, __m, __e,
62350b57cec5SDimitry Andric        __flags | regex_constants::match_continuous |
62360b57cec5SDimitry Andric        regex_constants::__full_match);
62370b57cec5SDimitry Andric    if (__r)
62380b57cec5SDimitry Andric    {
62390b57cec5SDimitry Andric        __r = !__m.suffix().matched;
62400b57cec5SDimitry Andric        if (!__r)
62410b57cec5SDimitry Andric            __m.__matches_.clear();
62420b57cec5SDimitry Andric    }
62430b57cec5SDimitry Andric    return __r;
62440b57cec5SDimitry Andric}
62450b57cec5SDimitry Andric
62460b57cec5SDimitry Andrictemplate <class _BidirectionalIterator, class _CharT, class _Traits>
62470b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
62480b57cec5SDimitry Andricbool
62490b57cec5SDimitry Andricregex_match(_BidirectionalIterator __first, _BidirectionalIterator __last,
62500b57cec5SDimitry Andric            const basic_regex<_CharT, _Traits>& __e,
62510b57cec5SDimitry Andric            regex_constants::match_flag_type __flags = regex_constants::match_default)
62520b57cec5SDimitry Andric{
62530b57cec5SDimitry Andric    match_results<_BidirectionalIterator> __m;
62540b57cec5SDimitry Andric    return _VSTD::regex_match(__first, __last, __m, __e, __flags);
62550b57cec5SDimitry Andric}
62560b57cec5SDimitry Andric
62570b57cec5SDimitry Andrictemplate <class _CharT, class _Allocator, class _Traits>
62580b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
62590b57cec5SDimitry Andricbool
62600b57cec5SDimitry Andricregex_match(const _CharT* __str, match_results<const _CharT*, _Allocator>& __m,
62610b57cec5SDimitry Andric            const basic_regex<_CharT, _Traits>& __e,
62620b57cec5SDimitry Andric            regex_constants::match_flag_type __flags = regex_constants::match_default)
62630b57cec5SDimitry Andric{
62640b57cec5SDimitry Andric    return _VSTD::regex_match(__str, __str + _Traits::length(__str), __m, __e, __flags);
62650b57cec5SDimitry Andric}
62660b57cec5SDimitry Andric
62670b57cec5SDimitry Andrictemplate <class _ST, class _SA, class _Allocator, class _CharT, class _Traits>
62680b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
62690b57cec5SDimitry Andricbool
62700b57cec5SDimitry Andricregex_match(const basic_string<_CharT, _ST, _SA>& __s,
62710b57cec5SDimitry Andric            match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m,
62720b57cec5SDimitry Andric            const basic_regex<_CharT, _Traits>& __e,
62730b57cec5SDimitry Andric            regex_constants::match_flag_type __flags = regex_constants::match_default)
62740b57cec5SDimitry Andric{
62750b57cec5SDimitry Andric    return _VSTD::regex_match(__s.begin(), __s.end(), __m, __e, __flags);
62760b57cec5SDimitry Andric}
62770b57cec5SDimitry Andric
62780b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11
62790b57cec5SDimitry Andrictemplate <class _ST, class _SA, class _Allocator, class _CharT, class _Traits>
62800b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
62810b57cec5SDimitry Andricbool
62820b57cec5SDimitry Andricregex_match(const basic_string<_CharT, _ST, _SA>&& __s,
62830b57cec5SDimitry Andric            match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m,
62840b57cec5SDimitry Andric            const basic_regex<_CharT, _Traits>& __e,
62850b57cec5SDimitry Andric            regex_constants::match_flag_type __flags = regex_constants::match_default) = delete;
62860b57cec5SDimitry Andric#endif
62870b57cec5SDimitry Andric
62880b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
62890b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
62900b57cec5SDimitry Andricbool
62910b57cec5SDimitry Andricregex_match(const _CharT* __str, const basic_regex<_CharT, _Traits>& __e,
62920b57cec5SDimitry Andric            regex_constants::match_flag_type __flags = regex_constants::match_default)
62930b57cec5SDimitry Andric{
62940b57cec5SDimitry Andric    return _VSTD::regex_match(__str, __str + _Traits::length(__str), __e, __flags);
62950b57cec5SDimitry Andric}
62960b57cec5SDimitry Andric
62970b57cec5SDimitry Andrictemplate <class _ST, class _SA, class _CharT, class _Traits>
62980b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
62990b57cec5SDimitry Andricbool
63000b57cec5SDimitry Andricregex_match(const basic_string<_CharT, _ST, _SA>& __s,
63010b57cec5SDimitry Andric            const basic_regex<_CharT, _Traits>& __e,
63020b57cec5SDimitry Andric            regex_constants::match_flag_type __flags = regex_constants::match_default)
63030b57cec5SDimitry Andric{
63040b57cec5SDimitry Andric    return _VSTD::regex_match(__s.begin(), __s.end(), __e, __flags);
63050b57cec5SDimitry Andric}
63060b57cec5SDimitry Andric
63070b57cec5SDimitry Andric// regex_iterator
63080b57cec5SDimitry Andric
63090b57cec5SDimitry Andrictemplate <class _BidirectionalIterator,
63100b57cec5SDimitry Andric          class _CharT = typename iterator_traits<_BidirectionalIterator>::value_type,
63110b57cec5SDimitry Andric          class _Traits = regex_traits<_CharT> >
6312e8d8bef9SDimitry Andric    class _LIBCPP_TEMPLATE_VIS regex_iterator;
6313e8d8bef9SDimitry Andric
6314e8d8bef9SDimitry Andrictypedef regex_iterator<const char*>             cregex_iterator;
6315e8d8bef9SDimitry Andrictypedef regex_iterator<string::const_iterator>  sregex_iterator;
6316349cc55cSDimitry Andric#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
6317349cc55cSDimitry Andrictypedef regex_iterator<const wchar_t*>          wcregex_iterator;
6318e8d8bef9SDimitry Andrictypedef regex_iterator<wstring::const_iterator> wsregex_iterator;
6319349cc55cSDimitry Andric#endif
6320e8d8bef9SDimitry Andric
6321e8d8bef9SDimitry Andrictemplate <class _BidirectionalIterator, class _CharT, class _Traits>
6322e8d8bef9SDimitry Andricclass
6323e8d8bef9SDimitry Andric    _LIBCPP_TEMPLATE_VIS
6324e8d8bef9SDimitry Andric    _LIBCPP_PREFERRED_NAME(cregex_iterator)
6325349cc55cSDimitry Andric    _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wcregex_iterator))
6326e8d8bef9SDimitry Andric    _LIBCPP_PREFERRED_NAME(sregex_iterator)
6327349cc55cSDimitry Andric    _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wsregex_iterator))
6328e8d8bef9SDimitry Andric    regex_iterator
63290b57cec5SDimitry Andric{
63300b57cec5SDimitry Andricpublic:
63310b57cec5SDimitry Andric    typedef basic_regex<_CharT, _Traits>          regex_type;
63320b57cec5SDimitry Andric    typedef match_results<_BidirectionalIterator> value_type;
63330b57cec5SDimitry Andric    typedef ptrdiff_t                             difference_type;
63340b57cec5SDimitry Andric    typedef const value_type*                     pointer;
63350b57cec5SDimitry Andric    typedef const value_type&                     reference;
63360b57cec5SDimitry Andric    typedef forward_iterator_tag                  iterator_category;
63370b57cec5SDimitry Andric
63380b57cec5SDimitry Andricprivate:
63390b57cec5SDimitry Andric    _BidirectionalIterator           __begin_;
63400b57cec5SDimitry Andric    _BidirectionalIterator           __end_;
63410b57cec5SDimitry Andric    const regex_type*                __pregex_;
63420b57cec5SDimitry Andric    regex_constants::match_flag_type __flags_;
63430b57cec5SDimitry Andric    value_type                       __match_;
63440b57cec5SDimitry Andric
63450b57cec5SDimitry Andricpublic:
63460b57cec5SDimitry Andric    regex_iterator();
63470b57cec5SDimitry Andric    regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
63480b57cec5SDimitry Andric                   const regex_type& __re,
63490b57cec5SDimitry Andric                   regex_constants::match_flag_type __m
63500b57cec5SDimitry Andric                                              = regex_constants::match_default);
63510b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11
63520b57cec5SDimitry Andric    regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
63530b57cec5SDimitry Andric                   const regex_type&& __re,
63540b57cec5SDimitry Andric                   regex_constants::match_flag_type __m
63550b57cec5SDimitry Andric                                     = regex_constants::match_default) = delete;
63560b57cec5SDimitry Andric#endif
63570b57cec5SDimitry Andric
63580b57cec5SDimitry Andric    bool operator==(const regex_iterator& __x) const;
63590b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
63600b57cec5SDimitry Andric    bool operator!=(const regex_iterator& __x) const {return !(*this == __x);}
63610b57cec5SDimitry Andric
63620b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
63630b57cec5SDimitry Andric    reference operator*() const {return  __match_;}
63640b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
63650b57cec5SDimitry Andric    pointer operator->() const  {return _VSTD::addressof(__match_);}
63660b57cec5SDimitry Andric
63670b57cec5SDimitry Andric    regex_iterator& operator++();
63680b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
63690b57cec5SDimitry Andric    regex_iterator operator++(int)
63700b57cec5SDimitry Andric    {
63710b57cec5SDimitry Andric        regex_iterator __t(*this);
63720b57cec5SDimitry Andric        ++(*this);
63730b57cec5SDimitry Andric        return __t;
63740b57cec5SDimitry Andric    }
63750b57cec5SDimitry Andric};
63760b57cec5SDimitry Andric
63770b57cec5SDimitry Andrictemplate <class _BidirectionalIterator, class _CharT, class _Traits>
63780b57cec5SDimitry Andricregex_iterator<_BidirectionalIterator, _CharT, _Traits>::regex_iterator()
63790b57cec5SDimitry Andric    : __begin_(), __end_(), __pregex_(nullptr), __flags_(), __match_()
63800b57cec5SDimitry Andric{
63810b57cec5SDimitry Andric}
63820b57cec5SDimitry Andric
63830b57cec5SDimitry Andrictemplate <class _BidirectionalIterator, class _CharT, class _Traits>
63840b57cec5SDimitry Andricregex_iterator<_BidirectionalIterator, _CharT, _Traits>::
63850b57cec5SDimitry Andric    regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
63860b57cec5SDimitry Andric                   const regex_type& __re, regex_constants::match_flag_type __m)
63870b57cec5SDimitry Andric    : __begin_(__a),
63880b57cec5SDimitry Andric      __end_(__b),
63890b57cec5SDimitry Andric      __pregex_(_VSTD::addressof(__re)),
63900b57cec5SDimitry Andric      __flags_(__m)
63910b57cec5SDimitry Andric{
63920b57cec5SDimitry Andric    _VSTD::regex_search(__begin_, __end_, __match_, *__pregex_, __flags_);
63930b57cec5SDimitry Andric}
63940b57cec5SDimitry Andric
63950b57cec5SDimitry Andrictemplate <class _BidirectionalIterator, class _CharT, class _Traits>
63960b57cec5SDimitry Andricbool
63970b57cec5SDimitry Andricregex_iterator<_BidirectionalIterator, _CharT, _Traits>::
63980b57cec5SDimitry Andric    operator==(const regex_iterator& __x) const
63990b57cec5SDimitry Andric{
64000b57cec5SDimitry Andric    if (__match_.empty() && __x.__match_.empty())
64010b57cec5SDimitry Andric        return true;
64020b57cec5SDimitry Andric    if (__match_.empty() || __x.__match_.empty())
64030b57cec5SDimitry Andric        return false;
64040b57cec5SDimitry Andric    return __begin_ == __x.__begin_       &&
64050b57cec5SDimitry Andric           __end_ == __x.__end_           &&
64060b57cec5SDimitry Andric           __pregex_ == __x.__pregex_     &&
64070b57cec5SDimitry Andric           __flags_ == __x.__flags_       &&
64080b57cec5SDimitry Andric           __match_[0] == __x.__match_[0];
64090b57cec5SDimitry Andric}
64100b57cec5SDimitry Andric
64110b57cec5SDimitry Andrictemplate <class _BidirectionalIterator, class _CharT, class _Traits>
64120b57cec5SDimitry Andricregex_iterator<_BidirectionalIterator, _CharT, _Traits>&
64130b57cec5SDimitry Andricregex_iterator<_BidirectionalIterator, _CharT, _Traits>::operator++()
64140b57cec5SDimitry Andric{
64150b57cec5SDimitry Andric    __flags_ |= regex_constants::__no_update_pos;
64160b57cec5SDimitry Andric    _BidirectionalIterator __start = __match_[0].second;
64170b57cec5SDimitry Andric    if (__match_[0].first == __match_[0].second)
64180b57cec5SDimitry Andric    {
64190b57cec5SDimitry Andric        if (__start == __end_)
64200b57cec5SDimitry Andric        {
64210b57cec5SDimitry Andric            __match_ = value_type();
64220b57cec5SDimitry Andric            return *this;
64230b57cec5SDimitry Andric        }
64240b57cec5SDimitry Andric        else if (_VSTD::regex_search(__start, __end_, __match_, *__pregex_,
64250b57cec5SDimitry Andric                                    __flags_ | regex_constants::match_not_null |
64260b57cec5SDimitry Andric                                    regex_constants::match_continuous))
64270b57cec5SDimitry Andric            return *this;
64280b57cec5SDimitry Andric        else
64290b57cec5SDimitry Andric            ++__start;
64300b57cec5SDimitry Andric    }
64310b57cec5SDimitry Andric    __flags_ |= regex_constants::match_prev_avail;
64320b57cec5SDimitry Andric    if (!_VSTD::regex_search(__start, __end_, __match_, *__pregex_, __flags_))
64330b57cec5SDimitry Andric        __match_ = value_type();
64340b57cec5SDimitry Andric    return *this;
64350b57cec5SDimitry Andric}
64360b57cec5SDimitry Andric
64370b57cec5SDimitry Andric// regex_token_iterator
64380b57cec5SDimitry Andric
64390b57cec5SDimitry Andrictemplate <class _BidirectionalIterator,
64400b57cec5SDimitry Andric          class _CharT = typename iterator_traits<_BidirectionalIterator>::value_type,
64410b57cec5SDimitry Andric          class _Traits = regex_traits<_CharT> >
6442e8d8bef9SDimitry Andric    class _LIBCPP_TEMPLATE_VIS regex_token_iterator;
6443e8d8bef9SDimitry Andric
6444e8d8bef9SDimitry Andrictypedef regex_token_iterator<const char*>             cregex_token_iterator;
6445e8d8bef9SDimitry Andrictypedef regex_token_iterator<string::const_iterator>  sregex_token_iterator;
6446349cc55cSDimitry Andric#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
6447349cc55cSDimitry Andrictypedef regex_token_iterator<const wchar_t*>          wcregex_token_iterator;
6448e8d8bef9SDimitry Andrictypedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator;
6449349cc55cSDimitry Andric#endif
6450e8d8bef9SDimitry Andric
6451e8d8bef9SDimitry Andrictemplate <class _BidirectionalIterator, class _CharT, class _Traits>
6452e8d8bef9SDimitry Andricclass
6453e8d8bef9SDimitry Andric    _LIBCPP_TEMPLATE_VIS
6454e8d8bef9SDimitry Andric    _LIBCPP_PREFERRED_NAME(cregex_token_iterator)
6455349cc55cSDimitry Andric    _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wcregex_token_iterator))
6456e8d8bef9SDimitry Andric    _LIBCPP_PREFERRED_NAME(sregex_token_iterator)
6457349cc55cSDimitry Andric    _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wsregex_token_iterator))
6458e8d8bef9SDimitry Andric    regex_token_iterator
64590b57cec5SDimitry Andric{
64600b57cec5SDimitry Andricpublic:
64610b57cec5SDimitry Andric    typedef basic_regex<_CharT, _Traits>      regex_type;
64620b57cec5SDimitry Andric    typedef sub_match<_BidirectionalIterator> value_type;
64630b57cec5SDimitry Andric    typedef ptrdiff_t                         difference_type;
64640b57cec5SDimitry Andric    typedef const value_type*                 pointer;
64650b57cec5SDimitry Andric    typedef const value_type&                 reference;
64660b57cec5SDimitry Andric    typedef forward_iterator_tag              iterator_category;
64670b57cec5SDimitry Andric
64680b57cec5SDimitry Andricprivate:
64690b57cec5SDimitry Andric    typedef regex_iterator<_BidirectionalIterator, _CharT, _Traits> _Position;
64700b57cec5SDimitry Andric
64710b57cec5SDimitry Andric    _Position         __position_;
64720b57cec5SDimitry Andric    const value_type* __result_;
64730b57cec5SDimitry Andric    value_type        __suffix_;
64740b57cec5SDimitry Andric    ptrdiff_t         __n_;
64750b57cec5SDimitry Andric    vector<int>       __subs_;
64760b57cec5SDimitry Andric
64770b57cec5SDimitry Andricpublic:
64780b57cec5SDimitry Andric    regex_token_iterator();
64790b57cec5SDimitry Andric    regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
64800b57cec5SDimitry Andric                         const regex_type& __re, int __submatch = 0,
64810b57cec5SDimitry Andric                         regex_constants::match_flag_type __m =
64820b57cec5SDimitry Andric                                                regex_constants::match_default);
64830b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11
64840b57cec5SDimitry Andric    regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
64850b57cec5SDimitry Andric                         const regex_type&& __re, int __submatch = 0,
64860b57cec5SDimitry Andric                         regex_constants::match_flag_type __m =
64870b57cec5SDimitry Andric                                       regex_constants::match_default) = delete;
64880b57cec5SDimitry Andric#endif
64890b57cec5SDimitry Andric
64900b57cec5SDimitry Andric    regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
64910b57cec5SDimitry Andric                         const regex_type& __re, const vector<int>& __submatches,
64920b57cec5SDimitry Andric                         regex_constants::match_flag_type __m =
64930b57cec5SDimitry Andric                                                regex_constants::match_default);
64940b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11
64950b57cec5SDimitry Andric    regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
64960b57cec5SDimitry Andric                         const regex_type&& __re, const vector<int>& __submatches,
64970b57cec5SDimitry Andric                         regex_constants::match_flag_type __m =
64980b57cec5SDimitry Andric                                     regex_constants::match_default) = delete;
64990b57cec5SDimitry Andric#endif
65000b57cec5SDimitry Andric
65010b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
65020b57cec5SDimitry Andric    regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
65030b57cec5SDimitry Andric                         const regex_type& __re,
65040b57cec5SDimitry Andric                         initializer_list<int> __submatches,
65050b57cec5SDimitry Andric                         regex_constants::match_flag_type __m =
65060b57cec5SDimitry Andric                                                regex_constants::match_default);
65070b57cec5SDimitry Andric
65080b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11
65090b57cec5SDimitry Andric    regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
65100b57cec5SDimitry Andric                         const regex_type&& __re,
65110b57cec5SDimitry Andric                         initializer_list<int> __submatches,
65120b57cec5SDimitry Andric                         regex_constants::match_flag_type __m =
65130b57cec5SDimitry Andric                                       regex_constants::match_default) = delete;
65140b57cec5SDimitry Andric#endif
65150b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG
65160b57cec5SDimitry Andric    template <size_t _Np>
65170b57cec5SDimitry Andric        regex_token_iterator(_BidirectionalIterator __a,
65180b57cec5SDimitry Andric                             _BidirectionalIterator __b,
65190b57cec5SDimitry Andric                             const regex_type& __re,
65200b57cec5SDimitry Andric                             const int (&__submatches)[_Np],
65210b57cec5SDimitry Andric                             regex_constants::match_flag_type __m =
65220b57cec5SDimitry Andric                                                regex_constants::match_default);
65230b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11
6524e8d8bef9SDimitry Andric    template <size_t _Np>
65250b57cec5SDimitry Andric        regex_token_iterator(_BidirectionalIterator __a,
65260b57cec5SDimitry Andric                             _BidirectionalIterator __b,
65270b57cec5SDimitry Andric                             const regex_type&& __re,
65280b57cec5SDimitry Andric                             const int (&__submatches)[_Np],
65290b57cec5SDimitry Andric                             regex_constants::match_flag_type __m =
65300b57cec5SDimitry Andric                                      regex_constants::match_default) = delete;
65310b57cec5SDimitry Andric#endif
65320b57cec5SDimitry Andric
65330b57cec5SDimitry Andric    regex_token_iterator(const regex_token_iterator&);
65340b57cec5SDimitry Andric    regex_token_iterator& operator=(const regex_token_iterator&);
65350b57cec5SDimitry Andric
65360b57cec5SDimitry Andric    bool operator==(const regex_token_iterator& __x) const;
65370b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
65380b57cec5SDimitry Andric    bool operator!=(const regex_token_iterator& __x) const {return !(*this == __x);}
65390b57cec5SDimitry Andric
65400b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
65410b57cec5SDimitry Andric    const value_type& operator*() const {return *__result_;}
65420b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
65430b57cec5SDimitry Andric    const value_type* operator->() const {return __result_;}
65440b57cec5SDimitry Andric
65450b57cec5SDimitry Andric    regex_token_iterator& operator++();
65460b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
65470b57cec5SDimitry Andric    regex_token_iterator operator++(int)
65480b57cec5SDimitry Andric    {
65490b57cec5SDimitry Andric        regex_token_iterator __t(*this);
65500b57cec5SDimitry Andric        ++(*this);
65510b57cec5SDimitry Andric        return __t;
65520b57cec5SDimitry Andric    }
65530b57cec5SDimitry Andric
65540b57cec5SDimitry Andricprivate:
65550b57cec5SDimitry Andric    void __init(_BidirectionalIterator __a, _BidirectionalIterator __b);
65560b57cec5SDimitry Andric    void __establish_result () {
65570b57cec5SDimitry Andric        if (__subs_[__n_] == -1)
65580b57cec5SDimitry Andric            __result_ = &__position_->prefix();
65590b57cec5SDimitry Andric        else
65600b57cec5SDimitry Andric            __result_ = &(*__position_)[__subs_[__n_]];
65610b57cec5SDimitry Andric        }
65620b57cec5SDimitry Andric};
65630b57cec5SDimitry Andric
65640b57cec5SDimitry Andrictemplate <class _BidirectionalIterator, class _CharT, class _Traits>
65650b57cec5SDimitry Andricregex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
65660b57cec5SDimitry Andric    regex_token_iterator()
65670b57cec5SDimitry Andric    : __result_(nullptr),
65680b57cec5SDimitry Andric      __suffix_(),
65690b57cec5SDimitry Andric      __n_(0)
65700b57cec5SDimitry Andric{
65710b57cec5SDimitry Andric}
65720b57cec5SDimitry Andric
65730b57cec5SDimitry Andrictemplate <class _BidirectionalIterator, class _CharT, class _Traits>
65740b57cec5SDimitry Andricvoid
65750b57cec5SDimitry Andricregex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
65760b57cec5SDimitry Andric    __init(_BidirectionalIterator __a, _BidirectionalIterator __b)
65770b57cec5SDimitry Andric{
65780b57cec5SDimitry Andric    if (__position_ != _Position())
65790b57cec5SDimitry Andric        __establish_result ();
65800b57cec5SDimitry Andric    else if (__subs_[__n_] == -1)
65810b57cec5SDimitry Andric    {
65820b57cec5SDimitry Andric        __suffix_.matched = true;
65830b57cec5SDimitry Andric        __suffix_.first = __a;
65840b57cec5SDimitry Andric        __suffix_.second = __b;
65850b57cec5SDimitry Andric        __result_ = &__suffix_;
65860b57cec5SDimitry Andric    }
65870b57cec5SDimitry Andric    else
65880b57cec5SDimitry Andric        __result_ = nullptr;
65890b57cec5SDimitry Andric}
65900b57cec5SDimitry Andric
65910b57cec5SDimitry Andrictemplate <class _BidirectionalIterator, class _CharT, class _Traits>
65920b57cec5SDimitry Andricregex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
65930b57cec5SDimitry Andric    regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
65940b57cec5SDimitry Andric                         const regex_type& __re, int __submatch,
65950b57cec5SDimitry Andric                         regex_constants::match_flag_type __m)
65960b57cec5SDimitry Andric    : __position_(__a, __b, __re, __m),
65970b57cec5SDimitry Andric      __n_(0),
65980b57cec5SDimitry Andric      __subs_(1, __submatch)
65990b57cec5SDimitry Andric{
66000b57cec5SDimitry Andric    __init(__a, __b);
66010b57cec5SDimitry Andric}
66020b57cec5SDimitry Andric
66030b57cec5SDimitry Andrictemplate <class _BidirectionalIterator, class _CharT, class _Traits>
66040b57cec5SDimitry Andricregex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
66050b57cec5SDimitry Andric    regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
66060b57cec5SDimitry Andric                         const regex_type& __re, const vector<int>& __submatches,
66070b57cec5SDimitry Andric                         regex_constants::match_flag_type __m)
66080b57cec5SDimitry Andric    : __position_(__a, __b, __re, __m),
66090b57cec5SDimitry Andric      __n_(0),
66100b57cec5SDimitry Andric      __subs_(__submatches)
66110b57cec5SDimitry Andric{
66120b57cec5SDimitry Andric    __init(__a, __b);
66130b57cec5SDimitry Andric}
66140b57cec5SDimitry Andric
66150b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
66160b57cec5SDimitry Andric
66170b57cec5SDimitry Andrictemplate <class _BidirectionalIterator, class _CharT, class _Traits>
66180b57cec5SDimitry Andricregex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
66190b57cec5SDimitry Andric    regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
66200b57cec5SDimitry Andric                         const regex_type& __re,
66210b57cec5SDimitry Andric                         initializer_list<int> __submatches,
66220b57cec5SDimitry Andric                         regex_constants::match_flag_type __m)
66230b57cec5SDimitry Andric    : __position_(__a, __b, __re, __m),
66240b57cec5SDimitry Andric      __n_(0),
66250b57cec5SDimitry Andric      __subs_(__submatches)
66260b57cec5SDimitry Andric{
66270b57cec5SDimitry Andric    __init(__a, __b);
66280b57cec5SDimitry Andric}
66290b57cec5SDimitry Andric
66300b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG
66310b57cec5SDimitry Andric
66320b57cec5SDimitry Andrictemplate <class _BidirectionalIterator, class _CharT, class _Traits>
66330b57cec5SDimitry Andrictemplate <size_t _Np>
66340b57cec5SDimitry Andricregex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
66350b57cec5SDimitry Andric    regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
66360b57cec5SDimitry Andric                             const regex_type& __re,
66370b57cec5SDimitry Andric                             const int (&__submatches)[_Np],
66380b57cec5SDimitry Andric                             regex_constants::match_flag_type __m)
66390b57cec5SDimitry Andric    : __position_(__a, __b, __re, __m),
66400b57cec5SDimitry Andric      __n_(0),
66410b57cec5SDimitry Andric      __subs_(begin(__submatches), end(__submatches))
66420b57cec5SDimitry Andric{
66430b57cec5SDimitry Andric    __init(__a, __b);
66440b57cec5SDimitry Andric}
66450b57cec5SDimitry Andric
66460b57cec5SDimitry Andrictemplate <class _BidirectionalIterator, class _CharT, class _Traits>
66470b57cec5SDimitry Andricregex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
66480b57cec5SDimitry Andric    regex_token_iterator(const regex_token_iterator& __x)
66490b57cec5SDimitry Andric    : __position_(__x.__position_),
66500b57cec5SDimitry Andric      __result_(__x.__result_),
66510b57cec5SDimitry Andric      __suffix_(__x.__suffix_),
66520b57cec5SDimitry Andric      __n_(__x.__n_),
66530b57cec5SDimitry Andric      __subs_(__x.__subs_)
66540b57cec5SDimitry Andric{
66550b57cec5SDimitry Andric    if (__x.__result_ == &__x.__suffix_)
66560b57cec5SDimitry Andric        __result_ = &__suffix_;
66570b57cec5SDimitry Andric    else if ( __result_ != nullptr )
66580b57cec5SDimitry Andric        __establish_result ();
66590b57cec5SDimitry Andric}
66600b57cec5SDimitry Andric
66610b57cec5SDimitry Andrictemplate <class _BidirectionalIterator, class _CharT, class _Traits>
66620b57cec5SDimitry Andricregex_token_iterator<_BidirectionalIterator, _CharT, _Traits>&
66630b57cec5SDimitry Andricregex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
66640b57cec5SDimitry Andric    operator=(const regex_token_iterator& __x)
66650b57cec5SDimitry Andric{
66660b57cec5SDimitry Andric    if (this != &__x)
66670b57cec5SDimitry Andric    {
66680b57cec5SDimitry Andric        __position_ = __x.__position_;
66690b57cec5SDimitry Andric        if (__x.__result_ == &__x.__suffix_)
66700b57cec5SDimitry Andric            __result_ = &__suffix_;
66710b57cec5SDimitry Andric        else
66720b57cec5SDimitry Andric            __result_ = __x.__result_;
66730b57cec5SDimitry Andric        __suffix_ = __x.__suffix_;
66740b57cec5SDimitry Andric        __n_ = __x.__n_;
66750b57cec5SDimitry Andric        __subs_ = __x.__subs_;
66760b57cec5SDimitry Andric
66770b57cec5SDimitry Andric        if ( __result_ != nullptr && __result_ != &__suffix_ )
66780b57cec5SDimitry Andric            __establish_result();
66790b57cec5SDimitry Andric    }
66800b57cec5SDimitry Andric    return *this;
66810b57cec5SDimitry Andric}
66820b57cec5SDimitry Andric
66830b57cec5SDimitry Andrictemplate <class _BidirectionalIterator, class _CharT, class _Traits>
66840b57cec5SDimitry Andricbool
66850b57cec5SDimitry Andricregex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
66860b57cec5SDimitry Andric    operator==(const regex_token_iterator& __x) const
66870b57cec5SDimitry Andric{
66880b57cec5SDimitry Andric    if (__result_ == nullptr && __x.__result_ == nullptr)
66890b57cec5SDimitry Andric        return true;
66900b57cec5SDimitry Andric    if (__result_ == &__suffix_ && __x.__result_ == &__x.__suffix_ &&
66910b57cec5SDimitry Andric            __suffix_ == __x.__suffix_)
66920b57cec5SDimitry Andric        return true;
66930b57cec5SDimitry Andric    if (__result_ == nullptr || __x.__result_ == nullptr)
66940b57cec5SDimitry Andric        return false;
66950b57cec5SDimitry Andric    if (__result_ == &__suffix_ || __x.__result_ == &__x.__suffix_)
66960b57cec5SDimitry Andric        return false;
66970b57cec5SDimitry Andric    return __position_ == __x.__position_ && __n_ == __x.__n_ &&
66980b57cec5SDimitry Andric           __subs_ == __x.__subs_;
66990b57cec5SDimitry Andric}
67000b57cec5SDimitry Andric
67010b57cec5SDimitry Andrictemplate <class _BidirectionalIterator, class _CharT, class _Traits>
67020b57cec5SDimitry Andricregex_token_iterator<_BidirectionalIterator, _CharT, _Traits>&
67030b57cec5SDimitry Andricregex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::operator++()
67040b57cec5SDimitry Andric{
67050b57cec5SDimitry Andric    _Position __prev = __position_;
67060b57cec5SDimitry Andric    if (__result_ == &__suffix_)
67070b57cec5SDimitry Andric        __result_ = nullptr;
67080b57cec5SDimitry Andric    else if (static_cast<size_t>(__n_ + 1) < __subs_.size())
67090b57cec5SDimitry Andric    {
67100b57cec5SDimitry Andric        ++__n_;
67110b57cec5SDimitry Andric        __establish_result();
67120b57cec5SDimitry Andric    }
67130b57cec5SDimitry Andric    else
67140b57cec5SDimitry Andric    {
67150b57cec5SDimitry Andric        __n_ = 0;
67160b57cec5SDimitry Andric        ++__position_;
67170b57cec5SDimitry Andric        if (__position_ != _Position())
67180b57cec5SDimitry Andric            __establish_result();
67190b57cec5SDimitry Andric        else
67200b57cec5SDimitry Andric        {
67210b57cec5SDimitry Andric            if (_VSTD::find(__subs_.begin(), __subs_.end(), -1) != __subs_.end()
67220b57cec5SDimitry Andric                && __prev->suffix().length() != 0)
67230b57cec5SDimitry Andric            {
67240b57cec5SDimitry Andric                __suffix_.matched = true;
67250b57cec5SDimitry Andric                __suffix_.first = __prev->suffix().first;
67260b57cec5SDimitry Andric                __suffix_.second = __prev->suffix().second;
67270b57cec5SDimitry Andric                __result_ = &__suffix_;
67280b57cec5SDimitry Andric            }
67290b57cec5SDimitry Andric            else
67300b57cec5SDimitry Andric                __result_ = nullptr;
67310b57cec5SDimitry Andric        }
67320b57cec5SDimitry Andric    }
67330b57cec5SDimitry Andric    return *this;
67340b57cec5SDimitry Andric}
67350b57cec5SDimitry Andric
67360b57cec5SDimitry Andric// regex_replace
67370b57cec5SDimitry Andric
67380b57cec5SDimitry Andrictemplate <class _OutputIterator, class _BidirectionalIterator,
67390b57cec5SDimitry Andric          class _Traits, class _CharT>
67400b57cec5SDimitry Andric_OutputIterator
67410b57cec5SDimitry Andricregex_replace(_OutputIterator __output_iter,
67420b57cec5SDimitry Andric              _BidirectionalIterator __first, _BidirectionalIterator __last,
67430b57cec5SDimitry Andric              const basic_regex<_CharT, _Traits>& __e, const _CharT* __fmt,
67440b57cec5SDimitry Andric              regex_constants::match_flag_type __flags = regex_constants::match_default)
67450b57cec5SDimitry Andric{
67460b57cec5SDimitry Andric    typedef regex_iterator<_BidirectionalIterator, _CharT, _Traits> _Iter;
67470b57cec5SDimitry Andric    _Iter __i(__first, __last, __e, __flags);
67480b57cec5SDimitry Andric    _Iter __eof;
67490b57cec5SDimitry Andric    if (__i == __eof)
67500b57cec5SDimitry Andric    {
67510b57cec5SDimitry Andric        if (!(__flags & regex_constants::format_no_copy))
67520b57cec5SDimitry Andric            __output_iter = _VSTD::copy(__first, __last, __output_iter);
67530b57cec5SDimitry Andric    }
67540b57cec5SDimitry Andric    else
67550b57cec5SDimitry Andric    {
67560b57cec5SDimitry Andric        sub_match<_BidirectionalIterator> __lm;
67570b57cec5SDimitry Andric        for (size_t __len = char_traits<_CharT>::length(__fmt); __i != __eof; ++__i)
67580b57cec5SDimitry Andric        {
67590b57cec5SDimitry Andric            if (!(__flags & regex_constants::format_no_copy))
67600b57cec5SDimitry Andric                __output_iter = _VSTD::copy(__i->prefix().first, __i->prefix().second, __output_iter);
67610b57cec5SDimitry Andric            __output_iter = __i->format(__output_iter, __fmt, __fmt + __len, __flags);
67620b57cec5SDimitry Andric            __lm = __i->suffix();
67630b57cec5SDimitry Andric            if (__flags & regex_constants::format_first_only)
67640b57cec5SDimitry Andric                break;
67650b57cec5SDimitry Andric        }
67660b57cec5SDimitry Andric        if (!(__flags & regex_constants::format_no_copy))
67670b57cec5SDimitry Andric            __output_iter = _VSTD::copy(__lm.first, __lm.second, __output_iter);
67680b57cec5SDimitry Andric    }
67690b57cec5SDimitry Andric    return __output_iter;
67700b57cec5SDimitry Andric}
67710b57cec5SDimitry Andric
67720b57cec5SDimitry Andrictemplate <class _OutputIterator, class _BidirectionalIterator,
67730b57cec5SDimitry Andric          class _Traits, class _CharT, class _ST, class _SA>
67740b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
67750b57cec5SDimitry Andric_OutputIterator
67760b57cec5SDimitry Andricregex_replace(_OutputIterator __output_iter,
67770b57cec5SDimitry Andric              _BidirectionalIterator __first, _BidirectionalIterator __last,
67780b57cec5SDimitry Andric              const basic_regex<_CharT, _Traits>& __e,
67790b57cec5SDimitry Andric              const basic_string<_CharT, _ST, _SA>& __fmt,
67800b57cec5SDimitry Andric              regex_constants::match_flag_type __flags = regex_constants::match_default)
67810b57cec5SDimitry Andric{
67820b57cec5SDimitry Andric    return _VSTD::regex_replace(__output_iter, __first, __last, __e, __fmt.c_str(), __flags);
67830b57cec5SDimitry Andric}
67840b57cec5SDimitry Andric
67850b57cec5SDimitry Andrictemplate <class _Traits, class _CharT, class _ST, class _SA, class _FST,
67860b57cec5SDimitry Andric          class _FSA>
67870b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
67880b57cec5SDimitry Andricbasic_string<_CharT, _ST, _SA>
67890b57cec5SDimitry Andricregex_replace(const basic_string<_CharT, _ST, _SA>& __s,
67900b57cec5SDimitry Andric              const basic_regex<_CharT, _Traits>& __e,
67910b57cec5SDimitry Andric              const basic_string<_CharT, _FST, _FSA>& __fmt,
67920b57cec5SDimitry Andric              regex_constants::match_flag_type __flags = regex_constants::match_default)
67930b57cec5SDimitry Andric{
67940b57cec5SDimitry Andric    basic_string<_CharT, _ST, _SA> __r;
67950b57cec5SDimitry Andric    _VSTD::regex_replace(back_inserter(__r), __s.begin(), __s.end(), __e,
67960b57cec5SDimitry Andric                        __fmt.c_str(), __flags);
67970b57cec5SDimitry Andric    return __r;
67980b57cec5SDimitry Andric}
67990b57cec5SDimitry Andric
68000b57cec5SDimitry Andrictemplate <class _Traits, class _CharT, class _ST, class _SA>
68010b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
68020b57cec5SDimitry Andricbasic_string<_CharT, _ST, _SA>
68030b57cec5SDimitry Andricregex_replace(const basic_string<_CharT, _ST, _SA>& __s,
68040b57cec5SDimitry Andric              const basic_regex<_CharT, _Traits>& __e, const _CharT* __fmt,
68050b57cec5SDimitry Andric              regex_constants::match_flag_type __flags = regex_constants::match_default)
68060b57cec5SDimitry Andric{
68070b57cec5SDimitry Andric    basic_string<_CharT, _ST, _SA> __r;
68080b57cec5SDimitry Andric    _VSTD::regex_replace(back_inserter(__r), __s.begin(), __s.end(), __e,
68090b57cec5SDimitry Andric                        __fmt, __flags);
68100b57cec5SDimitry Andric    return __r;
68110b57cec5SDimitry Andric}
68120b57cec5SDimitry Andric
68130b57cec5SDimitry Andrictemplate <class _Traits, class _CharT, class _ST, class _SA>
68140b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
68150b57cec5SDimitry Andricbasic_string<_CharT>
68160b57cec5SDimitry Andricregex_replace(const _CharT* __s,
68170b57cec5SDimitry Andric              const basic_regex<_CharT, _Traits>& __e,
68180b57cec5SDimitry Andric              const basic_string<_CharT, _ST, _SA>& __fmt,
68190b57cec5SDimitry Andric              regex_constants::match_flag_type __flags = regex_constants::match_default)
68200b57cec5SDimitry Andric{
68210b57cec5SDimitry Andric    basic_string<_CharT> __r;
68220b57cec5SDimitry Andric    _VSTD::regex_replace(back_inserter(__r), __s,
68230b57cec5SDimitry Andric                        __s + char_traits<_CharT>::length(__s), __e,
68240b57cec5SDimitry Andric                        __fmt.c_str(), __flags);
68250b57cec5SDimitry Andric    return __r;
68260b57cec5SDimitry Andric}
68270b57cec5SDimitry Andric
68280b57cec5SDimitry Andrictemplate <class _Traits, class _CharT>
68290b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
68300b57cec5SDimitry Andricbasic_string<_CharT>
68310b57cec5SDimitry Andricregex_replace(const _CharT* __s,
68320b57cec5SDimitry Andric              const basic_regex<_CharT, _Traits>& __e,
68330b57cec5SDimitry Andric              const _CharT* __fmt,
68340b57cec5SDimitry Andric              regex_constants::match_flag_type __flags = regex_constants::match_default)
68350b57cec5SDimitry Andric{
68360b57cec5SDimitry Andric    basic_string<_CharT> __r;
68370b57cec5SDimitry Andric    _VSTD::regex_replace(back_inserter(__r), __s,
68380b57cec5SDimitry Andric                        __s + char_traits<_CharT>::length(__s), __e,
68390b57cec5SDimitry Andric                        __fmt, __flags);
68400b57cec5SDimitry Andric    return __r;
68410b57cec5SDimitry Andric}
68420b57cec5SDimitry Andric
68430b57cec5SDimitry Andric_LIBCPP_END_NAMESPACE_STD
68440b57cec5SDimitry Andric
68450b57cec5SDimitry Andric_LIBCPP_POP_MACROS
68460b57cec5SDimitry Andric
68470b57cec5SDimitry Andric#endif // _LIBCPP_REGEX
6848