xref: /minix3/external/bsd/libc++/dist/libcxx/include/regex (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
14684ddb6SLionel Sambuc// -*- C++ -*-
24684ddb6SLionel Sambuc//===--------------------------- regex ------------------------------------===//
34684ddb6SLionel Sambuc//
44684ddb6SLionel Sambuc//                     The LLVM Compiler Infrastructure
54684ddb6SLionel Sambuc//
64684ddb6SLionel Sambuc// This file is dual licensed under the MIT and the University of Illinois Open
74684ddb6SLionel Sambuc// Source Licenses. See LICENSE.TXT for details.
84684ddb6SLionel Sambuc//
94684ddb6SLionel Sambuc//===----------------------------------------------------------------------===//
104684ddb6SLionel Sambuc
114684ddb6SLionel Sambuc#ifndef _LIBCPP_REGEX
124684ddb6SLionel Sambuc#define _LIBCPP_REGEX
134684ddb6SLionel Sambuc
144684ddb6SLionel Sambuc/*
154684ddb6SLionel Sambuc    regex synopsis
164684ddb6SLionel Sambuc
174684ddb6SLionel Sambuc#include <initializer_list>
184684ddb6SLionel Sambuc
194684ddb6SLionel Sambucnamespace std
204684ddb6SLionel Sambuc{
214684ddb6SLionel Sambuc
224684ddb6SLionel Sambucnamespace regex_constants
234684ddb6SLionel Sambuc{
244684ddb6SLionel Sambuc
254684ddb6SLionel Sambucemum syntax_option_type
264684ddb6SLionel Sambuc{
274684ddb6SLionel Sambuc    icase      = unspecified,
284684ddb6SLionel Sambuc    nosubs     = unspecified,
294684ddb6SLionel Sambuc    optimize   = unspecified,
304684ddb6SLionel Sambuc    collate    = unspecified,
314684ddb6SLionel Sambuc    ECMAScript = unspecified,
324684ddb6SLionel Sambuc    basic      = unspecified,
334684ddb6SLionel Sambuc    extended   = unspecified,
344684ddb6SLionel Sambuc    awk        = unspecified,
354684ddb6SLionel Sambuc    grep       = unspecified,
364684ddb6SLionel Sambuc    egrep      = unspecified
374684ddb6SLionel Sambuc};
384684ddb6SLionel Sambuc
394684ddb6SLionel Sambucconstexpr syntax_option_type operator~(syntax_option_type f);
404684ddb6SLionel Sambucconstexpr syntax_option_type operator&(syntax_option_type lhs, syntax_option_type rhs);
414684ddb6SLionel Sambucconstexpr syntax_option_type operator|(syntax_option_type lhs, syntax_option_type rhs);
424684ddb6SLionel Sambuc
434684ddb6SLionel Sambucenum match_flag_type
444684ddb6SLionel Sambuc{
454684ddb6SLionel Sambuc    match_default     = 0,
464684ddb6SLionel Sambuc    match_not_bol     = unspecified,
474684ddb6SLionel Sambuc    match_not_eol     = unspecified,
484684ddb6SLionel Sambuc    match_not_bow     = unspecified,
494684ddb6SLionel Sambuc    match_not_eow     = unspecified,
504684ddb6SLionel Sambuc    match_any         = unspecified,
514684ddb6SLionel Sambuc    match_not_null    = unspecified,
524684ddb6SLionel Sambuc    match_continuous  = unspecified,
534684ddb6SLionel Sambuc    match_prev_avail  = unspecified,
544684ddb6SLionel Sambuc    format_default    = 0,
554684ddb6SLionel Sambuc    format_sed        = unspecified,
564684ddb6SLionel Sambuc    format_no_copy    = unspecified,
574684ddb6SLionel Sambuc    format_first_only = unspecified
584684ddb6SLionel Sambuc};
594684ddb6SLionel Sambuc
604684ddb6SLionel Sambucconstexpr match_flag_type operator~(match_flag_type f);
614684ddb6SLionel Sambucconstexpr match_flag_type operator&(match_flag_type lhs, match_flag_type rhs);
624684ddb6SLionel Sambucconstexpr match_flag_type operator|(match_flag_type lhs, match_flag_type rhs);
634684ddb6SLionel Sambuc
644684ddb6SLionel Sambucenum error_type
654684ddb6SLionel Sambuc{
664684ddb6SLionel Sambuc    error_collate    = unspecified,
674684ddb6SLionel Sambuc    error_ctype      = unspecified,
684684ddb6SLionel Sambuc    error_escape     = unspecified,
694684ddb6SLionel Sambuc    error_backref    = unspecified,
704684ddb6SLionel Sambuc    error_brack      = unspecified,
714684ddb6SLionel Sambuc    error_paren      = unspecified,
724684ddb6SLionel Sambuc    error_brace      = unspecified,
734684ddb6SLionel Sambuc    error_badbrace   = unspecified,
744684ddb6SLionel Sambuc    error_range      = unspecified,
754684ddb6SLionel Sambuc    error_space      = unspecified,
764684ddb6SLionel Sambuc    error_badrepeat  = unspecified,
774684ddb6SLionel Sambuc    error_complexity = unspecified,
784684ddb6SLionel Sambuc    error_stack      = unspecified
794684ddb6SLionel Sambuc};
804684ddb6SLionel Sambuc
814684ddb6SLionel Sambuc}  // regex_constants
824684ddb6SLionel Sambuc
834684ddb6SLionel Sambucclass regex_error
844684ddb6SLionel Sambuc    : public runtime_error
854684ddb6SLionel Sambuc{
864684ddb6SLionel Sambucpublic:
874684ddb6SLionel Sambuc    explicit regex_error(regex_constants::error_type ecode);
884684ddb6SLionel Sambuc    regex_constants::error_type code() const;
894684ddb6SLionel Sambuc};
904684ddb6SLionel Sambuc
914684ddb6SLionel Sambuctemplate <class charT>
924684ddb6SLionel Sambucstruct regex_traits
934684ddb6SLionel Sambuc{
944684ddb6SLionel Sambucpublic:
954684ddb6SLionel Sambuc    typedef charT                   char_type;
964684ddb6SLionel Sambuc    typedef basic_string<char_type> string_type;
974684ddb6SLionel Sambuc    typedef locale                  locale_type;
984684ddb6SLionel Sambuc    typedef /bitmask_type/          char_class_type;
994684ddb6SLionel Sambuc
1004684ddb6SLionel Sambuc    regex_traits();
1014684ddb6SLionel Sambuc
1024684ddb6SLionel Sambuc    static size_t length(const char_type* p);
1034684ddb6SLionel Sambuc    charT translate(charT c) const;
1044684ddb6SLionel Sambuc    charT translate_nocase(charT c) const;
1054684ddb6SLionel Sambuc    template <class ForwardIterator>
1064684ddb6SLionel Sambuc        string_type
1074684ddb6SLionel Sambuc        transform(ForwardIterator first, ForwardIterator last) const;
1084684ddb6SLionel Sambuc    template <class ForwardIterator>
1094684ddb6SLionel Sambuc        string_type
1104684ddb6SLionel Sambuc        transform_primary( ForwardIterator first, ForwardIterator last) const;
1114684ddb6SLionel Sambuc    template <class ForwardIterator>
1124684ddb6SLionel Sambuc        string_type
1134684ddb6SLionel Sambuc        lookup_collatename(ForwardIterator first, ForwardIterator last) const;
1144684ddb6SLionel Sambuc    template <class ForwardIterator>
1154684ddb6SLionel Sambuc        char_class_type
1164684ddb6SLionel Sambuc        lookup_classname(ForwardIterator first, ForwardIterator last,
1174684ddb6SLionel Sambuc                         bool icase = false) const;
1184684ddb6SLionel Sambuc    bool isctype(charT c, char_class_type f) const;
1194684ddb6SLionel Sambuc    int value(charT ch, int radix) const;
1204684ddb6SLionel Sambuc    locale_type imbue(locale_type l);
1214684ddb6SLionel Sambuc    locale_type getloc()const;
1224684ddb6SLionel Sambuc};
1234684ddb6SLionel Sambuc
1244684ddb6SLionel Sambuctemplate <class charT, class traits = regex_traits<charT>>
1254684ddb6SLionel Sambucclass basic_regex
1264684ddb6SLionel Sambuc{
1274684ddb6SLionel Sambucpublic:
1284684ddb6SLionel Sambuc    // types:
1294684ddb6SLionel Sambuc    typedef charT                               value_type;
1304684ddb6SLionel Sambuc    typedef regex_constants::syntax_option_type flag_type;
1314684ddb6SLionel Sambuc    typedef typename traits::locale_type        locale_type;
1324684ddb6SLionel Sambuc
1334684ddb6SLionel Sambuc    // constants:
1344684ddb6SLionel Sambuc    static constexpr regex_constants::syntax_option_type icase = regex_constants::icase;
1354684ddb6SLionel Sambuc    static constexpr regex_constants::syntax_option_type nosubs = regex_constants::nosubs;
1364684ddb6SLionel Sambuc    static constexpr regex_constants::syntax_option_type optimize = regex_constants::optimize;
1374684ddb6SLionel Sambuc    static constexpr regex_constants::syntax_option_type collate = regex_constants::collate;
1384684ddb6SLionel Sambuc    static constexpr regex_constants::syntax_option_type ECMAScript = regex_constants::ECMAScript;
1394684ddb6SLionel Sambuc    static constexpr regex_constants::syntax_option_type basic = regex_constants::basic;
1404684ddb6SLionel Sambuc    static constexpr regex_constants::syntax_option_type extended = regex_constants::extended;
1414684ddb6SLionel Sambuc    static constexpr regex_constants::syntax_option_type awk = regex_constants::awk;
1424684ddb6SLionel Sambuc    static constexpr regex_constants::syntax_option_type grep = regex_constants::grep;
1434684ddb6SLionel Sambuc    static constexpr regex_constants::syntax_option_type egrep = regex_constants::egrep;
1444684ddb6SLionel Sambuc
1454684ddb6SLionel Sambuc    // construct/copy/destroy:
1464684ddb6SLionel Sambuc    basic_regex();
1474684ddb6SLionel Sambuc    explicit basic_regex(const charT* p, flag_type f = regex_constants::ECMAScript);
1484684ddb6SLionel Sambuc    basic_regex(const charT* p, size_t len, flag_type f);
1494684ddb6SLionel Sambuc    basic_regex(const basic_regex&);
1504684ddb6SLionel Sambuc    basic_regex(basic_regex&&) noexcept;
1514684ddb6SLionel Sambuc    template <class ST, class SA>
1524684ddb6SLionel Sambuc        explicit basic_regex(const basic_string<charT, ST, SA>& p,
1534684ddb6SLionel Sambuc                             flag_type f = regex_constants::ECMAScript);
1544684ddb6SLionel Sambuc    template <class ForwardIterator>
1554684ddb6SLionel Sambuc        basic_regex(ForwardIterator first, ForwardIterator last,
1564684ddb6SLionel Sambuc                    flag_type f = regex_constants::ECMAScript);
1574684ddb6SLionel Sambuc    basic_regex(initializer_list<charT>, flag_type = regex_constants::ECMAScript);
1584684ddb6SLionel Sambuc
1594684ddb6SLionel Sambuc    ~basic_regex();
1604684ddb6SLionel Sambuc
1614684ddb6SLionel Sambuc    basic_regex& operator=(const basic_regex&);
1624684ddb6SLionel Sambuc    basic_regex& operator=(basic_regex&&) noexcept;
1634684ddb6SLionel Sambuc    basic_regex& operator=(const charT* ptr);
1644684ddb6SLionel Sambuc    basic_regex& operator=(initializer_list<charT> il);
1654684ddb6SLionel Sambuc    template <class ST, class SA>
1664684ddb6SLionel Sambuc        basic_regex& operator=(const basic_string<charT, ST, SA>& p);
1674684ddb6SLionel Sambuc
1684684ddb6SLionel Sambuc    // assign:
1694684ddb6SLionel Sambuc    basic_regex& assign(const basic_regex& that);
1704684ddb6SLionel Sambuc    basic_regex& assign(basic_regex&& that) noexcept;
1714684ddb6SLionel Sambuc    basic_regex& assign(const charT* ptr, flag_type f = regex_constants::ECMAScript);
1724684ddb6SLionel Sambuc    basic_regex& assign(const charT* p, size_t len, flag_type f);
1734684ddb6SLionel Sambuc    template <class string_traits, class A>
1744684ddb6SLionel Sambuc        basic_regex& assign(const basic_string<charT, string_traits, A>& s,
1754684ddb6SLionel Sambuc                            flag_type f = regex_constants::ECMAScript);
1764684ddb6SLionel Sambuc    template <class InputIterator>
1774684ddb6SLionel Sambuc        basic_regex& assign(InputIterator first, InputIterator last,
1784684ddb6SLionel Sambuc                            flag_type f = regex_constants::ECMAScript);
1794684ddb6SLionel Sambuc    basic_regex& assign(initializer_list<charT>, flag_type = regex_constants::ECMAScript);
1804684ddb6SLionel Sambuc
1814684ddb6SLionel Sambuc    // const operations:
1824684ddb6SLionel Sambuc    unsigned mark_count() const;
1834684ddb6SLionel Sambuc    flag_type flags() const;
1844684ddb6SLionel Sambuc
1854684ddb6SLionel Sambuc    // locale:
1864684ddb6SLionel Sambuc    locale_type imbue(locale_type loc);
1874684ddb6SLionel Sambuc    locale_type getloc() const;
1884684ddb6SLionel Sambuc
1894684ddb6SLionel Sambuc    // swap:
1904684ddb6SLionel Sambuc    void swap(basic_regex&);
1914684ddb6SLionel Sambuc};
1924684ddb6SLionel Sambuc
1934684ddb6SLionel Sambuctypedef basic_regex<char>    regex;
1944684ddb6SLionel Sambuctypedef basic_regex<wchar_t> wregex;
1954684ddb6SLionel Sambuc
1964684ddb6SLionel Sambuctemplate <class charT, class traits>
1974684ddb6SLionel Sambuc    void swap(basic_regex<charT, traits>& e1, basic_regex<charT, traits>& e2);
1984684ddb6SLionel Sambuc
1994684ddb6SLionel Sambuctemplate <class BidirectionalIterator>
2004684ddb6SLionel Sambucclass sub_match
2014684ddb6SLionel Sambuc    : public pair<BidirectionalIterator, BidirectionalIterator>
2024684ddb6SLionel Sambuc{
2034684ddb6SLionel Sambucpublic:
2044684ddb6SLionel Sambuc    typedef typename iterator_traits<BidirectionalIterator>::value_type value_type;
2054684ddb6SLionel Sambuc    typedef typename iterator_traits<BidirectionalIterator>::difference_type difference_type;
2064684ddb6SLionel Sambuc    typedef BidirectionalIterator                                      iterator;
2074684ddb6SLionel Sambuc    typedef basic_string<value_type>                                string_type;
2084684ddb6SLionel Sambuc
2094684ddb6SLionel Sambuc    bool matched;
2104684ddb6SLionel Sambuc
2114684ddb6SLionel Sambuc    constexpr sub_match();
2124684ddb6SLionel Sambuc
2134684ddb6SLionel Sambuc    difference_type length() const;
2144684ddb6SLionel Sambuc    operator string_type() const;
2154684ddb6SLionel Sambuc    string_type str() const;
2164684ddb6SLionel Sambuc
2174684ddb6SLionel Sambuc    int compare(const sub_match& s) const;
2184684ddb6SLionel Sambuc    int compare(const string_type& s) const;
2194684ddb6SLionel Sambuc    int compare(const value_type* s) const;
2204684ddb6SLionel Sambuc};
2214684ddb6SLionel Sambuc
2224684ddb6SLionel Sambuctypedef sub_match<const char*>             csub_match;
2234684ddb6SLionel Sambuctypedef sub_match<const wchar_t*>          wcsub_match;
2244684ddb6SLionel Sambuctypedef sub_match<string::const_iterator>  ssub_match;
2254684ddb6SLionel Sambuctypedef sub_match<wstring::const_iterator> wssub_match;
2264684ddb6SLionel Sambuc
2274684ddb6SLionel Sambuctemplate <class BiIter>
2284684ddb6SLionel Sambuc    bool
2294684ddb6SLionel Sambuc    operator==(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
2304684ddb6SLionel Sambuc
2314684ddb6SLionel Sambuctemplate <class BiIter>
2324684ddb6SLionel Sambuc    bool
2334684ddb6SLionel Sambuc    operator!=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
2344684ddb6SLionel Sambuc
2354684ddb6SLionel Sambuctemplate <class BiIter>
2364684ddb6SLionel Sambuc    bool
2374684ddb6SLionel Sambuc    operator<(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
2384684ddb6SLionel Sambuc
2394684ddb6SLionel Sambuctemplate <class BiIter>
2404684ddb6SLionel Sambuc    bool
2414684ddb6SLionel Sambuc    operator<=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
2424684ddb6SLionel Sambuc
2434684ddb6SLionel Sambuctemplate <class BiIter>
2444684ddb6SLionel Sambuc    bool
2454684ddb6SLionel Sambuc    operator>=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
2464684ddb6SLionel Sambuc
2474684ddb6SLionel Sambuctemplate <class BiIter>
2484684ddb6SLionel Sambuc    bool
2494684ddb6SLionel Sambuc    operator>(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
2504684ddb6SLionel Sambuc
2514684ddb6SLionel Sambuctemplate <class BiIter, class ST, class SA>
2524684ddb6SLionel Sambuc    bool
2534684ddb6SLionel Sambuc    operator==(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
2544684ddb6SLionel Sambuc               const sub_match<BiIter>& rhs);
2554684ddb6SLionel Sambuc
2564684ddb6SLionel Sambuctemplate <class BiIter, class ST, class SA>
2574684ddb6SLionel Sambuc    bool
2584684ddb6SLionel Sambuc    operator!=(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
2594684ddb6SLionel Sambuc               const sub_match<BiIter>& rhs);
2604684ddb6SLionel Sambuc
2614684ddb6SLionel Sambuctemplate <class BiIter, class ST, class SA>
2624684ddb6SLionel Sambuc    bool
2634684ddb6SLionel Sambuc    operator<(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
2644684ddb6SLionel Sambuc              const sub_match<BiIter>& rhs);
2654684ddb6SLionel Sambuc
2664684ddb6SLionel Sambuctemplate <class BiIter, class ST, class SA>
2674684ddb6SLionel Sambuc    bool
2684684ddb6SLionel Sambuc    operator>(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
2694684ddb6SLionel Sambuc              const sub_match<BiIter>& rhs);
2704684ddb6SLionel Sambuc
2714684ddb6SLionel Sambuctemplate <class BiIter, class ST, class SA>
2724684ddb6SLionel Sambuc    bool operator>=(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
2734684ddb6SLionel Sambuc                    const sub_match<BiIter>& rhs);
2744684ddb6SLionel Sambuc
2754684ddb6SLionel Sambuctemplate <class BiIter, class ST, class SA>
2764684ddb6SLionel Sambuc    bool
2774684ddb6SLionel Sambuc    operator<=(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
2784684ddb6SLionel Sambuc               const sub_match<BiIter>& rhs);
2794684ddb6SLionel Sambuc
2804684ddb6SLionel Sambuctemplate <class BiIter, class ST, class SA>
2814684ddb6SLionel Sambuc    bool
2824684ddb6SLionel Sambuc    operator==(const sub_match<BiIter>& lhs,
2834684ddb6SLionel Sambuc               const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
2844684ddb6SLionel Sambuc
2854684ddb6SLionel Sambuctemplate <class BiIter, class ST, class SA>
2864684ddb6SLionel Sambuc    bool
2874684ddb6SLionel Sambuc    operator!=(const sub_match<BiIter>& lhs,
2884684ddb6SLionel Sambuc               const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
2894684ddb6SLionel Sambuc
2904684ddb6SLionel Sambuctemplate <class BiIter, class ST, class SA>
2914684ddb6SLionel Sambuc    bool
2924684ddb6SLionel Sambuc    operator<(const sub_match<BiIter>& lhs,
2934684ddb6SLionel Sambuc              const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
2944684ddb6SLionel Sambuc
2954684ddb6SLionel Sambuctemplate <class BiIter, class ST, class SA>
2964684ddb6SLionel Sambuc    bool operator>(const sub_match<BiIter>& lhs,
2974684ddb6SLionel Sambuc                   const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
2984684ddb6SLionel Sambuc
2994684ddb6SLionel Sambuctemplate <class BiIter, class ST, class SA>
3004684ddb6SLionel Sambuc    bool
3014684ddb6SLionel Sambuc    operator>=(const sub_match<BiIter>& lhs,
3024684ddb6SLionel Sambuc               const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
3034684ddb6SLionel Sambuc
3044684ddb6SLionel Sambuctemplate <class BiIter, class ST, class SA>
3054684ddb6SLionel Sambuc    bool
3064684ddb6SLionel Sambuc    operator<=(const sub_match<BiIter>& lhs,
3074684ddb6SLionel Sambuc               const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
3084684ddb6SLionel Sambuc
3094684ddb6SLionel Sambuctemplate <class BiIter>
3104684ddb6SLionel Sambuc    bool
3114684ddb6SLionel Sambuc    operator==(typename iterator_traits<BiIter>::value_type const* lhs,
3124684ddb6SLionel Sambuc               const sub_match<BiIter>& rhs);
3134684ddb6SLionel Sambuc
3144684ddb6SLionel Sambuctemplate <class BiIter>
3154684ddb6SLionel Sambuc    bool
3164684ddb6SLionel Sambuc    operator!=(typename iterator_traits<BiIter>::value_type const* lhs,
3174684ddb6SLionel Sambuc               const sub_match<BiIter>& rhs);
3184684ddb6SLionel Sambuc
3194684ddb6SLionel Sambuctemplate <class BiIter>
3204684ddb6SLionel Sambuc    bool
3214684ddb6SLionel Sambuc    operator<(typename iterator_traits<BiIter>::value_type const* lhs,
3224684ddb6SLionel Sambuc              const sub_match<BiIter>& rhs);
3234684ddb6SLionel Sambuc
3244684ddb6SLionel Sambuctemplate <class BiIter>
3254684ddb6SLionel Sambuc    bool
3264684ddb6SLionel Sambuc    operator>(typename iterator_traits<BiIter>::value_type const* lhs,
3274684ddb6SLionel Sambuc              const sub_match<BiIter>& rhs);
3284684ddb6SLionel Sambuc
3294684ddb6SLionel Sambuctemplate <class BiIter>
3304684ddb6SLionel Sambuc    bool
3314684ddb6SLionel Sambuc    operator>=(typename iterator_traits<BiIter>::value_type const* lhs,
3324684ddb6SLionel Sambuc               const sub_match<BiIter>& rhs);
3334684ddb6SLionel Sambuc
3344684ddb6SLionel Sambuctemplate <class BiIter>
3354684ddb6SLionel Sambuc    bool
3364684ddb6SLionel Sambuc    operator<=(typename iterator_traits<BiIter>::value_type const* lhs,
3374684ddb6SLionel Sambuc               const sub_match<BiIter>& rhs);
3384684ddb6SLionel Sambuc
3394684ddb6SLionel Sambuctemplate <class BiIter>
3404684ddb6SLionel Sambuc    bool
3414684ddb6SLionel Sambuc    operator==(const sub_match<BiIter>& lhs,
3424684ddb6SLionel Sambuc               typename iterator_traits<BiIter>::value_type const* rhs);
3434684ddb6SLionel Sambuc
3444684ddb6SLionel Sambuctemplate <class BiIter>
3454684ddb6SLionel Sambuc    bool
3464684ddb6SLionel Sambuc    operator!=(const sub_match<BiIter>& lhs,
3474684ddb6SLionel Sambuc               typename iterator_traits<BiIter>::value_type const* rhs);
3484684ddb6SLionel Sambuc
3494684ddb6SLionel Sambuctemplate <class BiIter>
3504684ddb6SLionel Sambuc    bool
3514684ddb6SLionel Sambuc    operator<(const sub_match<BiIter>& lhs,
3524684ddb6SLionel Sambuc              typename iterator_traits<BiIter>::value_type const* rhs);
3534684ddb6SLionel Sambuc
3544684ddb6SLionel Sambuctemplate <class BiIter>
3554684ddb6SLionel Sambuc    bool
3564684ddb6SLionel Sambuc    operator>(const sub_match<BiIter>& lhs,
3574684ddb6SLionel Sambuc              typename iterator_traits<BiIter>::value_type const* rhs);
3584684ddb6SLionel Sambuc
3594684ddb6SLionel Sambuctemplate <class BiIter>
3604684ddb6SLionel Sambuc    bool
3614684ddb6SLionel Sambuc    operator>=(const sub_match<BiIter>& lhs,
3624684ddb6SLionel Sambuc               typename iterator_traits<BiIter>::value_type const* rhs);
3634684ddb6SLionel Sambuc
3644684ddb6SLionel Sambuctemplate <class BiIter>
3654684ddb6SLionel Sambuc    bool
3664684ddb6SLionel Sambuc    operator<=(const sub_match<BiIter>& lhs,
3674684ddb6SLionel Sambuc               typename iterator_traits<BiIter>::value_type const* rhs);
3684684ddb6SLionel Sambuc
3694684ddb6SLionel Sambuctemplate <class BiIter>
3704684ddb6SLionel Sambuc    bool
3714684ddb6SLionel Sambuc    operator==(typename iterator_traits<BiIter>::value_type const& lhs,
3724684ddb6SLionel Sambuc               const sub_match<BiIter>& rhs);
3734684ddb6SLionel Sambuc
3744684ddb6SLionel Sambuctemplate <class BiIter>
3754684ddb6SLionel Sambuc    bool
3764684ddb6SLionel Sambuc    operator!=(typename iterator_traits<BiIter>::value_type const& lhs,
3774684ddb6SLionel Sambuc               const sub_match<BiIter>& rhs);
3784684ddb6SLionel Sambuc
3794684ddb6SLionel Sambuctemplate <class BiIter>
3804684ddb6SLionel Sambuc    bool
3814684ddb6SLionel Sambuc    operator<(typename iterator_traits<BiIter>::value_type const& lhs,
3824684ddb6SLionel Sambuc              const sub_match<BiIter>& rhs);
3834684ddb6SLionel Sambuc
3844684ddb6SLionel Sambuctemplate <class BiIter>
3854684ddb6SLionel Sambuc    bool
3864684ddb6SLionel Sambuc    operator>(typename iterator_traits<BiIter>::value_type const& lhs,
3874684ddb6SLionel Sambuc              const sub_match<BiIter>& rhs);
3884684ddb6SLionel Sambuc
3894684ddb6SLionel Sambuctemplate <class BiIter>
3904684ddb6SLionel Sambuc    bool
3914684ddb6SLionel Sambuc    operator>=(typename iterator_traits<BiIter>::value_type const& lhs,
3924684ddb6SLionel Sambuc               const sub_match<BiIter>& rhs);
3934684ddb6SLionel Sambuc
3944684ddb6SLionel Sambuctemplate <class BiIter>
3954684ddb6SLionel Sambuc    bool
3964684ddb6SLionel Sambuc    operator<=(typename iterator_traits<BiIter>::value_type const& lhs,
3974684ddb6SLionel Sambuc               const sub_match<BiIter>& rhs);
3984684ddb6SLionel Sambuc
3994684ddb6SLionel Sambuctemplate <class BiIter>
4004684ddb6SLionel Sambuc    bool
4014684ddb6SLionel Sambuc    operator==(const sub_match<BiIter>& lhs,
4024684ddb6SLionel Sambuc               typename iterator_traits<BiIter>::value_type const& rhs);
4034684ddb6SLionel Sambuc
4044684ddb6SLionel Sambuctemplate <class BiIter>
4054684ddb6SLionel Sambuc    bool
4064684ddb6SLionel Sambuc    operator!=(const sub_match<BiIter>& lhs,
4074684ddb6SLionel Sambuc               typename iterator_traits<BiIter>::value_type const& rhs);
4084684ddb6SLionel Sambuc
4094684ddb6SLionel Sambuctemplate <class BiIter>
4104684ddb6SLionel Sambuc    bool
4114684ddb6SLionel Sambuc    operator<(const sub_match<BiIter>& lhs,
4124684ddb6SLionel Sambuc              typename iterator_traits<BiIter>::value_type const& rhs);
4134684ddb6SLionel Sambuc
4144684ddb6SLionel Sambuctemplate <class BiIter>
4154684ddb6SLionel Sambuc    bool
4164684ddb6SLionel Sambuc    operator>(const sub_match<BiIter>& lhs,
4174684ddb6SLionel Sambuc              typename iterator_traits<BiIter>::value_type const& rhs);
4184684ddb6SLionel Sambuc
4194684ddb6SLionel Sambuctemplate <class BiIter>
4204684ddb6SLionel Sambuc    bool
4214684ddb6SLionel Sambuc    operator>=(const sub_match<BiIter>& lhs,
4224684ddb6SLionel Sambuc               typename iterator_traits<BiIter>::value_type const& rhs);
4234684ddb6SLionel Sambuc
4244684ddb6SLionel Sambuctemplate <class BiIter>
4254684ddb6SLionel Sambuc    bool
4264684ddb6SLionel Sambuc    operator<=(const sub_match<BiIter>& lhs,
4274684ddb6SLionel Sambuc               typename iterator_traits<BiIter>::value_type const& rhs);
4284684ddb6SLionel Sambuc
4294684ddb6SLionel Sambuctemplate <class charT, class ST, class BiIter>
4304684ddb6SLionel Sambuc    basic_ostream<charT, ST>&
4314684ddb6SLionel Sambuc    operator<<(basic_ostream<charT, ST>& os, const sub_match<BiIter>& m);
4324684ddb6SLionel Sambuc
4334684ddb6SLionel Sambuctemplate <class BidirectionalIterator,
4344684ddb6SLionel Sambuc          class Allocator = allocator<sub_match<BidirectionalIterator>>>
4354684ddb6SLionel Sambucclass match_results
4364684ddb6SLionel Sambuc{
4374684ddb6SLionel Sambucpublic:
4384684ddb6SLionel Sambuc    typedef sub_match<BidirectionalIterator>                  value_type;
4394684ddb6SLionel Sambuc    typedef const value_type&                                 const_reference;
440*0a6a1f1dSLionel Sambuc    typedef value_type&                                       reference;
4414684ddb6SLionel Sambuc    typedef /implementation-defined/                          const_iterator;
4424684ddb6SLionel Sambuc    typedef const_iterator                                    iterator;
4434684ddb6SLionel Sambuc    typedef typename iterator_traits<BidirectionalIterator>::difference_type difference_type;
4444684ddb6SLionel Sambuc    typedef typename allocator_traits<Allocator>::size_type   size_type;
4454684ddb6SLionel Sambuc    typedef Allocator                                         allocator_type;
4464684ddb6SLionel Sambuc    typedef typename iterator_traits<BidirectionalIterator>::value_type char_type;
4474684ddb6SLionel Sambuc    typedef basic_string<char_type>                           string_type;
4484684ddb6SLionel Sambuc
4494684ddb6SLionel Sambuc    // construct/copy/destroy:
4504684ddb6SLionel Sambuc    explicit match_results(const Allocator& a = Allocator());
4514684ddb6SLionel Sambuc    match_results(const match_results& m);
4524684ddb6SLionel Sambuc    match_results(match_results&& m) noexcept;
4534684ddb6SLionel Sambuc    match_results& operator=(const match_results& m);
4544684ddb6SLionel Sambuc    match_results& operator=(match_results&& m);
4554684ddb6SLionel Sambuc    ~match_results();
4564684ddb6SLionel Sambuc
4574684ddb6SLionel Sambuc    bool ready() const;
4584684ddb6SLionel Sambuc
4594684ddb6SLionel Sambuc    // size:
4604684ddb6SLionel Sambuc    size_type size() const;
4614684ddb6SLionel Sambuc    size_type max_size() const;
4624684ddb6SLionel Sambuc    bool empty() const;
4634684ddb6SLionel Sambuc
4644684ddb6SLionel Sambuc    // element access:
4654684ddb6SLionel Sambuc    difference_type length(size_type sub = 0) const;
4664684ddb6SLionel Sambuc    difference_type position(size_type sub = 0) const;
4674684ddb6SLionel Sambuc    string_type str(size_type sub = 0) const;
4684684ddb6SLionel Sambuc    const_reference operator[](size_type n) const;
4694684ddb6SLionel Sambuc
4704684ddb6SLionel Sambuc    const_reference prefix() const;
4714684ddb6SLionel Sambuc    const_reference suffix() const;
4724684ddb6SLionel Sambuc
4734684ddb6SLionel Sambuc    const_iterator begin() const;
4744684ddb6SLionel Sambuc    const_iterator end() const;
4754684ddb6SLionel Sambuc    const_iterator cbegin() const;
4764684ddb6SLionel Sambuc    const_iterator cend() const;
4774684ddb6SLionel Sambuc
4784684ddb6SLionel Sambuc    // format:
4794684ddb6SLionel Sambuc    template <class OutputIter>
4804684ddb6SLionel Sambuc        OutputIter
4814684ddb6SLionel Sambuc        format(OutputIter out, const char_type* fmt_first,
4824684ddb6SLionel Sambuc               const char_type* fmt_last,
4834684ddb6SLionel Sambuc               regex_constants::match_flag_type flags = regex_constants::format_default) const;
4844684ddb6SLionel Sambuc    template <class OutputIter, class ST, class SA>
4854684ddb6SLionel Sambuc        OutputIter
4864684ddb6SLionel Sambuc        format(OutputIter out, const basic_string<char_type, ST, SA>& fmt,
4874684ddb6SLionel Sambuc               regex_constants::match_flag_type flags = regex_constants::format_default) const;
4884684ddb6SLionel Sambuc    template <class ST, class SA>
4894684ddb6SLionel Sambuc        basic_string<char_type, ST, SA>
4904684ddb6SLionel Sambuc        format(const basic_string<char_type, ST, SA>& fmt,
4914684ddb6SLionel Sambuc               regex_constants::match_flag_type flags = regex_constants::format_default) const;
4924684ddb6SLionel Sambuc    string_type
4934684ddb6SLionel Sambuc        format(const char_type* fmt,
4944684ddb6SLionel Sambuc               regex_constants::match_flag_type flags = regex_constants::format_default) const;
4954684ddb6SLionel Sambuc
4964684ddb6SLionel Sambuc    // allocator:
4974684ddb6SLionel Sambuc    allocator_type get_allocator() const;
4984684ddb6SLionel Sambuc
4994684ddb6SLionel Sambuc    // swap:
5004684ddb6SLionel Sambuc    void swap(match_results& that);
5014684ddb6SLionel Sambuc};
5024684ddb6SLionel Sambuc
5034684ddb6SLionel Sambuctypedef match_results<const char*>             cmatch;
5044684ddb6SLionel Sambuctypedef match_results<const wchar_t*>          wcmatch;
5054684ddb6SLionel Sambuctypedef match_results<string::const_iterator>  smatch;
5064684ddb6SLionel Sambuctypedef match_results<wstring::const_iterator> wsmatch;
5074684ddb6SLionel Sambuc
5084684ddb6SLionel Sambuctemplate <class BidirectionalIterator, class Allocator>
5094684ddb6SLionel Sambuc    bool
5104684ddb6SLionel Sambuc    operator==(const match_results<BidirectionalIterator, Allocator>& m1,
5114684ddb6SLionel Sambuc               const match_results<BidirectionalIterator, Allocator>& m2);
5124684ddb6SLionel Sambuc
5134684ddb6SLionel Sambuctemplate <class BidirectionalIterator, class Allocator>
5144684ddb6SLionel Sambuc    bool
5154684ddb6SLionel Sambuc    operator!=(const match_results<BidirectionalIterator, Allocator>& m1,
5164684ddb6SLionel Sambuc               const match_results<BidirectionalIterator, Allocator>& m2);
5174684ddb6SLionel Sambuc
5184684ddb6SLionel Sambuctemplate <class BidirectionalIterator, class Allocator>
5194684ddb6SLionel Sambuc    void
5204684ddb6SLionel Sambuc    swap(match_results<BidirectionalIterator, Allocator>& m1,
5214684ddb6SLionel Sambuc         match_results<BidirectionalIterator, Allocator>& m2);
5224684ddb6SLionel Sambuc
5234684ddb6SLionel Sambuctemplate <class BidirectionalIterator, class Allocator, class charT, class traits>
5244684ddb6SLionel Sambuc    bool
5254684ddb6SLionel Sambuc    regex_match(BidirectionalIterator first, BidirectionalIterator last,
5264684ddb6SLionel Sambuc                match_results<BidirectionalIterator, Allocator>& m,
5274684ddb6SLionel Sambuc                const basic_regex<charT, traits>& e,
5284684ddb6SLionel Sambuc                regex_constants::match_flag_type flags = regex_constants::match_default);
5294684ddb6SLionel Sambuc
5304684ddb6SLionel Sambuctemplate <class BidirectionalIterator, class charT, class traits>
5314684ddb6SLionel Sambuc    bool
5324684ddb6SLionel Sambuc    regex_match(BidirectionalIterator first, BidirectionalIterator last,
5334684ddb6SLionel Sambuc                const basic_regex<charT, traits>& e,
5344684ddb6SLionel Sambuc                regex_constants::match_flag_type flags = regex_constants::match_default);
5354684ddb6SLionel Sambuc
5364684ddb6SLionel Sambuctemplate <class charT, class Allocator, class traits>
5374684ddb6SLionel Sambuc    bool
5384684ddb6SLionel Sambuc    regex_match(const charT* str, match_results<const charT*, Allocator>& m,
5394684ddb6SLionel Sambuc                const basic_regex<charT, traits>& e,
5404684ddb6SLionel Sambuc                regex_constants::match_flag_type flags = regex_constants::match_default);
5414684ddb6SLionel Sambuc
5424684ddb6SLionel Sambuctemplate <class ST, class SA, class Allocator, class charT, class traits>
5434684ddb6SLionel Sambuc    bool
5444684ddb6SLionel Sambuc    regex_match(const basic_string<charT, ST, SA>& s,
5454684ddb6SLionel Sambuc                match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m,
5464684ddb6SLionel Sambuc                const basic_regex<charT, traits>& e,
5474684ddb6SLionel Sambuc                regex_constants::match_flag_type flags = regex_constants::match_default);
5484684ddb6SLionel Sambuc
549*0a6a1f1dSLionel Sambuctemplate <class ST, class SA, class Allocator, class charT, class traits>
550*0a6a1f1dSLionel Sambuc    bool
551*0a6a1f1dSLionel Sambuc    regex_match(const basic_string<charT, ST, SA>&& s,
552*0a6a1f1dSLionel Sambuc                match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m,
553*0a6a1f1dSLionel Sambuc                const basic_regex<charT, traits>& e,
554*0a6a1f1dSLionel Sambuc                regex_constants::match_flag_type flags = regex_constants::match_default) = delete; // C++14
555*0a6a1f1dSLionel Sambuc
5564684ddb6SLionel Sambuctemplate <class charT, class traits>
5574684ddb6SLionel Sambuc    bool
5584684ddb6SLionel Sambuc    regex_match(const charT* str, const basic_regex<charT, traits>& e,
5594684ddb6SLionel Sambuc                regex_constants::match_flag_type flags = regex_constants::match_default);
5604684ddb6SLionel Sambuc
5614684ddb6SLionel Sambuctemplate <class ST, class SA, class charT, class traits>
5624684ddb6SLionel Sambuc    bool
5634684ddb6SLionel Sambuc    regex_match(const basic_string<charT, ST, SA>& s,
5644684ddb6SLionel Sambuc                const basic_regex<charT, traits>& e,
5654684ddb6SLionel Sambuc                regex_constants::match_flag_type flags = regex_constants::match_default);
5664684ddb6SLionel Sambuc
5674684ddb6SLionel Sambuctemplate <class BidirectionalIterator, class Allocator, class charT, class traits>
5684684ddb6SLionel Sambuc    bool
5694684ddb6SLionel Sambuc    regex_search(BidirectionalIterator first, BidirectionalIterator last,
5704684ddb6SLionel Sambuc                 match_results<BidirectionalIterator, Allocator>& m,
5714684ddb6SLionel Sambuc                 const basic_regex<charT, traits>& e,
5724684ddb6SLionel Sambuc                 regex_constants::match_flag_type flags = regex_constants::match_default);
5734684ddb6SLionel Sambuc
5744684ddb6SLionel Sambuctemplate <class BidirectionalIterator, class charT, class traits>
5754684ddb6SLionel Sambuc    bool
5764684ddb6SLionel Sambuc    regex_search(BidirectionalIterator first, BidirectionalIterator last,
5774684ddb6SLionel Sambuc                 const basic_regex<charT, traits>& e,
5784684ddb6SLionel Sambuc                 regex_constants::match_flag_type flags = regex_constants::match_default);
5794684ddb6SLionel Sambuc
5804684ddb6SLionel Sambuctemplate <class charT, class Allocator, class traits>
5814684ddb6SLionel Sambuc    bool
5824684ddb6SLionel Sambuc    regex_search(const charT* str, match_results<const charT*, Allocator>& m,
5834684ddb6SLionel Sambuc                 const basic_regex<charT, traits>& e,
5844684ddb6SLionel Sambuc                 regex_constants::match_flag_type flags = regex_constants::match_default);
5854684ddb6SLionel Sambuc
5864684ddb6SLionel Sambuctemplate <class charT, class traits>
5874684ddb6SLionel Sambuc    bool
5884684ddb6SLionel Sambuc    regex_search(const charT* str, const basic_regex<charT, traits>& e,
5894684ddb6SLionel Sambuc                 regex_constants::match_flag_type flags = regex_constants::match_default);
5904684ddb6SLionel Sambuc
5914684ddb6SLionel Sambuctemplate <class ST, class SA, class charT, class traits>
5924684ddb6SLionel Sambuc    bool
5934684ddb6SLionel Sambuc    regex_search(const basic_string<charT, ST, SA>& s,
5944684ddb6SLionel Sambuc                 const basic_regex<charT, traits>& e,
5954684ddb6SLionel Sambuc                 regex_constants::match_flag_type flags = regex_constants::match_default);
5964684ddb6SLionel Sambuc
5974684ddb6SLionel Sambuctemplate <class ST, class SA, class Allocator, class charT, class traits>
5984684ddb6SLionel Sambuc    bool
5994684ddb6SLionel Sambuc    regex_search(const basic_string<charT, ST, SA>& s,
6004684ddb6SLionel Sambuc                 match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m,
6014684ddb6SLionel Sambuc                 const basic_regex<charT, traits>& e,
6024684ddb6SLionel Sambuc                 regex_constants::match_flag_type flags = regex_constants::match_default);
6034684ddb6SLionel Sambuc
604*0a6a1f1dSLionel Sambuctemplate <class ST, class SA, class Allocator, class charT, class traits>
605*0a6a1f1dSLionel Sambuc    bool
606*0a6a1f1dSLionel Sambuc    regex_search(const basic_string<charT, ST, SA>&& s,
607*0a6a1f1dSLionel Sambuc                 match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m,
608*0a6a1f1dSLionel Sambuc                 const basic_regex<charT, traits>& e,
609*0a6a1f1dSLionel Sambuc                 regex_constants::match_flag_type flags = regex_constants::match_default) = delete; // C++14
610*0a6a1f1dSLionel Sambuc
6114684ddb6SLionel Sambuctemplate <class OutputIterator, class BidirectionalIterator,
6124684ddb6SLionel Sambuc          class traits, class charT, class ST, class SA>
6134684ddb6SLionel Sambuc    OutputIterator
6144684ddb6SLionel Sambuc    regex_replace(OutputIterator out,
6154684ddb6SLionel Sambuc                  BidirectionalIterator first, BidirectionalIterator last,
6164684ddb6SLionel Sambuc                  const basic_regex<charT, traits>& e,
6174684ddb6SLionel Sambuc                  const basic_string<charT, ST, SA>& fmt,
6184684ddb6SLionel Sambuc                  regex_constants::match_flag_type flags = regex_constants::match_default);
6194684ddb6SLionel Sambuc
6204684ddb6SLionel Sambuctemplate <class OutputIterator, class BidirectionalIterator,
6214684ddb6SLionel Sambuc          class traits, class charT>
6224684ddb6SLionel Sambuc    OutputIterator
6234684ddb6SLionel Sambuc    regex_replace(OutputIterator out,
6244684ddb6SLionel Sambuc                  BidirectionalIterator first, BidirectionalIterator last,
6254684ddb6SLionel Sambuc                  const basic_regex<charT, traits>& e, const charT* fmt,
6264684ddb6SLionel Sambuc                  regex_constants::match_flag_type flags = regex_constants::match_default);
6274684ddb6SLionel Sambuc
6284684ddb6SLionel Sambuctemplate <class traits, class charT, class ST, class SA, class FST, class FSA>>
6294684ddb6SLionel Sambuc    basic_string<charT, ST, SA>
6304684ddb6SLionel Sambuc    regex_replace(const basic_string<charT, ST, SA>& s,
6314684ddb6SLionel Sambuc                  const basic_regex<charT, traits>& e,
6324684ddb6SLionel Sambuc                  const basic_string<charT, FST, FSA>& fmt,
6334684ddb6SLionel Sambuc                  regex_constants::match_flag_type flags = regex_constants::match_default);
6344684ddb6SLionel Sambuc
6354684ddb6SLionel Sambuctemplate <class traits, class charT, class ST, class SA>
6364684ddb6SLionel Sambuc    basic_string<charT, ST, SA>
6374684ddb6SLionel Sambuc    regex_replace(const basic_string<charT, ST, SA>& s,
6384684ddb6SLionel Sambuc                  const basic_regex<charT, traits>& e, const charT* fmt,
6394684ddb6SLionel Sambuc                  regex_constants::match_flag_type flags = regex_constants::match_default);
6404684ddb6SLionel Sambuc
6414684ddb6SLionel Sambuctemplate <class traits, class charT, class ST, class SA>
6424684ddb6SLionel Sambuc    basic_string<charT>
6434684ddb6SLionel Sambuc    regex_replace(const charT* s,
6444684ddb6SLionel Sambuc                  const basic_regex<charT, traits>& e,
6454684ddb6SLionel Sambuc                  const basic_string<charT, ST, SA>& fmt,
6464684ddb6SLionel Sambuc                  regex_constants::match_flag_type flags = regex_constants::match_default);
6474684ddb6SLionel Sambuc
6484684ddb6SLionel Sambuctemplate <class traits, class charT>
6494684ddb6SLionel Sambuc    basic_string<charT>
6504684ddb6SLionel Sambuc    regex_replace(const charT* s,
6514684ddb6SLionel Sambuc                  const basic_regex<charT, traits>& e,
6524684ddb6SLionel Sambuc                  const charT* fmt,
6534684ddb6SLionel Sambuc                  regex_constants::match_flag_type flags = regex_constants::match_default);
6544684ddb6SLionel Sambuc
6554684ddb6SLionel Sambuctemplate <class BidirectionalIterator,
6564684ddb6SLionel Sambuc          class charT = typename iterator_traits< BidirectionalIterator>::value_type,
6574684ddb6SLionel Sambuc          class traits = regex_traits<charT>>
6584684ddb6SLionel Sambucclass regex_iterator
6594684ddb6SLionel Sambuc{
6604684ddb6SLionel Sambucpublic:
6614684ddb6SLionel Sambuc    typedef basic_regex<charT, traits>           regex_type;
6624684ddb6SLionel Sambuc    typedef match_results<BidirectionalIterator> value_type;
6634684ddb6SLionel Sambuc    typedef ptrdiff_t                            difference_type;
6644684ddb6SLionel Sambuc    typedef const value_type*                    pointer;
6654684ddb6SLionel Sambuc    typedef const value_type&                    reference;
6664684ddb6SLionel Sambuc    typedef forward_iterator_tag                 iterator_category;
6674684ddb6SLionel Sambuc
6684684ddb6SLionel Sambuc    regex_iterator();
6694684ddb6SLionel Sambuc    regex_iterator(BidirectionalIterator a, BidirectionalIterator b,
6704684ddb6SLionel Sambuc                   const regex_type& re,
6714684ddb6SLionel Sambuc                   regex_constants::match_flag_type m = regex_constants::match_default);
672*0a6a1f1dSLionel Sambuc    regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
673*0a6a1f1dSLionel Sambuc                   const regex_type&& __re,
674*0a6a1f1dSLionel Sambuc                   regex_constants::match_flag_type __m
675*0a6a1f1dSLionel Sambuc                                     = regex_constants::match_default) = delete; // C++14
6764684ddb6SLionel Sambuc    regex_iterator(const regex_iterator&);
6774684ddb6SLionel Sambuc    regex_iterator& operator=(const regex_iterator&);
6784684ddb6SLionel Sambuc
6794684ddb6SLionel Sambuc    bool operator==(const regex_iterator&) const;
6804684ddb6SLionel Sambuc    bool operator!=(const regex_iterator&) const;
6814684ddb6SLionel Sambuc
6824684ddb6SLionel Sambuc    const value_type& operator*() const;
6834684ddb6SLionel Sambuc    const value_type* operator->() const;
6844684ddb6SLionel Sambuc
6854684ddb6SLionel Sambuc    regex_iterator& operator++();
6864684ddb6SLionel Sambuc    regex_iterator operator++(int);
6874684ddb6SLionel Sambuc};
6884684ddb6SLionel Sambuc
6894684ddb6SLionel Sambuctypedef regex_iterator<const char*>             cregex_iterator;
6904684ddb6SLionel Sambuctypedef regex_iterator<const wchar_t*>          wcregex_iterator;
6914684ddb6SLionel Sambuctypedef regex_iterator<string::const_iterator>  sregex_iterator;
6924684ddb6SLionel Sambuctypedef regex_iterator<wstring::const_iterator> wsregex_iterator;
6934684ddb6SLionel Sambuc
6944684ddb6SLionel Sambuctemplate <class BidirectionalIterator,
6954684ddb6SLionel Sambuc          class charT = typename iterator_traits< BidirectionalIterator>::value_type,
6964684ddb6SLionel Sambuc          class traits = regex_traits<charT>>
6974684ddb6SLionel Sambucclass regex_token_iterator
6984684ddb6SLionel Sambuc{
6994684ddb6SLionel Sambucpublic:
7004684ddb6SLionel Sambuc    typedef basic_regex<charT, traits>       regex_type;
7014684ddb6SLionel Sambuc    typedef sub_match<BidirectionalIterator> value_type;
7024684ddb6SLionel Sambuc    typedef ptrdiff_t                        difference_type;
7034684ddb6SLionel Sambuc    typedef const value_type*                pointer;
7044684ddb6SLionel Sambuc    typedef const value_type&                reference;
7054684ddb6SLionel Sambuc    typedef forward_iterator_tag             iterator_category;
7064684ddb6SLionel Sambuc
7074684ddb6SLionel Sambuc    regex_token_iterator();
7084684ddb6SLionel Sambuc    regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
7094684ddb6SLionel Sambuc                         const regex_type& re, int submatch = 0,
7104684ddb6SLionel Sambuc                         regex_constants::match_flag_type m = regex_constants::match_default);
7114684ddb6SLionel Sambuc    regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
712*0a6a1f1dSLionel Sambuc                         const regex_type&& re, int submatch = 0,
713*0a6a1f1dSLionel Sambuc                         regex_constants::match_flag_type m = regex_constants::match_default) = delete; // C++14
714*0a6a1f1dSLionel Sambuc    regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
7154684ddb6SLionel Sambuc                         const regex_type& re, const vector<int>& submatches,
7164684ddb6SLionel Sambuc                         regex_constants::match_flag_type m = regex_constants::match_default);
7174684ddb6SLionel Sambuc    regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
718*0a6a1f1dSLionel Sambuc                         const regex_type&& re, const vector<int>& submatches,
719*0a6a1f1dSLionel Sambuc                         regex_constants::match_flag_type m = regex_constants::match_default) = delete; // C++14
720*0a6a1f1dSLionel Sambuc    regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
7214684ddb6SLionel Sambuc                         const regex_type& re, initializer_list<int> submatches,
7224684ddb6SLionel Sambuc                         regex_constants::match_flag_type m = regex_constants::match_default);
723*0a6a1f1dSLionel Sambuc    regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
724*0a6a1f1dSLionel Sambuc                         const regex_type&& re, initializer_list<int> submatches,
725*0a6a1f1dSLionel Sambuc                         regex_constants::match_flag_type m = regex_constants::match_default) = delete; // C++14
7264684ddb6SLionel Sambuc    template <size_t N>
7274684ddb6SLionel Sambuc        regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
7284684ddb6SLionel Sambuc                             const regex_type& re, const int (&submatches)[N],
7294684ddb6SLionel Sambuc                             regex_constants::match_flag_type m = regex_constants::match_default);
730*0a6a1f1dSLionel Sambuc    template <size_t N>
731*0a6a1f1dSLionel Sambuc        regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
732*0a6a1f1dSLionel Sambuc                             const regex_type& re, const int (&submatches)[N],
733*0a6a1f1dSLionel Sambuc                             regex_constants::match_flag_type m = regex_constants::match_default) = delete // C++14;
7344684ddb6SLionel Sambuc    regex_token_iterator(const regex_token_iterator&);
7354684ddb6SLionel Sambuc    regex_token_iterator& operator=(const regex_token_iterator&);
7364684ddb6SLionel Sambuc
7374684ddb6SLionel Sambuc    bool operator==(const regex_token_iterator&) const;
7384684ddb6SLionel Sambuc    bool operator!=(const regex_token_iterator&) const;
7394684ddb6SLionel Sambuc
7404684ddb6SLionel Sambuc    const value_type& operator*() const;
7414684ddb6SLionel Sambuc    const value_type* operator->() const;
7424684ddb6SLionel Sambuc
7434684ddb6SLionel Sambuc    regex_token_iterator& operator++();
7444684ddb6SLionel Sambuc    regex_token_iterator operator++(int);
7454684ddb6SLionel Sambuc};
7464684ddb6SLionel Sambuc
7474684ddb6SLionel Sambuctypedef regex_token_iterator<const char*>             cregex_token_iterator;
7484684ddb6SLionel Sambuctypedef regex_token_iterator<const wchar_t*>          wcregex_token_iterator;
7494684ddb6SLionel Sambuctypedef regex_token_iterator<string::const_iterator>  sregex_token_iterator;
7504684ddb6SLionel Sambuctypedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator;
7514684ddb6SLionel Sambuc
7524684ddb6SLionel Sambuc} // std
7534684ddb6SLionel Sambuc*/
7544684ddb6SLionel Sambuc
7554684ddb6SLionel Sambuc#include <__config>
7564684ddb6SLionel Sambuc#include <stdexcept>
7574684ddb6SLionel Sambuc#include <__locale>
7584684ddb6SLionel Sambuc#include <initializer_list>
7594684ddb6SLionel Sambuc#include <utility>
7604684ddb6SLionel Sambuc#include <iterator>
7614684ddb6SLionel Sambuc#include <string>
7624684ddb6SLionel Sambuc#include <memory>
7634684ddb6SLionel Sambuc#include <vector>
7644684ddb6SLionel Sambuc#include <deque>
765*0a6a1f1dSLionel Sambuc#include <cassert>
7664684ddb6SLionel Sambuc
7674684ddb6SLionel Sambuc#include <__undef_min_max>
7684684ddb6SLionel Sambuc
7694684ddb6SLionel Sambuc#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
7704684ddb6SLionel Sambuc#pragma GCC system_header
7714684ddb6SLionel Sambuc#endif
7724684ddb6SLionel Sambuc
7734684ddb6SLionel Sambuc_LIBCPP_BEGIN_NAMESPACE_STD
7744684ddb6SLionel Sambuc
7754684ddb6SLionel Sambucnamespace regex_constants
7764684ddb6SLionel Sambuc{
7774684ddb6SLionel Sambuc
7784684ddb6SLionel Sambuc// syntax_option_type
7794684ddb6SLionel Sambuc
7804684ddb6SLionel Sambucenum syntax_option_type
7814684ddb6SLionel Sambuc{
7824684ddb6SLionel Sambuc    icase      = 1 << 0,
7834684ddb6SLionel Sambuc    nosubs     = 1 << 1,
7844684ddb6SLionel Sambuc    optimize   = 1 << 2,
7854684ddb6SLionel Sambuc    collate    = 1 << 3,
7864684ddb6SLionel Sambuc    ECMAScript = 0,
7874684ddb6SLionel Sambuc    basic      = 1 << 4,
7884684ddb6SLionel Sambuc    extended   = 1 << 5,
7894684ddb6SLionel Sambuc    awk        = 1 << 6,
7904684ddb6SLionel Sambuc    grep       = 1 << 7,
7914684ddb6SLionel Sambuc    egrep      = 1 << 8
7924684ddb6SLionel Sambuc};
7934684ddb6SLionel Sambuc
7944684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
7954684ddb6SLionel Sambuc_LIBCPP_CONSTEXPR
7964684ddb6SLionel Sambucsyntax_option_type
7974684ddb6SLionel Sambucoperator~(syntax_option_type __x)
7984684ddb6SLionel Sambuc{
7994684ddb6SLionel Sambuc    return syntax_option_type(~int(__x) & 0x1FF);
8004684ddb6SLionel Sambuc}
8014684ddb6SLionel Sambuc
8024684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
8034684ddb6SLionel Sambuc_LIBCPP_CONSTEXPR
8044684ddb6SLionel Sambucsyntax_option_type
8054684ddb6SLionel Sambucoperator&(syntax_option_type __x, syntax_option_type __y)
8064684ddb6SLionel Sambuc{
8074684ddb6SLionel Sambuc    return syntax_option_type(int(__x) & int(__y));
8084684ddb6SLionel Sambuc}
8094684ddb6SLionel Sambuc
8104684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
8114684ddb6SLionel Sambuc_LIBCPP_CONSTEXPR
8124684ddb6SLionel Sambucsyntax_option_type
8134684ddb6SLionel Sambucoperator|(syntax_option_type __x, syntax_option_type __y)
8144684ddb6SLionel Sambuc{
8154684ddb6SLionel Sambuc    return syntax_option_type(int(__x) | int(__y));
8164684ddb6SLionel Sambuc}
8174684ddb6SLionel Sambuc
8184684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
8194684ddb6SLionel Sambuc_LIBCPP_CONSTEXPR
8204684ddb6SLionel Sambucsyntax_option_type
8214684ddb6SLionel Sambucoperator^(syntax_option_type __x, syntax_option_type __y)
8224684ddb6SLionel Sambuc{
8234684ddb6SLionel Sambuc    return syntax_option_type(int(__x) ^ int(__y));
8244684ddb6SLionel Sambuc}
8254684ddb6SLionel Sambuc
8264684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
8274684ddb6SLionel Sambucsyntax_option_type&
8284684ddb6SLionel Sambucoperator&=(syntax_option_type& __x, syntax_option_type __y)
8294684ddb6SLionel Sambuc{
8304684ddb6SLionel Sambuc    __x = __x & __y;
8314684ddb6SLionel Sambuc    return __x;
8324684ddb6SLionel Sambuc}
8334684ddb6SLionel Sambuc
8344684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
8354684ddb6SLionel Sambucsyntax_option_type&
8364684ddb6SLionel Sambucoperator|=(syntax_option_type& __x, syntax_option_type __y)
8374684ddb6SLionel Sambuc{
8384684ddb6SLionel Sambuc    __x = __x | __y;
8394684ddb6SLionel Sambuc    return __x;
8404684ddb6SLionel Sambuc}
8414684ddb6SLionel Sambuc
8424684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
8434684ddb6SLionel Sambucsyntax_option_type&
8444684ddb6SLionel Sambucoperator^=(syntax_option_type& __x, syntax_option_type __y)
8454684ddb6SLionel Sambuc{
8464684ddb6SLionel Sambuc    __x = __x ^ __y;
8474684ddb6SLionel Sambuc    return __x;
8484684ddb6SLionel Sambuc}
8494684ddb6SLionel Sambuc
8504684ddb6SLionel Sambuc// match_flag_type
8514684ddb6SLionel Sambuc
8524684ddb6SLionel Sambucenum match_flag_type
8534684ddb6SLionel Sambuc{
8544684ddb6SLionel Sambuc    match_default     = 0,
8554684ddb6SLionel Sambuc    match_not_bol     = 1 << 0,
8564684ddb6SLionel Sambuc    match_not_eol     = 1 << 1,
8574684ddb6SLionel Sambuc    match_not_bow     = 1 << 2,
8584684ddb6SLionel Sambuc    match_not_eow     = 1 << 3,
8594684ddb6SLionel Sambuc    match_any         = 1 << 4,
8604684ddb6SLionel Sambuc    match_not_null    = 1 << 5,
8614684ddb6SLionel Sambuc    match_continuous  = 1 << 6,
8624684ddb6SLionel Sambuc    match_prev_avail  = 1 << 7,
8634684ddb6SLionel Sambuc    format_default    = 0,
8644684ddb6SLionel Sambuc    format_sed        = 1 << 8,
8654684ddb6SLionel Sambuc    format_no_copy    = 1 << 9,
8664684ddb6SLionel Sambuc    format_first_only = 1 << 10,
8674684ddb6SLionel Sambuc    __no_update_pos   = 1 << 11
8684684ddb6SLionel Sambuc};
8694684ddb6SLionel Sambuc
8704684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
8714684ddb6SLionel Sambuc_LIBCPP_CONSTEXPR
8724684ddb6SLionel Sambucmatch_flag_type
8734684ddb6SLionel Sambucoperator~(match_flag_type __x)
8744684ddb6SLionel Sambuc{
8754684ddb6SLionel Sambuc    return match_flag_type(~int(__x) & 0x0FFF);
8764684ddb6SLionel Sambuc}
8774684ddb6SLionel Sambuc
8784684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
8794684ddb6SLionel Sambuc_LIBCPP_CONSTEXPR
8804684ddb6SLionel Sambucmatch_flag_type
8814684ddb6SLionel Sambucoperator&(match_flag_type __x, match_flag_type __y)
8824684ddb6SLionel Sambuc{
8834684ddb6SLionel Sambuc    return match_flag_type(int(__x) & int(__y));
8844684ddb6SLionel Sambuc}
8854684ddb6SLionel Sambuc
8864684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
8874684ddb6SLionel Sambuc_LIBCPP_CONSTEXPR
8884684ddb6SLionel Sambucmatch_flag_type
8894684ddb6SLionel Sambucoperator|(match_flag_type __x, match_flag_type __y)
8904684ddb6SLionel Sambuc{
8914684ddb6SLionel Sambuc    return match_flag_type(int(__x) | int(__y));
8924684ddb6SLionel Sambuc}
8934684ddb6SLionel Sambuc
8944684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
8954684ddb6SLionel Sambuc_LIBCPP_CONSTEXPR
8964684ddb6SLionel Sambucmatch_flag_type
8974684ddb6SLionel Sambucoperator^(match_flag_type __x, match_flag_type __y)
8984684ddb6SLionel Sambuc{
8994684ddb6SLionel Sambuc    return match_flag_type(int(__x) ^ int(__y));
9004684ddb6SLionel Sambuc}
9014684ddb6SLionel Sambuc
9024684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
9034684ddb6SLionel Sambucmatch_flag_type&
9044684ddb6SLionel Sambucoperator&=(match_flag_type& __x, match_flag_type __y)
9054684ddb6SLionel Sambuc{
9064684ddb6SLionel Sambuc    __x = __x & __y;
9074684ddb6SLionel Sambuc    return __x;
9084684ddb6SLionel Sambuc}
9094684ddb6SLionel Sambuc
9104684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
9114684ddb6SLionel Sambucmatch_flag_type&
9124684ddb6SLionel Sambucoperator|=(match_flag_type& __x, match_flag_type __y)
9134684ddb6SLionel Sambuc{
9144684ddb6SLionel Sambuc    __x = __x | __y;
9154684ddb6SLionel Sambuc    return __x;
9164684ddb6SLionel Sambuc}
9174684ddb6SLionel Sambuc
9184684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
9194684ddb6SLionel Sambucmatch_flag_type&
9204684ddb6SLionel Sambucoperator^=(match_flag_type& __x, match_flag_type __y)
9214684ddb6SLionel Sambuc{
9224684ddb6SLionel Sambuc    __x = __x ^ __y;
9234684ddb6SLionel Sambuc    return __x;
9244684ddb6SLionel Sambuc}
9254684ddb6SLionel Sambuc
9264684ddb6SLionel Sambucenum error_type
9274684ddb6SLionel Sambuc{
9284684ddb6SLionel Sambuc    error_collate = 1,
9294684ddb6SLionel Sambuc    error_ctype,
9304684ddb6SLionel Sambuc    error_escape,
9314684ddb6SLionel Sambuc    error_backref,
9324684ddb6SLionel Sambuc    error_brack,
9334684ddb6SLionel Sambuc    error_paren,
9344684ddb6SLionel Sambuc    error_brace,
9354684ddb6SLionel Sambuc    error_badbrace,
9364684ddb6SLionel Sambuc    error_range,
9374684ddb6SLionel Sambuc    error_space,
9384684ddb6SLionel Sambuc    error_badrepeat,
9394684ddb6SLionel Sambuc    error_complexity,
9404684ddb6SLionel Sambuc    error_stack,
9414684ddb6SLionel Sambuc    __re_err_grammar,
9424684ddb6SLionel Sambuc    __re_err_empty,
9434684ddb6SLionel Sambuc    __re_err_unknown
9444684ddb6SLionel Sambuc};
9454684ddb6SLionel Sambuc
9464684ddb6SLionel Sambuc}  // regex_constants
9474684ddb6SLionel Sambuc
9484684ddb6SLionel Sambucclass _LIBCPP_EXCEPTION_ABI regex_error
9494684ddb6SLionel Sambuc    : public runtime_error
9504684ddb6SLionel Sambuc{
9514684ddb6SLionel Sambuc    regex_constants::error_type __code_;
9524684ddb6SLionel Sambucpublic:
9534684ddb6SLionel Sambuc    explicit regex_error(regex_constants::error_type __ecode);
9544684ddb6SLionel Sambuc    virtual ~regex_error() throw();
9554684ddb6SLionel Sambuc     _LIBCPP_INLINE_VISIBILITY
9564684ddb6SLionel Sambuc    regex_constants::error_type code() const {return __code_;}
9574684ddb6SLionel Sambuc};
9584684ddb6SLionel Sambuc
959*0a6a1f1dSLionel Sambuctemplate <regex_constants::error_type _Ev>
960*0a6a1f1dSLionel Sambuc_LIBCPP_ALWAYS_INLINE
961*0a6a1f1dSLionel Sambucvoid __throw_regex_error()
962*0a6a1f1dSLionel Sambuc{
963*0a6a1f1dSLionel Sambuc#ifndef _LIBCPP_NO_EXCEPTIONS
964*0a6a1f1dSLionel Sambuc    throw regex_error(_Ev);
965*0a6a1f1dSLionel Sambuc#else
966*0a6a1f1dSLionel Sambuc    assert(!"regex_error");
967*0a6a1f1dSLionel Sambuc#endif
968*0a6a1f1dSLionel Sambuc}
969*0a6a1f1dSLionel Sambuc
9704684ddb6SLionel Sambuctemplate <class _CharT>
9714684ddb6SLionel Sambucstruct _LIBCPP_TYPE_VIS_ONLY regex_traits
9724684ddb6SLionel Sambuc{
9734684ddb6SLionel Sambucpublic:
9744684ddb6SLionel Sambuc    typedef _CharT                  char_type;
9754684ddb6SLionel Sambuc    typedef basic_string<char_type> string_type;
9764684ddb6SLionel Sambuc    typedef locale                  locale_type;
9774684ddb6SLionel Sambuc    typedef ctype_base::mask        char_class_type;
9784684ddb6SLionel Sambuc
9794684ddb6SLionel Sambuc    static const char_class_type __regex_word = 0x80;
9804684ddb6SLionel Sambucprivate:
9814684ddb6SLionel Sambuc    locale __loc_;
9824684ddb6SLionel Sambuc    const ctype<char_type>* __ct_;
9834684ddb6SLionel Sambuc    const collate<char_type>* __col_;
9844684ddb6SLionel Sambuc
9854684ddb6SLionel Sambucpublic:
9864684ddb6SLionel Sambuc    regex_traits();
9874684ddb6SLionel Sambuc
9884684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
9894684ddb6SLionel Sambuc    static size_t length(const char_type* __p)
9904684ddb6SLionel Sambuc        {return char_traits<char_type>::length(__p);}
9914684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
9924684ddb6SLionel Sambuc    char_type translate(char_type __c) const {return __c;}
9934684ddb6SLionel Sambuc    char_type translate_nocase(char_type __c) const;
9944684ddb6SLionel Sambuc    template <class _ForwardIterator>
9954684ddb6SLionel Sambuc        string_type
9964684ddb6SLionel Sambuc        transform(_ForwardIterator __f, _ForwardIterator __l) const;
9974684ddb6SLionel Sambuc    template <class _ForwardIterator>
9984684ddb6SLionel Sambuc        _LIBCPP_INLINE_VISIBILITY
9994684ddb6SLionel Sambuc        string_type
10004684ddb6SLionel Sambuc        transform_primary( _ForwardIterator __f, _ForwardIterator __l) const
10014684ddb6SLionel Sambuc            {return __transform_primary(__f, __l, char_type());}
10024684ddb6SLionel Sambuc    template <class _ForwardIterator>
10034684ddb6SLionel Sambuc        _LIBCPP_INLINE_VISIBILITY
10044684ddb6SLionel Sambuc        string_type
10054684ddb6SLionel Sambuc        lookup_collatename(_ForwardIterator __f, _ForwardIterator __l) const
10064684ddb6SLionel Sambuc            {return __lookup_collatename(__f, __l, char_type());}
10074684ddb6SLionel Sambuc    template <class _ForwardIterator>
10084684ddb6SLionel Sambuc        _LIBCPP_INLINE_VISIBILITY
10094684ddb6SLionel Sambuc        char_class_type
10104684ddb6SLionel Sambuc        lookup_classname(_ForwardIterator __f, _ForwardIterator __l,
10114684ddb6SLionel Sambuc                         bool __icase = false) const
10124684ddb6SLionel Sambuc            {return __lookup_classname(__f, __l, __icase, char_type());}
10134684ddb6SLionel Sambuc    bool isctype(char_type __c, char_class_type __m) const;
10144684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
10154684ddb6SLionel Sambuc    int value(char_type __ch, int __radix) const
10164684ddb6SLionel Sambuc        {return __regex_traits_value(__ch, __radix);}
10174684ddb6SLionel Sambuc    locale_type imbue(locale_type __l);
10184684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
10194684ddb6SLionel Sambuc    locale_type getloc()const {return __loc_;}
10204684ddb6SLionel Sambuc
10214684ddb6SLionel Sambucprivate:
10224684ddb6SLionel Sambuc    void __init();
10234684ddb6SLionel Sambuc
10244684ddb6SLionel Sambuc    template <class _ForwardIterator>
10254684ddb6SLionel Sambuc        string_type
10264684ddb6SLionel Sambuc        __transform_primary(_ForwardIterator __f, _ForwardIterator __l, char) const;
10274684ddb6SLionel Sambuc    template <class _ForwardIterator>
10284684ddb6SLionel Sambuc        string_type
10294684ddb6SLionel Sambuc        __transform_primary(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const;
10304684ddb6SLionel Sambuc
10314684ddb6SLionel Sambuc    template <class _ForwardIterator>
10324684ddb6SLionel Sambuc        string_type
10334684ddb6SLionel Sambuc        __lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, char) const;
10344684ddb6SLionel Sambuc    template <class _ForwardIterator>
10354684ddb6SLionel Sambuc        string_type
10364684ddb6SLionel Sambuc        __lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const;
10374684ddb6SLionel Sambuc
10384684ddb6SLionel Sambuc    template <class _ForwardIterator>
10394684ddb6SLionel Sambuc        char_class_type
10404684ddb6SLionel Sambuc        __lookup_classname(_ForwardIterator __f, _ForwardIterator __l,
10414684ddb6SLionel Sambuc                           bool __icase, char) const;
10424684ddb6SLionel Sambuc    template <class _ForwardIterator>
10434684ddb6SLionel Sambuc        char_class_type
10444684ddb6SLionel Sambuc        __lookup_classname(_ForwardIterator __f, _ForwardIterator __l,
10454684ddb6SLionel Sambuc                           bool __icase, wchar_t) const;
10464684ddb6SLionel Sambuc
10474684ddb6SLionel Sambuc    static int __regex_traits_value(unsigned char __ch, int __radix);
10484684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
10494684ddb6SLionel Sambuc    int __regex_traits_value(char __ch, int __radix) const
10504684ddb6SLionel Sambuc        {return __regex_traits_value(static_cast<unsigned char>(__ch), __radix);}
10514684ddb6SLionel Sambuc    int __regex_traits_value(wchar_t __ch, int __radix) const;
10524684ddb6SLionel Sambuc};
10534684ddb6SLionel Sambuc
10544684ddb6SLionel Sambuctemplate <class _CharT>
10554684ddb6SLionel Sambucconst typename regex_traits<_CharT>::char_class_type
10564684ddb6SLionel Sambucregex_traits<_CharT>::__regex_word;
10574684ddb6SLionel Sambuc
10584684ddb6SLionel Sambuctemplate <class _CharT>
10594684ddb6SLionel Sambucregex_traits<_CharT>::regex_traits()
10604684ddb6SLionel Sambuc{
10614684ddb6SLionel Sambuc    __init();
10624684ddb6SLionel Sambuc}
10634684ddb6SLionel Sambuc
10644684ddb6SLionel Sambuctemplate <class _CharT>
10654684ddb6SLionel Sambuctypename regex_traits<_CharT>::char_type
10664684ddb6SLionel Sambucregex_traits<_CharT>::translate_nocase(char_type __c) const
10674684ddb6SLionel Sambuc{
10684684ddb6SLionel Sambuc    return __ct_->tolower(__c);
10694684ddb6SLionel Sambuc}
10704684ddb6SLionel Sambuc
10714684ddb6SLionel Sambuctemplate <class _CharT>
10724684ddb6SLionel Sambuctemplate <class _ForwardIterator>
10734684ddb6SLionel Sambuctypename regex_traits<_CharT>::string_type
10744684ddb6SLionel Sambucregex_traits<_CharT>::transform(_ForwardIterator __f, _ForwardIterator __l) const
10754684ddb6SLionel Sambuc{
10764684ddb6SLionel Sambuc    string_type __s(__f, __l);
10774684ddb6SLionel Sambuc    return __col_->transform(__s.data(), __s.data() + __s.size());
10784684ddb6SLionel Sambuc}
10794684ddb6SLionel Sambuc
10804684ddb6SLionel Sambuctemplate <class _CharT>
10814684ddb6SLionel Sambucvoid
10824684ddb6SLionel Sambucregex_traits<_CharT>::__init()
10834684ddb6SLionel Sambuc{
10844684ddb6SLionel Sambuc    __ct_ = &use_facet<ctype<char_type> >(__loc_);
10854684ddb6SLionel Sambuc    __col_ = &use_facet<collate<char_type> >(__loc_);
10864684ddb6SLionel Sambuc}
10874684ddb6SLionel Sambuc
10884684ddb6SLionel Sambuctemplate <class _CharT>
10894684ddb6SLionel Sambuctypename regex_traits<_CharT>::locale_type
10904684ddb6SLionel Sambucregex_traits<_CharT>::imbue(locale_type __l)
10914684ddb6SLionel Sambuc{
10924684ddb6SLionel Sambuc    locale __r = __loc_;
10934684ddb6SLionel Sambuc    __loc_ = __l;
10944684ddb6SLionel Sambuc    __init();
10954684ddb6SLionel Sambuc    return __r;
10964684ddb6SLionel Sambuc}
10974684ddb6SLionel Sambuc
10984684ddb6SLionel Sambuc// transform_primary is very FreeBSD-specific
10994684ddb6SLionel Sambuc
11004684ddb6SLionel Sambuctemplate <class _CharT>
11014684ddb6SLionel Sambuctemplate <class _ForwardIterator>
11024684ddb6SLionel Sambuctypename regex_traits<_CharT>::string_type
11034684ddb6SLionel Sambucregex_traits<_CharT>::__transform_primary(_ForwardIterator __f,
11044684ddb6SLionel Sambuc                                          _ForwardIterator __l, char) const
11054684ddb6SLionel Sambuc{
11064684ddb6SLionel Sambuc    const string_type __s(__f, __l);
11074684ddb6SLionel Sambuc    string_type __d = __col_->transform(__s.data(), __s.data() + __s.size());
11084684ddb6SLionel Sambuc    switch (__d.size())
11094684ddb6SLionel Sambuc    {
11104684ddb6SLionel Sambuc    case 1:
11114684ddb6SLionel Sambuc        break;
11124684ddb6SLionel Sambuc    case 12:
11134684ddb6SLionel Sambuc        __d[11] = __d[3];
11144684ddb6SLionel Sambuc        break;
11154684ddb6SLionel Sambuc    default:
11164684ddb6SLionel Sambuc        __d.clear();
11174684ddb6SLionel Sambuc        break;
11184684ddb6SLionel Sambuc    }
11194684ddb6SLionel Sambuc    return __d;
11204684ddb6SLionel Sambuc}
11214684ddb6SLionel Sambuc
11224684ddb6SLionel Sambuctemplate <class _CharT>
11234684ddb6SLionel Sambuctemplate <class _ForwardIterator>
11244684ddb6SLionel Sambuctypename regex_traits<_CharT>::string_type
11254684ddb6SLionel Sambucregex_traits<_CharT>::__transform_primary(_ForwardIterator __f,
11264684ddb6SLionel Sambuc                                          _ForwardIterator __l, wchar_t) const
11274684ddb6SLionel Sambuc{
11284684ddb6SLionel Sambuc    const string_type __s(__f, __l);
11294684ddb6SLionel Sambuc    string_type __d = __col_->transform(__s.data(), __s.data() + __s.size());
11304684ddb6SLionel Sambuc    switch (__d.size())
11314684ddb6SLionel Sambuc    {
11324684ddb6SLionel Sambuc    case 1:
11334684ddb6SLionel Sambuc        break;
11344684ddb6SLionel Sambuc    case 3:
11354684ddb6SLionel Sambuc        __d[2] = __d[0];
11364684ddb6SLionel Sambuc        break;
11374684ddb6SLionel Sambuc    default:
11384684ddb6SLionel Sambuc        __d.clear();
11394684ddb6SLionel Sambuc        break;
11404684ddb6SLionel Sambuc    }
11414684ddb6SLionel Sambuc    return __d;
11424684ddb6SLionel Sambuc}
11434684ddb6SLionel Sambuc
11444684ddb6SLionel Sambuc// lookup_collatename is very FreeBSD-specific
11454684ddb6SLionel Sambuc
11464684ddb6SLionel Sambuc_LIBCPP_FUNC_VIS string __get_collation_name(const char* __s);
11474684ddb6SLionel Sambuc
11484684ddb6SLionel Sambuctemplate <class _CharT>
11494684ddb6SLionel Sambuctemplate <class _ForwardIterator>
11504684ddb6SLionel Sambuctypename regex_traits<_CharT>::string_type
11514684ddb6SLionel Sambucregex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f,
11524684ddb6SLionel Sambuc                                           _ForwardIterator __l, char) const
11534684ddb6SLionel Sambuc{
11544684ddb6SLionel Sambuc    string_type __s(__f, __l);
11554684ddb6SLionel Sambuc    string_type __r;
11564684ddb6SLionel Sambuc    if (!__s.empty())
11574684ddb6SLionel Sambuc    {
11584684ddb6SLionel Sambuc        __r = __get_collation_name(__s.c_str());
11594684ddb6SLionel Sambuc        if (__r.empty() && __s.size() <= 2)
11604684ddb6SLionel Sambuc        {
11614684ddb6SLionel Sambuc            __r = __col_->transform(__s.data(), __s.data() + __s.size());
11624684ddb6SLionel Sambuc            if (__r.size() == 1 || __r.size() == 12)
11634684ddb6SLionel Sambuc                __r = __s;
11644684ddb6SLionel Sambuc            else
11654684ddb6SLionel Sambuc                __r.clear();
11664684ddb6SLionel Sambuc        }
11674684ddb6SLionel Sambuc    }
11684684ddb6SLionel Sambuc    return __r;
11694684ddb6SLionel Sambuc}
11704684ddb6SLionel Sambuc
11714684ddb6SLionel Sambuctemplate <class _CharT>
11724684ddb6SLionel Sambuctemplate <class _ForwardIterator>
11734684ddb6SLionel Sambuctypename regex_traits<_CharT>::string_type
11744684ddb6SLionel Sambucregex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f,
11754684ddb6SLionel Sambuc                                           _ForwardIterator __l, wchar_t) const
11764684ddb6SLionel Sambuc{
11774684ddb6SLionel Sambuc    string_type __s(__f, __l);
11784684ddb6SLionel Sambuc    string __n;
11794684ddb6SLionel Sambuc    __n.reserve(__s.size());
11804684ddb6SLionel Sambuc    for (typename string_type::const_iterator __i = __s.begin(), __e = __s.end();
11814684ddb6SLionel Sambuc                                                              __i != __e; ++__i)
11824684ddb6SLionel Sambuc    {
11834684ddb6SLionel Sambuc        if (static_cast<unsigned>(*__i) >= 127)
11844684ddb6SLionel Sambuc            return string_type();
11854684ddb6SLionel Sambuc        __n.push_back(char(*__i));
11864684ddb6SLionel Sambuc    }
11874684ddb6SLionel Sambuc    string_type __r;
11884684ddb6SLionel Sambuc    if (!__s.empty())
11894684ddb6SLionel Sambuc    {
11904684ddb6SLionel Sambuc        __n = __get_collation_name(__n.c_str());
11914684ddb6SLionel Sambuc        if (!__n.empty())
11924684ddb6SLionel Sambuc            __r.assign(__n.begin(), __n.end());
11934684ddb6SLionel Sambuc        else if (__s.size() <= 2)
11944684ddb6SLionel Sambuc        {
11954684ddb6SLionel Sambuc            __r = __col_->transform(__s.data(), __s.data() + __s.size());
11964684ddb6SLionel Sambuc            if (__r.size() == 1 || __r.size() == 3)
11974684ddb6SLionel Sambuc                __r = __s;
11984684ddb6SLionel Sambuc            else
11994684ddb6SLionel Sambuc                __r.clear();
12004684ddb6SLionel Sambuc        }
12014684ddb6SLionel Sambuc    }
12024684ddb6SLionel Sambuc    return __r;
12034684ddb6SLionel Sambuc}
12044684ddb6SLionel Sambuc
12054684ddb6SLionel Sambuc// lookup_classname
12064684ddb6SLionel Sambuc
1207*0a6a1f1dSLionel Sambucregex_traits<char>::char_class_type _LIBCPP_FUNC_VIS
1208*0a6a1f1dSLionel Sambuc__get_classname(const char* __s, bool __icase);
12094684ddb6SLionel Sambuc
12104684ddb6SLionel Sambuctemplate <class _CharT>
12114684ddb6SLionel Sambuctemplate <class _ForwardIterator>
12124684ddb6SLionel Sambuctypename regex_traits<_CharT>::char_class_type
12134684ddb6SLionel Sambucregex_traits<_CharT>::__lookup_classname(_ForwardIterator __f,
12144684ddb6SLionel Sambuc                                         _ForwardIterator __l,
12154684ddb6SLionel Sambuc                                         bool __icase, char) const
12164684ddb6SLionel Sambuc{
12174684ddb6SLionel Sambuc    string_type __s(__f, __l);
12184684ddb6SLionel Sambuc    __ct_->tolower(&__s[0], &__s[0] + __s.size());
12194684ddb6SLionel Sambuc    return __get_classname(__s.c_str(), __icase);
12204684ddb6SLionel Sambuc}
12214684ddb6SLionel Sambuc
12224684ddb6SLionel Sambuctemplate <class _CharT>
12234684ddb6SLionel Sambuctemplate <class _ForwardIterator>
12244684ddb6SLionel Sambuctypename regex_traits<_CharT>::char_class_type
12254684ddb6SLionel Sambucregex_traits<_CharT>::__lookup_classname(_ForwardIterator __f,
12264684ddb6SLionel Sambuc                                         _ForwardIterator __l,
12274684ddb6SLionel Sambuc                                         bool __icase, wchar_t) const
12284684ddb6SLionel Sambuc{
12294684ddb6SLionel Sambuc    string_type __s(__f, __l);
12304684ddb6SLionel Sambuc    __ct_->tolower(&__s[0], &__s[0] + __s.size());
12314684ddb6SLionel Sambuc    string __n;
12324684ddb6SLionel Sambuc    __n.reserve(__s.size());
12334684ddb6SLionel Sambuc    for (typename string_type::const_iterator __i = __s.begin(), __e = __s.end();
12344684ddb6SLionel Sambuc                                                              __i != __e; ++__i)
12354684ddb6SLionel Sambuc    {
12364684ddb6SLionel Sambuc        if (static_cast<unsigned>(*__i) >= 127)
12374684ddb6SLionel Sambuc            return char_class_type();
12384684ddb6SLionel Sambuc        __n.push_back(char(*__i));
12394684ddb6SLionel Sambuc    }
12404684ddb6SLionel Sambuc    return __get_classname(__n.c_str(), __icase);
12414684ddb6SLionel Sambuc}
12424684ddb6SLionel Sambuc
12434684ddb6SLionel Sambuctemplate <class _CharT>
12444684ddb6SLionel Sambucbool
12454684ddb6SLionel Sambucregex_traits<_CharT>::isctype(char_type __c, char_class_type __m) const
12464684ddb6SLionel Sambuc{
12474684ddb6SLionel Sambuc    if (__ct_->is(__m, __c))
12484684ddb6SLionel Sambuc        return true;
12494684ddb6SLionel Sambuc    return (__c == '_' && (__m & __regex_word));
12504684ddb6SLionel Sambuc}
12514684ddb6SLionel Sambuc
12524684ddb6SLionel Sambuctemplate <class _CharT>
12534684ddb6SLionel Sambucint
12544684ddb6SLionel Sambucregex_traits<_CharT>::__regex_traits_value(unsigned char __ch, int __radix)
12554684ddb6SLionel Sambuc{
12564684ddb6SLionel Sambuc    if ((__ch & 0xF8u) == 0x30)  // '0' <= __ch && __ch <= '7'
12574684ddb6SLionel Sambuc        return __ch - '0';
12584684ddb6SLionel Sambuc    if (__radix != 8)
12594684ddb6SLionel Sambuc    {
12604684ddb6SLionel Sambuc        if ((__ch & 0xFEu) == 0x38)  // '8' <= __ch && __ch <= '9'
12614684ddb6SLionel Sambuc            return __ch - '0';
12624684ddb6SLionel Sambuc        if (__radix == 16)
12634684ddb6SLionel Sambuc        {
12644684ddb6SLionel Sambuc            __ch |= 0x20;  // tolower
12654684ddb6SLionel Sambuc            if ('a' <= __ch && __ch <= 'f')
12664684ddb6SLionel Sambuc                return __ch - ('a' - 10);
12674684ddb6SLionel Sambuc        }
12684684ddb6SLionel Sambuc    }
12694684ddb6SLionel Sambuc    return -1;
12704684ddb6SLionel Sambuc}
12714684ddb6SLionel Sambuc
12724684ddb6SLionel Sambuctemplate <class _CharT>
12734684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
12744684ddb6SLionel Sambucint
12754684ddb6SLionel Sambucregex_traits<_CharT>::__regex_traits_value(wchar_t __ch, int __radix) const
12764684ddb6SLionel Sambuc{
12774684ddb6SLionel Sambuc    return __regex_traits_value(static_cast<unsigned char>(__ct_->narrow(__ch, char_type())), __radix);
12784684ddb6SLionel Sambuc}
12794684ddb6SLionel Sambuc
12804684ddb6SLionel Sambuctemplate <class _CharT> class __node;
12814684ddb6SLionel Sambuc
12824684ddb6SLionel Sambuctemplate <class _BidirectionalIterator> class _LIBCPP_TYPE_VIS_ONLY sub_match;
12834684ddb6SLionel Sambuc
12844684ddb6SLionel Sambuctemplate <class _BidirectionalIterator,
12854684ddb6SLionel Sambuc          class _Allocator = allocator<sub_match<_BidirectionalIterator> > >
12864684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS_ONLY match_results;
12874684ddb6SLionel Sambuc
12884684ddb6SLionel Sambuctemplate <class _CharT>
12894684ddb6SLionel Sambucstruct __state
12904684ddb6SLionel Sambuc{
12914684ddb6SLionel Sambuc    enum
12924684ddb6SLionel Sambuc    {
12934684ddb6SLionel Sambuc        __end_state = -1000,
12944684ddb6SLionel Sambuc        __consume_input,  // -999
12954684ddb6SLionel Sambuc        __begin_marked_expr, // -998
12964684ddb6SLionel Sambuc        __end_marked_expr,   // -997
12974684ddb6SLionel Sambuc        __pop_state,           // -996
12984684ddb6SLionel Sambuc        __accept_and_consume,  // -995
12994684ddb6SLionel Sambuc        __accept_but_not_consume,  // -994
13004684ddb6SLionel Sambuc        __reject,                  // -993
13014684ddb6SLionel Sambuc        __split,
13024684ddb6SLionel Sambuc        __repeat
13034684ddb6SLionel Sambuc    };
13044684ddb6SLionel Sambuc
13054684ddb6SLionel Sambuc    int __do_;
13064684ddb6SLionel Sambuc    const _CharT* __first_;
13074684ddb6SLionel Sambuc    const _CharT* __current_;
13084684ddb6SLionel Sambuc    const _CharT* __last_;
13094684ddb6SLionel Sambuc    vector<sub_match<const _CharT*> > __sub_matches_;
13104684ddb6SLionel Sambuc    vector<pair<size_t, const _CharT*> > __loop_data_;
13114684ddb6SLionel Sambuc    const __node<_CharT>* __node_;
13124684ddb6SLionel Sambuc    regex_constants::match_flag_type __flags_;
13134684ddb6SLionel Sambuc    bool __at_first_;
13144684ddb6SLionel Sambuc
13154684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
13164684ddb6SLionel Sambuc    __state()
13174684ddb6SLionel Sambuc        : __do_(0), __first_(nullptr), __current_(nullptr), __last_(nullptr),
13184684ddb6SLionel Sambuc          __node_(nullptr), __flags_() {}
13194684ddb6SLionel Sambuc};
13204684ddb6SLionel Sambuc
13214684ddb6SLionel Sambuc// __node
13224684ddb6SLionel Sambuc
13234684ddb6SLionel Sambuctemplate <class _CharT>
13244684ddb6SLionel Sambucclass __node
13254684ddb6SLionel Sambuc{
13264684ddb6SLionel Sambuc    __node(const __node&);
13274684ddb6SLionel Sambuc    __node& operator=(const __node&);
13284684ddb6SLionel Sambucpublic:
13294684ddb6SLionel Sambuc    typedef _VSTD::__state<_CharT> __state;
13304684ddb6SLionel Sambuc
13314684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
13324684ddb6SLionel Sambuc    __node() {}
13334684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
13344684ddb6SLionel Sambuc    virtual ~__node() {}
13354684ddb6SLionel Sambuc
13364684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
13374684ddb6SLionel Sambuc    virtual void __exec(__state&) const {};
13384684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
13394684ddb6SLionel Sambuc    virtual void __exec_split(bool, __state&) const {};
13404684ddb6SLionel Sambuc};
13414684ddb6SLionel Sambuc
13424684ddb6SLionel Sambuc// __end_state
13434684ddb6SLionel Sambuc
13444684ddb6SLionel Sambuctemplate <class _CharT>
13454684ddb6SLionel Sambucclass __end_state
13464684ddb6SLionel Sambuc    : public __node<_CharT>
13474684ddb6SLionel Sambuc{
13484684ddb6SLionel Sambucpublic:
13494684ddb6SLionel Sambuc    typedef _VSTD::__state<_CharT> __state;
13504684ddb6SLionel Sambuc
13514684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
13524684ddb6SLionel Sambuc    __end_state() {}
13534684ddb6SLionel Sambuc
13544684ddb6SLionel Sambuc    virtual void __exec(__state&) const;
13554684ddb6SLionel Sambuc};
13564684ddb6SLionel Sambuc
13574684ddb6SLionel Sambuctemplate <class _CharT>
13584684ddb6SLionel Sambucvoid
13594684ddb6SLionel Sambuc__end_state<_CharT>::__exec(__state& __s) const
13604684ddb6SLionel Sambuc{
13614684ddb6SLionel Sambuc    __s.__do_ = __state::__end_state;
13624684ddb6SLionel Sambuc}
13634684ddb6SLionel Sambuc
13644684ddb6SLionel Sambuc// __has_one_state
13654684ddb6SLionel Sambuc
13664684ddb6SLionel Sambuctemplate <class _CharT>
13674684ddb6SLionel Sambucclass __has_one_state
13684684ddb6SLionel Sambuc    : public __node<_CharT>
13694684ddb6SLionel Sambuc{
13704684ddb6SLionel Sambuc    __node<_CharT>* __first_;
13714684ddb6SLionel Sambuc
13724684ddb6SLionel Sambucpublic:
13734684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
13744684ddb6SLionel Sambuc    explicit __has_one_state(__node<_CharT>* __s)
13754684ddb6SLionel Sambuc        : __first_(__s) {}
13764684ddb6SLionel Sambuc
13774684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
13784684ddb6SLionel Sambuc    __node<_CharT>*  first() const {return __first_;}
13794684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
13804684ddb6SLionel Sambuc    __node<_CharT>*& first()       {return __first_;}
13814684ddb6SLionel Sambuc};
13824684ddb6SLionel Sambuc
13834684ddb6SLionel Sambuc// __owns_one_state
13844684ddb6SLionel Sambuc
13854684ddb6SLionel Sambuctemplate <class _CharT>
13864684ddb6SLionel Sambucclass __owns_one_state
13874684ddb6SLionel Sambuc    : public __has_one_state<_CharT>
13884684ddb6SLionel Sambuc{
13894684ddb6SLionel Sambuc    typedef __has_one_state<_CharT> base;
13904684ddb6SLionel Sambuc
13914684ddb6SLionel Sambucpublic:
13924684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
13934684ddb6SLionel Sambuc    explicit __owns_one_state(__node<_CharT>* __s)
13944684ddb6SLionel Sambuc        : base(__s) {}
13954684ddb6SLionel Sambuc
13964684ddb6SLionel Sambuc    virtual ~__owns_one_state();
13974684ddb6SLionel Sambuc};
13984684ddb6SLionel Sambuc
13994684ddb6SLionel Sambuctemplate <class _CharT>
14004684ddb6SLionel Sambuc__owns_one_state<_CharT>::~__owns_one_state()
14014684ddb6SLionel Sambuc{
14024684ddb6SLionel Sambuc    delete this->first();
14034684ddb6SLionel Sambuc}
14044684ddb6SLionel Sambuc
14054684ddb6SLionel Sambuc// __empty_state
14064684ddb6SLionel Sambuc
14074684ddb6SLionel Sambuctemplate <class _CharT>
14084684ddb6SLionel Sambucclass __empty_state
14094684ddb6SLionel Sambuc    : public __owns_one_state<_CharT>
14104684ddb6SLionel Sambuc{
14114684ddb6SLionel Sambuc    typedef __owns_one_state<_CharT> base;
14124684ddb6SLionel Sambuc
14134684ddb6SLionel Sambucpublic:
14144684ddb6SLionel Sambuc    typedef _VSTD::__state<_CharT> __state;
14154684ddb6SLionel Sambuc
14164684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
14174684ddb6SLionel Sambuc    explicit __empty_state(__node<_CharT>* __s)
14184684ddb6SLionel Sambuc        : base(__s) {}
14194684ddb6SLionel Sambuc
14204684ddb6SLionel Sambuc    virtual void __exec(__state&) const;
14214684ddb6SLionel Sambuc};
14224684ddb6SLionel Sambuc
14234684ddb6SLionel Sambuctemplate <class _CharT>
14244684ddb6SLionel Sambucvoid
14254684ddb6SLionel Sambuc__empty_state<_CharT>::__exec(__state& __s) const
14264684ddb6SLionel Sambuc{
14274684ddb6SLionel Sambuc    __s.__do_ = __state::__accept_but_not_consume;
14284684ddb6SLionel Sambuc    __s.__node_ = this->first();
14294684ddb6SLionel Sambuc}
14304684ddb6SLionel Sambuc
14314684ddb6SLionel Sambuc// __empty_non_own_state
14324684ddb6SLionel Sambuc
14334684ddb6SLionel Sambuctemplate <class _CharT>
14344684ddb6SLionel Sambucclass __empty_non_own_state
14354684ddb6SLionel Sambuc    : public __has_one_state<_CharT>
14364684ddb6SLionel Sambuc{
14374684ddb6SLionel Sambuc    typedef __has_one_state<_CharT> base;
14384684ddb6SLionel Sambuc
14394684ddb6SLionel Sambucpublic:
14404684ddb6SLionel Sambuc    typedef _VSTD::__state<_CharT> __state;
14414684ddb6SLionel Sambuc
14424684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
14434684ddb6SLionel Sambuc    explicit __empty_non_own_state(__node<_CharT>* __s)
14444684ddb6SLionel Sambuc        : base(__s) {}
14454684ddb6SLionel Sambuc
14464684ddb6SLionel Sambuc    virtual void __exec(__state&) const;
14474684ddb6SLionel Sambuc};
14484684ddb6SLionel Sambuc
14494684ddb6SLionel Sambuctemplate <class _CharT>
14504684ddb6SLionel Sambucvoid
14514684ddb6SLionel Sambuc__empty_non_own_state<_CharT>::__exec(__state& __s) const
14524684ddb6SLionel Sambuc{
14534684ddb6SLionel Sambuc    __s.__do_ = __state::__accept_but_not_consume;
14544684ddb6SLionel Sambuc    __s.__node_ = this->first();
14554684ddb6SLionel Sambuc}
14564684ddb6SLionel Sambuc
14574684ddb6SLionel Sambuc// __repeat_one_loop
14584684ddb6SLionel Sambuc
14594684ddb6SLionel Sambuctemplate <class _CharT>
14604684ddb6SLionel Sambucclass __repeat_one_loop
14614684ddb6SLionel Sambuc    : public __has_one_state<_CharT>
14624684ddb6SLionel Sambuc{
14634684ddb6SLionel Sambuc    typedef __has_one_state<_CharT> base;
14644684ddb6SLionel Sambuc
14654684ddb6SLionel Sambucpublic:
14664684ddb6SLionel Sambuc    typedef _VSTD::__state<_CharT> __state;
14674684ddb6SLionel Sambuc
14684684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
14694684ddb6SLionel Sambuc    explicit __repeat_one_loop(__node<_CharT>* __s)
14704684ddb6SLionel Sambuc        : base(__s) {}
14714684ddb6SLionel Sambuc
14724684ddb6SLionel Sambuc    virtual void __exec(__state&) const;
14734684ddb6SLionel Sambuc};
14744684ddb6SLionel Sambuc
14754684ddb6SLionel Sambuctemplate <class _CharT>
14764684ddb6SLionel Sambucvoid
14774684ddb6SLionel Sambuc__repeat_one_loop<_CharT>::__exec(__state& __s) const
14784684ddb6SLionel Sambuc{
14794684ddb6SLionel Sambuc    __s.__do_ = __state::__repeat;
14804684ddb6SLionel Sambuc    __s.__node_ = this->first();
14814684ddb6SLionel Sambuc}
14824684ddb6SLionel Sambuc
14834684ddb6SLionel Sambuc// __owns_two_states
14844684ddb6SLionel Sambuc
14854684ddb6SLionel Sambuctemplate <class _CharT>
14864684ddb6SLionel Sambucclass __owns_two_states
14874684ddb6SLionel Sambuc    : public __owns_one_state<_CharT>
14884684ddb6SLionel Sambuc{
14894684ddb6SLionel Sambuc    typedef __owns_one_state<_CharT> base;
14904684ddb6SLionel Sambuc
14914684ddb6SLionel Sambuc    base* __second_;
14924684ddb6SLionel Sambuc
14934684ddb6SLionel Sambucpublic:
14944684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
14954684ddb6SLionel Sambuc    explicit __owns_two_states(__node<_CharT>* __s1, base* __s2)
14964684ddb6SLionel Sambuc        : base(__s1), __second_(__s2) {}
14974684ddb6SLionel Sambuc
14984684ddb6SLionel Sambuc    virtual ~__owns_two_states();
14994684ddb6SLionel Sambuc
15004684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
15014684ddb6SLionel Sambuc    base*  second() const {return __second_;}
15024684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
15034684ddb6SLionel Sambuc    base*& second()       {return __second_;}
15044684ddb6SLionel Sambuc};
15054684ddb6SLionel Sambuc
15064684ddb6SLionel Sambuctemplate <class _CharT>
15074684ddb6SLionel Sambuc__owns_two_states<_CharT>::~__owns_two_states()
15084684ddb6SLionel Sambuc{
15094684ddb6SLionel Sambuc    delete __second_;
15104684ddb6SLionel Sambuc}
15114684ddb6SLionel Sambuc
15124684ddb6SLionel Sambuc// __loop
15134684ddb6SLionel Sambuc
15144684ddb6SLionel Sambuctemplate <class _CharT>
15154684ddb6SLionel Sambucclass __loop
15164684ddb6SLionel Sambuc    : public __owns_two_states<_CharT>
15174684ddb6SLionel Sambuc{
15184684ddb6SLionel Sambuc    typedef __owns_two_states<_CharT> base;
15194684ddb6SLionel Sambuc
15204684ddb6SLionel Sambuc    size_t __min_;
15214684ddb6SLionel Sambuc    size_t __max_;
15224684ddb6SLionel Sambuc    unsigned __loop_id_;
15234684ddb6SLionel Sambuc    unsigned __mexp_begin_;
15244684ddb6SLionel Sambuc    unsigned __mexp_end_;
15254684ddb6SLionel Sambuc    bool __greedy_;
15264684ddb6SLionel Sambuc
15274684ddb6SLionel Sambucpublic:
15284684ddb6SLionel Sambuc    typedef _VSTD::__state<_CharT> __state;
15294684ddb6SLionel Sambuc
15304684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
15314684ddb6SLionel Sambuc    explicit __loop(unsigned __loop_id,
15324684ddb6SLionel Sambuc                          __node<_CharT>* __s1, __owns_one_state<_CharT>* __s2,
15334684ddb6SLionel Sambuc                          unsigned __mexp_begin, unsigned __mexp_end,
15344684ddb6SLionel Sambuc                          bool __greedy = true,
15354684ddb6SLionel Sambuc                          size_t __min = 0,
15364684ddb6SLionel Sambuc                          size_t __max = numeric_limits<size_t>::max())
15374684ddb6SLionel Sambuc        : base(__s1, __s2), __min_(__min), __max_(__max), __loop_id_(__loop_id),
15384684ddb6SLionel Sambuc          __mexp_begin_(__mexp_begin), __mexp_end_(__mexp_end),
15394684ddb6SLionel Sambuc          __greedy_(__greedy) {}
15404684ddb6SLionel Sambuc
15414684ddb6SLionel Sambuc    virtual void __exec(__state& __s) const;
15424684ddb6SLionel Sambuc    virtual void __exec_split(bool __second, __state& __s) const;
15434684ddb6SLionel Sambuc
15444684ddb6SLionel Sambucprivate:
15454684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
15464684ddb6SLionel Sambuc    void __init_repeat(__state& __s) const
15474684ddb6SLionel Sambuc    {
15484684ddb6SLionel Sambuc        __s.__loop_data_[__loop_id_].second = __s.__current_;
15494684ddb6SLionel Sambuc        for (size_t __i = __mexp_begin_-1; __i != __mexp_end_-1; ++__i)
15504684ddb6SLionel Sambuc        {
15514684ddb6SLionel Sambuc            __s.__sub_matches_[__i].first = __s.__last_;
15524684ddb6SLionel Sambuc            __s.__sub_matches_[__i].second = __s.__last_;
15534684ddb6SLionel Sambuc            __s.__sub_matches_[__i].matched = false;
15544684ddb6SLionel Sambuc        }
15554684ddb6SLionel Sambuc    }
15564684ddb6SLionel Sambuc};
15574684ddb6SLionel Sambuc
15584684ddb6SLionel Sambuctemplate <class _CharT>
15594684ddb6SLionel Sambucvoid
15604684ddb6SLionel Sambuc__loop<_CharT>::__exec(__state& __s) const
15614684ddb6SLionel Sambuc{
15624684ddb6SLionel Sambuc    if (__s.__do_ == __state::__repeat)
15634684ddb6SLionel Sambuc    {
15644684ddb6SLionel Sambuc        bool __do_repeat = ++__s.__loop_data_[__loop_id_].first < __max_;
15654684ddb6SLionel Sambuc        bool __do_alt = __s.__loop_data_[__loop_id_].first >= __min_;
15664684ddb6SLionel Sambuc        if (__do_repeat && __do_alt &&
15674684ddb6SLionel Sambuc                               __s.__loop_data_[__loop_id_].second == __s.__current_)
15684684ddb6SLionel Sambuc            __do_repeat = false;
15694684ddb6SLionel Sambuc        if (__do_repeat && __do_alt)
15704684ddb6SLionel Sambuc            __s.__do_ = __state::__split;
15714684ddb6SLionel Sambuc        else if (__do_repeat)
15724684ddb6SLionel Sambuc        {
15734684ddb6SLionel Sambuc            __s.__do_ = __state::__accept_but_not_consume;
15744684ddb6SLionel Sambuc            __s.__node_ = this->first();
15754684ddb6SLionel Sambuc            __init_repeat(__s);
15764684ddb6SLionel Sambuc        }
15774684ddb6SLionel Sambuc        else
15784684ddb6SLionel Sambuc        {
15794684ddb6SLionel Sambuc            __s.__do_ = __state::__accept_but_not_consume;
15804684ddb6SLionel Sambuc            __s.__node_ = this->second();
15814684ddb6SLionel Sambuc        }
15824684ddb6SLionel Sambuc    }
15834684ddb6SLionel Sambuc    else
15844684ddb6SLionel Sambuc    {
15854684ddb6SLionel Sambuc        __s.__loop_data_[__loop_id_].first = 0;
15864684ddb6SLionel Sambuc        bool __do_repeat = 0 < __max_;
15874684ddb6SLionel Sambuc        bool __do_alt = 0 >= __min_;
15884684ddb6SLionel Sambuc        if (__do_repeat && __do_alt)
15894684ddb6SLionel Sambuc            __s.__do_ = __state::__split;
15904684ddb6SLionel Sambuc        else if (__do_repeat)
15914684ddb6SLionel Sambuc        {
15924684ddb6SLionel Sambuc            __s.__do_ = __state::__accept_but_not_consume;
15934684ddb6SLionel Sambuc            __s.__node_ = this->first();
15944684ddb6SLionel Sambuc            __init_repeat(__s);
15954684ddb6SLionel Sambuc        }
15964684ddb6SLionel Sambuc        else
15974684ddb6SLionel Sambuc        {
15984684ddb6SLionel Sambuc            __s.__do_ = __state::__accept_but_not_consume;
15994684ddb6SLionel Sambuc            __s.__node_ = this->second();
16004684ddb6SLionel Sambuc        }
16014684ddb6SLionel Sambuc    }
16024684ddb6SLionel Sambuc}
16034684ddb6SLionel Sambuc
16044684ddb6SLionel Sambuctemplate <class _CharT>
16054684ddb6SLionel Sambucvoid
16064684ddb6SLionel Sambuc__loop<_CharT>::__exec_split(bool __second, __state& __s) const
16074684ddb6SLionel Sambuc{
16084684ddb6SLionel Sambuc    __s.__do_ = __state::__accept_but_not_consume;
16094684ddb6SLionel Sambuc    if (__greedy_ != __second)
16104684ddb6SLionel Sambuc    {
16114684ddb6SLionel Sambuc        __s.__node_ = this->first();
16124684ddb6SLionel Sambuc        __init_repeat(__s);
16134684ddb6SLionel Sambuc    }
16144684ddb6SLionel Sambuc    else
16154684ddb6SLionel Sambuc        __s.__node_ = this->second();
16164684ddb6SLionel Sambuc}
16174684ddb6SLionel Sambuc
16184684ddb6SLionel Sambuc// __alternate
16194684ddb6SLionel Sambuc
16204684ddb6SLionel Sambuctemplate <class _CharT>
16214684ddb6SLionel Sambucclass __alternate
16224684ddb6SLionel Sambuc    : public __owns_two_states<_CharT>
16234684ddb6SLionel Sambuc{
16244684ddb6SLionel Sambuc    typedef __owns_two_states<_CharT> base;
16254684ddb6SLionel Sambuc
16264684ddb6SLionel Sambucpublic:
16274684ddb6SLionel Sambuc    typedef _VSTD::__state<_CharT> __state;
16284684ddb6SLionel Sambuc
16294684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
16304684ddb6SLionel Sambuc    explicit __alternate(__owns_one_state<_CharT>* __s1,
16314684ddb6SLionel Sambuc                         __owns_one_state<_CharT>* __s2)
16324684ddb6SLionel Sambuc        : base(__s1, __s2) {}
16334684ddb6SLionel Sambuc
16344684ddb6SLionel Sambuc    virtual void __exec(__state& __s) const;
16354684ddb6SLionel Sambuc    virtual void __exec_split(bool __second, __state& __s) const;
16364684ddb6SLionel Sambuc};
16374684ddb6SLionel Sambuc
16384684ddb6SLionel Sambuctemplate <class _CharT>
16394684ddb6SLionel Sambucvoid
16404684ddb6SLionel Sambuc__alternate<_CharT>::__exec(__state& __s) const
16414684ddb6SLionel Sambuc{
16424684ddb6SLionel Sambuc    __s.__do_ = __state::__split;
16434684ddb6SLionel Sambuc}
16444684ddb6SLionel Sambuc
16454684ddb6SLionel Sambuctemplate <class _CharT>
16464684ddb6SLionel Sambucvoid
16474684ddb6SLionel Sambuc__alternate<_CharT>::__exec_split(bool __second, __state& __s) const
16484684ddb6SLionel Sambuc{
16494684ddb6SLionel Sambuc    __s.__do_ = __state::__accept_but_not_consume;
16504684ddb6SLionel Sambuc    if (__second)
16514684ddb6SLionel Sambuc        __s.__node_ = this->second();
16524684ddb6SLionel Sambuc    else
16534684ddb6SLionel Sambuc        __s.__node_ = this->first();
16544684ddb6SLionel Sambuc}
16554684ddb6SLionel Sambuc
16564684ddb6SLionel Sambuc// __begin_marked_subexpression
16574684ddb6SLionel Sambuc
16584684ddb6SLionel Sambuctemplate <class _CharT>
16594684ddb6SLionel Sambucclass __begin_marked_subexpression
16604684ddb6SLionel Sambuc    : public __owns_one_state<_CharT>
16614684ddb6SLionel Sambuc{
16624684ddb6SLionel Sambuc    typedef __owns_one_state<_CharT> base;
16634684ddb6SLionel Sambuc
16644684ddb6SLionel Sambuc    unsigned __mexp_;
16654684ddb6SLionel Sambucpublic:
16664684ddb6SLionel Sambuc    typedef _VSTD::__state<_CharT> __state;
16674684ddb6SLionel Sambuc
16684684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
16694684ddb6SLionel Sambuc    explicit __begin_marked_subexpression(unsigned __mexp, __node<_CharT>* __s)
16704684ddb6SLionel Sambuc        : base(__s), __mexp_(__mexp) {}
16714684ddb6SLionel Sambuc
16724684ddb6SLionel Sambuc    virtual void __exec(__state&) const;
16734684ddb6SLionel Sambuc};
16744684ddb6SLionel Sambuc
16754684ddb6SLionel Sambuctemplate <class _CharT>
16764684ddb6SLionel Sambucvoid
16774684ddb6SLionel Sambuc__begin_marked_subexpression<_CharT>::__exec(__state& __s) const
16784684ddb6SLionel Sambuc{
16794684ddb6SLionel Sambuc    __s.__do_ = __state::__accept_but_not_consume;
16804684ddb6SLionel Sambuc    __s.__sub_matches_[__mexp_-1].first = __s.__current_;
16814684ddb6SLionel Sambuc    __s.__node_ = this->first();
16824684ddb6SLionel Sambuc}
16834684ddb6SLionel Sambuc
16844684ddb6SLionel Sambuc// __end_marked_subexpression
16854684ddb6SLionel Sambuc
16864684ddb6SLionel Sambuctemplate <class _CharT>
16874684ddb6SLionel Sambucclass __end_marked_subexpression
16884684ddb6SLionel Sambuc    : public __owns_one_state<_CharT>
16894684ddb6SLionel Sambuc{
16904684ddb6SLionel Sambuc    typedef __owns_one_state<_CharT> base;
16914684ddb6SLionel Sambuc
16924684ddb6SLionel Sambuc    unsigned __mexp_;
16934684ddb6SLionel Sambucpublic:
16944684ddb6SLionel Sambuc    typedef _VSTD::__state<_CharT> __state;
16954684ddb6SLionel Sambuc
16964684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
16974684ddb6SLionel Sambuc    explicit __end_marked_subexpression(unsigned __mexp, __node<_CharT>* __s)
16984684ddb6SLionel Sambuc        : base(__s), __mexp_(__mexp) {}
16994684ddb6SLionel Sambuc
17004684ddb6SLionel Sambuc    virtual void __exec(__state&) const;
17014684ddb6SLionel Sambuc};
17024684ddb6SLionel Sambuc
17034684ddb6SLionel Sambuctemplate <class _CharT>
17044684ddb6SLionel Sambucvoid
17054684ddb6SLionel Sambuc__end_marked_subexpression<_CharT>::__exec(__state& __s) const
17064684ddb6SLionel Sambuc{
17074684ddb6SLionel Sambuc    __s.__do_ = __state::__accept_but_not_consume;
17084684ddb6SLionel Sambuc    __s.__sub_matches_[__mexp_-1].second = __s.__current_;
17094684ddb6SLionel Sambuc    __s.__sub_matches_[__mexp_-1].matched = true;
17104684ddb6SLionel Sambuc    __s.__node_ = this->first();
17114684ddb6SLionel Sambuc}
17124684ddb6SLionel Sambuc
17134684ddb6SLionel Sambuc// __back_ref
17144684ddb6SLionel Sambuc
17154684ddb6SLionel Sambuctemplate <class _CharT>
17164684ddb6SLionel Sambucclass __back_ref
17174684ddb6SLionel Sambuc    : public __owns_one_state<_CharT>
17184684ddb6SLionel Sambuc{
17194684ddb6SLionel Sambuc    typedef __owns_one_state<_CharT> base;
17204684ddb6SLionel Sambuc
17214684ddb6SLionel Sambuc    unsigned __mexp_;
17224684ddb6SLionel Sambucpublic:
17234684ddb6SLionel Sambuc    typedef _VSTD::__state<_CharT> __state;
17244684ddb6SLionel Sambuc
17254684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
17264684ddb6SLionel Sambuc    explicit __back_ref(unsigned __mexp, __node<_CharT>* __s)
17274684ddb6SLionel Sambuc        : base(__s), __mexp_(__mexp) {}
17284684ddb6SLionel Sambuc
17294684ddb6SLionel Sambuc    virtual void __exec(__state&) const;
17304684ddb6SLionel Sambuc};
17314684ddb6SLionel Sambuc
17324684ddb6SLionel Sambuctemplate <class _CharT>
17334684ddb6SLionel Sambucvoid
17344684ddb6SLionel Sambuc__back_ref<_CharT>::__exec(__state& __s) const
17354684ddb6SLionel Sambuc{
17364684ddb6SLionel Sambuc    sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1];
17374684ddb6SLionel Sambuc    if (__sm.matched)
17384684ddb6SLionel Sambuc    {
17394684ddb6SLionel Sambuc        ptrdiff_t __len = __sm.second - __sm.first;
17404684ddb6SLionel Sambuc        if (__s.__last_ - __s.__current_ >= __len &&
17414684ddb6SLionel Sambuc            _VSTD::equal(__sm.first, __sm.second, __s.__current_))
17424684ddb6SLionel Sambuc        {
17434684ddb6SLionel Sambuc            __s.__do_ = __state::__accept_but_not_consume;
17444684ddb6SLionel Sambuc            __s.__current_ += __len;
17454684ddb6SLionel Sambuc            __s.__node_ = this->first();
17464684ddb6SLionel Sambuc        }
17474684ddb6SLionel Sambuc        else
17484684ddb6SLionel Sambuc        {
17494684ddb6SLionel Sambuc            __s.__do_ = __state::__reject;
17504684ddb6SLionel Sambuc            __s.__node_ = nullptr;
17514684ddb6SLionel Sambuc        }
17524684ddb6SLionel Sambuc    }
17534684ddb6SLionel Sambuc    else
17544684ddb6SLionel Sambuc    {
17554684ddb6SLionel Sambuc        __s.__do_ = __state::__reject;
17564684ddb6SLionel Sambuc        __s.__node_ = nullptr;
17574684ddb6SLionel Sambuc    }
17584684ddb6SLionel Sambuc}
17594684ddb6SLionel Sambuc
17604684ddb6SLionel Sambuc// __back_ref_icase
17614684ddb6SLionel Sambuc
17624684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
17634684ddb6SLionel Sambucclass __back_ref_icase
17644684ddb6SLionel Sambuc    : public __owns_one_state<_CharT>
17654684ddb6SLionel Sambuc{
17664684ddb6SLionel Sambuc    typedef __owns_one_state<_CharT> base;
17674684ddb6SLionel Sambuc
17684684ddb6SLionel Sambuc    _Traits __traits_;
17694684ddb6SLionel Sambuc    unsigned __mexp_;
17704684ddb6SLionel Sambucpublic:
17714684ddb6SLionel Sambuc    typedef _VSTD::__state<_CharT> __state;
17724684ddb6SLionel Sambuc
17734684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
17744684ddb6SLionel Sambuc    explicit __back_ref_icase(const _Traits& __traits, unsigned __mexp,
17754684ddb6SLionel Sambuc                              __node<_CharT>* __s)
17764684ddb6SLionel Sambuc        : base(__s), __traits_(__traits), __mexp_(__mexp) {}
17774684ddb6SLionel Sambuc
17784684ddb6SLionel Sambuc    virtual void __exec(__state&) const;
17794684ddb6SLionel Sambuc};
17804684ddb6SLionel Sambuc
17814684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
17824684ddb6SLionel Sambucvoid
17834684ddb6SLionel Sambuc__back_ref_icase<_CharT, _Traits>::__exec(__state& __s) const
17844684ddb6SLionel Sambuc{
17854684ddb6SLionel Sambuc    sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1];
17864684ddb6SLionel Sambuc    if (__sm.matched)
17874684ddb6SLionel Sambuc    {
17884684ddb6SLionel Sambuc        ptrdiff_t __len = __sm.second - __sm.first;
17894684ddb6SLionel Sambuc        if (__s.__last_ - __s.__current_ >= __len)
17904684ddb6SLionel Sambuc        {
17914684ddb6SLionel Sambuc            for (ptrdiff_t __i = 0; __i < __len; ++__i)
17924684ddb6SLionel Sambuc            {
17934684ddb6SLionel Sambuc                if (__traits_.translate_nocase(__sm.first[__i]) !=
17944684ddb6SLionel Sambuc                                __traits_.translate_nocase(__s.__current_[__i]))
17954684ddb6SLionel Sambuc                    goto __not_equal;
17964684ddb6SLionel Sambuc            }
17974684ddb6SLionel Sambuc            __s.__do_ = __state::__accept_but_not_consume;
17984684ddb6SLionel Sambuc            __s.__current_ += __len;
17994684ddb6SLionel Sambuc            __s.__node_ = this->first();
18004684ddb6SLionel Sambuc        }
18014684ddb6SLionel Sambuc        else
18024684ddb6SLionel Sambuc        {
18034684ddb6SLionel Sambuc            __s.__do_ = __state::__reject;
18044684ddb6SLionel Sambuc            __s.__node_ = nullptr;
18054684ddb6SLionel Sambuc        }
18064684ddb6SLionel Sambuc    }
18074684ddb6SLionel Sambuc    else
18084684ddb6SLionel Sambuc    {
18094684ddb6SLionel Sambuc__not_equal:
18104684ddb6SLionel Sambuc        __s.__do_ = __state::__reject;
18114684ddb6SLionel Sambuc        __s.__node_ = nullptr;
18124684ddb6SLionel Sambuc    }
18134684ddb6SLionel Sambuc}
18144684ddb6SLionel Sambuc
18154684ddb6SLionel Sambuc// __back_ref_collate
18164684ddb6SLionel Sambuc
18174684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
18184684ddb6SLionel Sambucclass __back_ref_collate
18194684ddb6SLionel Sambuc    : public __owns_one_state<_CharT>
18204684ddb6SLionel Sambuc{
18214684ddb6SLionel Sambuc    typedef __owns_one_state<_CharT> base;
18224684ddb6SLionel Sambuc
18234684ddb6SLionel Sambuc    _Traits __traits_;
18244684ddb6SLionel Sambuc    unsigned __mexp_;
18254684ddb6SLionel Sambucpublic:
18264684ddb6SLionel Sambuc    typedef _VSTD::__state<_CharT> __state;
18274684ddb6SLionel Sambuc
18284684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
18294684ddb6SLionel Sambuc    explicit __back_ref_collate(const _Traits& __traits, unsigned __mexp,
18304684ddb6SLionel Sambuc                              __node<_CharT>* __s)
18314684ddb6SLionel Sambuc        : base(__s), __traits_(__traits), __mexp_(__mexp) {}
18324684ddb6SLionel Sambuc
18334684ddb6SLionel Sambuc    virtual void __exec(__state&) const;
18344684ddb6SLionel Sambuc};
18354684ddb6SLionel Sambuc
18364684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
18374684ddb6SLionel Sambucvoid
18384684ddb6SLionel Sambuc__back_ref_collate<_CharT, _Traits>::__exec(__state& __s) const
18394684ddb6SLionel Sambuc{
18404684ddb6SLionel Sambuc    sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1];
18414684ddb6SLionel Sambuc    if (__sm.matched)
18424684ddb6SLionel Sambuc    {
18434684ddb6SLionel Sambuc        ptrdiff_t __len = __sm.second - __sm.first;
18444684ddb6SLionel Sambuc        if (__s.__last_ - __s.__current_ >= __len)
18454684ddb6SLionel Sambuc        {
18464684ddb6SLionel Sambuc            for (ptrdiff_t __i = 0; __i < __len; ++__i)
18474684ddb6SLionel Sambuc            {
18484684ddb6SLionel Sambuc                if (__traits_.translate(__sm.first[__i]) !=
18494684ddb6SLionel Sambuc                                       __traits_.translate(__s.__current_[__i]))
18504684ddb6SLionel Sambuc                    goto __not_equal;
18514684ddb6SLionel Sambuc            }
18524684ddb6SLionel Sambuc            __s.__do_ = __state::__accept_but_not_consume;
18534684ddb6SLionel Sambuc            __s.__current_ += __len;
18544684ddb6SLionel Sambuc            __s.__node_ = this->first();
18554684ddb6SLionel Sambuc        }
18564684ddb6SLionel Sambuc        else
18574684ddb6SLionel Sambuc        {
18584684ddb6SLionel Sambuc            __s.__do_ = __state::__reject;
18594684ddb6SLionel Sambuc            __s.__node_ = nullptr;
18604684ddb6SLionel Sambuc        }
18614684ddb6SLionel Sambuc    }
18624684ddb6SLionel Sambuc    else
18634684ddb6SLionel Sambuc    {
18644684ddb6SLionel Sambuc__not_equal:
18654684ddb6SLionel Sambuc        __s.__do_ = __state::__reject;
18664684ddb6SLionel Sambuc        __s.__node_ = nullptr;
18674684ddb6SLionel Sambuc    }
18684684ddb6SLionel Sambuc}
18694684ddb6SLionel Sambuc
18704684ddb6SLionel Sambuc// __word_boundary
18714684ddb6SLionel Sambuc
18724684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
18734684ddb6SLionel Sambucclass __word_boundary
18744684ddb6SLionel Sambuc    : public __owns_one_state<_CharT>
18754684ddb6SLionel Sambuc{
18764684ddb6SLionel Sambuc    typedef __owns_one_state<_CharT> base;
18774684ddb6SLionel Sambuc
18784684ddb6SLionel Sambuc    _Traits __traits_;
18794684ddb6SLionel Sambuc    bool __invert_;
18804684ddb6SLionel Sambucpublic:
18814684ddb6SLionel Sambuc    typedef _VSTD::__state<_CharT> __state;
18824684ddb6SLionel Sambuc
18834684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
18844684ddb6SLionel Sambuc    explicit __word_boundary(const _Traits& __traits, bool __invert,
18854684ddb6SLionel Sambuc                             __node<_CharT>* __s)
18864684ddb6SLionel Sambuc        : base(__s), __traits_(__traits), __invert_(__invert) {}
18874684ddb6SLionel Sambuc
18884684ddb6SLionel Sambuc    virtual void __exec(__state&) const;
18894684ddb6SLionel Sambuc};
18904684ddb6SLionel Sambuc
18914684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
18924684ddb6SLionel Sambucvoid
18934684ddb6SLionel Sambuc__word_boundary<_CharT, _Traits>::__exec(__state& __s) const
18944684ddb6SLionel Sambuc{
18954684ddb6SLionel Sambuc    bool __is_word_b = false;
18964684ddb6SLionel Sambuc    if (__s.__first_ != __s.__last_)
18974684ddb6SLionel Sambuc    {
18984684ddb6SLionel Sambuc        if (__s.__current_ == __s.__last_)
18994684ddb6SLionel Sambuc        {
19004684ddb6SLionel Sambuc            if (!(__s.__flags_ & regex_constants::match_not_eow))
19014684ddb6SLionel Sambuc            {
19024684ddb6SLionel Sambuc                _CharT __c = __s.__current_[-1];
19034684ddb6SLionel Sambuc                __is_word_b = __c == '_' ||
19044684ddb6SLionel Sambuc                              __traits_.isctype(__c, ctype_base::alnum);
19054684ddb6SLionel Sambuc            }
19064684ddb6SLionel Sambuc        }
19074684ddb6SLionel Sambuc        else if (__s.__current_ == __s.__first_ &&
19084684ddb6SLionel Sambuc                !(__s.__flags_ & regex_constants::match_prev_avail))
19094684ddb6SLionel Sambuc        {
19104684ddb6SLionel Sambuc            if (!(__s.__flags_ & regex_constants::match_not_bow))
19114684ddb6SLionel Sambuc            {
19124684ddb6SLionel Sambuc                _CharT __c = *__s.__current_;
19134684ddb6SLionel Sambuc                __is_word_b = __c == '_' ||
19144684ddb6SLionel Sambuc                              __traits_.isctype(__c, ctype_base::alnum);
19154684ddb6SLionel Sambuc            }
19164684ddb6SLionel Sambuc        }
19174684ddb6SLionel Sambuc        else
19184684ddb6SLionel Sambuc        {
19194684ddb6SLionel Sambuc            _CharT __c1 = __s.__current_[-1];
19204684ddb6SLionel Sambuc            _CharT __c2 = *__s.__current_;
19214684ddb6SLionel Sambuc            bool __is_c1_b = __c1 == '_' ||
19224684ddb6SLionel Sambuc                             __traits_.isctype(__c1, ctype_base::alnum);
19234684ddb6SLionel Sambuc            bool __is_c2_b = __c2 == '_' ||
19244684ddb6SLionel Sambuc                             __traits_.isctype(__c2, ctype_base::alnum);
19254684ddb6SLionel Sambuc            __is_word_b = __is_c1_b != __is_c2_b;
19264684ddb6SLionel Sambuc        }
19274684ddb6SLionel Sambuc    }
19284684ddb6SLionel Sambuc    if (__is_word_b != __invert_)
19294684ddb6SLionel Sambuc    {
19304684ddb6SLionel Sambuc        __s.__do_ = __state::__accept_but_not_consume;
19314684ddb6SLionel Sambuc        __s.__node_ = this->first();
19324684ddb6SLionel Sambuc    }
19334684ddb6SLionel Sambuc    else
19344684ddb6SLionel Sambuc    {
19354684ddb6SLionel Sambuc        __s.__do_ = __state::__reject;
19364684ddb6SLionel Sambuc        __s.__node_ = nullptr;
19374684ddb6SLionel Sambuc    }
19384684ddb6SLionel Sambuc}
19394684ddb6SLionel Sambuc
19404684ddb6SLionel Sambuc// __l_anchor
19414684ddb6SLionel Sambuc
19424684ddb6SLionel Sambuctemplate <class _CharT>
19434684ddb6SLionel Sambucclass __l_anchor
19444684ddb6SLionel Sambuc    : public __owns_one_state<_CharT>
19454684ddb6SLionel Sambuc{
19464684ddb6SLionel Sambuc    typedef __owns_one_state<_CharT> base;
19474684ddb6SLionel Sambuc
19484684ddb6SLionel Sambucpublic:
19494684ddb6SLionel Sambuc    typedef _VSTD::__state<_CharT> __state;
19504684ddb6SLionel Sambuc
19514684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
19524684ddb6SLionel Sambuc    __l_anchor(__node<_CharT>* __s)
19534684ddb6SLionel Sambuc        : base(__s) {}
19544684ddb6SLionel Sambuc
19554684ddb6SLionel Sambuc    virtual void __exec(__state&) const;
19564684ddb6SLionel Sambuc};
19574684ddb6SLionel Sambuc
19584684ddb6SLionel Sambuctemplate <class _CharT>
19594684ddb6SLionel Sambucvoid
19604684ddb6SLionel Sambuc__l_anchor<_CharT>::__exec(__state& __s) const
19614684ddb6SLionel Sambuc{
1962*0a6a1f1dSLionel Sambuc    if (__s.__at_first_ && __s.__current_ == __s.__first_ &&
1963*0a6a1f1dSLionel Sambuc        !(__s.__flags_ & regex_constants::match_not_bol))
19644684ddb6SLionel Sambuc    {
19654684ddb6SLionel Sambuc        __s.__do_ = __state::__accept_but_not_consume;
19664684ddb6SLionel Sambuc        __s.__node_ = this->first();
19674684ddb6SLionel Sambuc    }
19684684ddb6SLionel Sambuc    else
19694684ddb6SLionel Sambuc    {
19704684ddb6SLionel Sambuc        __s.__do_ = __state::__reject;
19714684ddb6SLionel Sambuc        __s.__node_ = nullptr;
19724684ddb6SLionel Sambuc    }
19734684ddb6SLionel Sambuc}
19744684ddb6SLionel Sambuc
19754684ddb6SLionel Sambuc// __r_anchor
19764684ddb6SLionel Sambuc
19774684ddb6SLionel Sambuctemplate <class _CharT>
19784684ddb6SLionel Sambucclass __r_anchor
19794684ddb6SLionel Sambuc    : public __owns_one_state<_CharT>
19804684ddb6SLionel Sambuc{
19814684ddb6SLionel Sambuc    typedef __owns_one_state<_CharT> base;
19824684ddb6SLionel Sambuc
19834684ddb6SLionel Sambucpublic:
19844684ddb6SLionel Sambuc    typedef _VSTD::__state<_CharT> __state;
19854684ddb6SLionel Sambuc
19864684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
19874684ddb6SLionel Sambuc    __r_anchor(__node<_CharT>* __s)
19884684ddb6SLionel Sambuc        : base(__s) {}
19894684ddb6SLionel Sambuc
19904684ddb6SLionel Sambuc    virtual void __exec(__state&) const;
19914684ddb6SLionel Sambuc};
19924684ddb6SLionel Sambuc
19934684ddb6SLionel Sambuctemplate <class _CharT>
19944684ddb6SLionel Sambucvoid
19954684ddb6SLionel Sambuc__r_anchor<_CharT>::__exec(__state& __s) const
19964684ddb6SLionel Sambuc{
1997*0a6a1f1dSLionel Sambuc    if (__s.__current_ == __s.__last_ &&
1998*0a6a1f1dSLionel Sambuc        !(__s.__flags_ & regex_constants::match_not_eol))
19994684ddb6SLionel Sambuc    {
20004684ddb6SLionel Sambuc        __s.__do_ = __state::__accept_but_not_consume;
20014684ddb6SLionel Sambuc        __s.__node_ = this->first();
20024684ddb6SLionel Sambuc    }
20034684ddb6SLionel Sambuc    else
20044684ddb6SLionel Sambuc    {
20054684ddb6SLionel Sambuc        __s.__do_ = __state::__reject;
20064684ddb6SLionel Sambuc        __s.__node_ = nullptr;
20074684ddb6SLionel Sambuc    }
20084684ddb6SLionel Sambuc}
20094684ddb6SLionel Sambuc
20104684ddb6SLionel Sambuc// __match_any
20114684ddb6SLionel Sambuc
20124684ddb6SLionel Sambuctemplate <class _CharT>
20134684ddb6SLionel Sambucclass __match_any
20144684ddb6SLionel Sambuc    : public __owns_one_state<_CharT>
20154684ddb6SLionel Sambuc{
20164684ddb6SLionel Sambuc    typedef __owns_one_state<_CharT> base;
20174684ddb6SLionel Sambuc
20184684ddb6SLionel Sambucpublic:
20194684ddb6SLionel Sambuc    typedef _VSTD::__state<_CharT> __state;
20204684ddb6SLionel Sambuc
20214684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
20224684ddb6SLionel Sambuc    __match_any(__node<_CharT>* __s)
20234684ddb6SLionel Sambuc        : base(__s) {}
20244684ddb6SLionel Sambuc
20254684ddb6SLionel Sambuc    virtual void __exec(__state&) const;
20264684ddb6SLionel Sambuc};
20274684ddb6SLionel Sambuc
20284684ddb6SLionel Sambuctemplate <class _CharT>
20294684ddb6SLionel Sambucvoid
20304684ddb6SLionel Sambuc__match_any<_CharT>::__exec(__state& __s) const
20314684ddb6SLionel Sambuc{
20324684ddb6SLionel Sambuc    if (__s.__current_ != __s.__last_ && *__s.__current_ != 0)
20334684ddb6SLionel Sambuc    {
20344684ddb6SLionel Sambuc        __s.__do_ = __state::__accept_and_consume;
20354684ddb6SLionel Sambuc        ++__s.__current_;
20364684ddb6SLionel Sambuc        __s.__node_ = this->first();
20374684ddb6SLionel Sambuc    }
20384684ddb6SLionel Sambuc    else
20394684ddb6SLionel Sambuc    {
20404684ddb6SLionel Sambuc        __s.__do_ = __state::__reject;
20414684ddb6SLionel Sambuc        __s.__node_ = nullptr;
20424684ddb6SLionel Sambuc    }
20434684ddb6SLionel Sambuc}
20444684ddb6SLionel Sambuc
20454684ddb6SLionel Sambuc// __match_any_but_newline
20464684ddb6SLionel Sambuc
20474684ddb6SLionel Sambuctemplate <class _CharT>
20484684ddb6SLionel Sambucclass __match_any_but_newline
20494684ddb6SLionel Sambuc    : public __owns_one_state<_CharT>
20504684ddb6SLionel Sambuc{
20514684ddb6SLionel Sambuc    typedef __owns_one_state<_CharT> base;
20524684ddb6SLionel Sambuc
20534684ddb6SLionel Sambucpublic:
20544684ddb6SLionel Sambuc    typedef _VSTD::__state<_CharT> __state;
20554684ddb6SLionel Sambuc
20564684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
20574684ddb6SLionel Sambuc    __match_any_but_newline(__node<_CharT>* __s)
20584684ddb6SLionel Sambuc        : base(__s) {}
20594684ddb6SLionel Sambuc
20604684ddb6SLionel Sambuc    virtual void __exec(__state&) const;
20614684ddb6SLionel Sambuc};
20624684ddb6SLionel Sambuc
20634684ddb6SLionel Sambuctemplate <> _LIBCPP_FUNC_VIS void __match_any_but_newline<char>::__exec(__state&) const;
20644684ddb6SLionel Sambuctemplate <> _LIBCPP_FUNC_VIS void __match_any_but_newline<wchar_t>::__exec(__state&) const;
20654684ddb6SLionel Sambuc
20664684ddb6SLionel Sambuc// __match_char
20674684ddb6SLionel Sambuc
20684684ddb6SLionel Sambuctemplate <class _CharT>
20694684ddb6SLionel Sambucclass __match_char
20704684ddb6SLionel Sambuc    : public __owns_one_state<_CharT>
20714684ddb6SLionel Sambuc{
20724684ddb6SLionel Sambuc    typedef __owns_one_state<_CharT> base;
20734684ddb6SLionel Sambuc
20744684ddb6SLionel Sambuc    _CharT __c_;
20754684ddb6SLionel Sambuc
20764684ddb6SLionel Sambuc    __match_char(const __match_char&);
20774684ddb6SLionel Sambuc    __match_char& operator=(const __match_char&);
20784684ddb6SLionel Sambucpublic:
20794684ddb6SLionel Sambuc    typedef _VSTD::__state<_CharT> __state;
20804684ddb6SLionel Sambuc
20814684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
20824684ddb6SLionel Sambuc    __match_char(_CharT __c, __node<_CharT>* __s)
20834684ddb6SLionel Sambuc        : base(__s), __c_(__c) {}
20844684ddb6SLionel Sambuc
20854684ddb6SLionel Sambuc    virtual void __exec(__state&) const;
20864684ddb6SLionel Sambuc};
20874684ddb6SLionel Sambuc
20884684ddb6SLionel Sambuctemplate <class _CharT>
20894684ddb6SLionel Sambucvoid
20904684ddb6SLionel Sambuc__match_char<_CharT>::__exec(__state& __s) const
20914684ddb6SLionel Sambuc{
20924684ddb6SLionel Sambuc    if (__s.__current_ != __s.__last_ && *__s.__current_ == __c_)
20934684ddb6SLionel Sambuc    {
20944684ddb6SLionel Sambuc        __s.__do_ = __state::__accept_and_consume;
20954684ddb6SLionel Sambuc        ++__s.__current_;
20964684ddb6SLionel Sambuc        __s.__node_ = this->first();
20974684ddb6SLionel Sambuc    }
20984684ddb6SLionel Sambuc    else
20994684ddb6SLionel Sambuc    {
21004684ddb6SLionel Sambuc        __s.__do_ = __state::__reject;
21014684ddb6SLionel Sambuc        __s.__node_ = nullptr;
21024684ddb6SLionel Sambuc    }
21034684ddb6SLionel Sambuc}
21044684ddb6SLionel Sambuc
21054684ddb6SLionel Sambuc// __match_char_icase
21064684ddb6SLionel Sambuc
21074684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
21084684ddb6SLionel Sambucclass __match_char_icase
21094684ddb6SLionel Sambuc    : public __owns_one_state<_CharT>
21104684ddb6SLionel Sambuc{
21114684ddb6SLionel Sambuc    typedef __owns_one_state<_CharT> base;
21124684ddb6SLionel Sambuc
21134684ddb6SLionel Sambuc    _Traits __traits_;
21144684ddb6SLionel Sambuc    _CharT __c_;
21154684ddb6SLionel Sambuc
21164684ddb6SLionel Sambuc    __match_char_icase(const __match_char_icase&);
21174684ddb6SLionel Sambuc    __match_char_icase& operator=(const __match_char_icase&);
21184684ddb6SLionel Sambucpublic:
21194684ddb6SLionel Sambuc    typedef _VSTD::__state<_CharT> __state;
21204684ddb6SLionel Sambuc
21214684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
21224684ddb6SLionel Sambuc    __match_char_icase(const _Traits& __traits, _CharT __c, __node<_CharT>* __s)
21234684ddb6SLionel Sambuc        : base(__s), __traits_(__traits), __c_(__traits.translate_nocase(__c)) {}
21244684ddb6SLionel Sambuc
21254684ddb6SLionel Sambuc    virtual void __exec(__state&) const;
21264684ddb6SLionel Sambuc};
21274684ddb6SLionel Sambuc
21284684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
21294684ddb6SLionel Sambucvoid
21304684ddb6SLionel Sambuc__match_char_icase<_CharT, _Traits>::__exec(__state& __s) const
21314684ddb6SLionel Sambuc{
21324684ddb6SLionel Sambuc    if (__s.__current_ != __s.__last_ &&
21334684ddb6SLionel Sambuc        __traits_.translate_nocase(*__s.__current_) == __c_)
21344684ddb6SLionel Sambuc    {
21354684ddb6SLionel Sambuc        __s.__do_ = __state::__accept_and_consume;
21364684ddb6SLionel Sambuc        ++__s.__current_;
21374684ddb6SLionel Sambuc        __s.__node_ = this->first();
21384684ddb6SLionel Sambuc    }
21394684ddb6SLionel Sambuc    else
21404684ddb6SLionel Sambuc    {
21414684ddb6SLionel Sambuc        __s.__do_ = __state::__reject;
21424684ddb6SLionel Sambuc        __s.__node_ = nullptr;
21434684ddb6SLionel Sambuc    }
21444684ddb6SLionel Sambuc}
21454684ddb6SLionel Sambuc
21464684ddb6SLionel Sambuc// __match_char_collate
21474684ddb6SLionel Sambuc
21484684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
21494684ddb6SLionel Sambucclass __match_char_collate
21504684ddb6SLionel Sambuc    : public __owns_one_state<_CharT>
21514684ddb6SLionel Sambuc{
21524684ddb6SLionel Sambuc    typedef __owns_one_state<_CharT> base;
21534684ddb6SLionel Sambuc
21544684ddb6SLionel Sambuc    _Traits __traits_;
21554684ddb6SLionel Sambuc    _CharT __c_;
21564684ddb6SLionel Sambuc
21574684ddb6SLionel Sambuc    __match_char_collate(const __match_char_collate&);
21584684ddb6SLionel Sambuc    __match_char_collate& operator=(const __match_char_collate&);
21594684ddb6SLionel Sambucpublic:
21604684ddb6SLionel Sambuc    typedef _VSTD::__state<_CharT> __state;
21614684ddb6SLionel Sambuc
21624684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
21634684ddb6SLionel Sambuc    __match_char_collate(const _Traits& __traits, _CharT __c, __node<_CharT>* __s)
21644684ddb6SLionel Sambuc        : base(__s), __traits_(__traits), __c_(__traits.translate(__c)) {}
21654684ddb6SLionel Sambuc
21664684ddb6SLionel Sambuc    virtual void __exec(__state&) const;
21674684ddb6SLionel Sambuc};
21684684ddb6SLionel Sambuc
21694684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
21704684ddb6SLionel Sambucvoid
21714684ddb6SLionel Sambuc__match_char_collate<_CharT, _Traits>::__exec(__state& __s) const
21724684ddb6SLionel Sambuc{
21734684ddb6SLionel Sambuc    if (__s.__current_ != __s.__last_ &&
21744684ddb6SLionel Sambuc        __traits_.translate(*__s.__current_) == __c_)
21754684ddb6SLionel Sambuc    {
21764684ddb6SLionel Sambuc        __s.__do_ = __state::__accept_and_consume;
21774684ddb6SLionel Sambuc        ++__s.__current_;
21784684ddb6SLionel Sambuc        __s.__node_ = this->first();
21794684ddb6SLionel Sambuc    }
21804684ddb6SLionel Sambuc    else
21814684ddb6SLionel Sambuc    {
21824684ddb6SLionel Sambuc        __s.__do_ = __state::__reject;
21834684ddb6SLionel Sambuc        __s.__node_ = nullptr;
21844684ddb6SLionel Sambuc    }
21854684ddb6SLionel Sambuc}
21864684ddb6SLionel Sambuc
21874684ddb6SLionel Sambuc// __bracket_expression
21884684ddb6SLionel Sambuc
21894684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
21904684ddb6SLionel Sambucclass __bracket_expression
21914684ddb6SLionel Sambuc    : public __owns_one_state<_CharT>
21924684ddb6SLionel Sambuc{
21934684ddb6SLionel Sambuc    typedef __owns_one_state<_CharT> base;
21944684ddb6SLionel Sambuc    typedef typename _Traits::string_type string_type;
21954684ddb6SLionel Sambuc
21964684ddb6SLionel Sambuc    _Traits __traits_;
21974684ddb6SLionel Sambuc    vector<_CharT> __chars_;
21984684ddb6SLionel Sambuc    vector<_CharT> __neg_chars_;
21994684ddb6SLionel Sambuc    vector<pair<string_type, string_type> > __ranges_;
22004684ddb6SLionel Sambuc    vector<pair<_CharT, _CharT> > __digraphs_;
22014684ddb6SLionel Sambuc    vector<string_type> __equivalences_;
2202*0a6a1f1dSLionel Sambuc    typename regex_traits<_CharT>::char_class_type __mask_;
2203*0a6a1f1dSLionel Sambuc    typename regex_traits<_CharT>::char_class_type __neg_mask_;
22044684ddb6SLionel Sambuc    bool __negate_;
22054684ddb6SLionel Sambuc    bool __icase_;
22064684ddb6SLionel Sambuc    bool __collate_;
22074684ddb6SLionel Sambuc    bool __might_have_digraph_;
22084684ddb6SLionel Sambuc
22094684ddb6SLionel Sambuc    __bracket_expression(const __bracket_expression&);
22104684ddb6SLionel Sambuc    __bracket_expression& operator=(const __bracket_expression&);
22114684ddb6SLionel Sambucpublic:
22124684ddb6SLionel Sambuc    typedef _VSTD::__state<_CharT> __state;
22134684ddb6SLionel Sambuc
22144684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
22154684ddb6SLionel Sambuc    __bracket_expression(const _Traits& __traits, __node<_CharT>* __s,
22164684ddb6SLionel Sambuc                                 bool __negate, bool __icase, bool __collate)
22174684ddb6SLionel Sambuc        : base(__s), __traits_(__traits), __mask_(), __neg_mask_(),
22184684ddb6SLionel Sambuc          __negate_(__negate), __icase_(__icase), __collate_(__collate),
22194684ddb6SLionel Sambuc          __might_have_digraph_(__traits_.getloc().name() != "C") {}
22204684ddb6SLionel Sambuc
22214684ddb6SLionel Sambuc    virtual void __exec(__state&) const;
22224684ddb6SLionel Sambuc
22234684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
22244684ddb6SLionel Sambuc    bool __negated() const {return __negate_;}
22254684ddb6SLionel Sambuc
22264684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
22274684ddb6SLionel Sambuc    void __add_char(_CharT __c)
22284684ddb6SLionel Sambuc        {
22294684ddb6SLionel Sambuc            if (__icase_)
22304684ddb6SLionel Sambuc                __chars_.push_back(__traits_.translate_nocase(__c));
22314684ddb6SLionel Sambuc            else if (__collate_)
22324684ddb6SLionel Sambuc                __chars_.push_back(__traits_.translate(__c));
22334684ddb6SLionel Sambuc            else
22344684ddb6SLionel Sambuc                __chars_.push_back(__c);
22354684ddb6SLionel Sambuc        }
22364684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
22374684ddb6SLionel Sambuc    void __add_neg_char(_CharT __c)
22384684ddb6SLionel Sambuc        {
22394684ddb6SLionel Sambuc            if (__icase_)
22404684ddb6SLionel Sambuc                __neg_chars_.push_back(__traits_.translate_nocase(__c));
22414684ddb6SLionel Sambuc            else if (__collate_)
22424684ddb6SLionel Sambuc                __neg_chars_.push_back(__traits_.translate(__c));
22434684ddb6SLionel Sambuc            else
22444684ddb6SLionel Sambuc                __neg_chars_.push_back(__c);
22454684ddb6SLionel Sambuc        }
22464684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
22474684ddb6SLionel Sambuc    void __add_range(string_type __b, string_type __e)
22484684ddb6SLionel Sambuc        {
22494684ddb6SLionel Sambuc            if (__collate_)
22504684ddb6SLionel Sambuc            {
22514684ddb6SLionel Sambuc                if (__icase_)
22524684ddb6SLionel Sambuc                {
22534684ddb6SLionel Sambuc                    for (size_t __i = 0; __i < __b.size(); ++__i)
22544684ddb6SLionel Sambuc                        __b[__i] = __traits_.translate_nocase(__b[__i]);
22554684ddb6SLionel Sambuc                    for (size_t __i = 0; __i < __e.size(); ++__i)
22564684ddb6SLionel Sambuc                        __e[__i] = __traits_.translate_nocase(__e[__i]);
22574684ddb6SLionel Sambuc                }
22584684ddb6SLionel Sambuc                else
22594684ddb6SLionel Sambuc                {
22604684ddb6SLionel Sambuc                    for (size_t __i = 0; __i < __b.size(); ++__i)
22614684ddb6SLionel Sambuc                        __b[__i] = __traits_.translate(__b[__i]);
22624684ddb6SLionel Sambuc                    for (size_t __i = 0; __i < __e.size(); ++__i)
22634684ddb6SLionel Sambuc                        __e[__i] = __traits_.translate(__e[__i]);
22644684ddb6SLionel Sambuc                }
22654684ddb6SLionel Sambuc                __ranges_.push_back(make_pair(
22664684ddb6SLionel Sambuc                                  __traits_.transform(__b.begin(), __b.end()),
22674684ddb6SLionel Sambuc                                  __traits_.transform(__e.begin(), __e.end())));
22684684ddb6SLionel Sambuc            }
22694684ddb6SLionel Sambuc            else
22704684ddb6SLionel Sambuc            {
22714684ddb6SLionel Sambuc                if (__b.size() != 1 || __e.size() != 1)
2272*0a6a1f1dSLionel Sambuc                    __throw_regex_error<regex_constants::error_collate>();
22734684ddb6SLionel Sambuc                if (__icase_)
22744684ddb6SLionel Sambuc                {
22754684ddb6SLionel Sambuc                    __b[0] = __traits_.translate_nocase(__b[0]);
22764684ddb6SLionel Sambuc                    __e[0] = __traits_.translate_nocase(__e[0]);
22774684ddb6SLionel Sambuc                }
22784684ddb6SLionel Sambuc                __ranges_.push_back(make_pair(_VSTD::move(__b), _VSTD::move(__e)));
22794684ddb6SLionel Sambuc            }
22804684ddb6SLionel Sambuc        }
22814684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
22824684ddb6SLionel Sambuc    void __add_digraph(_CharT __c1, _CharT __c2)
22834684ddb6SLionel Sambuc        {
22844684ddb6SLionel Sambuc            if (__icase_)
22854684ddb6SLionel Sambuc                __digraphs_.push_back(make_pair(__traits_.translate_nocase(__c1),
22864684ddb6SLionel Sambuc                                                __traits_.translate_nocase(__c2)));
22874684ddb6SLionel Sambuc            else if (__collate_)
22884684ddb6SLionel Sambuc                __digraphs_.push_back(make_pair(__traits_.translate(__c1),
22894684ddb6SLionel Sambuc                                                __traits_.translate(__c2)));
22904684ddb6SLionel Sambuc            else
22914684ddb6SLionel Sambuc                __digraphs_.push_back(make_pair(__c1, __c2));
22924684ddb6SLionel Sambuc        }
22934684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
22944684ddb6SLionel Sambuc    void __add_equivalence(const string_type& __s)
22954684ddb6SLionel Sambuc        {__equivalences_.push_back(__s);}
22964684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
2297*0a6a1f1dSLionel Sambuc    void __add_class(typename regex_traits<_CharT>::char_class_type __mask)
22984684ddb6SLionel Sambuc        {__mask_ |= __mask;}
22994684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
2300*0a6a1f1dSLionel Sambuc    void __add_neg_class(typename regex_traits<_CharT>::char_class_type __mask)
23014684ddb6SLionel Sambuc        {__neg_mask_ |= __mask;}
23024684ddb6SLionel Sambuc};
23034684ddb6SLionel Sambuc
23044684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
23054684ddb6SLionel Sambucvoid
23064684ddb6SLionel Sambuc__bracket_expression<_CharT, _Traits>::__exec(__state& __s) const
23074684ddb6SLionel Sambuc{
23084684ddb6SLionel Sambuc    bool __found = false;
23094684ddb6SLionel Sambuc    unsigned __consumed = 0;
23104684ddb6SLionel Sambuc    if (__s.__current_ != __s.__last_)
23114684ddb6SLionel Sambuc    {
23124684ddb6SLionel Sambuc        ++__consumed;
23134684ddb6SLionel Sambuc        if (__might_have_digraph_)
23144684ddb6SLionel Sambuc        {
23154684ddb6SLionel Sambuc            const _CharT* __next = _VSTD::next(__s.__current_);
23164684ddb6SLionel Sambuc            if (__next != __s.__last_)
23174684ddb6SLionel Sambuc            {
23184684ddb6SLionel Sambuc                pair<_CharT, _CharT> __ch2(*__s.__current_, *__next);
23194684ddb6SLionel Sambuc                if (__icase_)
23204684ddb6SLionel Sambuc                {
23214684ddb6SLionel Sambuc                    __ch2.first = __traits_.translate_nocase(__ch2.first);
23224684ddb6SLionel Sambuc                    __ch2.second = __traits_.translate_nocase(__ch2.second);
23234684ddb6SLionel Sambuc                }
23244684ddb6SLionel Sambuc                else if (__collate_)
23254684ddb6SLionel Sambuc                {
23264684ddb6SLionel Sambuc                    __ch2.first = __traits_.translate(__ch2.first);
23274684ddb6SLionel Sambuc                    __ch2.second = __traits_.translate(__ch2.second);
23284684ddb6SLionel Sambuc                }
23294684ddb6SLionel Sambuc                if (!__traits_.lookup_collatename(&__ch2.first, &__ch2.first+2).empty())
23304684ddb6SLionel Sambuc                {
23314684ddb6SLionel Sambuc                    // __ch2 is a digraph in this locale
23324684ddb6SLionel Sambuc                    ++__consumed;
23334684ddb6SLionel Sambuc                    for (size_t __i = 0; __i < __digraphs_.size(); ++__i)
23344684ddb6SLionel Sambuc                    {
23354684ddb6SLionel Sambuc                        if (__ch2 == __digraphs_[__i])
23364684ddb6SLionel Sambuc                        {
23374684ddb6SLionel Sambuc                            __found = true;
23384684ddb6SLionel Sambuc                            goto __exit;
23394684ddb6SLionel Sambuc                        }
23404684ddb6SLionel Sambuc                    }
23414684ddb6SLionel Sambuc                    if (__collate_ && !__ranges_.empty())
23424684ddb6SLionel Sambuc                    {
23434684ddb6SLionel Sambuc                        string_type __s2 = __traits_.transform(&__ch2.first,
23444684ddb6SLionel Sambuc                                                               &__ch2.first + 2);
23454684ddb6SLionel Sambuc                        for (size_t __i = 0; __i < __ranges_.size(); ++__i)
23464684ddb6SLionel Sambuc                        {
23474684ddb6SLionel Sambuc                            if (__ranges_[__i].first <= __s2 &&
23484684ddb6SLionel Sambuc                                __s2 <= __ranges_[__i].second)
23494684ddb6SLionel Sambuc                            {
23504684ddb6SLionel Sambuc                                __found = true;
23514684ddb6SLionel Sambuc                                goto __exit;
23524684ddb6SLionel Sambuc                            }
23534684ddb6SLionel Sambuc                        }
23544684ddb6SLionel Sambuc                    }
23554684ddb6SLionel Sambuc                    if (!__equivalences_.empty())
23564684ddb6SLionel Sambuc                    {
23574684ddb6SLionel Sambuc                        string_type __s2 = __traits_.transform_primary(&__ch2.first,
23584684ddb6SLionel Sambuc                                                                       &__ch2.first + 2);
23594684ddb6SLionel Sambuc                        for (size_t __i = 0; __i < __equivalences_.size(); ++__i)
23604684ddb6SLionel Sambuc                        {
23614684ddb6SLionel Sambuc                            if (__s2 == __equivalences_[__i])
23624684ddb6SLionel Sambuc                            {
23634684ddb6SLionel Sambuc                                __found = true;
23644684ddb6SLionel Sambuc                                goto __exit;
23654684ddb6SLionel Sambuc                            }
23664684ddb6SLionel Sambuc                        }
23674684ddb6SLionel Sambuc                    }
23684684ddb6SLionel Sambuc                    if (__traits_.isctype(__ch2.first, __mask_) &&
23694684ddb6SLionel Sambuc                        __traits_.isctype(__ch2.second, __mask_))
23704684ddb6SLionel Sambuc                    {
23714684ddb6SLionel Sambuc                        __found = true;
23724684ddb6SLionel Sambuc                        goto __exit;
23734684ddb6SLionel Sambuc                    }
23744684ddb6SLionel Sambuc                    if (!__traits_.isctype(__ch2.first, __neg_mask_) &&
23754684ddb6SLionel Sambuc                        !__traits_.isctype(__ch2.second, __neg_mask_))
23764684ddb6SLionel Sambuc                    {
23774684ddb6SLionel Sambuc                        __found = true;
23784684ddb6SLionel Sambuc                        goto __exit;
23794684ddb6SLionel Sambuc                    }
23804684ddb6SLionel Sambuc                    goto __exit;
23814684ddb6SLionel Sambuc                }
23824684ddb6SLionel Sambuc            }
23834684ddb6SLionel Sambuc        }
23844684ddb6SLionel Sambuc        // test *__s.__current_ as not a digraph
23854684ddb6SLionel Sambuc        _CharT __ch = *__s.__current_;
23864684ddb6SLionel Sambuc        if (__icase_)
23874684ddb6SLionel Sambuc            __ch = __traits_.translate_nocase(__ch);
23884684ddb6SLionel Sambuc        else if (__collate_)
23894684ddb6SLionel Sambuc            __ch = __traits_.translate(__ch);
23904684ddb6SLionel Sambuc        for (size_t __i = 0; __i < __chars_.size(); ++__i)
23914684ddb6SLionel Sambuc        {
23924684ddb6SLionel Sambuc            if (__ch == __chars_[__i])
23934684ddb6SLionel Sambuc            {
23944684ddb6SLionel Sambuc                __found = true;
23954684ddb6SLionel Sambuc                goto __exit;
23964684ddb6SLionel Sambuc            }
23974684ddb6SLionel Sambuc        }
23984684ddb6SLionel Sambuc        if (!__neg_chars_.empty())
23994684ddb6SLionel Sambuc        {
24004684ddb6SLionel Sambuc            for (size_t __i = 0; __i < __neg_chars_.size(); ++__i)
24014684ddb6SLionel Sambuc            {
24024684ddb6SLionel Sambuc                if (__ch == __neg_chars_[__i])
24034684ddb6SLionel Sambuc                    goto __is_neg_char;
24044684ddb6SLionel Sambuc            }
24054684ddb6SLionel Sambuc            __found = true;
24064684ddb6SLionel Sambuc            goto __exit;
24074684ddb6SLionel Sambuc        }
24084684ddb6SLionel Sambuc__is_neg_char:
24094684ddb6SLionel Sambuc        if (!__ranges_.empty())
24104684ddb6SLionel Sambuc        {
24114684ddb6SLionel Sambuc            string_type __s2 = __collate_ ?
24124684ddb6SLionel Sambuc                                   __traits_.transform(&__ch, &__ch + 1) :
24134684ddb6SLionel Sambuc                                   string_type(1, __ch);
24144684ddb6SLionel Sambuc            for (size_t __i = 0; __i < __ranges_.size(); ++__i)
24154684ddb6SLionel Sambuc            {
24164684ddb6SLionel Sambuc                if (__ranges_[__i].first <= __s2 && __s2 <= __ranges_[__i].second)
24174684ddb6SLionel Sambuc                {
24184684ddb6SLionel Sambuc                    __found = true;
24194684ddb6SLionel Sambuc                    goto __exit;
24204684ddb6SLionel Sambuc                }
24214684ddb6SLionel Sambuc            }
24224684ddb6SLionel Sambuc        }
24234684ddb6SLionel Sambuc        if (!__equivalences_.empty())
24244684ddb6SLionel Sambuc        {
24254684ddb6SLionel Sambuc            string_type __s2 = __traits_.transform_primary(&__ch, &__ch + 1);
24264684ddb6SLionel Sambuc            for (size_t __i = 0; __i < __equivalences_.size(); ++__i)
24274684ddb6SLionel Sambuc            {
24284684ddb6SLionel Sambuc                if (__s2 == __equivalences_[__i])
24294684ddb6SLionel Sambuc                {
24304684ddb6SLionel Sambuc                    __found = true;
24314684ddb6SLionel Sambuc                    goto __exit;
24324684ddb6SLionel Sambuc                }
24334684ddb6SLionel Sambuc            }
24344684ddb6SLionel Sambuc        }
24354684ddb6SLionel Sambuc        if (__traits_.isctype(__ch, __mask_))
24364684ddb6SLionel Sambuc        {
24374684ddb6SLionel Sambuc            __found = true;
24384684ddb6SLionel Sambuc            goto __exit;
24394684ddb6SLionel Sambuc        }
24404684ddb6SLionel Sambuc        if (__neg_mask_ && !__traits_.isctype(__ch, __neg_mask_))
24414684ddb6SLionel Sambuc        {
24424684ddb6SLionel Sambuc            __found = true;
24434684ddb6SLionel Sambuc            goto __exit;
24444684ddb6SLionel Sambuc        }
24454684ddb6SLionel Sambuc    }
24464684ddb6SLionel Sambuc    else
24474684ddb6SLionel Sambuc        __found = __negate_;  // force reject
24484684ddb6SLionel Sambuc__exit:
24494684ddb6SLionel Sambuc    if (__found != __negate_)
24504684ddb6SLionel Sambuc    {
24514684ddb6SLionel Sambuc        __s.__do_ = __state::__accept_and_consume;
24524684ddb6SLionel Sambuc        __s.__current_ += __consumed;
24534684ddb6SLionel Sambuc        __s.__node_ = this->first();
24544684ddb6SLionel Sambuc    }
24554684ddb6SLionel Sambuc    else
24564684ddb6SLionel Sambuc    {
24574684ddb6SLionel Sambuc        __s.__do_ = __state::__reject;
24584684ddb6SLionel Sambuc        __s.__node_ = nullptr;
24594684ddb6SLionel Sambuc    }
24604684ddb6SLionel Sambuc}
24614684ddb6SLionel Sambuc
24624684ddb6SLionel Sambuctemplate <class _CharT, class _Traits> class __lookahead;
24634684ddb6SLionel Sambuc
24644684ddb6SLionel Sambuctemplate <class _CharT, class _Traits = regex_traits<_CharT> >
24654684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS_ONLY basic_regex
24664684ddb6SLionel Sambuc{
24674684ddb6SLionel Sambucpublic:
24684684ddb6SLionel Sambuc    // types:
24694684ddb6SLionel Sambuc    typedef _CharT                              value_type;
24704684ddb6SLionel Sambuc    typedef regex_constants::syntax_option_type flag_type;
24714684ddb6SLionel Sambuc    typedef typename _Traits::locale_type       locale_type;
24724684ddb6SLionel Sambuc
24734684ddb6SLionel Sambucprivate:
24744684ddb6SLionel Sambuc    _Traits   __traits_;
24754684ddb6SLionel Sambuc    flag_type __flags_;
24764684ddb6SLionel Sambuc    unsigned __marked_count_;
24774684ddb6SLionel Sambuc    unsigned __loop_count_;
24784684ddb6SLionel Sambuc    int __open_count_;
24794684ddb6SLionel Sambuc    shared_ptr<__empty_state<_CharT> > __start_;
24804684ddb6SLionel Sambuc    __owns_one_state<_CharT>* __end_;
24814684ddb6SLionel Sambuc
24824684ddb6SLionel Sambuc    typedef _VSTD::__state<_CharT> __state;
24834684ddb6SLionel Sambuc    typedef _VSTD::__node<_CharT> __node;
24844684ddb6SLionel Sambuc
24854684ddb6SLionel Sambucpublic:
24864684ddb6SLionel Sambuc    // constants:
24874684ddb6SLionel Sambuc    static const regex_constants::syntax_option_type icase = regex_constants::icase;
24884684ddb6SLionel Sambuc    static const regex_constants::syntax_option_type nosubs = regex_constants::nosubs;
24894684ddb6SLionel Sambuc    static const regex_constants::syntax_option_type optimize = regex_constants::optimize;
24904684ddb6SLionel Sambuc    static const regex_constants::syntax_option_type collate = regex_constants::collate;
24914684ddb6SLionel Sambuc    static const regex_constants::syntax_option_type ECMAScript = regex_constants::ECMAScript;
24924684ddb6SLionel Sambuc    static const regex_constants::syntax_option_type basic = regex_constants::basic;
24934684ddb6SLionel Sambuc    static const regex_constants::syntax_option_type extended = regex_constants::extended;
24944684ddb6SLionel Sambuc    static const regex_constants::syntax_option_type awk = regex_constants::awk;
24954684ddb6SLionel Sambuc    static const regex_constants::syntax_option_type grep = regex_constants::grep;
24964684ddb6SLionel Sambuc    static const regex_constants::syntax_option_type egrep = regex_constants::egrep;
24974684ddb6SLionel Sambuc
24984684ddb6SLionel Sambuc    // construct/copy/destroy:
24994684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
25004684ddb6SLionel Sambuc    basic_regex()
25014684ddb6SLionel Sambuc        : __flags_(), __marked_count_(0), __loop_count_(0), __open_count_(0),
25024684ddb6SLionel Sambuc          __end_(0)
25034684ddb6SLionel Sambuc        {}
25044684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
25054684ddb6SLionel Sambuc    explicit basic_regex(const value_type* __p, flag_type __f = regex_constants::ECMAScript)
25064684ddb6SLionel Sambuc        : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0),
25074684ddb6SLionel Sambuc          __end_(0)
25084684ddb6SLionel Sambuc        {__parse(__p, __p + __traits_.length(__p));}
25094684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
25104684ddb6SLionel Sambuc    basic_regex(const value_type* __p, size_t __len, flag_type __f)
25114684ddb6SLionel Sambuc        : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0),
25124684ddb6SLionel Sambuc          __end_(0)
25134684ddb6SLionel Sambuc        {__parse(__p, __p + __len);}
25144684ddb6SLionel Sambuc//     basic_regex(const basic_regex&) = default;
25154684ddb6SLionel Sambuc//     basic_regex(basic_regex&&) = default;
25164684ddb6SLionel Sambuc    template <class _ST, class _SA>
25174684ddb6SLionel Sambuc        _LIBCPP_INLINE_VISIBILITY
25184684ddb6SLionel Sambuc        explicit basic_regex(const basic_string<value_type, _ST, _SA>& __p,
25194684ddb6SLionel Sambuc                             flag_type __f = regex_constants::ECMAScript)
25204684ddb6SLionel Sambuc        : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0),
25214684ddb6SLionel Sambuc          __end_(0)
25224684ddb6SLionel Sambuc        {__parse(__p.begin(), __p.end());}
25234684ddb6SLionel Sambuc    template <class _ForwardIterator>
25244684ddb6SLionel Sambuc        _LIBCPP_INLINE_VISIBILITY
25254684ddb6SLionel Sambuc        basic_regex(_ForwardIterator __first, _ForwardIterator __last,
25264684ddb6SLionel Sambuc                    flag_type __f = regex_constants::ECMAScript)
25274684ddb6SLionel Sambuc        : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0),
25284684ddb6SLionel Sambuc          __end_(0)
25294684ddb6SLionel Sambuc        {__parse(__first, __last);}
25304684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
25314684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
25324684ddb6SLionel Sambuc    basic_regex(initializer_list<value_type> __il,
25334684ddb6SLionel Sambuc                flag_type __f = regex_constants::ECMAScript)
25344684ddb6SLionel Sambuc        : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0),
25354684ddb6SLionel Sambuc          __end_(0)
25364684ddb6SLionel Sambuc        {__parse(__il.begin(), __il.end());}
25374684ddb6SLionel Sambuc#endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
25384684ddb6SLionel Sambuc
25394684ddb6SLionel Sambuc//    ~basic_regex() = default;
25404684ddb6SLionel Sambuc
25414684ddb6SLionel Sambuc//     basic_regex& operator=(const basic_regex&) = default;
25424684ddb6SLionel Sambuc//     basic_regex& operator=(basic_regex&&) = default;
25434684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
25444684ddb6SLionel Sambuc    basic_regex& operator=(const value_type* __p)
25454684ddb6SLionel Sambuc        {return assign(__p);}
25464684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
25474684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
25484684ddb6SLionel Sambuc    basic_regex& operator=(initializer_list<value_type> __il)
25494684ddb6SLionel Sambuc        {return assign(__il);}
25504684ddb6SLionel Sambuc#endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
25514684ddb6SLionel Sambuc    template <class _ST, class _SA>
25524684ddb6SLionel Sambuc        _LIBCPP_INLINE_VISIBILITY
25534684ddb6SLionel Sambuc        basic_regex& operator=(const basic_string<value_type, _ST, _SA>& __p)
25544684ddb6SLionel Sambuc        {return assign(__p);}
25554684ddb6SLionel Sambuc
25564684ddb6SLionel Sambuc    // assign:
25574684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
25584684ddb6SLionel Sambuc    basic_regex& assign(const basic_regex& __that)
25594684ddb6SLionel Sambuc        {return *this = __that;}
25604684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
25614684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
25624684ddb6SLionel Sambuc    basic_regex& assign(basic_regex&& __that) _NOEXCEPT
25634684ddb6SLionel Sambuc        {return *this = _VSTD::move(__that);}
25644684ddb6SLionel Sambuc#endif
25654684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
25664684ddb6SLionel Sambuc    basic_regex& assign(const value_type* __p, flag_type __f = regex_constants::ECMAScript)
25674684ddb6SLionel Sambuc        {return assign(__p, __p + __traits_.length(__p), __f);}
25684684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
25694684ddb6SLionel Sambuc    basic_regex& assign(const value_type* __p, size_t __len, flag_type __f)
25704684ddb6SLionel Sambuc        {return assign(__p, __p + __len, __f);}
25714684ddb6SLionel Sambuc    template <class _ST, class _SA>
25724684ddb6SLionel Sambuc        _LIBCPP_INLINE_VISIBILITY
25734684ddb6SLionel Sambuc        basic_regex& assign(const basic_string<value_type, _ST, _SA>& __s,
25744684ddb6SLionel Sambuc                            flag_type __f = regex_constants::ECMAScript)
25754684ddb6SLionel Sambuc            {return assign(__s.begin(), __s.end(), __f);}
25764684ddb6SLionel Sambuc
25774684ddb6SLionel Sambuc    template <class _InputIterator>
25784684ddb6SLionel Sambuc        _LIBCPP_INLINE_VISIBILITY
25794684ddb6SLionel Sambuc        typename enable_if
25804684ddb6SLionel Sambuc        <
25814684ddb6SLionel Sambuc             __is_input_iterator  <_InputIterator>::value &&
25824684ddb6SLionel Sambuc            !__is_forward_iterator<_InputIterator>::value,
25834684ddb6SLionel Sambuc            basic_regex&
25844684ddb6SLionel Sambuc        >::type
25854684ddb6SLionel Sambuc        assign(_InputIterator __first, _InputIterator __last,
25864684ddb6SLionel Sambuc                            flag_type __f = regex_constants::ECMAScript)
25874684ddb6SLionel Sambuc        {
25884684ddb6SLionel Sambuc            basic_string<_CharT> __t(__first, __last);
25894684ddb6SLionel Sambuc            return assign(__t.begin(), __t.end(), __f);
25904684ddb6SLionel Sambuc        }
25914684ddb6SLionel Sambuc
25924684ddb6SLionel Sambucprivate:
25934684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
25944684ddb6SLionel Sambuc    void __member_init(flag_type __f)
25954684ddb6SLionel Sambuc    {
25964684ddb6SLionel Sambuc        __flags_ = __f;
25974684ddb6SLionel Sambuc        __marked_count_ = 0;
25984684ddb6SLionel Sambuc        __loop_count_ = 0;
25994684ddb6SLionel Sambuc        __open_count_ = 0;
26004684ddb6SLionel Sambuc        __end_ = nullptr;
26014684ddb6SLionel Sambuc    }
26024684ddb6SLionel Sambucpublic:
26034684ddb6SLionel Sambuc
26044684ddb6SLionel Sambuc    template <class _ForwardIterator>
26054684ddb6SLionel Sambuc        _LIBCPP_INLINE_VISIBILITY
26064684ddb6SLionel Sambuc        typename enable_if
26074684ddb6SLionel Sambuc        <
26084684ddb6SLionel Sambuc            __is_forward_iterator<_ForwardIterator>::value,
26094684ddb6SLionel Sambuc            basic_regex&
26104684ddb6SLionel Sambuc        >::type
26114684ddb6SLionel Sambuc        assign(_ForwardIterator __first, _ForwardIterator __last,
26124684ddb6SLionel Sambuc                            flag_type __f = regex_constants::ECMAScript)
26134684ddb6SLionel Sambuc        {
2614*0a6a1f1dSLionel Sambuc            return assign(basic_regex(__first, __last, __f));
26154684ddb6SLionel Sambuc        }
26164684ddb6SLionel Sambuc
26174684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
26184684ddb6SLionel Sambuc
26194684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
26204684ddb6SLionel Sambuc    basic_regex& assign(initializer_list<value_type> __il,
26214684ddb6SLionel Sambuc                        flag_type __f = regex_constants::ECMAScript)
26224684ddb6SLionel Sambuc        {return assign(__il.begin(), __il.end(), __f);}
26234684ddb6SLionel Sambuc
26244684ddb6SLionel Sambuc#endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
26254684ddb6SLionel Sambuc
26264684ddb6SLionel Sambuc    // const operations:
26274684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
26284684ddb6SLionel Sambuc    unsigned mark_count() const {return __marked_count_;}
26294684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
26304684ddb6SLionel Sambuc    flag_type flags() const {return __flags_;}
26314684ddb6SLionel Sambuc
26324684ddb6SLionel Sambuc    // locale:
26334684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
26344684ddb6SLionel Sambuc    locale_type imbue(locale_type __loc)
26354684ddb6SLionel Sambuc    {
26364684ddb6SLionel Sambuc        __member_init(ECMAScript);
26374684ddb6SLionel Sambuc        __start_.reset();
26384684ddb6SLionel Sambuc        return __traits_.imbue(__loc);
26394684ddb6SLionel Sambuc    }
26404684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
26414684ddb6SLionel Sambuc    locale_type getloc() const {return __traits_.getloc();}
26424684ddb6SLionel Sambuc
26434684ddb6SLionel Sambuc    // swap:
26444684ddb6SLionel Sambuc    void swap(basic_regex& __r);
26454684ddb6SLionel Sambuc
26464684ddb6SLionel Sambucprivate:
26474684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
26484684ddb6SLionel Sambuc    unsigned __loop_count() const {return __loop_count_;}
26494684ddb6SLionel Sambuc
26504684ddb6SLionel Sambuc    template <class _ForwardIterator>
26514684ddb6SLionel Sambuc        _ForwardIterator
26524684ddb6SLionel Sambuc        __parse(_ForwardIterator __first, _ForwardIterator __last);
26534684ddb6SLionel Sambuc    template <class _ForwardIterator>
26544684ddb6SLionel Sambuc        _ForwardIterator
26554684ddb6SLionel Sambuc        __parse_basic_reg_exp(_ForwardIterator __first, _ForwardIterator __last);
26564684ddb6SLionel Sambuc    template <class _ForwardIterator>
26574684ddb6SLionel Sambuc        _ForwardIterator
26584684ddb6SLionel Sambuc        __parse_RE_expression(_ForwardIterator __first, _ForwardIterator __last);
26594684ddb6SLionel Sambuc    template <class _ForwardIterator>
26604684ddb6SLionel Sambuc        _ForwardIterator
26614684ddb6SLionel Sambuc        __parse_simple_RE(_ForwardIterator __first, _ForwardIterator __last);
26624684ddb6SLionel Sambuc    template <class _ForwardIterator>
26634684ddb6SLionel Sambuc        _ForwardIterator
26644684ddb6SLionel Sambuc        __parse_nondupl_RE(_ForwardIterator __first, _ForwardIterator __last);
26654684ddb6SLionel Sambuc    template <class _ForwardIterator>
26664684ddb6SLionel Sambuc        _ForwardIterator
26674684ddb6SLionel Sambuc        __parse_one_char_or_coll_elem_RE(_ForwardIterator __first, _ForwardIterator __last);
26684684ddb6SLionel Sambuc    template <class _ForwardIterator>
26694684ddb6SLionel Sambuc        _ForwardIterator
26704684ddb6SLionel Sambuc        __parse_Back_open_paren(_ForwardIterator __first, _ForwardIterator __last);
26714684ddb6SLionel Sambuc    template <class _ForwardIterator>
26724684ddb6SLionel Sambuc        _ForwardIterator
26734684ddb6SLionel Sambuc        __parse_Back_close_paren(_ForwardIterator __first, _ForwardIterator __last);
26744684ddb6SLionel Sambuc    template <class _ForwardIterator>
26754684ddb6SLionel Sambuc        _ForwardIterator
26764684ddb6SLionel Sambuc        __parse_Back_open_brace(_ForwardIterator __first, _ForwardIterator __last);
26774684ddb6SLionel Sambuc    template <class _ForwardIterator>
26784684ddb6SLionel Sambuc        _ForwardIterator
26794684ddb6SLionel Sambuc        __parse_Back_close_brace(_ForwardIterator __first, _ForwardIterator __last);
26804684ddb6SLionel Sambuc    template <class _ForwardIterator>
26814684ddb6SLionel Sambuc        _ForwardIterator
26824684ddb6SLionel Sambuc        __parse_BACKREF(_ForwardIterator __first, _ForwardIterator __last);
26834684ddb6SLionel Sambuc    template <class _ForwardIterator>
26844684ddb6SLionel Sambuc        _ForwardIterator
26854684ddb6SLionel Sambuc        __parse_ORD_CHAR(_ForwardIterator __first, _ForwardIterator __last);
26864684ddb6SLionel Sambuc    template <class _ForwardIterator>
26874684ddb6SLionel Sambuc        _ForwardIterator
26884684ddb6SLionel Sambuc        __parse_QUOTED_CHAR(_ForwardIterator __first, _ForwardIterator __last);
26894684ddb6SLionel Sambuc    template <class _ForwardIterator>
26904684ddb6SLionel Sambuc        _ForwardIterator
26914684ddb6SLionel Sambuc        __parse_RE_dupl_symbol(_ForwardIterator __first, _ForwardIterator __last,
26924684ddb6SLionel Sambuc                               __owns_one_state<_CharT>* __s,
26934684ddb6SLionel Sambuc                               unsigned __mexp_begin, unsigned __mexp_end);
26944684ddb6SLionel Sambuc    template <class _ForwardIterator>
26954684ddb6SLionel Sambuc        _ForwardIterator
26964684ddb6SLionel Sambuc        __parse_ERE_dupl_symbol(_ForwardIterator __first, _ForwardIterator __last,
26974684ddb6SLionel Sambuc                                __owns_one_state<_CharT>* __s,
26984684ddb6SLionel Sambuc                                unsigned __mexp_begin, unsigned __mexp_end);
26994684ddb6SLionel Sambuc    template <class _ForwardIterator>
27004684ddb6SLionel Sambuc        _ForwardIterator
27014684ddb6SLionel Sambuc        __parse_bracket_expression(_ForwardIterator __first, _ForwardIterator __last);
27024684ddb6SLionel Sambuc    template <class _ForwardIterator>
27034684ddb6SLionel Sambuc        _ForwardIterator
27044684ddb6SLionel Sambuc        __parse_follow_list(_ForwardIterator __first, _ForwardIterator __last,
27054684ddb6SLionel Sambuc                            __bracket_expression<_CharT, _Traits>* __ml);
27064684ddb6SLionel Sambuc    template <class _ForwardIterator>
27074684ddb6SLionel Sambuc        _ForwardIterator
27084684ddb6SLionel Sambuc        __parse_expression_term(_ForwardIterator __first, _ForwardIterator __last,
27094684ddb6SLionel Sambuc                                __bracket_expression<_CharT, _Traits>* __ml);
27104684ddb6SLionel Sambuc    template <class _ForwardIterator>
27114684ddb6SLionel Sambuc        _ForwardIterator
27124684ddb6SLionel Sambuc        __parse_equivalence_class(_ForwardIterator __first, _ForwardIterator __last,
27134684ddb6SLionel Sambuc                                  __bracket_expression<_CharT, _Traits>* __ml);
27144684ddb6SLionel Sambuc    template <class _ForwardIterator>
27154684ddb6SLionel Sambuc        _ForwardIterator
27164684ddb6SLionel Sambuc        __parse_character_class(_ForwardIterator __first, _ForwardIterator __last,
27174684ddb6SLionel Sambuc                                __bracket_expression<_CharT, _Traits>* __ml);
27184684ddb6SLionel Sambuc    template <class _ForwardIterator>
27194684ddb6SLionel Sambuc        _ForwardIterator
27204684ddb6SLionel Sambuc        __parse_collating_symbol(_ForwardIterator __first, _ForwardIterator __last,
27214684ddb6SLionel Sambuc                                 basic_string<_CharT>& __col_sym);
27224684ddb6SLionel Sambuc    template <class _ForwardIterator>
27234684ddb6SLionel Sambuc        _ForwardIterator
27244684ddb6SLionel Sambuc        __parse_DUP_COUNT(_ForwardIterator __first, _ForwardIterator __last, int& __c);
27254684ddb6SLionel Sambuc    template <class _ForwardIterator>
27264684ddb6SLionel Sambuc        _ForwardIterator
27274684ddb6SLionel Sambuc        __parse_extended_reg_exp(_ForwardIterator __first, _ForwardIterator __last);
27284684ddb6SLionel Sambuc    template <class _ForwardIterator>
27294684ddb6SLionel Sambuc        _ForwardIterator
27304684ddb6SLionel Sambuc        __parse_ERE_branch(_ForwardIterator __first, _ForwardIterator __last);
27314684ddb6SLionel Sambuc    template <class _ForwardIterator>
27324684ddb6SLionel Sambuc        _ForwardIterator
27334684ddb6SLionel Sambuc        __parse_ERE_expression(_ForwardIterator __first, _ForwardIterator __last);
27344684ddb6SLionel Sambuc    template <class _ForwardIterator>
27354684ddb6SLionel Sambuc        _ForwardIterator
27364684ddb6SLionel Sambuc        __parse_one_char_or_coll_elem_ERE(_ForwardIterator __first, _ForwardIterator __last);
27374684ddb6SLionel Sambuc    template <class _ForwardIterator>
27384684ddb6SLionel Sambuc        _ForwardIterator
27394684ddb6SLionel Sambuc        __parse_ORD_CHAR_ERE(_ForwardIterator __first, _ForwardIterator __last);
27404684ddb6SLionel Sambuc    template <class _ForwardIterator>
27414684ddb6SLionel Sambuc        _ForwardIterator
27424684ddb6SLionel Sambuc        __parse_QUOTED_CHAR_ERE(_ForwardIterator __first, _ForwardIterator __last);
27434684ddb6SLionel Sambuc    template <class _ForwardIterator>
27444684ddb6SLionel Sambuc        _ForwardIterator
27454684ddb6SLionel Sambuc        __parse_ecma_exp(_ForwardIterator __first, _ForwardIterator __last);
27464684ddb6SLionel Sambuc    template <class _ForwardIterator>
27474684ddb6SLionel Sambuc        _ForwardIterator
27484684ddb6SLionel Sambuc        __parse_alternative(_ForwardIterator __first, _ForwardIterator __last);
27494684ddb6SLionel Sambuc    template <class _ForwardIterator>
27504684ddb6SLionel Sambuc        _ForwardIterator
27514684ddb6SLionel Sambuc        __parse_term(_ForwardIterator __first, _ForwardIterator __last);
27524684ddb6SLionel Sambuc    template <class _ForwardIterator>
27534684ddb6SLionel Sambuc        _ForwardIterator
27544684ddb6SLionel Sambuc        __parse_assertion(_ForwardIterator __first, _ForwardIterator __last);
27554684ddb6SLionel Sambuc    template <class _ForwardIterator>
27564684ddb6SLionel Sambuc        _ForwardIterator
27574684ddb6SLionel Sambuc        __parse_atom(_ForwardIterator __first, _ForwardIterator __last);
27584684ddb6SLionel Sambuc    template <class _ForwardIterator>
27594684ddb6SLionel Sambuc        _ForwardIterator
27604684ddb6SLionel Sambuc        __parse_atom_escape(_ForwardIterator __first, _ForwardIterator __last);
27614684ddb6SLionel Sambuc    template <class _ForwardIterator>
27624684ddb6SLionel Sambuc        _ForwardIterator
27634684ddb6SLionel Sambuc        __parse_decimal_escape(_ForwardIterator __first, _ForwardIterator __last);
27644684ddb6SLionel Sambuc    template <class _ForwardIterator>
27654684ddb6SLionel Sambuc        _ForwardIterator
27664684ddb6SLionel Sambuc        __parse_character_class_escape(_ForwardIterator __first, _ForwardIterator __last);
27674684ddb6SLionel Sambuc    template <class _ForwardIterator>
27684684ddb6SLionel Sambuc        _ForwardIterator
27694684ddb6SLionel Sambuc        __parse_character_escape(_ForwardIterator __first, _ForwardIterator __last,
27704684ddb6SLionel Sambuc                                 basic_string<_CharT>* __str = nullptr);
27714684ddb6SLionel Sambuc    template <class _ForwardIterator>
27724684ddb6SLionel Sambuc        _ForwardIterator
27734684ddb6SLionel Sambuc        __parse_pattern_character(_ForwardIterator __first, _ForwardIterator __last);
27744684ddb6SLionel Sambuc    template <class _ForwardIterator>
27754684ddb6SLionel Sambuc        _ForwardIterator
27764684ddb6SLionel Sambuc        __parse_grep(_ForwardIterator __first, _ForwardIterator __last);
27774684ddb6SLionel Sambuc    template <class _ForwardIterator>
27784684ddb6SLionel Sambuc        _ForwardIterator
27794684ddb6SLionel Sambuc        __parse_egrep(_ForwardIterator __first, _ForwardIterator __last);
27804684ddb6SLionel Sambuc    template <class _ForwardIterator>
27814684ddb6SLionel Sambuc        _ForwardIterator
27824684ddb6SLionel Sambuc        __parse_class_escape(_ForwardIterator __first, _ForwardIterator __last,
27834684ddb6SLionel Sambuc                          basic_string<_CharT>& __str,
27844684ddb6SLionel Sambuc                          __bracket_expression<_CharT, _Traits>* __ml);
27854684ddb6SLionel Sambuc    template <class _ForwardIterator>
27864684ddb6SLionel Sambuc        _ForwardIterator
27874684ddb6SLionel Sambuc        __parse_awk_escape(_ForwardIterator __first, _ForwardIterator __last,
27884684ddb6SLionel Sambuc                          basic_string<_CharT>* __str = nullptr);
27894684ddb6SLionel Sambuc
27904684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
27914684ddb6SLionel Sambuc    void __push_l_anchor();
27924684ddb6SLionel Sambuc    void __push_r_anchor();
27934684ddb6SLionel Sambuc    void __push_match_any();
27944684ddb6SLionel Sambuc    void __push_match_any_but_newline();
27954684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
27964684ddb6SLionel Sambuc    void __push_greedy_inf_repeat(size_t __min, __owns_one_state<_CharT>* __s,
27974684ddb6SLionel Sambuc                                  unsigned __mexp_begin = 0, unsigned __mexp_end = 0)
27984684ddb6SLionel Sambuc        {__push_loop(__min, numeric_limits<size_t>::max(), __s,
27994684ddb6SLionel Sambuc                     __mexp_begin, __mexp_end);}
28004684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
28014684ddb6SLionel Sambuc    void __push_nongreedy_inf_repeat(size_t __min, __owns_one_state<_CharT>* __s,
28024684ddb6SLionel Sambuc                                  unsigned __mexp_begin = 0, unsigned __mexp_end = 0)
28034684ddb6SLionel Sambuc        {__push_loop(__min, numeric_limits<size_t>::max(), __s,
28044684ddb6SLionel Sambuc                     __mexp_begin, __mexp_end, false);}
28054684ddb6SLionel Sambuc    void __push_loop(size_t __min, size_t __max, __owns_one_state<_CharT>* __s,
28064684ddb6SLionel Sambuc                     size_t __mexp_begin = 0, size_t __mexp_end = 0,
28074684ddb6SLionel Sambuc                     bool __greedy = true);
28084684ddb6SLionel Sambuc    __bracket_expression<_CharT, _Traits>* __start_matching_list(bool __negate);
28094684ddb6SLionel Sambuc    void __push_char(value_type __c);
28104684ddb6SLionel Sambuc    void __push_back_ref(int __i);
28114684ddb6SLionel Sambuc    void __push_alternation(__owns_one_state<_CharT>* __sa,
28124684ddb6SLionel Sambuc                            __owns_one_state<_CharT>* __sb);
28134684ddb6SLionel Sambuc    void __push_begin_marked_subexpression();
28144684ddb6SLionel Sambuc    void __push_end_marked_subexpression(unsigned);
28154684ddb6SLionel Sambuc    void __push_empty();
28164684ddb6SLionel Sambuc    void __push_word_boundary(bool);
28174684ddb6SLionel Sambuc    void __push_lookahead(const basic_regex&, bool, unsigned);
28184684ddb6SLionel Sambuc
28194684ddb6SLionel Sambuc    template <class _Allocator>
28204684ddb6SLionel Sambuc        bool
28214684ddb6SLionel Sambuc        __search(const _CharT* __first, const _CharT* __last,
28224684ddb6SLionel Sambuc                 match_results<const _CharT*, _Allocator>& __m,
28234684ddb6SLionel Sambuc                 regex_constants::match_flag_type __flags) const;
28244684ddb6SLionel Sambuc
28254684ddb6SLionel Sambuc    template <class _Allocator>
28264684ddb6SLionel Sambuc        bool
28274684ddb6SLionel Sambuc        __match_at_start(const _CharT* __first, const _CharT* __last,
28284684ddb6SLionel Sambuc                 match_results<const _CharT*, _Allocator>& __m,
28294684ddb6SLionel Sambuc                 regex_constants::match_flag_type __flags, bool) const;
28304684ddb6SLionel Sambuc    template <class _Allocator>
28314684ddb6SLionel Sambuc        bool
28324684ddb6SLionel Sambuc        __match_at_start_ecma(const _CharT* __first, const _CharT* __last,
28334684ddb6SLionel Sambuc                 match_results<const _CharT*, _Allocator>& __m,
28344684ddb6SLionel Sambuc                 regex_constants::match_flag_type __flags, bool) const;
28354684ddb6SLionel Sambuc    template <class _Allocator>
28364684ddb6SLionel Sambuc        bool
28374684ddb6SLionel Sambuc        __match_at_start_posix_nosubs(const _CharT* __first, const _CharT* __last,
28384684ddb6SLionel Sambuc                 match_results<const _CharT*, _Allocator>& __m,
28394684ddb6SLionel Sambuc                 regex_constants::match_flag_type __flags, bool) const;
28404684ddb6SLionel Sambuc    template <class _Allocator>
28414684ddb6SLionel Sambuc        bool
28424684ddb6SLionel Sambuc        __match_at_start_posix_subs(const _CharT* __first, const _CharT* __last,
28434684ddb6SLionel Sambuc                 match_results<const _CharT*, _Allocator>& __m,
28444684ddb6SLionel Sambuc                 regex_constants::match_flag_type __flags, bool) const;
28454684ddb6SLionel Sambuc
28464684ddb6SLionel Sambuc    template <class _Bp, class _Ap, class _Cp, class _Tp>
28474684ddb6SLionel Sambuc    friend
28484684ddb6SLionel Sambuc    bool
28494684ddb6SLionel Sambuc    regex_search(_Bp, _Bp, match_results<_Bp, _Ap>&, const basic_regex<_Cp, _Tp>&,
28504684ddb6SLionel Sambuc                 regex_constants::match_flag_type);
28514684ddb6SLionel Sambuc
28524684ddb6SLionel Sambuc    template <class _Ap, class _Cp, class _Tp>
28534684ddb6SLionel Sambuc    friend
28544684ddb6SLionel Sambuc    bool
28554684ddb6SLionel Sambuc    regex_search(const _Cp*, const _Cp*, match_results<const _Cp*, _Ap>&,
28564684ddb6SLionel Sambuc                 const basic_regex<_Cp, _Tp>&, regex_constants::match_flag_type);
28574684ddb6SLionel Sambuc
28584684ddb6SLionel Sambuc    template <class _Bp, class _Cp, class _Tp>
28594684ddb6SLionel Sambuc    friend
28604684ddb6SLionel Sambuc    bool
28614684ddb6SLionel Sambuc    regex_search(_Bp, _Bp, const basic_regex<_Cp, _Tp>&,
28624684ddb6SLionel Sambuc                 regex_constants::match_flag_type);
28634684ddb6SLionel Sambuc
28644684ddb6SLionel Sambuc    template <class _Cp, class _Tp>
28654684ddb6SLionel Sambuc    friend
28664684ddb6SLionel Sambuc    bool
28674684ddb6SLionel Sambuc    regex_search(const _Cp*, const _Cp*,
28684684ddb6SLionel Sambuc                 const basic_regex<_Cp, _Tp>&, regex_constants::match_flag_type);
28694684ddb6SLionel Sambuc
28704684ddb6SLionel Sambuc    template <class _Cp, class _Ap, class _Tp>
28714684ddb6SLionel Sambuc    friend
28724684ddb6SLionel Sambuc    bool
28734684ddb6SLionel Sambuc    regex_search(const _Cp*, match_results<const _Cp*, _Ap>&, const basic_regex<_Cp, _Tp>&,
28744684ddb6SLionel Sambuc                 regex_constants::match_flag_type);
28754684ddb6SLionel Sambuc
28764684ddb6SLionel Sambuc    template <class _ST, class _SA, class _Cp, class _Tp>
28774684ddb6SLionel Sambuc    friend
28784684ddb6SLionel Sambuc    bool
28794684ddb6SLionel Sambuc    regex_search(const basic_string<_Cp, _ST, _SA>& __s,
28804684ddb6SLionel Sambuc                 const basic_regex<_Cp, _Tp>& __e,
28814684ddb6SLionel Sambuc                 regex_constants::match_flag_type __flags);
28824684ddb6SLionel Sambuc
28834684ddb6SLionel Sambuc    template <class _ST, class _SA, class _Ap, class _Cp, class _Tp>
28844684ddb6SLionel Sambuc    friend
28854684ddb6SLionel Sambuc    bool
28864684ddb6SLionel Sambuc    regex_search(const basic_string<_Cp, _ST, _SA>& __s,
28874684ddb6SLionel Sambuc                 match_results<typename basic_string<_Cp, _ST, _SA>::const_iterator, _Ap>&,
28884684ddb6SLionel Sambuc                 const basic_regex<_Cp, _Tp>& __e,
28894684ddb6SLionel Sambuc                 regex_constants::match_flag_type __flags);
28904684ddb6SLionel Sambuc
28914684ddb6SLionel Sambuc    template <class _Iter, class _Ap, class _Cp, class _Tp>
28924684ddb6SLionel Sambuc    friend
28934684ddb6SLionel Sambuc    bool
28944684ddb6SLionel Sambuc    regex_search(__wrap_iter<_Iter> __first,
28954684ddb6SLionel Sambuc                 __wrap_iter<_Iter> __last,
28964684ddb6SLionel Sambuc                 match_results<__wrap_iter<_Iter>, _Ap>& __m,
28974684ddb6SLionel Sambuc                 const basic_regex<_Cp, _Tp>& __e,
28984684ddb6SLionel Sambuc                 regex_constants::match_flag_type __flags);
28994684ddb6SLionel Sambuc
29004684ddb6SLionel Sambuc    template <class, class> friend class __lookahead;
29014684ddb6SLionel Sambuc};
29024684ddb6SLionel Sambuc
29034684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
29044684ddb6SLionel Sambuc    const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::icase;
29054684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
29064684ddb6SLionel Sambuc    const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::nosubs;
29074684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
29084684ddb6SLionel Sambuc    const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::optimize;
29094684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
29104684ddb6SLionel Sambuc    const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::collate;
29114684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
29124684ddb6SLionel Sambuc    const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::ECMAScript;
29134684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
29144684ddb6SLionel Sambuc    const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::basic;
29154684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
29164684ddb6SLionel Sambuc    const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::extended;
29174684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
29184684ddb6SLionel Sambuc    const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::awk;
29194684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
29204684ddb6SLionel Sambuc    const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::grep;
29214684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
29224684ddb6SLionel Sambuc    const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::egrep;
29234684ddb6SLionel Sambuc
29244684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
29254684ddb6SLionel Sambucvoid
29264684ddb6SLionel Sambucbasic_regex<_CharT, _Traits>::swap(basic_regex& __r)
29274684ddb6SLionel Sambuc{
29284684ddb6SLionel Sambuc    using _VSTD::swap;
29294684ddb6SLionel Sambuc    swap(__traits_, __r.__traits_);
29304684ddb6SLionel Sambuc    swap(__flags_, __r.__flags_);
29314684ddb6SLionel Sambuc    swap(__marked_count_, __r.__marked_count_);
29324684ddb6SLionel Sambuc    swap(__loop_count_, __r.__loop_count_);
29334684ddb6SLionel Sambuc    swap(__open_count_, __r.__open_count_);
29344684ddb6SLionel Sambuc    swap(__start_, __r.__start_);
29354684ddb6SLionel Sambuc    swap(__end_, __r.__end_);
29364684ddb6SLionel Sambuc}
29374684ddb6SLionel Sambuc
29384684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
29394684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
29404684ddb6SLionel Sambucvoid
29414684ddb6SLionel Sambucswap(basic_regex<_CharT, _Traits>& __x, basic_regex<_CharT, _Traits>& __y)
29424684ddb6SLionel Sambuc{
29434684ddb6SLionel Sambuc    return __x.swap(__y);
29444684ddb6SLionel Sambuc}
29454684ddb6SLionel Sambuc
29464684ddb6SLionel Sambuc// __lookahead
29474684ddb6SLionel Sambuc
29484684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
29494684ddb6SLionel Sambucclass __lookahead
29504684ddb6SLionel Sambuc    : public __owns_one_state<_CharT>
29514684ddb6SLionel Sambuc{
29524684ddb6SLionel Sambuc    typedef __owns_one_state<_CharT> base;
29534684ddb6SLionel Sambuc
29544684ddb6SLionel Sambuc    basic_regex<_CharT, _Traits> __exp_;
29554684ddb6SLionel Sambuc    unsigned __mexp_;
29564684ddb6SLionel Sambuc    bool __invert_;
29574684ddb6SLionel Sambuc
29584684ddb6SLionel Sambuc    __lookahead(const __lookahead&);
29594684ddb6SLionel Sambuc    __lookahead& operator=(const __lookahead&);
29604684ddb6SLionel Sambucpublic:
29614684ddb6SLionel Sambuc    typedef _VSTD::__state<_CharT> __state;
29624684ddb6SLionel Sambuc
29634684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
29644684ddb6SLionel Sambuc    __lookahead(const basic_regex<_CharT, _Traits>& __exp, bool __invert, __node<_CharT>* __s, unsigned __mexp)
2965*0a6a1f1dSLionel Sambuc        : base(__s), __exp_(__exp), __mexp_(__mexp), __invert_(__invert) {}
29664684ddb6SLionel Sambuc
29674684ddb6SLionel Sambuc    virtual void __exec(__state&) const;
29684684ddb6SLionel Sambuc};
29694684ddb6SLionel Sambuc
29704684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
29714684ddb6SLionel Sambucvoid
29724684ddb6SLionel Sambuc__lookahead<_CharT, _Traits>::__exec(__state& __s) const
29734684ddb6SLionel Sambuc{
29744684ddb6SLionel Sambuc    match_results<const _CharT*> __m;
29754684ddb6SLionel Sambuc    __m.__init(1 + __exp_.mark_count(), __s.__current_, __s.__last_);
29764684ddb6SLionel Sambuc    bool __matched = __exp_.__match_at_start_ecma(__s.__current_, __s.__last_,
29774684ddb6SLionel Sambuc                                                  __m,
29784684ddb6SLionel Sambuc                                                  __s.__flags_ | regex_constants::match_continuous,
29794684ddb6SLionel Sambuc                                                  __s.__at_first_ && __s.__current_ == __s.__first_);
29804684ddb6SLionel Sambuc    if (__matched != __invert_)
29814684ddb6SLionel Sambuc    {
29824684ddb6SLionel Sambuc        __s.__do_ = __state::__accept_but_not_consume;
29834684ddb6SLionel Sambuc        __s.__node_ = this->first();
29844684ddb6SLionel Sambuc        for (unsigned __i = 1; __i < __m.size(); ++__i) {
29854684ddb6SLionel Sambuc            __s.__sub_matches_[__mexp_ + __i - 1] = __m.__matches_[__i];
29864684ddb6SLionel Sambuc        }
29874684ddb6SLionel Sambuc    }
29884684ddb6SLionel Sambuc    else
29894684ddb6SLionel Sambuc    {
29904684ddb6SLionel Sambuc        __s.__do_ = __state::__reject;
29914684ddb6SLionel Sambuc        __s.__node_ = nullptr;
29924684ddb6SLionel Sambuc    }
29934684ddb6SLionel Sambuc}
29944684ddb6SLionel Sambuc
29954684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
29964684ddb6SLionel Sambuctemplate <class _ForwardIterator>
29974684ddb6SLionel Sambuc_ForwardIterator
29984684ddb6SLionel Sambucbasic_regex<_CharT, _Traits>::__parse(_ForwardIterator __first,
29994684ddb6SLionel Sambuc                                      _ForwardIterator __last)
30004684ddb6SLionel Sambuc{
30014684ddb6SLionel Sambuc    {
30024684ddb6SLionel Sambuc        unique_ptr<__node> __h(new __end_state<_CharT>);
30034684ddb6SLionel Sambuc        __start_.reset(new __empty_state<_CharT>(__h.get()));
30044684ddb6SLionel Sambuc        __h.release();
30054684ddb6SLionel Sambuc        __end_ = __start_.get();
30064684ddb6SLionel Sambuc    }
30074684ddb6SLionel Sambuc    switch (__flags_ & 0x1F0)
30084684ddb6SLionel Sambuc    {
30094684ddb6SLionel Sambuc    case ECMAScript:
30104684ddb6SLionel Sambuc        __first = __parse_ecma_exp(__first, __last);
30114684ddb6SLionel Sambuc        break;
30124684ddb6SLionel Sambuc    case basic:
30134684ddb6SLionel Sambuc        __first = __parse_basic_reg_exp(__first, __last);
30144684ddb6SLionel Sambuc        break;
30154684ddb6SLionel Sambuc    case extended:
30164684ddb6SLionel Sambuc    case awk:
30174684ddb6SLionel Sambuc        __first = __parse_extended_reg_exp(__first, __last);
30184684ddb6SLionel Sambuc        break;
30194684ddb6SLionel Sambuc    case grep:
30204684ddb6SLionel Sambuc        __first = __parse_grep(__first, __last);
30214684ddb6SLionel Sambuc        break;
30224684ddb6SLionel Sambuc    case egrep:
30234684ddb6SLionel Sambuc        __first = __parse_egrep(__first, __last);
30244684ddb6SLionel Sambuc        break;
30254684ddb6SLionel Sambuc    default:
3026*0a6a1f1dSLionel Sambuc        __throw_regex_error<regex_constants::__re_err_grammar>();
30274684ddb6SLionel Sambuc    }
30284684ddb6SLionel Sambuc    return __first;
30294684ddb6SLionel Sambuc}
30304684ddb6SLionel Sambuc
30314684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
30324684ddb6SLionel Sambuctemplate <class _ForwardIterator>
30334684ddb6SLionel Sambuc_ForwardIterator
30344684ddb6SLionel Sambucbasic_regex<_CharT, _Traits>::__parse_basic_reg_exp(_ForwardIterator __first,
30354684ddb6SLionel Sambuc                                                    _ForwardIterator __last)
30364684ddb6SLionel Sambuc{
30374684ddb6SLionel Sambuc    if (__first != __last)
30384684ddb6SLionel Sambuc    {
30394684ddb6SLionel Sambuc        if (*__first == '^')
30404684ddb6SLionel Sambuc        {
30414684ddb6SLionel Sambuc            __push_l_anchor();
30424684ddb6SLionel Sambuc            ++__first;
30434684ddb6SLionel Sambuc        }
30444684ddb6SLionel Sambuc        if (__first != __last)
30454684ddb6SLionel Sambuc        {
30464684ddb6SLionel Sambuc            __first = __parse_RE_expression(__first, __last);
30474684ddb6SLionel Sambuc            if (__first != __last)
30484684ddb6SLionel Sambuc            {
30494684ddb6SLionel Sambuc                _ForwardIterator __temp = _VSTD::next(__first);
30504684ddb6SLionel Sambuc                if (__temp == __last && *__first == '$')
30514684ddb6SLionel Sambuc                {
30524684ddb6SLionel Sambuc                    __push_r_anchor();
30534684ddb6SLionel Sambuc                    ++__first;
30544684ddb6SLionel Sambuc                }
30554684ddb6SLionel Sambuc            }
30564684ddb6SLionel Sambuc        }
30574684ddb6SLionel Sambuc        if (__first != __last)
3058*0a6a1f1dSLionel Sambuc            __throw_regex_error<regex_constants::__re_err_empty>();
30594684ddb6SLionel Sambuc    }
30604684ddb6SLionel Sambuc    return __first;
30614684ddb6SLionel Sambuc}
30624684ddb6SLionel Sambuc
30634684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
30644684ddb6SLionel Sambuctemplate <class _ForwardIterator>
30654684ddb6SLionel Sambuc_ForwardIterator
30664684ddb6SLionel Sambucbasic_regex<_CharT, _Traits>::__parse_extended_reg_exp(_ForwardIterator __first,
30674684ddb6SLionel Sambuc                                                       _ForwardIterator __last)
30684684ddb6SLionel Sambuc{
30694684ddb6SLionel Sambuc    __owns_one_state<_CharT>* __sa = __end_;
30704684ddb6SLionel Sambuc    _ForwardIterator __temp = __parse_ERE_branch(__first, __last);
30714684ddb6SLionel Sambuc    if (__temp == __first)
3072*0a6a1f1dSLionel Sambuc        __throw_regex_error<regex_constants::__re_err_empty>();
30734684ddb6SLionel Sambuc    __first = __temp;
30744684ddb6SLionel Sambuc    while (__first != __last && *__first == '|')
30754684ddb6SLionel Sambuc    {
30764684ddb6SLionel Sambuc        __owns_one_state<_CharT>* __sb = __end_;
30774684ddb6SLionel Sambuc        __temp = __parse_ERE_branch(++__first, __last);
30784684ddb6SLionel Sambuc        if (__temp == __first)
3079*0a6a1f1dSLionel Sambuc            __throw_regex_error<regex_constants::__re_err_empty>();
30804684ddb6SLionel Sambuc        __push_alternation(__sa, __sb);
30814684ddb6SLionel Sambuc        __first = __temp;
30824684ddb6SLionel Sambuc    }
30834684ddb6SLionel Sambuc    return __first;
30844684ddb6SLionel Sambuc}
30854684ddb6SLionel Sambuc
30864684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
30874684ddb6SLionel Sambuctemplate <class _ForwardIterator>
30884684ddb6SLionel Sambuc_ForwardIterator
30894684ddb6SLionel Sambucbasic_regex<_CharT, _Traits>::__parse_ERE_branch(_ForwardIterator __first,
30904684ddb6SLionel Sambuc                                                 _ForwardIterator __last)
30914684ddb6SLionel Sambuc{
30924684ddb6SLionel Sambuc    _ForwardIterator __temp = __parse_ERE_expression(__first, __last);
30934684ddb6SLionel Sambuc    if (__temp == __first)
3094*0a6a1f1dSLionel Sambuc        __throw_regex_error<regex_constants::__re_err_empty>();
30954684ddb6SLionel Sambuc    do
30964684ddb6SLionel Sambuc    {
30974684ddb6SLionel Sambuc        __first = __temp;
30984684ddb6SLionel Sambuc        __temp = __parse_ERE_expression(__first, __last);
30994684ddb6SLionel Sambuc    } while (__temp != __first);
31004684ddb6SLionel Sambuc    return __first;
31014684ddb6SLionel Sambuc}
31024684ddb6SLionel Sambuc
31034684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
31044684ddb6SLionel Sambuctemplate <class _ForwardIterator>
31054684ddb6SLionel Sambuc_ForwardIterator
31064684ddb6SLionel Sambucbasic_regex<_CharT, _Traits>::__parse_ERE_expression(_ForwardIterator __first,
31074684ddb6SLionel Sambuc                                                     _ForwardIterator __last)
31084684ddb6SLionel Sambuc{
31094684ddb6SLionel Sambuc    __owns_one_state<_CharT>* __e = __end_;
31104684ddb6SLionel Sambuc    unsigned __mexp_begin = __marked_count_;
31114684ddb6SLionel Sambuc    _ForwardIterator __temp = __parse_one_char_or_coll_elem_ERE(__first, __last);
31124684ddb6SLionel Sambuc    if (__temp == __first && __temp != __last)
31134684ddb6SLionel Sambuc    {
31144684ddb6SLionel Sambuc        switch (*__temp)
31154684ddb6SLionel Sambuc        {
31164684ddb6SLionel Sambuc        case '^':
31174684ddb6SLionel Sambuc            __push_l_anchor();
31184684ddb6SLionel Sambuc            ++__temp;
31194684ddb6SLionel Sambuc            break;
31204684ddb6SLionel Sambuc        case '$':
31214684ddb6SLionel Sambuc            __push_r_anchor();
31224684ddb6SLionel Sambuc            ++__temp;
31234684ddb6SLionel Sambuc            break;
31244684ddb6SLionel Sambuc        case '(':
31254684ddb6SLionel Sambuc            __push_begin_marked_subexpression();
31264684ddb6SLionel Sambuc            unsigned __temp_count = __marked_count_;
31274684ddb6SLionel Sambuc            ++__open_count_;
31284684ddb6SLionel Sambuc            __temp = __parse_extended_reg_exp(++__temp, __last);
31294684ddb6SLionel Sambuc            if (__temp == __last || *__temp != ')')
3130*0a6a1f1dSLionel Sambuc                __throw_regex_error<regex_constants::error_paren>();
31314684ddb6SLionel Sambuc            __push_end_marked_subexpression(__temp_count);
31324684ddb6SLionel Sambuc            --__open_count_;
31334684ddb6SLionel Sambuc            ++__temp;
31344684ddb6SLionel Sambuc            break;
31354684ddb6SLionel Sambuc        }
31364684ddb6SLionel Sambuc    }
31374684ddb6SLionel Sambuc    if (__temp != __first)
31384684ddb6SLionel Sambuc        __temp = __parse_ERE_dupl_symbol(__temp, __last, __e, __mexp_begin+1,
31394684ddb6SLionel Sambuc                                         __marked_count_+1);
31404684ddb6SLionel Sambuc    __first = __temp;
31414684ddb6SLionel Sambuc    return __first;
31424684ddb6SLionel Sambuc}
31434684ddb6SLionel Sambuc
31444684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
31454684ddb6SLionel Sambuctemplate <class _ForwardIterator>
31464684ddb6SLionel Sambuc_ForwardIterator
31474684ddb6SLionel Sambucbasic_regex<_CharT, _Traits>::__parse_RE_expression(_ForwardIterator __first,
31484684ddb6SLionel Sambuc                                                    _ForwardIterator __last)
31494684ddb6SLionel Sambuc{
31504684ddb6SLionel Sambuc    while (true)
31514684ddb6SLionel Sambuc    {
31524684ddb6SLionel Sambuc        _ForwardIterator __temp = __parse_simple_RE(__first, __last);
31534684ddb6SLionel Sambuc        if (__temp == __first)
31544684ddb6SLionel Sambuc            break;
31554684ddb6SLionel Sambuc        __first = __temp;
31564684ddb6SLionel Sambuc    }
31574684ddb6SLionel Sambuc    return __first;
31584684ddb6SLionel Sambuc}
31594684ddb6SLionel Sambuc
31604684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
31614684ddb6SLionel Sambuctemplate <class _ForwardIterator>
31624684ddb6SLionel Sambuc_ForwardIterator
31634684ddb6SLionel Sambucbasic_regex<_CharT, _Traits>::__parse_simple_RE(_ForwardIterator __first,
31644684ddb6SLionel Sambuc                                                _ForwardIterator __last)
31654684ddb6SLionel Sambuc{
31664684ddb6SLionel Sambuc    if (__first != __last)
31674684ddb6SLionel Sambuc    {
31684684ddb6SLionel Sambuc        __owns_one_state<_CharT>* __e = __end_;
31694684ddb6SLionel Sambuc        unsigned __mexp_begin = __marked_count_;
31704684ddb6SLionel Sambuc        _ForwardIterator __temp = __parse_nondupl_RE(__first, __last);
31714684ddb6SLionel Sambuc        if (__temp != __first)
31724684ddb6SLionel Sambuc            __first = __parse_RE_dupl_symbol(__temp, __last, __e,
31734684ddb6SLionel Sambuc                                             __mexp_begin+1, __marked_count_+1);
31744684ddb6SLionel Sambuc    }
31754684ddb6SLionel Sambuc    return __first;
31764684ddb6SLionel Sambuc}
31774684ddb6SLionel Sambuc
31784684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
31794684ddb6SLionel Sambuctemplate <class _ForwardIterator>
31804684ddb6SLionel Sambuc_ForwardIterator
31814684ddb6SLionel Sambucbasic_regex<_CharT, _Traits>::__parse_nondupl_RE(_ForwardIterator __first,
31824684ddb6SLionel Sambuc                                                 _ForwardIterator __last)
31834684ddb6SLionel Sambuc{
31844684ddb6SLionel Sambuc    _ForwardIterator __temp = __first;
31854684ddb6SLionel Sambuc    __first = __parse_one_char_or_coll_elem_RE(__first, __last);
31864684ddb6SLionel Sambuc    if (__temp == __first)
31874684ddb6SLionel Sambuc    {
31884684ddb6SLionel Sambuc        __temp = __parse_Back_open_paren(__first, __last);
31894684ddb6SLionel Sambuc        if (__temp != __first)
31904684ddb6SLionel Sambuc        {
31914684ddb6SLionel Sambuc            __push_begin_marked_subexpression();
31924684ddb6SLionel Sambuc            unsigned __temp_count = __marked_count_;
31934684ddb6SLionel Sambuc            __first = __parse_RE_expression(__temp, __last);
31944684ddb6SLionel Sambuc            __temp = __parse_Back_close_paren(__first, __last);
31954684ddb6SLionel Sambuc            if (__temp == __first)
3196*0a6a1f1dSLionel Sambuc                __throw_regex_error<regex_constants::error_paren>();
31974684ddb6SLionel Sambuc            __push_end_marked_subexpression(__temp_count);
31984684ddb6SLionel Sambuc            __first = __temp;
31994684ddb6SLionel Sambuc        }
32004684ddb6SLionel Sambuc        else
32014684ddb6SLionel Sambuc            __first = __parse_BACKREF(__first, __last);
32024684ddb6SLionel Sambuc    }
32034684ddb6SLionel Sambuc    return __first;
32044684ddb6SLionel Sambuc}
32054684ddb6SLionel Sambuc
32064684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
32074684ddb6SLionel Sambuctemplate <class _ForwardIterator>
32084684ddb6SLionel Sambuc_ForwardIterator
32094684ddb6SLionel Sambucbasic_regex<_CharT, _Traits>::__parse_one_char_or_coll_elem_RE(
32104684ddb6SLionel Sambuc                                                       _ForwardIterator __first,
32114684ddb6SLionel Sambuc                                                       _ForwardIterator __last)
32124684ddb6SLionel Sambuc{
32134684ddb6SLionel Sambuc    _ForwardIterator __temp = __parse_ORD_CHAR(__first, __last);
32144684ddb6SLionel Sambuc    if (__temp == __first)
32154684ddb6SLionel Sambuc    {
32164684ddb6SLionel Sambuc        __temp = __parse_QUOTED_CHAR(__first, __last);
32174684ddb6SLionel Sambuc        if (__temp == __first)
32184684ddb6SLionel Sambuc        {
32194684ddb6SLionel Sambuc            if (__temp != __last && *__temp == '.')
32204684ddb6SLionel Sambuc            {
32214684ddb6SLionel Sambuc                __push_match_any();
32224684ddb6SLionel Sambuc                ++__temp;
32234684ddb6SLionel Sambuc            }
32244684ddb6SLionel Sambuc            else
32254684ddb6SLionel Sambuc                __temp = __parse_bracket_expression(__first, __last);
32264684ddb6SLionel Sambuc        }
32274684ddb6SLionel Sambuc    }
32284684ddb6SLionel Sambuc    __first = __temp;
32294684ddb6SLionel Sambuc    return __first;
32304684ddb6SLionel Sambuc}
32314684ddb6SLionel Sambuc
32324684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
32334684ddb6SLionel Sambuctemplate <class _ForwardIterator>
32344684ddb6SLionel Sambuc_ForwardIterator
32354684ddb6SLionel Sambucbasic_regex<_CharT, _Traits>::__parse_one_char_or_coll_elem_ERE(
32364684ddb6SLionel Sambuc                                                       _ForwardIterator __first,
32374684ddb6SLionel Sambuc                                                       _ForwardIterator __last)
32384684ddb6SLionel Sambuc{
32394684ddb6SLionel Sambuc    _ForwardIterator __temp = __parse_ORD_CHAR_ERE(__first, __last);
32404684ddb6SLionel Sambuc    if (__temp == __first)
32414684ddb6SLionel Sambuc    {
32424684ddb6SLionel Sambuc        __temp = __parse_QUOTED_CHAR_ERE(__first, __last);
32434684ddb6SLionel Sambuc        if (__temp == __first)
32444684ddb6SLionel Sambuc        {
32454684ddb6SLionel Sambuc            if (__temp != __last && *__temp == '.')
32464684ddb6SLionel Sambuc            {
32474684ddb6SLionel Sambuc                __push_match_any();
32484684ddb6SLionel Sambuc                ++__temp;
32494684ddb6SLionel Sambuc            }
32504684ddb6SLionel Sambuc            else
32514684ddb6SLionel Sambuc                __temp = __parse_bracket_expression(__first, __last);
32524684ddb6SLionel Sambuc        }
32534684ddb6SLionel Sambuc    }
32544684ddb6SLionel Sambuc    __first = __temp;
32554684ddb6SLionel Sambuc    return __first;
32564684ddb6SLionel Sambuc}
32574684ddb6SLionel Sambuc
32584684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
32594684ddb6SLionel Sambuctemplate <class _ForwardIterator>
32604684ddb6SLionel Sambuc_ForwardIterator
32614684ddb6SLionel Sambucbasic_regex<_CharT, _Traits>::__parse_Back_open_paren(_ForwardIterator __first,
32624684ddb6SLionel Sambuc                                                      _ForwardIterator __last)
32634684ddb6SLionel Sambuc{
32644684ddb6SLionel Sambuc    if (__first != __last)
32654684ddb6SLionel Sambuc    {
32664684ddb6SLionel Sambuc        _ForwardIterator __temp = _VSTD::next(__first);
32674684ddb6SLionel Sambuc        if (__temp != __last)
32684684ddb6SLionel Sambuc        {
32694684ddb6SLionel Sambuc            if (*__first == '\\' && *__temp == '(')
32704684ddb6SLionel Sambuc                __first = ++__temp;
32714684ddb6SLionel Sambuc        }
32724684ddb6SLionel Sambuc    }
32734684ddb6SLionel Sambuc    return __first;
32744684ddb6SLionel Sambuc}
32754684ddb6SLionel Sambuc
32764684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
32774684ddb6SLionel Sambuctemplate <class _ForwardIterator>
32784684ddb6SLionel Sambuc_ForwardIterator
32794684ddb6SLionel Sambucbasic_regex<_CharT, _Traits>::__parse_Back_close_paren(_ForwardIterator __first,
32804684ddb6SLionel Sambuc                                                       _ForwardIterator __last)
32814684ddb6SLionel Sambuc{
32824684ddb6SLionel Sambuc    if (__first != __last)
32834684ddb6SLionel Sambuc    {
32844684ddb6SLionel Sambuc        _ForwardIterator __temp = _VSTD::next(__first);
32854684ddb6SLionel Sambuc        if (__temp != __last)
32864684ddb6SLionel Sambuc        {
32874684ddb6SLionel Sambuc            if (*__first == '\\' && *__temp == ')')
32884684ddb6SLionel Sambuc                __first = ++__temp;
32894684ddb6SLionel Sambuc        }
32904684ddb6SLionel Sambuc    }
32914684ddb6SLionel Sambuc    return __first;
32924684ddb6SLionel Sambuc}
32934684ddb6SLionel Sambuc
32944684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
32954684ddb6SLionel Sambuctemplate <class _ForwardIterator>
32964684ddb6SLionel Sambuc_ForwardIterator
32974684ddb6SLionel Sambucbasic_regex<_CharT, _Traits>::__parse_Back_open_brace(_ForwardIterator __first,
32984684ddb6SLionel Sambuc                                                      _ForwardIterator __last)
32994684ddb6SLionel Sambuc{
33004684ddb6SLionel Sambuc    if (__first != __last)
33014684ddb6SLionel Sambuc    {
33024684ddb6SLionel Sambuc        _ForwardIterator __temp = _VSTD::next(__first);
33034684ddb6SLionel Sambuc        if (__temp != __last)
33044684ddb6SLionel Sambuc        {
33054684ddb6SLionel Sambuc            if (*__first == '\\' && *__temp == '{')
33064684ddb6SLionel Sambuc                __first = ++__temp;
33074684ddb6SLionel Sambuc        }
33084684ddb6SLionel Sambuc    }
33094684ddb6SLionel Sambuc    return __first;
33104684ddb6SLionel Sambuc}
33114684ddb6SLionel Sambuc
33124684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
33134684ddb6SLionel Sambuctemplate <class _ForwardIterator>
33144684ddb6SLionel Sambuc_ForwardIterator
33154684ddb6SLionel Sambucbasic_regex<_CharT, _Traits>::__parse_Back_close_brace(_ForwardIterator __first,
33164684ddb6SLionel Sambuc                                                       _ForwardIterator __last)
33174684ddb6SLionel Sambuc{
33184684ddb6SLionel Sambuc    if (__first != __last)
33194684ddb6SLionel Sambuc    {
33204684ddb6SLionel Sambuc        _ForwardIterator __temp = _VSTD::next(__first);
33214684ddb6SLionel Sambuc        if (__temp != __last)
33224684ddb6SLionel Sambuc        {
33234684ddb6SLionel Sambuc            if (*__first == '\\' && *__temp == '}')
33244684ddb6SLionel Sambuc                __first = ++__temp;
33254684ddb6SLionel Sambuc        }
33264684ddb6SLionel Sambuc    }
33274684ddb6SLionel Sambuc    return __first;
33284684ddb6SLionel Sambuc}
33294684ddb6SLionel Sambuc
33304684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
33314684ddb6SLionel Sambuctemplate <class _ForwardIterator>
33324684ddb6SLionel Sambuc_ForwardIterator
33334684ddb6SLionel Sambucbasic_regex<_CharT, _Traits>::__parse_BACKREF(_ForwardIterator __first,
33344684ddb6SLionel Sambuc                                              _ForwardIterator __last)
33354684ddb6SLionel Sambuc{
33364684ddb6SLionel Sambuc    if (__first != __last)
33374684ddb6SLionel Sambuc    {
33384684ddb6SLionel Sambuc        _ForwardIterator __temp = _VSTD::next(__first);
33394684ddb6SLionel Sambuc        if (__temp != __last)
33404684ddb6SLionel Sambuc        {
3341*0a6a1f1dSLionel Sambuc            if (*__first == '\\')
33424684ddb6SLionel Sambuc            {
3343*0a6a1f1dSLionel Sambuc                int __val = __traits_.value(*__temp, 10);
3344*0a6a1f1dSLionel Sambuc                if (__val >= 1 && __val <= 9)
3345*0a6a1f1dSLionel Sambuc                {
3346*0a6a1f1dSLionel Sambuc                    __push_back_ref(__val);
33474684ddb6SLionel Sambuc                    __first = ++__temp;
33484684ddb6SLionel Sambuc                }
33494684ddb6SLionel Sambuc            }
33504684ddb6SLionel Sambuc        }
3351*0a6a1f1dSLionel Sambuc    }
33524684ddb6SLionel Sambuc    return __first;
33534684ddb6SLionel Sambuc}
33544684ddb6SLionel Sambuc
33554684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
33564684ddb6SLionel Sambuctemplate <class _ForwardIterator>
33574684ddb6SLionel Sambuc_ForwardIterator
33584684ddb6SLionel Sambucbasic_regex<_CharT, _Traits>::__parse_ORD_CHAR(_ForwardIterator __first,
33594684ddb6SLionel Sambuc                                               _ForwardIterator __last)
33604684ddb6SLionel Sambuc{
33614684ddb6SLionel Sambuc    if (__first != __last)
33624684ddb6SLionel Sambuc    {
33634684ddb6SLionel Sambuc        _ForwardIterator __temp = _VSTD::next(__first);
33644684ddb6SLionel Sambuc        if (__temp == __last && *__first == '$')
33654684ddb6SLionel Sambuc            return __first;
33664684ddb6SLionel Sambuc        // Not called inside a bracket
33674684ddb6SLionel Sambuc        if (*__first == '.' || *__first == '\\' || *__first == '[')
33684684ddb6SLionel Sambuc            return __first;
33694684ddb6SLionel Sambuc        __push_char(*__first);
33704684ddb6SLionel Sambuc        ++__first;
33714684ddb6SLionel Sambuc    }
33724684ddb6SLionel Sambuc    return __first;
33734684ddb6SLionel Sambuc}
33744684ddb6SLionel Sambuc
33754684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
33764684ddb6SLionel Sambuctemplate <class _ForwardIterator>
33774684ddb6SLionel Sambuc_ForwardIterator
33784684ddb6SLionel Sambucbasic_regex<_CharT, _Traits>::__parse_ORD_CHAR_ERE(_ForwardIterator __first,
33794684ddb6SLionel Sambuc                                                   _ForwardIterator __last)
33804684ddb6SLionel Sambuc{
33814684ddb6SLionel Sambuc    if (__first != __last)
33824684ddb6SLionel Sambuc    {
33834684ddb6SLionel Sambuc        switch (*__first)
33844684ddb6SLionel Sambuc        {
33854684ddb6SLionel Sambuc        case '^':
33864684ddb6SLionel Sambuc        case '.':
33874684ddb6SLionel Sambuc        case '[':
33884684ddb6SLionel Sambuc        case '$':
33894684ddb6SLionel Sambuc        case '(':
33904684ddb6SLionel Sambuc        case '|':
33914684ddb6SLionel Sambuc        case '*':
33924684ddb6SLionel Sambuc        case '+':
33934684ddb6SLionel Sambuc        case '?':
33944684ddb6SLionel Sambuc        case '{':
33954684ddb6SLionel Sambuc        case '\\':
33964684ddb6SLionel Sambuc            break;
33974684ddb6SLionel Sambuc        case ')':
33984684ddb6SLionel Sambuc            if (__open_count_ == 0)
33994684ddb6SLionel Sambuc            {
34004684ddb6SLionel Sambuc                __push_char(*__first);
34014684ddb6SLionel Sambuc                ++__first;
34024684ddb6SLionel Sambuc            }
34034684ddb6SLionel Sambuc            break;
34044684ddb6SLionel Sambuc        default:
34054684ddb6SLionel Sambuc            __push_char(*__first);
34064684ddb6SLionel Sambuc            ++__first;
34074684ddb6SLionel Sambuc            break;
34084684ddb6SLionel Sambuc        }
34094684ddb6SLionel Sambuc    }
34104684ddb6SLionel Sambuc    return __first;
34114684ddb6SLionel Sambuc}
34124684ddb6SLionel Sambuc
34134684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
34144684ddb6SLionel Sambuctemplate <class _ForwardIterator>
34154684ddb6SLionel Sambuc_ForwardIterator
34164684ddb6SLionel Sambucbasic_regex<_CharT, _Traits>::__parse_QUOTED_CHAR(_ForwardIterator __first,
34174684ddb6SLionel Sambuc                                                  _ForwardIterator __last)
34184684ddb6SLionel Sambuc{
34194684ddb6SLionel Sambuc    if (__first != __last)
34204684ddb6SLionel Sambuc    {
34214684ddb6SLionel Sambuc        _ForwardIterator __temp = _VSTD::next(__first);
34224684ddb6SLionel Sambuc        if (__temp != __last)
34234684ddb6SLionel Sambuc        {
34244684ddb6SLionel Sambuc            if (*__first == '\\')
34254684ddb6SLionel Sambuc            {
34264684ddb6SLionel Sambuc                switch (*__temp)
34274684ddb6SLionel Sambuc                {
34284684ddb6SLionel Sambuc                case '^':
34294684ddb6SLionel Sambuc                case '.':
34304684ddb6SLionel Sambuc                case '*':
34314684ddb6SLionel Sambuc                case '[':
34324684ddb6SLionel Sambuc                case '$':
34334684ddb6SLionel Sambuc                case '\\':
34344684ddb6SLionel Sambuc                    __push_char(*__temp);
34354684ddb6SLionel Sambuc                    __first = ++__temp;
34364684ddb6SLionel Sambuc                    break;
34374684ddb6SLionel Sambuc                }
34384684ddb6SLionel Sambuc            }
34394684ddb6SLionel Sambuc        }
34404684ddb6SLionel Sambuc    }
34414684ddb6SLionel Sambuc    return __first;
34424684ddb6SLionel Sambuc}
34434684ddb6SLionel Sambuc
34444684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
34454684ddb6SLionel Sambuctemplate <class _ForwardIterator>
34464684ddb6SLionel Sambuc_ForwardIterator
34474684ddb6SLionel Sambucbasic_regex<_CharT, _Traits>::__parse_QUOTED_CHAR_ERE(_ForwardIterator __first,
34484684ddb6SLionel Sambuc                                                      _ForwardIterator __last)
34494684ddb6SLionel Sambuc{
34504684ddb6SLionel Sambuc    if (__first != __last)
34514684ddb6SLionel Sambuc    {
34524684ddb6SLionel Sambuc        _ForwardIterator __temp = _VSTD::next(__first);
34534684ddb6SLionel Sambuc        if (__temp != __last)
34544684ddb6SLionel Sambuc        {
34554684ddb6SLionel Sambuc            if (*__first == '\\')
34564684ddb6SLionel Sambuc            {
34574684ddb6SLionel Sambuc                switch (*__temp)
34584684ddb6SLionel Sambuc                {
34594684ddb6SLionel Sambuc                case '^':
34604684ddb6SLionel Sambuc                case '.':
34614684ddb6SLionel Sambuc                case '*':
34624684ddb6SLionel Sambuc                case '[':
34634684ddb6SLionel Sambuc                case '$':
34644684ddb6SLionel Sambuc                case '\\':
34654684ddb6SLionel Sambuc                case '(':
34664684ddb6SLionel Sambuc                case ')':
34674684ddb6SLionel Sambuc                case '|':
34684684ddb6SLionel Sambuc                case '+':
34694684ddb6SLionel Sambuc                case '?':
34704684ddb6SLionel Sambuc                case '{':
34714684ddb6SLionel Sambuc                case '}':
34724684ddb6SLionel Sambuc                    __push_char(*__temp);
34734684ddb6SLionel Sambuc                    __first = ++__temp;
34744684ddb6SLionel Sambuc                    break;
34754684ddb6SLionel Sambuc                default:
34764684ddb6SLionel Sambuc                    if ((__flags_ & 0x1F0) == awk)
34774684ddb6SLionel Sambuc                        __first = __parse_awk_escape(++__first, __last);
34784684ddb6SLionel Sambuc                    break;
34794684ddb6SLionel Sambuc                }
34804684ddb6SLionel Sambuc            }
34814684ddb6SLionel Sambuc        }
34824684ddb6SLionel Sambuc    }
34834684ddb6SLionel Sambuc    return __first;
34844684ddb6SLionel Sambuc}
34854684ddb6SLionel Sambuc
34864684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
34874684ddb6SLionel Sambuctemplate <class _ForwardIterator>
34884684ddb6SLionel Sambuc_ForwardIterator
34894684ddb6SLionel Sambucbasic_regex<_CharT, _Traits>::__parse_RE_dupl_symbol(_ForwardIterator __first,
34904684ddb6SLionel Sambuc                                                     _ForwardIterator __last,
34914684ddb6SLionel Sambuc                                                     __owns_one_state<_CharT>* __s,
34924684ddb6SLionel Sambuc                                                     unsigned __mexp_begin,
34934684ddb6SLionel Sambuc                                                     unsigned __mexp_end)
34944684ddb6SLionel Sambuc{
34954684ddb6SLionel Sambuc    if (__first != __last)
34964684ddb6SLionel Sambuc    {
34974684ddb6SLionel Sambuc        if (*__first == '*')
34984684ddb6SLionel Sambuc        {
34994684ddb6SLionel Sambuc            __push_greedy_inf_repeat(0, __s, __mexp_begin, __mexp_end);
35004684ddb6SLionel Sambuc            ++__first;
35014684ddb6SLionel Sambuc        }
35024684ddb6SLionel Sambuc        else
35034684ddb6SLionel Sambuc        {
35044684ddb6SLionel Sambuc            _ForwardIterator __temp = __parse_Back_open_brace(__first, __last);
35054684ddb6SLionel Sambuc            if (__temp != __first)
35064684ddb6SLionel Sambuc            {
35074684ddb6SLionel Sambuc                int __min = 0;
35084684ddb6SLionel Sambuc                __first = __temp;
35094684ddb6SLionel Sambuc                __temp = __parse_DUP_COUNT(__first, __last, __min);
35104684ddb6SLionel Sambuc                if (__temp == __first)
3511*0a6a1f1dSLionel Sambuc                    __throw_regex_error<regex_constants::error_badbrace>();
35124684ddb6SLionel Sambuc                __first = __temp;
35134684ddb6SLionel Sambuc                if (__first == __last)
3514*0a6a1f1dSLionel Sambuc                    __throw_regex_error<regex_constants::error_brace>();
35154684ddb6SLionel Sambuc                if (*__first != ',')
35164684ddb6SLionel Sambuc                {
35174684ddb6SLionel Sambuc                    __temp = __parse_Back_close_brace(__first, __last);
35184684ddb6SLionel Sambuc                    if (__temp == __first)
3519*0a6a1f1dSLionel Sambuc                        __throw_regex_error<regex_constants::error_brace>();
35204684ddb6SLionel Sambuc                    __push_loop(__min, __min, __s, __mexp_begin, __mexp_end,
35214684ddb6SLionel Sambuc                                    true);
35224684ddb6SLionel Sambuc                    __first = __temp;
35234684ddb6SLionel Sambuc                }
35244684ddb6SLionel Sambuc                else
35254684ddb6SLionel Sambuc                {
35264684ddb6SLionel Sambuc                    ++__first;  // consume ','
35274684ddb6SLionel Sambuc                    int __max = -1;
35284684ddb6SLionel Sambuc                    __first = __parse_DUP_COUNT(__first, __last, __max);
35294684ddb6SLionel Sambuc                    __temp = __parse_Back_close_brace(__first, __last);
35304684ddb6SLionel Sambuc                    if (__temp == __first)
3531*0a6a1f1dSLionel Sambuc                        __throw_regex_error<regex_constants::error_brace>();
35324684ddb6SLionel Sambuc                    if (__max == -1)
35334684ddb6SLionel Sambuc                        __push_greedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end);
35344684ddb6SLionel Sambuc                    else
35354684ddb6SLionel Sambuc                    {
35364684ddb6SLionel Sambuc                        if (__max < __min)
3537*0a6a1f1dSLionel Sambuc                            __throw_regex_error<regex_constants::error_badbrace>();
35384684ddb6SLionel Sambuc                        __push_loop(__min, __max, __s, __mexp_begin, __mexp_end,
35394684ddb6SLionel Sambuc                                    true);
35404684ddb6SLionel Sambuc                    }
35414684ddb6SLionel Sambuc                    __first = __temp;
35424684ddb6SLionel Sambuc                }
35434684ddb6SLionel Sambuc            }
35444684ddb6SLionel Sambuc        }
35454684ddb6SLionel Sambuc    }
35464684ddb6SLionel Sambuc    return __first;
35474684ddb6SLionel Sambuc}
35484684ddb6SLionel Sambuc
35494684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
35504684ddb6SLionel Sambuctemplate <class _ForwardIterator>
35514684ddb6SLionel Sambuc_ForwardIterator
35524684ddb6SLionel Sambucbasic_regex<_CharT, _Traits>::__parse_ERE_dupl_symbol(_ForwardIterator __first,
35534684ddb6SLionel Sambuc                                                      _ForwardIterator __last,
35544684ddb6SLionel Sambuc                                                      __owns_one_state<_CharT>* __s,
35554684ddb6SLionel Sambuc                                                      unsigned __mexp_begin,
35564684ddb6SLionel Sambuc                                                      unsigned __mexp_end)
35574684ddb6SLionel Sambuc{
35584684ddb6SLionel Sambuc    if (__first != __last)
35594684ddb6SLionel Sambuc    {
35604684ddb6SLionel Sambuc        unsigned __grammar = __flags_ & 0x1F0;
35614684ddb6SLionel Sambuc        switch (*__first)
35624684ddb6SLionel Sambuc        {
35634684ddb6SLionel Sambuc        case '*':
35644684ddb6SLionel Sambuc            ++__first;
35654684ddb6SLionel Sambuc            if (__grammar == ECMAScript && __first != __last && *__first == '?')
35664684ddb6SLionel Sambuc            {
35674684ddb6SLionel Sambuc                ++__first;
35684684ddb6SLionel Sambuc                __push_nongreedy_inf_repeat(0, __s, __mexp_begin, __mexp_end);
35694684ddb6SLionel Sambuc            }
35704684ddb6SLionel Sambuc            else
35714684ddb6SLionel Sambuc                __push_greedy_inf_repeat(0, __s, __mexp_begin, __mexp_end);
35724684ddb6SLionel Sambuc            break;
35734684ddb6SLionel Sambuc        case '+':
35744684ddb6SLionel Sambuc            ++__first;
35754684ddb6SLionel Sambuc            if (__grammar == ECMAScript && __first != __last && *__first == '?')
35764684ddb6SLionel Sambuc            {
35774684ddb6SLionel Sambuc                ++__first;
35784684ddb6SLionel Sambuc                __push_nongreedy_inf_repeat(1, __s, __mexp_begin, __mexp_end);
35794684ddb6SLionel Sambuc            }
35804684ddb6SLionel Sambuc            else
35814684ddb6SLionel Sambuc                __push_greedy_inf_repeat(1, __s, __mexp_begin, __mexp_end);
35824684ddb6SLionel Sambuc            break;
35834684ddb6SLionel Sambuc        case '?':
35844684ddb6SLionel Sambuc            ++__first;
35854684ddb6SLionel Sambuc            if (__grammar == ECMAScript && __first != __last && *__first == '?')
35864684ddb6SLionel Sambuc            {
35874684ddb6SLionel Sambuc                ++__first;
35884684ddb6SLionel Sambuc                __push_loop(0, 1, __s, __mexp_begin, __mexp_end, false);
35894684ddb6SLionel Sambuc            }
35904684ddb6SLionel Sambuc            else
35914684ddb6SLionel Sambuc                __push_loop(0, 1, __s, __mexp_begin, __mexp_end);
35924684ddb6SLionel Sambuc            break;
35934684ddb6SLionel Sambuc        case '{':
35944684ddb6SLionel Sambuc            {
35954684ddb6SLionel Sambuc                int __min;
35964684ddb6SLionel Sambuc                _ForwardIterator __temp = __parse_DUP_COUNT(++__first, __last, __min);
35974684ddb6SLionel Sambuc                if (__temp == __first)
3598*0a6a1f1dSLionel Sambuc                    __throw_regex_error<regex_constants::error_badbrace>();
35994684ddb6SLionel Sambuc                __first = __temp;
36004684ddb6SLionel Sambuc                if (__first == __last)
3601*0a6a1f1dSLionel Sambuc                    __throw_regex_error<regex_constants::error_brace>();
36024684ddb6SLionel Sambuc                switch (*__first)
36034684ddb6SLionel Sambuc                {
36044684ddb6SLionel Sambuc                case '}':
36054684ddb6SLionel Sambuc                    ++__first;
36064684ddb6SLionel Sambuc                    if (__grammar == ECMAScript && __first != __last && *__first == '?')
36074684ddb6SLionel Sambuc                    {
36084684ddb6SLionel Sambuc                        ++__first;
36094684ddb6SLionel Sambuc                        __push_loop(__min, __min, __s, __mexp_begin, __mexp_end, false);
36104684ddb6SLionel Sambuc                    }
36114684ddb6SLionel Sambuc                    else
36124684ddb6SLionel Sambuc                        __push_loop(__min, __min, __s, __mexp_begin, __mexp_end);
36134684ddb6SLionel Sambuc                    break;
36144684ddb6SLionel Sambuc                case ',':
36154684ddb6SLionel Sambuc                    ++__first;
36164684ddb6SLionel Sambuc                    if (__first == __last)
3617*0a6a1f1dSLionel Sambuc                        __throw_regex_error<regex_constants::error_badbrace>();
36184684ddb6SLionel Sambuc                    if (*__first == '}')
36194684ddb6SLionel Sambuc                    {
36204684ddb6SLionel Sambuc                        ++__first;
36214684ddb6SLionel Sambuc                        if (__grammar == ECMAScript && __first != __last && *__first == '?')
36224684ddb6SLionel Sambuc                        {
36234684ddb6SLionel Sambuc                            ++__first;
36244684ddb6SLionel Sambuc                            __push_nongreedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end);
36254684ddb6SLionel Sambuc                        }
36264684ddb6SLionel Sambuc                        else
36274684ddb6SLionel Sambuc                            __push_greedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end);
36284684ddb6SLionel Sambuc                    }
36294684ddb6SLionel Sambuc                    else
36304684ddb6SLionel Sambuc                    {
36314684ddb6SLionel Sambuc                        int __max = -1;
36324684ddb6SLionel Sambuc                        __temp = __parse_DUP_COUNT(__first, __last, __max);
36334684ddb6SLionel Sambuc                        if (__temp == __first)
3634*0a6a1f1dSLionel Sambuc                            __throw_regex_error<regex_constants::error_brace>();
36354684ddb6SLionel Sambuc                        __first = __temp;
36364684ddb6SLionel Sambuc                        if (__first == __last || *__first != '}')
3637*0a6a1f1dSLionel Sambuc                            __throw_regex_error<regex_constants::error_brace>();
36384684ddb6SLionel Sambuc                        ++__first;
36394684ddb6SLionel Sambuc                        if (__max < __min)
3640*0a6a1f1dSLionel Sambuc                            __throw_regex_error<regex_constants::error_badbrace>();
36414684ddb6SLionel Sambuc                        if (__grammar == ECMAScript && __first != __last && *__first == '?')
36424684ddb6SLionel Sambuc                        {
36434684ddb6SLionel Sambuc                            ++__first;
36444684ddb6SLionel Sambuc                            __push_loop(__min, __max, __s, __mexp_begin, __mexp_end, false);
36454684ddb6SLionel Sambuc                        }
36464684ddb6SLionel Sambuc                        else
36474684ddb6SLionel Sambuc                            __push_loop(__min, __max, __s, __mexp_begin, __mexp_end);
36484684ddb6SLionel Sambuc                    }
36494684ddb6SLionel Sambuc                    break;
36504684ddb6SLionel Sambuc                default:
3651*0a6a1f1dSLionel Sambuc                    __throw_regex_error<regex_constants::error_badbrace>();
36524684ddb6SLionel Sambuc                }
36534684ddb6SLionel Sambuc            }
36544684ddb6SLionel Sambuc            break;
36554684ddb6SLionel Sambuc        }
36564684ddb6SLionel Sambuc    }
36574684ddb6SLionel Sambuc    return __first;
36584684ddb6SLionel Sambuc}
36594684ddb6SLionel Sambuc
36604684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
36614684ddb6SLionel Sambuctemplate <class _ForwardIterator>
36624684ddb6SLionel Sambuc_ForwardIterator
36634684ddb6SLionel Sambucbasic_regex<_CharT, _Traits>::__parse_bracket_expression(_ForwardIterator __first,
36644684ddb6SLionel Sambuc                                                         _ForwardIterator __last)
36654684ddb6SLionel Sambuc{
36664684ddb6SLionel Sambuc    if (__first != __last && *__first == '[')
36674684ddb6SLionel Sambuc    {
36684684ddb6SLionel Sambuc        ++__first;
36694684ddb6SLionel Sambuc        if (__first == __last)
3670*0a6a1f1dSLionel Sambuc            __throw_regex_error<regex_constants::error_brack>();
36714684ddb6SLionel Sambuc        bool __negate = false;
36724684ddb6SLionel Sambuc        if (*__first == '^')
36734684ddb6SLionel Sambuc        {
36744684ddb6SLionel Sambuc            ++__first;
36754684ddb6SLionel Sambuc            __negate = true;
36764684ddb6SLionel Sambuc        }
36774684ddb6SLionel Sambuc        __bracket_expression<_CharT, _Traits>* __ml = __start_matching_list(__negate);
36784684ddb6SLionel Sambuc        // __ml owned by *this
36794684ddb6SLionel Sambuc        if (__first == __last)
3680*0a6a1f1dSLionel Sambuc            __throw_regex_error<regex_constants::error_brack>();
36814684ddb6SLionel Sambuc        if ((__flags_ & 0x1F0) != ECMAScript && *__first == ']')
36824684ddb6SLionel Sambuc        {
36834684ddb6SLionel Sambuc            __ml->__add_char(']');
36844684ddb6SLionel Sambuc            ++__first;
36854684ddb6SLionel Sambuc        }
36864684ddb6SLionel Sambuc        __first = __parse_follow_list(__first, __last, __ml);
36874684ddb6SLionel Sambuc        if (__first == __last)
3688*0a6a1f1dSLionel Sambuc            __throw_regex_error<regex_constants::error_brack>();
36894684ddb6SLionel Sambuc        if (*__first == '-')
36904684ddb6SLionel Sambuc        {
36914684ddb6SLionel Sambuc            __ml->__add_char('-');
36924684ddb6SLionel Sambuc            ++__first;
36934684ddb6SLionel Sambuc        }
36944684ddb6SLionel Sambuc        if (__first == __last || *__first != ']')
3695*0a6a1f1dSLionel Sambuc            __throw_regex_error<regex_constants::error_brack>();
36964684ddb6SLionel Sambuc        ++__first;
36974684ddb6SLionel Sambuc    }
36984684ddb6SLionel Sambuc    return __first;
36994684ddb6SLionel Sambuc}
37004684ddb6SLionel Sambuc
37014684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
37024684ddb6SLionel Sambuctemplate <class _ForwardIterator>
37034684ddb6SLionel Sambuc_ForwardIterator
37044684ddb6SLionel Sambucbasic_regex<_CharT, _Traits>::__parse_follow_list(_ForwardIterator __first,
37054684ddb6SLionel Sambuc                                    _ForwardIterator __last,
37064684ddb6SLionel Sambuc                                    __bracket_expression<_CharT, _Traits>* __ml)
37074684ddb6SLionel Sambuc{
37084684ddb6SLionel Sambuc    if (__first != __last)
37094684ddb6SLionel Sambuc    {
37104684ddb6SLionel Sambuc        while (true)
37114684ddb6SLionel Sambuc        {
37124684ddb6SLionel Sambuc            _ForwardIterator __temp = __parse_expression_term(__first, __last,
37134684ddb6SLionel Sambuc                                                              __ml);
37144684ddb6SLionel Sambuc            if (__temp == __first)
37154684ddb6SLionel Sambuc                break;
37164684ddb6SLionel Sambuc            __first = __temp;
37174684ddb6SLionel Sambuc        }
37184684ddb6SLionel Sambuc    }
37194684ddb6SLionel Sambuc    return __first;
37204684ddb6SLionel Sambuc}
37214684ddb6SLionel Sambuc
37224684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
37234684ddb6SLionel Sambuctemplate <class _ForwardIterator>
37244684ddb6SLionel Sambuc_ForwardIterator
37254684ddb6SLionel Sambucbasic_regex<_CharT, _Traits>::__parse_expression_term(_ForwardIterator __first,
37264684ddb6SLionel Sambuc                                    _ForwardIterator __last,
37274684ddb6SLionel Sambuc                                    __bracket_expression<_CharT, _Traits>* __ml)
37284684ddb6SLionel Sambuc{
37294684ddb6SLionel Sambuc    if (__first != __last && *__first != ']')
37304684ddb6SLionel Sambuc    {
37314684ddb6SLionel Sambuc        _ForwardIterator __temp = _VSTD::next(__first);
37324684ddb6SLionel Sambuc        basic_string<_CharT> __start_range;
37334684ddb6SLionel Sambuc        if (__temp != __last && *__first == '[')
37344684ddb6SLionel Sambuc        {
37354684ddb6SLionel Sambuc            if (*__temp == '=')
37364684ddb6SLionel Sambuc                return __parse_equivalence_class(++__temp, __last, __ml);
37374684ddb6SLionel Sambuc            else if (*__temp == ':')
37384684ddb6SLionel Sambuc                return __parse_character_class(++__temp, __last, __ml);
37394684ddb6SLionel Sambuc            else if (*__temp == '.')
37404684ddb6SLionel Sambuc                __first = __parse_collating_symbol(++__temp, __last, __start_range);
37414684ddb6SLionel Sambuc        }
37424684ddb6SLionel Sambuc        unsigned __grammar = __flags_ & 0x1F0;
37434684ddb6SLionel Sambuc        if (__start_range.empty())
37444684ddb6SLionel Sambuc        {
37454684ddb6SLionel Sambuc            if ((__grammar == ECMAScript || __grammar == awk) && *__first == '\\')
37464684ddb6SLionel Sambuc            {
37474684ddb6SLionel Sambuc                if (__grammar == ECMAScript)
37484684ddb6SLionel Sambuc                    __first = __parse_class_escape(++__first, __last, __start_range, __ml);
37494684ddb6SLionel Sambuc                else
37504684ddb6SLionel Sambuc                    __first = __parse_awk_escape(++__first, __last, &__start_range);
37514684ddb6SLionel Sambuc            }
37524684ddb6SLionel Sambuc            else
37534684ddb6SLionel Sambuc            {
37544684ddb6SLionel Sambuc                __start_range = *__first;
37554684ddb6SLionel Sambuc                ++__first;
37564684ddb6SLionel Sambuc            }
37574684ddb6SLionel Sambuc        }
37584684ddb6SLionel Sambuc        if (__first != __last && *__first != ']')
37594684ddb6SLionel Sambuc        {
37604684ddb6SLionel Sambuc            __temp = _VSTD::next(__first);
37614684ddb6SLionel Sambuc            if (__temp != __last && *__first == '-' && *__temp != ']')
37624684ddb6SLionel Sambuc            {
37634684ddb6SLionel Sambuc                // parse a range
37644684ddb6SLionel Sambuc                basic_string<_CharT> __end_range;
37654684ddb6SLionel Sambuc                __first = __temp;
37664684ddb6SLionel Sambuc                ++__temp;
37674684ddb6SLionel Sambuc                if (__temp != __last && *__first == '[' && *__temp == '.')
37684684ddb6SLionel Sambuc                    __first = __parse_collating_symbol(++__temp, __last, __end_range);
37694684ddb6SLionel Sambuc                else
37704684ddb6SLionel Sambuc                {
37714684ddb6SLionel Sambuc                    if ((__grammar == ECMAScript || __grammar == awk) && *__first == '\\')
37724684ddb6SLionel Sambuc                    {
37734684ddb6SLionel Sambuc                        if (__grammar == ECMAScript)
37744684ddb6SLionel Sambuc                            __first = __parse_class_escape(++__first, __last,
37754684ddb6SLionel Sambuc                                                           __end_range, __ml);
37764684ddb6SLionel Sambuc                        else
37774684ddb6SLionel Sambuc                            __first = __parse_awk_escape(++__first, __last,
37784684ddb6SLionel Sambuc                                                         &__end_range);
37794684ddb6SLionel Sambuc                    }
37804684ddb6SLionel Sambuc                    else
37814684ddb6SLionel Sambuc                    {
37824684ddb6SLionel Sambuc                        __end_range = *__first;
37834684ddb6SLionel Sambuc                        ++__first;
37844684ddb6SLionel Sambuc                    }
37854684ddb6SLionel Sambuc                }
37864684ddb6SLionel Sambuc                __ml->__add_range(_VSTD::move(__start_range), _VSTD::move(__end_range));
37874684ddb6SLionel Sambuc            }
37884684ddb6SLionel Sambuc            else if (!__start_range.empty())
37894684ddb6SLionel Sambuc            {
37904684ddb6SLionel Sambuc                if (__start_range.size() == 1)
37914684ddb6SLionel Sambuc                    __ml->__add_char(__start_range[0]);
37924684ddb6SLionel Sambuc                else
37934684ddb6SLionel Sambuc                    __ml->__add_digraph(__start_range[0], __start_range[1]);
37944684ddb6SLionel Sambuc            }
37954684ddb6SLionel Sambuc        }
37964684ddb6SLionel Sambuc        else if (!__start_range.empty())
37974684ddb6SLionel Sambuc        {
37984684ddb6SLionel Sambuc            if (__start_range.size() == 1)
37994684ddb6SLionel Sambuc                __ml->__add_char(__start_range[0]);
38004684ddb6SLionel Sambuc            else
38014684ddb6SLionel Sambuc                __ml->__add_digraph(__start_range[0], __start_range[1]);
38024684ddb6SLionel Sambuc        }
38034684ddb6SLionel Sambuc    }
38044684ddb6SLionel Sambuc    return __first;
38054684ddb6SLionel Sambuc}
38064684ddb6SLionel Sambuc
38074684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
38084684ddb6SLionel Sambuctemplate <class _ForwardIterator>
38094684ddb6SLionel Sambuc_ForwardIterator
38104684ddb6SLionel Sambucbasic_regex<_CharT, _Traits>::__parse_class_escape(_ForwardIterator __first,
38114684ddb6SLionel Sambuc                          _ForwardIterator __last,
38124684ddb6SLionel Sambuc                          basic_string<_CharT>& __str,
38134684ddb6SLionel Sambuc                          __bracket_expression<_CharT, _Traits>* __ml)
38144684ddb6SLionel Sambuc{
38154684ddb6SLionel Sambuc    if (__first == __last)
3816*0a6a1f1dSLionel Sambuc        __throw_regex_error<regex_constants::error_escape>();
38174684ddb6SLionel Sambuc    switch (*__first)
38184684ddb6SLionel Sambuc    {
38194684ddb6SLionel Sambuc    case 0:
38204684ddb6SLionel Sambuc        __str = *__first;
38214684ddb6SLionel Sambuc        return ++__first;
38224684ddb6SLionel Sambuc    case 'b':
38234684ddb6SLionel Sambuc        __str = _CharT(8);
38244684ddb6SLionel Sambuc        return ++__first;
38254684ddb6SLionel Sambuc    case 'd':
38264684ddb6SLionel Sambuc        __ml->__add_class(ctype_base::digit);
38274684ddb6SLionel Sambuc        return ++__first;
38284684ddb6SLionel Sambuc    case 'D':
38294684ddb6SLionel Sambuc        __ml->__add_neg_class(ctype_base::digit);
38304684ddb6SLionel Sambuc        return ++__first;
38314684ddb6SLionel Sambuc    case 's':
38324684ddb6SLionel Sambuc        __ml->__add_class(ctype_base::space);
38334684ddb6SLionel Sambuc        return ++__first;
38344684ddb6SLionel Sambuc    case 'S':
38354684ddb6SLionel Sambuc        __ml->__add_neg_class(ctype_base::space);
38364684ddb6SLionel Sambuc        return ++__first;
38374684ddb6SLionel Sambuc    case 'w':
38384684ddb6SLionel Sambuc        __ml->__add_class(ctype_base::alnum);
38394684ddb6SLionel Sambuc        __ml->__add_char('_');
38404684ddb6SLionel Sambuc        return ++__first;
38414684ddb6SLionel Sambuc    case 'W':
38424684ddb6SLionel Sambuc        __ml->__add_neg_class(ctype_base::alnum);
38434684ddb6SLionel Sambuc        __ml->__add_neg_char('_');
38444684ddb6SLionel Sambuc        return ++__first;
38454684ddb6SLionel Sambuc    }
38464684ddb6SLionel Sambuc    __first = __parse_character_escape(__first, __last, &__str);
38474684ddb6SLionel Sambuc    return __first;
38484684ddb6SLionel Sambuc}
38494684ddb6SLionel Sambuc
38504684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
38514684ddb6SLionel Sambuctemplate <class _ForwardIterator>
38524684ddb6SLionel Sambuc_ForwardIterator
38534684ddb6SLionel Sambucbasic_regex<_CharT, _Traits>::__parse_awk_escape(_ForwardIterator __first,
38544684ddb6SLionel Sambuc                          _ForwardIterator __last,
38554684ddb6SLionel Sambuc                          basic_string<_CharT>* __str)
38564684ddb6SLionel Sambuc{
38574684ddb6SLionel Sambuc    if (__first == __last)
3858*0a6a1f1dSLionel Sambuc        __throw_regex_error<regex_constants::error_escape>();
38594684ddb6SLionel Sambuc    switch (*__first)
38604684ddb6SLionel Sambuc    {
38614684ddb6SLionel Sambuc    case '\\':
38624684ddb6SLionel Sambuc    case '"':
38634684ddb6SLionel Sambuc    case '/':
38644684ddb6SLionel Sambuc        if (__str)
38654684ddb6SLionel Sambuc            *__str = *__first;
38664684ddb6SLionel Sambuc        else
38674684ddb6SLionel Sambuc            __push_char(*__first);
38684684ddb6SLionel Sambuc        return ++__first;
38694684ddb6SLionel Sambuc    case 'a':
38704684ddb6SLionel Sambuc        if (__str)
38714684ddb6SLionel Sambuc            *__str = _CharT(7);
38724684ddb6SLionel Sambuc        else
38734684ddb6SLionel Sambuc            __push_char(_CharT(7));
38744684ddb6SLionel Sambuc        return ++__first;
38754684ddb6SLionel Sambuc    case 'b':
38764684ddb6SLionel Sambuc        if (__str)
38774684ddb6SLionel Sambuc            *__str = _CharT(8);
38784684ddb6SLionel Sambuc        else
38794684ddb6SLionel Sambuc            __push_char(_CharT(8));
38804684ddb6SLionel Sambuc        return ++__first;
38814684ddb6SLionel Sambuc    case 'f':
38824684ddb6SLionel Sambuc        if (__str)
38834684ddb6SLionel Sambuc            *__str = _CharT(0xC);
38844684ddb6SLionel Sambuc        else
38854684ddb6SLionel Sambuc            __push_char(_CharT(0xC));
38864684ddb6SLionel Sambuc        return ++__first;
38874684ddb6SLionel Sambuc    case 'n':
38884684ddb6SLionel Sambuc        if (__str)
38894684ddb6SLionel Sambuc            *__str = _CharT(0xA);
38904684ddb6SLionel Sambuc        else
38914684ddb6SLionel Sambuc            __push_char(_CharT(0xA));
38924684ddb6SLionel Sambuc        return ++__first;
38934684ddb6SLionel Sambuc    case 'r':
38944684ddb6SLionel Sambuc        if (__str)
38954684ddb6SLionel Sambuc            *__str = _CharT(0xD);
38964684ddb6SLionel Sambuc        else
38974684ddb6SLionel Sambuc            __push_char(_CharT(0xD));
38984684ddb6SLionel Sambuc        return ++__first;
38994684ddb6SLionel Sambuc    case 't':
39004684ddb6SLionel Sambuc        if (__str)
39014684ddb6SLionel Sambuc            *__str = _CharT(0x9);
39024684ddb6SLionel Sambuc        else
39034684ddb6SLionel Sambuc            __push_char(_CharT(0x9));
39044684ddb6SLionel Sambuc        return ++__first;
39054684ddb6SLionel Sambuc    case 'v':
39064684ddb6SLionel Sambuc        if (__str)
39074684ddb6SLionel Sambuc            *__str = _CharT(0xB);
39084684ddb6SLionel Sambuc        else
39094684ddb6SLionel Sambuc            __push_char(_CharT(0xB));
39104684ddb6SLionel Sambuc        return ++__first;
39114684ddb6SLionel Sambuc    }
39124684ddb6SLionel Sambuc    if ('0' <= *__first && *__first <= '7')
39134684ddb6SLionel Sambuc    {
39144684ddb6SLionel Sambuc        unsigned __val = *__first - '0';
39154684ddb6SLionel Sambuc        if (++__first != __last && ('0' <= *__first && *__first <= '7'))
39164684ddb6SLionel Sambuc        {
39174684ddb6SLionel Sambuc            __val = 8 * __val + *__first - '0';
39184684ddb6SLionel Sambuc            if (++__first != __last && ('0' <= *__first && *__first <= '7'))
39194684ddb6SLionel Sambuc                __val = 8 * __val + *__first++ - '0';
39204684ddb6SLionel Sambuc        }
39214684ddb6SLionel Sambuc        if (__str)
39224684ddb6SLionel Sambuc            *__str = _CharT(__val);
39234684ddb6SLionel Sambuc        else
39244684ddb6SLionel Sambuc            __push_char(_CharT(__val));
39254684ddb6SLionel Sambuc    }
39264684ddb6SLionel Sambuc    else
3927*0a6a1f1dSLionel Sambuc        __throw_regex_error<regex_constants::error_escape>();
39284684ddb6SLionel Sambuc    return __first;
39294684ddb6SLionel Sambuc}
39304684ddb6SLionel Sambuc
39314684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
39324684ddb6SLionel Sambuctemplate <class _ForwardIterator>
39334684ddb6SLionel Sambuc_ForwardIterator
39344684ddb6SLionel Sambucbasic_regex<_CharT, _Traits>::__parse_equivalence_class(_ForwardIterator __first,
39354684ddb6SLionel Sambuc                                    _ForwardIterator __last,
39364684ddb6SLionel Sambuc                                    __bracket_expression<_CharT, _Traits>* __ml)
39374684ddb6SLionel Sambuc{
39384684ddb6SLionel Sambuc    // Found [=
39394684ddb6SLionel Sambuc    //   This means =] must exist
39404684ddb6SLionel Sambuc    value_type _Equal_close[2] = {'=', ']'};
39414684ddb6SLionel Sambuc    _ForwardIterator __temp = _VSTD::search(__first, __last, _Equal_close,
39424684ddb6SLionel Sambuc                                                            _Equal_close+2);
39434684ddb6SLionel Sambuc    if (__temp == __last)
3944*0a6a1f1dSLionel Sambuc        __throw_regex_error<regex_constants::error_brack>();
39454684ddb6SLionel Sambuc    // [__first, __temp) contains all text in [= ... =]
39464684ddb6SLionel Sambuc    typedef typename _Traits::string_type string_type;
39474684ddb6SLionel Sambuc    string_type __collate_name =
39484684ddb6SLionel Sambuc        __traits_.lookup_collatename(__first, __temp);
39494684ddb6SLionel Sambuc    if (__collate_name.empty())
3950*0a6a1f1dSLionel Sambuc        __throw_regex_error<regex_constants::error_collate>();
39514684ddb6SLionel Sambuc    string_type __equiv_name =
39524684ddb6SLionel Sambuc        __traits_.transform_primary(__collate_name.begin(),
39534684ddb6SLionel Sambuc                                    __collate_name.end());
39544684ddb6SLionel Sambuc    if (!__equiv_name.empty())
39554684ddb6SLionel Sambuc        __ml->__add_equivalence(__equiv_name);
39564684ddb6SLionel Sambuc    else
39574684ddb6SLionel Sambuc    {
39584684ddb6SLionel Sambuc        switch (__collate_name.size())
39594684ddb6SLionel Sambuc        {
39604684ddb6SLionel Sambuc        case 1:
39614684ddb6SLionel Sambuc            __ml->__add_char(__collate_name[0]);
39624684ddb6SLionel Sambuc            break;
39634684ddb6SLionel Sambuc        case 2:
39644684ddb6SLionel Sambuc            __ml->__add_digraph(__collate_name[0], __collate_name[1]);
39654684ddb6SLionel Sambuc            break;
39664684ddb6SLionel Sambuc        default:
3967*0a6a1f1dSLionel Sambuc            __throw_regex_error<regex_constants::error_collate>();
39684684ddb6SLionel Sambuc        }
39694684ddb6SLionel Sambuc    }
39704684ddb6SLionel Sambuc    __first = _VSTD::next(__temp, 2);
39714684ddb6SLionel Sambuc    return __first;
39724684ddb6SLionel Sambuc}
39734684ddb6SLionel Sambuc
39744684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
39754684ddb6SLionel Sambuctemplate <class _ForwardIterator>
39764684ddb6SLionel Sambuc_ForwardIterator
39774684ddb6SLionel Sambucbasic_regex<_CharT, _Traits>::__parse_character_class(_ForwardIterator __first,
39784684ddb6SLionel Sambuc                                    _ForwardIterator __last,
39794684ddb6SLionel Sambuc                                    __bracket_expression<_CharT, _Traits>* __ml)
39804684ddb6SLionel Sambuc{
39814684ddb6SLionel Sambuc    // Found [:
39824684ddb6SLionel Sambuc    //   This means :] must exist
39834684ddb6SLionel Sambuc    value_type _Colon_close[2] = {':', ']'};
39844684ddb6SLionel Sambuc    _ForwardIterator __temp = _VSTD::search(__first, __last, _Colon_close,
39854684ddb6SLionel Sambuc                                                            _Colon_close+2);
39864684ddb6SLionel Sambuc    if (__temp == __last)
3987*0a6a1f1dSLionel Sambuc        __throw_regex_error<regex_constants::error_brack>();
39884684ddb6SLionel Sambuc    // [__first, __temp) contains all text in [: ... :]
39894684ddb6SLionel Sambuc    typedef typename _Traits::char_class_type char_class_type;
39904684ddb6SLionel Sambuc    char_class_type __class_type =
39914684ddb6SLionel Sambuc        __traits_.lookup_classname(__first, __temp, __flags_ & icase);
39924684ddb6SLionel Sambuc    if (__class_type == 0)
3993*0a6a1f1dSLionel Sambuc        __throw_regex_error<regex_constants::error_brack>();
39944684ddb6SLionel Sambuc    __ml->__add_class(__class_type);
39954684ddb6SLionel Sambuc    __first = _VSTD::next(__temp, 2);
39964684ddb6SLionel Sambuc    return __first;
39974684ddb6SLionel Sambuc}
39984684ddb6SLionel Sambuc
39994684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
40004684ddb6SLionel Sambuctemplate <class _ForwardIterator>
40014684ddb6SLionel Sambuc_ForwardIterator
40024684ddb6SLionel Sambucbasic_regex<_CharT, _Traits>::__parse_collating_symbol(_ForwardIterator __first,
40034684ddb6SLionel Sambuc                                                _ForwardIterator __last,
40044684ddb6SLionel Sambuc                                                basic_string<_CharT>& __col_sym)
40054684ddb6SLionel Sambuc{
40064684ddb6SLionel Sambuc    // Found [.
40074684ddb6SLionel Sambuc    //   This means .] must exist
40084684ddb6SLionel Sambuc    value_type _Dot_close[2] = {'.', ']'};
40094684ddb6SLionel Sambuc    _ForwardIterator __temp = _VSTD::search(__first, __last, _Dot_close,
40104684ddb6SLionel Sambuc                                                            _Dot_close+2);
40114684ddb6SLionel Sambuc    if (__temp == __last)
4012*0a6a1f1dSLionel Sambuc        __throw_regex_error<regex_constants::error_brack>();
40134684ddb6SLionel Sambuc    // [__first, __temp) contains all text in [. ... .]
40144684ddb6SLionel Sambuc    __col_sym = __traits_.lookup_collatename(__first, __temp);
40154684ddb6SLionel Sambuc    switch (__col_sym.size())
40164684ddb6SLionel Sambuc    {
40174684ddb6SLionel Sambuc    case 1:
40184684ddb6SLionel Sambuc    case 2:
40194684ddb6SLionel Sambuc        break;
40204684ddb6SLionel Sambuc    default:
4021*0a6a1f1dSLionel Sambuc        __throw_regex_error<regex_constants::error_collate>();
40224684ddb6SLionel Sambuc    }
40234684ddb6SLionel Sambuc    __first = _VSTD::next(__temp, 2);
40244684ddb6SLionel Sambuc    return __first;
40254684ddb6SLionel Sambuc}
40264684ddb6SLionel Sambuc
40274684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
40284684ddb6SLionel Sambuctemplate <class _ForwardIterator>
40294684ddb6SLionel Sambuc_ForwardIterator
40304684ddb6SLionel Sambucbasic_regex<_CharT, _Traits>::__parse_DUP_COUNT(_ForwardIterator __first,
40314684ddb6SLionel Sambuc                                                _ForwardIterator __last,
40324684ddb6SLionel Sambuc                                                int& __c)
40334684ddb6SLionel Sambuc{
4034*0a6a1f1dSLionel Sambuc    if (__first != __last )
40354684ddb6SLionel Sambuc    {
4036*0a6a1f1dSLionel Sambuc        int __val = __traits_.value(*__first, 10);
4037*0a6a1f1dSLionel Sambuc        if ( __val != -1 )
4038*0a6a1f1dSLionel Sambuc        {
4039*0a6a1f1dSLionel Sambuc            __c = __val;
4040*0a6a1f1dSLionel Sambuc            for (++__first;
4041*0a6a1f1dSLionel Sambuc                 __first != __last && ( __val = __traits_.value(*__first, 10)) != -1;
40424684ddb6SLionel Sambuc                 ++__first)
40434684ddb6SLionel Sambuc            {
40444684ddb6SLionel Sambuc                __c *= 10;
4045*0a6a1f1dSLionel Sambuc                __c += __val;
4046*0a6a1f1dSLionel Sambuc            }
40474684ddb6SLionel Sambuc        }
40484684ddb6SLionel Sambuc    }
40494684ddb6SLionel Sambuc    return __first;
40504684ddb6SLionel Sambuc}
40514684ddb6SLionel Sambuc
40524684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
40534684ddb6SLionel Sambuctemplate <class _ForwardIterator>
40544684ddb6SLionel Sambuc_ForwardIterator
40554684ddb6SLionel Sambucbasic_regex<_CharT, _Traits>::__parse_ecma_exp(_ForwardIterator __first,
40564684ddb6SLionel Sambuc                                               _ForwardIterator __last)
40574684ddb6SLionel Sambuc{
40584684ddb6SLionel Sambuc    __owns_one_state<_CharT>* __sa = __end_;
40594684ddb6SLionel Sambuc    _ForwardIterator __temp = __parse_alternative(__first, __last);
40604684ddb6SLionel Sambuc    if (__temp == __first)
40614684ddb6SLionel Sambuc        __push_empty();
40624684ddb6SLionel Sambuc    __first = __temp;
40634684ddb6SLionel Sambuc    while (__first != __last && *__first == '|')
40644684ddb6SLionel Sambuc    {
40654684ddb6SLionel Sambuc        __owns_one_state<_CharT>* __sb = __end_;
40664684ddb6SLionel Sambuc        __temp = __parse_alternative(++__first, __last);
40674684ddb6SLionel Sambuc        if (__temp == __first)
40684684ddb6SLionel Sambuc            __push_empty();
40694684ddb6SLionel Sambuc        __push_alternation(__sa, __sb);
40704684ddb6SLionel Sambuc        __first = __temp;
40714684ddb6SLionel Sambuc    }
40724684ddb6SLionel Sambuc    return __first;
40734684ddb6SLionel Sambuc}
40744684ddb6SLionel Sambuc
40754684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
40764684ddb6SLionel Sambuctemplate <class _ForwardIterator>
40774684ddb6SLionel Sambuc_ForwardIterator
40784684ddb6SLionel Sambucbasic_regex<_CharT, _Traits>::__parse_alternative(_ForwardIterator __first,
40794684ddb6SLionel Sambuc                                                  _ForwardIterator __last)
40804684ddb6SLionel Sambuc{
40814684ddb6SLionel Sambuc    while (true)
40824684ddb6SLionel Sambuc    {
40834684ddb6SLionel Sambuc        _ForwardIterator __temp = __parse_term(__first, __last);
40844684ddb6SLionel Sambuc        if (__temp == __first)
40854684ddb6SLionel Sambuc            break;
40864684ddb6SLionel Sambuc        __first = __temp;
40874684ddb6SLionel Sambuc    }
40884684ddb6SLionel Sambuc    return __first;
40894684ddb6SLionel Sambuc}
40904684ddb6SLionel Sambuc
40914684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
40924684ddb6SLionel Sambuctemplate <class _ForwardIterator>
40934684ddb6SLionel Sambuc_ForwardIterator
40944684ddb6SLionel Sambucbasic_regex<_CharT, _Traits>::__parse_term(_ForwardIterator __first,
40954684ddb6SLionel Sambuc                                           _ForwardIterator __last)
40964684ddb6SLionel Sambuc{
40974684ddb6SLionel Sambuc    _ForwardIterator __temp = __parse_assertion(__first, __last);
40984684ddb6SLionel Sambuc    if (__temp == __first)
40994684ddb6SLionel Sambuc    {
41004684ddb6SLionel Sambuc        __owns_one_state<_CharT>* __e = __end_;
41014684ddb6SLionel Sambuc        unsigned __mexp_begin = __marked_count_;
41024684ddb6SLionel Sambuc        __temp = __parse_atom(__first, __last);
41034684ddb6SLionel Sambuc        if (__temp != __first)
41044684ddb6SLionel Sambuc            __first = __parse_ERE_dupl_symbol(__temp, __last, __e,
41054684ddb6SLionel Sambuc                                              __mexp_begin+1, __marked_count_+1);
41064684ddb6SLionel Sambuc    }
41074684ddb6SLionel Sambuc    else
41084684ddb6SLionel Sambuc        __first = __temp;
41094684ddb6SLionel Sambuc    return __first;
41104684ddb6SLionel Sambuc}
41114684ddb6SLionel Sambuc
41124684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
41134684ddb6SLionel Sambuctemplate <class _ForwardIterator>
41144684ddb6SLionel Sambuc_ForwardIterator
41154684ddb6SLionel Sambucbasic_regex<_CharT, _Traits>::__parse_assertion(_ForwardIterator __first,
41164684ddb6SLionel Sambuc                                                _ForwardIterator __last)
41174684ddb6SLionel Sambuc{
41184684ddb6SLionel Sambuc    if (__first != __last)
41194684ddb6SLionel Sambuc    {
41204684ddb6SLionel Sambuc        switch (*__first)
41214684ddb6SLionel Sambuc        {
41224684ddb6SLionel Sambuc        case '^':
41234684ddb6SLionel Sambuc            __push_l_anchor();
41244684ddb6SLionel Sambuc            ++__first;
41254684ddb6SLionel Sambuc            break;
41264684ddb6SLionel Sambuc        case '$':
41274684ddb6SLionel Sambuc            __push_r_anchor();
41284684ddb6SLionel Sambuc            ++__first;
41294684ddb6SLionel Sambuc            break;
41304684ddb6SLionel Sambuc        case '\\':
41314684ddb6SLionel Sambuc            {
41324684ddb6SLionel Sambuc                _ForwardIterator __temp = _VSTD::next(__first);
41334684ddb6SLionel Sambuc                if (__temp != __last)
41344684ddb6SLionel Sambuc                {
41354684ddb6SLionel Sambuc                    if (*__temp == 'b')
41364684ddb6SLionel Sambuc                    {
41374684ddb6SLionel Sambuc                        __push_word_boundary(false);
41384684ddb6SLionel Sambuc                        __first = ++__temp;
41394684ddb6SLionel Sambuc                    }
41404684ddb6SLionel Sambuc                    else if (*__temp == 'B')
41414684ddb6SLionel Sambuc                    {
41424684ddb6SLionel Sambuc                        __push_word_boundary(true);
41434684ddb6SLionel Sambuc                        __first = ++__temp;
41444684ddb6SLionel Sambuc                    }
41454684ddb6SLionel Sambuc                }
41464684ddb6SLionel Sambuc            }
41474684ddb6SLionel Sambuc            break;
41484684ddb6SLionel Sambuc        case '(':
41494684ddb6SLionel Sambuc            {
41504684ddb6SLionel Sambuc                _ForwardIterator __temp = _VSTD::next(__first);
41514684ddb6SLionel Sambuc                if (__temp != __last && *__temp == '?')
41524684ddb6SLionel Sambuc                {
41534684ddb6SLionel Sambuc                    if (++__temp != __last)
41544684ddb6SLionel Sambuc                    {
41554684ddb6SLionel Sambuc                        switch (*__temp)
41564684ddb6SLionel Sambuc                        {
41574684ddb6SLionel Sambuc                        case '=':
41584684ddb6SLionel Sambuc                            {
41594684ddb6SLionel Sambuc                                basic_regex __exp;
41604684ddb6SLionel Sambuc                                __exp.__flags_ = __flags_;
41614684ddb6SLionel Sambuc                                __temp = __exp.__parse(++__temp, __last);
41624684ddb6SLionel Sambuc                                unsigned __mexp = __exp.__marked_count_;
41634684ddb6SLionel Sambuc                                __push_lookahead(_VSTD::move(__exp), false, __marked_count_);
41644684ddb6SLionel Sambuc                                __marked_count_ += __mexp;
41654684ddb6SLionel Sambuc                                if (__temp == __last || *__temp != ')')
4166*0a6a1f1dSLionel Sambuc                                    __throw_regex_error<regex_constants::error_paren>();
41674684ddb6SLionel Sambuc                                __first = ++__temp;
41684684ddb6SLionel Sambuc                            }
41694684ddb6SLionel Sambuc                            break;
41704684ddb6SLionel Sambuc                        case '!':
41714684ddb6SLionel Sambuc                            {
41724684ddb6SLionel Sambuc                                basic_regex __exp;
41734684ddb6SLionel Sambuc                                __exp.__flags_ = __flags_;
41744684ddb6SLionel Sambuc                                __temp = __exp.__parse(++__temp, __last);
41754684ddb6SLionel Sambuc                                unsigned __mexp = __exp.__marked_count_;
41764684ddb6SLionel Sambuc                                __push_lookahead(_VSTD::move(__exp), true, __marked_count_);
41774684ddb6SLionel Sambuc                                __marked_count_ += __mexp;
41784684ddb6SLionel Sambuc                                if (__temp == __last || *__temp != ')')
4179*0a6a1f1dSLionel Sambuc                                    __throw_regex_error<regex_constants::error_paren>();
41804684ddb6SLionel Sambuc                                __first = ++__temp;
41814684ddb6SLionel Sambuc                            }
41824684ddb6SLionel Sambuc                            break;
41834684ddb6SLionel Sambuc                        }
41844684ddb6SLionel Sambuc                    }
41854684ddb6SLionel Sambuc                }
41864684ddb6SLionel Sambuc            }
41874684ddb6SLionel Sambuc            break;
41884684ddb6SLionel Sambuc        }
41894684ddb6SLionel Sambuc    }
41904684ddb6SLionel Sambuc    return __first;
41914684ddb6SLionel Sambuc}
41924684ddb6SLionel Sambuc
41934684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
41944684ddb6SLionel Sambuctemplate <class _ForwardIterator>
41954684ddb6SLionel Sambuc_ForwardIterator
41964684ddb6SLionel Sambucbasic_regex<_CharT, _Traits>::__parse_atom(_ForwardIterator __first,
41974684ddb6SLionel Sambuc                                           _ForwardIterator __last)
41984684ddb6SLionel Sambuc{
41994684ddb6SLionel Sambuc    if (__first != __last)
42004684ddb6SLionel Sambuc    {
42014684ddb6SLionel Sambuc        switch (*__first)
42024684ddb6SLionel Sambuc        {
42034684ddb6SLionel Sambuc        case '.':
42044684ddb6SLionel Sambuc            __push_match_any_but_newline();
42054684ddb6SLionel Sambuc            ++__first;
42064684ddb6SLionel Sambuc            break;
42074684ddb6SLionel Sambuc        case '\\':
42084684ddb6SLionel Sambuc            __first = __parse_atom_escape(__first, __last);
42094684ddb6SLionel Sambuc            break;
42104684ddb6SLionel Sambuc        case '[':
42114684ddb6SLionel Sambuc            __first = __parse_bracket_expression(__first, __last);
42124684ddb6SLionel Sambuc            break;
42134684ddb6SLionel Sambuc        case '(':
42144684ddb6SLionel Sambuc            {
42154684ddb6SLionel Sambuc                ++__first;
42164684ddb6SLionel Sambuc                if (__first == __last)
4217*0a6a1f1dSLionel Sambuc                    __throw_regex_error<regex_constants::error_paren>();
42184684ddb6SLionel Sambuc                _ForwardIterator __temp = _VSTD::next(__first);
42194684ddb6SLionel Sambuc                if (__temp != __last && *__first == '?' && *__temp == ':')
42204684ddb6SLionel Sambuc                {
42214684ddb6SLionel Sambuc                    ++__open_count_;
42224684ddb6SLionel Sambuc                    __first = __parse_ecma_exp(++__temp, __last);
42234684ddb6SLionel Sambuc                    if (__first == __last || *__first != ')')
4224*0a6a1f1dSLionel Sambuc                        __throw_regex_error<regex_constants::error_paren>();
42254684ddb6SLionel Sambuc                    --__open_count_;
42264684ddb6SLionel Sambuc                    ++__first;
42274684ddb6SLionel Sambuc                }
42284684ddb6SLionel Sambuc                else
42294684ddb6SLionel Sambuc                {
42304684ddb6SLionel Sambuc                    __push_begin_marked_subexpression();
42314684ddb6SLionel Sambuc                    unsigned __temp_count = __marked_count_;
42324684ddb6SLionel Sambuc                    ++__open_count_;
42334684ddb6SLionel Sambuc                    __first = __parse_ecma_exp(__first, __last);
42344684ddb6SLionel Sambuc                    if (__first == __last || *__first != ')')
4235*0a6a1f1dSLionel Sambuc                        __throw_regex_error<regex_constants::error_paren>();
42364684ddb6SLionel Sambuc                    __push_end_marked_subexpression(__temp_count);
42374684ddb6SLionel Sambuc                    --__open_count_;
42384684ddb6SLionel Sambuc                    ++__first;
42394684ddb6SLionel Sambuc                }
42404684ddb6SLionel Sambuc            }
42414684ddb6SLionel Sambuc            break;
4242*0a6a1f1dSLionel Sambuc        case '*':
4243*0a6a1f1dSLionel Sambuc        case '+':
4244*0a6a1f1dSLionel Sambuc        case '?':
4245*0a6a1f1dSLionel Sambuc        case '{':
4246*0a6a1f1dSLionel Sambuc            __throw_regex_error<regex_constants::error_badrepeat>();
4247*0a6a1f1dSLionel Sambuc            break;
42484684ddb6SLionel Sambuc        default:
42494684ddb6SLionel Sambuc            __first = __parse_pattern_character(__first, __last);
42504684ddb6SLionel Sambuc            break;
42514684ddb6SLionel Sambuc        }
42524684ddb6SLionel Sambuc    }
42534684ddb6SLionel Sambuc    return __first;
42544684ddb6SLionel Sambuc}
42554684ddb6SLionel Sambuc
42564684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
42574684ddb6SLionel Sambuctemplate <class _ForwardIterator>
42584684ddb6SLionel Sambuc_ForwardIterator
42594684ddb6SLionel Sambucbasic_regex<_CharT, _Traits>::__parse_atom_escape(_ForwardIterator __first,
42604684ddb6SLionel Sambuc                                                  _ForwardIterator __last)
42614684ddb6SLionel Sambuc{
42624684ddb6SLionel Sambuc    if (__first != __last && *__first == '\\')
42634684ddb6SLionel Sambuc    {
42644684ddb6SLionel Sambuc        _ForwardIterator __t1 = _VSTD::next(__first);
42654684ddb6SLionel Sambuc        _ForwardIterator __t2 = __parse_decimal_escape(__t1, __last);
42664684ddb6SLionel Sambuc        if (__t2 != __t1)
42674684ddb6SLionel Sambuc            __first = __t2;
42684684ddb6SLionel Sambuc        else
42694684ddb6SLionel Sambuc        {
42704684ddb6SLionel Sambuc            __t2 = __parse_character_class_escape(__t1, __last);
42714684ddb6SLionel Sambuc            if (__t2 != __t1)
42724684ddb6SLionel Sambuc                __first = __t2;
42734684ddb6SLionel Sambuc            else
42744684ddb6SLionel Sambuc            {
42754684ddb6SLionel Sambuc                __t2 = __parse_character_escape(__t1, __last);
42764684ddb6SLionel Sambuc                if (__t2 != __t1)
42774684ddb6SLionel Sambuc                    __first = __t2;
42784684ddb6SLionel Sambuc            }
42794684ddb6SLionel Sambuc        }
42804684ddb6SLionel Sambuc    }
42814684ddb6SLionel Sambuc    return __first;
42824684ddb6SLionel Sambuc}
42834684ddb6SLionel Sambuc
42844684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
42854684ddb6SLionel Sambuctemplate <class _ForwardIterator>
42864684ddb6SLionel Sambuc_ForwardIterator
42874684ddb6SLionel Sambucbasic_regex<_CharT, _Traits>::__parse_decimal_escape(_ForwardIterator __first,
42884684ddb6SLionel Sambuc                                                     _ForwardIterator __last)
42894684ddb6SLionel Sambuc{
42904684ddb6SLionel Sambuc    if (__first != __last)
42914684ddb6SLionel Sambuc    {
42924684ddb6SLionel Sambuc        if (*__first == '0')
42934684ddb6SLionel Sambuc        {
42944684ddb6SLionel Sambuc            __push_char(_CharT());
42954684ddb6SLionel Sambuc            ++__first;
42964684ddb6SLionel Sambuc        }
42974684ddb6SLionel Sambuc        else if ('1' <= *__first && *__first <= '9')
42984684ddb6SLionel Sambuc        {
42994684ddb6SLionel Sambuc            unsigned __v = *__first - '0';
43004684ddb6SLionel Sambuc            for (++__first; '0' <= *__first && *__first <= '9'; ++__first)
43014684ddb6SLionel Sambuc                __v = 10 * __v + *__first - '0';
43024684ddb6SLionel Sambuc            if (__v > mark_count())
4303*0a6a1f1dSLionel Sambuc                __throw_regex_error<regex_constants::error_backref>();
43044684ddb6SLionel Sambuc            __push_back_ref(__v);
43054684ddb6SLionel Sambuc        }
43064684ddb6SLionel Sambuc    }
43074684ddb6SLionel Sambuc    return __first;
43084684ddb6SLionel Sambuc}
43094684ddb6SLionel Sambuc
43104684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
43114684ddb6SLionel Sambuctemplate <class _ForwardIterator>
43124684ddb6SLionel Sambuc_ForwardIterator
43134684ddb6SLionel Sambucbasic_regex<_CharT, _Traits>::__parse_character_class_escape(_ForwardIterator __first,
43144684ddb6SLionel Sambuc                                                             _ForwardIterator __last)
43154684ddb6SLionel Sambuc{
43164684ddb6SLionel Sambuc    if (__first != __last)
43174684ddb6SLionel Sambuc    {
43184684ddb6SLionel Sambuc        __bracket_expression<_CharT, _Traits>* __ml;
43194684ddb6SLionel Sambuc        switch (*__first)
43204684ddb6SLionel Sambuc        {
43214684ddb6SLionel Sambuc        case 'd':
43224684ddb6SLionel Sambuc            __ml = __start_matching_list(false);
43234684ddb6SLionel Sambuc            __ml->__add_class(ctype_base::digit);
43244684ddb6SLionel Sambuc            ++__first;
43254684ddb6SLionel Sambuc            break;
43264684ddb6SLionel Sambuc        case 'D':
43274684ddb6SLionel Sambuc            __ml = __start_matching_list(true);
43284684ddb6SLionel Sambuc            __ml->__add_class(ctype_base::digit);
43294684ddb6SLionel Sambuc            ++__first;
43304684ddb6SLionel Sambuc            break;
43314684ddb6SLionel Sambuc        case 's':
43324684ddb6SLionel Sambuc            __ml = __start_matching_list(false);
43334684ddb6SLionel Sambuc            __ml->__add_class(ctype_base::space);
43344684ddb6SLionel Sambuc            ++__first;
43354684ddb6SLionel Sambuc            break;
43364684ddb6SLionel Sambuc        case 'S':
43374684ddb6SLionel Sambuc            __ml = __start_matching_list(true);
43384684ddb6SLionel Sambuc            __ml->__add_class(ctype_base::space);
43394684ddb6SLionel Sambuc            ++__first;
43404684ddb6SLionel Sambuc            break;
43414684ddb6SLionel Sambuc        case 'w':
43424684ddb6SLionel Sambuc            __ml = __start_matching_list(false);
43434684ddb6SLionel Sambuc            __ml->__add_class(ctype_base::alnum);
43444684ddb6SLionel Sambuc            __ml->__add_char('_');
43454684ddb6SLionel Sambuc            ++__first;
43464684ddb6SLionel Sambuc            break;
43474684ddb6SLionel Sambuc        case 'W':
43484684ddb6SLionel Sambuc            __ml = __start_matching_list(true);
43494684ddb6SLionel Sambuc            __ml->__add_class(ctype_base::alnum);
43504684ddb6SLionel Sambuc            __ml->__add_char('_');
43514684ddb6SLionel Sambuc            ++__first;
43524684ddb6SLionel Sambuc            break;
43534684ddb6SLionel Sambuc        }
43544684ddb6SLionel Sambuc    }
43554684ddb6SLionel Sambuc    return __first;
43564684ddb6SLionel Sambuc}
43574684ddb6SLionel Sambuc
43584684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
43594684ddb6SLionel Sambuctemplate <class _ForwardIterator>
43604684ddb6SLionel Sambuc_ForwardIterator
43614684ddb6SLionel Sambucbasic_regex<_CharT, _Traits>::__parse_character_escape(_ForwardIterator __first,
43624684ddb6SLionel Sambuc                                                    _ForwardIterator __last,
43634684ddb6SLionel Sambuc                                                    basic_string<_CharT>* __str)
43644684ddb6SLionel Sambuc{
43654684ddb6SLionel Sambuc    if (__first != __last)
43664684ddb6SLionel Sambuc    {
43674684ddb6SLionel Sambuc        _ForwardIterator __t;
43684684ddb6SLionel Sambuc        unsigned __sum = 0;
43694684ddb6SLionel Sambuc        int __hd;
43704684ddb6SLionel Sambuc        switch (*__first)
43714684ddb6SLionel Sambuc        {
43724684ddb6SLionel Sambuc        case 'f':
43734684ddb6SLionel Sambuc            if (__str)
43744684ddb6SLionel Sambuc                *__str = _CharT(0xC);
43754684ddb6SLionel Sambuc            else
43764684ddb6SLionel Sambuc                __push_char(_CharT(0xC));
43774684ddb6SLionel Sambuc            ++__first;
43784684ddb6SLionel Sambuc            break;
43794684ddb6SLionel Sambuc        case 'n':
43804684ddb6SLionel Sambuc            if (__str)
43814684ddb6SLionel Sambuc                *__str = _CharT(0xA);
43824684ddb6SLionel Sambuc            else
43834684ddb6SLionel Sambuc                __push_char(_CharT(0xA));
43844684ddb6SLionel Sambuc            ++__first;
43854684ddb6SLionel Sambuc            break;
43864684ddb6SLionel Sambuc        case 'r':
43874684ddb6SLionel Sambuc            if (__str)
43884684ddb6SLionel Sambuc                *__str = _CharT(0xD);
43894684ddb6SLionel Sambuc            else
43904684ddb6SLionel Sambuc                __push_char(_CharT(0xD));
43914684ddb6SLionel Sambuc            ++__first;
43924684ddb6SLionel Sambuc            break;
43934684ddb6SLionel Sambuc        case 't':
43944684ddb6SLionel Sambuc            if (__str)
43954684ddb6SLionel Sambuc                *__str = _CharT(0x9);
43964684ddb6SLionel Sambuc            else
43974684ddb6SLionel Sambuc                __push_char(_CharT(0x9));
43984684ddb6SLionel Sambuc            ++__first;
43994684ddb6SLionel Sambuc            break;
44004684ddb6SLionel Sambuc        case 'v':
44014684ddb6SLionel Sambuc            if (__str)
44024684ddb6SLionel Sambuc                *__str = _CharT(0xB);
44034684ddb6SLionel Sambuc            else
44044684ddb6SLionel Sambuc                __push_char(_CharT(0xB));
44054684ddb6SLionel Sambuc            ++__first;
44064684ddb6SLionel Sambuc            break;
44074684ddb6SLionel Sambuc        case 'c':
44084684ddb6SLionel Sambuc            if ((__t = _VSTD::next(__first)) != __last)
44094684ddb6SLionel Sambuc            {
44104684ddb6SLionel Sambuc                if (('A' <= *__t && *__t <= 'Z') ||
44114684ddb6SLionel Sambuc                    ('a' <= *__t && *__t <= 'z'))
44124684ddb6SLionel Sambuc                {
44134684ddb6SLionel Sambuc                    if (__str)
44144684ddb6SLionel Sambuc                        *__str = _CharT(*__t % 32);
44154684ddb6SLionel Sambuc                    else
44164684ddb6SLionel Sambuc                        __push_char(_CharT(*__t % 32));
44174684ddb6SLionel Sambuc                    __first = ++__t;
44184684ddb6SLionel Sambuc                }
44194684ddb6SLionel Sambuc                else
4420*0a6a1f1dSLionel Sambuc                    __throw_regex_error<regex_constants::error_escape>();
44214684ddb6SLionel Sambuc            }
44224684ddb6SLionel Sambuc            else
4423*0a6a1f1dSLionel Sambuc                __throw_regex_error<regex_constants::error_escape>();
44244684ddb6SLionel Sambuc            break;
44254684ddb6SLionel Sambuc        case 'u':
44264684ddb6SLionel Sambuc            ++__first;
44274684ddb6SLionel Sambuc            if (__first == __last)
4428*0a6a1f1dSLionel Sambuc                __throw_regex_error<regex_constants::error_escape>();
44294684ddb6SLionel Sambuc            __hd = __traits_.value(*__first, 16);
44304684ddb6SLionel Sambuc            if (__hd == -1)
4431*0a6a1f1dSLionel Sambuc                __throw_regex_error<regex_constants::error_escape>();
44324684ddb6SLionel Sambuc            __sum = 16 * __sum + static_cast<unsigned>(__hd);
44334684ddb6SLionel Sambuc            ++__first;
44344684ddb6SLionel Sambuc            if (__first == __last)
4435*0a6a1f1dSLionel Sambuc                __throw_regex_error<regex_constants::error_escape>();
44364684ddb6SLionel Sambuc            __hd = __traits_.value(*__first, 16);
44374684ddb6SLionel Sambuc            if (__hd == -1)
4438*0a6a1f1dSLionel Sambuc                __throw_regex_error<regex_constants::error_escape>();
44394684ddb6SLionel Sambuc            __sum = 16 * __sum + static_cast<unsigned>(__hd);
44404684ddb6SLionel Sambuc            // drop through
44414684ddb6SLionel Sambuc        case 'x':
44424684ddb6SLionel Sambuc            ++__first;
44434684ddb6SLionel Sambuc            if (__first == __last)
4444*0a6a1f1dSLionel Sambuc                __throw_regex_error<regex_constants::error_escape>();
44454684ddb6SLionel Sambuc            __hd = __traits_.value(*__first, 16);
44464684ddb6SLionel Sambuc            if (__hd == -1)
4447*0a6a1f1dSLionel Sambuc                __throw_regex_error<regex_constants::error_escape>();
44484684ddb6SLionel Sambuc            __sum = 16 * __sum + static_cast<unsigned>(__hd);
44494684ddb6SLionel Sambuc            ++__first;
44504684ddb6SLionel Sambuc            if (__first == __last)
4451*0a6a1f1dSLionel Sambuc                __throw_regex_error<regex_constants::error_escape>();
44524684ddb6SLionel Sambuc            __hd = __traits_.value(*__first, 16);
44534684ddb6SLionel Sambuc            if (__hd == -1)
4454*0a6a1f1dSLionel Sambuc                __throw_regex_error<regex_constants::error_escape>();
44554684ddb6SLionel Sambuc            __sum = 16 * __sum + static_cast<unsigned>(__hd);
44564684ddb6SLionel Sambuc            if (__str)
44574684ddb6SLionel Sambuc                *__str = _CharT(__sum);
44584684ddb6SLionel Sambuc            else
44594684ddb6SLionel Sambuc                __push_char(_CharT(__sum));
44604684ddb6SLionel Sambuc            ++__first;
44614684ddb6SLionel Sambuc            break;
4462*0a6a1f1dSLionel Sambuc        case '0':
4463*0a6a1f1dSLionel Sambuc            if (__str)
4464*0a6a1f1dSLionel Sambuc                *__str = _CharT(0);
4465*0a6a1f1dSLionel Sambuc            else
4466*0a6a1f1dSLionel Sambuc                __push_char(_CharT(0));
4467*0a6a1f1dSLionel Sambuc            ++__first;
4468*0a6a1f1dSLionel Sambuc            break;
44694684ddb6SLionel Sambuc        default:
44704684ddb6SLionel Sambuc            if (*__first != '_' && !__traits_.isctype(*__first, ctype_base::alnum))
44714684ddb6SLionel Sambuc            {
44724684ddb6SLionel Sambuc                if (__str)
44734684ddb6SLionel Sambuc                    *__str = *__first;
44744684ddb6SLionel Sambuc                else
44754684ddb6SLionel Sambuc                    __push_char(*__first);
44764684ddb6SLionel Sambuc                ++__first;
44774684ddb6SLionel Sambuc            }
44784684ddb6SLionel Sambuc            else
4479*0a6a1f1dSLionel Sambuc                __throw_regex_error<regex_constants::error_escape>();
44804684ddb6SLionel Sambuc            break;
44814684ddb6SLionel Sambuc        }
44824684ddb6SLionel Sambuc    }
44834684ddb6SLionel Sambuc    return __first;
44844684ddb6SLionel Sambuc}
44854684ddb6SLionel Sambuc
44864684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
44874684ddb6SLionel Sambuctemplate <class _ForwardIterator>
44884684ddb6SLionel Sambuc_ForwardIterator
44894684ddb6SLionel Sambucbasic_regex<_CharT, _Traits>::__parse_pattern_character(_ForwardIterator __first,
44904684ddb6SLionel Sambuc                                                        _ForwardIterator __last)
44914684ddb6SLionel Sambuc{
44924684ddb6SLionel Sambuc    if (__first != __last)
44934684ddb6SLionel Sambuc    {
44944684ddb6SLionel Sambuc        switch (*__first)
44954684ddb6SLionel Sambuc        {
44964684ddb6SLionel Sambuc        case '^':
44974684ddb6SLionel Sambuc        case '$':
44984684ddb6SLionel Sambuc        case '\\':
44994684ddb6SLionel Sambuc        case '.':
45004684ddb6SLionel Sambuc        case '*':
45014684ddb6SLionel Sambuc        case '+':
45024684ddb6SLionel Sambuc        case '?':
45034684ddb6SLionel Sambuc        case '(':
45044684ddb6SLionel Sambuc        case ')':
45054684ddb6SLionel Sambuc        case '[':
45064684ddb6SLionel Sambuc        case ']':
45074684ddb6SLionel Sambuc        case '{':
45084684ddb6SLionel Sambuc        case '}':
45094684ddb6SLionel Sambuc        case '|':
45104684ddb6SLionel Sambuc            break;
45114684ddb6SLionel Sambuc        default:
45124684ddb6SLionel Sambuc            __push_char(*__first);
45134684ddb6SLionel Sambuc            ++__first;
45144684ddb6SLionel Sambuc            break;
45154684ddb6SLionel Sambuc        }
45164684ddb6SLionel Sambuc    }
45174684ddb6SLionel Sambuc    return __first;
45184684ddb6SLionel Sambuc}
45194684ddb6SLionel Sambuc
45204684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
45214684ddb6SLionel Sambuctemplate <class _ForwardIterator>
45224684ddb6SLionel Sambuc_ForwardIterator
45234684ddb6SLionel Sambucbasic_regex<_CharT, _Traits>::__parse_grep(_ForwardIterator __first,
45244684ddb6SLionel Sambuc                                           _ForwardIterator __last)
45254684ddb6SLionel Sambuc{
45264684ddb6SLionel Sambuc    __owns_one_state<_CharT>* __sa = __end_;
45274684ddb6SLionel Sambuc    _ForwardIterator __t1 = _VSTD::find(__first, __last, _CharT('\n'));
45284684ddb6SLionel Sambuc    if (__t1 != __first)
45294684ddb6SLionel Sambuc        __parse_basic_reg_exp(__first, __t1);
45304684ddb6SLionel Sambuc    else
45314684ddb6SLionel Sambuc        __push_empty();
45324684ddb6SLionel Sambuc    __first = __t1;
45334684ddb6SLionel Sambuc    if (__first != __last)
45344684ddb6SLionel Sambuc        ++__first;
45354684ddb6SLionel Sambuc    while (__first != __last)
45364684ddb6SLionel Sambuc    {
45374684ddb6SLionel Sambuc        __t1 = _VSTD::find(__first, __last, _CharT('\n'));
45384684ddb6SLionel Sambuc        __owns_one_state<_CharT>* __sb = __end_;
45394684ddb6SLionel Sambuc        if (__t1 != __first)
45404684ddb6SLionel Sambuc            __parse_basic_reg_exp(__first, __t1);
45414684ddb6SLionel Sambuc        else
45424684ddb6SLionel Sambuc            __push_empty();
45434684ddb6SLionel Sambuc        __push_alternation(__sa, __sb);
45444684ddb6SLionel Sambuc        __first = __t1;
45454684ddb6SLionel Sambuc        if (__first != __last)
45464684ddb6SLionel Sambuc            ++__first;
45474684ddb6SLionel Sambuc    }
45484684ddb6SLionel Sambuc    return __first;
45494684ddb6SLionel Sambuc}
45504684ddb6SLionel Sambuc
45514684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
45524684ddb6SLionel Sambuctemplate <class _ForwardIterator>
45534684ddb6SLionel Sambuc_ForwardIterator
45544684ddb6SLionel Sambucbasic_regex<_CharT, _Traits>::__parse_egrep(_ForwardIterator __first,
45554684ddb6SLionel Sambuc                                            _ForwardIterator __last)
45564684ddb6SLionel Sambuc{
45574684ddb6SLionel Sambuc    __owns_one_state<_CharT>* __sa = __end_;
45584684ddb6SLionel Sambuc    _ForwardIterator __t1 = _VSTD::find(__first, __last, _CharT('\n'));
45594684ddb6SLionel Sambuc    if (__t1 != __first)
45604684ddb6SLionel Sambuc        __parse_extended_reg_exp(__first, __t1);
45614684ddb6SLionel Sambuc    else
45624684ddb6SLionel Sambuc        __push_empty();
45634684ddb6SLionel Sambuc    __first = __t1;
45644684ddb6SLionel Sambuc    if (__first != __last)
45654684ddb6SLionel Sambuc        ++__first;
45664684ddb6SLionel Sambuc    while (__first != __last)
45674684ddb6SLionel Sambuc    {
45684684ddb6SLionel Sambuc        __t1 = _VSTD::find(__first, __last, _CharT('\n'));
45694684ddb6SLionel Sambuc        __owns_one_state<_CharT>* __sb = __end_;
45704684ddb6SLionel Sambuc        if (__t1 != __first)
45714684ddb6SLionel Sambuc            __parse_extended_reg_exp(__first, __t1);
45724684ddb6SLionel Sambuc        else
45734684ddb6SLionel Sambuc            __push_empty();
45744684ddb6SLionel Sambuc        __push_alternation(__sa, __sb);
45754684ddb6SLionel Sambuc        __first = __t1;
45764684ddb6SLionel Sambuc        if (__first != __last)
45774684ddb6SLionel Sambuc            ++__first;
45784684ddb6SLionel Sambuc    }
45794684ddb6SLionel Sambuc    return __first;
45804684ddb6SLionel Sambuc}
45814684ddb6SLionel Sambuc
45824684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
45834684ddb6SLionel Sambucvoid
45844684ddb6SLionel Sambucbasic_regex<_CharT, _Traits>::__push_loop(size_t __min, size_t __max,
45854684ddb6SLionel Sambuc        __owns_one_state<_CharT>* __s, size_t __mexp_begin, size_t __mexp_end,
45864684ddb6SLionel Sambuc        bool __greedy)
45874684ddb6SLionel Sambuc{
45884684ddb6SLionel Sambuc    unique_ptr<__empty_state<_CharT> > __e1(new __empty_state<_CharT>(__end_->first()));
45894684ddb6SLionel Sambuc    __end_->first() = nullptr;
45904684ddb6SLionel Sambuc    unique_ptr<__loop<_CharT> > __e2(new __loop<_CharT>(__loop_count_,
45914684ddb6SLionel Sambuc                __s->first(), __e1.get(), __mexp_begin, __mexp_end, __greedy,
45924684ddb6SLionel Sambuc                __min, __max));
45934684ddb6SLionel Sambuc    __s->first() = nullptr;
45944684ddb6SLionel Sambuc    __e1.release();
45954684ddb6SLionel Sambuc    __end_->first() = new __repeat_one_loop<_CharT>(__e2.get());
45964684ddb6SLionel Sambuc    __end_ = __e2->second();
45974684ddb6SLionel Sambuc    __s->first() = __e2.release();
45984684ddb6SLionel Sambuc    ++__loop_count_;
45994684ddb6SLionel Sambuc}
46004684ddb6SLionel Sambuc
46014684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
46024684ddb6SLionel Sambucvoid
46034684ddb6SLionel Sambucbasic_regex<_CharT, _Traits>::__push_char(value_type __c)
46044684ddb6SLionel Sambuc{
46054684ddb6SLionel Sambuc    if (flags() & icase)
46064684ddb6SLionel Sambuc        __end_->first() = new __match_char_icase<_CharT, _Traits>
46074684ddb6SLionel Sambuc                                              (__traits_, __c, __end_->first());
46084684ddb6SLionel Sambuc    else if (flags() & collate)
46094684ddb6SLionel Sambuc        __end_->first() = new __match_char_collate<_CharT, _Traits>
46104684ddb6SLionel Sambuc                                              (__traits_, __c, __end_->first());
46114684ddb6SLionel Sambuc    else
46124684ddb6SLionel Sambuc        __end_->first() = new __match_char<_CharT>(__c, __end_->first());
46134684ddb6SLionel Sambuc    __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
46144684ddb6SLionel Sambuc}
46154684ddb6SLionel Sambuc
46164684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
46174684ddb6SLionel Sambucvoid
46184684ddb6SLionel Sambucbasic_regex<_CharT, _Traits>::__push_begin_marked_subexpression()
46194684ddb6SLionel Sambuc{
46204684ddb6SLionel Sambuc    if (!(__flags_ & nosubs))
46214684ddb6SLionel Sambuc    {
46224684ddb6SLionel Sambuc        __end_->first() =
46234684ddb6SLionel Sambuc                new __begin_marked_subexpression<_CharT>(++__marked_count_,
46244684ddb6SLionel Sambuc                                                         __end_->first());
46254684ddb6SLionel Sambuc        __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
46264684ddb6SLionel Sambuc    }
46274684ddb6SLionel Sambuc}
46284684ddb6SLionel Sambuc
46294684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
46304684ddb6SLionel Sambucvoid
46314684ddb6SLionel Sambucbasic_regex<_CharT, _Traits>::__push_end_marked_subexpression(unsigned __sub)
46324684ddb6SLionel Sambuc{
46334684ddb6SLionel Sambuc    if (!(__flags_ & nosubs))
46344684ddb6SLionel Sambuc    {
46354684ddb6SLionel Sambuc        __end_->first() =
46364684ddb6SLionel Sambuc                new __end_marked_subexpression<_CharT>(__sub, __end_->first());
46374684ddb6SLionel Sambuc        __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
46384684ddb6SLionel Sambuc    }
46394684ddb6SLionel Sambuc}
46404684ddb6SLionel Sambuc
46414684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
46424684ddb6SLionel Sambucvoid
46434684ddb6SLionel Sambucbasic_regex<_CharT, _Traits>::__push_l_anchor()
46444684ddb6SLionel Sambuc{
46454684ddb6SLionel Sambuc    __end_->first() = new __l_anchor<_CharT>(__end_->first());
46464684ddb6SLionel Sambuc    __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
46474684ddb6SLionel Sambuc}
46484684ddb6SLionel Sambuc
46494684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
46504684ddb6SLionel Sambucvoid
46514684ddb6SLionel Sambucbasic_regex<_CharT, _Traits>::__push_r_anchor()
46524684ddb6SLionel Sambuc{
46534684ddb6SLionel Sambuc    __end_->first() = new __r_anchor<_CharT>(__end_->first());
46544684ddb6SLionel Sambuc    __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
46554684ddb6SLionel Sambuc}
46564684ddb6SLionel Sambuc
46574684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
46584684ddb6SLionel Sambucvoid
46594684ddb6SLionel Sambucbasic_regex<_CharT, _Traits>::__push_match_any()
46604684ddb6SLionel Sambuc{
46614684ddb6SLionel Sambuc    __end_->first() = new __match_any<_CharT>(__end_->first());
46624684ddb6SLionel Sambuc    __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
46634684ddb6SLionel Sambuc}
46644684ddb6SLionel Sambuc
46654684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
46664684ddb6SLionel Sambucvoid
46674684ddb6SLionel Sambucbasic_regex<_CharT, _Traits>::__push_match_any_but_newline()
46684684ddb6SLionel Sambuc{
46694684ddb6SLionel Sambuc    __end_->first() = new __match_any_but_newline<_CharT>(__end_->first());
46704684ddb6SLionel Sambuc    __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
46714684ddb6SLionel Sambuc}
46724684ddb6SLionel Sambuc
46734684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
46744684ddb6SLionel Sambucvoid
46754684ddb6SLionel Sambucbasic_regex<_CharT, _Traits>::__push_empty()
46764684ddb6SLionel Sambuc{
46774684ddb6SLionel Sambuc    __end_->first() = new __empty_state<_CharT>(__end_->first());
46784684ddb6SLionel Sambuc    __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
46794684ddb6SLionel Sambuc}
46804684ddb6SLionel Sambuc
46814684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
46824684ddb6SLionel Sambucvoid
46834684ddb6SLionel Sambucbasic_regex<_CharT, _Traits>::__push_word_boundary(bool __invert)
46844684ddb6SLionel Sambuc{
46854684ddb6SLionel Sambuc    __end_->first() = new __word_boundary<_CharT, _Traits>(__traits_, __invert,
46864684ddb6SLionel Sambuc                                                           __end_->first());
46874684ddb6SLionel Sambuc    __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
46884684ddb6SLionel Sambuc}
46894684ddb6SLionel Sambuc
46904684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
46914684ddb6SLionel Sambucvoid
46924684ddb6SLionel Sambucbasic_regex<_CharT, _Traits>::__push_back_ref(int __i)
46934684ddb6SLionel Sambuc{
46944684ddb6SLionel Sambuc    if (flags() & icase)
46954684ddb6SLionel Sambuc        __end_->first() = new __back_ref_icase<_CharT, _Traits>
46964684ddb6SLionel Sambuc                                              (__traits_, __i, __end_->first());
46974684ddb6SLionel Sambuc    else if (flags() & collate)
46984684ddb6SLionel Sambuc        __end_->first() = new __back_ref_collate<_CharT, _Traits>
46994684ddb6SLionel Sambuc                                              (__traits_, __i, __end_->first());
47004684ddb6SLionel Sambuc    else
47014684ddb6SLionel Sambuc        __end_->first() = new __back_ref<_CharT>(__i, __end_->first());
47024684ddb6SLionel Sambuc    __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
47034684ddb6SLionel Sambuc}
47044684ddb6SLionel Sambuc
47054684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
47064684ddb6SLionel Sambucvoid
47074684ddb6SLionel Sambucbasic_regex<_CharT, _Traits>::__push_alternation(__owns_one_state<_CharT>* __sa,
47084684ddb6SLionel Sambuc                                                 __owns_one_state<_CharT>* __ea)
47094684ddb6SLionel Sambuc{
47104684ddb6SLionel Sambuc    __sa->first() = new __alternate<_CharT>(
47114684ddb6SLionel Sambuc                         static_cast<__owns_one_state<_CharT>*>(__sa->first()),
47124684ddb6SLionel Sambuc                         static_cast<__owns_one_state<_CharT>*>(__ea->first()));
47134684ddb6SLionel Sambuc    __ea->first() = nullptr;
47144684ddb6SLionel Sambuc    __ea->first() = new __empty_state<_CharT>(__end_->first());
47154684ddb6SLionel Sambuc    __end_->first() = nullptr;
47164684ddb6SLionel Sambuc    __end_->first() = new __empty_non_own_state<_CharT>(__ea->first());
47174684ddb6SLionel Sambuc    __end_ = static_cast<__owns_one_state<_CharT>*>(__ea->first());
47184684ddb6SLionel Sambuc}
47194684ddb6SLionel Sambuc
47204684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
47214684ddb6SLionel Sambuc__bracket_expression<_CharT, _Traits>*
47224684ddb6SLionel Sambucbasic_regex<_CharT, _Traits>::__start_matching_list(bool __negate)
47234684ddb6SLionel Sambuc{
47244684ddb6SLionel Sambuc    __bracket_expression<_CharT, _Traits>* __r =
47254684ddb6SLionel Sambuc        new __bracket_expression<_CharT, _Traits>(__traits_, __end_->first(),
47264684ddb6SLionel Sambuc                                                  __negate, __flags_ & icase,
47274684ddb6SLionel Sambuc                                                  __flags_ & collate);
47284684ddb6SLionel Sambuc    __end_->first() = __r;
47294684ddb6SLionel Sambuc    __end_ = __r;
47304684ddb6SLionel Sambuc    return __r;
47314684ddb6SLionel Sambuc}
47324684ddb6SLionel Sambuc
47334684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
47344684ddb6SLionel Sambucvoid
47354684ddb6SLionel Sambucbasic_regex<_CharT, _Traits>::__push_lookahead(const basic_regex& __exp,
47364684ddb6SLionel Sambuc                                               bool __invert,
47374684ddb6SLionel Sambuc                                               unsigned __mexp)
47384684ddb6SLionel Sambuc{
47394684ddb6SLionel Sambuc    __end_->first() = new __lookahead<_CharT, _Traits>(__exp, __invert,
47404684ddb6SLionel Sambuc                                                           __end_->first(), __mexp);
47414684ddb6SLionel Sambuc    __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
47424684ddb6SLionel Sambuc}
47434684ddb6SLionel Sambuc
47444684ddb6SLionel Sambuctypedef basic_regex<char>    regex;
47454684ddb6SLionel Sambuctypedef basic_regex<wchar_t> wregex;
47464684ddb6SLionel Sambuc
47474684ddb6SLionel Sambuc// sub_match
47484684ddb6SLionel Sambuc
47494684ddb6SLionel Sambuctemplate <class _BidirectionalIterator>
47504684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS_ONLY sub_match
47514684ddb6SLionel Sambuc    : public pair<_BidirectionalIterator, _BidirectionalIterator>
47524684ddb6SLionel Sambuc{
47534684ddb6SLionel Sambucpublic:
47544684ddb6SLionel Sambuc    typedef _BidirectionalIterator                              iterator;
47554684ddb6SLionel Sambuc    typedef typename iterator_traits<iterator>::value_type      value_type;
47564684ddb6SLionel Sambuc    typedef typename iterator_traits<iterator>::difference_type difference_type;
47574684ddb6SLionel Sambuc    typedef basic_string<value_type>                            string_type;
47584684ddb6SLionel Sambuc
47594684ddb6SLionel Sambuc    bool matched;
47604684ddb6SLionel Sambuc
47614684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
47624684ddb6SLionel Sambuc    _LIBCPP_CONSTEXPR sub_match() : matched() {}
47634684ddb6SLionel Sambuc
47644684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
47654684ddb6SLionel Sambuc    difference_type length() const
47664684ddb6SLionel Sambuc        {return matched ? _VSTD::distance(this->first, this->second) : 0;}
47674684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
47684684ddb6SLionel Sambuc    string_type str() const
47694684ddb6SLionel Sambuc        {return matched ? string_type(this->first, this->second) : string_type();}
47704684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
47714684ddb6SLionel Sambuc    operator string_type() const
47724684ddb6SLionel Sambuc        {return str();}
47734684ddb6SLionel Sambuc
47744684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
47754684ddb6SLionel Sambuc    int compare(const sub_match& __s) const
47764684ddb6SLionel Sambuc        {return str().compare(__s.str());}
47774684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
47784684ddb6SLionel Sambuc    int compare(const string_type& __s) const
47794684ddb6SLionel Sambuc        {return str().compare(__s);}
47804684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
47814684ddb6SLionel Sambuc    int compare(const value_type* __s) const
47824684ddb6SLionel Sambuc        {return str().compare(__s);}
47834684ddb6SLionel Sambuc};
47844684ddb6SLionel Sambuc
47854684ddb6SLionel Sambuctypedef sub_match<const char*>             csub_match;
47864684ddb6SLionel Sambuctypedef sub_match<const wchar_t*>          wcsub_match;
47874684ddb6SLionel Sambuctypedef sub_match<string::const_iterator>  ssub_match;
47884684ddb6SLionel Sambuctypedef sub_match<wstring::const_iterator> wssub_match;
47894684ddb6SLionel Sambuc
47904684ddb6SLionel Sambuctemplate <class _BiIter>
47914684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
47924684ddb6SLionel Sambucbool
47934684ddb6SLionel Sambucoperator==(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
47944684ddb6SLionel Sambuc{
47954684ddb6SLionel Sambuc    return __x.compare(__y) == 0;
47964684ddb6SLionel Sambuc}
47974684ddb6SLionel Sambuc
47984684ddb6SLionel Sambuctemplate <class _BiIter>
47994684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
48004684ddb6SLionel Sambucbool
48014684ddb6SLionel Sambucoperator!=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
48024684ddb6SLionel Sambuc{
48034684ddb6SLionel Sambuc    return !(__x == __y);
48044684ddb6SLionel Sambuc}
48054684ddb6SLionel Sambuc
48064684ddb6SLionel Sambuctemplate <class _BiIter>
48074684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
48084684ddb6SLionel Sambucbool
48094684ddb6SLionel Sambucoperator<(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
48104684ddb6SLionel Sambuc{
48114684ddb6SLionel Sambuc    return __x.compare(__y) < 0;
48124684ddb6SLionel Sambuc}
48134684ddb6SLionel Sambuc
48144684ddb6SLionel Sambuctemplate <class _BiIter>
48154684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
48164684ddb6SLionel Sambucbool
48174684ddb6SLionel Sambucoperator<=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
48184684ddb6SLionel Sambuc{
48194684ddb6SLionel Sambuc    return !(__y < __x);
48204684ddb6SLionel Sambuc}
48214684ddb6SLionel Sambuc
48224684ddb6SLionel Sambuctemplate <class _BiIter>
48234684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
48244684ddb6SLionel Sambucbool
48254684ddb6SLionel Sambucoperator>=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
48264684ddb6SLionel Sambuc{
48274684ddb6SLionel Sambuc    return !(__x < __y);
48284684ddb6SLionel Sambuc}
48294684ddb6SLionel Sambuc
48304684ddb6SLionel Sambuctemplate <class _BiIter>
48314684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
48324684ddb6SLionel Sambucbool
48334684ddb6SLionel Sambucoperator>(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
48344684ddb6SLionel Sambuc{
48354684ddb6SLionel Sambuc    return __y < __x;
48364684ddb6SLionel Sambuc}
48374684ddb6SLionel Sambuc
48384684ddb6SLionel Sambuctemplate <class _BiIter, class _ST, class _SA>
48394684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
48404684ddb6SLionel Sambucbool
48414684ddb6SLionel Sambucoperator==(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
48424684ddb6SLionel Sambuc           const sub_match<_BiIter>& __y)
48434684ddb6SLionel Sambuc{
4844*0a6a1f1dSLionel Sambuc    return __y.compare(typename sub_match<_BiIter>::string_type(__x.data(), __x.size())) == 0;
48454684ddb6SLionel Sambuc}
48464684ddb6SLionel Sambuc
48474684ddb6SLionel Sambuctemplate <class _BiIter, class _ST, class _SA>
48484684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
48494684ddb6SLionel Sambucbool
48504684ddb6SLionel Sambucoperator!=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
48514684ddb6SLionel Sambuc           const sub_match<_BiIter>& __y)
48524684ddb6SLionel Sambuc{
48534684ddb6SLionel Sambuc    return !(__x == __y);
48544684ddb6SLionel Sambuc}
48554684ddb6SLionel Sambuc
48564684ddb6SLionel Sambuctemplate <class _BiIter, class _ST, class _SA>
48574684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
48584684ddb6SLionel Sambucbool
48594684ddb6SLionel Sambucoperator<(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
48604684ddb6SLionel Sambuc          const sub_match<_BiIter>& __y)
48614684ddb6SLionel Sambuc{
4862*0a6a1f1dSLionel Sambuc    return __y.compare(typename sub_match<_BiIter>::string_type(__x.data(), __x.size())) > 0;
48634684ddb6SLionel Sambuc}
48644684ddb6SLionel Sambuc
48654684ddb6SLionel Sambuctemplate <class _BiIter, class _ST, class _SA>
48664684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
48674684ddb6SLionel Sambucbool
48684684ddb6SLionel Sambucoperator>(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
48694684ddb6SLionel Sambuc          const sub_match<_BiIter>& __y)
48704684ddb6SLionel Sambuc{
48714684ddb6SLionel Sambuc    return __y < __x;
48724684ddb6SLionel Sambuc}
48734684ddb6SLionel Sambuc
48744684ddb6SLionel Sambuctemplate <class _BiIter, class _ST, class _SA>
48754684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
48764684ddb6SLionel Sambucbool operator>=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
48774684ddb6SLionel Sambuc                const sub_match<_BiIter>& __y)
48784684ddb6SLionel Sambuc{
48794684ddb6SLionel Sambuc    return !(__x < __y);
48804684ddb6SLionel Sambuc}
48814684ddb6SLionel Sambuc
48824684ddb6SLionel Sambuctemplate <class _BiIter, class _ST, class _SA>
48834684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
48844684ddb6SLionel Sambucbool
48854684ddb6SLionel Sambucoperator<=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
48864684ddb6SLionel Sambuc           const sub_match<_BiIter>& __y)
48874684ddb6SLionel Sambuc{
48884684ddb6SLionel Sambuc    return !(__y < __x);
48894684ddb6SLionel Sambuc}
48904684ddb6SLionel Sambuc
48914684ddb6SLionel Sambuctemplate <class _BiIter, class _ST, class _SA>
48924684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
48934684ddb6SLionel Sambucbool
48944684ddb6SLionel Sambucoperator==(const sub_match<_BiIter>& __x,
48954684ddb6SLionel Sambuc           const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
48964684ddb6SLionel Sambuc{
4897*0a6a1f1dSLionel Sambuc    return __x.compare(typename sub_match<_BiIter>::string_type(__y.data(), __y.size())) == 0;
48984684ddb6SLionel Sambuc}
48994684ddb6SLionel Sambuc
49004684ddb6SLionel Sambuctemplate <class _BiIter, class _ST, class _SA>
49014684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
49024684ddb6SLionel Sambucbool
49034684ddb6SLionel Sambucoperator!=(const sub_match<_BiIter>& __x,
49044684ddb6SLionel Sambuc           const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
49054684ddb6SLionel Sambuc{
49064684ddb6SLionel Sambuc    return !(__x == __y);
49074684ddb6SLionel Sambuc}
49084684ddb6SLionel Sambuc
49094684ddb6SLionel Sambuctemplate <class _BiIter, class _ST, class _SA>
49104684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
49114684ddb6SLionel Sambucbool
49124684ddb6SLionel Sambucoperator<(const sub_match<_BiIter>& __x,
49134684ddb6SLionel Sambuc          const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
49144684ddb6SLionel Sambuc{
4915*0a6a1f1dSLionel Sambuc    return __x.compare(typename sub_match<_BiIter>::string_type(__y.data(), __y.size())) < 0;
49164684ddb6SLionel Sambuc}
49174684ddb6SLionel Sambuc
49184684ddb6SLionel Sambuctemplate <class _BiIter, class _ST, class _SA>
49194684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
49204684ddb6SLionel Sambucbool operator>(const sub_match<_BiIter>& __x,
49214684ddb6SLionel Sambuc               const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
49224684ddb6SLionel Sambuc{
49234684ddb6SLionel Sambuc    return __y < __x;
49244684ddb6SLionel Sambuc}
49254684ddb6SLionel Sambuc
49264684ddb6SLionel Sambuctemplate <class _BiIter, class _ST, class _SA>
49274684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
49284684ddb6SLionel Sambucbool
49294684ddb6SLionel Sambucoperator>=(const sub_match<_BiIter>& __x,
49304684ddb6SLionel Sambuc           const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
49314684ddb6SLionel Sambuc{
49324684ddb6SLionel Sambuc    return !(__x < __y);
49334684ddb6SLionel Sambuc}
49344684ddb6SLionel Sambuc
49354684ddb6SLionel Sambuctemplate <class _BiIter, class _ST, class _SA>
49364684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
49374684ddb6SLionel Sambucbool
49384684ddb6SLionel Sambucoperator<=(const sub_match<_BiIter>& __x,
49394684ddb6SLionel Sambuc           const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
49404684ddb6SLionel Sambuc{
49414684ddb6SLionel Sambuc    return !(__y < __x);
49424684ddb6SLionel Sambuc}
49434684ddb6SLionel Sambuc
49444684ddb6SLionel Sambuctemplate <class _BiIter>
49454684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
49464684ddb6SLionel Sambucbool
49474684ddb6SLionel Sambucoperator==(typename iterator_traits<_BiIter>::value_type const* __x,
49484684ddb6SLionel Sambuc           const sub_match<_BiIter>& __y)
49494684ddb6SLionel Sambuc{
49504684ddb6SLionel Sambuc    return __y.compare(__x) == 0;
49514684ddb6SLionel Sambuc}
49524684ddb6SLionel Sambuc
49534684ddb6SLionel Sambuctemplate <class _BiIter>
49544684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
49554684ddb6SLionel Sambucbool
49564684ddb6SLionel Sambucoperator!=(typename iterator_traits<_BiIter>::value_type const* __x,
49574684ddb6SLionel Sambuc           const sub_match<_BiIter>& __y)
49584684ddb6SLionel Sambuc{
49594684ddb6SLionel Sambuc    return !(__x == __y);
49604684ddb6SLionel Sambuc}
49614684ddb6SLionel Sambuc
49624684ddb6SLionel Sambuctemplate <class _BiIter>
49634684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
49644684ddb6SLionel Sambucbool
49654684ddb6SLionel Sambucoperator<(typename iterator_traits<_BiIter>::value_type const* __x,
49664684ddb6SLionel Sambuc          const sub_match<_BiIter>& __y)
49674684ddb6SLionel Sambuc{
49684684ddb6SLionel Sambuc    return __y.compare(__x) > 0;
49694684ddb6SLionel Sambuc}
49704684ddb6SLionel Sambuc
49714684ddb6SLionel Sambuctemplate <class _BiIter>
49724684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
49734684ddb6SLionel Sambucbool
49744684ddb6SLionel Sambucoperator>(typename iterator_traits<_BiIter>::value_type const* __x,
49754684ddb6SLionel Sambuc          const sub_match<_BiIter>& __y)
49764684ddb6SLionel Sambuc{
49774684ddb6SLionel Sambuc    return __y < __x;
49784684ddb6SLionel Sambuc}
49794684ddb6SLionel Sambuc
49804684ddb6SLionel Sambuctemplate <class _BiIter>
49814684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
49824684ddb6SLionel Sambucbool
49834684ddb6SLionel Sambucoperator>=(typename iterator_traits<_BiIter>::value_type const* __x,
49844684ddb6SLionel Sambuc           const sub_match<_BiIter>& __y)
49854684ddb6SLionel Sambuc{
49864684ddb6SLionel Sambuc    return !(__x < __y);
49874684ddb6SLionel Sambuc}
49884684ddb6SLionel Sambuc
49894684ddb6SLionel Sambuctemplate <class _BiIter>
49904684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
49914684ddb6SLionel Sambucbool
49924684ddb6SLionel Sambucoperator<=(typename iterator_traits<_BiIter>::value_type const* __x,
49934684ddb6SLionel Sambuc           const sub_match<_BiIter>& __y)
49944684ddb6SLionel Sambuc{
49954684ddb6SLionel Sambuc    return !(__y < __x);
49964684ddb6SLionel Sambuc}
49974684ddb6SLionel Sambuc
49984684ddb6SLionel Sambuctemplate <class _BiIter>
49994684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
50004684ddb6SLionel Sambucbool
50014684ddb6SLionel Sambucoperator==(const sub_match<_BiIter>& __x,
50024684ddb6SLionel Sambuc           typename iterator_traits<_BiIter>::value_type const* __y)
50034684ddb6SLionel Sambuc{
50044684ddb6SLionel Sambuc    return __x.compare(__y) == 0;
50054684ddb6SLionel Sambuc}
50064684ddb6SLionel Sambuc
50074684ddb6SLionel Sambuctemplate <class _BiIter>
50084684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
50094684ddb6SLionel Sambucbool
50104684ddb6SLionel Sambucoperator!=(const sub_match<_BiIter>& __x,
50114684ddb6SLionel Sambuc           typename iterator_traits<_BiIter>::value_type const* __y)
50124684ddb6SLionel Sambuc{
50134684ddb6SLionel Sambuc    return !(__x == __y);
50144684ddb6SLionel Sambuc}
50154684ddb6SLionel Sambuc
50164684ddb6SLionel Sambuctemplate <class _BiIter>
50174684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
50184684ddb6SLionel Sambucbool
50194684ddb6SLionel Sambucoperator<(const sub_match<_BiIter>& __x,
50204684ddb6SLionel Sambuc          typename iterator_traits<_BiIter>::value_type const* __y)
50214684ddb6SLionel Sambuc{
50224684ddb6SLionel Sambuc    return __x.compare(__y) < 0;
50234684ddb6SLionel Sambuc}
50244684ddb6SLionel Sambuc
50254684ddb6SLionel Sambuctemplate <class _BiIter>
50264684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
50274684ddb6SLionel Sambucbool
50284684ddb6SLionel Sambucoperator>(const sub_match<_BiIter>& __x,
50294684ddb6SLionel Sambuc          typename iterator_traits<_BiIter>::value_type const* __y)
50304684ddb6SLionel Sambuc{
50314684ddb6SLionel Sambuc    return __y < __x;
50324684ddb6SLionel Sambuc}
50334684ddb6SLionel Sambuc
50344684ddb6SLionel Sambuctemplate <class _BiIter>
50354684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
50364684ddb6SLionel Sambucbool
50374684ddb6SLionel Sambucoperator>=(const sub_match<_BiIter>& __x,
50384684ddb6SLionel Sambuc           typename iterator_traits<_BiIter>::value_type const* __y)
50394684ddb6SLionel Sambuc{
50404684ddb6SLionel Sambuc    return !(__x < __y);
50414684ddb6SLionel Sambuc}
50424684ddb6SLionel Sambuc
50434684ddb6SLionel Sambuctemplate <class _BiIter>
50444684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
50454684ddb6SLionel Sambucbool
50464684ddb6SLionel Sambucoperator<=(const sub_match<_BiIter>& __x,
50474684ddb6SLionel Sambuc           typename iterator_traits<_BiIter>::value_type const* __y)
50484684ddb6SLionel Sambuc{
50494684ddb6SLionel Sambuc    return !(__y < __x);
50504684ddb6SLionel Sambuc}
50514684ddb6SLionel Sambuc
50524684ddb6SLionel Sambuctemplate <class _BiIter>
50534684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
50544684ddb6SLionel Sambucbool
50554684ddb6SLionel Sambucoperator==(typename iterator_traits<_BiIter>::value_type const& __x,
50564684ddb6SLionel Sambuc           const sub_match<_BiIter>& __y)
50574684ddb6SLionel Sambuc{
50584684ddb6SLionel Sambuc    typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
50594684ddb6SLionel Sambuc    return __y.compare(string_type(1, __x)) == 0;
50604684ddb6SLionel Sambuc}
50614684ddb6SLionel Sambuc
50624684ddb6SLionel Sambuctemplate <class _BiIter>
50634684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
50644684ddb6SLionel Sambucbool
50654684ddb6SLionel Sambucoperator!=(typename iterator_traits<_BiIter>::value_type const& __x,
50664684ddb6SLionel Sambuc           const sub_match<_BiIter>& __y)
50674684ddb6SLionel Sambuc{
50684684ddb6SLionel Sambuc    return !(__x == __y);
50694684ddb6SLionel Sambuc}
50704684ddb6SLionel Sambuc
50714684ddb6SLionel Sambuctemplate <class _BiIter>
50724684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
50734684ddb6SLionel Sambucbool
50744684ddb6SLionel Sambucoperator<(typename iterator_traits<_BiIter>::value_type const& __x,
50754684ddb6SLionel Sambuc          const sub_match<_BiIter>& __y)
50764684ddb6SLionel Sambuc{
50774684ddb6SLionel Sambuc    typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
50784684ddb6SLionel Sambuc    return __y.compare(string_type(1, __x)) > 0;
50794684ddb6SLionel Sambuc}
50804684ddb6SLionel Sambuc
50814684ddb6SLionel Sambuctemplate <class _BiIter>
50824684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
50834684ddb6SLionel Sambucbool
50844684ddb6SLionel Sambucoperator>(typename iterator_traits<_BiIter>::value_type const& __x,
50854684ddb6SLionel Sambuc          const sub_match<_BiIter>& __y)
50864684ddb6SLionel Sambuc{
50874684ddb6SLionel Sambuc    return __y < __x;
50884684ddb6SLionel Sambuc}
50894684ddb6SLionel Sambuc
50904684ddb6SLionel Sambuctemplate <class _BiIter>
50914684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
50924684ddb6SLionel Sambucbool
50934684ddb6SLionel Sambucoperator>=(typename iterator_traits<_BiIter>::value_type const& __x,
50944684ddb6SLionel Sambuc           const sub_match<_BiIter>& __y)
50954684ddb6SLionel Sambuc{
50964684ddb6SLionel Sambuc    return !(__x < __y);
50974684ddb6SLionel Sambuc}
50984684ddb6SLionel Sambuc
50994684ddb6SLionel Sambuctemplate <class _BiIter>
51004684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
51014684ddb6SLionel Sambucbool
51024684ddb6SLionel Sambucoperator<=(typename iterator_traits<_BiIter>::value_type const& __x,
51034684ddb6SLionel Sambuc           const sub_match<_BiIter>& __y)
51044684ddb6SLionel Sambuc{
51054684ddb6SLionel Sambuc    return !(__y < __x);
51064684ddb6SLionel Sambuc}
51074684ddb6SLionel Sambuc
51084684ddb6SLionel Sambuctemplate <class _BiIter>
51094684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
51104684ddb6SLionel Sambucbool
51114684ddb6SLionel Sambucoperator==(const sub_match<_BiIter>& __x,
51124684ddb6SLionel Sambuc           typename iterator_traits<_BiIter>::value_type const& __y)
51134684ddb6SLionel Sambuc{
51144684ddb6SLionel Sambuc    typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
51154684ddb6SLionel Sambuc    return __x.compare(string_type(1, __y)) == 0;
51164684ddb6SLionel Sambuc}
51174684ddb6SLionel Sambuc
51184684ddb6SLionel Sambuctemplate <class _BiIter>
51194684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
51204684ddb6SLionel Sambucbool
51214684ddb6SLionel Sambucoperator!=(const sub_match<_BiIter>& __x,
51224684ddb6SLionel Sambuc           typename iterator_traits<_BiIter>::value_type const& __y)
51234684ddb6SLionel Sambuc{
51244684ddb6SLionel Sambuc    return !(__x == __y);
51254684ddb6SLionel Sambuc}
51264684ddb6SLionel Sambuc
51274684ddb6SLionel Sambuctemplate <class _BiIter>
51284684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
51294684ddb6SLionel Sambucbool
51304684ddb6SLionel Sambucoperator<(const sub_match<_BiIter>& __x,
51314684ddb6SLionel Sambuc          typename iterator_traits<_BiIter>::value_type const& __y)
51324684ddb6SLionel Sambuc{
51334684ddb6SLionel Sambuc    typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
51344684ddb6SLionel Sambuc    return __x.compare(string_type(1, __y)) < 0;
51354684ddb6SLionel Sambuc}
51364684ddb6SLionel Sambuc
51374684ddb6SLionel Sambuctemplate <class _BiIter>
51384684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
51394684ddb6SLionel Sambucbool
51404684ddb6SLionel Sambucoperator>(const sub_match<_BiIter>& __x,
51414684ddb6SLionel Sambuc          typename iterator_traits<_BiIter>::value_type const& __y)
51424684ddb6SLionel Sambuc{
51434684ddb6SLionel Sambuc    return __y < __x;
51444684ddb6SLionel Sambuc}
51454684ddb6SLionel Sambuc
51464684ddb6SLionel Sambuctemplate <class _BiIter>
51474684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
51484684ddb6SLionel Sambucbool
51494684ddb6SLionel Sambucoperator>=(const sub_match<_BiIter>& __x,
51504684ddb6SLionel Sambuc           typename iterator_traits<_BiIter>::value_type const& __y)
51514684ddb6SLionel Sambuc{
51524684ddb6SLionel Sambuc    return !(__x < __y);
51534684ddb6SLionel Sambuc}
51544684ddb6SLionel Sambuc
51554684ddb6SLionel Sambuctemplate <class _BiIter>
51564684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
51574684ddb6SLionel Sambucbool
51584684ddb6SLionel Sambucoperator<=(const sub_match<_BiIter>& __x,
51594684ddb6SLionel Sambuc           typename iterator_traits<_BiIter>::value_type const& __y)
51604684ddb6SLionel Sambuc{
51614684ddb6SLionel Sambuc    return !(__y < __x);
51624684ddb6SLionel Sambuc}
51634684ddb6SLionel Sambuc
51644684ddb6SLionel Sambuctemplate <class _CharT, class _ST, class _BiIter>
51654684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
51664684ddb6SLionel Sambucbasic_ostream<_CharT, _ST>&
51674684ddb6SLionel Sambucoperator<<(basic_ostream<_CharT, _ST>& __os, const sub_match<_BiIter>& __m)
51684684ddb6SLionel Sambuc{
51694684ddb6SLionel Sambuc    return __os << __m.str();
51704684ddb6SLionel Sambuc}
51714684ddb6SLionel Sambuc
51724684ddb6SLionel Sambuctemplate <class _BidirectionalIterator, class _Allocator>
51734684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS_ONLY match_results
51744684ddb6SLionel Sambuc{
51754684ddb6SLionel Sambucpublic:
51764684ddb6SLionel Sambuc    typedef _Allocator                                        allocator_type;
51774684ddb6SLionel Sambuc    typedef sub_match<_BidirectionalIterator>                 value_type;
51784684ddb6SLionel Sambucprivate:
51794684ddb6SLionel Sambuc    typedef vector<value_type, allocator_type>                __container_type;
51804684ddb6SLionel Sambuc
51814684ddb6SLionel Sambuc    __container_type  __matches_;
51824684ddb6SLionel Sambuc    value_type __unmatched_;
51834684ddb6SLionel Sambuc    value_type __prefix_;
51844684ddb6SLionel Sambuc    value_type __suffix_;
51854684ddb6SLionel Sambuc    bool       __ready_;
51864684ddb6SLionel Sambucpublic:
51874684ddb6SLionel Sambuc    _BidirectionalIterator __position_start_;
51884684ddb6SLionel Sambuc    typedef const value_type&                                 const_reference;
5189*0a6a1f1dSLionel Sambuc    typedef value_type&                                       reference;
51904684ddb6SLionel Sambuc    typedef typename __container_type::const_iterator         const_iterator;
51914684ddb6SLionel Sambuc    typedef const_iterator                                    iterator;
51924684ddb6SLionel Sambuc    typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type;
51934684ddb6SLionel Sambuc    typedef typename allocator_traits<allocator_type>::size_type size_type;
51944684ddb6SLionel Sambuc    typedef typename iterator_traits<_BidirectionalIterator>::value_type char_type;
51954684ddb6SLionel Sambuc    typedef basic_string<char_type>                           string_type;
51964684ddb6SLionel Sambuc
51974684ddb6SLionel Sambuc    // construct/copy/destroy:
51984684ddb6SLionel Sambuc    explicit match_results(const allocator_type& __a = allocator_type());
51994684ddb6SLionel Sambuc//    match_results(const match_results&) = default;
52004684ddb6SLionel Sambuc//    match_results& operator=(const match_results&) = default;
52014684ddb6SLionel Sambuc//    match_results(match_results&& __m) = default;
52024684ddb6SLionel Sambuc//    match_results& operator=(match_results&& __m) = default;
52034684ddb6SLionel Sambuc//    ~match_results() = default;
52044684ddb6SLionel Sambuc
52054684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
52064684ddb6SLionel Sambuc    bool ready() const {return __ready_;}
52074684ddb6SLionel Sambuc
52084684ddb6SLionel Sambuc    // size:
52094684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
52104684ddb6SLionel Sambuc    size_type size() const {return __matches_.size();}
52114684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
52124684ddb6SLionel Sambuc    size_type max_size() const {return __matches_.max_size();}
52134684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
52144684ddb6SLionel Sambuc    bool empty() const {return size() == 0;}
52154684ddb6SLionel Sambuc
52164684ddb6SLionel Sambuc    // element access:
52174684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
52184684ddb6SLionel Sambuc    difference_type length(size_type __sub = 0) const
52194684ddb6SLionel Sambuc        {return (*this)[__sub].length();}
52204684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
52214684ddb6SLionel Sambuc    difference_type position(size_type __sub = 0) const
52224684ddb6SLionel Sambuc        {return _VSTD::distance(__position_start_, (*this)[__sub].first);}
52234684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
52244684ddb6SLionel Sambuc    string_type str(size_type __sub = 0) const
52254684ddb6SLionel Sambuc        {return (*this)[__sub].str();}
52264684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
52274684ddb6SLionel Sambuc    const_reference operator[](size_type __n) const
52284684ddb6SLionel Sambuc        {return __n < __matches_.size() ? __matches_[__n] : __unmatched_;}
52294684ddb6SLionel Sambuc
52304684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
52314684ddb6SLionel Sambuc    const_reference prefix() const {return __prefix_;}
52324684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
52334684ddb6SLionel Sambuc    const_reference suffix() const {return __suffix_;}
52344684ddb6SLionel Sambuc
52354684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
52364684ddb6SLionel Sambuc    const_iterator begin() const {return empty() ? __matches_.end() : __matches_.begin();}
52374684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
52384684ddb6SLionel Sambuc    const_iterator end() const {return __matches_.end();}
52394684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
52404684ddb6SLionel Sambuc    const_iterator cbegin() const {return empty() ? __matches_.end() : __matches_.begin();}
52414684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
52424684ddb6SLionel Sambuc    const_iterator cend() const {return __matches_.end();}
52434684ddb6SLionel Sambuc
52444684ddb6SLionel Sambuc    // format:
52454684ddb6SLionel Sambuc    template <class _OutputIter>
52464684ddb6SLionel Sambuc        _OutputIter
52474684ddb6SLionel Sambuc        format(_OutputIter __out, const char_type* __fmt_first,
52484684ddb6SLionel Sambuc               const char_type* __fmt_last,
52494684ddb6SLionel Sambuc               regex_constants::match_flag_type __flags = regex_constants::format_default) const;
52504684ddb6SLionel Sambuc    template <class _OutputIter, class _ST, class _SA>
52514684ddb6SLionel Sambuc        _LIBCPP_INLINE_VISIBILITY
52524684ddb6SLionel Sambuc        _OutputIter
52534684ddb6SLionel Sambuc        format(_OutputIter __out, const basic_string<char_type, _ST, _SA>& __fmt,
52544684ddb6SLionel Sambuc               regex_constants::match_flag_type __flags = regex_constants::format_default) const
52554684ddb6SLionel Sambuc            {return format(__out, __fmt.data(), __fmt.data() + __fmt.size(), __flags);}
52564684ddb6SLionel Sambuc    template <class _ST, class _SA>
52574684ddb6SLionel Sambuc        _LIBCPP_INLINE_VISIBILITY
52584684ddb6SLionel Sambuc        basic_string<char_type, _ST, _SA>
52594684ddb6SLionel Sambuc        format(const basic_string<char_type, _ST, _SA>& __fmt,
52604684ddb6SLionel Sambuc               regex_constants::match_flag_type __flags = regex_constants::format_default) const
52614684ddb6SLionel Sambuc        {
52624684ddb6SLionel Sambuc            basic_string<char_type, _ST, _SA> __r;
52634684ddb6SLionel Sambuc            format(back_inserter(__r), __fmt.data(), __fmt.data() + __fmt.size(),
52644684ddb6SLionel Sambuc                   __flags);
52654684ddb6SLionel Sambuc            return __r;
52664684ddb6SLionel Sambuc        }
52674684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
52684684ddb6SLionel Sambuc    string_type
52694684ddb6SLionel Sambuc        format(const char_type* __fmt,
52704684ddb6SLionel Sambuc               regex_constants::match_flag_type __flags = regex_constants::format_default) const
52714684ddb6SLionel Sambuc        {
52724684ddb6SLionel Sambuc            string_type __r;
52734684ddb6SLionel Sambuc            format(back_inserter(__r), __fmt,
52744684ddb6SLionel Sambuc                   __fmt + char_traits<char_type>::length(__fmt), __flags);
52754684ddb6SLionel Sambuc            return __r;
52764684ddb6SLionel Sambuc        }
52774684ddb6SLionel Sambuc
52784684ddb6SLionel Sambuc    // allocator:
52794684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
52804684ddb6SLionel Sambuc    allocator_type get_allocator() const {return __matches_.get_allocator();}
52814684ddb6SLionel Sambuc
52824684ddb6SLionel Sambuc    // swap:
52834684ddb6SLionel Sambuc    void swap(match_results& __m);
52844684ddb6SLionel Sambuc
52854684ddb6SLionel Sambuc    template <class _Bp, class _Ap>
52864684ddb6SLionel Sambuc        _LIBCPP_INLINE_VISIBILITY
52874684ddb6SLionel Sambuc        void __assign(_BidirectionalIterator __f, _BidirectionalIterator __l,
52884684ddb6SLionel Sambuc                      const match_results<_Bp, _Ap>& __m, bool __no_update_pos)
52894684ddb6SLionel Sambuc    {
52904684ddb6SLionel Sambuc        _Bp __mf = __m.prefix().first;
52914684ddb6SLionel Sambuc        __matches_.resize(__m.size());
52924684ddb6SLionel Sambuc        for (size_type __i = 0; __i < __matches_.size(); ++__i)
52934684ddb6SLionel Sambuc        {
52944684ddb6SLionel Sambuc            __matches_[__i].first = _VSTD::next(__f, _VSTD::distance(__mf, __m[__i].first));
52954684ddb6SLionel Sambuc            __matches_[__i].second = _VSTD::next(__f, _VSTD::distance(__mf, __m[__i].second));
52964684ddb6SLionel Sambuc            __matches_[__i].matched = __m[__i].matched;
52974684ddb6SLionel Sambuc        }
52984684ddb6SLionel Sambuc        __unmatched_.first   = __l;
52994684ddb6SLionel Sambuc        __unmatched_.second  = __l;
53004684ddb6SLionel Sambuc        __unmatched_.matched = false;
53014684ddb6SLionel Sambuc        __prefix_.first = _VSTD::next(__f, _VSTD::distance(__mf, __m.prefix().first));
53024684ddb6SLionel Sambuc        __prefix_.second = _VSTD::next(__f, _VSTD::distance(__mf, __m.prefix().second));
53034684ddb6SLionel Sambuc        __prefix_.matched = __m.prefix().matched;
53044684ddb6SLionel Sambuc        __suffix_.first = _VSTD::next(__f, _VSTD::distance(__mf, __m.suffix().first));
53054684ddb6SLionel Sambuc        __suffix_.second = _VSTD::next(__f, _VSTD::distance(__mf, __m.suffix().second));
53064684ddb6SLionel Sambuc        __suffix_.matched = __m.suffix().matched;
53074684ddb6SLionel Sambuc        if (!__no_update_pos)
53084684ddb6SLionel Sambuc            __position_start_ = __prefix_.first;
53094684ddb6SLionel Sambuc        __ready_ = __m.ready();
53104684ddb6SLionel Sambuc    }
53114684ddb6SLionel Sambuc
53124684ddb6SLionel Sambucprivate:
53134684ddb6SLionel Sambuc    void __init(unsigned __s,
53144684ddb6SLionel Sambuc                _BidirectionalIterator __f, _BidirectionalIterator __l,
53154684ddb6SLionel Sambuc                bool __no_update_pos = false);
53164684ddb6SLionel Sambuc
53174684ddb6SLionel Sambuc    template <class, class> friend class basic_regex;
53184684ddb6SLionel Sambuc
53194684ddb6SLionel Sambuc    template <class _Bp, class _Ap, class _Cp, class _Tp>
53204684ddb6SLionel Sambuc    friend
53214684ddb6SLionel Sambuc    bool
53224684ddb6SLionel Sambuc    regex_match(_Bp, _Bp, match_results<_Bp, _Ap>&, const basic_regex<_Cp, _Tp>&,
53234684ddb6SLionel Sambuc                regex_constants::match_flag_type);
53244684ddb6SLionel Sambuc
53254684ddb6SLionel Sambuc    template <class _Bp, class _Ap>
53264684ddb6SLionel Sambuc    friend
53274684ddb6SLionel Sambuc    bool
53284684ddb6SLionel Sambuc    operator==(const match_results<_Bp, _Ap>&, const match_results<_Bp, _Ap>&);
53294684ddb6SLionel Sambuc
53304684ddb6SLionel Sambuc    template <class, class> friend class __lookahead;
53314684ddb6SLionel Sambuc};
53324684ddb6SLionel Sambuc
53334684ddb6SLionel Sambuctemplate <class _BidirectionalIterator, class _Allocator>
53344684ddb6SLionel Sambucmatch_results<_BidirectionalIterator, _Allocator>::match_results(
53354684ddb6SLionel Sambuc        const allocator_type& __a)
53364684ddb6SLionel Sambuc    : __matches_(__a),
53374684ddb6SLionel Sambuc      __unmatched_(),
53384684ddb6SLionel Sambuc      __prefix_(),
53394684ddb6SLionel Sambuc      __suffix_(),
5340*0a6a1f1dSLionel Sambuc      __ready_(false),
5341*0a6a1f1dSLionel Sambuc      __position_start_()
53424684ddb6SLionel Sambuc{
53434684ddb6SLionel Sambuc}
53444684ddb6SLionel Sambuc
53454684ddb6SLionel Sambuctemplate <class _BidirectionalIterator, class _Allocator>
53464684ddb6SLionel Sambucvoid
53474684ddb6SLionel Sambucmatch_results<_BidirectionalIterator, _Allocator>::__init(unsigned __s,
53484684ddb6SLionel Sambuc                         _BidirectionalIterator __f, _BidirectionalIterator __l,
53494684ddb6SLionel Sambuc                         bool __no_update_pos)
53504684ddb6SLionel Sambuc{
53514684ddb6SLionel Sambuc    __unmatched_.first   = __l;
53524684ddb6SLionel Sambuc    __unmatched_.second  = __l;
53534684ddb6SLionel Sambuc    __unmatched_.matched = false;
53544684ddb6SLionel Sambuc    __matches_.assign(__s, __unmatched_);
53554684ddb6SLionel Sambuc    __prefix_.first      = __f;
53564684ddb6SLionel Sambuc    __prefix_.second     = __f;
53574684ddb6SLionel Sambuc    __prefix_.matched    = false;
53584684ddb6SLionel Sambuc    __suffix_ = __unmatched_;
53594684ddb6SLionel Sambuc    if (!__no_update_pos)
53604684ddb6SLionel Sambuc        __position_start_ = __prefix_.first;
53614684ddb6SLionel Sambuc    __ready_ = true;
53624684ddb6SLionel Sambuc}
53634684ddb6SLionel Sambuc
53644684ddb6SLionel Sambuctemplate <class _BidirectionalIterator, class _Allocator>
53654684ddb6SLionel Sambuctemplate <class _OutputIter>
53664684ddb6SLionel Sambuc_OutputIter
53674684ddb6SLionel Sambucmatch_results<_BidirectionalIterator, _Allocator>::format(_OutputIter __out,
53684684ddb6SLionel Sambuc        const char_type* __fmt_first, const char_type* __fmt_last,
53694684ddb6SLionel Sambuc        regex_constants::match_flag_type __flags) const
53704684ddb6SLionel Sambuc{
53714684ddb6SLionel Sambuc    if (__flags & regex_constants::format_sed)
53724684ddb6SLionel Sambuc    {
53734684ddb6SLionel Sambuc        for (; __fmt_first != __fmt_last; ++__fmt_first)
53744684ddb6SLionel Sambuc        {
53754684ddb6SLionel Sambuc            if (*__fmt_first == '&')
53764684ddb6SLionel Sambuc                __out = _VSTD::copy(__matches_[0].first, __matches_[0].second,
53774684ddb6SLionel Sambuc                                   __out);
53784684ddb6SLionel Sambuc            else if (*__fmt_first == '\\' && __fmt_first + 1 != __fmt_last)
53794684ddb6SLionel Sambuc            {
53804684ddb6SLionel Sambuc                ++__fmt_first;
53814684ddb6SLionel Sambuc                if ('0' <= *__fmt_first && *__fmt_first <= '9')
53824684ddb6SLionel Sambuc                {
53834684ddb6SLionel Sambuc                    size_t __i = *__fmt_first - '0';
53844684ddb6SLionel Sambuc                    __out = _VSTD::copy(__matches_[__i].first,
53854684ddb6SLionel Sambuc                                       __matches_[__i].second, __out);
53864684ddb6SLionel Sambuc                }
53874684ddb6SLionel Sambuc                else
53884684ddb6SLionel Sambuc                {
53894684ddb6SLionel Sambuc                    *__out = *__fmt_first;
53904684ddb6SLionel Sambuc                    ++__out;
53914684ddb6SLionel Sambuc                }
53924684ddb6SLionel Sambuc            }
53934684ddb6SLionel Sambuc            else
53944684ddb6SLionel Sambuc            {
53954684ddb6SLionel Sambuc                *__out = *__fmt_first;
53964684ddb6SLionel Sambuc                ++__out;
53974684ddb6SLionel Sambuc            }
53984684ddb6SLionel Sambuc        }
53994684ddb6SLionel Sambuc    }
54004684ddb6SLionel Sambuc    else
54014684ddb6SLionel Sambuc    {
54024684ddb6SLionel Sambuc        for (; __fmt_first != __fmt_last; ++__fmt_first)
54034684ddb6SLionel Sambuc        {
54044684ddb6SLionel Sambuc            if (*__fmt_first == '$' && __fmt_first + 1 != __fmt_last)
54054684ddb6SLionel Sambuc            {
54064684ddb6SLionel Sambuc                switch (__fmt_first[1])
54074684ddb6SLionel Sambuc                {
54084684ddb6SLionel Sambuc                case '$':
54094684ddb6SLionel Sambuc                    *__out = *++__fmt_first;
54104684ddb6SLionel Sambuc                    ++__out;
54114684ddb6SLionel Sambuc                    break;
54124684ddb6SLionel Sambuc                case '&':
54134684ddb6SLionel Sambuc                    ++__fmt_first;
54144684ddb6SLionel Sambuc                    __out = _VSTD::copy(__matches_[0].first, __matches_[0].second,
54154684ddb6SLionel Sambuc                                       __out);
54164684ddb6SLionel Sambuc                    break;
54174684ddb6SLionel Sambuc                case '`':
54184684ddb6SLionel Sambuc                    ++__fmt_first;
54194684ddb6SLionel Sambuc                    __out = _VSTD::copy(__prefix_.first, __prefix_.second, __out);
54204684ddb6SLionel Sambuc                    break;
54214684ddb6SLionel Sambuc                case '\'':
54224684ddb6SLionel Sambuc                    ++__fmt_first;
54234684ddb6SLionel Sambuc                    __out = _VSTD::copy(__suffix_.first, __suffix_.second, __out);
54244684ddb6SLionel Sambuc                    break;
54254684ddb6SLionel Sambuc                default:
54264684ddb6SLionel Sambuc                    if ('0' <= __fmt_first[1] && __fmt_first[1] <= '9')
54274684ddb6SLionel Sambuc                    {
54284684ddb6SLionel Sambuc                        ++__fmt_first;
54294684ddb6SLionel Sambuc                        size_t __i = *__fmt_first - '0';
54304684ddb6SLionel Sambuc                        if (__fmt_first + 1 != __fmt_last &&
54314684ddb6SLionel Sambuc                            '0' <= __fmt_first[1] && __fmt_first[1] <= '9')
54324684ddb6SLionel Sambuc                        {
54334684ddb6SLionel Sambuc                            ++__fmt_first;
54344684ddb6SLionel Sambuc                            __i = 10 * __i + *__fmt_first - '0';
54354684ddb6SLionel Sambuc                        }
54364684ddb6SLionel Sambuc                        __out = _VSTD::copy(__matches_[__i].first,
54374684ddb6SLionel Sambuc                                           __matches_[__i].second, __out);
54384684ddb6SLionel Sambuc                    }
54394684ddb6SLionel Sambuc                    else
54404684ddb6SLionel Sambuc                    {
54414684ddb6SLionel Sambuc                        *__out = *__fmt_first;
54424684ddb6SLionel Sambuc                        ++__out;
54434684ddb6SLionel Sambuc                    }
54444684ddb6SLionel Sambuc                    break;
54454684ddb6SLionel Sambuc                }
54464684ddb6SLionel Sambuc            }
54474684ddb6SLionel Sambuc            else
54484684ddb6SLionel Sambuc            {
54494684ddb6SLionel Sambuc                *__out = *__fmt_first;
54504684ddb6SLionel Sambuc                ++__out;
54514684ddb6SLionel Sambuc            }
54524684ddb6SLionel Sambuc        }
54534684ddb6SLionel Sambuc    }
54544684ddb6SLionel Sambuc    return __out;
54554684ddb6SLionel Sambuc}
54564684ddb6SLionel Sambuc
54574684ddb6SLionel Sambuctemplate <class _BidirectionalIterator, class _Allocator>
54584684ddb6SLionel Sambucvoid
54594684ddb6SLionel Sambucmatch_results<_BidirectionalIterator, _Allocator>::swap(match_results& __m)
54604684ddb6SLionel Sambuc{
54614684ddb6SLionel Sambuc    using _VSTD::swap;
54624684ddb6SLionel Sambuc    swap(__matches_, __m.__matches_);
54634684ddb6SLionel Sambuc    swap(__unmatched_, __m.__unmatched_);
54644684ddb6SLionel Sambuc    swap(__prefix_, __m.__prefix_);
54654684ddb6SLionel Sambuc    swap(__suffix_, __m.__suffix_);
54664684ddb6SLionel Sambuc    swap(__position_start_, __m.__position_start_);
54674684ddb6SLionel Sambuc    swap(__ready_, __m.__ready_);
54684684ddb6SLionel Sambuc}
54694684ddb6SLionel Sambuc
54704684ddb6SLionel Sambuctypedef match_results<const char*>             cmatch;
54714684ddb6SLionel Sambuctypedef match_results<const wchar_t*>          wcmatch;
54724684ddb6SLionel Sambuctypedef match_results<string::const_iterator>  smatch;
54734684ddb6SLionel Sambuctypedef match_results<wstring::const_iterator> wsmatch;
54744684ddb6SLionel Sambuc
54754684ddb6SLionel Sambuctemplate <class _BidirectionalIterator, class _Allocator>
54764684ddb6SLionel Sambucbool
54774684ddb6SLionel Sambucoperator==(const match_results<_BidirectionalIterator, _Allocator>& __x,
54784684ddb6SLionel Sambuc           const match_results<_BidirectionalIterator, _Allocator>& __y)
54794684ddb6SLionel Sambuc{
54804684ddb6SLionel Sambuc    if (__x.__ready_ != __y.__ready_)
54814684ddb6SLionel Sambuc        return false;
54824684ddb6SLionel Sambuc    if (!__x.__ready_)
54834684ddb6SLionel Sambuc        return true;
54844684ddb6SLionel Sambuc    return __x.__matches_ == __y.__matches_ &&
54854684ddb6SLionel Sambuc           __x.__prefix_ == __y.__prefix_ &&
54864684ddb6SLionel Sambuc           __x.__suffix_ == __y.__suffix_;
54874684ddb6SLionel Sambuc}
54884684ddb6SLionel Sambuc
54894684ddb6SLionel Sambuctemplate <class _BidirectionalIterator, class _Allocator>
54904684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
54914684ddb6SLionel Sambucbool
54924684ddb6SLionel Sambucoperator!=(const match_results<_BidirectionalIterator, _Allocator>& __x,
54934684ddb6SLionel Sambuc           const match_results<_BidirectionalIterator, _Allocator>& __y)
54944684ddb6SLionel Sambuc{
54954684ddb6SLionel Sambuc    return !(__x == __y);
54964684ddb6SLionel Sambuc}
54974684ddb6SLionel Sambuc
54984684ddb6SLionel Sambuctemplate <class _BidirectionalIterator, class _Allocator>
54994684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
55004684ddb6SLionel Sambucvoid
55014684ddb6SLionel Sambucswap(match_results<_BidirectionalIterator, _Allocator>& __x,
55024684ddb6SLionel Sambuc     match_results<_BidirectionalIterator, _Allocator>& __y)
55034684ddb6SLionel Sambuc{
55044684ddb6SLionel Sambuc    __x.swap(__y);
55054684ddb6SLionel Sambuc}
55064684ddb6SLionel Sambuc
55074684ddb6SLionel Sambuc// regex_search
55084684ddb6SLionel Sambuc
55094684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
55104684ddb6SLionel Sambuctemplate <class _Allocator>
55114684ddb6SLionel Sambucbool
55124684ddb6SLionel Sambucbasic_regex<_CharT, _Traits>::__match_at_start_ecma(
55134684ddb6SLionel Sambuc        const _CharT* __first, const _CharT* __last,
55144684ddb6SLionel Sambuc        match_results<const _CharT*, _Allocator>& __m,
55154684ddb6SLionel Sambuc        regex_constants::match_flag_type __flags, bool __at_first) const
55164684ddb6SLionel Sambuc{
55174684ddb6SLionel Sambuc    vector<__state> __states;
55184684ddb6SLionel Sambuc    __node* __st = __start_.get();
55194684ddb6SLionel Sambuc    if (__st)
55204684ddb6SLionel Sambuc    {
5521*0a6a1f1dSLionel Sambuc        sub_match<const _CharT*> __unmatched;
5522*0a6a1f1dSLionel Sambuc        __unmatched.first   = __last;
5523*0a6a1f1dSLionel Sambuc        __unmatched.second  = __last;
5524*0a6a1f1dSLionel Sambuc        __unmatched.matched = false;
5525*0a6a1f1dSLionel Sambuc
55264684ddb6SLionel Sambuc        __states.push_back(__state());
55274684ddb6SLionel Sambuc        __states.back().__do_ = 0;
55284684ddb6SLionel Sambuc        __states.back().__first_ = __first;
55294684ddb6SLionel Sambuc        __states.back().__current_ = __first;
55304684ddb6SLionel Sambuc        __states.back().__last_ = __last;
5531*0a6a1f1dSLionel Sambuc        __states.back().__sub_matches_.resize(mark_count(), __unmatched);
55324684ddb6SLionel Sambuc        __states.back().__loop_data_.resize(__loop_count());
55334684ddb6SLionel Sambuc        __states.back().__node_ = __st;
55344684ddb6SLionel Sambuc        __states.back().__flags_ = __flags;
55354684ddb6SLionel Sambuc        __states.back().__at_first_ = __at_first;
55364684ddb6SLionel Sambuc        do
55374684ddb6SLionel Sambuc        {
55384684ddb6SLionel Sambuc            __state& __s = __states.back();
55394684ddb6SLionel Sambuc            if (__s.__node_)
55404684ddb6SLionel Sambuc                __s.__node_->__exec(__s);
55414684ddb6SLionel Sambuc            switch (__s.__do_)
55424684ddb6SLionel Sambuc            {
55434684ddb6SLionel Sambuc            case __state::__end_state:
55444684ddb6SLionel Sambuc                __m.__matches_[0].first = __first;
55454684ddb6SLionel Sambuc                __m.__matches_[0].second = _VSTD::next(__first, __s.__current_ - __first);
55464684ddb6SLionel Sambuc                __m.__matches_[0].matched = true;
55474684ddb6SLionel Sambuc                for (unsigned __i = 0; __i < __s.__sub_matches_.size(); ++__i)
55484684ddb6SLionel Sambuc                    __m.__matches_[__i+1] = __s.__sub_matches_[__i];
55494684ddb6SLionel Sambuc                return true;
55504684ddb6SLionel Sambuc            case __state::__accept_and_consume:
55514684ddb6SLionel Sambuc            case __state::__repeat:
55524684ddb6SLionel Sambuc            case __state::__accept_but_not_consume:
55534684ddb6SLionel Sambuc                break;
55544684ddb6SLionel Sambuc            case __state::__split:
55554684ddb6SLionel Sambuc                {
55564684ddb6SLionel Sambuc                __state __snext = __s;
55574684ddb6SLionel Sambuc                __s.__node_->__exec_split(true, __s);
55584684ddb6SLionel Sambuc                __snext.__node_->__exec_split(false, __snext);
55594684ddb6SLionel Sambuc                __states.push_back(_VSTD::move(__snext));
55604684ddb6SLionel Sambuc                }
55614684ddb6SLionel Sambuc                break;
55624684ddb6SLionel Sambuc            case __state::__reject:
55634684ddb6SLionel Sambuc                __states.pop_back();
55644684ddb6SLionel Sambuc                break;
55654684ddb6SLionel Sambuc            default:
5566*0a6a1f1dSLionel Sambuc                __throw_regex_error<regex_constants::__re_err_unknown>();
55674684ddb6SLionel Sambuc                break;
55684684ddb6SLionel Sambuc
55694684ddb6SLionel Sambuc            }
55704684ddb6SLionel Sambuc        } while (!__states.empty());
55714684ddb6SLionel Sambuc    }
55724684ddb6SLionel Sambuc    return false;
55734684ddb6SLionel Sambuc}
55744684ddb6SLionel Sambuc
55754684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
55764684ddb6SLionel Sambuctemplate <class _Allocator>
55774684ddb6SLionel Sambucbool
55784684ddb6SLionel Sambucbasic_regex<_CharT, _Traits>::__match_at_start_posix_nosubs(
55794684ddb6SLionel Sambuc        const _CharT* __first, const _CharT* __last,
55804684ddb6SLionel Sambuc        match_results<const _CharT*, _Allocator>& __m,
55814684ddb6SLionel Sambuc        regex_constants::match_flag_type __flags, bool __at_first) const
55824684ddb6SLionel Sambuc{
55834684ddb6SLionel Sambuc    deque<__state> __states;
55844684ddb6SLionel Sambuc    ptrdiff_t __highest_j = 0;
55854684ddb6SLionel Sambuc    ptrdiff_t _Np = _VSTD::distance(__first, __last);
55864684ddb6SLionel Sambuc    __node* __st = __start_.get();
55874684ddb6SLionel Sambuc    if (__st)
55884684ddb6SLionel Sambuc    {
55894684ddb6SLionel Sambuc        __states.push_back(__state());
55904684ddb6SLionel Sambuc        __states.back().__do_ = 0;
55914684ddb6SLionel Sambuc        __states.back().__first_ = __first;
55924684ddb6SLionel Sambuc        __states.back().__current_ = __first;
55934684ddb6SLionel Sambuc        __states.back().__last_ = __last;
55944684ddb6SLionel Sambuc        __states.back().__loop_data_.resize(__loop_count());
55954684ddb6SLionel Sambuc        __states.back().__node_ = __st;
55964684ddb6SLionel Sambuc        __states.back().__flags_ = __flags;
55974684ddb6SLionel Sambuc        __states.back().__at_first_ = __at_first;
55984684ddb6SLionel Sambuc        bool __matched = false;
55994684ddb6SLionel Sambuc        do
56004684ddb6SLionel Sambuc        {
56014684ddb6SLionel Sambuc            __state& __s = __states.back();
56024684ddb6SLionel Sambuc            if (__s.__node_)
56034684ddb6SLionel Sambuc                __s.__node_->__exec(__s);
56044684ddb6SLionel Sambuc            switch (__s.__do_)
56054684ddb6SLionel Sambuc            {
56064684ddb6SLionel Sambuc            case __state::__end_state:
56074684ddb6SLionel Sambuc                if (!__matched || __highest_j < __s.__current_ - __s.__first_)
56084684ddb6SLionel Sambuc                    __highest_j = __s.__current_ - __s.__first_;
56094684ddb6SLionel Sambuc                __matched = true;
56104684ddb6SLionel Sambuc                if (__highest_j == _Np)
56114684ddb6SLionel Sambuc                    __states.clear();
56124684ddb6SLionel Sambuc                else
56134684ddb6SLionel Sambuc                    __states.pop_back();
56144684ddb6SLionel Sambuc                break;
56154684ddb6SLionel Sambuc            case __state::__consume_input:
56164684ddb6SLionel Sambuc                break;
56174684ddb6SLionel Sambuc            case __state::__accept_and_consume:
56184684ddb6SLionel Sambuc                __states.push_front(_VSTD::move(__s));
56194684ddb6SLionel Sambuc                __states.pop_back();
56204684ddb6SLionel Sambuc                break;
56214684ddb6SLionel Sambuc            case __state::__repeat:
56224684ddb6SLionel Sambuc            case __state::__accept_but_not_consume:
56234684ddb6SLionel Sambuc                break;
56244684ddb6SLionel Sambuc            case __state::__split:
56254684ddb6SLionel Sambuc                {
56264684ddb6SLionel Sambuc                __state __snext = __s;
56274684ddb6SLionel Sambuc                __s.__node_->__exec_split(true, __s);
56284684ddb6SLionel Sambuc                __snext.__node_->__exec_split(false, __snext);
56294684ddb6SLionel Sambuc                __states.push_back(_VSTD::move(__snext));
56304684ddb6SLionel Sambuc                }
56314684ddb6SLionel Sambuc                break;
56324684ddb6SLionel Sambuc            case __state::__reject:
56334684ddb6SLionel Sambuc                __states.pop_back();
56344684ddb6SLionel Sambuc                break;
56354684ddb6SLionel Sambuc            default:
5636*0a6a1f1dSLionel Sambuc                __throw_regex_error<regex_constants::__re_err_unknown>();
56374684ddb6SLionel Sambuc                break;
56384684ddb6SLionel Sambuc            }
56394684ddb6SLionel Sambuc        } while (!__states.empty());
56404684ddb6SLionel Sambuc        if (__matched)
56414684ddb6SLionel Sambuc        {
56424684ddb6SLionel Sambuc            __m.__matches_[0].first = __first;
56434684ddb6SLionel Sambuc            __m.__matches_[0].second = _VSTD::next(__first, __highest_j);
56444684ddb6SLionel Sambuc            __m.__matches_[0].matched = true;
56454684ddb6SLionel Sambuc            return true;
56464684ddb6SLionel Sambuc        }
56474684ddb6SLionel Sambuc    }
56484684ddb6SLionel Sambuc    return false;
56494684ddb6SLionel Sambuc}
56504684ddb6SLionel Sambuc
56514684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
56524684ddb6SLionel Sambuctemplate <class _Allocator>
56534684ddb6SLionel Sambucbool
56544684ddb6SLionel Sambucbasic_regex<_CharT, _Traits>::__match_at_start_posix_subs(
56554684ddb6SLionel Sambuc        const _CharT* __first, const _CharT* __last,
56564684ddb6SLionel Sambuc        match_results<const _CharT*, _Allocator>& __m,
56574684ddb6SLionel Sambuc        regex_constants::match_flag_type __flags, bool __at_first) const
56584684ddb6SLionel Sambuc{
56594684ddb6SLionel Sambuc    vector<__state> __states;
56604684ddb6SLionel Sambuc    __state __best_state;
56614684ddb6SLionel Sambuc    ptrdiff_t __j = 0;
56624684ddb6SLionel Sambuc    ptrdiff_t __highest_j = 0;
56634684ddb6SLionel Sambuc    ptrdiff_t _Np = _VSTD::distance(__first, __last);
56644684ddb6SLionel Sambuc    __node* __st = __start_.get();
56654684ddb6SLionel Sambuc    if (__st)
56664684ddb6SLionel Sambuc    {
5667*0a6a1f1dSLionel Sambuc        sub_match<const _CharT*> __unmatched;
5668*0a6a1f1dSLionel Sambuc        __unmatched.first   = __last;
5669*0a6a1f1dSLionel Sambuc        __unmatched.second  = __last;
5670*0a6a1f1dSLionel Sambuc        __unmatched.matched = false;
5671*0a6a1f1dSLionel Sambuc
56724684ddb6SLionel Sambuc        __states.push_back(__state());
56734684ddb6SLionel Sambuc        __states.back().__do_ = 0;
56744684ddb6SLionel Sambuc        __states.back().__first_ = __first;
56754684ddb6SLionel Sambuc        __states.back().__current_ = __first;
56764684ddb6SLionel Sambuc        __states.back().__last_ = __last;
5677*0a6a1f1dSLionel Sambuc        __states.back().__sub_matches_.resize(mark_count(), __unmatched);
56784684ddb6SLionel Sambuc        __states.back().__loop_data_.resize(__loop_count());
56794684ddb6SLionel Sambuc        __states.back().__node_ = __st;
56804684ddb6SLionel Sambuc        __states.back().__flags_ = __flags;
56814684ddb6SLionel Sambuc        __states.back().__at_first_ = __at_first;
56824684ddb6SLionel Sambuc        const _CharT* __current = __first;
56834684ddb6SLionel Sambuc        bool __matched = false;
56844684ddb6SLionel Sambuc        do
56854684ddb6SLionel Sambuc        {
56864684ddb6SLionel Sambuc            __state& __s = __states.back();
56874684ddb6SLionel Sambuc            if (__s.__node_)
56884684ddb6SLionel Sambuc                __s.__node_->__exec(__s);
56894684ddb6SLionel Sambuc            switch (__s.__do_)
56904684ddb6SLionel Sambuc            {
56914684ddb6SLionel Sambuc            case __state::__end_state:
56924684ddb6SLionel Sambuc                if (!__matched || __highest_j < __s.__current_ - __s.__first_)
56934684ddb6SLionel Sambuc                {
56944684ddb6SLionel Sambuc                    __highest_j = __s.__current_ - __s.__first_;
56954684ddb6SLionel Sambuc                    __best_state = __s;
56964684ddb6SLionel Sambuc                }
56974684ddb6SLionel Sambuc                __matched = true;
56984684ddb6SLionel Sambuc                if (__highest_j == _Np)
56994684ddb6SLionel Sambuc                    __states.clear();
57004684ddb6SLionel Sambuc                else
57014684ddb6SLionel Sambuc                    __states.pop_back();
57024684ddb6SLionel Sambuc                break;
57034684ddb6SLionel Sambuc            case __state::__accept_and_consume:
57044684ddb6SLionel Sambuc                __j += __s.__current_ - __current;
57054684ddb6SLionel Sambuc                __current = __s.__current_;
57064684ddb6SLionel Sambuc                break;
57074684ddb6SLionel Sambuc            case __state::__repeat:
57084684ddb6SLionel Sambuc            case __state::__accept_but_not_consume:
57094684ddb6SLionel Sambuc                break;
57104684ddb6SLionel Sambuc            case __state::__split:
57114684ddb6SLionel Sambuc                {
57124684ddb6SLionel Sambuc                __state __snext = __s;
57134684ddb6SLionel Sambuc                __s.__node_->__exec_split(true, __s);
57144684ddb6SLionel Sambuc                __snext.__node_->__exec_split(false, __snext);
57154684ddb6SLionel Sambuc                __states.push_back(_VSTD::move(__snext));
57164684ddb6SLionel Sambuc                }
57174684ddb6SLionel Sambuc                break;
57184684ddb6SLionel Sambuc            case __state::__reject:
57194684ddb6SLionel Sambuc                __states.pop_back();
57204684ddb6SLionel Sambuc                break;
57214684ddb6SLionel Sambuc            default:
5722*0a6a1f1dSLionel Sambuc                __throw_regex_error<regex_constants::__re_err_unknown>();
57234684ddb6SLionel Sambuc                break;
57244684ddb6SLionel Sambuc            }
57254684ddb6SLionel Sambuc        } while (!__states.empty());
57264684ddb6SLionel Sambuc        if (__matched)
57274684ddb6SLionel Sambuc        {
57284684ddb6SLionel Sambuc            __m.__matches_[0].first = __first;
57294684ddb6SLionel Sambuc            __m.__matches_[0].second = _VSTD::next(__first, __highest_j);
57304684ddb6SLionel Sambuc            __m.__matches_[0].matched = true;
57314684ddb6SLionel Sambuc            for (unsigned __i = 0; __i < __best_state.__sub_matches_.size(); ++__i)
57324684ddb6SLionel Sambuc                __m.__matches_[__i+1] = __best_state.__sub_matches_[__i];
57334684ddb6SLionel Sambuc            return true;
57344684ddb6SLionel Sambuc        }
57354684ddb6SLionel Sambuc    }
57364684ddb6SLionel Sambuc    return false;
57374684ddb6SLionel Sambuc}
57384684ddb6SLionel Sambuc
57394684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
57404684ddb6SLionel Sambuctemplate <class _Allocator>
57414684ddb6SLionel Sambucbool
57424684ddb6SLionel Sambucbasic_regex<_CharT, _Traits>::__match_at_start(
57434684ddb6SLionel Sambuc        const _CharT* __first, const _CharT* __last,
57444684ddb6SLionel Sambuc        match_results<const _CharT*, _Allocator>& __m,
57454684ddb6SLionel Sambuc        regex_constants::match_flag_type __flags, bool __at_first) const
57464684ddb6SLionel Sambuc{
57474684ddb6SLionel Sambuc    if ((__flags_ & 0x1F0) == ECMAScript)
57484684ddb6SLionel Sambuc        return __match_at_start_ecma(__first, __last, __m, __flags, __at_first);
57494684ddb6SLionel Sambuc    if (mark_count() == 0)
57504684ddb6SLionel Sambuc        return __match_at_start_posix_nosubs(__first, __last, __m, __flags, __at_first);
57514684ddb6SLionel Sambuc    return __match_at_start_posix_subs(__first, __last, __m, __flags, __at_first);
57524684ddb6SLionel Sambuc}
57534684ddb6SLionel Sambuc
57544684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
57554684ddb6SLionel Sambuctemplate <class _Allocator>
57564684ddb6SLionel Sambucbool
57574684ddb6SLionel Sambucbasic_regex<_CharT, _Traits>::__search(
57584684ddb6SLionel Sambuc        const _CharT* __first, const _CharT* __last,
57594684ddb6SLionel Sambuc        match_results<const _CharT*, _Allocator>& __m,
57604684ddb6SLionel Sambuc        regex_constants::match_flag_type __flags) const
57614684ddb6SLionel Sambuc{
57624684ddb6SLionel Sambuc    __m.__init(1 + mark_count(), __first, __last,
57634684ddb6SLionel Sambuc                                    __flags & regex_constants::__no_update_pos);
57644684ddb6SLionel Sambuc    if (__match_at_start(__first, __last, __m, __flags,
57654684ddb6SLionel Sambuc                                    !(__flags & regex_constants::__no_update_pos)))
57664684ddb6SLionel Sambuc    {
57674684ddb6SLionel Sambuc        __m.__prefix_.second = __m[0].first;
57684684ddb6SLionel Sambuc        __m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second;
57694684ddb6SLionel Sambuc        __m.__suffix_.first = __m[0].second;
57704684ddb6SLionel Sambuc        __m.__suffix_.matched = __m.__suffix_.first != __m.__suffix_.second;
57714684ddb6SLionel Sambuc        return true;
57724684ddb6SLionel Sambuc    }
57734684ddb6SLionel Sambuc    if (__first != __last && !(__flags & regex_constants::match_continuous))
57744684ddb6SLionel Sambuc    {
57754684ddb6SLionel Sambuc        __flags |= regex_constants::match_prev_avail;
57764684ddb6SLionel Sambuc        for (++__first; __first != __last; ++__first)
57774684ddb6SLionel Sambuc        {
57784684ddb6SLionel Sambuc            __m.__matches_.assign(__m.size(), __m.__unmatched_);
57794684ddb6SLionel Sambuc            if (__match_at_start(__first, __last, __m, __flags, false))
57804684ddb6SLionel Sambuc            {
57814684ddb6SLionel Sambuc                __m.__prefix_.second = __m[0].first;
57824684ddb6SLionel Sambuc                __m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second;
57834684ddb6SLionel Sambuc                __m.__suffix_.first = __m[0].second;
57844684ddb6SLionel Sambuc                __m.__suffix_.matched = __m.__suffix_.first != __m.__suffix_.second;
57854684ddb6SLionel Sambuc                return true;
57864684ddb6SLionel Sambuc            }
57874684ddb6SLionel Sambuc            __m.__matches_.assign(__m.size(), __m.__unmatched_);
57884684ddb6SLionel Sambuc        }
57894684ddb6SLionel Sambuc    }
57904684ddb6SLionel Sambuc    __m.__matches_.clear();
57914684ddb6SLionel Sambuc    return false;
57924684ddb6SLionel Sambuc}
57934684ddb6SLionel Sambuc
57944684ddb6SLionel Sambuctemplate <class _BidirectionalIterator, class _Allocator, class _CharT, class _Traits>
57954684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
57964684ddb6SLionel Sambucbool
57974684ddb6SLionel Sambucregex_search(_BidirectionalIterator __first, _BidirectionalIterator __last,
57984684ddb6SLionel Sambuc             match_results<_BidirectionalIterator, _Allocator>& __m,
57994684ddb6SLionel Sambuc             const basic_regex<_CharT, _Traits>& __e,
58004684ddb6SLionel Sambuc             regex_constants::match_flag_type __flags = regex_constants::match_default)
58014684ddb6SLionel Sambuc{
58024684ddb6SLionel Sambuc    int __offset = (__flags & regex_constants::match_prev_avail) ? 1 : 0;
58034684ddb6SLionel Sambuc    basic_string<_CharT> __s(_VSTD::prev(__first, __offset), __last);
58044684ddb6SLionel Sambuc    match_results<const _CharT*> __mc;
58054684ddb6SLionel Sambuc    bool __r = __e.__search(__s.data() + __offset, __s.data() + __s.size(), __mc, __flags);
58064684ddb6SLionel Sambuc    __m.__assign(__first, __last, __mc, __flags & regex_constants::__no_update_pos);
58074684ddb6SLionel Sambuc    return __r;
58084684ddb6SLionel Sambuc}
58094684ddb6SLionel Sambuc
58104684ddb6SLionel Sambuctemplate <class _Iter, class _Allocator, class _CharT, class _Traits>
58114684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
58124684ddb6SLionel Sambucbool
58134684ddb6SLionel Sambucregex_search(__wrap_iter<_Iter> __first,
58144684ddb6SLionel Sambuc             __wrap_iter<_Iter> __last,
58154684ddb6SLionel Sambuc             match_results<__wrap_iter<_Iter>, _Allocator>& __m,
58164684ddb6SLionel Sambuc             const basic_regex<_CharT, _Traits>& __e,
58174684ddb6SLionel Sambuc             regex_constants::match_flag_type __flags = regex_constants::match_default)
58184684ddb6SLionel Sambuc{
58194684ddb6SLionel Sambuc    match_results<const _CharT*> __mc;
58204684ddb6SLionel Sambuc    bool __r = __e.__search(__first.base(), __last.base(), __mc, __flags);
58214684ddb6SLionel Sambuc    __m.__assign(__first, __last, __mc, __flags & regex_constants::__no_update_pos);
58224684ddb6SLionel Sambuc    return __r;
58234684ddb6SLionel Sambuc}
58244684ddb6SLionel Sambuc
58254684ddb6SLionel Sambuctemplate <class _Allocator, class _CharT, class _Traits>
58264684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
58274684ddb6SLionel Sambucbool
58284684ddb6SLionel Sambucregex_search(const _CharT* __first, const _CharT* __last,
58294684ddb6SLionel Sambuc             match_results<const _CharT*, _Allocator>& __m,
58304684ddb6SLionel Sambuc             const basic_regex<_CharT, _Traits>& __e,
58314684ddb6SLionel Sambuc             regex_constants::match_flag_type __flags = regex_constants::match_default)
58324684ddb6SLionel Sambuc{
58334684ddb6SLionel Sambuc    return __e.__search(__first, __last, __m, __flags);
58344684ddb6SLionel Sambuc}
58354684ddb6SLionel Sambuc
58364684ddb6SLionel Sambuctemplate <class _BidirectionalIterator, class _CharT, class _Traits>
58374684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
58384684ddb6SLionel Sambucbool
58394684ddb6SLionel Sambucregex_search(_BidirectionalIterator __first, _BidirectionalIterator __last,
58404684ddb6SLionel Sambuc             const basic_regex<_CharT, _Traits>& __e,
58414684ddb6SLionel Sambuc             regex_constants::match_flag_type __flags = regex_constants::match_default)
58424684ddb6SLionel Sambuc{
58434684ddb6SLionel Sambuc    basic_string<_CharT> __s(__first, __last);
58444684ddb6SLionel Sambuc    match_results<const _CharT*> __mc;
58454684ddb6SLionel Sambuc    return __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags);
58464684ddb6SLionel Sambuc}
58474684ddb6SLionel Sambuc
58484684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
58494684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
58504684ddb6SLionel Sambucbool
58514684ddb6SLionel Sambucregex_search(const _CharT* __first, const _CharT* __last,
58524684ddb6SLionel Sambuc             const basic_regex<_CharT, _Traits>& __e,
58534684ddb6SLionel Sambuc             regex_constants::match_flag_type __flags = regex_constants::match_default)
58544684ddb6SLionel Sambuc{
58554684ddb6SLionel Sambuc    match_results<const _CharT*> __mc;
58564684ddb6SLionel Sambuc    return __e.__search(__first, __last, __mc, __flags);
58574684ddb6SLionel Sambuc}
58584684ddb6SLionel Sambuc
58594684ddb6SLionel Sambuctemplate <class _CharT, class _Allocator, class _Traits>
58604684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
58614684ddb6SLionel Sambucbool
58624684ddb6SLionel Sambucregex_search(const _CharT* __str, match_results<const _CharT*, _Allocator>& __m,
58634684ddb6SLionel Sambuc             const basic_regex<_CharT, _Traits>& __e,
58644684ddb6SLionel Sambuc             regex_constants::match_flag_type __flags = regex_constants::match_default)
58654684ddb6SLionel Sambuc{
58664684ddb6SLionel Sambuc    return __e.__search(__str, __str + _Traits::length(__str), __m, __flags);
58674684ddb6SLionel Sambuc}
58684684ddb6SLionel Sambuc
58694684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
58704684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
58714684ddb6SLionel Sambucbool
58724684ddb6SLionel Sambucregex_search(const _CharT* __str, const basic_regex<_CharT, _Traits>& __e,
58734684ddb6SLionel Sambuc             regex_constants::match_flag_type __flags = regex_constants::match_default)
58744684ddb6SLionel Sambuc{
58754684ddb6SLionel Sambuc    match_results<const _CharT*> __m;
58764684ddb6SLionel Sambuc    return _VSTD::regex_search(__str, __m, __e, __flags);
58774684ddb6SLionel Sambuc}
58784684ddb6SLionel Sambuc
58794684ddb6SLionel Sambuctemplate <class _ST, class _SA, class _CharT, class _Traits>
58804684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
58814684ddb6SLionel Sambucbool
58824684ddb6SLionel Sambucregex_search(const basic_string<_CharT, _ST, _SA>& __s,
58834684ddb6SLionel Sambuc             const basic_regex<_CharT, _Traits>& __e,
58844684ddb6SLionel Sambuc             regex_constants::match_flag_type __flags = regex_constants::match_default)
58854684ddb6SLionel Sambuc{
58864684ddb6SLionel Sambuc    match_results<const _CharT*> __mc;
58874684ddb6SLionel Sambuc    return __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags);
58884684ddb6SLionel Sambuc}
58894684ddb6SLionel Sambuc
58904684ddb6SLionel Sambuctemplate <class _ST, class _SA, class _Allocator, class _CharT, class _Traits>
58914684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
58924684ddb6SLionel Sambucbool
58934684ddb6SLionel Sambucregex_search(const basic_string<_CharT, _ST, _SA>& __s,
58944684ddb6SLionel Sambuc             match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m,
58954684ddb6SLionel Sambuc             const basic_regex<_CharT, _Traits>& __e,
58964684ddb6SLionel Sambuc             regex_constants::match_flag_type __flags = regex_constants::match_default)
58974684ddb6SLionel Sambuc{
58984684ddb6SLionel Sambuc    match_results<const _CharT*> __mc;
58994684ddb6SLionel Sambuc    bool __r = __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags);
59004684ddb6SLionel Sambuc    __m.__assign(__s.begin(), __s.end(), __mc, __flags & regex_constants::__no_update_pos);
59014684ddb6SLionel Sambuc    return __r;
59024684ddb6SLionel Sambuc}
59034684ddb6SLionel Sambuc
5904*0a6a1f1dSLionel Sambuc#if _LIBCPP_STD_VER > 11
5905*0a6a1f1dSLionel Sambuctemplate <class _ST, class _SA, class _Ap, class _Cp, class _Tp>
5906*0a6a1f1dSLionel Sambucbool
5907*0a6a1f1dSLionel Sambucregex_search(const basic_string<_Cp, _ST, _SA>&& __s,
5908*0a6a1f1dSLionel Sambuc             match_results<typename basic_string<_Cp, _ST, _SA>::const_iterator, _Ap>&,
5909*0a6a1f1dSLionel Sambuc             const basic_regex<_Cp, _Tp>& __e,
5910*0a6a1f1dSLionel Sambuc             regex_constants::match_flag_type __flags = regex_constants::match_default) = delete;
5911*0a6a1f1dSLionel Sambuc#endif
5912*0a6a1f1dSLionel Sambuc
59134684ddb6SLionel Sambuc// regex_match
59144684ddb6SLionel Sambuc
59154684ddb6SLionel Sambuctemplate <class _BidirectionalIterator, class _Allocator, class _CharT, class _Traits>
59164684ddb6SLionel Sambucbool
59174684ddb6SLionel Sambucregex_match(_BidirectionalIterator __first, _BidirectionalIterator __last,
59184684ddb6SLionel Sambuc            match_results<_BidirectionalIterator, _Allocator>& __m,
59194684ddb6SLionel Sambuc            const basic_regex<_CharT, _Traits>& __e,
59204684ddb6SLionel Sambuc            regex_constants::match_flag_type __flags = regex_constants::match_default)
59214684ddb6SLionel Sambuc{
59224684ddb6SLionel Sambuc    bool __r = _VSTD::regex_search(__first, __last, __m, __e,
59234684ddb6SLionel Sambuc                            __flags | regex_constants::match_continuous);
59244684ddb6SLionel Sambuc    if (__r)
59254684ddb6SLionel Sambuc    {
59264684ddb6SLionel Sambuc        __r = !__m.suffix().matched;
59274684ddb6SLionel Sambuc        if (!__r)
59284684ddb6SLionel Sambuc            __m.__matches_.clear();
59294684ddb6SLionel Sambuc    }
59304684ddb6SLionel Sambuc    return __r;
59314684ddb6SLionel Sambuc}
59324684ddb6SLionel Sambuc
59334684ddb6SLionel Sambuctemplate <class _BidirectionalIterator, class _CharT, class _Traits>
59344684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
59354684ddb6SLionel Sambucbool
59364684ddb6SLionel Sambucregex_match(_BidirectionalIterator __first, _BidirectionalIterator __last,
59374684ddb6SLionel Sambuc            const basic_regex<_CharT, _Traits>& __e,
59384684ddb6SLionel Sambuc            regex_constants::match_flag_type __flags = regex_constants::match_default)
59394684ddb6SLionel Sambuc{
59404684ddb6SLionel Sambuc    match_results<_BidirectionalIterator> __m;
59414684ddb6SLionel Sambuc    return _VSTD::regex_match(__first, __last, __m, __e, __flags);
59424684ddb6SLionel Sambuc}
59434684ddb6SLionel Sambuc
59444684ddb6SLionel Sambuctemplate <class _CharT, class _Allocator, class _Traits>
59454684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
59464684ddb6SLionel Sambucbool
59474684ddb6SLionel Sambucregex_match(const _CharT* __str, match_results<const _CharT*, _Allocator>& __m,
59484684ddb6SLionel Sambuc            const basic_regex<_CharT, _Traits>& __e,
59494684ddb6SLionel Sambuc            regex_constants::match_flag_type __flags = regex_constants::match_default)
59504684ddb6SLionel Sambuc{
59514684ddb6SLionel Sambuc    return _VSTD::regex_match(__str, __str + _Traits::length(__str), __m, __e, __flags);
59524684ddb6SLionel Sambuc}
59534684ddb6SLionel Sambuc
59544684ddb6SLionel Sambuctemplate <class _ST, class _SA, class _Allocator, class _CharT, class _Traits>
59554684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
59564684ddb6SLionel Sambucbool
59574684ddb6SLionel Sambucregex_match(const basic_string<_CharT, _ST, _SA>& __s,
59584684ddb6SLionel Sambuc            match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m,
59594684ddb6SLionel Sambuc            const basic_regex<_CharT, _Traits>& __e,
59604684ddb6SLionel Sambuc            regex_constants::match_flag_type __flags = regex_constants::match_default)
59614684ddb6SLionel Sambuc{
59624684ddb6SLionel Sambuc    return _VSTD::regex_match(__s.begin(), __s.end(), __m, __e, __flags);
59634684ddb6SLionel Sambuc}
59644684ddb6SLionel Sambuc
5965*0a6a1f1dSLionel Sambuc#if _LIBCPP_STD_VER > 11
5966*0a6a1f1dSLionel Sambuctemplate <class _ST, class _SA, class _Allocator, class _CharT, class _Traits>
5967*0a6a1f1dSLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
5968*0a6a1f1dSLionel Sambucbool
5969*0a6a1f1dSLionel Sambucregex_match(const basic_string<_CharT, _ST, _SA>&& __s,
5970*0a6a1f1dSLionel Sambuc            match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m,
5971*0a6a1f1dSLionel Sambuc            const basic_regex<_CharT, _Traits>& __e,
5972*0a6a1f1dSLionel Sambuc            regex_constants::match_flag_type __flags = regex_constants::match_default) = delete;
5973*0a6a1f1dSLionel Sambuc#endif
5974*0a6a1f1dSLionel Sambuc
59754684ddb6SLionel Sambuctemplate <class _CharT, class _Traits>
59764684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
59774684ddb6SLionel Sambucbool
59784684ddb6SLionel Sambucregex_match(const _CharT* __str, const basic_regex<_CharT, _Traits>& __e,
59794684ddb6SLionel Sambuc            regex_constants::match_flag_type __flags = regex_constants::match_default)
59804684ddb6SLionel Sambuc{
59814684ddb6SLionel Sambuc    return _VSTD::regex_match(__str, __str + _Traits::length(__str), __e, __flags);
59824684ddb6SLionel Sambuc}
59834684ddb6SLionel Sambuc
59844684ddb6SLionel Sambuctemplate <class _ST, class _SA, class _CharT, class _Traits>
59854684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
59864684ddb6SLionel Sambucbool
59874684ddb6SLionel Sambucregex_match(const basic_string<_CharT, _ST, _SA>& __s,
59884684ddb6SLionel Sambuc            const basic_regex<_CharT, _Traits>& __e,
59894684ddb6SLionel Sambuc            regex_constants::match_flag_type __flags = regex_constants::match_default)
59904684ddb6SLionel Sambuc{
59914684ddb6SLionel Sambuc    return _VSTD::regex_match(__s.begin(), __s.end(), __e, __flags);
59924684ddb6SLionel Sambuc}
59934684ddb6SLionel Sambuc
59944684ddb6SLionel Sambuc// regex_iterator
59954684ddb6SLionel Sambuc
59964684ddb6SLionel Sambuctemplate <class _BidirectionalIterator,
59974684ddb6SLionel Sambuc          class _CharT = typename iterator_traits<_BidirectionalIterator>::value_type,
59984684ddb6SLionel Sambuc          class _Traits = regex_traits<_CharT> >
59994684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS_ONLY regex_iterator
60004684ddb6SLionel Sambuc{
60014684ddb6SLionel Sambucpublic:
60024684ddb6SLionel Sambuc    typedef basic_regex<_CharT, _Traits>          regex_type;
60034684ddb6SLionel Sambuc    typedef match_results<_BidirectionalIterator> value_type;
60044684ddb6SLionel Sambuc    typedef ptrdiff_t                             difference_type;
60054684ddb6SLionel Sambuc    typedef const value_type*                     pointer;
60064684ddb6SLionel Sambuc    typedef const value_type&                     reference;
60074684ddb6SLionel Sambuc    typedef forward_iterator_tag                  iterator_category;
60084684ddb6SLionel Sambuc
60094684ddb6SLionel Sambucprivate:
60104684ddb6SLionel Sambuc    _BidirectionalIterator           __begin_;
60114684ddb6SLionel Sambuc    _BidirectionalIterator           __end_;
60124684ddb6SLionel Sambuc    const regex_type*                __pregex_;
60134684ddb6SLionel Sambuc    regex_constants::match_flag_type __flags_;
60144684ddb6SLionel Sambuc    value_type                       __match_;
60154684ddb6SLionel Sambuc
60164684ddb6SLionel Sambucpublic:
60174684ddb6SLionel Sambuc    regex_iterator();
60184684ddb6SLionel Sambuc    regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
60194684ddb6SLionel Sambuc                   const regex_type& __re,
6020*0a6a1f1dSLionel Sambuc                   regex_constants::match_flag_type __m
6021*0a6a1f1dSLionel Sambuc                                              = regex_constants::match_default);
6022*0a6a1f1dSLionel Sambuc#if _LIBCPP_STD_VER > 11
6023*0a6a1f1dSLionel Sambuc    regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6024*0a6a1f1dSLionel Sambuc                   const regex_type&& __re,
6025*0a6a1f1dSLionel Sambuc                   regex_constants::match_flag_type __m
6026*0a6a1f1dSLionel Sambuc                                     = regex_constants::match_default) = delete;
6027*0a6a1f1dSLionel Sambuc#endif
60284684ddb6SLionel Sambuc
60294684ddb6SLionel Sambuc    bool operator==(const regex_iterator& __x) const;
60304684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
60314684ddb6SLionel Sambuc    bool operator!=(const regex_iterator& __x) const {return !(*this == __x);}
60324684ddb6SLionel Sambuc
60334684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
60344684ddb6SLionel Sambuc    reference operator*() const {return  __match_;}
60354684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
60364684ddb6SLionel Sambuc    pointer operator->() const  {return &__match_;}
60374684ddb6SLionel Sambuc
60384684ddb6SLionel Sambuc    regex_iterator& operator++();
60394684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
60404684ddb6SLionel Sambuc    regex_iterator operator++(int)
60414684ddb6SLionel Sambuc    {
60424684ddb6SLionel Sambuc        regex_iterator __t(*this);
60434684ddb6SLionel Sambuc        ++(*this);
60444684ddb6SLionel Sambuc        return __t;
60454684ddb6SLionel Sambuc    }
60464684ddb6SLionel Sambuc};
60474684ddb6SLionel Sambuc
60484684ddb6SLionel Sambuctemplate <class _BidirectionalIterator, class _CharT, class _Traits>
60494684ddb6SLionel Sambucregex_iterator<_BidirectionalIterator, _CharT, _Traits>::regex_iterator()
60504684ddb6SLionel Sambuc    : __begin_(), __end_(), __pregex_(nullptr), __flags_(), __match_()
60514684ddb6SLionel Sambuc{
60524684ddb6SLionel Sambuc}
60534684ddb6SLionel Sambuc
60544684ddb6SLionel Sambuctemplate <class _BidirectionalIterator, class _CharT, class _Traits>
60554684ddb6SLionel Sambucregex_iterator<_BidirectionalIterator, _CharT, _Traits>::
60564684ddb6SLionel Sambuc    regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
60574684ddb6SLionel Sambuc                   const regex_type& __re, regex_constants::match_flag_type __m)
60584684ddb6SLionel Sambuc    : __begin_(__a),
60594684ddb6SLionel Sambuc      __end_(__b),
60604684ddb6SLionel Sambuc      __pregex_(&__re),
60614684ddb6SLionel Sambuc      __flags_(__m)
60624684ddb6SLionel Sambuc{
60634684ddb6SLionel Sambuc    _VSTD::regex_search(__begin_, __end_, __match_, *__pregex_, __flags_);
60644684ddb6SLionel Sambuc}
60654684ddb6SLionel Sambuc
60664684ddb6SLionel Sambuctemplate <class _BidirectionalIterator, class _CharT, class _Traits>
60674684ddb6SLionel Sambucbool
60684684ddb6SLionel Sambucregex_iterator<_BidirectionalIterator, _CharT, _Traits>::
60694684ddb6SLionel Sambuc    operator==(const regex_iterator& __x) const
60704684ddb6SLionel Sambuc{
60714684ddb6SLionel Sambuc    if (__match_.empty() && __x.__match_.empty())
60724684ddb6SLionel Sambuc        return true;
60734684ddb6SLionel Sambuc    if (__match_.empty() || __x.__match_.empty())
60744684ddb6SLionel Sambuc        return false;
60754684ddb6SLionel Sambuc    return __begin_ == __x.__begin_       &&
60764684ddb6SLionel Sambuc           __end_ == __x.__end_           &&
60774684ddb6SLionel Sambuc           __pregex_ == __x.__pregex_     &&
60784684ddb6SLionel Sambuc           __flags_ == __x.__flags_       &&
60794684ddb6SLionel Sambuc           __match_[0] == __x.__match_[0];
60804684ddb6SLionel Sambuc}
60814684ddb6SLionel Sambuc
60824684ddb6SLionel Sambuctemplate <class _BidirectionalIterator, class _CharT, class _Traits>
60834684ddb6SLionel Sambucregex_iterator<_BidirectionalIterator, _CharT, _Traits>&
60844684ddb6SLionel Sambucregex_iterator<_BidirectionalIterator, _CharT, _Traits>::operator++()
60854684ddb6SLionel Sambuc{
60864684ddb6SLionel Sambuc    __flags_ |= regex_constants::__no_update_pos;
60874684ddb6SLionel Sambuc    _BidirectionalIterator __start = __match_[0].second;
60884684ddb6SLionel Sambuc    if (__match_.empty())
60894684ddb6SLionel Sambuc    {
60904684ddb6SLionel Sambuc        if (__start == __end_)
60914684ddb6SLionel Sambuc        {
60924684ddb6SLionel Sambuc            __match_ = value_type();
60934684ddb6SLionel Sambuc            return *this;
60944684ddb6SLionel Sambuc        }
60954684ddb6SLionel Sambuc        else if (_VSTD::regex_search(__start, __end_, __match_, *__pregex_,
60964684ddb6SLionel Sambuc                                    __flags_ | regex_constants::match_not_null |
60974684ddb6SLionel Sambuc                                    regex_constants::match_continuous))
60984684ddb6SLionel Sambuc            return *this;
60994684ddb6SLionel Sambuc        else
61004684ddb6SLionel Sambuc            ++__start;
61014684ddb6SLionel Sambuc    }
61024684ddb6SLionel Sambuc    __flags_ |= regex_constants::match_prev_avail;
61034684ddb6SLionel Sambuc    if (!_VSTD::regex_search(__start, __end_, __match_, *__pregex_, __flags_))
61044684ddb6SLionel Sambuc        __match_ = value_type();
61054684ddb6SLionel Sambuc    return *this;
61064684ddb6SLionel Sambuc}
61074684ddb6SLionel Sambuc
61084684ddb6SLionel Sambuctypedef regex_iterator<const char*>             cregex_iterator;
61094684ddb6SLionel Sambuctypedef regex_iterator<const wchar_t*>          wcregex_iterator;
61104684ddb6SLionel Sambuctypedef regex_iterator<string::const_iterator>  sregex_iterator;
61114684ddb6SLionel Sambuctypedef regex_iterator<wstring::const_iterator> wsregex_iterator;
61124684ddb6SLionel Sambuc
61134684ddb6SLionel Sambuc// regex_token_iterator
61144684ddb6SLionel Sambuc
61154684ddb6SLionel Sambuctemplate <class _BidirectionalIterator,
61164684ddb6SLionel Sambuc          class _CharT = typename iterator_traits<_BidirectionalIterator>::value_type,
61174684ddb6SLionel Sambuc          class _Traits = regex_traits<_CharT> >
61184684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS_ONLY regex_token_iterator
61194684ddb6SLionel Sambuc{
61204684ddb6SLionel Sambucpublic:
61214684ddb6SLionel Sambuc    typedef basic_regex<_CharT, _Traits>      regex_type;
61224684ddb6SLionel Sambuc    typedef sub_match<_BidirectionalIterator> value_type;
61234684ddb6SLionel Sambuc    typedef ptrdiff_t                         difference_type;
61244684ddb6SLionel Sambuc    typedef const value_type*                 pointer;
61254684ddb6SLionel Sambuc    typedef const value_type&                 reference;
61264684ddb6SLionel Sambuc    typedef forward_iterator_tag              iterator_category;
61274684ddb6SLionel Sambuc
61284684ddb6SLionel Sambucprivate:
61294684ddb6SLionel Sambuc    typedef regex_iterator<_BidirectionalIterator, _CharT, _Traits> _Position;
61304684ddb6SLionel Sambuc
61314684ddb6SLionel Sambuc    _Position         __position_;
61324684ddb6SLionel Sambuc    const value_type* __result_;
61334684ddb6SLionel Sambuc    value_type        __suffix_;
61344684ddb6SLionel Sambuc    ptrdiff_t         _N_;
61354684ddb6SLionel Sambuc    vector<int>       __subs_;
61364684ddb6SLionel Sambuc
61374684ddb6SLionel Sambucpublic:
61384684ddb6SLionel Sambuc    regex_token_iterator();
61394684ddb6SLionel Sambuc    regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
61404684ddb6SLionel Sambuc                         const regex_type& __re, int __submatch = 0,
61414684ddb6SLionel Sambuc                         regex_constants::match_flag_type __m =
61424684ddb6SLionel Sambuc                                                regex_constants::match_default);
6143*0a6a1f1dSLionel Sambuc#if _LIBCPP_STD_VER > 11
6144*0a6a1f1dSLionel Sambuc    regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6145*0a6a1f1dSLionel Sambuc                         const regex_type&& __re, int __submatch = 0,
6146*0a6a1f1dSLionel Sambuc                         regex_constants::match_flag_type __m =
6147*0a6a1f1dSLionel Sambuc                                       regex_constants::match_default) = delete;
6148*0a6a1f1dSLionel Sambuc#endif
6149*0a6a1f1dSLionel Sambuc
61504684ddb6SLionel Sambuc    regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
61514684ddb6SLionel Sambuc                         const regex_type& __re, const vector<int>& __submatches,
61524684ddb6SLionel Sambuc                         regex_constants::match_flag_type __m =
61534684ddb6SLionel Sambuc                                                regex_constants::match_default);
6154*0a6a1f1dSLionel Sambuc#if _LIBCPP_STD_VER > 11
6155*0a6a1f1dSLionel Sambuc    regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6156*0a6a1f1dSLionel Sambuc                         const regex_type&& __re, const vector<int>& __submatches,
6157*0a6a1f1dSLionel Sambuc                         regex_constants::match_flag_type __m =
6158*0a6a1f1dSLionel Sambuc                                     regex_constants::match_default) = delete;
6159*0a6a1f1dSLionel Sambuc#endif
6160*0a6a1f1dSLionel Sambuc
61614684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
61624684ddb6SLionel Sambuc    regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
61634684ddb6SLionel Sambuc                         const regex_type& __re,
61644684ddb6SLionel Sambuc                         initializer_list<int> __submatches,
61654684ddb6SLionel Sambuc                         regex_constants::match_flag_type __m =
61664684ddb6SLionel Sambuc                                                regex_constants::match_default);
6167*0a6a1f1dSLionel Sambuc
6168*0a6a1f1dSLionel Sambuc#if _LIBCPP_STD_VER > 11
6169*0a6a1f1dSLionel Sambuc    regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6170*0a6a1f1dSLionel Sambuc                         const regex_type&& __re,
6171*0a6a1f1dSLionel Sambuc                         initializer_list<int> __submatches,
6172*0a6a1f1dSLionel Sambuc                         regex_constants::match_flag_type __m =
6173*0a6a1f1dSLionel Sambuc                                       regex_constants::match_default) = delete;
6174*0a6a1f1dSLionel Sambuc#endif
61754684ddb6SLionel Sambuc#endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
61764684ddb6SLionel Sambuc    template <size_t _Np>
61774684ddb6SLionel Sambuc        regex_token_iterator(_BidirectionalIterator __a,
61784684ddb6SLionel Sambuc                             _BidirectionalIterator __b,
61794684ddb6SLionel Sambuc                             const regex_type& __re,
61804684ddb6SLionel Sambuc                             const int (&__submatches)[_Np],
61814684ddb6SLionel Sambuc                             regex_constants::match_flag_type __m =
61824684ddb6SLionel Sambuc                                                regex_constants::match_default);
6183*0a6a1f1dSLionel Sambuc#if _LIBCPP_STD_VER > 11
6184*0a6a1f1dSLionel Sambuc    template <std::size_t _Np>
6185*0a6a1f1dSLionel Sambuc        regex_token_iterator(_BidirectionalIterator __a,
6186*0a6a1f1dSLionel Sambuc                             _BidirectionalIterator __b,
6187*0a6a1f1dSLionel Sambuc                             const regex_type&& __re,
6188*0a6a1f1dSLionel Sambuc                             const int (&__submatches)[_Np],
6189*0a6a1f1dSLionel Sambuc                             regex_constants::match_flag_type __m =
6190*0a6a1f1dSLionel Sambuc                                      regex_constants::match_default) = delete;
6191*0a6a1f1dSLionel Sambuc#endif
6192*0a6a1f1dSLionel Sambuc
61934684ddb6SLionel Sambuc    regex_token_iterator(const regex_token_iterator&);
61944684ddb6SLionel Sambuc    regex_token_iterator& operator=(const regex_token_iterator&);
61954684ddb6SLionel Sambuc
61964684ddb6SLionel Sambuc    bool operator==(const regex_token_iterator& __x) const;
61974684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
61984684ddb6SLionel Sambuc    bool operator!=(const regex_token_iterator& __x) const {return !(*this == __x);}
61994684ddb6SLionel Sambuc
62004684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
62014684ddb6SLionel Sambuc    const value_type& operator*() const {return *__result_;}
62024684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
62034684ddb6SLionel Sambuc    const value_type* operator->() const {return __result_;}
62044684ddb6SLionel Sambuc
62054684ddb6SLionel Sambuc    regex_token_iterator& operator++();
62064684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
62074684ddb6SLionel Sambuc    regex_token_iterator operator++(int)
62084684ddb6SLionel Sambuc    {
62094684ddb6SLionel Sambuc        regex_token_iterator __t(*this);
62104684ddb6SLionel Sambuc        ++(*this);
62114684ddb6SLionel Sambuc        return __t;
62124684ddb6SLionel Sambuc    }
62134684ddb6SLionel Sambuc
62144684ddb6SLionel Sambucprivate:
62154684ddb6SLionel Sambuc    void __init(_BidirectionalIterator __a, _BidirectionalIterator __b);
6216*0a6a1f1dSLionel Sambuc    void __establish_result () {
6217*0a6a1f1dSLionel Sambuc        if (__subs_[_N_] == -1)
6218*0a6a1f1dSLionel Sambuc            __result_ = &__position_->prefix();
6219*0a6a1f1dSLionel Sambuc        else
6220*0a6a1f1dSLionel Sambuc            __result_ = &(*__position_)[__subs_[_N_]];
6221*0a6a1f1dSLionel Sambuc        }
62224684ddb6SLionel Sambuc};
62234684ddb6SLionel Sambuc
62244684ddb6SLionel Sambuctemplate <class _BidirectionalIterator, class _CharT, class _Traits>
62254684ddb6SLionel Sambucregex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
62264684ddb6SLionel Sambuc    regex_token_iterator()
62274684ddb6SLionel Sambuc    : __result_(nullptr),
62284684ddb6SLionel Sambuc      __suffix_(),
62294684ddb6SLionel Sambuc      _N_(0)
62304684ddb6SLionel Sambuc{
62314684ddb6SLionel Sambuc}
62324684ddb6SLionel Sambuc
62334684ddb6SLionel Sambuctemplate <class _BidirectionalIterator, class _CharT, class _Traits>
62344684ddb6SLionel Sambucvoid
62354684ddb6SLionel Sambucregex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
62364684ddb6SLionel Sambuc    __init(_BidirectionalIterator __a, _BidirectionalIterator __b)
62374684ddb6SLionel Sambuc{
62384684ddb6SLionel Sambuc    if (__position_ != _Position())
6239*0a6a1f1dSLionel Sambuc        __establish_result ();
62404684ddb6SLionel Sambuc    else if (__subs_[_N_] == -1)
62414684ddb6SLionel Sambuc    {
62424684ddb6SLionel Sambuc        __suffix_.matched = true;
62434684ddb6SLionel Sambuc        __suffix_.first = __a;
62444684ddb6SLionel Sambuc        __suffix_.second = __b;
62454684ddb6SLionel Sambuc        __result_ = &__suffix_;
62464684ddb6SLionel Sambuc    }
62474684ddb6SLionel Sambuc    else
62484684ddb6SLionel Sambuc        __result_ = nullptr;
62494684ddb6SLionel Sambuc}
62504684ddb6SLionel Sambuc
62514684ddb6SLionel Sambuctemplate <class _BidirectionalIterator, class _CharT, class _Traits>
62524684ddb6SLionel Sambucregex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
62534684ddb6SLionel Sambuc    regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
62544684ddb6SLionel Sambuc                         const regex_type& __re, int __submatch,
62554684ddb6SLionel Sambuc                         regex_constants::match_flag_type __m)
62564684ddb6SLionel Sambuc    : __position_(__a, __b, __re, __m),
62574684ddb6SLionel Sambuc      _N_(0),
62584684ddb6SLionel Sambuc      __subs_(1, __submatch)
62594684ddb6SLionel Sambuc{
62604684ddb6SLionel Sambuc    __init(__a, __b);
62614684ddb6SLionel Sambuc}
62624684ddb6SLionel Sambuc
62634684ddb6SLionel Sambuctemplate <class _BidirectionalIterator, class _CharT, class _Traits>
62644684ddb6SLionel Sambucregex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
62654684ddb6SLionel Sambuc    regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
62664684ddb6SLionel Sambuc                         const regex_type& __re, const vector<int>& __submatches,
62674684ddb6SLionel Sambuc                         regex_constants::match_flag_type __m)
62684684ddb6SLionel Sambuc    : __position_(__a, __b, __re, __m),
62694684ddb6SLionel Sambuc      _N_(0),
62704684ddb6SLionel Sambuc      __subs_(__submatches)
62714684ddb6SLionel Sambuc{
62724684ddb6SLionel Sambuc    __init(__a, __b);
62734684ddb6SLionel Sambuc}
62744684ddb6SLionel Sambuc
62754684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
62764684ddb6SLionel Sambuc
62774684ddb6SLionel Sambuctemplate <class _BidirectionalIterator, class _CharT, class _Traits>
62784684ddb6SLionel Sambucregex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
62794684ddb6SLionel Sambuc    regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
62804684ddb6SLionel Sambuc                         const regex_type& __re,
62814684ddb6SLionel Sambuc                         initializer_list<int> __submatches,
62824684ddb6SLionel Sambuc                         regex_constants::match_flag_type __m)
62834684ddb6SLionel Sambuc    : __position_(__a, __b, __re, __m),
62844684ddb6SLionel Sambuc      _N_(0),
62854684ddb6SLionel Sambuc      __subs_(__submatches)
62864684ddb6SLionel Sambuc{
62874684ddb6SLionel Sambuc    __init(__a, __b);
62884684ddb6SLionel Sambuc}
62894684ddb6SLionel Sambuc
62904684ddb6SLionel Sambuc#endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
62914684ddb6SLionel Sambuc
62924684ddb6SLionel Sambuctemplate <class _BidirectionalIterator, class _CharT, class _Traits>
62934684ddb6SLionel Sambuctemplate <size_t _Np>
62944684ddb6SLionel Sambucregex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
62954684ddb6SLionel Sambuc    regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
62964684ddb6SLionel Sambuc                             const regex_type& __re,
62974684ddb6SLionel Sambuc                             const int (&__submatches)[_Np],
62984684ddb6SLionel Sambuc                             regex_constants::match_flag_type __m)
62994684ddb6SLionel Sambuc    : __position_(__a, __b, __re, __m),
63004684ddb6SLionel Sambuc      _N_(0),
63014684ddb6SLionel Sambuc      __subs_(__submatches, __submatches + _Np)
63024684ddb6SLionel Sambuc{
63034684ddb6SLionel Sambuc    __init(__a, __b);
63044684ddb6SLionel Sambuc}
63054684ddb6SLionel Sambuc
63064684ddb6SLionel Sambuctemplate <class _BidirectionalIterator, class _CharT, class _Traits>
63074684ddb6SLionel Sambucregex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
63084684ddb6SLionel Sambuc    regex_token_iterator(const regex_token_iterator& __x)
63094684ddb6SLionel Sambuc    : __position_(__x.__position_),
63104684ddb6SLionel Sambuc      __result_(__x.__result_),
63114684ddb6SLionel Sambuc      __suffix_(__x.__suffix_),
63124684ddb6SLionel Sambuc      _N_(__x._N_),
63134684ddb6SLionel Sambuc      __subs_(__x.__subs_)
63144684ddb6SLionel Sambuc{
63154684ddb6SLionel Sambuc    if (__x.__result_ == &__x.__suffix_)
6316*0a6a1f1dSLionel Sambuc        __result_ = &__suffix_;
6317*0a6a1f1dSLionel Sambuc    else if ( __result_ != nullptr )
6318*0a6a1f1dSLionel Sambuc        __establish_result ();
63194684ddb6SLionel Sambuc}
63204684ddb6SLionel Sambuc
63214684ddb6SLionel Sambuctemplate <class _BidirectionalIterator, class _CharT, class _Traits>
63224684ddb6SLionel Sambucregex_token_iterator<_BidirectionalIterator, _CharT, _Traits>&
63234684ddb6SLionel Sambucregex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
63244684ddb6SLionel Sambuc    operator=(const regex_token_iterator& __x)
63254684ddb6SLionel Sambuc{
63264684ddb6SLionel Sambuc    if (this != &__x)
63274684ddb6SLionel Sambuc    {
63284684ddb6SLionel Sambuc        __position_ = __x.__position_;
63294684ddb6SLionel Sambuc        if (__x.__result_ == &__x.__suffix_)
6330*0a6a1f1dSLionel Sambuc            __result_ = &__suffix_;
63314684ddb6SLionel Sambuc        else
63324684ddb6SLionel Sambuc            __result_ = __x.__result_;
63334684ddb6SLionel Sambuc        __suffix_ = __x.__suffix_;
63344684ddb6SLionel Sambuc        _N_ = __x._N_;
63354684ddb6SLionel Sambuc        __subs_ = __x.__subs_;
6336*0a6a1f1dSLionel Sambuc
6337*0a6a1f1dSLionel Sambuc        if ( __result_ != nullptr && __result_ != &__suffix_ )
6338*0a6a1f1dSLionel Sambuc            __establish_result();
63394684ddb6SLionel Sambuc    }
63404684ddb6SLionel Sambuc    return *this;
63414684ddb6SLionel Sambuc}
63424684ddb6SLionel Sambuc
63434684ddb6SLionel Sambuctemplate <class _BidirectionalIterator, class _CharT, class _Traits>
63444684ddb6SLionel Sambucbool
63454684ddb6SLionel Sambucregex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
63464684ddb6SLionel Sambuc    operator==(const regex_token_iterator& __x) const
63474684ddb6SLionel Sambuc{
63484684ddb6SLionel Sambuc    if (__result_ == nullptr && __x.__result_ == nullptr)
63494684ddb6SLionel Sambuc        return true;
63504684ddb6SLionel Sambuc    if (__result_ == &__suffix_ && __x.__result_ == &__x.__suffix_ &&
63514684ddb6SLionel Sambuc            __suffix_ == __x.__suffix_)
63524684ddb6SLionel Sambuc        return true;
63534684ddb6SLionel Sambuc    if (__result_ == nullptr || __x.__result_ == nullptr)
63544684ddb6SLionel Sambuc        return false;
63554684ddb6SLionel Sambuc    if (__result_ == &__suffix_ || __x.__result_ == &__x.__suffix_)
63564684ddb6SLionel Sambuc        return false;
63574684ddb6SLionel Sambuc    return __position_ == __x.__position_ && _N_ == __x._N_ &&
63584684ddb6SLionel Sambuc           __subs_ == __x.__subs_;
63594684ddb6SLionel Sambuc}
63604684ddb6SLionel Sambuc
63614684ddb6SLionel Sambuctemplate <class _BidirectionalIterator, class _CharT, class _Traits>
63624684ddb6SLionel Sambucregex_token_iterator<_BidirectionalIterator, _CharT, _Traits>&
63634684ddb6SLionel Sambucregex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::operator++()
63644684ddb6SLionel Sambuc{
63654684ddb6SLionel Sambuc    _Position __prev = __position_;
63664684ddb6SLionel Sambuc    if (__result_ == &__suffix_)
63674684ddb6SLionel Sambuc        __result_ = nullptr;
63684684ddb6SLionel Sambuc    else if (_N_ + 1 < __subs_.size())
63694684ddb6SLionel Sambuc    {
63704684ddb6SLionel Sambuc        ++_N_;
6371*0a6a1f1dSLionel Sambuc        __establish_result();
63724684ddb6SLionel Sambuc    }
63734684ddb6SLionel Sambuc    else
63744684ddb6SLionel Sambuc    {
63754684ddb6SLionel Sambuc        _N_ = 0;
63764684ddb6SLionel Sambuc        ++__position_;
63774684ddb6SLionel Sambuc        if (__position_ != _Position())
6378*0a6a1f1dSLionel Sambuc            __establish_result();
63794684ddb6SLionel Sambuc        else
63804684ddb6SLionel Sambuc        {
63814684ddb6SLionel Sambuc            if (_VSTD::find(__subs_.begin(), __subs_.end(), -1) != __subs_.end()
63824684ddb6SLionel Sambuc                && __prev->suffix().length() != 0)
63834684ddb6SLionel Sambuc            {
63844684ddb6SLionel Sambuc                __suffix_.matched = true;
63854684ddb6SLionel Sambuc                __suffix_.first = __prev->suffix().first;
63864684ddb6SLionel Sambuc                __suffix_.second = __prev->suffix().second;
63874684ddb6SLionel Sambuc                __result_ = &__suffix_;
63884684ddb6SLionel Sambuc            }
63894684ddb6SLionel Sambuc            else
63904684ddb6SLionel Sambuc                __result_ = nullptr;
63914684ddb6SLionel Sambuc        }
63924684ddb6SLionel Sambuc    }
63934684ddb6SLionel Sambuc    return *this;
63944684ddb6SLionel Sambuc}
63954684ddb6SLionel Sambuc
63964684ddb6SLionel Sambuctypedef regex_token_iterator<const char*>             cregex_token_iterator;
63974684ddb6SLionel Sambuctypedef regex_token_iterator<const wchar_t*>          wcregex_token_iterator;
63984684ddb6SLionel Sambuctypedef regex_token_iterator<string::const_iterator>  sregex_token_iterator;
63994684ddb6SLionel Sambuctypedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator;
64004684ddb6SLionel Sambuc
64014684ddb6SLionel Sambuc// regex_replace
64024684ddb6SLionel Sambuc
64034684ddb6SLionel Sambuctemplate <class _OutputIterator, class _BidirectionalIterator,
64044684ddb6SLionel Sambuc          class _Traits, class _CharT>
64054684ddb6SLionel Sambuc_OutputIterator
64064684ddb6SLionel Sambucregex_replace(_OutputIterator __out,
64074684ddb6SLionel Sambuc              _BidirectionalIterator __first, _BidirectionalIterator __last,
64084684ddb6SLionel Sambuc              const basic_regex<_CharT, _Traits>& __e, const _CharT* __fmt,
64094684ddb6SLionel Sambuc              regex_constants::match_flag_type __flags = regex_constants::match_default)
64104684ddb6SLionel Sambuc{
64114684ddb6SLionel Sambuc    typedef regex_iterator<_BidirectionalIterator, _CharT, _Traits> _Iter;
64124684ddb6SLionel Sambuc    _Iter __i(__first, __last, __e, __flags);
64134684ddb6SLionel Sambuc    _Iter __eof;
64144684ddb6SLionel Sambuc    if (__i == __eof)
64154684ddb6SLionel Sambuc    {
64164684ddb6SLionel Sambuc        if (!(__flags & regex_constants::format_no_copy))
64174684ddb6SLionel Sambuc            __out = _VSTD::copy(__first, __last, __out);
64184684ddb6SLionel Sambuc    }
64194684ddb6SLionel Sambuc    else
64204684ddb6SLionel Sambuc    {
64214684ddb6SLionel Sambuc        sub_match<_BidirectionalIterator> __lm;
64224684ddb6SLionel Sambuc        for (size_t __len = char_traits<_CharT>::length(__fmt); __i != __eof; ++__i)
64234684ddb6SLionel Sambuc        {
64244684ddb6SLionel Sambuc            if (!(__flags & regex_constants::format_no_copy))
64254684ddb6SLionel Sambuc                __out = _VSTD::copy(__i->prefix().first, __i->prefix().second, __out);
64264684ddb6SLionel Sambuc            __out = __i->format(__out, __fmt, __fmt + __len, __flags);
64274684ddb6SLionel Sambuc            __lm = __i->suffix();
64284684ddb6SLionel Sambuc            if (__flags & regex_constants::format_first_only)
64294684ddb6SLionel Sambuc                break;
64304684ddb6SLionel Sambuc        }
64314684ddb6SLionel Sambuc        if (!(__flags & regex_constants::format_no_copy))
64324684ddb6SLionel Sambuc            __out = _VSTD::copy(__lm.first, __lm.second, __out);
64334684ddb6SLionel Sambuc    }
64344684ddb6SLionel Sambuc    return __out;
64354684ddb6SLionel Sambuc}
64364684ddb6SLionel Sambuc
64374684ddb6SLionel Sambuctemplate <class _OutputIterator, class _BidirectionalIterator,
64384684ddb6SLionel Sambuc          class _Traits, class _CharT, class _ST, class _SA>
64394684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
64404684ddb6SLionel Sambuc_OutputIterator
64414684ddb6SLionel Sambucregex_replace(_OutputIterator __out,
64424684ddb6SLionel Sambuc              _BidirectionalIterator __first, _BidirectionalIterator __last,
64434684ddb6SLionel Sambuc              const basic_regex<_CharT, _Traits>& __e,
64444684ddb6SLionel Sambuc              const basic_string<_CharT, _ST, _SA>& __fmt,
64454684ddb6SLionel Sambuc              regex_constants::match_flag_type __flags = regex_constants::match_default)
64464684ddb6SLionel Sambuc{
64474684ddb6SLionel Sambuc    return _VSTD::regex_replace(__out, __first, __last, __e, __fmt.c_str(), __flags);
64484684ddb6SLionel Sambuc}
64494684ddb6SLionel Sambuc
64504684ddb6SLionel Sambuctemplate <class _Traits, class _CharT, class _ST, class _SA, class _FST,
64514684ddb6SLionel Sambuc          class _FSA>
64524684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
64534684ddb6SLionel Sambucbasic_string<_CharT, _ST, _SA>
64544684ddb6SLionel Sambucregex_replace(const basic_string<_CharT, _ST, _SA>& __s,
64554684ddb6SLionel Sambuc              const basic_regex<_CharT, _Traits>& __e,
64564684ddb6SLionel Sambuc              const basic_string<_CharT, _FST, _FSA>& __fmt,
64574684ddb6SLionel Sambuc              regex_constants::match_flag_type __flags = regex_constants::match_default)
64584684ddb6SLionel Sambuc{
64594684ddb6SLionel Sambuc    basic_string<_CharT, _ST, _SA> __r;
64604684ddb6SLionel Sambuc    _VSTD::regex_replace(back_inserter(__r), __s.begin(), __s.end(), __e,
64614684ddb6SLionel Sambuc                        __fmt.c_str(), __flags);
64624684ddb6SLionel Sambuc    return __r;
64634684ddb6SLionel Sambuc}
64644684ddb6SLionel Sambuc
64654684ddb6SLionel Sambuctemplate <class _Traits, class _CharT, class _ST, class _SA>
64664684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
64674684ddb6SLionel Sambucbasic_string<_CharT, _ST, _SA>
64684684ddb6SLionel Sambucregex_replace(const basic_string<_CharT, _ST, _SA>& __s,
64694684ddb6SLionel Sambuc              const basic_regex<_CharT, _Traits>& __e, const _CharT* __fmt,
64704684ddb6SLionel Sambuc              regex_constants::match_flag_type __flags = regex_constants::match_default)
64714684ddb6SLionel Sambuc{
64724684ddb6SLionel Sambuc    basic_string<_CharT, _ST, _SA> __r;
64734684ddb6SLionel Sambuc    _VSTD::regex_replace(back_inserter(__r), __s.begin(), __s.end(), __e,
64744684ddb6SLionel Sambuc                        __fmt, __flags);
64754684ddb6SLionel Sambuc    return __r;
64764684ddb6SLionel Sambuc}
64774684ddb6SLionel Sambuc
64784684ddb6SLionel Sambuctemplate <class _Traits, class _CharT, class _ST, class _SA>
64794684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
64804684ddb6SLionel Sambucbasic_string<_CharT>
64814684ddb6SLionel Sambucregex_replace(const _CharT* __s,
64824684ddb6SLionel Sambuc              const basic_regex<_CharT, _Traits>& __e,
64834684ddb6SLionel Sambuc              const basic_string<_CharT, _ST, _SA>& __fmt,
64844684ddb6SLionel Sambuc              regex_constants::match_flag_type __flags = regex_constants::match_default)
64854684ddb6SLionel Sambuc{
64864684ddb6SLionel Sambuc    basic_string<_CharT> __r;
64874684ddb6SLionel Sambuc    _VSTD::regex_replace(back_inserter(__r), __s,
64884684ddb6SLionel Sambuc                        __s + char_traits<_CharT>::length(__s), __e,
64894684ddb6SLionel Sambuc                        __fmt.c_str(), __flags);
64904684ddb6SLionel Sambuc    return __r;
64914684ddb6SLionel Sambuc}
64924684ddb6SLionel Sambuc
64934684ddb6SLionel Sambuctemplate <class _Traits, class _CharT>
64944684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
64954684ddb6SLionel Sambucbasic_string<_CharT>
64964684ddb6SLionel Sambucregex_replace(const _CharT* __s,
64974684ddb6SLionel Sambuc              const basic_regex<_CharT, _Traits>& __e,
64984684ddb6SLionel Sambuc              const _CharT* __fmt,
64994684ddb6SLionel Sambuc              regex_constants::match_flag_type __flags = regex_constants::match_default)
65004684ddb6SLionel Sambuc{
65014684ddb6SLionel Sambuc    basic_string<_CharT> __r;
65024684ddb6SLionel Sambuc    _VSTD::regex_replace(back_inserter(__r), __s,
65034684ddb6SLionel Sambuc                        __s + char_traits<_CharT>::length(__s), __e,
65044684ddb6SLionel Sambuc                        __fmt, __flags);
65054684ddb6SLionel Sambuc    return __r;
65064684ddb6SLionel Sambuc}
65074684ddb6SLionel Sambuc
65084684ddb6SLionel Sambuc_LIBCPP_END_NAMESPACE_STD
65094684ddb6SLionel Sambuc
65104684ddb6SLionel Sambuc#endif  // _LIBCPP_REGEX
6511