xref: /freebsd-12.1/contrib/libc++/include/regex (revision b5893f02)
17a984708SDavid Chisnall// -*- C++ -*-
27a984708SDavid Chisnall//===--------------------------- regex ------------------------------------===//
37a984708SDavid Chisnall//
47a984708SDavid Chisnall//                     The LLVM Compiler Infrastructure
57a984708SDavid Chisnall//
67a984708SDavid Chisnall// This file is dual licensed under the MIT and the University of Illinois Open
77a984708SDavid Chisnall// Source Licenses. See LICENSE.TXT for details.
87a984708SDavid Chisnall//
97a984708SDavid Chisnall//===----------------------------------------------------------------------===//
107a984708SDavid Chisnall
117a984708SDavid Chisnall#ifndef _LIBCPP_REGEX
127a984708SDavid Chisnall#define _LIBCPP_REGEX
137a984708SDavid Chisnall
147a984708SDavid Chisnall/*
157a984708SDavid Chisnall    regex synopsis
167a984708SDavid Chisnall
177a984708SDavid Chisnall#include <initializer_list>
187a984708SDavid Chisnall
197a984708SDavid Chisnallnamespace std
207a984708SDavid Chisnall{
217a984708SDavid Chisnall
227a984708SDavid Chisnallnamespace regex_constants
237a984708SDavid Chisnall{
247a984708SDavid Chisnall
257a984708SDavid Chisnallemum syntax_option_type
267a984708SDavid Chisnall{
277a984708SDavid Chisnall    icase      = unspecified,
287a984708SDavid Chisnall    nosubs     = unspecified,
297a984708SDavid Chisnall    optimize   = unspecified,
307a984708SDavid Chisnall    collate    = unspecified,
317a984708SDavid Chisnall    ECMAScript = unspecified,
327a984708SDavid Chisnall    basic      = unspecified,
337a984708SDavid Chisnall    extended   = unspecified,
347a984708SDavid Chisnall    awk        = unspecified,
357a984708SDavid Chisnall    grep       = unspecified,
367a984708SDavid Chisnall    egrep      = unspecified
377a984708SDavid Chisnall};
387a984708SDavid Chisnall
397a984708SDavid Chisnallconstexpr syntax_option_type operator~(syntax_option_type f);
407a984708SDavid Chisnallconstexpr syntax_option_type operator&(syntax_option_type lhs, syntax_option_type rhs);
417a984708SDavid Chisnallconstexpr syntax_option_type operator|(syntax_option_type lhs, syntax_option_type rhs);
427a984708SDavid Chisnall
437a984708SDavid Chisnallenum match_flag_type
447a984708SDavid Chisnall{
457a984708SDavid Chisnall    match_default     = 0,
467a984708SDavid Chisnall    match_not_bol     = unspecified,
477a984708SDavid Chisnall    match_not_eol     = unspecified,
487a984708SDavid Chisnall    match_not_bow     = unspecified,
497a984708SDavid Chisnall    match_not_eow     = unspecified,
507a984708SDavid Chisnall    match_any         = unspecified,
517a984708SDavid Chisnall    match_not_null    = unspecified,
527a984708SDavid Chisnall    match_continuous  = unspecified,
537a984708SDavid Chisnall    match_prev_avail  = unspecified,
547a984708SDavid Chisnall    format_default    = 0,
557a984708SDavid Chisnall    format_sed        = unspecified,
567a984708SDavid Chisnall    format_no_copy    = unspecified,
577a984708SDavid Chisnall    format_first_only = unspecified
587a984708SDavid Chisnall};
597a984708SDavid Chisnall
607a984708SDavid Chisnallconstexpr match_flag_type operator~(match_flag_type f);
617a984708SDavid Chisnallconstexpr match_flag_type operator&(match_flag_type lhs, match_flag_type rhs);
627a984708SDavid Chisnallconstexpr match_flag_type operator|(match_flag_type lhs, match_flag_type rhs);
637a984708SDavid Chisnall
647a984708SDavid Chisnallenum error_type
657a984708SDavid Chisnall{
667a984708SDavid Chisnall    error_collate    = unspecified,
677a984708SDavid Chisnall    error_ctype      = unspecified,
687a984708SDavid Chisnall    error_escape     = unspecified,
697a984708SDavid Chisnall    error_backref    = unspecified,
707a984708SDavid Chisnall    error_brack      = unspecified,
717a984708SDavid Chisnall    error_paren      = unspecified,
727a984708SDavid Chisnall    error_brace      = unspecified,
737a984708SDavid Chisnall    error_badbrace   = unspecified,
747a984708SDavid Chisnall    error_range      = unspecified,
757a984708SDavid Chisnall    error_space      = unspecified,
767a984708SDavid Chisnall    error_badrepeat  = unspecified,
777a984708SDavid Chisnall    error_complexity = unspecified,
787a984708SDavid Chisnall    error_stack      = unspecified
797a984708SDavid Chisnall};
807a984708SDavid Chisnall
817a984708SDavid Chisnall}  // regex_constants
827a984708SDavid Chisnall
837a984708SDavid Chisnallclass regex_error
847a984708SDavid Chisnall    : public runtime_error
857a984708SDavid Chisnall{
867a984708SDavid Chisnallpublic:
877a984708SDavid Chisnall    explicit regex_error(regex_constants::error_type ecode);
887a984708SDavid Chisnall    regex_constants::error_type code() const;
897a984708SDavid Chisnall};
907a984708SDavid Chisnall
917a984708SDavid Chisnalltemplate <class charT>
927a984708SDavid Chisnallstruct regex_traits
937a984708SDavid Chisnall{
947a984708SDavid Chisnallpublic:
957a984708SDavid Chisnall    typedef charT                   char_type;
967a984708SDavid Chisnall    typedef basic_string<char_type> string_type;
977a984708SDavid Chisnall    typedef locale                  locale_type;
987a984708SDavid Chisnall    typedef /bitmask_type/          char_class_type;
997a984708SDavid Chisnall
1007a984708SDavid Chisnall    regex_traits();
1017a984708SDavid Chisnall
1027a984708SDavid Chisnall    static size_t length(const char_type* p);
1037a984708SDavid Chisnall    charT translate(charT c) const;
1047a984708SDavid Chisnall    charT translate_nocase(charT c) const;
1057a984708SDavid Chisnall    template <class ForwardIterator>
1067a984708SDavid Chisnall        string_type
1077a984708SDavid Chisnall        transform(ForwardIterator first, ForwardIterator last) const;
1087a984708SDavid Chisnall    template <class ForwardIterator>
1097a984708SDavid Chisnall        string_type
1107a984708SDavid Chisnall        transform_primary( ForwardIterator first, ForwardIterator last) const;
1117a984708SDavid Chisnall    template <class ForwardIterator>
1127a984708SDavid Chisnall        string_type
1137a984708SDavid Chisnall        lookup_collatename(ForwardIterator first, ForwardIterator last) const;
1147a984708SDavid Chisnall    template <class ForwardIterator>
1157a984708SDavid Chisnall        char_class_type
1167a984708SDavid Chisnall        lookup_classname(ForwardIterator first, ForwardIterator last,
1177a984708SDavid Chisnall                         bool icase = false) const;
1187a984708SDavid Chisnall    bool isctype(charT c, char_class_type f) const;
1197a984708SDavid Chisnall    int value(charT ch, int radix) const;
1207a984708SDavid Chisnall    locale_type imbue(locale_type l);
1217a984708SDavid Chisnall    locale_type getloc()const;
1227a984708SDavid Chisnall};
1237a984708SDavid Chisnall
1247a984708SDavid Chisnalltemplate <class charT, class traits = regex_traits<charT>>
1257a984708SDavid Chisnallclass basic_regex
1267a984708SDavid Chisnall{
1277a984708SDavid Chisnallpublic:
1287a984708SDavid Chisnall    // types:
1297a984708SDavid Chisnall    typedef charT                               value_type;
130aed8d94eSDimitry Andric    typedef traits                              traits_type;
131aed8d94eSDimitry Andric    typedef typename traits::string_type        string_type;
1327a984708SDavid Chisnall    typedef regex_constants::syntax_option_type flag_type;
1337a984708SDavid Chisnall    typedef typename traits::locale_type        locale_type;
1347a984708SDavid Chisnall
1357a984708SDavid Chisnall    // constants:
1367a984708SDavid Chisnall    static constexpr regex_constants::syntax_option_type icase = regex_constants::icase;
1377a984708SDavid Chisnall    static constexpr regex_constants::syntax_option_type nosubs = regex_constants::nosubs;
1387a984708SDavid Chisnall    static constexpr regex_constants::syntax_option_type optimize = regex_constants::optimize;
1397a984708SDavid Chisnall    static constexpr regex_constants::syntax_option_type collate = regex_constants::collate;
1407a984708SDavid Chisnall    static constexpr regex_constants::syntax_option_type ECMAScript = regex_constants::ECMAScript;
1417a984708SDavid Chisnall    static constexpr regex_constants::syntax_option_type basic = regex_constants::basic;
1427a984708SDavid Chisnall    static constexpr regex_constants::syntax_option_type extended = regex_constants::extended;
1437a984708SDavid Chisnall    static constexpr regex_constants::syntax_option_type awk = regex_constants::awk;
1447a984708SDavid Chisnall    static constexpr regex_constants::syntax_option_type grep = regex_constants::grep;
1457a984708SDavid Chisnall    static constexpr regex_constants::syntax_option_type egrep = regex_constants::egrep;
1467a984708SDavid Chisnall
1477a984708SDavid Chisnall    // construct/copy/destroy:
1487a984708SDavid Chisnall    basic_regex();
1497a984708SDavid Chisnall    explicit basic_regex(const charT* p, flag_type f = regex_constants::ECMAScript);
150aed8d94eSDimitry Andric    basic_regex(const charT* p, size_t len, flag_type f = regex_constants::ECMAScript);
1517a984708SDavid Chisnall    basic_regex(const basic_regex&);
152936e9439SDimitry Andric    basic_regex(basic_regex&&) noexcept;
1537a984708SDavid Chisnall    template <class ST, class SA>
1547a984708SDavid Chisnall        explicit basic_regex(const basic_string<charT, ST, SA>& p,
1557a984708SDavid Chisnall                             flag_type f = regex_constants::ECMAScript);
1567a984708SDavid Chisnall    template <class ForwardIterator>
1577a984708SDavid Chisnall        basic_regex(ForwardIterator first, ForwardIterator last,
1587a984708SDavid Chisnall                    flag_type f = regex_constants::ECMAScript);
1597a984708SDavid Chisnall    basic_regex(initializer_list<charT>, flag_type = regex_constants::ECMAScript);
1607a984708SDavid Chisnall
1617a984708SDavid Chisnall    ~basic_regex();
1627a984708SDavid Chisnall
1637a984708SDavid Chisnall    basic_regex& operator=(const basic_regex&);
164936e9439SDimitry Andric    basic_regex& operator=(basic_regex&&) noexcept;
1657a984708SDavid Chisnall    basic_regex& operator=(const charT* ptr);
1667a984708SDavid Chisnall    basic_regex& operator=(initializer_list<charT> il);
1677a984708SDavid Chisnall    template <class ST, class SA>
1687a984708SDavid Chisnall        basic_regex& operator=(const basic_string<charT, ST, SA>& p);
1697a984708SDavid Chisnall
1707a984708SDavid Chisnall    // assign:
1717a984708SDavid Chisnall    basic_regex& assign(const basic_regex& that);
172936e9439SDimitry Andric    basic_regex& assign(basic_regex&& that) noexcept;
1737a984708SDavid Chisnall    basic_regex& assign(const charT* ptr, flag_type f = regex_constants::ECMAScript);
1747a984708SDavid Chisnall    basic_regex& assign(const charT* p, size_t len, flag_type f);
1757a984708SDavid Chisnall    template <class string_traits, class A>
1767a984708SDavid Chisnall        basic_regex& assign(const basic_string<charT, string_traits, A>& s,
1777a984708SDavid Chisnall                            flag_type f = regex_constants::ECMAScript);
1787a984708SDavid Chisnall    template <class InputIterator>
1797a984708SDavid Chisnall        basic_regex& assign(InputIterator first, InputIterator last,
1807a984708SDavid Chisnall                            flag_type f = regex_constants::ECMAScript);
1817a984708SDavid Chisnall    basic_regex& assign(initializer_list<charT>, flag_type = regex_constants::ECMAScript);
1827a984708SDavid Chisnall
1837a984708SDavid Chisnall    // const operations:
1847a984708SDavid Chisnall    unsigned mark_count() const;
1857a984708SDavid Chisnall    flag_type flags() const;
1867a984708SDavid Chisnall
1877a984708SDavid Chisnall    // locale:
1887a984708SDavid Chisnall    locale_type imbue(locale_type loc);
1897a984708SDavid Chisnall    locale_type getloc() const;
1907a984708SDavid Chisnall
1917a984708SDavid Chisnall    // swap:
1927a984708SDavid Chisnall    void swap(basic_regex&);
1937a984708SDavid Chisnall};
1947a984708SDavid Chisnall
1954ba319b5SDimitry Andrictemplate<class ForwardIterator>
1964ba319b5SDimitry Andricbasic_regex(ForwardIterator, ForwardIterator,
1974ba319b5SDimitry Andric            regex_constants::syntax_option_type = regex_constants::ECMAScript)
1984ba319b5SDimitry Andric    -> basic_regex<typename iterator_traits<ForwardIterator>::value_type>; // C++17
1994ba319b5SDimitry Andric
2007a984708SDavid Chisnalltypedef basic_regex<char>    regex;
2017a984708SDavid Chisnalltypedef basic_regex<wchar_t> wregex;
2027a984708SDavid Chisnall
2037a984708SDavid Chisnalltemplate <class charT, class traits>
2047a984708SDavid Chisnall    void swap(basic_regex<charT, traits>& e1, basic_regex<charT, traits>& e2);
2057a984708SDavid Chisnall
2067a984708SDavid Chisnalltemplate <class BidirectionalIterator>
2077a984708SDavid Chisnallclass sub_match
2087a984708SDavid Chisnall    : public pair<BidirectionalIterator, BidirectionalIterator>
2097a984708SDavid Chisnall{
2107a984708SDavid Chisnallpublic:
2117a984708SDavid Chisnall    typedef typename iterator_traits<BidirectionalIterator>::value_type value_type;
2127a984708SDavid Chisnall    typedef typename iterator_traits<BidirectionalIterator>::difference_type difference_type;
2137a984708SDavid Chisnall    typedef BidirectionalIterator                                      iterator;
2147a984708SDavid Chisnall    typedef basic_string<value_type>                                string_type;
2157a984708SDavid Chisnall
2167a984708SDavid Chisnall    bool matched;
2177a984708SDavid Chisnall
2187a984708SDavid Chisnall    constexpr sub_match();
2197a984708SDavid Chisnall
2207a984708SDavid Chisnall    difference_type length() const;
2217a984708SDavid Chisnall    operator string_type() const;
2227a984708SDavid Chisnall    string_type str() const;
2237a984708SDavid Chisnall
2247a984708SDavid Chisnall    int compare(const sub_match& s) const;
2257a984708SDavid Chisnall    int compare(const string_type& s) const;
2267a984708SDavid Chisnall    int compare(const value_type* s) const;
2277a984708SDavid Chisnall};
2287a984708SDavid Chisnall
2297a984708SDavid Chisnalltypedef sub_match<const char*>             csub_match;
2307a984708SDavid Chisnalltypedef sub_match<const wchar_t*>          wcsub_match;
2317a984708SDavid Chisnalltypedef sub_match<string::const_iterator>  ssub_match;
2327a984708SDavid Chisnalltypedef sub_match<wstring::const_iterator> wssub_match;
2337a984708SDavid Chisnall
2347a984708SDavid Chisnalltemplate <class BiIter>
2357a984708SDavid Chisnall    bool
2367a984708SDavid Chisnall    operator==(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
2377a984708SDavid Chisnall
2387a984708SDavid Chisnalltemplate <class BiIter>
2397a984708SDavid Chisnall    bool
2407a984708SDavid Chisnall    operator!=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
2417a984708SDavid Chisnall
2427a984708SDavid Chisnalltemplate <class BiIter>
2437a984708SDavid Chisnall    bool
2447a984708SDavid Chisnall    operator<(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
2457a984708SDavid Chisnall
2467a984708SDavid Chisnalltemplate <class BiIter>
2477a984708SDavid Chisnall    bool
2487a984708SDavid Chisnall    operator<=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
2497a984708SDavid Chisnall
2507a984708SDavid Chisnalltemplate <class BiIter>
2517a984708SDavid Chisnall    bool
2527a984708SDavid Chisnall    operator>=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
2537a984708SDavid Chisnall
2547a984708SDavid Chisnalltemplate <class BiIter>
2557a984708SDavid Chisnall    bool
2567a984708SDavid Chisnall    operator>(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
2577a984708SDavid Chisnall
2587a984708SDavid Chisnalltemplate <class BiIter, class ST, class SA>
2597a984708SDavid Chisnall    bool
2607a984708SDavid Chisnall    operator==(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
2617a984708SDavid Chisnall               const sub_match<BiIter>& rhs);
2627a984708SDavid Chisnall
2637a984708SDavid Chisnalltemplate <class BiIter, class ST, class SA>
2647a984708SDavid Chisnall    bool
2657a984708SDavid Chisnall    operator!=(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
2667a984708SDavid Chisnall               const sub_match<BiIter>& rhs);
2677a984708SDavid Chisnall
2687a984708SDavid Chisnalltemplate <class BiIter, class ST, class SA>
2697a984708SDavid Chisnall    bool
2707a984708SDavid Chisnall    operator<(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
2717a984708SDavid Chisnall              const sub_match<BiIter>& rhs);
2727a984708SDavid Chisnall
2737a984708SDavid Chisnalltemplate <class BiIter, class ST, class SA>
2747a984708SDavid Chisnall    bool
2757a984708SDavid Chisnall    operator>(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
2767a984708SDavid Chisnall              const sub_match<BiIter>& rhs);
2777a984708SDavid Chisnall
2787a984708SDavid Chisnalltemplate <class BiIter, class ST, class SA>
2797a984708SDavid Chisnall    bool operator>=(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
2807a984708SDavid Chisnall                    const sub_match<BiIter>& rhs);
2817a984708SDavid Chisnall
2827a984708SDavid Chisnalltemplate <class BiIter, class ST, class SA>
2837a984708SDavid Chisnall    bool
2847a984708SDavid Chisnall    operator<=(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
2857a984708SDavid Chisnall               const sub_match<BiIter>& rhs);
2867a984708SDavid Chisnall
2877a984708SDavid Chisnalltemplate <class BiIter, class ST, class SA>
2887a984708SDavid Chisnall    bool
2897a984708SDavid Chisnall    operator==(const sub_match<BiIter>& lhs,
2907a984708SDavid Chisnall               const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
2917a984708SDavid Chisnall
2927a984708SDavid Chisnalltemplate <class BiIter, class ST, class SA>
2937a984708SDavid Chisnall    bool
2947a984708SDavid Chisnall    operator!=(const sub_match<BiIter>& lhs,
2957a984708SDavid Chisnall               const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
2967a984708SDavid Chisnall
2977a984708SDavid Chisnalltemplate <class BiIter, class ST, class SA>
2987a984708SDavid Chisnall    bool
2997a984708SDavid Chisnall    operator<(const sub_match<BiIter>& lhs,
3007a984708SDavid Chisnall              const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
3017a984708SDavid Chisnall
3027a984708SDavid Chisnalltemplate <class BiIter, class ST, class SA>
3037a984708SDavid Chisnall    bool operator>(const sub_match<BiIter>& lhs,
3047a984708SDavid Chisnall                   const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
3057a984708SDavid Chisnall
3067a984708SDavid Chisnalltemplate <class BiIter, class ST, class SA>
3077a984708SDavid Chisnall    bool
3087a984708SDavid Chisnall    operator>=(const sub_match<BiIter>& lhs,
3097a984708SDavid Chisnall               const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
3107a984708SDavid Chisnall
3117a984708SDavid Chisnalltemplate <class BiIter, class ST, class SA>
3127a984708SDavid Chisnall    bool
3137a984708SDavid Chisnall    operator<=(const sub_match<BiIter>& lhs,
3147a984708SDavid Chisnall               const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
3157a984708SDavid Chisnall
3167a984708SDavid Chisnalltemplate <class BiIter>
3177a984708SDavid Chisnall    bool
3187a984708SDavid Chisnall    operator==(typename iterator_traits<BiIter>::value_type const* lhs,
3197a984708SDavid Chisnall               const sub_match<BiIter>& rhs);
3207a984708SDavid Chisnall
3217a984708SDavid Chisnalltemplate <class BiIter>
3227a984708SDavid Chisnall    bool
3237a984708SDavid Chisnall    operator!=(typename iterator_traits<BiIter>::value_type const* lhs,
3247a984708SDavid Chisnall               const sub_match<BiIter>& rhs);
3257a984708SDavid Chisnall
3267a984708SDavid Chisnalltemplate <class BiIter>
3277a984708SDavid Chisnall    bool
3287a984708SDavid Chisnall    operator<(typename iterator_traits<BiIter>::value_type const* lhs,
3297a984708SDavid Chisnall              const sub_match<BiIter>& rhs);
3307a984708SDavid Chisnall
3317a984708SDavid Chisnalltemplate <class BiIter>
3327a984708SDavid Chisnall    bool
3337a984708SDavid Chisnall    operator>(typename iterator_traits<BiIter>::value_type const* lhs,
3347a984708SDavid Chisnall              const sub_match<BiIter>& rhs);
3357a984708SDavid Chisnall
3367a984708SDavid Chisnalltemplate <class BiIter>
3377a984708SDavid Chisnall    bool
3387a984708SDavid Chisnall    operator>=(typename iterator_traits<BiIter>::value_type const* lhs,
3397a984708SDavid Chisnall               const sub_match<BiIter>& rhs);
3407a984708SDavid Chisnall
3417a984708SDavid Chisnalltemplate <class BiIter>
3427a984708SDavid Chisnall    bool
3437a984708SDavid Chisnall    operator<=(typename iterator_traits<BiIter>::value_type const* lhs,
3447a984708SDavid Chisnall               const sub_match<BiIter>& rhs);
3457a984708SDavid Chisnall
3467a984708SDavid Chisnalltemplate <class BiIter>
3477a984708SDavid Chisnall    bool
3487a984708SDavid Chisnall    operator==(const sub_match<BiIter>& lhs,
3497a984708SDavid Chisnall               typename iterator_traits<BiIter>::value_type const* rhs);
3507a984708SDavid Chisnall
3517a984708SDavid Chisnalltemplate <class BiIter>
3527a984708SDavid Chisnall    bool
3537a984708SDavid Chisnall    operator!=(const sub_match<BiIter>& lhs,
3547a984708SDavid Chisnall               typename iterator_traits<BiIter>::value_type const* rhs);
3557a984708SDavid Chisnall
3567a984708SDavid Chisnalltemplate <class BiIter>
3577a984708SDavid Chisnall    bool
3587a984708SDavid Chisnall    operator<(const sub_match<BiIter>& lhs,
3597a984708SDavid Chisnall              typename iterator_traits<BiIter>::value_type const* rhs);
3607a984708SDavid Chisnall
3617a984708SDavid Chisnalltemplate <class BiIter>
3627a984708SDavid Chisnall    bool
3637a984708SDavid Chisnall    operator>(const sub_match<BiIter>& lhs,
3647a984708SDavid Chisnall              typename iterator_traits<BiIter>::value_type const* rhs);
3657a984708SDavid Chisnall
3667a984708SDavid Chisnalltemplate <class BiIter>
3677a984708SDavid Chisnall    bool
3687a984708SDavid Chisnall    operator>=(const sub_match<BiIter>& lhs,
3697a984708SDavid Chisnall               typename iterator_traits<BiIter>::value_type const* rhs);
3707a984708SDavid Chisnall
3717a984708SDavid Chisnalltemplate <class BiIter>
3727a984708SDavid Chisnall    bool
3737a984708SDavid Chisnall    operator<=(const sub_match<BiIter>& lhs,
3747a984708SDavid Chisnall               typename iterator_traits<BiIter>::value_type const* rhs);
3757a984708SDavid Chisnall
3767a984708SDavid Chisnalltemplate <class BiIter>
3777a984708SDavid Chisnall    bool
3787a984708SDavid Chisnall    operator==(typename iterator_traits<BiIter>::value_type const& lhs,
3797a984708SDavid Chisnall               const sub_match<BiIter>& rhs);
3807a984708SDavid Chisnall
3817a984708SDavid Chisnalltemplate <class BiIter>
3827a984708SDavid Chisnall    bool
3837a984708SDavid Chisnall    operator!=(typename iterator_traits<BiIter>::value_type const& lhs,
3847a984708SDavid Chisnall               const sub_match<BiIter>& rhs);
3857a984708SDavid Chisnall
3867a984708SDavid Chisnalltemplate <class BiIter>
3877a984708SDavid Chisnall    bool
3887a984708SDavid Chisnall    operator<(typename iterator_traits<BiIter>::value_type const& lhs,
3897a984708SDavid Chisnall              const sub_match<BiIter>& rhs);
3907a984708SDavid Chisnall
3917a984708SDavid Chisnalltemplate <class BiIter>
3927a984708SDavid Chisnall    bool
3937a984708SDavid Chisnall    operator>(typename iterator_traits<BiIter>::value_type const& lhs,
3947a984708SDavid Chisnall              const sub_match<BiIter>& rhs);
3957a984708SDavid Chisnall
3967a984708SDavid Chisnalltemplate <class BiIter>
3977a984708SDavid Chisnall    bool
3987a984708SDavid Chisnall    operator>=(typename iterator_traits<BiIter>::value_type const& lhs,
3997a984708SDavid Chisnall               const sub_match<BiIter>& rhs);
4007a984708SDavid Chisnall
4017a984708SDavid Chisnalltemplate <class BiIter>
4027a984708SDavid Chisnall    bool
4037a984708SDavid Chisnall    operator<=(typename iterator_traits<BiIter>::value_type const& lhs,
4047a984708SDavid Chisnall               const sub_match<BiIter>& rhs);
4057a984708SDavid Chisnall
4067a984708SDavid Chisnalltemplate <class BiIter>
4077a984708SDavid Chisnall    bool
4087a984708SDavid Chisnall    operator==(const sub_match<BiIter>& lhs,
4097a984708SDavid Chisnall               typename iterator_traits<BiIter>::value_type const& rhs);
4107a984708SDavid Chisnall
4117a984708SDavid Chisnalltemplate <class BiIter>
4127a984708SDavid Chisnall    bool
4137a984708SDavid Chisnall    operator!=(const sub_match<BiIter>& lhs,
4147a984708SDavid Chisnall               typename iterator_traits<BiIter>::value_type const& rhs);
4157a984708SDavid Chisnall
4167a984708SDavid Chisnalltemplate <class BiIter>
4177a984708SDavid Chisnall    bool
4187a984708SDavid Chisnall    operator<(const sub_match<BiIter>& lhs,
4197a984708SDavid Chisnall              typename iterator_traits<BiIter>::value_type const& rhs);
4207a984708SDavid Chisnall
4217a984708SDavid Chisnalltemplate <class BiIter>
4227a984708SDavid Chisnall    bool
4237a984708SDavid Chisnall    operator>(const sub_match<BiIter>& lhs,
4247a984708SDavid Chisnall              typename iterator_traits<BiIter>::value_type const& rhs);
4257a984708SDavid Chisnall
4267a984708SDavid Chisnalltemplate <class BiIter>
4277a984708SDavid Chisnall    bool
4287a984708SDavid Chisnall    operator>=(const sub_match<BiIter>& lhs,
4297a984708SDavid Chisnall               typename iterator_traits<BiIter>::value_type const& rhs);
4307a984708SDavid Chisnall
4317a984708SDavid Chisnalltemplate <class BiIter>
4327a984708SDavid Chisnall    bool
4337a984708SDavid Chisnall    operator<=(const sub_match<BiIter>& lhs,
4347a984708SDavid Chisnall               typename iterator_traits<BiIter>::value_type const& rhs);
4357a984708SDavid Chisnall
4367a984708SDavid Chisnalltemplate <class charT, class ST, class BiIter>
4377a984708SDavid Chisnall    basic_ostream<charT, ST>&
4387a984708SDavid Chisnall    operator<<(basic_ostream<charT, ST>& os, const sub_match<BiIter>& m);
4397a984708SDavid Chisnall
4407a984708SDavid Chisnalltemplate <class BidirectionalIterator,
4417a984708SDavid Chisnall          class Allocator = allocator<sub_match<BidirectionalIterator>>>
4427a984708SDavid Chisnallclass match_results
4437a984708SDavid Chisnall{
4447a984708SDavid Chisnallpublic:
4457a984708SDavid Chisnall    typedef sub_match<BidirectionalIterator>                  value_type;
4467a984708SDavid Chisnall    typedef const value_type&                                 const_reference;
447d72607e9SDimitry Andric    typedef value_type&                                       reference;
4487a984708SDavid Chisnall    typedef /implementation-defined/                          const_iterator;
4497a984708SDavid Chisnall    typedef const_iterator                                    iterator;
4507a984708SDavid Chisnall    typedef typename iterator_traits<BidirectionalIterator>::difference_type difference_type;
4517a984708SDavid Chisnall    typedef typename allocator_traits<Allocator>::size_type   size_type;
4527a984708SDavid Chisnall    typedef Allocator                                         allocator_type;
4537a984708SDavid Chisnall    typedef typename iterator_traits<BidirectionalIterator>::value_type char_type;
4547a984708SDavid Chisnall    typedef basic_string<char_type>                           string_type;
4557a984708SDavid Chisnall
4567a984708SDavid Chisnall    // construct/copy/destroy:
4577a984708SDavid Chisnall    explicit match_results(const Allocator& a = Allocator());
4587a984708SDavid Chisnall    match_results(const match_results& m);
459936e9439SDimitry Andric    match_results(match_results&& m) noexcept;
4607a984708SDavid Chisnall    match_results& operator=(const match_results& m);
4617a984708SDavid Chisnall    match_results& operator=(match_results&& m);
4627a984708SDavid Chisnall    ~match_results();
4637a984708SDavid Chisnall
4647a984708SDavid Chisnall    bool ready() const;
4657a984708SDavid Chisnall
4667a984708SDavid Chisnall    // size:
4677a984708SDavid Chisnall    size_type size() const;
4687a984708SDavid Chisnall    size_type max_size() const;
4697a984708SDavid Chisnall    bool empty() const;
4707a984708SDavid Chisnall
4717a984708SDavid Chisnall    // element access:
4727a984708SDavid Chisnall    difference_type length(size_type sub = 0) const;
4737a984708SDavid Chisnall    difference_type position(size_type sub = 0) const;
4747a984708SDavid Chisnall    string_type str(size_type sub = 0) const;
4757a984708SDavid Chisnall    const_reference operator[](size_type n) const;
4767a984708SDavid Chisnall
4777a984708SDavid Chisnall    const_reference prefix() const;
4787a984708SDavid Chisnall    const_reference suffix() const;
4797a984708SDavid Chisnall
4807a984708SDavid Chisnall    const_iterator begin() const;
4817a984708SDavid Chisnall    const_iterator end() const;
4827a984708SDavid Chisnall    const_iterator cbegin() const;
4837a984708SDavid Chisnall    const_iterator cend() const;
4847a984708SDavid Chisnall
4857a984708SDavid Chisnall    // format:
4867a984708SDavid Chisnall    template <class OutputIter>
4877a984708SDavid Chisnall        OutputIter
4887a984708SDavid Chisnall        format(OutputIter out, const char_type* fmt_first,
4897a984708SDavid Chisnall               const char_type* fmt_last,
4907a984708SDavid Chisnall               regex_constants::match_flag_type flags = regex_constants::format_default) const;
4917a984708SDavid Chisnall    template <class OutputIter, class ST, class SA>
4927a984708SDavid Chisnall        OutputIter
4937a984708SDavid Chisnall        format(OutputIter out, const basic_string<char_type, ST, SA>& fmt,
4947a984708SDavid Chisnall               regex_constants::match_flag_type flags = regex_constants::format_default) const;
4957a984708SDavid Chisnall    template <class ST, class SA>
4967a984708SDavid Chisnall        basic_string<char_type, ST, SA>
4977a984708SDavid Chisnall        format(const basic_string<char_type, ST, SA>& fmt,
4987a984708SDavid Chisnall               regex_constants::match_flag_type flags = regex_constants::format_default) const;
4997a984708SDavid Chisnall    string_type
5007a984708SDavid Chisnall        format(const char_type* fmt,
5017a984708SDavid Chisnall               regex_constants::match_flag_type flags = regex_constants::format_default) const;
5027a984708SDavid Chisnall
5037a984708SDavid Chisnall    // allocator:
5047a984708SDavid Chisnall    allocator_type get_allocator() const;
5057a984708SDavid Chisnall
5067a984708SDavid Chisnall    // swap:
5077a984708SDavid Chisnall    void swap(match_results& that);
5087a984708SDavid Chisnall};
5097a984708SDavid Chisnall
5107a984708SDavid Chisnalltypedef match_results<const char*>             cmatch;
5117a984708SDavid Chisnalltypedef match_results<const wchar_t*>          wcmatch;
5127a984708SDavid Chisnalltypedef match_results<string::const_iterator>  smatch;
5137a984708SDavid Chisnalltypedef match_results<wstring::const_iterator> wsmatch;
5147a984708SDavid Chisnall
5157a984708SDavid Chisnalltemplate <class BidirectionalIterator, class Allocator>
5167a984708SDavid Chisnall    bool
5177a984708SDavid Chisnall    operator==(const match_results<BidirectionalIterator, Allocator>& m1,
5187a984708SDavid Chisnall               const match_results<BidirectionalIterator, Allocator>& m2);
5197a984708SDavid Chisnall
5207a984708SDavid Chisnalltemplate <class BidirectionalIterator, class Allocator>
5217a984708SDavid Chisnall    bool
5227a984708SDavid Chisnall    operator!=(const match_results<BidirectionalIterator, Allocator>& m1,
5237a984708SDavid Chisnall               const match_results<BidirectionalIterator, Allocator>& m2);
5247a984708SDavid Chisnall
5257a984708SDavid Chisnalltemplate <class BidirectionalIterator, class Allocator>
5267a984708SDavid Chisnall    void
5277a984708SDavid Chisnall    swap(match_results<BidirectionalIterator, Allocator>& m1,
5287a984708SDavid Chisnall         match_results<BidirectionalIterator, Allocator>& m2);
5297a984708SDavid Chisnall
5307a984708SDavid Chisnalltemplate <class BidirectionalIterator, class Allocator, class charT, class traits>
5317a984708SDavid Chisnall    bool
5327a984708SDavid Chisnall    regex_match(BidirectionalIterator first, BidirectionalIterator last,
5337a984708SDavid Chisnall                match_results<BidirectionalIterator, Allocator>& m,
5347a984708SDavid Chisnall                const basic_regex<charT, traits>& e,
5357a984708SDavid Chisnall                regex_constants::match_flag_type flags = regex_constants::match_default);
5367a984708SDavid Chisnall
5377a984708SDavid Chisnalltemplate <class BidirectionalIterator, class charT, class traits>
5387a984708SDavid Chisnall    bool
5397a984708SDavid Chisnall    regex_match(BidirectionalIterator first, BidirectionalIterator last,
5407a984708SDavid Chisnall                const basic_regex<charT, traits>& e,
5417a984708SDavid Chisnall                regex_constants::match_flag_type flags = regex_constants::match_default);
5427a984708SDavid Chisnall
5437a984708SDavid Chisnalltemplate <class charT, class Allocator, class traits>
5447a984708SDavid Chisnall    bool
5457a984708SDavid Chisnall    regex_match(const charT* str, match_results<const charT*, Allocator>& m,
5467a984708SDavid Chisnall                const basic_regex<charT, traits>& e,
5477a984708SDavid Chisnall                regex_constants::match_flag_type flags = regex_constants::match_default);
5487a984708SDavid Chisnall
5497a984708SDavid Chisnalltemplate <class ST, class SA, class Allocator, class charT, class traits>
5507a984708SDavid Chisnall    bool
5517a984708SDavid Chisnall    regex_match(const basic_string<charT, ST, SA>& s,
5527a984708SDavid Chisnall                match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m,
5537a984708SDavid Chisnall                const basic_regex<charT, traits>& e,
5547a984708SDavid Chisnall                regex_constants::match_flag_type flags = regex_constants::match_default);
5557a984708SDavid Chisnall
556d72607e9SDimitry Andrictemplate <class ST, class SA, class Allocator, class charT, class traits>
557d72607e9SDimitry Andric    bool
558d72607e9SDimitry Andric    regex_match(const basic_string<charT, ST, SA>&& s,
559d72607e9SDimitry Andric                match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m,
560d72607e9SDimitry Andric                const basic_regex<charT, traits>& e,
561d72607e9SDimitry Andric                regex_constants::match_flag_type flags = regex_constants::match_default) = delete; // C++14
562d72607e9SDimitry Andric
5637a984708SDavid Chisnalltemplate <class charT, class traits>
5647a984708SDavid Chisnall    bool
5657a984708SDavid Chisnall    regex_match(const charT* str, const basic_regex<charT, traits>& e,
5667a984708SDavid Chisnall                regex_constants::match_flag_type flags = regex_constants::match_default);
5677a984708SDavid Chisnall
5687a984708SDavid Chisnalltemplate <class ST, class SA, class charT, class traits>
5697a984708SDavid Chisnall    bool
5707a984708SDavid Chisnall    regex_match(const basic_string<charT, ST, SA>& s,
5717a984708SDavid Chisnall                const basic_regex<charT, traits>& e,
5727a984708SDavid Chisnall                regex_constants::match_flag_type flags = regex_constants::match_default);
5737a984708SDavid Chisnall
5747a984708SDavid Chisnalltemplate <class BidirectionalIterator, class Allocator, class charT, class traits>
5757a984708SDavid Chisnall    bool
5767a984708SDavid Chisnall    regex_search(BidirectionalIterator first, BidirectionalIterator last,
5777a984708SDavid Chisnall                 match_results<BidirectionalIterator, Allocator>& m,
5787a984708SDavid Chisnall                 const basic_regex<charT, traits>& e,
5797a984708SDavid Chisnall                 regex_constants::match_flag_type flags = regex_constants::match_default);
5807a984708SDavid Chisnall
5817a984708SDavid Chisnalltemplate <class BidirectionalIterator, class charT, class traits>
5827a984708SDavid Chisnall    bool
5837a984708SDavid Chisnall    regex_search(BidirectionalIterator first, BidirectionalIterator last,
5847a984708SDavid Chisnall                 const basic_regex<charT, traits>& e,
5857a984708SDavid Chisnall                 regex_constants::match_flag_type flags = regex_constants::match_default);
5867a984708SDavid Chisnall
5877a984708SDavid Chisnalltemplate <class charT, class Allocator, class traits>
5887a984708SDavid Chisnall    bool
5897a984708SDavid Chisnall    regex_search(const charT* str, match_results<const charT*, Allocator>& m,
5907a984708SDavid Chisnall                 const basic_regex<charT, traits>& e,
5917a984708SDavid Chisnall                 regex_constants::match_flag_type flags = regex_constants::match_default);
5927a984708SDavid Chisnall
5937a984708SDavid Chisnalltemplate <class charT, class traits>
5947a984708SDavid Chisnall    bool
5957a984708SDavid Chisnall    regex_search(const charT* str, const basic_regex<charT, traits>& e,
5967a984708SDavid Chisnall                 regex_constants::match_flag_type flags = regex_constants::match_default);
5977a984708SDavid Chisnall
5987a984708SDavid Chisnalltemplate <class ST, class SA, class charT, class traits>
5997a984708SDavid Chisnall    bool
6007a984708SDavid Chisnall    regex_search(const basic_string<charT, ST, SA>& s,
6017a984708SDavid Chisnall                 const basic_regex<charT, traits>& e,
6027a984708SDavid Chisnall                 regex_constants::match_flag_type flags = regex_constants::match_default);
6037a984708SDavid Chisnall
6047a984708SDavid Chisnalltemplate <class ST, class SA, class Allocator, class charT, class traits>
6057a984708SDavid Chisnall    bool
6067a984708SDavid Chisnall    regex_search(const basic_string<charT, ST, SA>& s,
6077a984708SDavid Chisnall                 match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m,
6087a984708SDavid Chisnall                 const basic_regex<charT, traits>& e,
6097a984708SDavid Chisnall                 regex_constants::match_flag_type flags = regex_constants::match_default);
6107a984708SDavid Chisnall
611d72607e9SDimitry Andrictemplate <class ST, class SA, class Allocator, class charT, class traits>
612d72607e9SDimitry Andric    bool
613d72607e9SDimitry Andric    regex_search(const basic_string<charT, ST, SA>&& s,
614d72607e9SDimitry Andric                 match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m,
615d72607e9SDimitry Andric                 const basic_regex<charT, traits>& e,
616d72607e9SDimitry Andric                 regex_constants::match_flag_type flags = regex_constants::match_default) = delete; // C++14
617d72607e9SDimitry Andric
6187a984708SDavid Chisnalltemplate <class OutputIterator, class BidirectionalIterator,
6197a984708SDavid Chisnall          class traits, class charT, class ST, class SA>
6207a984708SDavid Chisnall    OutputIterator
6217a984708SDavid Chisnall    regex_replace(OutputIterator out,
6227a984708SDavid Chisnall                  BidirectionalIterator first, BidirectionalIterator last,
6237a984708SDavid Chisnall                  const basic_regex<charT, traits>& e,
6247a984708SDavid Chisnall                  const basic_string<charT, ST, SA>& fmt,
6257a984708SDavid Chisnall                  regex_constants::match_flag_type flags = regex_constants::match_default);
6267a984708SDavid Chisnall
6277a984708SDavid Chisnalltemplate <class OutputIterator, class BidirectionalIterator,
6287a984708SDavid Chisnall          class traits, class charT>
6297a984708SDavid Chisnall    OutputIterator
6307a984708SDavid Chisnall    regex_replace(OutputIterator out,
6317a984708SDavid Chisnall                  BidirectionalIterator first, BidirectionalIterator last,
6327a984708SDavid Chisnall                  const basic_regex<charT, traits>& e, const charT* fmt,
6337a984708SDavid Chisnall                  regex_constants::match_flag_type flags = regex_constants::match_default);
6347a984708SDavid Chisnall
6357a984708SDavid Chisnalltemplate <class traits, class charT, class ST, class SA, class FST, class FSA>>
6367a984708SDavid Chisnall    basic_string<charT, ST, SA>
6377a984708SDavid Chisnall    regex_replace(const basic_string<charT, ST, SA>& s,
6387a984708SDavid Chisnall                  const basic_regex<charT, traits>& e,
6397a984708SDavid Chisnall                  const basic_string<charT, FST, FSA>& fmt,
6407a984708SDavid Chisnall                  regex_constants::match_flag_type flags = regex_constants::match_default);
6417a984708SDavid Chisnall
6427a984708SDavid Chisnalltemplate <class traits, class charT, class ST, class SA>
6437a984708SDavid Chisnall    basic_string<charT, ST, SA>
6447a984708SDavid Chisnall    regex_replace(const basic_string<charT, ST, SA>& s,
6457a984708SDavid Chisnall                  const basic_regex<charT, traits>& e, const charT* fmt,
6467a984708SDavid Chisnall                  regex_constants::match_flag_type flags = regex_constants::match_default);
6477a984708SDavid Chisnall
6487a984708SDavid Chisnalltemplate <class traits, class charT, class ST, class SA>
6497a984708SDavid Chisnall    basic_string<charT>
6507a984708SDavid Chisnall    regex_replace(const charT* s,
6517a984708SDavid Chisnall                  const basic_regex<charT, traits>& e,
6527a984708SDavid Chisnall                  const basic_string<charT, ST, SA>& fmt,
6537a984708SDavid Chisnall                  regex_constants::match_flag_type flags = regex_constants::match_default);
6547a984708SDavid Chisnall
6557a984708SDavid Chisnalltemplate <class traits, class charT>
6567a984708SDavid Chisnall    basic_string<charT>
6577a984708SDavid Chisnall    regex_replace(const charT* s,
6587a984708SDavid Chisnall                  const basic_regex<charT, traits>& e,
6597a984708SDavid Chisnall                  const charT* fmt,
6607a984708SDavid Chisnall                  regex_constants::match_flag_type flags = regex_constants::match_default);
6617a984708SDavid Chisnall
6627a984708SDavid Chisnalltemplate <class BidirectionalIterator,
6637a984708SDavid Chisnall          class charT = typename iterator_traits< BidirectionalIterator>::value_type,
6647a984708SDavid Chisnall          class traits = regex_traits<charT>>
6657a984708SDavid Chisnallclass regex_iterator
6667a984708SDavid Chisnall{
6677a984708SDavid Chisnallpublic:
6687a984708SDavid Chisnall    typedef basic_regex<charT, traits>           regex_type;
6697a984708SDavid Chisnall    typedef match_results<BidirectionalIterator> value_type;
6707a984708SDavid Chisnall    typedef ptrdiff_t                            difference_type;
6717a984708SDavid Chisnall    typedef const value_type*                    pointer;
6727a984708SDavid Chisnall    typedef const value_type&                    reference;
6737a984708SDavid Chisnall    typedef forward_iterator_tag                 iterator_category;
6747a984708SDavid Chisnall
6757a984708SDavid Chisnall    regex_iterator();
6767a984708SDavid Chisnall    regex_iterator(BidirectionalIterator a, BidirectionalIterator b,
6777a984708SDavid Chisnall                   const regex_type& re,
6787a984708SDavid Chisnall                   regex_constants::match_flag_type m = regex_constants::match_default);
679d72607e9SDimitry Andric    regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
680d72607e9SDimitry Andric                   const regex_type&& __re,
681d72607e9SDimitry Andric                   regex_constants::match_flag_type __m
682d72607e9SDimitry Andric                                     = regex_constants::match_default) = delete; // C++14
6837a984708SDavid Chisnall    regex_iterator(const regex_iterator&);
6847a984708SDavid Chisnall    regex_iterator& operator=(const regex_iterator&);
6857a984708SDavid Chisnall
6867a984708SDavid Chisnall    bool operator==(const regex_iterator&) const;
6877a984708SDavid Chisnall    bool operator!=(const regex_iterator&) const;
6887a984708SDavid Chisnall
6897a984708SDavid Chisnall    const value_type& operator*() const;
6907a984708SDavid Chisnall    const value_type* operator->() const;
6917a984708SDavid Chisnall
6927a984708SDavid Chisnall    regex_iterator& operator++();
6937a984708SDavid Chisnall    regex_iterator operator++(int);
6947a984708SDavid Chisnall};
6957a984708SDavid Chisnall
6967a984708SDavid Chisnalltypedef regex_iterator<const char*>             cregex_iterator;
6977a984708SDavid Chisnalltypedef regex_iterator<const wchar_t*>          wcregex_iterator;
6987a984708SDavid Chisnalltypedef regex_iterator<string::const_iterator>  sregex_iterator;
6997a984708SDavid Chisnalltypedef regex_iterator<wstring::const_iterator> wsregex_iterator;
7007a984708SDavid Chisnall
7017a984708SDavid Chisnalltemplate <class BidirectionalIterator,
7027a984708SDavid Chisnall          class charT = typename iterator_traits< BidirectionalIterator>::value_type,
7037a984708SDavid Chisnall          class traits = regex_traits<charT>>
7047a984708SDavid Chisnallclass regex_token_iterator
7057a984708SDavid Chisnall{
7067a984708SDavid Chisnallpublic:
7077a984708SDavid Chisnall    typedef basic_regex<charT, traits>       regex_type;
7087a984708SDavid Chisnall    typedef sub_match<BidirectionalIterator> value_type;
7097a984708SDavid Chisnall    typedef ptrdiff_t                        difference_type;
7107a984708SDavid Chisnall    typedef const value_type*                pointer;
7117a984708SDavid Chisnall    typedef const value_type&                reference;
7127a984708SDavid Chisnall    typedef forward_iterator_tag             iterator_category;
7137a984708SDavid Chisnall
7147a984708SDavid Chisnall    regex_token_iterator();
7157a984708SDavid Chisnall    regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
7167a984708SDavid Chisnall                         const regex_type& re, int submatch = 0,
7177a984708SDavid Chisnall                         regex_constants::match_flag_type m = regex_constants::match_default);
7187a984708SDavid Chisnall    regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
719d72607e9SDimitry Andric                         const regex_type&& re, int submatch = 0,
720d72607e9SDimitry Andric                         regex_constants::match_flag_type m = regex_constants::match_default) = delete; // C++14
721d72607e9SDimitry Andric    regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
7227a984708SDavid Chisnall                         const regex_type& re, const vector<int>& submatches,
7237a984708SDavid Chisnall                         regex_constants::match_flag_type m = regex_constants::match_default);
7247a984708SDavid Chisnall    regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
725d72607e9SDimitry Andric                         const regex_type&& re, const vector<int>& submatches,
726d72607e9SDimitry Andric                         regex_constants::match_flag_type m = regex_constants::match_default) = delete; // C++14
727d72607e9SDimitry Andric    regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
7287a984708SDavid Chisnall                         const regex_type& re, initializer_list<int> submatches,
7297a984708SDavid Chisnall                         regex_constants::match_flag_type m = regex_constants::match_default);
730d72607e9SDimitry Andric    regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
731d72607e9SDimitry Andric                         const regex_type&& re, initializer_list<int> submatches,
732d72607e9SDimitry Andric                         regex_constants::match_flag_type m = regex_constants::match_default) = delete; // C++14
7337a984708SDavid Chisnall    template <size_t N>
7347a984708SDavid Chisnall        regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
7357a984708SDavid Chisnall                             const regex_type& re, const int (&submatches)[N],
7367a984708SDavid Chisnall                             regex_constants::match_flag_type m = regex_constants::match_default);
737d72607e9SDimitry Andric    template <size_t N>
738d72607e9SDimitry Andric        regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
739d72607e9SDimitry Andric                             const regex_type& re, const int (&submatches)[N],
740d72607e9SDimitry Andric                             regex_constants::match_flag_type m = regex_constants::match_default) = delete // C++14;
7417a984708SDavid Chisnall    regex_token_iterator(const regex_token_iterator&);
7427a984708SDavid Chisnall    regex_token_iterator& operator=(const regex_token_iterator&);
7437a984708SDavid Chisnall
7447a984708SDavid Chisnall    bool operator==(const regex_token_iterator&) const;
7457a984708SDavid Chisnall    bool operator!=(const regex_token_iterator&) const;
7467a984708SDavid Chisnall
7477a984708SDavid Chisnall    const value_type& operator*() const;
7487a984708SDavid Chisnall    const value_type* operator->() const;
7497a984708SDavid Chisnall
7507a984708SDavid Chisnall    regex_token_iterator& operator++();
7517a984708SDavid Chisnall    regex_token_iterator operator++(int);
7527a984708SDavid Chisnall};
7537a984708SDavid Chisnall
7547a984708SDavid Chisnalltypedef regex_token_iterator<const char*>             cregex_token_iterator;
7557a984708SDavid Chisnalltypedef regex_token_iterator<const wchar_t*>          wcregex_token_iterator;
7567a984708SDavid Chisnalltypedef regex_token_iterator<string::const_iterator>  sregex_token_iterator;
7577a984708SDavid Chisnalltypedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator;
7587a984708SDavid Chisnall
7597a984708SDavid Chisnall} // std
7607a984708SDavid Chisnall*/
7617a984708SDavid Chisnall
7627a984708SDavid Chisnall#include <__config>
7637a984708SDavid Chisnall#include <stdexcept>
7647a984708SDavid Chisnall#include <__locale>
7657a984708SDavid Chisnall#include <initializer_list>
7667a984708SDavid Chisnall#include <utility>
7677a984708SDavid Chisnall#include <iterator>
7687a984708SDavid Chisnall#include <string>
7697a984708SDavid Chisnall#include <memory>
7707a984708SDavid Chisnall#include <vector>
7717a984708SDavid Chisnall#include <deque>
772*b5893f02SDimitry Andric#include <version>
7737a984708SDavid Chisnall
7747a984708SDavid Chisnall#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
7757a984708SDavid Chisnall#pragma GCC system_header
7767a984708SDavid Chisnall#endif
7777a984708SDavid Chisnall
778f9448bf3SDimitry Andric_LIBCPP_PUSH_MACROS
779f9448bf3SDimitry Andric#include <__undef_macros>
780f9448bf3SDimitry Andric
781f9448bf3SDimitry Andric
782b2c7081bSDimitry Andric#define _LIBCPP_REGEX_COMPLEXITY_FACTOR 4096
783b2c7081bSDimitry Andric
7847a984708SDavid Chisnall_LIBCPP_BEGIN_NAMESPACE_STD
7857a984708SDavid Chisnall
7867a984708SDavid Chisnallnamespace regex_constants
7877a984708SDavid Chisnall{
7887a984708SDavid Chisnall
7897a984708SDavid Chisnall// syntax_option_type
7907a984708SDavid Chisnall
7917a984708SDavid Chisnallenum syntax_option_type
7927a984708SDavid Chisnall{
7937a984708SDavid Chisnall    icase      = 1 << 0,
7947a984708SDavid Chisnall    nosubs     = 1 << 1,
7957a984708SDavid Chisnall    optimize   = 1 << 2,
7967a984708SDavid Chisnall    collate    = 1 << 3,
7977a984708SDavid Chisnall    ECMAScript = 0,
7987a984708SDavid Chisnall    basic      = 1 << 4,
7997a984708SDavid Chisnall    extended   = 1 << 5,
8007a984708SDavid Chisnall    awk        = 1 << 6,
8017a984708SDavid Chisnall    grep       = 1 << 7,
8027a984708SDavid Chisnall    egrep      = 1 << 8
8037a984708SDavid Chisnall};
8047a984708SDavid Chisnall
8057a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
806936e9439SDimitry Andric_LIBCPP_CONSTEXPR
8077a984708SDavid Chisnallsyntax_option_type
8087a984708SDavid Chisnalloperator~(syntax_option_type __x)
8097a984708SDavid Chisnall{
8101bf9f7c1SDimitry Andric    return syntax_option_type(~int(__x) & 0x1FF);
8117a984708SDavid Chisnall}
8127a984708SDavid Chisnall
8137a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
814936e9439SDimitry Andric_LIBCPP_CONSTEXPR
8157a984708SDavid Chisnallsyntax_option_type
8167a984708SDavid Chisnalloperator&(syntax_option_type __x, syntax_option_type __y)
8177a984708SDavid Chisnall{
8187a984708SDavid Chisnall    return syntax_option_type(int(__x) & int(__y));
8197a984708SDavid Chisnall}
8207a984708SDavid Chisnall
8217a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
822936e9439SDimitry Andric_LIBCPP_CONSTEXPR
8237a984708SDavid Chisnallsyntax_option_type
8247a984708SDavid Chisnalloperator|(syntax_option_type __x, syntax_option_type __y)
8257a984708SDavid Chisnall{
8267a984708SDavid Chisnall    return syntax_option_type(int(__x) | int(__y));
8277a984708SDavid Chisnall}
8287a984708SDavid Chisnall
8297a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
830936e9439SDimitry Andric_LIBCPP_CONSTEXPR
8317a984708SDavid Chisnallsyntax_option_type
8327a984708SDavid Chisnalloperator^(syntax_option_type __x, syntax_option_type __y)
8337a984708SDavid Chisnall{
8347a984708SDavid Chisnall    return syntax_option_type(int(__x) ^ int(__y));
8357a984708SDavid Chisnall}
8367a984708SDavid Chisnall
8377a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
8387a984708SDavid Chisnallsyntax_option_type&
8397a984708SDavid Chisnalloperator&=(syntax_option_type& __x, syntax_option_type __y)
8407a984708SDavid Chisnall{
8417a984708SDavid Chisnall    __x = __x & __y;
8427a984708SDavid Chisnall    return __x;
8437a984708SDavid Chisnall}
8447a984708SDavid Chisnall
8457a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
8467a984708SDavid Chisnallsyntax_option_type&
8477a984708SDavid Chisnalloperator|=(syntax_option_type& __x, syntax_option_type __y)
8487a984708SDavid Chisnall{
8497a984708SDavid Chisnall    __x = __x | __y;
8507a984708SDavid Chisnall    return __x;
8517a984708SDavid Chisnall}
8527a984708SDavid Chisnall
8537a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
8547a984708SDavid Chisnallsyntax_option_type&
8557a984708SDavid Chisnalloperator^=(syntax_option_type& __x, syntax_option_type __y)
8567a984708SDavid Chisnall{
8577a984708SDavid Chisnall    __x = __x ^ __y;
8587a984708SDavid Chisnall    return __x;
8597a984708SDavid Chisnall}
8607a984708SDavid Chisnall
8617a984708SDavid Chisnall// match_flag_type
8627a984708SDavid Chisnall
8637a984708SDavid Chisnallenum match_flag_type
8647a984708SDavid Chisnall{
8657a984708SDavid Chisnall    match_default     = 0,
8667a984708SDavid Chisnall    match_not_bol     = 1 << 0,
8677a984708SDavid Chisnall    match_not_eol     = 1 << 1,
8687a984708SDavid Chisnall    match_not_bow     = 1 << 2,
8697a984708SDavid Chisnall    match_not_eow     = 1 << 3,
8707a984708SDavid Chisnall    match_any         = 1 << 4,
8717a984708SDavid Chisnall    match_not_null    = 1 << 5,
8727a984708SDavid Chisnall    match_continuous  = 1 << 6,
8737a984708SDavid Chisnall    match_prev_avail  = 1 << 7,
8747a984708SDavid Chisnall    format_default    = 0,
8757a984708SDavid Chisnall    format_sed        = 1 << 8,
8767a984708SDavid Chisnall    format_no_copy    = 1 << 9,
8777a984708SDavid Chisnall    format_first_only = 1 << 10,
878aed8d94eSDimitry Andric    __no_update_pos   = 1 << 11,
879aed8d94eSDimitry Andric    __full_match      = 1 << 12
8807a984708SDavid Chisnall};
8817a984708SDavid Chisnall
8827a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
883936e9439SDimitry Andric_LIBCPP_CONSTEXPR
8847a984708SDavid Chisnallmatch_flag_type
8857a984708SDavid Chisnalloperator~(match_flag_type __x)
8867a984708SDavid Chisnall{
8871bf9f7c1SDimitry Andric    return match_flag_type(~int(__x) & 0x0FFF);
8887a984708SDavid Chisnall}
8897a984708SDavid Chisnall
8907a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
891936e9439SDimitry Andric_LIBCPP_CONSTEXPR
8927a984708SDavid Chisnallmatch_flag_type
8937a984708SDavid Chisnalloperator&(match_flag_type __x, match_flag_type __y)
8947a984708SDavid Chisnall{
8957a984708SDavid Chisnall    return match_flag_type(int(__x) & int(__y));
8967a984708SDavid Chisnall}
8977a984708SDavid Chisnall
8987a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
899936e9439SDimitry Andric_LIBCPP_CONSTEXPR
9007a984708SDavid Chisnallmatch_flag_type
9017a984708SDavid Chisnalloperator|(match_flag_type __x, match_flag_type __y)
9027a984708SDavid Chisnall{
9037a984708SDavid Chisnall    return match_flag_type(int(__x) | int(__y));
9047a984708SDavid Chisnall}
9057a984708SDavid Chisnall
9067a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
907936e9439SDimitry Andric_LIBCPP_CONSTEXPR
9087a984708SDavid Chisnallmatch_flag_type
9097a984708SDavid Chisnalloperator^(match_flag_type __x, match_flag_type __y)
9107a984708SDavid Chisnall{
9117a984708SDavid Chisnall    return match_flag_type(int(__x) ^ int(__y));
9127a984708SDavid Chisnall}
9137a984708SDavid Chisnall
9147a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
9157a984708SDavid Chisnallmatch_flag_type&
9167a984708SDavid Chisnalloperator&=(match_flag_type& __x, match_flag_type __y)
9177a984708SDavid Chisnall{
9187a984708SDavid Chisnall    __x = __x & __y;
9197a984708SDavid Chisnall    return __x;
9207a984708SDavid Chisnall}
9217a984708SDavid Chisnall
9227a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
9237a984708SDavid Chisnallmatch_flag_type&
9247a984708SDavid Chisnalloperator|=(match_flag_type& __x, match_flag_type __y)
9257a984708SDavid Chisnall{
9267a984708SDavid Chisnall    __x = __x | __y;
9277a984708SDavid Chisnall    return __x;
9287a984708SDavid Chisnall}
9297a984708SDavid Chisnall
9307a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
9317a984708SDavid Chisnallmatch_flag_type&
9327a984708SDavid Chisnalloperator^=(match_flag_type& __x, match_flag_type __y)
9337a984708SDavid Chisnall{
9347a984708SDavid Chisnall    __x = __x ^ __y;
9357a984708SDavid Chisnall    return __x;
9367a984708SDavid Chisnall}
9377a984708SDavid Chisnall
9387a984708SDavid Chisnallenum error_type
9397a984708SDavid Chisnall{
9407a984708SDavid Chisnall    error_collate = 1,
9417a984708SDavid Chisnall    error_ctype,
9427a984708SDavid Chisnall    error_escape,
9437a984708SDavid Chisnall    error_backref,
9447a984708SDavid Chisnall    error_brack,
9457a984708SDavid Chisnall    error_paren,
9467a984708SDavid Chisnall    error_brace,
9477a984708SDavid Chisnall    error_badbrace,
9487a984708SDavid Chisnall    error_range,
9497a984708SDavid Chisnall    error_space,
9507a984708SDavid Chisnall    error_badrepeat,
9517a984708SDavid Chisnall    error_complexity,
9527a984708SDavid Chisnall    error_stack,
9537a984708SDavid Chisnall    __re_err_grammar,
9547a984708SDavid Chisnall    __re_err_empty,
9557a984708SDavid Chisnall    __re_err_unknown
9567a984708SDavid Chisnall};
9577a984708SDavid Chisnall
9587a984708SDavid Chisnall}  // regex_constants
9597a984708SDavid Chisnall
9607a984708SDavid Chisnallclass _LIBCPP_EXCEPTION_ABI regex_error
9617a984708SDavid Chisnall    : public runtime_error
9627a984708SDavid Chisnall{
9637a984708SDavid Chisnall    regex_constants::error_type __code_;
9647a984708SDavid Chisnallpublic:
9657a984708SDavid Chisnall    explicit regex_error(regex_constants::error_type __ecode);
9667a984708SDavid Chisnall    virtual ~regex_error() throw();
9677a984708SDavid Chisnall     _LIBCPP_INLINE_VISIBILITY
9687a984708SDavid Chisnall    regex_constants::error_type code() const {return __code_;}
9697a984708SDavid Chisnall};
9707a984708SDavid Chisnall
9719729cf09SDimitry Andrictemplate <regex_constants::error_type _Ev>
9724ba319b5SDimitry Andric_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
9739729cf09SDimitry Andricvoid __throw_regex_error()
9749729cf09SDimitry Andric{
9759729cf09SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS
9769729cf09SDimitry Andric    throw regex_error(_Ev);
9779729cf09SDimitry Andric#else
978aed8d94eSDimitry Andric    _VSTD::abort();
9799729cf09SDimitry Andric#endif
9809729cf09SDimitry Andric}
9819729cf09SDimitry Andric
9827a984708SDavid Chisnalltemplate <class _CharT>
983aed8d94eSDimitry Andricstruct _LIBCPP_TEMPLATE_VIS regex_traits
9847a984708SDavid Chisnall{
9857a984708SDavid Chisnallpublic:
9867a984708SDavid Chisnall    typedef _CharT                  char_type;
9877a984708SDavid Chisnall    typedef basic_string<char_type> string_type;
9887a984708SDavid Chisnall    typedef locale                  locale_type;
9897a984708SDavid Chisnall    typedef ctype_base::mask        char_class_type;
9907a984708SDavid Chisnall
9919729cf09SDimitry Andric#if defined(__mips__) && defined(__GLIBC__)
9929729cf09SDimitry Andric    static const char_class_type __regex_word = static_cast<char_class_type>(_ISbit(15));
993*b5893f02SDimitry Andric#elif defined(__NetBSD__)
994*b5893f02SDimitry Andric    // NetBSD defines classes up to 0x2000
995*b5893f02SDimitry Andric    // see sys/ctype_bits.h, _CTYPE_Q
996*b5893f02SDimitry Andric    static const char_class_type __regex_word = 0x8000;
9979729cf09SDimitry Andric#else
9987a984708SDavid Chisnall    static const char_class_type __regex_word = 0x80;
9999729cf09SDimitry Andric#endif
10009729cf09SDimitry Andric
10017a984708SDavid Chisnallprivate:
10027a984708SDavid Chisnall    locale __loc_;
10037a984708SDavid Chisnall    const ctype<char_type>* __ct_;
10047a984708SDavid Chisnall    const collate<char_type>* __col_;
10057a984708SDavid Chisnall
10067a984708SDavid Chisnallpublic:
10077a984708SDavid Chisnall    regex_traits();
10087a984708SDavid Chisnall
10097a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
10107a984708SDavid Chisnall    static size_t length(const char_type* __p)
10117a984708SDavid Chisnall        {return char_traits<char_type>::length(__p);}
10127a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
10137a984708SDavid Chisnall    char_type translate(char_type __c) const {return __c;}
10147a984708SDavid Chisnall    char_type translate_nocase(char_type __c) const;
10157a984708SDavid Chisnall    template <class _ForwardIterator>
10167a984708SDavid Chisnall        string_type
10177a984708SDavid Chisnall        transform(_ForwardIterator __f, _ForwardIterator __l) const;
10187a984708SDavid Chisnall    template <class _ForwardIterator>
10197a984708SDavid Chisnall        _LIBCPP_INLINE_VISIBILITY
10207a984708SDavid Chisnall        string_type
10217a984708SDavid Chisnall        transform_primary( _ForwardIterator __f, _ForwardIterator __l) const
10227a984708SDavid Chisnall            {return __transform_primary(__f, __l, char_type());}
10237a984708SDavid Chisnall    template <class _ForwardIterator>
10247a984708SDavid Chisnall        _LIBCPP_INLINE_VISIBILITY
10257a984708SDavid Chisnall        string_type
10267a984708SDavid Chisnall        lookup_collatename(_ForwardIterator __f, _ForwardIterator __l) const
10277a984708SDavid Chisnall            {return __lookup_collatename(__f, __l, char_type());}
10287a984708SDavid Chisnall    template <class _ForwardIterator>
10297a984708SDavid Chisnall        _LIBCPP_INLINE_VISIBILITY
10307a984708SDavid Chisnall        char_class_type
10317a984708SDavid Chisnall        lookup_classname(_ForwardIterator __f, _ForwardIterator __l,
10327a984708SDavid Chisnall                         bool __icase = false) const
10337a984708SDavid Chisnall            {return __lookup_classname(__f, __l, __icase, char_type());}
10347a984708SDavid Chisnall    bool isctype(char_type __c, char_class_type __m) const;
10357a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
10367a984708SDavid Chisnall    int value(char_type __ch, int __radix) const
10374f7ab58eSDimitry Andric        {return __regex_traits_value(__ch, __radix);}
10387a984708SDavid Chisnall    locale_type imbue(locale_type __l);
10397a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
10407a984708SDavid Chisnall    locale_type getloc()const {return __loc_;}
10417a984708SDavid Chisnall
10427a984708SDavid Chisnallprivate:
10437a984708SDavid Chisnall    void __init();
10447a984708SDavid Chisnall
10457a984708SDavid Chisnall    template <class _ForwardIterator>
10467a984708SDavid Chisnall        string_type
10477a984708SDavid Chisnall        __transform_primary(_ForwardIterator __f, _ForwardIterator __l, char) const;
10487a984708SDavid Chisnall    template <class _ForwardIterator>
10497a984708SDavid Chisnall        string_type
10507a984708SDavid Chisnall        __transform_primary(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const;
10517a984708SDavid Chisnall
10527a984708SDavid Chisnall    template <class _ForwardIterator>
10537a984708SDavid Chisnall        string_type
10547a984708SDavid Chisnall        __lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, char) const;
10557a984708SDavid Chisnall    template <class _ForwardIterator>
10567a984708SDavid Chisnall        string_type
10577a984708SDavid Chisnall        __lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const;
10587a984708SDavid Chisnall
10597a984708SDavid Chisnall    template <class _ForwardIterator>
10607a984708SDavid Chisnall        char_class_type
10617a984708SDavid Chisnall        __lookup_classname(_ForwardIterator __f, _ForwardIterator __l,
10627a984708SDavid Chisnall                           bool __icase, char) const;
10637a984708SDavid Chisnall    template <class _ForwardIterator>
10647a984708SDavid Chisnall        char_class_type
10657a984708SDavid Chisnall        __lookup_classname(_ForwardIterator __f, _ForwardIterator __l,
10667a984708SDavid Chisnall                           bool __icase, wchar_t) const;
10677a984708SDavid Chisnall
10684f7ab58eSDimitry Andric    static int __regex_traits_value(unsigned char __ch, int __radix);
10697a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
10704f7ab58eSDimitry Andric    int __regex_traits_value(char __ch, int __radix) const
10714f7ab58eSDimitry Andric        {return __regex_traits_value(static_cast<unsigned char>(__ch), __radix);}
10729729cf09SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
10734f7ab58eSDimitry Andric    int __regex_traits_value(wchar_t __ch, int __radix) const;
10747a984708SDavid Chisnall};
10757a984708SDavid Chisnall
10767a984708SDavid Chisnalltemplate <class _CharT>
10771bf9f7c1SDimitry Andricconst typename regex_traits<_CharT>::char_class_type
10781bf9f7c1SDimitry Andricregex_traits<_CharT>::__regex_word;
10791bf9f7c1SDimitry Andric
10801bf9f7c1SDimitry Andrictemplate <class _CharT>
10817a984708SDavid Chisnallregex_traits<_CharT>::regex_traits()
10827a984708SDavid Chisnall{
10837a984708SDavid Chisnall    __init();
10847a984708SDavid Chisnall}
10857a984708SDavid Chisnall
10867a984708SDavid Chisnalltemplate <class _CharT>
10877a984708SDavid Chisnalltypename regex_traits<_CharT>::char_type
10887a984708SDavid Chisnallregex_traits<_CharT>::translate_nocase(char_type __c) const
10897a984708SDavid Chisnall{
10907a984708SDavid Chisnall    return __ct_->tolower(__c);
10917a984708SDavid Chisnall}
10927a984708SDavid Chisnall
10937a984708SDavid Chisnalltemplate <class _CharT>
10947a984708SDavid Chisnalltemplate <class _ForwardIterator>
10957a984708SDavid Chisnalltypename regex_traits<_CharT>::string_type
10967a984708SDavid Chisnallregex_traits<_CharT>::transform(_ForwardIterator __f, _ForwardIterator __l) const
10977a984708SDavid Chisnall{
10987a984708SDavid Chisnall    string_type __s(__f, __l);
10997a984708SDavid Chisnall    return __col_->transform(__s.data(), __s.data() + __s.size());
11007a984708SDavid Chisnall}
11017a984708SDavid Chisnall
11027a984708SDavid Chisnalltemplate <class _CharT>
11037a984708SDavid Chisnallvoid
11047a984708SDavid Chisnallregex_traits<_CharT>::__init()
11057a984708SDavid Chisnall{
11067a984708SDavid Chisnall    __ct_ = &use_facet<ctype<char_type> >(__loc_);
11077a984708SDavid Chisnall    __col_ = &use_facet<collate<char_type> >(__loc_);
11087a984708SDavid Chisnall}
11097a984708SDavid Chisnall
11107a984708SDavid Chisnalltemplate <class _CharT>
11117a984708SDavid Chisnalltypename regex_traits<_CharT>::locale_type
11127a984708SDavid Chisnallregex_traits<_CharT>::imbue(locale_type __l)
11137a984708SDavid Chisnall{
11147a984708SDavid Chisnall    locale __r = __loc_;
11157a984708SDavid Chisnall    __loc_ = __l;
11167a984708SDavid Chisnall    __init();
11177a984708SDavid Chisnall    return __r;
11187a984708SDavid Chisnall}
11197a984708SDavid Chisnall
11207a984708SDavid Chisnall// transform_primary is very FreeBSD-specific
11217a984708SDavid Chisnall
11227a984708SDavid Chisnalltemplate <class _CharT>
11237a984708SDavid Chisnalltemplate <class _ForwardIterator>
11247a984708SDavid Chisnalltypename regex_traits<_CharT>::string_type
11257a984708SDavid Chisnallregex_traits<_CharT>::__transform_primary(_ForwardIterator __f,
11267a984708SDavid Chisnall                                          _ForwardIterator __l, char) const
11277a984708SDavid Chisnall{
11287a984708SDavid Chisnall    const string_type __s(__f, __l);
11297a984708SDavid Chisnall    string_type __d = __col_->transform(__s.data(), __s.data() + __s.size());
11307a984708SDavid Chisnall    switch (__d.size())
11317a984708SDavid Chisnall    {
11327a984708SDavid Chisnall    case 1:
11337a984708SDavid Chisnall        break;
11347a984708SDavid Chisnall    case 12:
11357a984708SDavid Chisnall        __d[11] = __d[3];
11367a984708SDavid Chisnall        break;
11377a984708SDavid Chisnall    default:
11387a984708SDavid Chisnall        __d.clear();
11397a984708SDavid Chisnall        break;
11407a984708SDavid Chisnall    }
11417a984708SDavid Chisnall    return __d;
11427a984708SDavid Chisnall}
11437a984708SDavid Chisnall
11447a984708SDavid Chisnalltemplate <class _CharT>
11457a984708SDavid Chisnalltemplate <class _ForwardIterator>
11467a984708SDavid Chisnalltypename regex_traits<_CharT>::string_type
11477a984708SDavid Chisnallregex_traits<_CharT>::__transform_primary(_ForwardIterator __f,
11487a984708SDavid Chisnall                                          _ForwardIterator __l, wchar_t) const
11497a984708SDavid Chisnall{
11507a984708SDavid Chisnall    const string_type __s(__f, __l);
11517a984708SDavid Chisnall    string_type __d = __col_->transform(__s.data(), __s.data() + __s.size());
11527a984708SDavid Chisnall    switch (__d.size())
11537a984708SDavid Chisnall    {
11547a984708SDavid Chisnall    case 1:
11557a984708SDavid Chisnall        break;
11567a984708SDavid Chisnall    case 3:
11577a984708SDavid Chisnall        __d[2] = __d[0];
11587a984708SDavid Chisnall        break;
11597a984708SDavid Chisnall    default:
11607a984708SDavid Chisnall        __d.clear();
11617a984708SDavid Chisnall        break;
11627a984708SDavid Chisnall    }
11637a984708SDavid Chisnall    return __d;
11647a984708SDavid Chisnall}
11657a984708SDavid Chisnall
11667a984708SDavid Chisnall// lookup_collatename is very FreeBSD-specific
11677a984708SDavid Chisnall
11684f7ab58eSDimitry Andric_LIBCPP_FUNC_VIS string __get_collation_name(const char* __s);
11697a984708SDavid Chisnall
11707a984708SDavid Chisnalltemplate <class _CharT>
11717a984708SDavid Chisnalltemplate <class _ForwardIterator>
11727a984708SDavid Chisnalltypename regex_traits<_CharT>::string_type
11737a984708SDavid Chisnallregex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f,
11747a984708SDavid Chisnall                                           _ForwardIterator __l, char) const
11757a984708SDavid Chisnall{
11767a984708SDavid Chisnall    string_type __s(__f, __l);
11777a984708SDavid Chisnall    string_type __r;
11787a984708SDavid Chisnall    if (!__s.empty())
11797a984708SDavid Chisnall    {
11807a984708SDavid Chisnall        __r = __get_collation_name(__s.c_str());
11817a984708SDavid Chisnall        if (__r.empty() && __s.size() <= 2)
11827a984708SDavid Chisnall        {
11837a984708SDavid Chisnall            __r = __col_->transform(__s.data(), __s.data() + __s.size());
11847a984708SDavid Chisnall            if (__r.size() == 1 || __r.size() == 12)
11857a984708SDavid Chisnall                __r = __s;
11867a984708SDavid Chisnall            else
11877a984708SDavid Chisnall                __r.clear();
11887a984708SDavid Chisnall        }
11897a984708SDavid Chisnall    }
11907a984708SDavid Chisnall    return __r;
11917a984708SDavid Chisnall}
11927a984708SDavid Chisnall
11937a984708SDavid Chisnalltemplate <class _CharT>
11947a984708SDavid Chisnalltemplate <class _ForwardIterator>
11957a984708SDavid Chisnalltypename regex_traits<_CharT>::string_type
11967a984708SDavid Chisnallregex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f,
11977a984708SDavid Chisnall                                           _ForwardIterator __l, wchar_t) const
11987a984708SDavid Chisnall{
11997a984708SDavid Chisnall    string_type __s(__f, __l);
12007a984708SDavid Chisnall    string __n;
12017a984708SDavid Chisnall    __n.reserve(__s.size());
12027a984708SDavid Chisnall    for (typename string_type::const_iterator __i = __s.begin(), __e = __s.end();
12037a984708SDavid Chisnall                                                              __i != __e; ++__i)
12047a984708SDavid Chisnall    {
12057a984708SDavid Chisnall        if (static_cast<unsigned>(*__i) >= 127)
12067a984708SDavid Chisnall            return string_type();
12077a984708SDavid Chisnall        __n.push_back(char(*__i));
12087a984708SDavid Chisnall    }
12097a984708SDavid Chisnall    string_type __r;
12107a984708SDavid Chisnall    if (!__s.empty())
12117a984708SDavid Chisnall    {
12127a984708SDavid Chisnall        __n = __get_collation_name(__n.c_str());
12137a984708SDavid Chisnall        if (!__n.empty())
12147a984708SDavid Chisnall            __r.assign(__n.begin(), __n.end());
12157a984708SDavid Chisnall        else if (__s.size() <= 2)
12167a984708SDavid Chisnall        {
12177a984708SDavid Chisnall            __r = __col_->transform(__s.data(), __s.data() + __s.size());
12187a984708SDavid Chisnall            if (__r.size() == 1 || __r.size() == 3)
12197a984708SDavid Chisnall                __r = __s;
12207a984708SDavid Chisnall            else
12217a984708SDavid Chisnall                __r.clear();
12227a984708SDavid Chisnall        }
12237a984708SDavid Chisnall    }
12247a984708SDavid Chisnall    return __r;
12257a984708SDavid Chisnall}
12267a984708SDavid Chisnall
12277a984708SDavid Chisnall// lookup_classname
12287a984708SDavid Chisnall
1229d72607e9SDimitry Andricregex_traits<char>::char_class_type _LIBCPP_FUNC_VIS
1230d72607e9SDimitry Andric__get_classname(const char* __s, bool __icase);
12317a984708SDavid Chisnall
12327a984708SDavid Chisnalltemplate <class _CharT>
12337a984708SDavid Chisnalltemplate <class _ForwardIterator>
12347a984708SDavid Chisnalltypename regex_traits<_CharT>::char_class_type
12357a984708SDavid Chisnallregex_traits<_CharT>::__lookup_classname(_ForwardIterator __f,
12367a984708SDavid Chisnall                                         _ForwardIterator __l,
12377a984708SDavid Chisnall                                         bool __icase, char) const
12387a984708SDavid Chisnall{
12397a984708SDavid Chisnall    string_type __s(__f, __l);
12407a984708SDavid Chisnall    __ct_->tolower(&__s[0], &__s[0] + __s.size());
12417a984708SDavid Chisnall    return __get_classname(__s.c_str(), __icase);
12427a984708SDavid Chisnall}
12437a984708SDavid Chisnall
12447a984708SDavid Chisnalltemplate <class _CharT>
12457a984708SDavid Chisnalltemplate <class _ForwardIterator>
12467a984708SDavid Chisnalltypename regex_traits<_CharT>::char_class_type
12477a984708SDavid Chisnallregex_traits<_CharT>::__lookup_classname(_ForwardIterator __f,
12487a984708SDavid Chisnall                                         _ForwardIterator __l,
12497a984708SDavid Chisnall                                         bool __icase, wchar_t) const
12507a984708SDavid Chisnall{
12517a984708SDavid Chisnall    string_type __s(__f, __l);
12527a984708SDavid Chisnall    __ct_->tolower(&__s[0], &__s[0] + __s.size());
12537a984708SDavid Chisnall    string __n;
12547a984708SDavid Chisnall    __n.reserve(__s.size());
12557a984708SDavid Chisnall    for (typename string_type::const_iterator __i = __s.begin(), __e = __s.end();
12567a984708SDavid Chisnall                                                              __i != __e; ++__i)
12577a984708SDavid Chisnall    {
12587a984708SDavid Chisnall        if (static_cast<unsigned>(*__i) >= 127)
12597a984708SDavid Chisnall            return char_class_type();
12607a984708SDavid Chisnall        __n.push_back(char(*__i));
12617a984708SDavid Chisnall    }
12627a984708SDavid Chisnall    return __get_classname(__n.c_str(), __icase);
12637a984708SDavid Chisnall}
12647a984708SDavid Chisnall
12657a984708SDavid Chisnalltemplate <class _CharT>
12667a984708SDavid Chisnallbool
12677a984708SDavid Chisnallregex_traits<_CharT>::isctype(char_type __c, char_class_type __m) const
12687a984708SDavid Chisnall{
12697a984708SDavid Chisnall    if (__ct_->is(__m, __c))
12707a984708SDavid Chisnall        return true;
12717a984708SDavid Chisnall    return (__c == '_' && (__m & __regex_word));
12727a984708SDavid Chisnall}
12737a984708SDavid Chisnall
12747a984708SDavid Chisnalltemplate <class _CharT>
12757a984708SDavid Chisnallint
12764f7ab58eSDimitry Andricregex_traits<_CharT>::__regex_traits_value(unsigned char __ch, int __radix)
12777a984708SDavid Chisnall{
12787a984708SDavid Chisnall    if ((__ch & 0xF8u) == 0x30)  // '0' <= __ch && __ch <= '7'
12797a984708SDavid Chisnall        return __ch - '0';
12807a984708SDavid Chisnall    if (__radix != 8)
12817a984708SDavid Chisnall    {
12827a984708SDavid Chisnall        if ((__ch & 0xFEu) == 0x38)  // '8' <= __ch && __ch <= '9'
12837a984708SDavid Chisnall            return __ch - '0';
12847a984708SDavid Chisnall        if (__radix == 16)
12857a984708SDavid Chisnall        {
12867a984708SDavid Chisnall            __ch |= 0x20;  // tolower
12877a984708SDavid Chisnall            if ('a' <= __ch && __ch <= 'f')
12887a984708SDavid Chisnall                return __ch - ('a' - 10);
12897a984708SDavid Chisnall        }
12907a984708SDavid Chisnall    }
12917a984708SDavid Chisnall    return -1;
12927a984708SDavid Chisnall}
12937a984708SDavid Chisnall
12947a984708SDavid Chisnalltemplate <class _CharT>
12959729cf09SDimitry Andricinline
12967a984708SDavid Chisnallint
12974f7ab58eSDimitry Andricregex_traits<_CharT>::__regex_traits_value(wchar_t __ch, int __radix) const
12987a984708SDavid Chisnall{
12994f7ab58eSDimitry Andric    return __regex_traits_value(static_cast<unsigned char>(__ct_->narrow(__ch, char_type())), __radix);
13007a984708SDavid Chisnall}
13017a984708SDavid Chisnall
13027a984708SDavid Chisnalltemplate <class _CharT> class __node;
13037a984708SDavid Chisnall
1304aed8d94eSDimitry Andrictemplate <class _BidirectionalIterator> class _LIBCPP_TEMPLATE_VIS sub_match;
13057a984708SDavid Chisnall
13067a984708SDavid Chisnalltemplate <class _BidirectionalIterator,
13077a984708SDavid Chisnall          class _Allocator = allocator<sub_match<_BidirectionalIterator> > >
1308aed8d94eSDimitry Andricclass _LIBCPP_TEMPLATE_VIS match_results;
13097a984708SDavid Chisnall
13107a984708SDavid Chisnalltemplate <class _CharT>
13117a984708SDavid Chisnallstruct __state
13127a984708SDavid Chisnall{
13137a984708SDavid Chisnall    enum
13147a984708SDavid Chisnall    {
13157a984708SDavid Chisnall        __end_state = -1000,
13167a984708SDavid Chisnall        __consume_input,  // -999
13177a984708SDavid Chisnall        __begin_marked_expr, // -998
13187a984708SDavid Chisnall        __end_marked_expr,   // -997
13197a984708SDavid Chisnall        __pop_state,           // -996
13207a984708SDavid Chisnall        __accept_and_consume,  // -995
13217a984708SDavid Chisnall        __accept_but_not_consume,  // -994
13227a984708SDavid Chisnall        __reject,                  // -993
13237a984708SDavid Chisnall        __split,
13247a984708SDavid Chisnall        __repeat
13257a984708SDavid Chisnall    };
13267a984708SDavid Chisnall
13277a984708SDavid Chisnall    int __do_;
13287a984708SDavid Chisnall    const _CharT* __first_;
13297a984708SDavid Chisnall    const _CharT* __current_;
13307a984708SDavid Chisnall    const _CharT* __last_;
13317a984708SDavid Chisnall    vector<sub_match<const _CharT*> > __sub_matches_;
13327a984708SDavid Chisnall    vector<pair<size_t, const _CharT*> > __loop_data_;
13337a984708SDavid Chisnall    const __node<_CharT>* __node_;
13347a984708SDavid Chisnall    regex_constants::match_flag_type __flags_;
13357a984708SDavid Chisnall    bool __at_first_;
13367a984708SDavid Chisnall
13377a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
13387a984708SDavid Chisnall    __state()
13397a984708SDavid Chisnall        : __do_(0), __first_(nullptr), __current_(nullptr), __last_(nullptr),
13407a984708SDavid Chisnall          __node_(nullptr), __flags_() {}
13417a984708SDavid Chisnall};
13427a984708SDavid Chisnall
13437a984708SDavid Chisnall// __node
13447a984708SDavid Chisnall
13457a984708SDavid Chisnalltemplate <class _CharT>
13467a984708SDavid Chisnallclass __node
13477a984708SDavid Chisnall{
13487a984708SDavid Chisnall    __node(const __node&);
13497a984708SDavid Chisnall    __node& operator=(const __node&);
13507a984708SDavid Chisnallpublic:
13517a984708SDavid Chisnall    typedef _VSTD::__state<_CharT> __state;
13527a984708SDavid Chisnall
13537a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
13547a984708SDavid Chisnall    __node() {}
13557a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
13567a984708SDavid Chisnall    virtual ~__node() {}
13577a984708SDavid Chisnall
13587a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
1359*b5893f02SDimitry Andric    virtual void __exec(__state&) const {}
13607a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
1361*b5893f02SDimitry Andric    virtual void __exec_split(bool, __state&) const {}
13627a984708SDavid Chisnall};
13637a984708SDavid Chisnall
13647a984708SDavid Chisnall// __end_state
13657a984708SDavid Chisnall
13667a984708SDavid Chisnalltemplate <class _CharT>
13677a984708SDavid Chisnallclass __end_state
13687a984708SDavid Chisnall    : public __node<_CharT>
13697a984708SDavid Chisnall{
13707a984708SDavid Chisnallpublic:
13717a984708SDavid Chisnall    typedef _VSTD::__state<_CharT> __state;
13727a984708SDavid Chisnall
13737a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
13747a984708SDavid Chisnall    __end_state() {}
13757a984708SDavid Chisnall
13767a984708SDavid Chisnall    virtual void __exec(__state&) const;
13777a984708SDavid Chisnall};
13787a984708SDavid Chisnall
13797a984708SDavid Chisnalltemplate <class _CharT>
13807a984708SDavid Chisnallvoid
13817a984708SDavid Chisnall__end_state<_CharT>::__exec(__state& __s) const
13827a984708SDavid Chisnall{
13837a984708SDavid Chisnall    __s.__do_ = __state::__end_state;
13847a984708SDavid Chisnall}
13857a984708SDavid Chisnall
13867a984708SDavid Chisnall// __has_one_state
13877a984708SDavid Chisnall
13887a984708SDavid Chisnalltemplate <class _CharT>
13897a984708SDavid Chisnallclass __has_one_state
13907a984708SDavid Chisnall    : public __node<_CharT>
13917a984708SDavid Chisnall{
13927a984708SDavid Chisnall    __node<_CharT>* __first_;
13937a984708SDavid Chisnall
13947a984708SDavid Chisnallpublic:
13957a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
13967a984708SDavid Chisnall    explicit __has_one_state(__node<_CharT>* __s)
13977a984708SDavid Chisnall        : __first_(__s) {}
13987a984708SDavid Chisnall
13997a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
14007a984708SDavid Chisnall    __node<_CharT>*  first() const {return __first_;}
14017a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
14027a984708SDavid Chisnall    __node<_CharT>*& first()       {return __first_;}
14037a984708SDavid Chisnall};
14047a984708SDavid Chisnall
14057a984708SDavid Chisnall// __owns_one_state
14067a984708SDavid Chisnall
14077a984708SDavid Chisnalltemplate <class _CharT>
14087a984708SDavid Chisnallclass __owns_one_state
14097a984708SDavid Chisnall    : public __has_one_state<_CharT>
14107a984708SDavid Chisnall{
14117a984708SDavid Chisnall    typedef __has_one_state<_CharT> base;
14127a984708SDavid Chisnall
14137a984708SDavid Chisnallpublic:
14147a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
14157a984708SDavid Chisnall    explicit __owns_one_state(__node<_CharT>* __s)
14167a984708SDavid Chisnall        : base(__s) {}
14177a984708SDavid Chisnall
14187a984708SDavid Chisnall    virtual ~__owns_one_state();
14197a984708SDavid Chisnall};
14207a984708SDavid Chisnall
14217a984708SDavid Chisnalltemplate <class _CharT>
14227a984708SDavid Chisnall__owns_one_state<_CharT>::~__owns_one_state()
14237a984708SDavid Chisnall{
14247a984708SDavid Chisnall    delete this->first();
14257a984708SDavid Chisnall}
14267a984708SDavid Chisnall
14277a984708SDavid Chisnall// __empty_state
14287a984708SDavid Chisnall
14297a984708SDavid Chisnalltemplate <class _CharT>
14307a984708SDavid Chisnallclass __empty_state
14317a984708SDavid Chisnall    : public __owns_one_state<_CharT>
14327a984708SDavid Chisnall{
14337a984708SDavid Chisnall    typedef __owns_one_state<_CharT> base;
14347a984708SDavid Chisnall
14357a984708SDavid Chisnallpublic:
14367a984708SDavid Chisnall    typedef _VSTD::__state<_CharT> __state;
14377a984708SDavid Chisnall
14387a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
14397a984708SDavid Chisnall    explicit __empty_state(__node<_CharT>* __s)
14407a984708SDavid Chisnall        : base(__s) {}
14417a984708SDavid Chisnall
14427a984708SDavid Chisnall    virtual void __exec(__state&) const;
14437a984708SDavid Chisnall};
14447a984708SDavid Chisnall
14457a984708SDavid Chisnalltemplate <class _CharT>
14467a984708SDavid Chisnallvoid
14477a984708SDavid Chisnall__empty_state<_CharT>::__exec(__state& __s) const
14487a984708SDavid Chisnall{
14497a984708SDavid Chisnall    __s.__do_ = __state::__accept_but_not_consume;
14507a984708SDavid Chisnall    __s.__node_ = this->first();
14517a984708SDavid Chisnall}
14527a984708SDavid Chisnall
14537a984708SDavid Chisnall// __empty_non_own_state
14547a984708SDavid Chisnall
14557a984708SDavid Chisnalltemplate <class _CharT>
14567a984708SDavid Chisnallclass __empty_non_own_state
14577a984708SDavid Chisnall    : public __has_one_state<_CharT>
14587a984708SDavid Chisnall{
14597a984708SDavid Chisnall    typedef __has_one_state<_CharT> base;
14607a984708SDavid Chisnall
14617a984708SDavid Chisnallpublic:
14627a984708SDavid Chisnall    typedef _VSTD::__state<_CharT> __state;
14637a984708SDavid Chisnall
14647a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
14657a984708SDavid Chisnall    explicit __empty_non_own_state(__node<_CharT>* __s)
14667a984708SDavid Chisnall        : base(__s) {}
14677a984708SDavid Chisnall
14687a984708SDavid Chisnall    virtual void __exec(__state&) const;
14697a984708SDavid Chisnall};
14707a984708SDavid Chisnall
14717a984708SDavid Chisnalltemplate <class _CharT>
14727a984708SDavid Chisnallvoid
14737a984708SDavid Chisnall__empty_non_own_state<_CharT>::__exec(__state& __s) const
14747a984708SDavid Chisnall{
14757a984708SDavid Chisnall    __s.__do_ = __state::__accept_but_not_consume;
14767a984708SDavid Chisnall    __s.__node_ = this->first();
14777a984708SDavid Chisnall}
14787a984708SDavid Chisnall
14797a984708SDavid Chisnall// __repeat_one_loop
14807a984708SDavid Chisnall
14817a984708SDavid Chisnalltemplate <class _CharT>
14827a984708SDavid Chisnallclass __repeat_one_loop
14837a984708SDavid Chisnall    : public __has_one_state<_CharT>
14847a984708SDavid Chisnall{
14857a984708SDavid Chisnall    typedef __has_one_state<_CharT> base;
14867a984708SDavid Chisnall
14877a984708SDavid Chisnallpublic:
14887a984708SDavid Chisnall    typedef _VSTD::__state<_CharT> __state;
14897a984708SDavid Chisnall
14907a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
14917a984708SDavid Chisnall    explicit __repeat_one_loop(__node<_CharT>* __s)
14927a984708SDavid Chisnall        : base(__s) {}
14937a984708SDavid Chisnall
14947a984708SDavid Chisnall    virtual void __exec(__state&) const;
14957a984708SDavid Chisnall};
14967a984708SDavid Chisnall
14977a984708SDavid Chisnalltemplate <class _CharT>
14987a984708SDavid Chisnallvoid
14997a984708SDavid Chisnall__repeat_one_loop<_CharT>::__exec(__state& __s) const
15007a984708SDavid Chisnall{
15017a984708SDavid Chisnall    __s.__do_ = __state::__repeat;
15027a984708SDavid Chisnall    __s.__node_ = this->first();
15037a984708SDavid Chisnall}
15047a984708SDavid Chisnall
15057a984708SDavid Chisnall// __owns_two_states
15067a984708SDavid Chisnall
15077a984708SDavid Chisnalltemplate <class _CharT>
15087a984708SDavid Chisnallclass __owns_two_states
15097a984708SDavid Chisnall    : public __owns_one_state<_CharT>
15107a984708SDavid Chisnall{
15117a984708SDavid Chisnall    typedef __owns_one_state<_CharT> base;
15127a984708SDavid Chisnall
15137a984708SDavid Chisnall    base* __second_;
15147a984708SDavid Chisnall
15157a984708SDavid Chisnallpublic:
15167a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
15177a984708SDavid Chisnall    explicit __owns_two_states(__node<_CharT>* __s1, base* __s2)
15187a984708SDavid Chisnall        : base(__s1), __second_(__s2) {}
15197a984708SDavid Chisnall
15207a984708SDavid Chisnall    virtual ~__owns_two_states();
15217a984708SDavid Chisnall
15227a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
15237a984708SDavid Chisnall    base*  second() const {return __second_;}
15247a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
15257a984708SDavid Chisnall    base*& second()       {return __second_;}
15267a984708SDavid Chisnall};
15277a984708SDavid Chisnall
15287a984708SDavid Chisnalltemplate <class _CharT>
15297a984708SDavid Chisnall__owns_two_states<_CharT>::~__owns_two_states()
15307a984708SDavid Chisnall{
15317a984708SDavid Chisnall    delete __second_;
15327a984708SDavid Chisnall}
15337a984708SDavid Chisnall
15347a984708SDavid Chisnall// __loop
15357a984708SDavid Chisnall
15367a984708SDavid Chisnalltemplate <class _CharT>
15377a984708SDavid Chisnallclass __loop
15387a984708SDavid Chisnall    : public __owns_two_states<_CharT>
15397a984708SDavid Chisnall{
15407a984708SDavid Chisnall    typedef __owns_two_states<_CharT> base;
15417a984708SDavid Chisnall
15427a984708SDavid Chisnall    size_t __min_;
15437a984708SDavid Chisnall    size_t __max_;
15447a984708SDavid Chisnall    unsigned __loop_id_;
15457a984708SDavid Chisnall    unsigned __mexp_begin_;
15467a984708SDavid Chisnall    unsigned __mexp_end_;
15477a984708SDavid Chisnall    bool __greedy_;
15487a984708SDavid Chisnall
15497a984708SDavid Chisnallpublic:
15507a984708SDavid Chisnall    typedef _VSTD::__state<_CharT> __state;
15517a984708SDavid Chisnall
15527a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
15537a984708SDavid Chisnall    explicit __loop(unsigned __loop_id,
15547a984708SDavid Chisnall                          __node<_CharT>* __s1, __owns_one_state<_CharT>* __s2,
15557a984708SDavid Chisnall                          unsigned __mexp_begin, unsigned __mexp_end,
15567a984708SDavid Chisnall                          bool __greedy = true,
15577a984708SDavid Chisnall                          size_t __min = 0,
15587a984708SDavid Chisnall                          size_t __max = numeric_limits<size_t>::max())
15597a984708SDavid Chisnall        : base(__s1, __s2), __min_(__min), __max_(__max), __loop_id_(__loop_id),
15607a984708SDavid Chisnall          __mexp_begin_(__mexp_begin), __mexp_end_(__mexp_end),
15617a984708SDavid Chisnall          __greedy_(__greedy) {}
15627a984708SDavid Chisnall
15637a984708SDavid Chisnall    virtual void __exec(__state& __s) const;
15647a984708SDavid Chisnall    virtual void __exec_split(bool __second, __state& __s) const;
15657a984708SDavid Chisnall
15667a984708SDavid Chisnallprivate:
15677a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
15687a984708SDavid Chisnall    void __init_repeat(__state& __s) const
15697a984708SDavid Chisnall    {
15707a984708SDavid Chisnall        __s.__loop_data_[__loop_id_].second = __s.__current_;
15717a984708SDavid Chisnall        for (size_t __i = __mexp_begin_-1; __i != __mexp_end_-1; ++__i)
15727a984708SDavid Chisnall        {
15737a984708SDavid Chisnall            __s.__sub_matches_[__i].first = __s.__last_;
15747a984708SDavid Chisnall            __s.__sub_matches_[__i].second = __s.__last_;
15757a984708SDavid Chisnall            __s.__sub_matches_[__i].matched = false;
15767a984708SDavid Chisnall        }
15777a984708SDavid Chisnall    }
15787a984708SDavid Chisnall};
15797a984708SDavid Chisnall
15807a984708SDavid Chisnalltemplate <class _CharT>
15817a984708SDavid Chisnallvoid
15827a984708SDavid Chisnall__loop<_CharT>::__exec(__state& __s) const
15837a984708SDavid Chisnall{
15847a984708SDavid Chisnall    if (__s.__do_ == __state::__repeat)
15857a984708SDavid Chisnall    {
15867a984708SDavid Chisnall        bool __do_repeat = ++__s.__loop_data_[__loop_id_].first < __max_;
15877a984708SDavid Chisnall        bool __do_alt = __s.__loop_data_[__loop_id_].first >= __min_;
15887a984708SDavid Chisnall        if (__do_repeat && __do_alt &&
15897a984708SDavid Chisnall                               __s.__loop_data_[__loop_id_].second == __s.__current_)
15907a984708SDavid Chisnall            __do_repeat = false;
15917a984708SDavid Chisnall        if (__do_repeat && __do_alt)
15927a984708SDavid Chisnall            __s.__do_ = __state::__split;
15937a984708SDavid Chisnall        else if (__do_repeat)
15947a984708SDavid Chisnall        {
15957a984708SDavid Chisnall            __s.__do_ = __state::__accept_but_not_consume;
15967a984708SDavid Chisnall            __s.__node_ = this->first();
15977a984708SDavid Chisnall            __init_repeat(__s);
15987a984708SDavid Chisnall        }
15997a984708SDavid Chisnall        else
16007a984708SDavid Chisnall        {
16017a984708SDavid Chisnall            __s.__do_ = __state::__accept_but_not_consume;
16027a984708SDavid Chisnall            __s.__node_ = this->second();
16037a984708SDavid Chisnall        }
16047a984708SDavid Chisnall    }
16057a984708SDavid Chisnall    else
16067a984708SDavid Chisnall    {
16077a984708SDavid Chisnall        __s.__loop_data_[__loop_id_].first = 0;
16087a984708SDavid Chisnall        bool __do_repeat = 0 < __max_;
16097a984708SDavid Chisnall        bool __do_alt = 0 >= __min_;
16107a984708SDavid Chisnall        if (__do_repeat && __do_alt)
16117a984708SDavid Chisnall            __s.__do_ = __state::__split;
16127a984708SDavid Chisnall        else if (__do_repeat)
16137a984708SDavid Chisnall        {
16147a984708SDavid Chisnall            __s.__do_ = __state::__accept_but_not_consume;
16157a984708SDavid Chisnall            __s.__node_ = this->first();
16167a984708SDavid Chisnall            __init_repeat(__s);
16177a984708SDavid Chisnall        }
16187a984708SDavid Chisnall        else
16197a984708SDavid Chisnall        {
16207a984708SDavid Chisnall            __s.__do_ = __state::__accept_but_not_consume;
16217a984708SDavid Chisnall            __s.__node_ = this->second();
16227a984708SDavid Chisnall        }
16237a984708SDavid Chisnall    }
16247a984708SDavid Chisnall}
16257a984708SDavid Chisnall
16267a984708SDavid Chisnalltemplate <class _CharT>
16277a984708SDavid Chisnallvoid
16287a984708SDavid Chisnall__loop<_CharT>::__exec_split(bool __second, __state& __s) const
16297a984708SDavid Chisnall{
16307a984708SDavid Chisnall    __s.__do_ = __state::__accept_but_not_consume;
16317a984708SDavid Chisnall    if (__greedy_ != __second)
16327a984708SDavid Chisnall    {
16337a984708SDavid Chisnall        __s.__node_ = this->first();
16347a984708SDavid Chisnall        __init_repeat(__s);
16357a984708SDavid Chisnall    }
16367a984708SDavid Chisnall    else
16377a984708SDavid Chisnall        __s.__node_ = this->second();
16387a984708SDavid Chisnall}
16397a984708SDavid Chisnall
16407a984708SDavid Chisnall// __alternate
16417a984708SDavid Chisnall
16427a984708SDavid Chisnalltemplate <class _CharT>
16437a984708SDavid Chisnallclass __alternate
16447a984708SDavid Chisnall    : public __owns_two_states<_CharT>
16457a984708SDavid Chisnall{
16467a984708SDavid Chisnall    typedef __owns_two_states<_CharT> base;
16477a984708SDavid Chisnall
16487a984708SDavid Chisnallpublic:
16497a984708SDavid Chisnall    typedef _VSTD::__state<_CharT> __state;
16507a984708SDavid Chisnall
16517a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
16527a984708SDavid Chisnall    explicit __alternate(__owns_one_state<_CharT>* __s1,
16537a984708SDavid Chisnall                         __owns_one_state<_CharT>* __s2)
16547a984708SDavid Chisnall        : base(__s1, __s2) {}
16557a984708SDavid Chisnall
16567a984708SDavid Chisnall    virtual void __exec(__state& __s) const;
16577a984708SDavid Chisnall    virtual void __exec_split(bool __second, __state& __s) const;
16587a984708SDavid Chisnall};
16597a984708SDavid Chisnall
16607a984708SDavid Chisnalltemplate <class _CharT>
16617a984708SDavid Chisnallvoid
16627a984708SDavid Chisnall__alternate<_CharT>::__exec(__state& __s) const
16637a984708SDavid Chisnall{
16647a984708SDavid Chisnall    __s.__do_ = __state::__split;
16657a984708SDavid Chisnall}
16667a984708SDavid Chisnall
16677a984708SDavid Chisnalltemplate <class _CharT>
16687a984708SDavid Chisnallvoid
16697a984708SDavid Chisnall__alternate<_CharT>::__exec_split(bool __second, __state& __s) const
16707a984708SDavid Chisnall{
16717a984708SDavid Chisnall    __s.__do_ = __state::__accept_but_not_consume;
16727a984708SDavid Chisnall    if (__second)
16737a984708SDavid Chisnall        __s.__node_ = this->second();
16747a984708SDavid Chisnall    else
16757a984708SDavid Chisnall        __s.__node_ = this->first();
16767a984708SDavid Chisnall}
16777a984708SDavid Chisnall
16787a984708SDavid Chisnall// __begin_marked_subexpression
16797a984708SDavid Chisnall
16807a984708SDavid Chisnalltemplate <class _CharT>
16817a984708SDavid Chisnallclass __begin_marked_subexpression
16827a984708SDavid Chisnall    : public __owns_one_state<_CharT>
16837a984708SDavid Chisnall{
16847a984708SDavid Chisnall    typedef __owns_one_state<_CharT> base;
16857a984708SDavid Chisnall
16867a984708SDavid Chisnall    unsigned __mexp_;
16877a984708SDavid Chisnallpublic:
16887a984708SDavid Chisnall    typedef _VSTD::__state<_CharT> __state;
16897a984708SDavid Chisnall
16907a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
16917a984708SDavid Chisnall    explicit __begin_marked_subexpression(unsigned __mexp, __node<_CharT>* __s)
16927a984708SDavid Chisnall        : base(__s), __mexp_(__mexp) {}
16937a984708SDavid Chisnall
16947a984708SDavid Chisnall    virtual void __exec(__state&) const;
16957a984708SDavid Chisnall};
16967a984708SDavid Chisnall
16977a984708SDavid Chisnalltemplate <class _CharT>
16987a984708SDavid Chisnallvoid
16997a984708SDavid Chisnall__begin_marked_subexpression<_CharT>::__exec(__state& __s) const
17007a984708SDavid Chisnall{
17017a984708SDavid Chisnall    __s.__do_ = __state::__accept_but_not_consume;
17027a984708SDavid Chisnall    __s.__sub_matches_[__mexp_-1].first = __s.__current_;
17037a984708SDavid Chisnall    __s.__node_ = this->first();
17047a984708SDavid Chisnall}
17057a984708SDavid Chisnall
17067a984708SDavid Chisnall// __end_marked_subexpression
17077a984708SDavid Chisnall
17087a984708SDavid Chisnalltemplate <class _CharT>
17097a984708SDavid Chisnallclass __end_marked_subexpression
17107a984708SDavid Chisnall    : public __owns_one_state<_CharT>
17117a984708SDavid Chisnall{
17127a984708SDavid Chisnall    typedef __owns_one_state<_CharT> base;
17137a984708SDavid Chisnall
17147a984708SDavid Chisnall    unsigned __mexp_;
17157a984708SDavid Chisnallpublic:
17167a984708SDavid Chisnall    typedef _VSTD::__state<_CharT> __state;
17177a984708SDavid Chisnall
17187a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
17197a984708SDavid Chisnall    explicit __end_marked_subexpression(unsigned __mexp, __node<_CharT>* __s)
17207a984708SDavid Chisnall        : base(__s), __mexp_(__mexp) {}
17217a984708SDavid Chisnall
17227a984708SDavid Chisnall    virtual void __exec(__state&) const;
17237a984708SDavid Chisnall};
17247a984708SDavid Chisnall
17257a984708SDavid Chisnalltemplate <class _CharT>
17267a984708SDavid Chisnallvoid
17277a984708SDavid Chisnall__end_marked_subexpression<_CharT>::__exec(__state& __s) const
17287a984708SDavid Chisnall{
17297a984708SDavid Chisnall    __s.__do_ = __state::__accept_but_not_consume;
17307a984708SDavid Chisnall    __s.__sub_matches_[__mexp_-1].second = __s.__current_;
17317a984708SDavid Chisnall    __s.__sub_matches_[__mexp_-1].matched = true;
17327a984708SDavid Chisnall    __s.__node_ = this->first();
17337a984708SDavid Chisnall}
17347a984708SDavid Chisnall
17357a984708SDavid Chisnall// __back_ref
17367a984708SDavid Chisnall
17377a984708SDavid Chisnalltemplate <class _CharT>
17387a984708SDavid Chisnallclass __back_ref
17397a984708SDavid Chisnall    : public __owns_one_state<_CharT>
17407a984708SDavid Chisnall{
17417a984708SDavid Chisnall    typedef __owns_one_state<_CharT> base;
17427a984708SDavid Chisnall
17437a984708SDavid Chisnall    unsigned __mexp_;
17447a984708SDavid Chisnallpublic:
17457a984708SDavid Chisnall    typedef _VSTD::__state<_CharT> __state;
17467a984708SDavid Chisnall
17477a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
17487a984708SDavid Chisnall    explicit __back_ref(unsigned __mexp, __node<_CharT>* __s)
17497a984708SDavid Chisnall        : base(__s), __mexp_(__mexp) {}
17507a984708SDavid Chisnall
17517a984708SDavid Chisnall    virtual void __exec(__state&) const;
17527a984708SDavid Chisnall};
17537a984708SDavid Chisnall
17547a984708SDavid Chisnalltemplate <class _CharT>
17557a984708SDavid Chisnallvoid
17567a984708SDavid Chisnall__back_ref<_CharT>::__exec(__state& __s) const
17577a984708SDavid Chisnall{
17589729cf09SDimitry Andric    if (__mexp_ > __s.__sub_matches_.size())
17599729cf09SDimitry Andric        __throw_regex_error<regex_constants::error_backref>();
17607a984708SDavid Chisnall    sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1];
17617a984708SDavid Chisnall    if (__sm.matched)
17627a984708SDavid Chisnall    {
17637a984708SDavid Chisnall        ptrdiff_t __len = __sm.second - __sm.first;
17647a984708SDavid Chisnall        if (__s.__last_ - __s.__current_ >= __len &&
17657a984708SDavid Chisnall            _VSTD::equal(__sm.first, __sm.second, __s.__current_))
17667a984708SDavid Chisnall        {
17677a984708SDavid Chisnall            __s.__do_ = __state::__accept_but_not_consume;
17687a984708SDavid Chisnall            __s.__current_ += __len;
17697a984708SDavid Chisnall            __s.__node_ = this->first();
17707a984708SDavid Chisnall        }
17717a984708SDavid Chisnall        else
17727a984708SDavid Chisnall        {
17737a984708SDavid Chisnall            __s.__do_ = __state::__reject;
17747a984708SDavid Chisnall            __s.__node_ = nullptr;
17757a984708SDavid Chisnall        }
17767a984708SDavid Chisnall    }
17777a984708SDavid Chisnall    else
17787a984708SDavid Chisnall    {
17797a984708SDavid Chisnall        __s.__do_ = __state::__reject;
17807a984708SDavid Chisnall        __s.__node_ = nullptr;
17817a984708SDavid Chisnall    }
17827a984708SDavid Chisnall}
17837a984708SDavid Chisnall
17847a984708SDavid Chisnall// __back_ref_icase
17857a984708SDavid Chisnall
17867a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
17877a984708SDavid Chisnallclass __back_ref_icase
17887a984708SDavid Chisnall    : public __owns_one_state<_CharT>
17897a984708SDavid Chisnall{
17907a984708SDavid Chisnall    typedef __owns_one_state<_CharT> base;
17917a984708SDavid Chisnall
17927a984708SDavid Chisnall    _Traits __traits_;
17937a984708SDavid Chisnall    unsigned __mexp_;
17947a984708SDavid Chisnallpublic:
17957a984708SDavid Chisnall    typedef _VSTD::__state<_CharT> __state;
17967a984708SDavid Chisnall
17977a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
17987a984708SDavid Chisnall    explicit __back_ref_icase(const _Traits& __traits, unsigned __mexp,
17997a984708SDavid Chisnall                              __node<_CharT>* __s)
18007a984708SDavid Chisnall        : base(__s), __traits_(__traits), __mexp_(__mexp) {}
18017a984708SDavid Chisnall
18027a984708SDavid Chisnall    virtual void __exec(__state&) const;
18037a984708SDavid Chisnall};
18047a984708SDavid Chisnall
18057a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
18067a984708SDavid Chisnallvoid
18077a984708SDavid Chisnall__back_ref_icase<_CharT, _Traits>::__exec(__state& __s) const
18087a984708SDavid Chisnall{
18097a984708SDavid Chisnall    sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1];
18107a984708SDavid Chisnall    if (__sm.matched)
18117a984708SDavid Chisnall    {
18127a984708SDavid Chisnall        ptrdiff_t __len = __sm.second - __sm.first;
18137a984708SDavid Chisnall        if (__s.__last_ - __s.__current_ >= __len)
18147a984708SDavid Chisnall        {
18157a984708SDavid Chisnall            for (ptrdiff_t __i = 0; __i < __len; ++__i)
18167a984708SDavid Chisnall            {
18177a984708SDavid Chisnall                if (__traits_.translate_nocase(__sm.first[__i]) !=
18187a984708SDavid Chisnall                                __traits_.translate_nocase(__s.__current_[__i]))
18197a984708SDavid Chisnall                    goto __not_equal;
18207a984708SDavid Chisnall            }
18217a984708SDavid Chisnall            __s.__do_ = __state::__accept_but_not_consume;
18227a984708SDavid Chisnall            __s.__current_ += __len;
18237a984708SDavid Chisnall            __s.__node_ = this->first();
18247a984708SDavid Chisnall        }
18257a984708SDavid Chisnall        else
18267a984708SDavid Chisnall        {
18277a984708SDavid Chisnall            __s.__do_ = __state::__reject;
18287a984708SDavid Chisnall            __s.__node_ = nullptr;
18297a984708SDavid Chisnall        }
18307a984708SDavid Chisnall    }
18317a984708SDavid Chisnall    else
18327a984708SDavid Chisnall    {
18337a984708SDavid Chisnall__not_equal:
18347a984708SDavid Chisnall        __s.__do_ = __state::__reject;
18357a984708SDavid Chisnall        __s.__node_ = nullptr;
18367a984708SDavid Chisnall    }
18377a984708SDavid Chisnall}
18387a984708SDavid Chisnall
18397a984708SDavid Chisnall// __back_ref_collate
18407a984708SDavid Chisnall
18417a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
18427a984708SDavid Chisnallclass __back_ref_collate
18437a984708SDavid Chisnall    : public __owns_one_state<_CharT>
18447a984708SDavid Chisnall{
18457a984708SDavid Chisnall    typedef __owns_one_state<_CharT> base;
18467a984708SDavid Chisnall
18477a984708SDavid Chisnall    _Traits __traits_;
18487a984708SDavid Chisnall    unsigned __mexp_;
18497a984708SDavid Chisnallpublic:
18507a984708SDavid Chisnall    typedef _VSTD::__state<_CharT> __state;
18517a984708SDavid Chisnall
18527a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
18537a984708SDavid Chisnall    explicit __back_ref_collate(const _Traits& __traits, unsigned __mexp,
18547a984708SDavid Chisnall                              __node<_CharT>* __s)
18557a984708SDavid Chisnall        : base(__s), __traits_(__traits), __mexp_(__mexp) {}
18567a984708SDavid Chisnall
18577a984708SDavid Chisnall    virtual void __exec(__state&) const;
18587a984708SDavid Chisnall};
18597a984708SDavid Chisnall
18607a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
18617a984708SDavid Chisnallvoid
18627a984708SDavid Chisnall__back_ref_collate<_CharT, _Traits>::__exec(__state& __s) const
18637a984708SDavid Chisnall{
18647a984708SDavid Chisnall    sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1];
18657a984708SDavid Chisnall    if (__sm.matched)
18667a984708SDavid Chisnall    {
18677a984708SDavid Chisnall        ptrdiff_t __len = __sm.second - __sm.first;
18687a984708SDavid Chisnall        if (__s.__last_ - __s.__current_ >= __len)
18697a984708SDavid Chisnall        {
18707a984708SDavid Chisnall            for (ptrdiff_t __i = 0; __i < __len; ++__i)
18717a984708SDavid Chisnall            {
18727a984708SDavid Chisnall                if (__traits_.translate(__sm.first[__i]) !=
18737a984708SDavid Chisnall                                       __traits_.translate(__s.__current_[__i]))
18747a984708SDavid Chisnall                    goto __not_equal;
18757a984708SDavid Chisnall            }
18767a984708SDavid Chisnall            __s.__do_ = __state::__accept_but_not_consume;
18777a984708SDavid Chisnall            __s.__current_ += __len;
18787a984708SDavid Chisnall            __s.__node_ = this->first();
18797a984708SDavid Chisnall        }
18807a984708SDavid Chisnall        else
18817a984708SDavid Chisnall        {
18827a984708SDavid Chisnall            __s.__do_ = __state::__reject;
18837a984708SDavid Chisnall            __s.__node_ = nullptr;
18847a984708SDavid Chisnall        }
18857a984708SDavid Chisnall    }
18867a984708SDavid Chisnall    else
18877a984708SDavid Chisnall    {
18887a984708SDavid Chisnall__not_equal:
18897a984708SDavid Chisnall        __s.__do_ = __state::__reject;
18907a984708SDavid Chisnall        __s.__node_ = nullptr;
18917a984708SDavid Chisnall    }
18927a984708SDavid Chisnall}
18937a984708SDavid Chisnall
18947a984708SDavid Chisnall// __word_boundary
18957a984708SDavid Chisnall
18967a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
18977a984708SDavid Chisnallclass __word_boundary
18987a984708SDavid Chisnall    : public __owns_one_state<_CharT>
18997a984708SDavid Chisnall{
19007a984708SDavid Chisnall    typedef __owns_one_state<_CharT> base;
19017a984708SDavid Chisnall
19027a984708SDavid Chisnall    _Traits __traits_;
19037a984708SDavid Chisnall    bool __invert_;
19047a984708SDavid Chisnallpublic:
19057a984708SDavid Chisnall    typedef _VSTD::__state<_CharT> __state;
19067a984708SDavid Chisnall
19077a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
19087a984708SDavid Chisnall    explicit __word_boundary(const _Traits& __traits, bool __invert,
19097a984708SDavid Chisnall                             __node<_CharT>* __s)
19107a984708SDavid Chisnall        : base(__s), __traits_(__traits), __invert_(__invert) {}
19117a984708SDavid Chisnall
19127a984708SDavid Chisnall    virtual void __exec(__state&) const;
19137a984708SDavid Chisnall};
19147a984708SDavid Chisnall
19157a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
19167a984708SDavid Chisnallvoid
19177a984708SDavid Chisnall__word_boundary<_CharT, _Traits>::__exec(__state& __s) const
19187a984708SDavid Chisnall{
19197a984708SDavid Chisnall    bool __is_word_b = false;
19207a984708SDavid Chisnall    if (__s.__first_ != __s.__last_)
19217a984708SDavid Chisnall    {
19227a984708SDavid Chisnall        if (__s.__current_ == __s.__last_)
19237a984708SDavid Chisnall        {
19247a984708SDavid Chisnall            if (!(__s.__flags_ & regex_constants::match_not_eow))
19257a984708SDavid Chisnall            {
19267a984708SDavid Chisnall                _CharT __c = __s.__current_[-1];
19277a984708SDavid Chisnall                __is_word_b = __c == '_' ||
19287a984708SDavid Chisnall                              __traits_.isctype(__c, ctype_base::alnum);
19297a984708SDavid Chisnall            }
19307a984708SDavid Chisnall        }
19317a984708SDavid Chisnall        else if (__s.__current_ == __s.__first_ &&
19327a984708SDavid Chisnall                !(__s.__flags_ & regex_constants::match_prev_avail))
19337a984708SDavid Chisnall        {
19347a984708SDavid Chisnall            if (!(__s.__flags_ & regex_constants::match_not_bow))
19357a984708SDavid Chisnall            {
19367a984708SDavid Chisnall                _CharT __c = *__s.__current_;
19377a984708SDavid Chisnall                __is_word_b = __c == '_' ||
19387a984708SDavid Chisnall                              __traits_.isctype(__c, ctype_base::alnum);
19397a984708SDavid Chisnall            }
19407a984708SDavid Chisnall        }
19417a984708SDavid Chisnall        else
19427a984708SDavid Chisnall        {
19437a984708SDavid Chisnall            _CharT __c1 = __s.__current_[-1];
19447a984708SDavid Chisnall            _CharT __c2 = *__s.__current_;
19457a984708SDavid Chisnall            bool __is_c1_b = __c1 == '_' ||
19467a984708SDavid Chisnall                             __traits_.isctype(__c1, ctype_base::alnum);
19477a984708SDavid Chisnall            bool __is_c2_b = __c2 == '_' ||
19487a984708SDavid Chisnall                             __traits_.isctype(__c2, ctype_base::alnum);
19497a984708SDavid Chisnall            __is_word_b = __is_c1_b != __is_c2_b;
19507a984708SDavid Chisnall        }
19517a984708SDavid Chisnall    }
19527a984708SDavid Chisnall    if (__is_word_b != __invert_)
19537a984708SDavid Chisnall    {
19547a984708SDavid Chisnall        __s.__do_ = __state::__accept_but_not_consume;
19557a984708SDavid Chisnall        __s.__node_ = this->first();
19567a984708SDavid Chisnall    }
19577a984708SDavid Chisnall    else
19587a984708SDavid Chisnall    {
19597a984708SDavid Chisnall        __s.__do_ = __state::__reject;
19607a984708SDavid Chisnall        __s.__node_ = nullptr;
19617a984708SDavid Chisnall    }
19627a984708SDavid Chisnall}
19637a984708SDavid Chisnall
19647a984708SDavid Chisnall// __l_anchor
19657a984708SDavid Chisnall
19667a984708SDavid Chisnalltemplate <class _CharT>
19677a984708SDavid Chisnallclass __l_anchor
19687a984708SDavid Chisnall    : public __owns_one_state<_CharT>
19697a984708SDavid Chisnall{
19707a984708SDavid Chisnall    typedef __owns_one_state<_CharT> base;
19717a984708SDavid Chisnall
19727a984708SDavid Chisnallpublic:
19737a984708SDavid Chisnall    typedef _VSTD::__state<_CharT> __state;
19747a984708SDavid Chisnall
19757a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
19767a984708SDavid Chisnall    __l_anchor(__node<_CharT>* __s)
19777a984708SDavid Chisnall        : base(__s) {}
19787a984708SDavid Chisnall
19797a984708SDavid Chisnall    virtual void __exec(__state&) const;
19807a984708SDavid Chisnall};
19817a984708SDavid Chisnall
19827a984708SDavid Chisnalltemplate <class _CharT>
19837a984708SDavid Chisnallvoid
19847a984708SDavid Chisnall__l_anchor<_CharT>::__exec(__state& __s) const
19857a984708SDavid Chisnall{
1986854fa44bSDimitry Andric    if (__s.__at_first_ && __s.__current_ == __s.__first_ &&
1987854fa44bSDimitry Andric        !(__s.__flags_ & regex_constants::match_not_bol))
19887a984708SDavid Chisnall    {
19897a984708SDavid Chisnall        __s.__do_ = __state::__accept_but_not_consume;
19907a984708SDavid Chisnall        __s.__node_ = this->first();
19917a984708SDavid Chisnall    }
19927a984708SDavid Chisnall    else
19937a984708SDavid Chisnall    {
19947a984708SDavid Chisnall        __s.__do_ = __state::__reject;
19957a984708SDavid Chisnall        __s.__node_ = nullptr;
19967a984708SDavid Chisnall    }
19977a984708SDavid Chisnall}
19987a984708SDavid Chisnall
19997a984708SDavid Chisnall// __r_anchor
20007a984708SDavid Chisnall
20017a984708SDavid Chisnalltemplate <class _CharT>
20027a984708SDavid Chisnallclass __r_anchor
20037a984708SDavid Chisnall    : public __owns_one_state<_CharT>
20047a984708SDavid Chisnall{
20057a984708SDavid Chisnall    typedef __owns_one_state<_CharT> base;
20067a984708SDavid Chisnall
20077a984708SDavid Chisnallpublic:
20087a984708SDavid Chisnall    typedef _VSTD::__state<_CharT> __state;
20097a984708SDavid Chisnall
20107a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
20117a984708SDavid Chisnall    __r_anchor(__node<_CharT>* __s)
20127a984708SDavid Chisnall        : base(__s) {}
20137a984708SDavid Chisnall
20147a984708SDavid Chisnall    virtual void __exec(__state&) const;
20157a984708SDavid Chisnall};
20167a984708SDavid Chisnall
20177a984708SDavid Chisnalltemplate <class _CharT>
20187a984708SDavid Chisnallvoid
20197a984708SDavid Chisnall__r_anchor<_CharT>::__exec(__state& __s) const
20207a984708SDavid Chisnall{
2021854fa44bSDimitry Andric    if (__s.__current_ == __s.__last_ &&
2022854fa44bSDimitry Andric        !(__s.__flags_ & regex_constants::match_not_eol))
20237a984708SDavid Chisnall    {
20247a984708SDavid Chisnall        __s.__do_ = __state::__accept_but_not_consume;
20257a984708SDavid Chisnall        __s.__node_ = this->first();
20267a984708SDavid Chisnall    }
20277a984708SDavid Chisnall    else
20287a984708SDavid Chisnall    {
20297a984708SDavid Chisnall        __s.__do_ = __state::__reject;
20307a984708SDavid Chisnall        __s.__node_ = nullptr;
20317a984708SDavid Chisnall    }
20327a984708SDavid Chisnall}
20337a984708SDavid Chisnall
20347a984708SDavid Chisnall// __match_any
20357a984708SDavid Chisnall
20367a984708SDavid Chisnalltemplate <class _CharT>
20377a984708SDavid Chisnallclass __match_any
20387a984708SDavid Chisnall    : public __owns_one_state<_CharT>
20397a984708SDavid Chisnall{
20407a984708SDavid Chisnall    typedef __owns_one_state<_CharT> base;
20417a984708SDavid Chisnall
20427a984708SDavid Chisnallpublic:
20437a984708SDavid Chisnall    typedef _VSTD::__state<_CharT> __state;
20447a984708SDavid Chisnall
20457a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
20467a984708SDavid Chisnall    __match_any(__node<_CharT>* __s)
20477a984708SDavid Chisnall        : base(__s) {}
20487a984708SDavid Chisnall
20497a984708SDavid Chisnall    virtual void __exec(__state&) const;
20507a984708SDavid Chisnall};
20517a984708SDavid Chisnall
20527a984708SDavid Chisnalltemplate <class _CharT>
20537a984708SDavid Chisnallvoid
20547a984708SDavid Chisnall__match_any<_CharT>::__exec(__state& __s) const
20557a984708SDavid Chisnall{
20567a984708SDavid Chisnall    if (__s.__current_ != __s.__last_ && *__s.__current_ != 0)
20577a984708SDavid Chisnall    {
20587a984708SDavid Chisnall        __s.__do_ = __state::__accept_and_consume;
20597a984708SDavid Chisnall        ++__s.__current_;
20607a984708SDavid Chisnall        __s.__node_ = this->first();
20617a984708SDavid Chisnall    }
20627a984708SDavid Chisnall    else
20637a984708SDavid Chisnall    {
20647a984708SDavid Chisnall        __s.__do_ = __state::__reject;
20657a984708SDavid Chisnall        __s.__node_ = nullptr;
20667a984708SDavid Chisnall    }
20677a984708SDavid Chisnall}
20687a984708SDavid Chisnall
20697a984708SDavid Chisnall// __match_any_but_newline
20707a984708SDavid Chisnall
20717a984708SDavid Chisnalltemplate <class _CharT>
20727a984708SDavid Chisnallclass __match_any_but_newline
20737a984708SDavid Chisnall    : public __owns_one_state<_CharT>
20747a984708SDavid Chisnall{
20757a984708SDavid Chisnall    typedef __owns_one_state<_CharT> base;
20767a984708SDavid Chisnall
20777a984708SDavid Chisnallpublic:
20787a984708SDavid Chisnall    typedef _VSTD::__state<_CharT> __state;
20797a984708SDavid Chisnall
20807a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
20817a984708SDavid Chisnall    __match_any_but_newline(__node<_CharT>* __s)
20827a984708SDavid Chisnall        : base(__s) {}
20837a984708SDavid Chisnall
20847a984708SDavid Chisnall    virtual void __exec(__state&) const;
20857a984708SDavid Chisnall};
20867a984708SDavid Chisnall
20874f7ab58eSDimitry Andrictemplate <> _LIBCPP_FUNC_VIS void __match_any_but_newline<char>::__exec(__state&) const;
20884f7ab58eSDimitry Andrictemplate <> _LIBCPP_FUNC_VIS void __match_any_but_newline<wchar_t>::__exec(__state&) const;
20894f7ab58eSDimitry Andric
20907a984708SDavid Chisnall// __match_char
20917a984708SDavid Chisnall
20927a984708SDavid Chisnalltemplate <class _CharT>
20937a984708SDavid Chisnallclass __match_char
20947a984708SDavid Chisnall    : public __owns_one_state<_CharT>
20957a984708SDavid Chisnall{
20967a984708SDavid Chisnall    typedef __owns_one_state<_CharT> base;
20977a984708SDavid Chisnall
20987a984708SDavid Chisnall    _CharT __c_;
20997a984708SDavid Chisnall
21007a984708SDavid Chisnall    __match_char(const __match_char&);
21017a984708SDavid Chisnall    __match_char& operator=(const __match_char&);
21027a984708SDavid Chisnallpublic:
21037a984708SDavid Chisnall    typedef _VSTD::__state<_CharT> __state;
21047a984708SDavid Chisnall
21057a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
21067a984708SDavid Chisnall    __match_char(_CharT __c, __node<_CharT>* __s)
21077a984708SDavid Chisnall        : base(__s), __c_(__c) {}
21087a984708SDavid Chisnall
21097a984708SDavid Chisnall    virtual void __exec(__state&) const;
21107a984708SDavid Chisnall};
21117a984708SDavid Chisnall
21127a984708SDavid Chisnalltemplate <class _CharT>
21137a984708SDavid Chisnallvoid
21147a984708SDavid Chisnall__match_char<_CharT>::__exec(__state& __s) const
21157a984708SDavid Chisnall{
21167a984708SDavid Chisnall    if (__s.__current_ != __s.__last_ && *__s.__current_ == __c_)
21177a984708SDavid Chisnall    {
21187a984708SDavid Chisnall        __s.__do_ = __state::__accept_and_consume;
21197a984708SDavid Chisnall        ++__s.__current_;
21207a984708SDavid Chisnall        __s.__node_ = this->first();
21217a984708SDavid Chisnall    }
21227a984708SDavid Chisnall    else
21237a984708SDavid Chisnall    {
21247a984708SDavid Chisnall        __s.__do_ = __state::__reject;
21257a984708SDavid Chisnall        __s.__node_ = nullptr;
21267a984708SDavid Chisnall    }
21277a984708SDavid Chisnall}
21287a984708SDavid Chisnall
21297a984708SDavid Chisnall// __match_char_icase
21307a984708SDavid Chisnall
21317a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
21327a984708SDavid Chisnallclass __match_char_icase
21337a984708SDavid Chisnall    : public __owns_one_state<_CharT>
21347a984708SDavid Chisnall{
21357a984708SDavid Chisnall    typedef __owns_one_state<_CharT> base;
21367a984708SDavid Chisnall
21377a984708SDavid Chisnall    _Traits __traits_;
21387a984708SDavid Chisnall    _CharT __c_;
21397a984708SDavid Chisnall
21407a984708SDavid Chisnall    __match_char_icase(const __match_char_icase&);
21417a984708SDavid Chisnall    __match_char_icase& operator=(const __match_char_icase&);
21427a984708SDavid Chisnallpublic:
21437a984708SDavid Chisnall    typedef _VSTD::__state<_CharT> __state;
21447a984708SDavid Chisnall
21457a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
21467a984708SDavid Chisnall    __match_char_icase(const _Traits& __traits, _CharT __c, __node<_CharT>* __s)
21477a984708SDavid Chisnall        : base(__s), __traits_(__traits), __c_(__traits.translate_nocase(__c)) {}
21487a984708SDavid Chisnall
21497a984708SDavid Chisnall    virtual void __exec(__state&) const;
21507a984708SDavid Chisnall};
21517a984708SDavid Chisnall
21527a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
21537a984708SDavid Chisnallvoid
21547a984708SDavid Chisnall__match_char_icase<_CharT, _Traits>::__exec(__state& __s) const
21557a984708SDavid Chisnall{
21567a984708SDavid Chisnall    if (__s.__current_ != __s.__last_ &&
21577a984708SDavid Chisnall        __traits_.translate_nocase(*__s.__current_) == __c_)
21587a984708SDavid Chisnall    {
21597a984708SDavid Chisnall        __s.__do_ = __state::__accept_and_consume;
21607a984708SDavid Chisnall        ++__s.__current_;
21617a984708SDavid Chisnall        __s.__node_ = this->first();
21627a984708SDavid Chisnall    }
21637a984708SDavid Chisnall    else
21647a984708SDavid Chisnall    {
21657a984708SDavid Chisnall        __s.__do_ = __state::__reject;
21667a984708SDavid Chisnall        __s.__node_ = nullptr;
21677a984708SDavid Chisnall    }
21687a984708SDavid Chisnall}
21697a984708SDavid Chisnall
21707a984708SDavid Chisnall// __match_char_collate
21717a984708SDavid Chisnall
21727a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
21737a984708SDavid Chisnallclass __match_char_collate
21747a984708SDavid Chisnall    : public __owns_one_state<_CharT>
21757a984708SDavid Chisnall{
21767a984708SDavid Chisnall    typedef __owns_one_state<_CharT> base;
21777a984708SDavid Chisnall
21787a984708SDavid Chisnall    _Traits __traits_;
21797a984708SDavid Chisnall    _CharT __c_;
21807a984708SDavid Chisnall
21817a984708SDavid Chisnall    __match_char_collate(const __match_char_collate&);
21827a984708SDavid Chisnall    __match_char_collate& operator=(const __match_char_collate&);
21837a984708SDavid Chisnallpublic:
21847a984708SDavid Chisnall    typedef _VSTD::__state<_CharT> __state;
21857a984708SDavid Chisnall
21867a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
21877a984708SDavid Chisnall    __match_char_collate(const _Traits& __traits, _CharT __c, __node<_CharT>* __s)
21887a984708SDavid Chisnall        : base(__s), __traits_(__traits), __c_(__traits.translate(__c)) {}
21897a984708SDavid Chisnall
21907a984708SDavid Chisnall    virtual void __exec(__state&) const;
21917a984708SDavid Chisnall};
21927a984708SDavid Chisnall
21937a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
21947a984708SDavid Chisnallvoid
21957a984708SDavid Chisnall__match_char_collate<_CharT, _Traits>::__exec(__state& __s) const
21967a984708SDavid Chisnall{
21977a984708SDavid Chisnall    if (__s.__current_ != __s.__last_ &&
21987a984708SDavid Chisnall        __traits_.translate(*__s.__current_) == __c_)
21997a984708SDavid Chisnall    {
22007a984708SDavid Chisnall        __s.__do_ = __state::__accept_and_consume;
22017a984708SDavid Chisnall        ++__s.__current_;
22027a984708SDavid Chisnall        __s.__node_ = this->first();
22037a984708SDavid Chisnall    }
22047a984708SDavid Chisnall    else
22057a984708SDavid Chisnall    {
22067a984708SDavid Chisnall        __s.__do_ = __state::__reject;
22077a984708SDavid Chisnall        __s.__node_ = nullptr;
22087a984708SDavid Chisnall    }
22097a984708SDavid Chisnall}
22107a984708SDavid Chisnall
22117a984708SDavid Chisnall// __bracket_expression
22127a984708SDavid Chisnall
22137a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
22147a984708SDavid Chisnallclass __bracket_expression
22157a984708SDavid Chisnall    : public __owns_one_state<_CharT>
22167a984708SDavid Chisnall{
22177a984708SDavid Chisnall    typedef __owns_one_state<_CharT> base;
22187a984708SDavid Chisnall    typedef typename _Traits::string_type string_type;
22197a984708SDavid Chisnall
22207a984708SDavid Chisnall    _Traits __traits_;
22217a984708SDavid Chisnall    vector<_CharT> __chars_;
22227a984708SDavid Chisnall    vector<_CharT> __neg_chars_;
22237a984708SDavid Chisnall    vector<pair<string_type, string_type> > __ranges_;
22247a984708SDavid Chisnall    vector<pair<_CharT, _CharT> > __digraphs_;
22257a984708SDavid Chisnall    vector<string_type> __equivalences_;
2226d72607e9SDimitry Andric    typename regex_traits<_CharT>::char_class_type __mask_;
2227d72607e9SDimitry Andric    typename regex_traits<_CharT>::char_class_type __neg_mask_;
22287a984708SDavid Chisnall    bool __negate_;
22297a984708SDavid Chisnall    bool __icase_;
22307a984708SDavid Chisnall    bool __collate_;
22317a984708SDavid Chisnall    bool __might_have_digraph_;
22327a984708SDavid Chisnall
22337a984708SDavid Chisnall    __bracket_expression(const __bracket_expression&);
22347a984708SDavid Chisnall    __bracket_expression& operator=(const __bracket_expression&);
22357a984708SDavid Chisnallpublic:
22367a984708SDavid Chisnall    typedef _VSTD::__state<_CharT> __state;
22377a984708SDavid Chisnall
22387a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
22397a984708SDavid Chisnall    __bracket_expression(const _Traits& __traits, __node<_CharT>* __s,
22407a984708SDavid Chisnall                                 bool __negate, bool __icase, bool __collate)
22417a984708SDavid Chisnall        : base(__s), __traits_(__traits), __mask_(), __neg_mask_(),
22427a984708SDavid Chisnall          __negate_(__negate), __icase_(__icase), __collate_(__collate),
22437a984708SDavid Chisnall          __might_have_digraph_(__traits_.getloc().name() != "C") {}
22447a984708SDavid Chisnall
22457a984708SDavid Chisnall    virtual void __exec(__state&) const;
22467a984708SDavid Chisnall
22477a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
22487a984708SDavid Chisnall    bool __negated() const {return __negate_;}
22497a984708SDavid Chisnall
22507a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
22517a984708SDavid Chisnall    void __add_char(_CharT __c)
22527a984708SDavid Chisnall        {
22537a984708SDavid Chisnall            if (__icase_)
22547a984708SDavid Chisnall                __chars_.push_back(__traits_.translate_nocase(__c));
22557a984708SDavid Chisnall            else if (__collate_)
22567a984708SDavid Chisnall                __chars_.push_back(__traits_.translate(__c));
22577a984708SDavid Chisnall            else
22587a984708SDavid Chisnall                __chars_.push_back(__c);
22597a984708SDavid Chisnall        }
22607a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
22617a984708SDavid Chisnall    void __add_neg_char(_CharT __c)
22627a984708SDavid Chisnall        {
22637a984708SDavid Chisnall            if (__icase_)
22647a984708SDavid Chisnall                __neg_chars_.push_back(__traits_.translate_nocase(__c));
22657a984708SDavid Chisnall            else if (__collate_)
22667a984708SDavid Chisnall                __neg_chars_.push_back(__traits_.translate(__c));
22677a984708SDavid Chisnall            else
22687a984708SDavid Chisnall                __neg_chars_.push_back(__c);
22697a984708SDavid Chisnall        }
22707a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
22717a984708SDavid Chisnall    void __add_range(string_type __b, string_type __e)
22727a984708SDavid Chisnall        {
22737a984708SDavid Chisnall            if (__collate_)
22747a984708SDavid Chisnall            {
22757a984708SDavid Chisnall                if (__icase_)
22767a984708SDavid Chisnall                {
22777a984708SDavid Chisnall                    for (size_t __i = 0; __i < __b.size(); ++__i)
22787a984708SDavid Chisnall                        __b[__i] = __traits_.translate_nocase(__b[__i]);
22797a984708SDavid Chisnall                    for (size_t __i = 0; __i < __e.size(); ++__i)
22807a984708SDavid Chisnall                        __e[__i] = __traits_.translate_nocase(__e[__i]);
22817a984708SDavid Chisnall                }
22827a984708SDavid Chisnall                else
22837a984708SDavid Chisnall                {
22847a984708SDavid Chisnall                    for (size_t __i = 0; __i < __b.size(); ++__i)
22857a984708SDavid Chisnall                        __b[__i] = __traits_.translate(__b[__i]);
22867a984708SDavid Chisnall                    for (size_t __i = 0; __i < __e.size(); ++__i)
22877a984708SDavid Chisnall                        __e[__i] = __traits_.translate(__e[__i]);
22887a984708SDavid Chisnall                }
22897a984708SDavid Chisnall                __ranges_.push_back(make_pair(
22907a984708SDavid Chisnall                                  __traits_.transform(__b.begin(), __b.end()),
22917a984708SDavid Chisnall                                  __traits_.transform(__e.begin(), __e.end())));
22927a984708SDavid Chisnall            }
22937a984708SDavid Chisnall            else
22947a984708SDavid Chisnall            {
22957a984708SDavid Chisnall                if (__b.size() != 1 || __e.size() != 1)
22969729cf09SDimitry Andric                    __throw_regex_error<regex_constants::error_collate>();
22977a984708SDavid Chisnall                if (__icase_)
22987a984708SDavid Chisnall                {
22997a984708SDavid Chisnall                    __b[0] = __traits_.translate_nocase(__b[0]);
23007a984708SDavid Chisnall                    __e[0] = __traits_.translate_nocase(__e[0]);
23017a984708SDavid Chisnall                }
23027a984708SDavid Chisnall                __ranges_.push_back(make_pair(_VSTD::move(__b), _VSTD::move(__e)));
23037a984708SDavid Chisnall            }
23047a984708SDavid Chisnall        }
23057a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
23067a984708SDavid Chisnall    void __add_digraph(_CharT __c1, _CharT __c2)
23077a984708SDavid Chisnall        {
23087a984708SDavid Chisnall            if (__icase_)
23097a984708SDavid Chisnall                __digraphs_.push_back(make_pair(__traits_.translate_nocase(__c1),
23107a984708SDavid Chisnall                                                __traits_.translate_nocase(__c2)));
23117a984708SDavid Chisnall            else if (__collate_)
23127a984708SDavid Chisnall                __digraphs_.push_back(make_pair(__traits_.translate(__c1),
23137a984708SDavid Chisnall                                                __traits_.translate(__c2)));
23147a984708SDavid Chisnall            else
23157a984708SDavid Chisnall                __digraphs_.push_back(make_pair(__c1, __c2));
23167a984708SDavid Chisnall        }
23177a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
23187a984708SDavid Chisnall    void __add_equivalence(const string_type& __s)
23197a984708SDavid Chisnall        {__equivalences_.push_back(__s);}
23207a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
2321d72607e9SDimitry Andric    void __add_class(typename regex_traits<_CharT>::char_class_type __mask)
23227a984708SDavid Chisnall        {__mask_ |= __mask;}
23237a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
2324d72607e9SDimitry Andric    void __add_neg_class(typename regex_traits<_CharT>::char_class_type __mask)
23257a984708SDavid Chisnall        {__neg_mask_ |= __mask;}
23267a984708SDavid Chisnall};
23277a984708SDavid Chisnall
23287a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
23297a984708SDavid Chisnallvoid
23307a984708SDavid Chisnall__bracket_expression<_CharT, _Traits>::__exec(__state& __s) const
23317a984708SDavid Chisnall{
23327a984708SDavid Chisnall    bool __found = false;
23337a984708SDavid Chisnall    unsigned __consumed = 0;
23347a984708SDavid Chisnall    if (__s.__current_ != __s.__last_)
23357a984708SDavid Chisnall    {
23367a984708SDavid Chisnall        ++__consumed;
23377a984708SDavid Chisnall        if (__might_have_digraph_)
23387a984708SDavid Chisnall        {
23397a984708SDavid Chisnall            const _CharT* __next = _VSTD::next(__s.__current_);
23407a984708SDavid Chisnall            if (__next != __s.__last_)
23417a984708SDavid Chisnall            {
23427a984708SDavid Chisnall                pair<_CharT, _CharT> __ch2(*__s.__current_, *__next);
23437a984708SDavid Chisnall                if (__icase_)
23447a984708SDavid Chisnall                {
23457a984708SDavid Chisnall                    __ch2.first = __traits_.translate_nocase(__ch2.first);
23467a984708SDavid Chisnall                    __ch2.second = __traits_.translate_nocase(__ch2.second);
23477a984708SDavid Chisnall                }
23487a984708SDavid Chisnall                else if (__collate_)
23497a984708SDavid Chisnall                {
23507a984708SDavid Chisnall                    __ch2.first = __traits_.translate(__ch2.first);
23517a984708SDavid Chisnall                    __ch2.second = __traits_.translate(__ch2.second);
23527a984708SDavid Chisnall                }
23537a984708SDavid Chisnall                if (!__traits_.lookup_collatename(&__ch2.first, &__ch2.first+2).empty())
23547a984708SDavid Chisnall                {
23557a984708SDavid Chisnall                    // __ch2 is a digraph in this locale
23567a984708SDavid Chisnall                    ++__consumed;
23577a984708SDavid Chisnall                    for (size_t __i = 0; __i < __digraphs_.size(); ++__i)
23587a984708SDavid Chisnall                    {
23597a984708SDavid Chisnall                        if (__ch2 == __digraphs_[__i])
23607a984708SDavid Chisnall                        {
23617a984708SDavid Chisnall                            __found = true;
23627a984708SDavid Chisnall                            goto __exit;
23637a984708SDavid Chisnall                        }
23647a984708SDavid Chisnall                    }
23657a984708SDavid Chisnall                    if (__collate_ && !__ranges_.empty())
23667a984708SDavid Chisnall                    {
23677a984708SDavid Chisnall                        string_type __s2 = __traits_.transform(&__ch2.first,
23687a984708SDavid Chisnall                                                               &__ch2.first + 2);
23697a984708SDavid Chisnall                        for (size_t __i = 0; __i < __ranges_.size(); ++__i)
23707a984708SDavid Chisnall                        {
23717a984708SDavid Chisnall                            if (__ranges_[__i].first <= __s2 &&
23727a984708SDavid Chisnall                                __s2 <= __ranges_[__i].second)
23737a984708SDavid Chisnall                            {
23747a984708SDavid Chisnall                                __found = true;
23757a984708SDavid Chisnall                                goto __exit;
23767a984708SDavid Chisnall                            }
23777a984708SDavid Chisnall                        }
23787a984708SDavid Chisnall                    }
23797a984708SDavid Chisnall                    if (!__equivalences_.empty())
23807a984708SDavid Chisnall                    {
23817a984708SDavid Chisnall                        string_type __s2 = __traits_.transform_primary(&__ch2.first,
23827a984708SDavid Chisnall                                                                       &__ch2.first + 2);
23837a984708SDavid Chisnall                        for (size_t __i = 0; __i < __equivalences_.size(); ++__i)
23847a984708SDavid Chisnall                        {
23857a984708SDavid Chisnall                            if (__s2 == __equivalences_[__i])
23867a984708SDavid Chisnall                            {
23877a984708SDavid Chisnall                                __found = true;
23887a984708SDavid Chisnall                                goto __exit;
23897a984708SDavid Chisnall                            }
23907a984708SDavid Chisnall                        }
23917a984708SDavid Chisnall                    }
23927a984708SDavid Chisnall                    if (__traits_.isctype(__ch2.first, __mask_) &&
23937a984708SDavid Chisnall                        __traits_.isctype(__ch2.second, __mask_))
23947a984708SDavid Chisnall                    {
23957a984708SDavid Chisnall                        __found = true;
23967a984708SDavid Chisnall                        goto __exit;
23977a984708SDavid Chisnall                    }
23987a984708SDavid Chisnall                    if (!__traits_.isctype(__ch2.first, __neg_mask_) &&
23997a984708SDavid Chisnall                        !__traits_.isctype(__ch2.second, __neg_mask_))
24007a984708SDavid Chisnall                    {
24017a984708SDavid Chisnall                        __found = true;
24027a984708SDavid Chisnall                        goto __exit;
24037a984708SDavid Chisnall                    }
24047a984708SDavid Chisnall                    goto __exit;
24057a984708SDavid Chisnall                }
24067a984708SDavid Chisnall            }
24077a984708SDavid Chisnall        }
24087a984708SDavid Chisnall        // test *__s.__current_ as not a digraph
24097a984708SDavid Chisnall        _CharT __ch = *__s.__current_;
24107a984708SDavid Chisnall        if (__icase_)
24117a984708SDavid Chisnall            __ch = __traits_.translate_nocase(__ch);
24127a984708SDavid Chisnall        else if (__collate_)
24137a984708SDavid Chisnall            __ch = __traits_.translate(__ch);
24147a984708SDavid Chisnall        for (size_t __i = 0; __i < __chars_.size(); ++__i)
24157a984708SDavid Chisnall        {
24167a984708SDavid Chisnall            if (__ch == __chars_[__i])
24177a984708SDavid Chisnall            {
24187a984708SDavid Chisnall                __found = true;
24197a984708SDavid Chisnall                goto __exit;
24207a984708SDavid Chisnall            }
24217a984708SDavid Chisnall        }
24224ba319b5SDimitry Andric        // When there's at least one of __neg_chars_ and __neg_mask_, the set
24234ba319b5SDimitry Andric        // of "__found" chars is
2424b2c7081bSDimitry Andric        //   union(complement(union(__neg_chars_, __neg_mask_)),
2425b2c7081bSDimitry Andric        //         other cases...)
2426b2c7081bSDimitry Andric        //
24274ba319b5SDimitry Andric        // It doesn't make sense to check this when there are no __neg_chars_
24284ba319b5SDimitry Andric        // and no __neg_mask_.
24294ba319b5SDimitry Andric        if (!(__neg_mask_ == 0 && __neg_chars_.empty()))
24307a984708SDavid Chisnall        {
24314ba319b5SDimitry Andric            const bool __in_neg_mask = __traits_.isctype(__ch, __neg_mask_);
2432b2c7081bSDimitry Andric          const bool __in_neg_chars =
2433b2c7081bSDimitry Andric              std::find(__neg_chars_.begin(), __neg_chars_.end(), __ch) !=
2434b2c7081bSDimitry Andric              __neg_chars_.end();
2435b2c7081bSDimitry Andric          if (!(__in_neg_mask || __in_neg_chars))
24367a984708SDavid Chisnall          {
24377a984708SDavid Chisnall            __found = true;
24387a984708SDavid Chisnall            goto __exit;
24397a984708SDavid Chisnall          }
2440b2c7081bSDimitry Andric        }
24417a984708SDavid Chisnall        if (!__ranges_.empty())
24427a984708SDavid Chisnall        {
24437a984708SDavid Chisnall            string_type __s2 = __collate_ ?
24447a984708SDavid Chisnall                                   __traits_.transform(&__ch, &__ch + 1) :
24457a984708SDavid Chisnall                                   string_type(1, __ch);
24467a984708SDavid Chisnall            for (size_t __i = 0; __i < __ranges_.size(); ++__i)
24477a984708SDavid Chisnall            {
24487a984708SDavid Chisnall                if (__ranges_[__i].first <= __s2 && __s2 <= __ranges_[__i].second)
24497a984708SDavid Chisnall                {
24507a984708SDavid Chisnall                    __found = true;
24517a984708SDavid Chisnall                    goto __exit;
24527a984708SDavid Chisnall                }
24537a984708SDavid Chisnall            }
24547a984708SDavid Chisnall        }
24557a984708SDavid Chisnall        if (!__equivalences_.empty())
24567a984708SDavid Chisnall        {
24577a984708SDavid Chisnall            string_type __s2 = __traits_.transform_primary(&__ch, &__ch + 1);
24587a984708SDavid Chisnall            for (size_t __i = 0; __i < __equivalences_.size(); ++__i)
24597a984708SDavid Chisnall            {
24607a984708SDavid Chisnall                if (__s2 == __equivalences_[__i])
24617a984708SDavid Chisnall                {
24627a984708SDavid Chisnall                    __found = true;
24637a984708SDavid Chisnall                    goto __exit;
24647a984708SDavid Chisnall                }
24657a984708SDavid Chisnall            }
24667a984708SDavid Chisnall        }
24677a984708SDavid Chisnall        if (__traits_.isctype(__ch, __mask_))
24687a984708SDavid Chisnall        {
24697a984708SDavid Chisnall            __found = true;
24707a984708SDavid Chisnall            goto __exit;
24717a984708SDavid Chisnall        }
24727a984708SDavid Chisnall    }
24737a984708SDavid Chisnall    else
24747a984708SDavid Chisnall        __found = __negate_;  // force reject
24757a984708SDavid Chisnall__exit:
24767a984708SDavid Chisnall    if (__found != __negate_)
24777a984708SDavid Chisnall    {
24787a984708SDavid Chisnall        __s.__do_ = __state::__accept_and_consume;
24797a984708SDavid Chisnall        __s.__current_ += __consumed;
24807a984708SDavid Chisnall        __s.__node_ = this->first();
24817a984708SDavid Chisnall    }
24827a984708SDavid Chisnall    else
24837a984708SDavid Chisnall    {
24847a984708SDavid Chisnall        __s.__do_ = __state::__reject;
24857a984708SDavid Chisnall        __s.__node_ = nullptr;
24867a984708SDavid Chisnall    }
24877a984708SDavid Chisnall}
24887a984708SDavid Chisnall
24897a984708SDavid Chisnalltemplate <class _CharT, class _Traits> class __lookahead;
24907a984708SDavid Chisnall
24917a984708SDavid Chisnalltemplate <class _CharT, class _Traits = regex_traits<_CharT> >
2492aed8d94eSDimitry Andricclass _LIBCPP_TEMPLATE_VIS basic_regex
24937a984708SDavid Chisnall{
24947a984708SDavid Chisnallpublic:
24957a984708SDavid Chisnall    // types:
24967a984708SDavid Chisnall    typedef _CharT                              value_type;
2497aed8d94eSDimitry Andric    typedef _Traits                             traits_type;
2498aed8d94eSDimitry Andric    typedef typename _Traits::string_type       string_type;
24997a984708SDavid Chisnall    typedef regex_constants::syntax_option_type flag_type;
25007a984708SDavid Chisnall    typedef typename _Traits::locale_type       locale_type;
25017a984708SDavid Chisnall
25027a984708SDavid Chisnallprivate:
25037a984708SDavid Chisnall    _Traits   __traits_;
25047a984708SDavid Chisnall    flag_type __flags_;
25057a984708SDavid Chisnall    unsigned __marked_count_;
25067a984708SDavid Chisnall    unsigned __loop_count_;
25077a984708SDavid Chisnall    int __open_count_;
25087a984708SDavid Chisnall    shared_ptr<__empty_state<_CharT> > __start_;
25097a984708SDavid Chisnall    __owns_one_state<_CharT>* __end_;
25107a984708SDavid Chisnall
25117a984708SDavid Chisnall    typedef _VSTD::__state<_CharT> __state;
25127a984708SDavid Chisnall    typedef _VSTD::__node<_CharT> __node;
25137a984708SDavid Chisnall
25147a984708SDavid Chisnallpublic:
25157a984708SDavid Chisnall    // constants:
2516936e9439SDimitry Andric    static const regex_constants::syntax_option_type icase = regex_constants::icase;
2517936e9439SDimitry Andric    static const regex_constants::syntax_option_type nosubs = regex_constants::nosubs;
2518936e9439SDimitry Andric    static const regex_constants::syntax_option_type optimize = regex_constants::optimize;
2519936e9439SDimitry Andric    static const regex_constants::syntax_option_type collate = regex_constants::collate;
2520936e9439SDimitry Andric    static const regex_constants::syntax_option_type ECMAScript = regex_constants::ECMAScript;
2521936e9439SDimitry Andric    static const regex_constants::syntax_option_type basic = regex_constants::basic;
2522936e9439SDimitry Andric    static const regex_constants::syntax_option_type extended = regex_constants::extended;
2523936e9439SDimitry Andric    static const regex_constants::syntax_option_type awk = regex_constants::awk;
2524936e9439SDimitry Andric    static const regex_constants::syntax_option_type grep = regex_constants::grep;
2525936e9439SDimitry Andric    static const regex_constants::syntax_option_type egrep = regex_constants::egrep;
25267a984708SDavid Chisnall
25277a984708SDavid Chisnall    // construct/copy/destroy:
25287a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
25297a984708SDavid Chisnall    basic_regex()
25307a984708SDavid Chisnall        : __flags_(), __marked_count_(0), __loop_count_(0), __open_count_(0),
25317a984708SDavid Chisnall          __end_(0)
25327a984708SDavid Chisnall        {}
25337a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
25347a984708SDavid Chisnall    explicit basic_regex(const value_type* __p, flag_type __f = regex_constants::ECMAScript)
25357a984708SDavid Chisnall        : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0),
25367a984708SDavid Chisnall          __end_(0)
25377a984708SDavid Chisnall        {__parse(__p, __p + __traits_.length(__p));}
25387a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
2539aed8d94eSDimitry Andric    basic_regex(const value_type* __p, size_t __len, flag_type __f = regex_constants::ECMAScript)
25407a984708SDavid Chisnall        : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0),
25417a984708SDavid Chisnall          __end_(0)
25427a984708SDavid Chisnall        {__parse(__p, __p + __len);}
25437a984708SDavid Chisnall//     basic_regex(const basic_regex&) = default;
25447a984708SDavid Chisnall//     basic_regex(basic_regex&&) = default;
25457a984708SDavid Chisnall    template <class _ST, class _SA>
25467a984708SDavid Chisnall        _LIBCPP_INLINE_VISIBILITY
25477a984708SDavid Chisnall        explicit basic_regex(const basic_string<value_type, _ST, _SA>& __p,
25487a984708SDavid Chisnall                             flag_type __f = regex_constants::ECMAScript)
25497a984708SDavid Chisnall        : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0),
25507a984708SDavid Chisnall          __end_(0)
25517a984708SDavid Chisnall        {__parse(__p.begin(), __p.end());}
25527a984708SDavid Chisnall    template <class _ForwardIterator>
25537a984708SDavid Chisnall        _LIBCPP_INLINE_VISIBILITY
25547a984708SDavid Chisnall        basic_regex(_ForwardIterator __first, _ForwardIterator __last,
25557a984708SDavid Chisnall                    flag_type __f = regex_constants::ECMAScript)
25567a984708SDavid Chisnall        : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0),
25577a984708SDavid Chisnall          __end_(0)
25587a984708SDavid Chisnall        {__parse(__first, __last);}
2559540d2a8bSDimitry Andric#ifndef _LIBCPP_CXX03_LANG
25607a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
25617a984708SDavid Chisnall    basic_regex(initializer_list<value_type> __il,
25627a984708SDavid Chisnall                flag_type __f = regex_constants::ECMAScript)
25637a984708SDavid Chisnall        : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0),
25647a984708SDavid Chisnall          __end_(0)
25657a984708SDavid Chisnall        {__parse(__il.begin(), __il.end());}
2566540d2a8bSDimitry Andric#endif  // _LIBCPP_CXX03_LANG
25677a984708SDavid Chisnall
25687a984708SDavid Chisnall//    ~basic_regex() = default;
25697a984708SDavid Chisnall
25707a984708SDavid Chisnall//     basic_regex& operator=(const basic_regex&) = default;
25717a984708SDavid Chisnall//     basic_regex& operator=(basic_regex&&) = default;
25727a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
25737a984708SDavid Chisnall    basic_regex& operator=(const value_type* __p)
25747a984708SDavid Chisnall        {return assign(__p);}
2575540d2a8bSDimitry Andric#ifndef _LIBCPP_CXX03_LANG
25767a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
25777a984708SDavid Chisnall    basic_regex& operator=(initializer_list<value_type> __il)
25787a984708SDavid Chisnall        {return assign(__il);}
2579540d2a8bSDimitry Andric#endif  // _LIBCPP_CXX03_LANG
25807a984708SDavid Chisnall    template <class _ST, class _SA>
25817a984708SDavid Chisnall        _LIBCPP_INLINE_VISIBILITY
25827a984708SDavid Chisnall        basic_regex& operator=(const basic_string<value_type, _ST, _SA>& __p)
25837a984708SDavid Chisnall        {return assign(__p);}
25847a984708SDavid Chisnall
25857a984708SDavid Chisnall    // assign:
25867a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
25877a984708SDavid Chisnall    basic_regex& assign(const basic_regex& __that)
25887a984708SDavid Chisnall        {return *this = __that;}
2589540d2a8bSDimitry Andric#ifndef _LIBCPP_CXX03_LANG
2590936e9439SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
2591936e9439SDimitry Andric    basic_regex& assign(basic_regex&& __that) _NOEXCEPT
2592936e9439SDimitry Andric        {return *this = _VSTD::move(__that);}
2593936e9439SDimitry Andric#endif
25947a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
25957a984708SDavid Chisnall    basic_regex& assign(const value_type* __p, flag_type __f = regex_constants::ECMAScript)
25967a984708SDavid Chisnall        {return assign(__p, __p + __traits_.length(__p), __f);}
25977a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
25987a984708SDavid Chisnall    basic_regex& assign(const value_type* __p, size_t __len, flag_type __f)
25997a984708SDavid Chisnall        {return assign(__p, __p + __len, __f);}
26007a984708SDavid Chisnall    template <class _ST, class _SA>
26017a984708SDavid Chisnall        _LIBCPP_INLINE_VISIBILITY
26027a984708SDavid Chisnall        basic_regex& assign(const basic_string<value_type, _ST, _SA>& __s,
26037a984708SDavid Chisnall                            flag_type __f = regex_constants::ECMAScript)
26047a984708SDavid Chisnall            {return assign(__s.begin(), __s.end(), __f);}
26057a984708SDavid Chisnall
26067a984708SDavid Chisnall    template <class _InputIterator>
26077a984708SDavid Chisnall        _LIBCPP_INLINE_VISIBILITY
26087a984708SDavid Chisnall        typename enable_if
26097a984708SDavid Chisnall        <
26107a984708SDavid Chisnall             __is_input_iterator  <_InputIterator>::value &&
26117a984708SDavid Chisnall            !__is_forward_iterator<_InputIterator>::value,
26127a984708SDavid Chisnall            basic_regex&
26137a984708SDavid Chisnall        >::type
26147a984708SDavid Chisnall        assign(_InputIterator __first, _InputIterator __last,
26157a984708SDavid Chisnall                            flag_type __f = regex_constants::ECMAScript)
26167a984708SDavid Chisnall        {
26177a984708SDavid Chisnall            basic_string<_CharT> __t(__first, __last);
26187a984708SDavid Chisnall            return assign(__t.begin(), __t.end(), __f);
26197a984708SDavid Chisnall        }
26207a984708SDavid Chisnall
26217a984708SDavid Chisnallprivate:
26227a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
26237a984708SDavid Chisnall    void __member_init(flag_type __f)
26247a984708SDavid Chisnall    {
26257a984708SDavid Chisnall        __flags_ = __f;
26267a984708SDavid Chisnall        __marked_count_ = 0;
26277a984708SDavid Chisnall        __loop_count_ = 0;
26287a984708SDavid Chisnall        __open_count_ = 0;
26297a984708SDavid Chisnall        __end_ = nullptr;
26307a984708SDavid Chisnall    }
26317a984708SDavid Chisnallpublic:
26327a984708SDavid Chisnall
26337a984708SDavid Chisnall    template <class _ForwardIterator>
26347a984708SDavid Chisnall        _LIBCPP_INLINE_VISIBILITY
26357a984708SDavid Chisnall        typename enable_if
26367a984708SDavid Chisnall        <
26377a984708SDavid Chisnall            __is_forward_iterator<_ForwardIterator>::value,
26387a984708SDavid Chisnall            basic_regex&
26397a984708SDavid Chisnall        >::type
26407a984708SDavid Chisnall        assign(_ForwardIterator __first, _ForwardIterator __last,
26417a984708SDavid Chisnall                            flag_type __f = regex_constants::ECMAScript)
26427a984708SDavid Chisnall        {
2643854fa44bSDimitry Andric            return assign(basic_regex(__first, __last, __f));
26447a984708SDavid Chisnall        }
26457a984708SDavid Chisnall
2646540d2a8bSDimitry Andric#ifndef _LIBCPP_CXX03_LANG
26477a984708SDavid Chisnall
26487a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
26497a984708SDavid Chisnall    basic_regex& assign(initializer_list<value_type> __il,
26507a984708SDavid Chisnall                        flag_type __f = regex_constants::ECMAScript)
26517a984708SDavid Chisnall        {return assign(__il.begin(), __il.end(), __f);}
26527a984708SDavid Chisnall
2653540d2a8bSDimitry Andric#endif  // _LIBCPP_CXX03_LANG
26547a984708SDavid Chisnall
26557a984708SDavid Chisnall    // const operations:
26567a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
26577a984708SDavid Chisnall    unsigned mark_count() const {return __marked_count_;}
26587a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
26597a984708SDavid Chisnall    flag_type flags() const {return __flags_;}
26607a984708SDavid Chisnall
26617a984708SDavid Chisnall    // locale:
26627a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
26637a984708SDavid Chisnall    locale_type imbue(locale_type __loc)
26647a984708SDavid Chisnall    {
26657a984708SDavid Chisnall        __member_init(ECMAScript);
26667a984708SDavid Chisnall        __start_.reset();
26677a984708SDavid Chisnall        return __traits_.imbue(__loc);
26687a984708SDavid Chisnall    }
26697a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
26707a984708SDavid Chisnall    locale_type getloc() const {return __traits_.getloc();}
26717a984708SDavid Chisnall
26727a984708SDavid Chisnall    // swap:
26737a984708SDavid Chisnall    void swap(basic_regex& __r);
26747a984708SDavid Chisnall
26757a984708SDavid Chisnallprivate:
26767a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
26777a984708SDavid Chisnall    unsigned __loop_count() const {return __loop_count_;}
26787a984708SDavid Chisnall
26797a984708SDavid Chisnall    template <class _ForwardIterator>
26807a984708SDavid Chisnall        _ForwardIterator
26817a984708SDavid Chisnall        __parse(_ForwardIterator __first, _ForwardIterator __last);
26827a984708SDavid Chisnall    template <class _ForwardIterator>
26837a984708SDavid Chisnall        _ForwardIterator
26847a984708SDavid Chisnall        __parse_basic_reg_exp(_ForwardIterator __first, _ForwardIterator __last);
26857a984708SDavid Chisnall    template <class _ForwardIterator>
26867a984708SDavid Chisnall        _ForwardIterator
26877a984708SDavid Chisnall        __parse_RE_expression(_ForwardIterator __first, _ForwardIterator __last);
26887a984708SDavid Chisnall    template <class _ForwardIterator>
26897a984708SDavid Chisnall        _ForwardIterator
26907a984708SDavid Chisnall        __parse_simple_RE(_ForwardIterator __first, _ForwardIterator __last);
26917a984708SDavid Chisnall    template <class _ForwardIterator>
26927a984708SDavid Chisnall        _ForwardIterator
26937a984708SDavid Chisnall        __parse_nondupl_RE(_ForwardIterator __first, _ForwardIterator __last);
26947a984708SDavid Chisnall    template <class _ForwardIterator>
26957a984708SDavid Chisnall        _ForwardIterator
26967a984708SDavid Chisnall        __parse_one_char_or_coll_elem_RE(_ForwardIterator __first, _ForwardIterator __last);
26977a984708SDavid Chisnall    template <class _ForwardIterator>
26987a984708SDavid Chisnall        _ForwardIterator
26997a984708SDavid Chisnall        __parse_Back_open_paren(_ForwardIterator __first, _ForwardIterator __last);
27007a984708SDavid Chisnall    template <class _ForwardIterator>
27017a984708SDavid Chisnall        _ForwardIterator
27027a984708SDavid Chisnall        __parse_Back_close_paren(_ForwardIterator __first, _ForwardIterator __last);
27037a984708SDavid Chisnall    template <class _ForwardIterator>
27047a984708SDavid Chisnall        _ForwardIterator
27057a984708SDavid Chisnall        __parse_Back_open_brace(_ForwardIterator __first, _ForwardIterator __last);
27067a984708SDavid Chisnall    template <class _ForwardIterator>
27077a984708SDavid Chisnall        _ForwardIterator
27087a984708SDavid Chisnall        __parse_Back_close_brace(_ForwardIterator __first, _ForwardIterator __last);
27097a984708SDavid Chisnall    template <class _ForwardIterator>
27107a984708SDavid Chisnall        _ForwardIterator
27117a984708SDavid Chisnall        __parse_BACKREF(_ForwardIterator __first, _ForwardIterator __last);
27127a984708SDavid Chisnall    template <class _ForwardIterator>
27137a984708SDavid Chisnall        _ForwardIterator
27147a984708SDavid Chisnall        __parse_ORD_CHAR(_ForwardIterator __first, _ForwardIterator __last);
27157a984708SDavid Chisnall    template <class _ForwardIterator>
27167a984708SDavid Chisnall        _ForwardIterator
27177a984708SDavid Chisnall        __parse_QUOTED_CHAR(_ForwardIterator __first, _ForwardIterator __last);
27187a984708SDavid Chisnall    template <class _ForwardIterator>
27197a984708SDavid Chisnall        _ForwardIterator
27207a984708SDavid Chisnall        __parse_RE_dupl_symbol(_ForwardIterator __first, _ForwardIterator __last,
27217a984708SDavid Chisnall                               __owns_one_state<_CharT>* __s,
27227a984708SDavid Chisnall                               unsigned __mexp_begin, unsigned __mexp_end);
27237a984708SDavid Chisnall    template <class _ForwardIterator>
27247a984708SDavid Chisnall        _ForwardIterator
27257a984708SDavid Chisnall        __parse_ERE_dupl_symbol(_ForwardIterator __first, _ForwardIterator __last,
27267a984708SDavid Chisnall                                __owns_one_state<_CharT>* __s,
27277a984708SDavid Chisnall                                unsigned __mexp_begin, unsigned __mexp_end);
27287a984708SDavid Chisnall    template <class _ForwardIterator>
27297a984708SDavid Chisnall        _ForwardIterator
27307a984708SDavid Chisnall        __parse_bracket_expression(_ForwardIterator __first, _ForwardIterator __last);
27317a984708SDavid Chisnall    template <class _ForwardIterator>
27327a984708SDavid Chisnall        _ForwardIterator
27337a984708SDavid Chisnall        __parse_follow_list(_ForwardIterator __first, _ForwardIterator __last,
27347a984708SDavid Chisnall                            __bracket_expression<_CharT, _Traits>* __ml);
27357a984708SDavid Chisnall    template <class _ForwardIterator>
27367a984708SDavid Chisnall        _ForwardIterator
27377a984708SDavid Chisnall        __parse_expression_term(_ForwardIterator __first, _ForwardIterator __last,
27387a984708SDavid Chisnall                                __bracket_expression<_CharT, _Traits>* __ml);
27397a984708SDavid Chisnall    template <class _ForwardIterator>
27407a984708SDavid Chisnall        _ForwardIterator
27417a984708SDavid Chisnall        __parse_equivalence_class(_ForwardIterator __first, _ForwardIterator __last,
27427a984708SDavid Chisnall                                  __bracket_expression<_CharT, _Traits>* __ml);
27437a984708SDavid Chisnall    template <class _ForwardIterator>
27447a984708SDavid Chisnall        _ForwardIterator
27457a984708SDavid Chisnall        __parse_character_class(_ForwardIterator __first, _ForwardIterator __last,
27467a984708SDavid Chisnall                                __bracket_expression<_CharT, _Traits>* __ml);
27477a984708SDavid Chisnall    template <class _ForwardIterator>
27487a984708SDavid Chisnall        _ForwardIterator
27497a984708SDavid Chisnall        __parse_collating_symbol(_ForwardIterator __first, _ForwardIterator __last,
27507a984708SDavid Chisnall                                 basic_string<_CharT>& __col_sym);
27517a984708SDavid Chisnall    template <class _ForwardIterator>
27527a984708SDavid Chisnall        _ForwardIterator
27537a984708SDavid Chisnall        __parse_DUP_COUNT(_ForwardIterator __first, _ForwardIterator __last, int& __c);
27547a984708SDavid Chisnall    template <class _ForwardIterator>
27557a984708SDavid Chisnall        _ForwardIterator
27567a984708SDavid Chisnall        __parse_extended_reg_exp(_ForwardIterator __first, _ForwardIterator __last);
27577a984708SDavid Chisnall    template <class _ForwardIterator>
27587a984708SDavid Chisnall        _ForwardIterator
27597a984708SDavid Chisnall        __parse_ERE_branch(_ForwardIterator __first, _ForwardIterator __last);
27607a984708SDavid Chisnall    template <class _ForwardIterator>
27617a984708SDavid Chisnall        _ForwardIterator
27627a984708SDavid Chisnall        __parse_ERE_expression(_ForwardIterator __first, _ForwardIterator __last);
27637a984708SDavid Chisnall    template <class _ForwardIterator>
27647a984708SDavid Chisnall        _ForwardIterator
27657a984708SDavid Chisnall        __parse_one_char_or_coll_elem_ERE(_ForwardIterator __first, _ForwardIterator __last);
27667a984708SDavid Chisnall    template <class _ForwardIterator>
27677a984708SDavid Chisnall        _ForwardIterator
27687a984708SDavid Chisnall        __parse_ORD_CHAR_ERE(_ForwardIterator __first, _ForwardIterator __last);
27697a984708SDavid Chisnall    template <class _ForwardIterator>
27707a984708SDavid Chisnall        _ForwardIterator
27717a984708SDavid Chisnall        __parse_QUOTED_CHAR_ERE(_ForwardIterator __first, _ForwardIterator __last);
27727a984708SDavid Chisnall    template <class _ForwardIterator>
27737a984708SDavid Chisnall        _ForwardIterator
27747a984708SDavid Chisnall        __parse_ecma_exp(_ForwardIterator __first, _ForwardIterator __last);
27757a984708SDavid Chisnall    template <class _ForwardIterator>
27767a984708SDavid Chisnall        _ForwardIterator
27777a984708SDavid Chisnall        __parse_alternative(_ForwardIterator __first, _ForwardIterator __last);
27787a984708SDavid Chisnall    template <class _ForwardIterator>
27797a984708SDavid Chisnall        _ForwardIterator
27807a984708SDavid Chisnall        __parse_term(_ForwardIterator __first, _ForwardIterator __last);
27817a984708SDavid Chisnall    template <class _ForwardIterator>
27827a984708SDavid Chisnall        _ForwardIterator
27837a984708SDavid Chisnall        __parse_assertion(_ForwardIterator __first, _ForwardIterator __last);
27847a984708SDavid Chisnall    template <class _ForwardIterator>
27857a984708SDavid Chisnall        _ForwardIterator
27867a984708SDavid Chisnall        __parse_atom(_ForwardIterator __first, _ForwardIterator __last);
27877a984708SDavid Chisnall    template <class _ForwardIterator>
27887a984708SDavid Chisnall        _ForwardIterator
27897a984708SDavid Chisnall        __parse_atom_escape(_ForwardIterator __first, _ForwardIterator __last);
27907a984708SDavid Chisnall    template <class _ForwardIterator>
27917a984708SDavid Chisnall        _ForwardIterator
27927a984708SDavid Chisnall        __parse_decimal_escape(_ForwardIterator __first, _ForwardIterator __last);
27937a984708SDavid Chisnall    template <class _ForwardIterator>
27947a984708SDavid Chisnall        _ForwardIterator
27957a984708SDavid Chisnall        __parse_character_class_escape(_ForwardIterator __first, _ForwardIterator __last);
27967a984708SDavid Chisnall    template <class _ForwardIterator>
27977a984708SDavid Chisnall        _ForwardIterator
27987a984708SDavid Chisnall        __parse_character_escape(_ForwardIterator __first, _ForwardIterator __last,
27997a984708SDavid Chisnall                                 basic_string<_CharT>* __str = nullptr);
28007a984708SDavid Chisnall    template <class _ForwardIterator>
28017a984708SDavid Chisnall        _ForwardIterator
28027a984708SDavid Chisnall        __parse_pattern_character(_ForwardIterator __first, _ForwardIterator __last);
28037a984708SDavid Chisnall    template <class _ForwardIterator>
28047a984708SDavid Chisnall        _ForwardIterator
28057a984708SDavid Chisnall        __parse_grep(_ForwardIterator __first, _ForwardIterator __last);
28067a984708SDavid Chisnall    template <class _ForwardIterator>
28077a984708SDavid Chisnall        _ForwardIterator
28087a984708SDavid Chisnall        __parse_egrep(_ForwardIterator __first, _ForwardIterator __last);
28097a984708SDavid Chisnall    template <class _ForwardIterator>
28107a984708SDavid Chisnall        _ForwardIterator
28117a984708SDavid Chisnall        __parse_class_escape(_ForwardIterator __first, _ForwardIterator __last,
28127a984708SDavid Chisnall                          basic_string<_CharT>& __str,
28137a984708SDavid Chisnall                          __bracket_expression<_CharT, _Traits>* __ml);
28147a984708SDavid Chisnall    template <class _ForwardIterator>
28157a984708SDavid Chisnall        _ForwardIterator
28167a984708SDavid Chisnall        __parse_awk_escape(_ForwardIterator __first, _ForwardIterator __last,
28177a984708SDavid Chisnall                          basic_string<_CharT>* __str = nullptr);
28187a984708SDavid Chisnall
28197a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
28207a984708SDavid Chisnall    void __push_l_anchor();
28217a984708SDavid Chisnall    void __push_r_anchor();
28227a984708SDavid Chisnall    void __push_match_any();
28237a984708SDavid Chisnall    void __push_match_any_but_newline();
28247a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
28257a984708SDavid Chisnall    void __push_greedy_inf_repeat(size_t __min, __owns_one_state<_CharT>* __s,
28267a984708SDavid Chisnall                                  unsigned __mexp_begin = 0, unsigned __mexp_end = 0)
28277a984708SDavid Chisnall        {__push_loop(__min, numeric_limits<size_t>::max(), __s,
28287a984708SDavid Chisnall                     __mexp_begin, __mexp_end);}
28297a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
28307a984708SDavid Chisnall    void __push_nongreedy_inf_repeat(size_t __min, __owns_one_state<_CharT>* __s,
28317a984708SDavid Chisnall                                  unsigned __mexp_begin = 0, unsigned __mexp_end = 0)
28327a984708SDavid Chisnall        {__push_loop(__min, numeric_limits<size_t>::max(), __s,
28337a984708SDavid Chisnall                     __mexp_begin, __mexp_end, false);}
28347a984708SDavid Chisnall    void __push_loop(size_t __min, size_t __max, __owns_one_state<_CharT>* __s,
28357a984708SDavid Chisnall                     size_t __mexp_begin = 0, size_t __mexp_end = 0,
28367a984708SDavid Chisnall                     bool __greedy = true);
28377a984708SDavid Chisnall    __bracket_expression<_CharT, _Traits>* __start_matching_list(bool __negate);
28387a984708SDavid Chisnall    void __push_char(value_type __c);
28397a984708SDavid Chisnall    void __push_back_ref(int __i);
28407a984708SDavid Chisnall    void __push_alternation(__owns_one_state<_CharT>* __sa,
28417a984708SDavid Chisnall                            __owns_one_state<_CharT>* __sb);
28427a984708SDavid Chisnall    void __push_begin_marked_subexpression();
28437a984708SDavid Chisnall    void __push_end_marked_subexpression(unsigned);
28447a984708SDavid Chisnall    void __push_empty();
28457a984708SDavid Chisnall    void __push_word_boundary(bool);
28464f7ab58eSDimitry Andric    void __push_lookahead(const basic_regex&, bool, unsigned);
28477a984708SDavid Chisnall
28487a984708SDavid Chisnall    template <class _Allocator>
28497a984708SDavid Chisnall        bool
28507a984708SDavid Chisnall        __search(const _CharT* __first, const _CharT* __last,
28517a984708SDavid Chisnall                 match_results<const _CharT*, _Allocator>& __m,
28527a984708SDavid Chisnall                 regex_constants::match_flag_type __flags) const;
28537a984708SDavid Chisnall
28547a984708SDavid Chisnall    template <class _Allocator>
28557a984708SDavid Chisnall        bool
28567a984708SDavid Chisnall        __match_at_start(const _CharT* __first, const _CharT* __last,
28577a984708SDavid Chisnall                 match_results<const _CharT*, _Allocator>& __m,
28587a984708SDavid Chisnall                 regex_constants::match_flag_type __flags, bool) const;
28597a984708SDavid Chisnall    template <class _Allocator>
28607a984708SDavid Chisnall        bool
28617a984708SDavid Chisnall        __match_at_start_ecma(const _CharT* __first, const _CharT* __last,
28627a984708SDavid Chisnall                 match_results<const _CharT*, _Allocator>& __m,
28637a984708SDavid Chisnall                 regex_constants::match_flag_type __flags, bool) const;
28647a984708SDavid Chisnall    template <class _Allocator>
28657a984708SDavid Chisnall        bool
28667a984708SDavid Chisnall        __match_at_start_posix_nosubs(const _CharT* __first, const _CharT* __last,
28677a984708SDavid Chisnall                 match_results<const _CharT*, _Allocator>& __m,
28687a984708SDavid Chisnall                 regex_constants::match_flag_type __flags, bool) const;
28697a984708SDavid Chisnall    template <class _Allocator>
28707a984708SDavid Chisnall        bool
28717a984708SDavid Chisnall        __match_at_start_posix_subs(const _CharT* __first, const _CharT* __last,
28727a984708SDavid Chisnall                 match_results<const _CharT*, _Allocator>& __m,
28737a984708SDavid Chisnall                 regex_constants::match_flag_type __flags, bool) const;
28747a984708SDavid Chisnall
287594e3ee44SDavid Chisnall    template <class _Bp, class _Ap, class _Cp, class _Tp>
28767a984708SDavid Chisnall    friend
28777a984708SDavid Chisnall    bool
287894e3ee44SDavid Chisnall    regex_search(_Bp, _Bp, match_results<_Bp, _Ap>&, const basic_regex<_Cp, _Tp>&,
28797a984708SDavid Chisnall                 regex_constants::match_flag_type);
28807a984708SDavid Chisnall
288194e3ee44SDavid Chisnall    template <class _Ap, class _Cp, class _Tp>
28827a984708SDavid Chisnall    friend
28837a984708SDavid Chisnall    bool
288494e3ee44SDavid Chisnall    regex_search(const _Cp*, const _Cp*, match_results<const _Cp*, _Ap>&,
288594e3ee44SDavid Chisnall                 const basic_regex<_Cp, _Tp>&, regex_constants::match_flag_type);
28867a984708SDavid Chisnall
288794e3ee44SDavid Chisnall    template <class _Bp, class _Cp, class _Tp>
28887a984708SDavid Chisnall    friend
28897a984708SDavid Chisnall    bool
289094e3ee44SDavid Chisnall    regex_search(_Bp, _Bp, const basic_regex<_Cp, _Tp>&,
28917a984708SDavid Chisnall                 regex_constants::match_flag_type);
28927a984708SDavid Chisnall
289394e3ee44SDavid Chisnall    template <class _Cp, class _Tp>
28947a984708SDavid Chisnall    friend
28957a984708SDavid Chisnall    bool
289694e3ee44SDavid Chisnall    regex_search(const _Cp*, const _Cp*,
289794e3ee44SDavid Chisnall                 const basic_regex<_Cp, _Tp>&, regex_constants::match_flag_type);
28987a984708SDavid Chisnall
289994e3ee44SDavid Chisnall    template <class _Cp, class _Ap, class _Tp>
29007a984708SDavid Chisnall    friend
29017a984708SDavid Chisnall    bool
290294e3ee44SDavid Chisnall    regex_search(const _Cp*, match_results<const _Cp*, _Ap>&, const basic_regex<_Cp, _Tp>&,
29037a984708SDavid Chisnall                 regex_constants::match_flag_type);
29047a984708SDavid Chisnall
290594e3ee44SDavid Chisnall    template <class _ST, class _SA, class _Cp, class _Tp>
29067a984708SDavid Chisnall    friend
29077a984708SDavid Chisnall    bool
290894e3ee44SDavid Chisnall    regex_search(const basic_string<_Cp, _ST, _SA>& __s,
290994e3ee44SDavid Chisnall                 const basic_regex<_Cp, _Tp>& __e,
29107a984708SDavid Chisnall                 regex_constants::match_flag_type __flags);
29117a984708SDavid Chisnall
291294e3ee44SDavid Chisnall    template <class _ST, class _SA, class _Ap, class _Cp, class _Tp>
29137a984708SDavid Chisnall    friend
29147a984708SDavid Chisnall    bool
291594e3ee44SDavid Chisnall    regex_search(const basic_string<_Cp, _ST, _SA>& __s,
291694e3ee44SDavid Chisnall                 match_results<typename basic_string<_Cp, _ST, _SA>::const_iterator, _Ap>&,
291794e3ee44SDavid Chisnall                 const basic_regex<_Cp, _Tp>& __e,
29187a984708SDavid Chisnall                 regex_constants::match_flag_type __flags);
29197a984708SDavid Chisnall
29204bab9fd9SDavid Chisnall    template <class _Iter, class _Ap, class _Cp, class _Tp>
29214bab9fd9SDavid Chisnall    friend
29224bab9fd9SDavid Chisnall    bool
29234bab9fd9SDavid Chisnall    regex_search(__wrap_iter<_Iter> __first,
29244bab9fd9SDavid Chisnall                 __wrap_iter<_Iter> __last,
29254bab9fd9SDavid Chisnall                 match_results<__wrap_iter<_Iter>, _Ap>& __m,
29264bab9fd9SDavid Chisnall                 const basic_regex<_Cp, _Tp>& __e,
29274bab9fd9SDavid Chisnall                 regex_constants::match_flag_type __flags);
29284bab9fd9SDavid Chisnall
29297a984708SDavid Chisnall    template <class, class> friend class __lookahead;
29307a984708SDavid Chisnall};
29317a984708SDavid Chisnall
29324ba319b5SDimitry Andric#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
29334ba319b5SDimitry Andrictemplate <class _ForwardIterator,
29344ba319b5SDimitry Andric          class = typename enable_if<__is_forward_iterator<_ForwardIterator>::value, nullptr_t>::type
29354ba319b5SDimitry Andric>
29364ba319b5SDimitry Andricbasic_regex(_ForwardIterator, _ForwardIterator,
29374ba319b5SDimitry Andric            regex_constants::syntax_option_type = regex_constants::ECMAScript)
29384ba319b5SDimitry Andric    -> basic_regex<typename iterator_traits<_ForwardIterator>::value_type>;
29394ba319b5SDimitry Andric#endif
29404ba319b5SDimitry Andric
29417a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
2942cfdf2879SDavid Chisnall    const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::icase;
2943cfdf2879SDavid Chisnalltemplate <class _CharT, class _Traits>
2944cfdf2879SDavid Chisnall    const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::nosubs;
2945cfdf2879SDavid Chisnalltemplate <class _CharT, class _Traits>
2946cfdf2879SDavid Chisnall    const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::optimize;
2947cfdf2879SDavid Chisnalltemplate <class _CharT, class _Traits>
2948cfdf2879SDavid Chisnall    const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::collate;
2949cfdf2879SDavid Chisnalltemplate <class _CharT, class _Traits>
2950cfdf2879SDavid Chisnall    const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::ECMAScript;
2951cfdf2879SDavid Chisnalltemplate <class _CharT, class _Traits>
2952cfdf2879SDavid Chisnall    const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::basic;
2953cfdf2879SDavid Chisnalltemplate <class _CharT, class _Traits>
2954cfdf2879SDavid Chisnall    const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::extended;
2955cfdf2879SDavid Chisnalltemplate <class _CharT, class _Traits>
2956cfdf2879SDavid Chisnall    const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::awk;
2957cfdf2879SDavid Chisnalltemplate <class _CharT, class _Traits>
2958cfdf2879SDavid Chisnall    const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::grep;
2959cfdf2879SDavid Chisnalltemplate <class _CharT, class _Traits>
2960cfdf2879SDavid Chisnall    const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::egrep;
2961cfdf2879SDavid Chisnall
2962cfdf2879SDavid Chisnalltemplate <class _CharT, class _Traits>
29637a984708SDavid Chisnallvoid
29647a984708SDavid Chisnallbasic_regex<_CharT, _Traits>::swap(basic_regex& __r)
29657a984708SDavid Chisnall{
29667a984708SDavid Chisnall    using _VSTD::swap;
29677a984708SDavid Chisnall    swap(__traits_, __r.__traits_);
29687a984708SDavid Chisnall    swap(__flags_, __r.__flags_);
29697a984708SDavid Chisnall    swap(__marked_count_, __r.__marked_count_);
29707a984708SDavid Chisnall    swap(__loop_count_, __r.__loop_count_);
29717a984708SDavid Chisnall    swap(__open_count_, __r.__open_count_);
29727a984708SDavid Chisnall    swap(__start_, __r.__start_);
29737a984708SDavid Chisnall    swap(__end_, __r.__end_);
29747a984708SDavid Chisnall}
29757a984708SDavid Chisnall
29767a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
29777a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
29787a984708SDavid Chisnallvoid
29797a984708SDavid Chisnallswap(basic_regex<_CharT, _Traits>& __x, basic_regex<_CharT, _Traits>& __y)
29807a984708SDavid Chisnall{
29817a984708SDavid Chisnall    return __x.swap(__y);
29827a984708SDavid Chisnall}
29837a984708SDavid Chisnall
29847a984708SDavid Chisnall// __lookahead
29857a984708SDavid Chisnall
29867a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
29877a984708SDavid Chisnallclass __lookahead
29887a984708SDavid Chisnall    : public __owns_one_state<_CharT>
29897a984708SDavid Chisnall{
29907a984708SDavid Chisnall    typedef __owns_one_state<_CharT> base;
29917a984708SDavid Chisnall
29927a984708SDavid Chisnall    basic_regex<_CharT, _Traits> __exp_;
29934f7ab58eSDimitry Andric    unsigned __mexp_;
29947a984708SDavid Chisnall    bool __invert_;
29957a984708SDavid Chisnall
29967a984708SDavid Chisnall    __lookahead(const __lookahead&);
29977a984708SDavid Chisnall    __lookahead& operator=(const __lookahead&);
29987a984708SDavid Chisnallpublic:
29997a984708SDavid Chisnall    typedef _VSTD::__state<_CharT> __state;
30007a984708SDavid Chisnall
30017a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
30024f7ab58eSDimitry Andric    __lookahead(const basic_regex<_CharT, _Traits>& __exp, bool __invert, __node<_CharT>* __s, unsigned __mexp)
30039729cf09SDimitry Andric        : base(__s), __exp_(__exp), __mexp_(__mexp), __invert_(__invert) {}
30047a984708SDavid Chisnall
30057a984708SDavid Chisnall    virtual void __exec(__state&) const;
30067a984708SDavid Chisnall};
30077a984708SDavid Chisnall
30087a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
30097a984708SDavid Chisnallvoid
30107a984708SDavid Chisnall__lookahead<_CharT, _Traits>::__exec(__state& __s) const
30117a984708SDavid Chisnall{
30127a984708SDavid Chisnall    match_results<const _CharT*> __m;
30137a984708SDavid Chisnall    __m.__init(1 + __exp_.mark_count(), __s.__current_, __s.__last_);
3014aed8d94eSDimitry Andric    bool __matched = __exp_.__match_at_start_ecma(
3015aed8d94eSDimitry Andric        __s.__current_, __s.__last_,
30167a984708SDavid Chisnall        __m,
3017aed8d94eSDimitry Andric        (__s.__flags_ | regex_constants::match_continuous) &
3018aed8d94eSDimitry Andric        ~regex_constants::__full_match,
30194bab9fd9SDavid Chisnall        __s.__at_first_ && __s.__current_ == __s.__first_);
30207a984708SDavid Chisnall    if (__matched != __invert_)
30217a984708SDavid Chisnall    {
30227a984708SDavid Chisnall        __s.__do_ = __state::__accept_but_not_consume;
30237a984708SDavid Chisnall        __s.__node_ = this->first();
30244f7ab58eSDimitry Andric        for (unsigned __i = 1; __i < __m.size(); ++__i) {
30254f7ab58eSDimitry Andric            __s.__sub_matches_[__mexp_ + __i - 1] = __m.__matches_[__i];
30264f7ab58eSDimitry Andric        }
30277a984708SDavid Chisnall    }
30287a984708SDavid Chisnall    else
30297a984708SDavid Chisnall    {
30307a984708SDavid Chisnall        __s.__do_ = __state::__reject;
30317a984708SDavid Chisnall        __s.__node_ = nullptr;
30327a984708SDavid Chisnall    }
30337a984708SDavid Chisnall}
30347a984708SDavid Chisnall
30357a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
30367a984708SDavid Chisnalltemplate <class _ForwardIterator>
30377a984708SDavid Chisnall_ForwardIterator
30387a984708SDavid Chisnallbasic_regex<_CharT, _Traits>::__parse(_ForwardIterator __first,
30397a984708SDavid Chisnall                                      _ForwardIterator __last)
30407a984708SDavid Chisnall{
30417a984708SDavid Chisnall    {
30427a984708SDavid Chisnall        unique_ptr<__node> __h(new __end_state<_CharT>);
30437a984708SDavid Chisnall        __start_.reset(new __empty_state<_CharT>(__h.get()));
30447a984708SDavid Chisnall        __h.release();
30457a984708SDavid Chisnall        __end_ = __start_.get();
30467a984708SDavid Chisnall    }
30477a984708SDavid Chisnall    switch (__flags_ & 0x1F0)
30487a984708SDavid Chisnall    {
30497a984708SDavid Chisnall    case ECMAScript:
30507a984708SDavid Chisnall        __first = __parse_ecma_exp(__first, __last);
30517a984708SDavid Chisnall        break;
30527a984708SDavid Chisnall    case basic:
30537a984708SDavid Chisnall        __first = __parse_basic_reg_exp(__first, __last);
30547a984708SDavid Chisnall        break;
30557a984708SDavid Chisnall    case extended:
30567a984708SDavid Chisnall    case awk:
30577a984708SDavid Chisnall        __first = __parse_extended_reg_exp(__first, __last);
30587a984708SDavid Chisnall        break;
30597a984708SDavid Chisnall    case grep:
30607a984708SDavid Chisnall        __first = __parse_grep(__first, __last);
30617a984708SDavid Chisnall        break;
30627a984708SDavid Chisnall    case egrep:
30637a984708SDavid Chisnall        __first = __parse_egrep(__first, __last);
30647a984708SDavid Chisnall        break;
30657a984708SDavid Chisnall    default:
30669729cf09SDimitry Andric        __throw_regex_error<regex_constants::__re_err_grammar>();
30677a984708SDavid Chisnall    }
30687a984708SDavid Chisnall    return __first;
30697a984708SDavid Chisnall}
30707a984708SDavid Chisnall
30717a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
30727a984708SDavid Chisnalltemplate <class _ForwardIterator>
30737a984708SDavid Chisnall_ForwardIterator
30747a984708SDavid Chisnallbasic_regex<_CharT, _Traits>::__parse_basic_reg_exp(_ForwardIterator __first,
30757a984708SDavid Chisnall                                                    _ForwardIterator __last)
30767a984708SDavid Chisnall{
30777a984708SDavid Chisnall    if (__first != __last)
30787a984708SDavid Chisnall    {
30797a984708SDavid Chisnall        if (*__first == '^')
30807a984708SDavid Chisnall        {
30817a984708SDavid Chisnall            __push_l_anchor();
30827a984708SDavid Chisnall            ++__first;
30837a984708SDavid Chisnall        }
30847a984708SDavid Chisnall        if (__first != __last)
30857a984708SDavid Chisnall        {
30867a984708SDavid Chisnall            __first = __parse_RE_expression(__first, __last);
30877a984708SDavid Chisnall            if (__first != __last)
30887a984708SDavid Chisnall            {
30897a984708SDavid Chisnall                _ForwardIterator __temp = _VSTD::next(__first);
30907a984708SDavid Chisnall                if (__temp == __last && *__first == '$')
30917a984708SDavid Chisnall                {
30927a984708SDavid Chisnall                    __push_r_anchor();
30937a984708SDavid Chisnall                    ++__first;
30947a984708SDavid Chisnall                }
30957a984708SDavid Chisnall            }
30967a984708SDavid Chisnall        }
30977a984708SDavid Chisnall        if (__first != __last)
30989729cf09SDimitry Andric            __throw_regex_error<regex_constants::__re_err_empty>();
30997a984708SDavid Chisnall    }
31007a984708SDavid Chisnall    return __first;
31017a984708SDavid Chisnall}
31027a984708SDavid Chisnall
31037a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
31047a984708SDavid Chisnalltemplate <class _ForwardIterator>
31057a984708SDavid Chisnall_ForwardIterator
31067a984708SDavid Chisnallbasic_regex<_CharT, _Traits>::__parse_extended_reg_exp(_ForwardIterator __first,
31077a984708SDavid Chisnall                                                       _ForwardIterator __last)
31087a984708SDavid Chisnall{
31097a984708SDavid Chisnall    __owns_one_state<_CharT>* __sa = __end_;
31107a984708SDavid Chisnall    _ForwardIterator __temp = __parse_ERE_branch(__first, __last);
31117a984708SDavid Chisnall    if (__temp == __first)
31129729cf09SDimitry Andric        __throw_regex_error<regex_constants::__re_err_empty>();
31137a984708SDavid Chisnall    __first = __temp;
31147a984708SDavid Chisnall    while (__first != __last && *__first == '|')
31157a984708SDavid Chisnall    {
31167a984708SDavid Chisnall        __owns_one_state<_CharT>* __sb = __end_;
31177a984708SDavid Chisnall        __temp = __parse_ERE_branch(++__first, __last);
31187a984708SDavid Chisnall        if (__temp == __first)
31199729cf09SDimitry Andric            __throw_regex_error<regex_constants::__re_err_empty>();
31207a984708SDavid Chisnall        __push_alternation(__sa, __sb);
31217a984708SDavid Chisnall        __first = __temp;
31227a984708SDavid Chisnall    }
31237a984708SDavid Chisnall    return __first;
31247a984708SDavid Chisnall}
31257a984708SDavid Chisnall
31267a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
31277a984708SDavid Chisnalltemplate <class _ForwardIterator>
31287a984708SDavid Chisnall_ForwardIterator
31297a984708SDavid Chisnallbasic_regex<_CharT, _Traits>::__parse_ERE_branch(_ForwardIterator __first,
31307a984708SDavid Chisnall                                                 _ForwardIterator __last)
31317a984708SDavid Chisnall{
31327a984708SDavid Chisnall    _ForwardIterator __temp = __parse_ERE_expression(__first, __last);
31337a984708SDavid Chisnall    if (__temp == __first)
31349729cf09SDimitry Andric        __throw_regex_error<regex_constants::__re_err_empty>();
31357a984708SDavid Chisnall    do
31367a984708SDavid Chisnall    {
31377a984708SDavid Chisnall        __first = __temp;
31387a984708SDavid Chisnall        __temp = __parse_ERE_expression(__first, __last);
31397a984708SDavid Chisnall    } while (__temp != __first);
31407a984708SDavid Chisnall    return __first;
31417a984708SDavid Chisnall}
31427a984708SDavid Chisnall
31437a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
31447a984708SDavid Chisnalltemplate <class _ForwardIterator>
31457a984708SDavid Chisnall_ForwardIterator
31467a984708SDavid Chisnallbasic_regex<_CharT, _Traits>::__parse_ERE_expression(_ForwardIterator __first,
31477a984708SDavid Chisnall                                                     _ForwardIterator __last)
31487a984708SDavid Chisnall{
31497a984708SDavid Chisnall    __owns_one_state<_CharT>* __e = __end_;
31507a984708SDavid Chisnall    unsigned __mexp_begin = __marked_count_;
31517a984708SDavid Chisnall    _ForwardIterator __temp = __parse_one_char_or_coll_elem_ERE(__first, __last);
31527a984708SDavid Chisnall    if (__temp == __first && __temp != __last)
31537a984708SDavid Chisnall    {
31547a984708SDavid Chisnall        switch (*__temp)
31557a984708SDavid Chisnall        {
31567a984708SDavid Chisnall        case '^':
31577a984708SDavid Chisnall            __push_l_anchor();
31587a984708SDavid Chisnall            ++__temp;
31597a984708SDavid Chisnall            break;
31607a984708SDavid Chisnall        case '$':
31617a984708SDavid Chisnall            __push_r_anchor();
31627a984708SDavid Chisnall            ++__temp;
31637a984708SDavid Chisnall            break;
31647a984708SDavid Chisnall        case '(':
31657a984708SDavid Chisnall            __push_begin_marked_subexpression();
31667a984708SDavid Chisnall            unsigned __temp_count = __marked_count_;
31677a984708SDavid Chisnall            ++__open_count_;
31687a984708SDavid Chisnall            __temp = __parse_extended_reg_exp(++__temp, __last);
31697a984708SDavid Chisnall            if (__temp == __last || *__temp != ')')
31709729cf09SDimitry Andric                __throw_regex_error<regex_constants::error_paren>();
31717a984708SDavid Chisnall            __push_end_marked_subexpression(__temp_count);
31727a984708SDavid Chisnall            --__open_count_;
31737a984708SDavid Chisnall            ++__temp;
31747a984708SDavid Chisnall            break;
31757a984708SDavid Chisnall        }
31767a984708SDavid Chisnall    }
31777a984708SDavid Chisnall    if (__temp != __first)
31787a984708SDavid Chisnall        __temp = __parse_ERE_dupl_symbol(__temp, __last, __e, __mexp_begin+1,
31797a984708SDavid Chisnall                                         __marked_count_+1);
31807a984708SDavid Chisnall    __first = __temp;
31817a984708SDavid Chisnall    return __first;
31827a984708SDavid Chisnall}
31837a984708SDavid Chisnall
31847a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
31857a984708SDavid Chisnalltemplate <class _ForwardIterator>
31867a984708SDavid Chisnall_ForwardIterator
31877a984708SDavid Chisnallbasic_regex<_CharT, _Traits>::__parse_RE_expression(_ForwardIterator __first,
31887a984708SDavid Chisnall                                                    _ForwardIterator __last)
31897a984708SDavid Chisnall{
31907a984708SDavid Chisnall    while (true)
31917a984708SDavid Chisnall    {
31927a984708SDavid Chisnall        _ForwardIterator __temp = __parse_simple_RE(__first, __last);
31937a984708SDavid Chisnall        if (__temp == __first)
31947a984708SDavid Chisnall            break;
31957a984708SDavid Chisnall        __first = __temp;
31967a984708SDavid Chisnall    }
31977a984708SDavid Chisnall    return __first;
31987a984708SDavid Chisnall}
31997a984708SDavid Chisnall
32007a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
32017a984708SDavid Chisnalltemplate <class _ForwardIterator>
32027a984708SDavid Chisnall_ForwardIterator
32037a984708SDavid Chisnallbasic_regex<_CharT, _Traits>::__parse_simple_RE(_ForwardIterator __first,
32047a984708SDavid Chisnall                                                _ForwardIterator __last)
32057a984708SDavid Chisnall{
32067a984708SDavid Chisnall    if (__first != __last)
32077a984708SDavid Chisnall    {
32087a984708SDavid Chisnall        __owns_one_state<_CharT>* __e = __end_;
32097a984708SDavid Chisnall        unsigned __mexp_begin = __marked_count_;
32107a984708SDavid Chisnall        _ForwardIterator __temp = __parse_nondupl_RE(__first, __last);
32117a984708SDavid Chisnall        if (__temp != __first)
32127a984708SDavid Chisnall            __first = __parse_RE_dupl_symbol(__temp, __last, __e,
32137a984708SDavid Chisnall                                             __mexp_begin+1, __marked_count_+1);
32147a984708SDavid Chisnall    }
32157a984708SDavid Chisnall    return __first;
32167a984708SDavid Chisnall}
32177a984708SDavid Chisnall
32187a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
32197a984708SDavid Chisnalltemplate <class _ForwardIterator>
32207a984708SDavid Chisnall_ForwardIterator
32217a984708SDavid Chisnallbasic_regex<_CharT, _Traits>::__parse_nondupl_RE(_ForwardIterator __first,
32227a984708SDavid Chisnall                                                 _ForwardIterator __last)
32237a984708SDavid Chisnall{
32247a984708SDavid Chisnall    _ForwardIterator __temp = __first;
32257a984708SDavid Chisnall    __first = __parse_one_char_or_coll_elem_RE(__first, __last);
32267a984708SDavid Chisnall    if (__temp == __first)
32277a984708SDavid Chisnall    {
32287a984708SDavid Chisnall        __temp = __parse_Back_open_paren(__first, __last);
32297a984708SDavid Chisnall        if (__temp != __first)
32307a984708SDavid Chisnall        {
32317a984708SDavid Chisnall            __push_begin_marked_subexpression();
32327a984708SDavid Chisnall            unsigned __temp_count = __marked_count_;
32337a984708SDavid Chisnall            __first = __parse_RE_expression(__temp, __last);
32347a984708SDavid Chisnall            __temp = __parse_Back_close_paren(__first, __last);
32357a984708SDavid Chisnall            if (__temp == __first)
32369729cf09SDimitry Andric                __throw_regex_error<regex_constants::error_paren>();
32377a984708SDavid Chisnall            __push_end_marked_subexpression(__temp_count);
32387a984708SDavid Chisnall            __first = __temp;
32397a984708SDavid Chisnall        }
32407a984708SDavid Chisnall        else
32417a984708SDavid Chisnall            __first = __parse_BACKREF(__first, __last);
32427a984708SDavid Chisnall    }
32437a984708SDavid Chisnall    return __first;
32447a984708SDavid Chisnall}
32457a984708SDavid Chisnall
32467a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
32477a984708SDavid Chisnalltemplate <class _ForwardIterator>
32487a984708SDavid Chisnall_ForwardIterator
32497a984708SDavid Chisnallbasic_regex<_CharT, _Traits>::__parse_one_char_or_coll_elem_RE(
32507a984708SDavid Chisnall                                                       _ForwardIterator __first,
32517a984708SDavid Chisnall                                                       _ForwardIterator __last)
32527a984708SDavid Chisnall{
32537a984708SDavid Chisnall    _ForwardIterator __temp = __parse_ORD_CHAR(__first, __last);
32547a984708SDavid Chisnall    if (__temp == __first)
32557a984708SDavid Chisnall    {
32567a984708SDavid Chisnall        __temp = __parse_QUOTED_CHAR(__first, __last);
32577a984708SDavid Chisnall        if (__temp == __first)
32587a984708SDavid Chisnall        {
32597a984708SDavid Chisnall            if (__temp != __last && *__temp == '.')
32607a984708SDavid Chisnall            {
32617a984708SDavid Chisnall                __push_match_any();
32627a984708SDavid Chisnall                ++__temp;
32637a984708SDavid Chisnall            }
32647a984708SDavid Chisnall            else
32657a984708SDavid Chisnall                __temp = __parse_bracket_expression(__first, __last);
32667a984708SDavid Chisnall        }
32677a984708SDavid Chisnall    }
32687a984708SDavid Chisnall    __first = __temp;
32697a984708SDavid Chisnall    return __first;
32707a984708SDavid Chisnall}
32717a984708SDavid Chisnall
32727a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
32737a984708SDavid Chisnalltemplate <class _ForwardIterator>
32747a984708SDavid Chisnall_ForwardIterator
32757a984708SDavid Chisnallbasic_regex<_CharT, _Traits>::__parse_one_char_or_coll_elem_ERE(
32767a984708SDavid Chisnall                                                       _ForwardIterator __first,
32777a984708SDavid Chisnall                                                       _ForwardIterator __last)
32787a984708SDavid Chisnall{
32797a984708SDavid Chisnall    _ForwardIterator __temp = __parse_ORD_CHAR_ERE(__first, __last);
32807a984708SDavid Chisnall    if (__temp == __first)
32817a984708SDavid Chisnall    {
32827a984708SDavid Chisnall        __temp = __parse_QUOTED_CHAR_ERE(__first, __last);
32837a984708SDavid Chisnall        if (__temp == __first)
32847a984708SDavid Chisnall        {
32857a984708SDavid Chisnall            if (__temp != __last && *__temp == '.')
32867a984708SDavid Chisnall            {
32877a984708SDavid Chisnall                __push_match_any();
32887a984708SDavid Chisnall                ++__temp;
32897a984708SDavid Chisnall            }
32907a984708SDavid Chisnall            else
32917a984708SDavid Chisnall                __temp = __parse_bracket_expression(__first, __last);
32927a984708SDavid Chisnall        }
32937a984708SDavid Chisnall    }
32947a984708SDavid Chisnall    __first = __temp;
32957a984708SDavid Chisnall    return __first;
32967a984708SDavid Chisnall}
32977a984708SDavid Chisnall
32987a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
32997a984708SDavid Chisnalltemplate <class _ForwardIterator>
33007a984708SDavid Chisnall_ForwardIterator
33017a984708SDavid Chisnallbasic_regex<_CharT, _Traits>::__parse_Back_open_paren(_ForwardIterator __first,
33027a984708SDavid Chisnall                                                      _ForwardIterator __last)
33037a984708SDavid Chisnall{
33047a984708SDavid Chisnall    if (__first != __last)
33057a984708SDavid Chisnall    {
33067a984708SDavid Chisnall        _ForwardIterator __temp = _VSTD::next(__first);
33077a984708SDavid Chisnall        if (__temp != __last)
33087a984708SDavid Chisnall        {
33097a984708SDavid Chisnall            if (*__first == '\\' && *__temp == '(')
33107a984708SDavid Chisnall                __first = ++__temp;
33117a984708SDavid Chisnall        }
33127a984708SDavid Chisnall    }
33137a984708SDavid Chisnall    return __first;
33147a984708SDavid Chisnall}
33157a984708SDavid Chisnall
33167a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
33177a984708SDavid Chisnalltemplate <class _ForwardIterator>
33187a984708SDavid Chisnall_ForwardIterator
33197a984708SDavid Chisnallbasic_regex<_CharT, _Traits>::__parse_Back_close_paren(_ForwardIterator __first,
33207a984708SDavid Chisnall                                                       _ForwardIterator __last)
33217a984708SDavid Chisnall{
33227a984708SDavid Chisnall    if (__first != __last)
33237a984708SDavid Chisnall    {
33247a984708SDavid Chisnall        _ForwardIterator __temp = _VSTD::next(__first);
33257a984708SDavid Chisnall        if (__temp != __last)
33267a984708SDavid Chisnall        {
33277a984708SDavid Chisnall            if (*__first == '\\' && *__temp == ')')
33287a984708SDavid Chisnall                __first = ++__temp;
33297a984708SDavid Chisnall        }
33307a984708SDavid Chisnall    }
33317a984708SDavid Chisnall    return __first;
33327a984708SDavid Chisnall}
33337a984708SDavid Chisnall
33347a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
33357a984708SDavid Chisnalltemplate <class _ForwardIterator>
33367a984708SDavid Chisnall_ForwardIterator
33377a984708SDavid Chisnallbasic_regex<_CharT, _Traits>::__parse_Back_open_brace(_ForwardIterator __first,
33387a984708SDavid Chisnall                                                      _ForwardIterator __last)
33397a984708SDavid Chisnall{
33407a984708SDavid Chisnall    if (__first != __last)
33417a984708SDavid Chisnall    {
33427a984708SDavid Chisnall        _ForwardIterator __temp = _VSTD::next(__first);
33437a984708SDavid Chisnall        if (__temp != __last)
33447a984708SDavid Chisnall        {
33457a984708SDavid Chisnall            if (*__first == '\\' && *__temp == '{')
33467a984708SDavid Chisnall                __first = ++__temp;
33477a984708SDavid Chisnall        }
33487a984708SDavid Chisnall    }
33497a984708SDavid Chisnall    return __first;
33507a984708SDavid Chisnall}
33517a984708SDavid Chisnall
33527a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
33537a984708SDavid Chisnalltemplate <class _ForwardIterator>
33547a984708SDavid Chisnall_ForwardIterator
33557a984708SDavid Chisnallbasic_regex<_CharT, _Traits>::__parse_Back_close_brace(_ForwardIterator __first,
33567a984708SDavid Chisnall                                                       _ForwardIterator __last)
33577a984708SDavid Chisnall{
33587a984708SDavid Chisnall    if (__first != __last)
33597a984708SDavid Chisnall    {
33607a984708SDavid Chisnall        _ForwardIterator __temp = _VSTD::next(__first);
33617a984708SDavid Chisnall        if (__temp != __last)
33627a984708SDavid Chisnall        {
33637a984708SDavid Chisnall            if (*__first == '\\' && *__temp == '}')
33647a984708SDavid Chisnall                __first = ++__temp;
33657a984708SDavid Chisnall        }
33667a984708SDavid Chisnall    }
33677a984708SDavid Chisnall    return __first;
33687a984708SDavid Chisnall}
33697a984708SDavid Chisnall
33707a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
33717a984708SDavid Chisnalltemplate <class _ForwardIterator>
33727a984708SDavid Chisnall_ForwardIterator
33737a984708SDavid Chisnallbasic_regex<_CharT, _Traits>::__parse_BACKREF(_ForwardIterator __first,
33747a984708SDavid Chisnall                                              _ForwardIterator __last)
33757a984708SDavid Chisnall{
33767a984708SDavid Chisnall    if (__first != __last)
33777a984708SDavid Chisnall    {
33787a984708SDavid Chisnall        _ForwardIterator __temp = _VSTD::next(__first);
33797a984708SDavid Chisnall        if (__temp != __last)
33807a984708SDavid Chisnall        {
3381d72607e9SDimitry Andric            if (*__first == '\\')
33827a984708SDavid Chisnall            {
3383d72607e9SDimitry Andric                int __val = __traits_.value(*__temp, 10);
3384d72607e9SDimitry Andric                if (__val >= 1 && __val <= 9)
3385d72607e9SDimitry Andric                {
3386d72607e9SDimitry Andric                    __push_back_ref(__val);
33877a984708SDavid Chisnall                    __first = ++__temp;
33887a984708SDavid Chisnall                }
33897a984708SDavid Chisnall            }
33907a984708SDavid Chisnall        }
3391d72607e9SDimitry Andric    }
33927a984708SDavid Chisnall    return __first;
33937a984708SDavid Chisnall}
33947a984708SDavid Chisnall
33957a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
33967a984708SDavid Chisnalltemplate <class _ForwardIterator>
33977a984708SDavid Chisnall_ForwardIterator
33987a984708SDavid Chisnallbasic_regex<_CharT, _Traits>::__parse_ORD_CHAR(_ForwardIterator __first,
33997a984708SDavid Chisnall                                               _ForwardIterator __last)
34007a984708SDavid Chisnall{
34017a984708SDavid Chisnall    if (__first != __last)
34027a984708SDavid Chisnall    {
34037a984708SDavid Chisnall        _ForwardIterator __temp = _VSTD::next(__first);
34047a984708SDavid Chisnall        if (__temp == __last && *__first == '$')
34057a984708SDavid Chisnall            return __first;
34067a984708SDavid Chisnall        // Not called inside a bracket
34077a984708SDavid Chisnall        if (*__first == '.' || *__first == '\\' || *__first == '[')
34087a984708SDavid Chisnall            return __first;
34097a984708SDavid Chisnall        __push_char(*__first);
34107a984708SDavid Chisnall        ++__first;
34117a984708SDavid Chisnall    }
34127a984708SDavid Chisnall    return __first;
34137a984708SDavid Chisnall}
34147a984708SDavid Chisnall
34157a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
34167a984708SDavid Chisnalltemplate <class _ForwardIterator>
34177a984708SDavid Chisnall_ForwardIterator
34187a984708SDavid Chisnallbasic_regex<_CharT, _Traits>::__parse_ORD_CHAR_ERE(_ForwardIterator __first,
34197a984708SDavid Chisnall                                                   _ForwardIterator __last)
34207a984708SDavid Chisnall{
34217a984708SDavid Chisnall    if (__first != __last)
34227a984708SDavid Chisnall    {
34237a984708SDavid Chisnall        switch (*__first)
34247a984708SDavid Chisnall        {
34257a984708SDavid Chisnall        case '^':
34267a984708SDavid Chisnall        case '.':
34277a984708SDavid Chisnall        case '[':
34287a984708SDavid Chisnall        case '$':
34297a984708SDavid Chisnall        case '(':
34307a984708SDavid Chisnall        case '|':
34317a984708SDavid Chisnall        case '*':
34327a984708SDavid Chisnall        case '+':
34337a984708SDavid Chisnall        case '?':
34347a984708SDavid Chisnall        case '{':
34357a984708SDavid Chisnall        case '\\':
34367a984708SDavid Chisnall            break;
34377a984708SDavid Chisnall        case ')':
34387a984708SDavid Chisnall            if (__open_count_ == 0)
34397a984708SDavid Chisnall            {
34407a984708SDavid Chisnall                __push_char(*__first);
34417a984708SDavid Chisnall                ++__first;
34427a984708SDavid Chisnall            }
34437a984708SDavid Chisnall            break;
34447a984708SDavid Chisnall        default:
34457a984708SDavid Chisnall            __push_char(*__first);
34467a984708SDavid Chisnall            ++__first;
34477a984708SDavid Chisnall            break;
34487a984708SDavid Chisnall        }
34497a984708SDavid Chisnall    }
34507a984708SDavid Chisnall    return __first;
34517a984708SDavid Chisnall}
34527a984708SDavid Chisnall
34537a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
34547a984708SDavid Chisnalltemplate <class _ForwardIterator>
34557a984708SDavid Chisnall_ForwardIterator
34567a984708SDavid Chisnallbasic_regex<_CharT, _Traits>::__parse_QUOTED_CHAR(_ForwardIterator __first,
34577a984708SDavid Chisnall                                                  _ForwardIterator __last)
34587a984708SDavid Chisnall{
34597a984708SDavid Chisnall    if (__first != __last)
34607a984708SDavid Chisnall    {
34617a984708SDavid Chisnall        _ForwardIterator __temp = _VSTD::next(__first);
34627a984708SDavid Chisnall        if (__temp != __last)
34637a984708SDavid Chisnall        {
34647a984708SDavid Chisnall            if (*__first == '\\')
34657a984708SDavid Chisnall            {
34667a984708SDavid Chisnall                switch (*__temp)
34677a984708SDavid Chisnall                {
34687a984708SDavid Chisnall                case '^':
34697a984708SDavid Chisnall                case '.':
34707a984708SDavid Chisnall                case '*':
34717a984708SDavid Chisnall                case '[':
34727a984708SDavid Chisnall                case '$':
34737a984708SDavid Chisnall                case '\\':
34747a984708SDavid Chisnall                    __push_char(*__temp);
34757a984708SDavid Chisnall                    __first = ++__temp;
34767a984708SDavid Chisnall                    break;
34777a984708SDavid Chisnall                }
34787a984708SDavid Chisnall            }
34797a984708SDavid Chisnall        }
34807a984708SDavid Chisnall    }
34817a984708SDavid Chisnall    return __first;
34827a984708SDavid Chisnall}
34837a984708SDavid Chisnall
34847a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
34857a984708SDavid Chisnalltemplate <class _ForwardIterator>
34867a984708SDavid Chisnall_ForwardIterator
34877a984708SDavid Chisnallbasic_regex<_CharT, _Traits>::__parse_QUOTED_CHAR_ERE(_ForwardIterator __first,
34887a984708SDavid Chisnall                                                      _ForwardIterator __last)
34897a984708SDavid Chisnall{
34907a984708SDavid Chisnall    if (__first != __last)
34917a984708SDavid Chisnall    {
34927a984708SDavid Chisnall        _ForwardIterator __temp = _VSTD::next(__first);
34937a984708SDavid Chisnall        if (__temp != __last)
34947a984708SDavid Chisnall        {
34957a984708SDavid Chisnall            if (*__first == '\\')
34967a984708SDavid Chisnall            {
34977a984708SDavid Chisnall                switch (*__temp)
34987a984708SDavid Chisnall                {
34997a984708SDavid Chisnall                case '^':
35007a984708SDavid Chisnall                case '.':
35017a984708SDavid Chisnall                case '*':
35027a984708SDavid Chisnall                case '[':
35037a984708SDavid Chisnall                case '$':
35047a984708SDavid Chisnall                case '\\':
35057a984708SDavid Chisnall                case '(':
35067a984708SDavid Chisnall                case ')':
35077a984708SDavid Chisnall                case '|':
35087a984708SDavid Chisnall                case '+':
35097a984708SDavid Chisnall                case '?':
35107a984708SDavid Chisnall                case '{':
35114bab9fd9SDavid Chisnall                case '}':
35127a984708SDavid Chisnall                    __push_char(*__temp);
35137a984708SDavid Chisnall                    __first = ++__temp;
35147a984708SDavid Chisnall                    break;
35157a984708SDavid Chisnall                default:
35167a984708SDavid Chisnall                    if ((__flags_ & 0x1F0) == awk)
35177a984708SDavid Chisnall                        __first = __parse_awk_escape(++__first, __last);
35187a984708SDavid Chisnall                    break;
35197a984708SDavid Chisnall                }
35207a984708SDavid Chisnall            }
35217a984708SDavid Chisnall        }
35227a984708SDavid Chisnall    }
35237a984708SDavid Chisnall    return __first;
35247a984708SDavid Chisnall}
35257a984708SDavid Chisnall
35267a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
35277a984708SDavid Chisnalltemplate <class _ForwardIterator>
35287a984708SDavid Chisnall_ForwardIterator
35297a984708SDavid Chisnallbasic_regex<_CharT, _Traits>::__parse_RE_dupl_symbol(_ForwardIterator __first,
35307a984708SDavid Chisnall                                                     _ForwardIterator __last,
35317a984708SDavid Chisnall                                                     __owns_one_state<_CharT>* __s,
35327a984708SDavid Chisnall                                                     unsigned __mexp_begin,
35337a984708SDavid Chisnall                                                     unsigned __mexp_end)
35347a984708SDavid Chisnall{
35357a984708SDavid Chisnall    if (__first != __last)
35367a984708SDavid Chisnall    {
35377a984708SDavid Chisnall        if (*__first == '*')
35387a984708SDavid Chisnall        {
35397a984708SDavid Chisnall            __push_greedy_inf_repeat(0, __s, __mexp_begin, __mexp_end);
35407a984708SDavid Chisnall            ++__first;
35417a984708SDavid Chisnall        }
35427a984708SDavid Chisnall        else
35437a984708SDavid Chisnall        {
35447a984708SDavid Chisnall            _ForwardIterator __temp = __parse_Back_open_brace(__first, __last);
35457a984708SDavid Chisnall            if (__temp != __first)
35467a984708SDavid Chisnall            {
35477a984708SDavid Chisnall                int __min = 0;
35487a984708SDavid Chisnall                __first = __temp;
35497a984708SDavid Chisnall                __temp = __parse_DUP_COUNT(__first, __last, __min);
35507a984708SDavid Chisnall                if (__temp == __first)
35519729cf09SDimitry Andric                    __throw_regex_error<regex_constants::error_badbrace>();
35527a984708SDavid Chisnall                __first = __temp;
35537a984708SDavid Chisnall                if (__first == __last)
35549729cf09SDimitry Andric                    __throw_regex_error<regex_constants::error_brace>();
35557a984708SDavid Chisnall                if (*__first != ',')
35567a984708SDavid Chisnall                {
35577a984708SDavid Chisnall                    __temp = __parse_Back_close_brace(__first, __last);
35587a984708SDavid Chisnall                    if (__temp == __first)
35599729cf09SDimitry Andric                        __throw_regex_error<regex_constants::error_brace>();
35607a984708SDavid Chisnall                    __push_loop(__min, __min, __s, __mexp_begin, __mexp_end,
35617a984708SDavid Chisnall                                    true);
35627a984708SDavid Chisnall                    __first = __temp;
35637a984708SDavid Chisnall                }
35647a984708SDavid Chisnall                else
35657a984708SDavid Chisnall                {
35667a984708SDavid Chisnall                    ++__first;  // consume ','
35677a984708SDavid Chisnall                    int __max = -1;
35687a984708SDavid Chisnall                    __first = __parse_DUP_COUNT(__first, __last, __max);
35697a984708SDavid Chisnall                    __temp = __parse_Back_close_brace(__first, __last);
35707a984708SDavid Chisnall                    if (__temp == __first)
35719729cf09SDimitry Andric                        __throw_regex_error<regex_constants::error_brace>();
35727a984708SDavid Chisnall                    if (__max == -1)
35737a984708SDavid Chisnall                        __push_greedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end);
35747a984708SDavid Chisnall                    else
35757a984708SDavid Chisnall                    {
35767a984708SDavid Chisnall                        if (__max < __min)
35779729cf09SDimitry Andric                            __throw_regex_error<regex_constants::error_badbrace>();
35787a984708SDavid Chisnall                        __push_loop(__min, __max, __s, __mexp_begin, __mexp_end,
35797a984708SDavid Chisnall                                    true);
35807a984708SDavid Chisnall                    }
35817a984708SDavid Chisnall                    __first = __temp;
35827a984708SDavid Chisnall                }
35837a984708SDavid Chisnall            }
35847a984708SDavid Chisnall        }
35857a984708SDavid Chisnall    }
35867a984708SDavid Chisnall    return __first;
35877a984708SDavid Chisnall}
35887a984708SDavid Chisnall
35897a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
35907a984708SDavid Chisnalltemplate <class _ForwardIterator>
35917a984708SDavid Chisnall_ForwardIterator
35927a984708SDavid Chisnallbasic_regex<_CharT, _Traits>::__parse_ERE_dupl_symbol(_ForwardIterator __first,
35937a984708SDavid Chisnall                                                      _ForwardIterator __last,
35947a984708SDavid Chisnall                                                      __owns_one_state<_CharT>* __s,
35957a984708SDavid Chisnall                                                      unsigned __mexp_begin,
35967a984708SDavid Chisnall                                                      unsigned __mexp_end)
35977a984708SDavid Chisnall{
35987a984708SDavid Chisnall    if (__first != __last)
35997a984708SDavid Chisnall    {
36007a984708SDavid Chisnall        unsigned __grammar = __flags_ & 0x1F0;
36017a984708SDavid Chisnall        switch (*__first)
36027a984708SDavid Chisnall        {
36037a984708SDavid Chisnall        case '*':
36047a984708SDavid Chisnall            ++__first;
36057a984708SDavid Chisnall            if (__grammar == ECMAScript && __first != __last && *__first == '?')
36067a984708SDavid Chisnall            {
36077a984708SDavid Chisnall                ++__first;
36087a984708SDavid Chisnall                __push_nongreedy_inf_repeat(0, __s, __mexp_begin, __mexp_end);
36097a984708SDavid Chisnall            }
36107a984708SDavid Chisnall            else
36117a984708SDavid Chisnall                __push_greedy_inf_repeat(0, __s, __mexp_begin, __mexp_end);
36127a984708SDavid Chisnall            break;
36137a984708SDavid Chisnall        case '+':
36147a984708SDavid Chisnall            ++__first;
36157a984708SDavid Chisnall            if (__grammar == ECMAScript && __first != __last && *__first == '?')
36167a984708SDavid Chisnall            {
36177a984708SDavid Chisnall                ++__first;
36187a984708SDavid Chisnall                __push_nongreedy_inf_repeat(1, __s, __mexp_begin, __mexp_end);
36197a984708SDavid Chisnall            }
36207a984708SDavid Chisnall            else
36217a984708SDavid Chisnall                __push_greedy_inf_repeat(1, __s, __mexp_begin, __mexp_end);
36227a984708SDavid Chisnall            break;
36237a984708SDavid Chisnall        case '?':
36247a984708SDavid Chisnall            ++__first;
36257a984708SDavid Chisnall            if (__grammar == ECMAScript && __first != __last && *__first == '?')
36267a984708SDavid Chisnall            {
36277a984708SDavid Chisnall                ++__first;
36287a984708SDavid Chisnall                __push_loop(0, 1, __s, __mexp_begin, __mexp_end, false);
36297a984708SDavid Chisnall            }
36307a984708SDavid Chisnall            else
36317a984708SDavid Chisnall                __push_loop(0, 1, __s, __mexp_begin, __mexp_end);
36327a984708SDavid Chisnall            break;
36337a984708SDavid Chisnall        case '{':
36347a984708SDavid Chisnall            {
36357a984708SDavid Chisnall                int __min;
36367a984708SDavid Chisnall                _ForwardIterator __temp = __parse_DUP_COUNT(++__first, __last, __min);
36377a984708SDavid Chisnall                if (__temp == __first)
36389729cf09SDimitry Andric                    __throw_regex_error<regex_constants::error_badbrace>();
36397a984708SDavid Chisnall                __first = __temp;
36407a984708SDavid Chisnall                if (__first == __last)
36419729cf09SDimitry Andric                    __throw_regex_error<regex_constants::error_brace>();
36427a984708SDavid Chisnall                switch (*__first)
36437a984708SDavid Chisnall                {
36447a984708SDavid Chisnall                case '}':
36457a984708SDavid Chisnall                    ++__first;
36467a984708SDavid Chisnall                    if (__grammar == ECMAScript && __first != __last && *__first == '?')
36477a984708SDavid Chisnall                    {
36487a984708SDavid Chisnall                        ++__first;
36497a984708SDavid Chisnall                        __push_loop(__min, __min, __s, __mexp_begin, __mexp_end, false);
36507a984708SDavid Chisnall                    }
36517a984708SDavid Chisnall                    else
36527a984708SDavid Chisnall                        __push_loop(__min, __min, __s, __mexp_begin, __mexp_end);
36537a984708SDavid Chisnall                    break;
36547a984708SDavid Chisnall                case ',':
36557a984708SDavid Chisnall                    ++__first;
36567a984708SDavid Chisnall                    if (__first == __last)
36579729cf09SDimitry Andric                        __throw_regex_error<regex_constants::error_badbrace>();
36587a984708SDavid Chisnall                    if (*__first == '}')
36597a984708SDavid Chisnall                    {
36607a984708SDavid Chisnall                        ++__first;
36617a984708SDavid Chisnall                        if (__grammar == ECMAScript && __first != __last && *__first == '?')
36627a984708SDavid Chisnall                        {
36637a984708SDavid Chisnall                            ++__first;
36647a984708SDavid Chisnall                            __push_nongreedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end);
36657a984708SDavid Chisnall                        }
36667a984708SDavid Chisnall                        else
36677a984708SDavid Chisnall                            __push_greedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end);
36687a984708SDavid Chisnall                    }
36697a984708SDavid Chisnall                    else
36707a984708SDavid Chisnall                    {
36717a984708SDavid Chisnall                        int __max = -1;
36727a984708SDavid Chisnall                        __temp = __parse_DUP_COUNT(__first, __last, __max);
36737a984708SDavid Chisnall                        if (__temp == __first)
36749729cf09SDimitry Andric                            __throw_regex_error<regex_constants::error_brace>();
36757a984708SDavid Chisnall                        __first = __temp;
36767a984708SDavid Chisnall                        if (__first == __last || *__first != '}')
36779729cf09SDimitry Andric                            __throw_regex_error<regex_constants::error_brace>();
36787a984708SDavid Chisnall                        ++__first;
36797a984708SDavid Chisnall                        if (__max < __min)
36809729cf09SDimitry Andric                            __throw_regex_error<regex_constants::error_badbrace>();
36817a984708SDavid Chisnall                        if (__grammar == ECMAScript && __first != __last && *__first == '?')
36827a984708SDavid Chisnall                        {
36837a984708SDavid Chisnall                            ++__first;
36847a984708SDavid Chisnall                            __push_loop(__min, __max, __s, __mexp_begin, __mexp_end, false);
36857a984708SDavid Chisnall                        }
36867a984708SDavid Chisnall                        else
36877a984708SDavid Chisnall                            __push_loop(__min, __max, __s, __mexp_begin, __mexp_end);
36887a984708SDavid Chisnall                    }
36897a984708SDavid Chisnall                    break;
36907a984708SDavid Chisnall                default:
36919729cf09SDimitry Andric                    __throw_regex_error<regex_constants::error_badbrace>();
36927a984708SDavid Chisnall                }
36937a984708SDavid Chisnall            }
36947a984708SDavid Chisnall            break;
36957a984708SDavid Chisnall        }
36967a984708SDavid Chisnall    }
36977a984708SDavid Chisnall    return __first;
36987a984708SDavid Chisnall}
36997a984708SDavid Chisnall
37007a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
37017a984708SDavid Chisnalltemplate <class _ForwardIterator>
37027a984708SDavid Chisnall_ForwardIterator
37037a984708SDavid Chisnallbasic_regex<_CharT, _Traits>::__parse_bracket_expression(_ForwardIterator __first,
37047a984708SDavid Chisnall                                                         _ForwardIterator __last)
37057a984708SDavid Chisnall{
37067a984708SDavid Chisnall    if (__first != __last && *__first == '[')
37077a984708SDavid Chisnall    {
37087a984708SDavid Chisnall        ++__first;
37097a984708SDavid Chisnall        if (__first == __last)
37109729cf09SDimitry Andric            __throw_regex_error<regex_constants::error_brack>();
37117a984708SDavid Chisnall        bool __negate = false;
37127a984708SDavid Chisnall        if (*__first == '^')
37137a984708SDavid Chisnall        {
37147a984708SDavid Chisnall            ++__first;
37157a984708SDavid Chisnall            __negate = true;
37167a984708SDavid Chisnall        }
37177a984708SDavid Chisnall        __bracket_expression<_CharT, _Traits>* __ml = __start_matching_list(__negate);
37187a984708SDavid Chisnall        // __ml owned by *this
37197a984708SDavid Chisnall        if (__first == __last)
37209729cf09SDimitry Andric            __throw_regex_error<regex_constants::error_brack>();
37217a984708SDavid Chisnall        if ((__flags_ & 0x1F0) != ECMAScript && *__first == ']')
37227a984708SDavid Chisnall        {
37237a984708SDavid Chisnall            __ml->__add_char(']');
37247a984708SDavid Chisnall            ++__first;
37257a984708SDavid Chisnall        }
37267a984708SDavid Chisnall        __first = __parse_follow_list(__first, __last, __ml);
37277a984708SDavid Chisnall        if (__first == __last)
37289729cf09SDimitry Andric            __throw_regex_error<regex_constants::error_brack>();
37297a984708SDavid Chisnall        if (*__first == '-')
37307a984708SDavid Chisnall        {
37317a984708SDavid Chisnall            __ml->__add_char('-');
37327a984708SDavid Chisnall            ++__first;
37337a984708SDavid Chisnall        }
37347a984708SDavid Chisnall        if (__first == __last || *__first != ']')
37359729cf09SDimitry Andric            __throw_regex_error<regex_constants::error_brack>();
37367a984708SDavid Chisnall        ++__first;
37377a984708SDavid Chisnall    }
37387a984708SDavid Chisnall    return __first;
37397a984708SDavid Chisnall}
37407a984708SDavid Chisnall
37417a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
37427a984708SDavid Chisnalltemplate <class _ForwardIterator>
37437a984708SDavid Chisnall_ForwardIterator
37447a984708SDavid Chisnallbasic_regex<_CharT, _Traits>::__parse_follow_list(_ForwardIterator __first,
37457a984708SDavid Chisnall                                    _ForwardIterator __last,
37467a984708SDavid Chisnall                                    __bracket_expression<_CharT, _Traits>* __ml)
37477a984708SDavid Chisnall{
37487a984708SDavid Chisnall    if (__first != __last)
37497a984708SDavid Chisnall    {
37507a984708SDavid Chisnall        while (true)
37517a984708SDavid Chisnall        {
37527a984708SDavid Chisnall            _ForwardIterator __temp = __parse_expression_term(__first, __last,
37537a984708SDavid Chisnall                                                              __ml);
37547a984708SDavid Chisnall            if (__temp == __first)
37557a984708SDavid Chisnall                break;
37567a984708SDavid Chisnall            __first = __temp;
37577a984708SDavid Chisnall        }
37587a984708SDavid Chisnall    }
37597a984708SDavid Chisnall    return __first;
37607a984708SDavid Chisnall}
37617a984708SDavid Chisnall
37627a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
37637a984708SDavid Chisnalltemplate <class _ForwardIterator>
37647a984708SDavid Chisnall_ForwardIterator
37657a984708SDavid Chisnallbasic_regex<_CharT, _Traits>::__parse_expression_term(_ForwardIterator __first,
37667a984708SDavid Chisnall                                    _ForwardIterator __last,
37677a984708SDavid Chisnall                                    __bracket_expression<_CharT, _Traits>* __ml)
37687a984708SDavid Chisnall{
37697a984708SDavid Chisnall    if (__first != __last && *__first != ']')
37707a984708SDavid Chisnall    {
37717a984708SDavid Chisnall        _ForwardIterator __temp = _VSTD::next(__first);
37727a984708SDavid Chisnall        basic_string<_CharT> __start_range;
37737a984708SDavid Chisnall        if (__temp != __last && *__first == '[')
37747a984708SDavid Chisnall        {
37757a984708SDavid Chisnall            if (*__temp == '=')
37767a984708SDavid Chisnall                return __parse_equivalence_class(++__temp, __last, __ml);
37777a984708SDavid Chisnall            else if (*__temp == ':')
37787a984708SDavid Chisnall                return __parse_character_class(++__temp, __last, __ml);
37797a984708SDavid Chisnall            else if (*__temp == '.')
37807a984708SDavid Chisnall                __first = __parse_collating_symbol(++__temp, __last, __start_range);
37817a984708SDavid Chisnall        }
37827a984708SDavid Chisnall        unsigned __grammar = __flags_ & 0x1F0;
37837a984708SDavid Chisnall        if (__start_range.empty())
37847a984708SDavid Chisnall        {
37857a984708SDavid Chisnall            if ((__grammar == ECMAScript || __grammar == awk) && *__first == '\\')
37867a984708SDavid Chisnall            {
37877a984708SDavid Chisnall                if (__grammar == ECMAScript)
37887a984708SDavid Chisnall                    __first = __parse_class_escape(++__first, __last, __start_range, __ml);
37897a984708SDavid Chisnall                else
37907a984708SDavid Chisnall                    __first = __parse_awk_escape(++__first, __last, &__start_range);
37917a984708SDavid Chisnall            }
37927a984708SDavid Chisnall            else
37937a984708SDavid Chisnall            {
37947a984708SDavid Chisnall                __start_range = *__first;
37957a984708SDavid Chisnall                ++__first;
37967a984708SDavid Chisnall            }
37977a984708SDavid Chisnall        }
37987a984708SDavid Chisnall        if (__first != __last && *__first != ']')
37997a984708SDavid Chisnall        {
38007a984708SDavid Chisnall            __temp = _VSTD::next(__first);
38017a984708SDavid Chisnall            if (__temp != __last && *__first == '-' && *__temp != ']')
38027a984708SDavid Chisnall            {
38037a984708SDavid Chisnall                // parse a range
38047a984708SDavid Chisnall                basic_string<_CharT> __end_range;
38057a984708SDavid Chisnall                __first = __temp;
38067a984708SDavid Chisnall                ++__temp;
38077a984708SDavid Chisnall                if (__temp != __last && *__first == '[' && *__temp == '.')
38087a984708SDavid Chisnall                    __first = __parse_collating_symbol(++__temp, __last, __end_range);
38097a984708SDavid Chisnall                else
38107a984708SDavid Chisnall                {
38117a984708SDavid Chisnall                    if ((__grammar == ECMAScript || __grammar == awk) && *__first == '\\')
38127a984708SDavid Chisnall                    {
38137a984708SDavid Chisnall                        if (__grammar == ECMAScript)
38147a984708SDavid Chisnall                            __first = __parse_class_escape(++__first, __last,
38157a984708SDavid Chisnall                                                           __end_range, __ml);
38167a984708SDavid Chisnall                        else
38177a984708SDavid Chisnall                            __first = __parse_awk_escape(++__first, __last,
38187a984708SDavid Chisnall                                                         &__end_range);
38197a984708SDavid Chisnall                    }
38207a984708SDavid Chisnall                    else
38217a984708SDavid Chisnall                    {
38227a984708SDavid Chisnall                        __end_range = *__first;
38237a984708SDavid Chisnall                        ++__first;
38247a984708SDavid Chisnall                    }
38257a984708SDavid Chisnall                }
38267a984708SDavid Chisnall                __ml->__add_range(_VSTD::move(__start_range), _VSTD::move(__end_range));
38277a984708SDavid Chisnall            }
38284f7ab58eSDimitry Andric            else if (!__start_range.empty())
38297a984708SDavid Chisnall            {
38307a984708SDavid Chisnall                if (__start_range.size() == 1)
38317a984708SDavid Chisnall                    __ml->__add_char(__start_range[0]);
38327a984708SDavid Chisnall                else
38337a984708SDavid Chisnall                    __ml->__add_digraph(__start_range[0], __start_range[1]);
38347a984708SDavid Chisnall            }
38357a984708SDavid Chisnall        }
38364f7ab58eSDimitry Andric        else if (!__start_range.empty())
38377a984708SDavid Chisnall        {
38387a984708SDavid Chisnall            if (__start_range.size() == 1)
38397a984708SDavid Chisnall                __ml->__add_char(__start_range[0]);
38407a984708SDavid Chisnall            else
38417a984708SDavid Chisnall                __ml->__add_digraph(__start_range[0], __start_range[1]);
38427a984708SDavid Chisnall        }
38437a984708SDavid Chisnall    }
38447a984708SDavid Chisnall    return __first;
38457a984708SDavid Chisnall}
38467a984708SDavid Chisnall
38477a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
38487a984708SDavid Chisnalltemplate <class _ForwardIterator>
38497a984708SDavid Chisnall_ForwardIterator
38507a984708SDavid Chisnallbasic_regex<_CharT, _Traits>::__parse_class_escape(_ForwardIterator __first,
38517a984708SDavid Chisnall                          _ForwardIterator __last,
38527a984708SDavid Chisnall                          basic_string<_CharT>& __str,
38537a984708SDavid Chisnall                          __bracket_expression<_CharT, _Traits>* __ml)
38547a984708SDavid Chisnall{
38557a984708SDavid Chisnall    if (__first == __last)
38569729cf09SDimitry Andric        __throw_regex_error<regex_constants::error_escape>();
38577a984708SDavid Chisnall    switch (*__first)
38587a984708SDavid Chisnall    {
38597a984708SDavid Chisnall    case 0:
38607a984708SDavid Chisnall        __str = *__first;
38617a984708SDavid Chisnall        return ++__first;
38627a984708SDavid Chisnall    case 'b':
38637a984708SDavid Chisnall        __str = _CharT(8);
38647a984708SDavid Chisnall        return ++__first;
38657a984708SDavid Chisnall    case 'd':
38667a984708SDavid Chisnall        __ml->__add_class(ctype_base::digit);
38677a984708SDavid Chisnall        return ++__first;
38687a984708SDavid Chisnall    case 'D':
38697a984708SDavid Chisnall        __ml->__add_neg_class(ctype_base::digit);
38707a984708SDavid Chisnall        return ++__first;
38717a984708SDavid Chisnall    case 's':
38727a984708SDavid Chisnall        __ml->__add_class(ctype_base::space);
38737a984708SDavid Chisnall        return ++__first;
38747a984708SDavid Chisnall    case 'S':
38757a984708SDavid Chisnall        __ml->__add_neg_class(ctype_base::space);
38767a984708SDavid Chisnall        return ++__first;
38777a984708SDavid Chisnall    case 'w':
38787a984708SDavid Chisnall        __ml->__add_class(ctype_base::alnum);
38797a984708SDavid Chisnall        __ml->__add_char('_');
38807a984708SDavid Chisnall        return ++__first;
38817a984708SDavid Chisnall    case 'W':
38827a984708SDavid Chisnall        __ml->__add_neg_class(ctype_base::alnum);
38837a984708SDavid Chisnall        __ml->__add_neg_char('_');
38847a984708SDavid Chisnall        return ++__first;
38857a984708SDavid Chisnall    }
38867a984708SDavid Chisnall    __first = __parse_character_escape(__first, __last, &__str);
38877a984708SDavid Chisnall    return __first;
38887a984708SDavid Chisnall}
38897a984708SDavid Chisnall
38907a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
38917a984708SDavid Chisnalltemplate <class _ForwardIterator>
38927a984708SDavid Chisnall_ForwardIterator
38937a984708SDavid Chisnallbasic_regex<_CharT, _Traits>::__parse_awk_escape(_ForwardIterator __first,
38947a984708SDavid Chisnall                          _ForwardIterator __last,
38957a984708SDavid Chisnall                          basic_string<_CharT>* __str)
38967a984708SDavid Chisnall{
38977a984708SDavid Chisnall    if (__first == __last)
38989729cf09SDimitry Andric        __throw_regex_error<regex_constants::error_escape>();
38997a984708SDavid Chisnall    switch (*__first)
39007a984708SDavid Chisnall    {
39017a984708SDavid Chisnall    case '\\':
39027a984708SDavid Chisnall    case '"':
39037a984708SDavid Chisnall    case '/':
39047a984708SDavid Chisnall        if (__str)
39057a984708SDavid Chisnall            *__str = *__first;
39067a984708SDavid Chisnall        else
39077a984708SDavid Chisnall            __push_char(*__first);
39087a984708SDavid Chisnall        return ++__first;
39097a984708SDavid Chisnall    case 'a':
39107a984708SDavid Chisnall        if (__str)
39117a984708SDavid Chisnall            *__str = _CharT(7);
39127a984708SDavid Chisnall        else
39137a984708SDavid Chisnall            __push_char(_CharT(7));
39147a984708SDavid Chisnall        return ++__first;
39157a984708SDavid Chisnall    case 'b':
39167a984708SDavid Chisnall        if (__str)
39177a984708SDavid Chisnall            *__str = _CharT(8);
39187a984708SDavid Chisnall        else
39197a984708SDavid Chisnall            __push_char(_CharT(8));
39207a984708SDavid Chisnall        return ++__first;
39217a984708SDavid Chisnall    case 'f':
39227a984708SDavid Chisnall        if (__str)
39237a984708SDavid Chisnall            *__str = _CharT(0xC);
39247a984708SDavid Chisnall        else
39257a984708SDavid Chisnall            __push_char(_CharT(0xC));
39267a984708SDavid Chisnall        return ++__first;
39277a984708SDavid Chisnall    case 'n':
39287a984708SDavid Chisnall        if (__str)
39297a984708SDavid Chisnall            *__str = _CharT(0xA);
39307a984708SDavid Chisnall        else
39317a984708SDavid Chisnall            __push_char(_CharT(0xA));
39327a984708SDavid Chisnall        return ++__first;
39337a984708SDavid Chisnall    case 'r':
39347a984708SDavid Chisnall        if (__str)
39357a984708SDavid Chisnall            *__str = _CharT(0xD);
39367a984708SDavid Chisnall        else
39377a984708SDavid Chisnall            __push_char(_CharT(0xD));
39387a984708SDavid Chisnall        return ++__first;
39397a984708SDavid Chisnall    case 't':
39407a984708SDavid Chisnall        if (__str)
39417a984708SDavid Chisnall            *__str = _CharT(0x9);
39427a984708SDavid Chisnall        else
39437a984708SDavid Chisnall            __push_char(_CharT(0x9));
39447a984708SDavid Chisnall        return ++__first;
39457a984708SDavid Chisnall    case 'v':
39467a984708SDavid Chisnall        if (__str)
39477a984708SDavid Chisnall            *__str = _CharT(0xB);
39487a984708SDavid Chisnall        else
39497a984708SDavid Chisnall            __push_char(_CharT(0xB));
39507a984708SDavid Chisnall        return ++__first;
39517a984708SDavid Chisnall    }
39527a984708SDavid Chisnall    if ('0' <= *__first && *__first <= '7')
39537a984708SDavid Chisnall    {
39547a984708SDavid Chisnall        unsigned __val = *__first - '0';
39557a984708SDavid Chisnall        if (++__first != __last && ('0' <= *__first && *__first <= '7'))
39567a984708SDavid Chisnall        {
39577a984708SDavid Chisnall            __val = 8 * __val + *__first - '0';
39587a984708SDavid Chisnall            if (++__first != __last && ('0' <= *__first && *__first <= '7'))
39594bab9fd9SDavid Chisnall                __val = 8 * __val + *__first++ - '0';
39607a984708SDavid Chisnall        }
39617a984708SDavid Chisnall        if (__str)
39627a984708SDavid Chisnall            *__str = _CharT(__val);
39637a984708SDavid Chisnall        else
39647a984708SDavid Chisnall            __push_char(_CharT(__val));
39657a984708SDavid Chisnall    }
39667a984708SDavid Chisnall    else
39679729cf09SDimitry Andric        __throw_regex_error<regex_constants::error_escape>();
39687a984708SDavid Chisnall    return __first;
39697a984708SDavid Chisnall}
39707a984708SDavid Chisnall
39717a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
39727a984708SDavid Chisnalltemplate <class _ForwardIterator>
39737a984708SDavid Chisnall_ForwardIterator
39747a984708SDavid Chisnallbasic_regex<_CharT, _Traits>::__parse_equivalence_class(_ForwardIterator __first,
39757a984708SDavid Chisnall                                    _ForwardIterator __last,
39767a984708SDavid Chisnall                                    __bracket_expression<_CharT, _Traits>* __ml)
39777a984708SDavid Chisnall{
39787a984708SDavid Chisnall    // Found [=
39797a984708SDavid Chisnall    //   This means =] must exist
39807a984708SDavid Chisnall    value_type _Equal_close[2] = {'=', ']'};
39817a984708SDavid Chisnall    _ForwardIterator __temp = _VSTD::search(__first, __last, _Equal_close,
39827a984708SDavid Chisnall                                                            _Equal_close+2);
39837a984708SDavid Chisnall    if (__temp == __last)
39849729cf09SDimitry Andric        __throw_regex_error<regex_constants::error_brack>();
39857a984708SDavid Chisnall    // [__first, __temp) contains all text in [= ... =]
39867a984708SDavid Chisnall    string_type __collate_name =
39877a984708SDavid Chisnall        __traits_.lookup_collatename(__first, __temp);
39887a984708SDavid Chisnall    if (__collate_name.empty())
39899729cf09SDimitry Andric        __throw_regex_error<regex_constants::error_collate>();
39907a984708SDavid Chisnall    string_type __equiv_name =
39917a984708SDavid Chisnall        __traits_.transform_primary(__collate_name.begin(),
39927a984708SDavid Chisnall                                    __collate_name.end());
39937a984708SDavid Chisnall    if (!__equiv_name.empty())
39947a984708SDavid Chisnall        __ml->__add_equivalence(__equiv_name);
39957a984708SDavid Chisnall    else
39967a984708SDavid Chisnall    {
39977a984708SDavid Chisnall        switch (__collate_name.size())
39987a984708SDavid Chisnall        {
39997a984708SDavid Chisnall        case 1:
40007a984708SDavid Chisnall            __ml->__add_char(__collate_name[0]);
40017a984708SDavid Chisnall            break;
40027a984708SDavid Chisnall        case 2:
40037a984708SDavid Chisnall            __ml->__add_digraph(__collate_name[0], __collate_name[1]);
40047a984708SDavid Chisnall            break;
40057a984708SDavid Chisnall        default:
40069729cf09SDimitry Andric            __throw_regex_error<regex_constants::error_collate>();
40077a984708SDavid Chisnall        }
40087a984708SDavid Chisnall    }
40097a984708SDavid Chisnall    __first = _VSTD::next(__temp, 2);
40107a984708SDavid Chisnall    return __first;
40117a984708SDavid Chisnall}
40127a984708SDavid Chisnall
40137a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
40147a984708SDavid Chisnalltemplate <class _ForwardIterator>
40157a984708SDavid Chisnall_ForwardIterator
40167a984708SDavid Chisnallbasic_regex<_CharT, _Traits>::__parse_character_class(_ForwardIterator __first,
40177a984708SDavid Chisnall                                    _ForwardIterator __last,
40187a984708SDavid Chisnall                                    __bracket_expression<_CharT, _Traits>* __ml)
40197a984708SDavid Chisnall{
40207a984708SDavid Chisnall    // Found [:
40217a984708SDavid Chisnall    //   This means :] must exist
40227a984708SDavid Chisnall    value_type _Colon_close[2] = {':', ']'};
40237a984708SDavid Chisnall    _ForwardIterator __temp = _VSTD::search(__first, __last, _Colon_close,
40247a984708SDavid Chisnall                                                            _Colon_close+2);
40257a984708SDavid Chisnall    if (__temp == __last)
40269729cf09SDimitry Andric        __throw_regex_error<regex_constants::error_brack>();
40277a984708SDavid Chisnall    // [__first, __temp) contains all text in [: ... :]
40287a984708SDavid Chisnall    typedef typename _Traits::char_class_type char_class_type;
40297a984708SDavid Chisnall    char_class_type __class_type =
40307a984708SDavid Chisnall        __traits_.lookup_classname(__first, __temp, __flags_ & icase);
40317a984708SDavid Chisnall    if (__class_type == 0)
40324ba319b5SDimitry Andric        __throw_regex_error<regex_constants::error_ctype>();
40337a984708SDavid Chisnall    __ml->__add_class(__class_type);
40347a984708SDavid Chisnall    __first = _VSTD::next(__temp, 2);
40357a984708SDavid Chisnall    return __first;
40367a984708SDavid Chisnall}
40377a984708SDavid Chisnall
40387a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
40397a984708SDavid Chisnalltemplate <class _ForwardIterator>
40407a984708SDavid Chisnall_ForwardIterator
40417a984708SDavid Chisnallbasic_regex<_CharT, _Traits>::__parse_collating_symbol(_ForwardIterator __first,
40427a984708SDavid Chisnall                                                _ForwardIterator __last,
40437a984708SDavid Chisnall                                                basic_string<_CharT>& __col_sym)
40447a984708SDavid Chisnall{
40457a984708SDavid Chisnall    // Found [.
40467a984708SDavid Chisnall    //   This means .] must exist
40477a984708SDavid Chisnall    value_type _Dot_close[2] = {'.', ']'};
40487a984708SDavid Chisnall    _ForwardIterator __temp = _VSTD::search(__first, __last, _Dot_close,
40497a984708SDavid Chisnall                                                            _Dot_close+2);
40507a984708SDavid Chisnall    if (__temp == __last)
40519729cf09SDimitry Andric        __throw_regex_error<regex_constants::error_brack>();
40527a984708SDavid Chisnall    // [__first, __temp) contains all text in [. ... .]
40537a984708SDavid Chisnall    __col_sym = __traits_.lookup_collatename(__first, __temp);
40547a984708SDavid Chisnall    switch (__col_sym.size())
40557a984708SDavid Chisnall    {
40567a984708SDavid Chisnall    case 1:
40577a984708SDavid Chisnall    case 2:
40587a984708SDavid Chisnall        break;
40597a984708SDavid Chisnall    default:
40609729cf09SDimitry Andric        __throw_regex_error<regex_constants::error_collate>();
40617a984708SDavid Chisnall    }
40627a984708SDavid Chisnall    __first = _VSTD::next(__temp, 2);
40637a984708SDavid Chisnall    return __first;
40647a984708SDavid Chisnall}
40657a984708SDavid Chisnall
40667a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
40677a984708SDavid Chisnalltemplate <class _ForwardIterator>
40687a984708SDavid Chisnall_ForwardIterator
40697a984708SDavid Chisnallbasic_regex<_CharT, _Traits>::__parse_DUP_COUNT(_ForwardIterator __first,
40707a984708SDavid Chisnall                                                _ForwardIterator __last,
40717a984708SDavid Chisnall                                                int& __c)
40727a984708SDavid Chisnall{
4073d72607e9SDimitry Andric    if (__first != __last )
40747a984708SDavid Chisnall    {
4075d72607e9SDimitry Andric        int __val = __traits_.value(*__first, 10);
4076d72607e9SDimitry Andric        if ( __val != -1 )
4077d72607e9SDimitry Andric        {
4078d72607e9SDimitry Andric            __c = __val;
4079d72607e9SDimitry Andric            for (++__first;
4080d72607e9SDimitry Andric                 __first != __last && ( __val = __traits_.value(*__first, 10)) != -1;
40817a984708SDavid Chisnall                 ++__first)
40827a984708SDavid Chisnall            {
4083b2c7081bSDimitry Andric                if (__c >= std::numeric_limits<int>::max() / 10)
4084b2c7081bSDimitry Andric                    __throw_regex_error<regex_constants::error_badbrace>();
40857a984708SDavid Chisnall                __c *= 10;
4086d72607e9SDimitry Andric                __c += __val;
4087d72607e9SDimitry Andric            }
40887a984708SDavid Chisnall        }
40897a984708SDavid Chisnall    }
40907a984708SDavid Chisnall    return __first;
40917a984708SDavid Chisnall}
40927a984708SDavid Chisnall
40937a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
40947a984708SDavid Chisnalltemplate <class _ForwardIterator>
40957a984708SDavid Chisnall_ForwardIterator
40967a984708SDavid Chisnallbasic_regex<_CharT, _Traits>::__parse_ecma_exp(_ForwardIterator __first,
40977a984708SDavid Chisnall                                               _ForwardIterator __last)
40987a984708SDavid Chisnall{
40997a984708SDavid Chisnall    __owns_one_state<_CharT>* __sa = __end_;
41007a984708SDavid Chisnall    _ForwardIterator __temp = __parse_alternative(__first, __last);
41017a984708SDavid Chisnall    if (__temp == __first)
41027a984708SDavid Chisnall        __push_empty();
41037a984708SDavid Chisnall    __first = __temp;
41047a984708SDavid Chisnall    while (__first != __last && *__first == '|')
41057a984708SDavid Chisnall    {
41067a984708SDavid Chisnall        __owns_one_state<_CharT>* __sb = __end_;
41077a984708SDavid Chisnall        __temp = __parse_alternative(++__first, __last);
41087a984708SDavid Chisnall        if (__temp == __first)
41097a984708SDavid Chisnall            __push_empty();
41107a984708SDavid Chisnall        __push_alternation(__sa, __sb);
41117a984708SDavid Chisnall        __first = __temp;
41127a984708SDavid Chisnall    }
41137a984708SDavid Chisnall    return __first;
41147a984708SDavid Chisnall}
41157a984708SDavid Chisnall
41167a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
41177a984708SDavid Chisnalltemplate <class _ForwardIterator>
41187a984708SDavid Chisnall_ForwardIterator
41197a984708SDavid Chisnallbasic_regex<_CharT, _Traits>::__parse_alternative(_ForwardIterator __first,
41207a984708SDavid Chisnall                                                  _ForwardIterator __last)
41217a984708SDavid Chisnall{
41227a984708SDavid Chisnall    while (true)
41237a984708SDavid Chisnall    {
41247a984708SDavid Chisnall        _ForwardIterator __temp = __parse_term(__first, __last);
41257a984708SDavid Chisnall        if (__temp == __first)
41267a984708SDavid Chisnall            break;
41277a984708SDavid Chisnall        __first = __temp;
41287a984708SDavid Chisnall    }
41297a984708SDavid Chisnall    return __first;
41307a984708SDavid Chisnall}
41317a984708SDavid Chisnall
41327a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
41337a984708SDavid Chisnalltemplate <class _ForwardIterator>
41347a984708SDavid Chisnall_ForwardIterator
41357a984708SDavid Chisnallbasic_regex<_CharT, _Traits>::__parse_term(_ForwardIterator __first,
41367a984708SDavid Chisnall                                           _ForwardIterator __last)
41377a984708SDavid Chisnall{
41387a984708SDavid Chisnall    _ForwardIterator __temp = __parse_assertion(__first, __last);
41397a984708SDavid Chisnall    if (__temp == __first)
41407a984708SDavid Chisnall    {
41417a984708SDavid Chisnall        __owns_one_state<_CharT>* __e = __end_;
41427a984708SDavid Chisnall        unsigned __mexp_begin = __marked_count_;
41437a984708SDavid Chisnall        __temp = __parse_atom(__first, __last);
41447a984708SDavid Chisnall        if (__temp != __first)
41457a984708SDavid Chisnall            __first = __parse_ERE_dupl_symbol(__temp, __last, __e,
41467a984708SDavid Chisnall                                              __mexp_begin+1, __marked_count_+1);
41477a984708SDavid Chisnall    }
41487a984708SDavid Chisnall    else
41497a984708SDavid Chisnall        __first = __temp;
41507a984708SDavid Chisnall    return __first;
41517a984708SDavid Chisnall}
41527a984708SDavid Chisnall
41537a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
41547a984708SDavid Chisnalltemplate <class _ForwardIterator>
41557a984708SDavid Chisnall_ForwardIterator
41567a984708SDavid Chisnallbasic_regex<_CharT, _Traits>::__parse_assertion(_ForwardIterator __first,
41577a984708SDavid Chisnall                                                _ForwardIterator __last)
41587a984708SDavid Chisnall{
41597a984708SDavid Chisnall    if (__first != __last)
41607a984708SDavid Chisnall    {
41617a984708SDavid Chisnall        switch (*__first)
41627a984708SDavid Chisnall        {
41637a984708SDavid Chisnall        case '^':
41647a984708SDavid Chisnall            __push_l_anchor();
41657a984708SDavid Chisnall            ++__first;
41667a984708SDavid Chisnall            break;
41677a984708SDavid Chisnall        case '$':
41687a984708SDavid Chisnall            __push_r_anchor();
41697a984708SDavid Chisnall            ++__first;
41707a984708SDavid Chisnall            break;
41717a984708SDavid Chisnall        case '\\':
41727a984708SDavid Chisnall            {
41737a984708SDavid Chisnall                _ForwardIterator __temp = _VSTD::next(__first);
41747a984708SDavid Chisnall                if (__temp != __last)
41757a984708SDavid Chisnall                {
41767a984708SDavid Chisnall                    if (*__temp == 'b')
41777a984708SDavid Chisnall                    {
41787a984708SDavid Chisnall                        __push_word_boundary(false);
41797a984708SDavid Chisnall                        __first = ++__temp;
41807a984708SDavid Chisnall                    }
41817a984708SDavid Chisnall                    else if (*__temp == 'B')
41827a984708SDavid Chisnall                    {
41837a984708SDavid Chisnall                        __push_word_boundary(true);
41847a984708SDavid Chisnall                        __first = ++__temp;
41857a984708SDavid Chisnall                    }
41867a984708SDavid Chisnall                }
41877a984708SDavid Chisnall            }
41887a984708SDavid Chisnall            break;
41897a984708SDavid Chisnall        case '(':
41907a984708SDavid Chisnall            {
41917a984708SDavid Chisnall                _ForwardIterator __temp = _VSTD::next(__first);
41927a984708SDavid Chisnall                if (__temp != __last && *__temp == '?')
41937a984708SDavid Chisnall                {
41947a984708SDavid Chisnall                    if (++__temp != __last)
41957a984708SDavid Chisnall                    {
41967a984708SDavid Chisnall                        switch (*__temp)
41977a984708SDavid Chisnall                        {
41987a984708SDavid Chisnall                        case '=':
41997a984708SDavid Chisnall                            {
42007a984708SDavid Chisnall                                basic_regex __exp;
42017a984708SDavid Chisnall                                __exp.__flags_ = __flags_;
42027a984708SDavid Chisnall                                __temp = __exp.__parse(++__temp, __last);
42034f7ab58eSDimitry Andric                                unsigned __mexp = __exp.__marked_count_;
42044f7ab58eSDimitry Andric                                __push_lookahead(_VSTD::move(__exp), false, __marked_count_);
42054f7ab58eSDimitry Andric                                __marked_count_ += __mexp;
42067a984708SDavid Chisnall                                if (__temp == __last || *__temp != ')')
42079729cf09SDimitry Andric                                    __throw_regex_error<regex_constants::error_paren>();
42087a984708SDavid Chisnall                                __first = ++__temp;
42097a984708SDavid Chisnall                            }
42107a984708SDavid Chisnall                            break;
42117a984708SDavid Chisnall                        case '!':
42127a984708SDavid Chisnall                            {
42137a984708SDavid Chisnall                                basic_regex __exp;
42147a984708SDavid Chisnall                                __exp.__flags_ = __flags_;
42157a984708SDavid Chisnall                                __temp = __exp.__parse(++__temp, __last);
42164f7ab58eSDimitry Andric                                unsigned __mexp = __exp.__marked_count_;
42174f7ab58eSDimitry Andric                                __push_lookahead(_VSTD::move(__exp), true, __marked_count_);
42184f7ab58eSDimitry Andric                                __marked_count_ += __mexp;
42197a984708SDavid Chisnall                                if (__temp == __last || *__temp != ')')
42209729cf09SDimitry Andric                                    __throw_regex_error<regex_constants::error_paren>();
42217a984708SDavid Chisnall                                __first = ++__temp;
42227a984708SDavid Chisnall                            }
42237a984708SDavid Chisnall                            break;
42247a984708SDavid Chisnall                        }
42257a984708SDavid Chisnall                    }
42267a984708SDavid Chisnall                }
42277a984708SDavid Chisnall            }
42287a984708SDavid Chisnall            break;
42297a984708SDavid Chisnall        }
42307a984708SDavid Chisnall    }
42317a984708SDavid Chisnall    return __first;
42327a984708SDavid Chisnall}
42337a984708SDavid Chisnall
42347a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
42357a984708SDavid Chisnalltemplate <class _ForwardIterator>
42367a984708SDavid Chisnall_ForwardIterator
42377a984708SDavid Chisnallbasic_regex<_CharT, _Traits>::__parse_atom(_ForwardIterator __first,
42387a984708SDavid Chisnall                                           _ForwardIterator __last)
42397a984708SDavid Chisnall{
42407a984708SDavid Chisnall    if (__first != __last)
42417a984708SDavid Chisnall    {
42427a984708SDavid Chisnall        switch (*__first)
42437a984708SDavid Chisnall        {
42447a984708SDavid Chisnall        case '.':
42457a984708SDavid Chisnall            __push_match_any_but_newline();
42467a984708SDavid Chisnall            ++__first;
42477a984708SDavid Chisnall            break;
42487a984708SDavid Chisnall        case '\\':
42497a984708SDavid Chisnall            __first = __parse_atom_escape(__first, __last);
42507a984708SDavid Chisnall            break;
42517a984708SDavid Chisnall        case '[':
42527a984708SDavid Chisnall            __first = __parse_bracket_expression(__first, __last);
42537a984708SDavid Chisnall            break;
42547a984708SDavid Chisnall        case '(':
42557a984708SDavid Chisnall            {
42567a984708SDavid Chisnall                ++__first;
42577a984708SDavid Chisnall                if (__first == __last)
42589729cf09SDimitry Andric                    __throw_regex_error<regex_constants::error_paren>();
42597a984708SDavid Chisnall                _ForwardIterator __temp = _VSTD::next(__first);
42607a984708SDavid Chisnall                if (__temp != __last && *__first == '?' && *__temp == ':')
42617a984708SDavid Chisnall                {
42627a984708SDavid Chisnall                    ++__open_count_;
42637a984708SDavid Chisnall                    __first = __parse_ecma_exp(++__temp, __last);
42647a984708SDavid Chisnall                    if (__first == __last || *__first != ')')
42659729cf09SDimitry Andric                        __throw_regex_error<regex_constants::error_paren>();
42667a984708SDavid Chisnall                    --__open_count_;
42677a984708SDavid Chisnall                    ++__first;
42687a984708SDavid Chisnall                }
42697a984708SDavid Chisnall                else
42707a984708SDavid Chisnall                {
42717a984708SDavid Chisnall                    __push_begin_marked_subexpression();
42727a984708SDavid Chisnall                    unsigned __temp_count = __marked_count_;
42737a984708SDavid Chisnall                    ++__open_count_;
42747a984708SDavid Chisnall                    __first = __parse_ecma_exp(__first, __last);
42757a984708SDavid Chisnall                    if (__first == __last || *__first != ')')
42769729cf09SDimitry Andric                        __throw_regex_error<regex_constants::error_paren>();
42777a984708SDavid Chisnall                    __push_end_marked_subexpression(__temp_count);
42787a984708SDavid Chisnall                    --__open_count_;
42797a984708SDavid Chisnall                    ++__first;
42807a984708SDavid Chisnall                }
42817a984708SDavid Chisnall            }
42827a984708SDavid Chisnall            break;
42839729cf09SDimitry Andric        case '*':
42849729cf09SDimitry Andric        case '+':
42859729cf09SDimitry Andric        case '?':
42869729cf09SDimitry Andric        case '{':
42879729cf09SDimitry Andric            __throw_regex_error<regex_constants::error_badrepeat>();
42889729cf09SDimitry Andric            break;
42897a984708SDavid Chisnall        default:
42907a984708SDavid Chisnall            __first = __parse_pattern_character(__first, __last);
42917a984708SDavid Chisnall            break;
42927a984708SDavid Chisnall        }
42937a984708SDavid Chisnall    }
42947a984708SDavid Chisnall    return __first;
42957a984708SDavid Chisnall}
42967a984708SDavid Chisnall
42977a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
42987a984708SDavid Chisnalltemplate <class _ForwardIterator>
42997a984708SDavid Chisnall_ForwardIterator
43007a984708SDavid Chisnallbasic_regex<_CharT, _Traits>::__parse_atom_escape(_ForwardIterator __first,
43017a984708SDavid Chisnall                                                  _ForwardIterator __last)
43027a984708SDavid Chisnall{
43037a984708SDavid Chisnall    if (__first != __last && *__first == '\\')
43047a984708SDavid Chisnall    {
43057a984708SDavid Chisnall        _ForwardIterator __t1 = _VSTD::next(__first);
43069729cf09SDimitry Andric        if (__t1 == __last)
43079729cf09SDimitry Andric            __throw_regex_error<regex_constants::error_escape>();
43089729cf09SDimitry Andric
43097a984708SDavid Chisnall        _ForwardIterator __t2 = __parse_decimal_escape(__t1, __last);
43107a984708SDavid Chisnall        if (__t2 != __t1)
43117a984708SDavid Chisnall            __first = __t2;
43127a984708SDavid Chisnall        else
43137a984708SDavid Chisnall        {
43147a984708SDavid Chisnall            __t2 = __parse_character_class_escape(__t1, __last);
43157a984708SDavid Chisnall            if (__t2 != __t1)
43167a984708SDavid Chisnall                __first = __t2;
43177a984708SDavid Chisnall            else
43187a984708SDavid Chisnall            {
43197a984708SDavid Chisnall                __t2 = __parse_character_escape(__t1, __last);
43207a984708SDavid Chisnall                if (__t2 != __t1)
43217a984708SDavid Chisnall                    __first = __t2;
43227a984708SDavid Chisnall            }
43237a984708SDavid Chisnall        }
43247a984708SDavid Chisnall    }
43257a984708SDavid Chisnall    return __first;
43267a984708SDavid Chisnall}
43277a984708SDavid Chisnall
43287a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
43297a984708SDavid Chisnalltemplate <class _ForwardIterator>
43307a984708SDavid Chisnall_ForwardIterator
43317a984708SDavid Chisnallbasic_regex<_CharT, _Traits>::__parse_decimal_escape(_ForwardIterator __first,
43327a984708SDavid Chisnall                                                     _ForwardIterator __last)
43337a984708SDavid Chisnall{
43347a984708SDavid Chisnall    if (__first != __last)
43357a984708SDavid Chisnall    {
43367a984708SDavid Chisnall        if (*__first == '0')
43377a984708SDavid Chisnall        {
43387a984708SDavid Chisnall            __push_char(_CharT());
43397a984708SDavid Chisnall            ++__first;
43407a984708SDavid Chisnall        }
43417a984708SDavid Chisnall        else if ('1' <= *__first && *__first <= '9')
43427a984708SDavid Chisnall        {
43437a984708SDavid Chisnall            unsigned __v = *__first - '0';
4344aed8d94eSDimitry Andric            for (++__first;
4345aed8d94eSDimitry Andric                    __first != __last && '0' <= *__first && *__first <= '9'; ++__first)
4346b2c7081bSDimitry Andric                {
4347b2c7081bSDimitry Andric                if (__v >= std::numeric_limits<unsigned>::max() / 10)
4348b2c7081bSDimitry Andric                    __throw_regex_error<regex_constants::error_backref>();
43497a984708SDavid Chisnall                __v = 10 * __v + *__first - '0';
4350b2c7081bSDimitry Andric                }
4351b2c7081bSDimitry Andric            if (__v == 0 || __v > mark_count())
43529729cf09SDimitry Andric                __throw_regex_error<regex_constants::error_backref>();
43537a984708SDavid Chisnall            __push_back_ref(__v);
43547a984708SDavid Chisnall        }
43557a984708SDavid Chisnall    }
43567a984708SDavid Chisnall    return __first;
43577a984708SDavid Chisnall}
43587a984708SDavid Chisnall
43597a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
43607a984708SDavid Chisnalltemplate <class _ForwardIterator>
43617a984708SDavid Chisnall_ForwardIterator
43627a984708SDavid Chisnallbasic_regex<_CharT, _Traits>::__parse_character_class_escape(_ForwardIterator __first,
43637a984708SDavid Chisnall                                                             _ForwardIterator __last)
43647a984708SDavid Chisnall{
43657a984708SDavid Chisnall    if (__first != __last)
43667a984708SDavid Chisnall    {
43677a984708SDavid Chisnall        __bracket_expression<_CharT, _Traits>* __ml;
43687a984708SDavid Chisnall        switch (*__first)
43697a984708SDavid Chisnall        {
43707a984708SDavid Chisnall        case 'd':
43717a984708SDavid Chisnall            __ml = __start_matching_list(false);
43727a984708SDavid Chisnall            __ml->__add_class(ctype_base::digit);
43737a984708SDavid Chisnall            ++__first;
43747a984708SDavid Chisnall            break;
43757a984708SDavid Chisnall        case 'D':
43767a984708SDavid Chisnall            __ml = __start_matching_list(true);
43777a984708SDavid Chisnall            __ml->__add_class(ctype_base::digit);
43787a984708SDavid Chisnall            ++__first;
43797a984708SDavid Chisnall            break;
43807a984708SDavid Chisnall        case 's':
43817a984708SDavid Chisnall            __ml = __start_matching_list(false);
43827a984708SDavid Chisnall            __ml->__add_class(ctype_base::space);
43837a984708SDavid Chisnall            ++__first;
43847a984708SDavid Chisnall            break;
43857a984708SDavid Chisnall        case 'S':
43867a984708SDavid Chisnall            __ml = __start_matching_list(true);
43877a984708SDavid Chisnall            __ml->__add_class(ctype_base::space);
43887a984708SDavid Chisnall            ++__first;
43897a984708SDavid Chisnall            break;
43907a984708SDavid Chisnall        case 'w':
43917a984708SDavid Chisnall            __ml = __start_matching_list(false);
43927a984708SDavid Chisnall            __ml->__add_class(ctype_base::alnum);
43937a984708SDavid Chisnall            __ml->__add_char('_');
43947a984708SDavid Chisnall            ++__first;
43957a984708SDavid Chisnall            break;
43967a984708SDavid Chisnall        case 'W':
43977a984708SDavid Chisnall            __ml = __start_matching_list(true);
43987a984708SDavid Chisnall            __ml->__add_class(ctype_base::alnum);
43997a984708SDavid Chisnall            __ml->__add_char('_');
44007a984708SDavid Chisnall            ++__first;
44017a984708SDavid Chisnall            break;
44027a984708SDavid Chisnall        }
44037a984708SDavid Chisnall    }
44047a984708SDavid Chisnall    return __first;
44057a984708SDavid Chisnall}
44067a984708SDavid Chisnall
44077a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
44087a984708SDavid Chisnalltemplate <class _ForwardIterator>
44097a984708SDavid Chisnall_ForwardIterator
44107a984708SDavid Chisnallbasic_regex<_CharT, _Traits>::__parse_character_escape(_ForwardIterator __first,
44117a984708SDavid Chisnall                                                    _ForwardIterator __last,
44127a984708SDavid Chisnall                                                    basic_string<_CharT>* __str)
44137a984708SDavid Chisnall{
44147a984708SDavid Chisnall    if (__first != __last)
44157a984708SDavid Chisnall    {
44167a984708SDavid Chisnall        _ForwardIterator __t;
44177a984708SDavid Chisnall        unsigned __sum = 0;
44187a984708SDavid Chisnall        int __hd;
44197a984708SDavid Chisnall        switch (*__first)
44207a984708SDavid Chisnall        {
44217a984708SDavid Chisnall        case 'f':
44227a984708SDavid Chisnall            if (__str)
44237a984708SDavid Chisnall                *__str = _CharT(0xC);
44247a984708SDavid Chisnall            else
44257a984708SDavid Chisnall                __push_char(_CharT(0xC));
44267a984708SDavid Chisnall            ++__first;
44277a984708SDavid Chisnall            break;
44287a984708SDavid Chisnall        case 'n':
44297a984708SDavid Chisnall            if (__str)
44307a984708SDavid Chisnall                *__str = _CharT(0xA);
44317a984708SDavid Chisnall            else
44327a984708SDavid Chisnall                __push_char(_CharT(0xA));
44337a984708SDavid Chisnall            ++__first;
44347a984708SDavid Chisnall            break;
44357a984708SDavid Chisnall        case 'r':
44367a984708SDavid Chisnall            if (__str)
44377a984708SDavid Chisnall                *__str = _CharT(0xD);
44387a984708SDavid Chisnall            else
44397a984708SDavid Chisnall                __push_char(_CharT(0xD));
44407a984708SDavid Chisnall            ++__first;
44417a984708SDavid Chisnall            break;
44427a984708SDavid Chisnall        case 't':
44437a984708SDavid Chisnall            if (__str)
44447a984708SDavid Chisnall                *__str = _CharT(0x9);
44457a984708SDavid Chisnall            else
44467a984708SDavid Chisnall                __push_char(_CharT(0x9));
44477a984708SDavid Chisnall            ++__first;
44487a984708SDavid Chisnall            break;
44497a984708SDavid Chisnall        case 'v':
44507a984708SDavid Chisnall            if (__str)
44517a984708SDavid Chisnall                *__str = _CharT(0xB);
44527a984708SDavid Chisnall            else
44537a984708SDavid Chisnall                __push_char(_CharT(0xB));
44547a984708SDavid Chisnall            ++__first;
44557a984708SDavid Chisnall            break;
44567a984708SDavid Chisnall        case 'c':
44577a984708SDavid Chisnall            if ((__t = _VSTD::next(__first)) != __last)
44587a984708SDavid Chisnall            {
44594f7ab58eSDimitry Andric                if (('A' <= *__t && *__t <= 'Z') ||
44604f7ab58eSDimitry Andric                    ('a' <= *__t && *__t <= 'z'))
44617a984708SDavid Chisnall                {
44627a984708SDavid Chisnall                    if (__str)
44637a984708SDavid Chisnall                        *__str = _CharT(*__t % 32);
44647a984708SDavid Chisnall                    else
44657a984708SDavid Chisnall                        __push_char(_CharT(*__t % 32));
44667a984708SDavid Chisnall                    __first = ++__t;
44677a984708SDavid Chisnall                }
44684f7ab58eSDimitry Andric                else
44699729cf09SDimitry Andric                    __throw_regex_error<regex_constants::error_escape>();
44707a984708SDavid Chisnall            }
44714f7ab58eSDimitry Andric            else
44729729cf09SDimitry Andric                __throw_regex_error<regex_constants::error_escape>();
44737a984708SDavid Chisnall            break;
44747a984708SDavid Chisnall        case 'u':
44757a984708SDavid Chisnall            ++__first;
44767a984708SDavid Chisnall            if (__first == __last)
44779729cf09SDimitry Andric                __throw_regex_error<regex_constants::error_escape>();
44787a984708SDavid Chisnall            __hd = __traits_.value(*__first, 16);
44797a984708SDavid Chisnall            if (__hd == -1)
44809729cf09SDimitry Andric                __throw_regex_error<regex_constants::error_escape>();
448194e3ee44SDavid Chisnall            __sum = 16 * __sum + static_cast<unsigned>(__hd);
44827a984708SDavid Chisnall            ++__first;
44837a984708SDavid Chisnall            if (__first == __last)
44849729cf09SDimitry Andric                __throw_regex_error<regex_constants::error_escape>();
44857a984708SDavid Chisnall            __hd = __traits_.value(*__first, 16);
44867a984708SDavid Chisnall            if (__hd == -1)
44879729cf09SDimitry Andric                __throw_regex_error<regex_constants::error_escape>();
448894e3ee44SDavid Chisnall            __sum = 16 * __sum + static_cast<unsigned>(__hd);
44897a984708SDavid Chisnall            // drop through
44907a984708SDavid Chisnall        case 'x':
44917a984708SDavid Chisnall            ++__first;
44927a984708SDavid Chisnall            if (__first == __last)
44939729cf09SDimitry Andric                __throw_regex_error<regex_constants::error_escape>();
44947a984708SDavid Chisnall            __hd = __traits_.value(*__first, 16);
44957a984708SDavid Chisnall            if (__hd == -1)
44969729cf09SDimitry Andric                __throw_regex_error<regex_constants::error_escape>();
449794e3ee44SDavid Chisnall            __sum = 16 * __sum + static_cast<unsigned>(__hd);
44987a984708SDavid Chisnall            ++__first;
44997a984708SDavid Chisnall            if (__first == __last)
45009729cf09SDimitry Andric                __throw_regex_error<regex_constants::error_escape>();
45017a984708SDavid Chisnall            __hd = __traits_.value(*__first, 16);
45027a984708SDavid Chisnall            if (__hd == -1)
45039729cf09SDimitry Andric                __throw_regex_error<regex_constants::error_escape>();
450494e3ee44SDavid Chisnall            __sum = 16 * __sum + static_cast<unsigned>(__hd);
45057a984708SDavid Chisnall            if (__str)
45067a984708SDavid Chisnall                *__str = _CharT(__sum);
45077a984708SDavid Chisnall            else
45087a984708SDavid Chisnall                __push_char(_CharT(__sum));
45097a984708SDavid Chisnall            ++__first;
45107a984708SDavid Chisnall            break;
4511d72607e9SDimitry Andric        case '0':
4512d72607e9SDimitry Andric            if (__str)
4513d72607e9SDimitry Andric                *__str = _CharT(0);
4514d72607e9SDimitry Andric            else
4515d72607e9SDimitry Andric                __push_char(_CharT(0));
4516d72607e9SDimitry Andric            ++__first;
4517d72607e9SDimitry Andric            break;
45187a984708SDavid Chisnall        default:
45197a984708SDavid Chisnall            if (*__first != '_' && !__traits_.isctype(*__first, ctype_base::alnum))
45207a984708SDavid Chisnall            {
45217a984708SDavid Chisnall                if (__str)
45227a984708SDavid Chisnall                    *__str = *__first;
45237a984708SDavid Chisnall                else
45247a984708SDavid Chisnall                    __push_char(*__first);
45257a984708SDavid Chisnall                ++__first;
45267a984708SDavid Chisnall            }
45274bab9fd9SDavid Chisnall            else
45289729cf09SDimitry Andric                __throw_regex_error<regex_constants::error_escape>();
45297a984708SDavid Chisnall            break;
45307a984708SDavid Chisnall        }
45317a984708SDavid Chisnall    }
45327a984708SDavid Chisnall    return __first;
45337a984708SDavid Chisnall}
45347a984708SDavid Chisnall
45357a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
45367a984708SDavid Chisnalltemplate <class _ForwardIterator>
45377a984708SDavid Chisnall_ForwardIterator
45387a984708SDavid Chisnallbasic_regex<_CharT, _Traits>::__parse_pattern_character(_ForwardIterator __first,
45397a984708SDavid Chisnall                                                        _ForwardIterator __last)
45407a984708SDavid Chisnall{
45417a984708SDavid Chisnall    if (__first != __last)
45427a984708SDavid Chisnall    {
45437a984708SDavid Chisnall        switch (*__first)
45447a984708SDavid Chisnall        {
45457a984708SDavid Chisnall        case '^':
45467a984708SDavid Chisnall        case '$':
45477a984708SDavid Chisnall        case '\\':
45487a984708SDavid Chisnall        case '.':
45497a984708SDavid Chisnall        case '*':
45507a984708SDavid Chisnall        case '+':
45517a984708SDavid Chisnall        case '?':
45527a984708SDavid Chisnall        case '(':
45537a984708SDavid Chisnall        case ')':
45547a984708SDavid Chisnall        case '[':
45557a984708SDavid Chisnall        case ']':
45567a984708SDavid Chisnall        case '{':
45577a984708SDavid Chisnall        case '}':
45587a984708SDavid Chisnall        case '|':
45597a984708SDavid Chisnall            break;
45607a984708SDavid Chisnall        default:
45617a984708SDavid Chisnall            __push_char(*__first);
45627a984708SDavid Chisnall            ++__first;
45637a984708SDavid Chisnall            break;
45647a984708SDavid Chisnall        }
45657a984708SDavid Chisnall    }
45667a984708SDavid Chisnall    return __first;
45677a984708SDavid Chisnall}
45687a984708SDavid Chisnall
45697a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
45707a984708SDavid Chisnalltemplate <class _ForwardIterator>
45717a984708SDavid Chisnall_ForwardIterator
45727a984708SDavid Chisnallbasic_regex<_CharT, _Traits>::__parse_grep(_ForwardIterator __first,
45737a984708SDavid Chisnall                                           _ForwardIterator __last)
45747a984708SDavid Chisnall{
45757a984708SDavid Chisnall    __owns_one_state<_CharT>* __sa = __end_;
45767a984708SDavid Chisnall    _ForwardIterator __t1 = _VSTD::find(__first, __last, _CharT('\n'));
45777a984708SDavid Chisnall    if (__t1 != __first)
45787a984708SDavid Chisnall        __parse_basic_reg_exp(__first, __t1);
45797a984708SDavid Chisnall    else
45807a984708SDavid Chisnall        __push_empty();
45817a984708SDavid Chisnall    __first = __t1;
45827a984708SDavid Chisnall    if (__first != __last)
45837a984708SDavid Chisnall        ++__first;
45847a984708SDavid Chisnall    while (__first != __last)
45857a984708SDavid Chisnall    {
45867a984708SDavid Chisnall        __t1 = _VSTD::find(__first, __last, _CharT('\n'));
45877a984708SDavid Chisnall        __owns_one_state<_CharT>* __sb = __end_;
45887a984708SDavid Chisnall        if (__t1 != __first)
45897a984708SDavid Chisnall            __parse_basic_reg_exp(__first, __t1);
45907a984708SDavid Chisnall        else
45917a984708SDavid Chisnall            __push_empty();
45927a984708SDavid Chisnall        __push_alternation(__sa, __sb);
45937a984708SDavid Chisnall        __first = __t1;
45947a984708SDavid Chisnall        if (__first != __last)
45957a984708SDavid Chisnall            ++__first;
45967a984708SDavid Chisnall    }
45977a984708SDavid Chisnall    return __first;
45987a984708SDavid Chisnall}
45997a984708SDavid Chisnall
46007a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
46017a984708SDavid Chisnalltemplate <class _ForwardIterator>
46027a984708SDavid Chisnall_ForwardIterator
46037a984708SDavid Chisnallbasic_regex<_CharT, _Traits>::__parse_egrep(_ForwardIterator __first,
46047a984708SDavid Chisnall                                            _ForwardIterator __last)
46057a984708SDavid Chisnall{
46067a984708SDavid Chisnall    __owns_one_state<_CharT>* __sa = __end_;
46077a984708SDavid Chisnall    _ForwardIterator __t1 = _VSTD::find(__first, __last, _CharT('\n'));
46087a984708SDavid Chisnall    if (__t1 != __first)
46097a984708SDavid Chisnall        __parse_extended_reg_exp(__first, __t1);
46107a984708SDavid Chisnall    else
46117a984708SDavid Chisnall        __push_empty();
46127a984708SDavid Chisnall    __first = __t1;
46137a984708SDavid Chisnall    if (__first != __last)
46147a984708SDavid Chisnall        ++__first;
46157a984708SDavid Chisnall    while (__first != __last)
46167a984708SDavid Chisnall    {
46177a984708SDavid Chisnall        __t1 = _VSTD::find(__first, __last, _CharT('\n'));
46187a984708SDavid Chisnall        __owns_one_state<_CharT>* __sb = __end_;
46197a984708SDavid Chisnall        if (__t1 != __first)
46207a984708SDavid Chisnall            __parse_extended_reg_exp(__first, __t1);
46217a984708SDavid Chisnall        else
46227a984708SDavid Chisnall            __push_empty();
46237a984708SDavid Chisnall        __push_alternation(__sa, __sb);
46247a984708SDavid Chisnall        __first = __t1;
46257a984708SDavid Chisnall        if (__first != __last)
46267a984708SDavid Chisnall            ++__first;
46277a984708SDavid Chisnall    }
46287a984708SDavid Chisnall    return __first;
46297a984708SDavid Chisnall}
46307a984708SDavid Chisnall
46317a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
46327a984708SDavid Chisnallvoid
46337a984708SDavid Chisnallbasic_regex<_CharT, _Traits>::__push_loop(size_t __min, size_t __max,
46347a984708SDavid Chisnall        __owns_one_state<_CharT>* __s, size_t __mexp_begin, size_t __mexp_end,
46357a984708SDavid Chisnall        bool __greedy)
46367a984708SDavid Chisnall{
46377a984708SDavid Chisnall    unique_ptr<__empty_state<_CharT> > __e1(new __empty_state<_CharT>(__end_->first()));
46387a984708SDavid Chisnall    __end_->first() = nullptr;
46397a984708SDavid Chisnall    unique_ptr<__loop<_CharT> > __e2(new __loop<_CharT>(__loop_count_,
46407a984708SDavid Chisnall                __s->first(), __e1.get(), __mexp_begin, __mexp_end, __greedy,
46417a984708SDavid Chisnall                __min, __max));
46427a984708SDavid Chisnall    __s->first() = nullptr;
46437a984708SDavid Chisnall    __e1.release();
46447a984708SDavid Chisnall    __end_->first() = new __repeat_one_loop<_CharT>(__e2.get());
46457a984708SDavid Chisnall    __end_ = __e2->second();
46467a984708SDavid Chisnall    __s->first() = __e2.release();
46477a984708SDavid Chisnall    ++__loop_count_;
46487a984708SDavid Chisnall}
46497a984708SDavid Chisnall
46507a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
46517a984708SDavid Chisnallvoid
46527a984708SDavid Chisnallbasic_regex<_CharT, _Traits>::__push_char(value_type __c)
46537a984708SDavid Chisnall{
46547a984708SDavid Chisnall    if (flags() & icase)
46557a984708SDavid Chisnall        __end_->first() = new __match_char_icase<_CharT, _Traits>
46567a984708SDavid Chisnall                                              (__traits_, __c, __end_->first());
46577a984708SDavid Chisnall    else if (flags() & collate)
46587a984708SDavid Chisnall        __end_->first() = new __match_char_collate<_CharT, _Traits>
46597a984708SDavid Chisnall                                              (__traits_, __c, __end_->first());
46607a984708SDavid Chisnall    else
46617a984708SDavid Chisnall        __end_->first() = new __match_char<_CharT>(__c, __end_->first());
46627a984708SDavid Chisnall    __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
46637a984708SDavid Chisnall}
46647a984708SDavid Chisnall
46657a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
46667a984708SDavid Chisnallvoid
46677a984708SDavid Chisnallbasic_regex<_CharT, _Traits>::__push_begin_marked_subexpression()
46687a984708SDavid Chisnall{
46697a984708SDavid Chisnall    if (!(__flags_ & nosubs))
46707a984708SDavid Chisnall    {
46717a984708SDavid Chisnall        __end_->first() =
46727a984708SDavid Chisnall                new __begin_marked_subexpression<_CharT>(++__marked_count_,
46737a984708SDavid Chisnall                                                         __end_->first());
46747a984708SDavid Chisnall        __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
46757a984708SDavid Chisnall    }
46767a984708SDavid Chisnall}
46777a984708SDavid Chisnall
46787a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
46797a984708SDavid Chisnallvoid
46807a984708SDavid Chisnallbasic_regex<_CharT, _Traits>::__push_end_marked_subexpression(unsigned __sub)
46817a984708SDavid Chisnall{
46827a984708SDavid Chisnall    if (!(__flags_ & nosubs))
46837a984708SDavid Chisnall    {
46847a984708SDavid Chisnall        __end_->first() =
46857a984708SDavid Chisnall                new __end_marked_subexpression<_CharT>(__sub, __end_->first());
46867a984708SDavid Chisnall        __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
46877a984708SDavid Chisnall    }
46887a984708SDavid Chisnall}
46897a984708SDavid Chisnall
46907a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
46917a984708SDavid Chisnallvoid
46927a984708SDavid Chisnallbasic_regex<_CharT, _Traits>::__push_l_anchor()
46937a984708SDavid Chisnall{
46947a984708SDavid Chisnall    __end_->first() = new __l_anchor<_CharT>(__end_->first());
46957a984708SDavid Chisnall    __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
46967a984708SDavid Chisnall}
46977a984708SDavid Chisnall
46987a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
46997a984708SDavid Chisnallvoid
47007a984708SDavid Chisnallbasic_regex<_CharT, _Traits>::__push_r_anchor()
47017a984708SDavid Chisnall{
47027a984708SDavid Chisnall    __end_->first() = new __r_anchor<_CharT>(__end_->first());
47037a984708SDavid Chisnall    __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
47047a984708SDavid Chisnall}
47057a984708SDavid Chisnall
47067a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
47077a984708SDavid Chisnallvoid
47087a984708SDavid Chisnallbasic_regex<_CharT, _Traits>::__push_match_any()
47097a984708SDavid Chisnall{
47107a984708SDavid Chisnall    __end_->first() = new __match_any<_CharT>(__end_->first());
47117a984708SDavid Chisnall    __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
47127a984708SDavid Chisnall}
47137a984708SDavid Chisnall
47147a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
47157a984708SDavid Chisnallvoid
47167a984708SDavid Chisnallbasic_regex<_CharT, _Traits>::__push_match_any_but_newline()
47177a984708SDavid Chisnall{
47187a984708SDavid Chisnall    __end_->first() = new __match_any_but_newline<_CharT>(__end_->first());
47197a984708SDavid Chisnall    __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
47207a984708SDavid Chisnall}
47217a984708SDavid Chisnall
47227a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
47237a984708SDavid Chisnallvoid
47247a984708SDavid Chisnallbasic_regex<_CharT, _Traits>::__push_empty()
47257a984708SDavid Chisnall{
47267a984708SDavid Chisnall    __end_->first() = new __empty_state<_CharT>(__end_->first());
47277a984708SDavid Chisnall    __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
47287a984708SDavid Chisnall}
47297a984708SDavid Chisnall
47307a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
47317a984708SDavid Chisnallvoid
47327a984708SDavid Chisnallbasic_regex<_CharT, _Traits>::__push_word_boundary(bool __invert)
47337a984708SDavid Chisnall{
47347a984708SDavid Chisnall    __end_->first() = new __word_boundary<_CharT, _Traits>(__traits_, __invert,
47357a984708SDavid Chisnall                                                           __end_->first());
47367a984708SDavid Chisnall    __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
47377a984708SDavid Chisnall}
47387a984708SDavid Chisnall
47397a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
47407a984708SDavid Chisnallvoid
47417a984708SDavid Chisnallbasic_regex<_CharT, _Traits>::__push_back_ref(int __i)
47427a984708SDavid Chisnall{
47437a984708SDavid Chisnall    if (flags() & icase)
47447a984708SDavid Chisnall        __end_->first() = new __back_ref_icase<_CharT, _Traits>
47457a984708SDavid Chisnall                                              (__traits_, __i, __end_->first());
47467a984708SDavid Chisnall    else if (flags() & collate)
47477a984708SDavid Chisnall        __end_->first() = new __back_ref_collate<_CharT, _Traits>
47487a984708SDavid Chisnall                                              (__traits_, __i, __end_->first());
47497a984708SDavid Chisnall    else
47507a984708SDavid Chisnall        __end_->first() = new __back_ref<_CharT>(__i, __end_->first());
47517a984708SDavid Chisnall    __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
47527a984708SDavid Chisnall}
47537a984708SDavid Chisnall
47547a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
47557a984708SDavid Chisnallvoid
47567a984708SDavid Chisnallbasic_regex<_CharT, _Traits>::__push_alternation(__owns_one_state<_CharT>* __sa,
47577a984708SDavid Chisnall                                                 __owns_one_state<_CharT>* __ea)
47587a984708SDavid Chisnall{
47597a984708SDavid Chisnall    __sa->first() = new __alternate<_CharT>(
47607a984708SDavid Chisnall                         static_cast<__owns_one_state<_CharT>*>(__sa->first()),
47617a984708SDavid Chisnall                         static_cast<__owns_one_state<_CharT>*>(__ea->first()));
47627a984708SDavid Chisnall    __ea->first() = nullptr;
47637a984708SDavid Chisnall    __ea->first() = new __empty_state<_CharT>(__end_->first());
47647a984708SDavid Chisnall    __end_->first() = nullptr;
47657a984708SDavid Chisnall    __end_->first() = new __empty_non_own_state<_CharT>(__ea->first());
47667a984708SDavid Chisnall    __end_ = static_cast<__owns_one_state<_CharT>*>(__ea->first());
47677a984708SDavid Chisnall}
47687a984708SDavid Chisnall
47697a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
47707a984708SDavid Chisnall__bracket_expression<_CharT, _Traits>*
47717a984708SDavid Chisnallbasic_regex<_CharT, _Traits>::__start_matching_list(bool __negate)
47727a984708SDavid Chisnall{
47737a984708SDavid Chisnall    __bracket_expression<_CharT, _Traits>* __r =
47747a984708SDavid Chisnall        new __bracket_expression<_CharT, _Traits>(__traits_, __end_->first(),
47757a984708SDavid Chisnall                                                  __negate, __flags_ & icase,
47767a984708SDavid Chisnall                                                  __flags_ & collate);
47777a984708SDavid Chisnall    __end_->first() = __r;
47787a984708SDavid Chisnall    __end_ = __r;
47797a984708SDavid Chisnall    return __r;
47807a984708SDavid Chisnall}
47817a984708SDavid Chisnall
47827a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
47837a984708SDavid Chisnallvoid
47847a984708SDavid Chisnallbasic_regex<_CharT, _Traits>::__push_lookahead(const basic_regex& __exp,
47854f7ab58eSDimitry Andric                                               bool __invert,
47864f7ab58eSDimitry Andric                                               unsigned __mexp)
47877a984708SDavid Chisnall{
47887a984708SDavid Chisnall    __end_->first() = new __lookahead<_CharT, _Traits>(__exp, __invert,
47894f7ab58eSDimitry Andric                                                           __end_->first(), __mexp);
47907a984708SDavid Chisnall    __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
47917a984708SDavid Chisnall}
47927a984708SDavid Chisnall
47937a984708SDavid Chisnalltypedef basic_regex<char>    regex;
47947a984708SDavid Chisnalltypedef basic_regex<wchar_t> wregex;
47957a984708SDavid Chisnall
47967a984708SDavid Chisnall// sub_match
47977a984708SDavid Chisnall
47987a984708SDavid Chisnalltemplate <class _BidirectionalIterator>
4799aed8d94eSDimitry Andricclass _LIBCPP_TEMPLATE_VIS sub_match
48007a984708SDavid Chisnall    : public pair<_BidirectionalIterator, _BidirectionalIterator>
48017a984708SDavid Chisnall{
48027a984708SDavid Chisnallpublic:
48037a984708SDavid Chisnall    typedef _BidirectionalIterator                              iterator;
48047a984708SDavid Chisnall    typedef typename iterator_traits<iterator>::value_type      value_type;
48057a984708SDavid Chisnall    typedef typename iterator_traits<iterator>::difference_type difference_type;
48067a984708SDavid Chisnall    typedef basic_string<value_type>                            string_type;
48077a984708SDavid Chisnall
48087a984708SDavid Chisnall    bool matched;
48097a984708SDavid Chisnall
48107a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
4811936e9439SDimitry Andric    _LIBCPP_CONSTEXPR sub_match() : matched() {}
48127a984708SDavid Chisnall
48137a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
48147a984708SDavid Chisnall    difference_type length() const
48157a984708SDavid Chisnall        {return matched ? _VSTD::distance(this->first, this->second) : 0;}
48167a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
48177a984708SDavid Chisnall    string_type str() const
48187a984708SDavid Chisnall        {return matched ? string_type(this->first, this->second) : string_type();}
48197a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
48207a984708SDavid Chisnall    operator string_type() const
48217a984708SDavid Chisnall        {return str();}
48227a984708SDavid Chisnall
48237a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
48247a984708SDavid Chisnall    int compare(const sub_match& __s) const
48257a984708SDavid Chisnall        {return str().compare(__s.str());}
48267a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
48277a984708SDavid Chisnall    int compare(const string_type& __s) const
48287a984708SDavid Chisnall        {return str().compare(__s);}
48297a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
48307a984708SDavid Chisnall    int compare(const value_type* __s) const
48317a984708SDavid Chisnall        {return str().compare(__s);}
48327a984708SDavid Chisnall};
48337a984708SDavid Chisnall
48347a984708SDavid Chisnalltypedef sub_match<const char*>             csub_match;
48357a984708SDavid Chisnalltypedef sub_match<const wchar_t*>          wcsub_match;
48367a984708SDavid Chisnalltypedef sub_match<string::const_iterator>  ssub_match;
48377a984708SDavid Chisnalltypedef sub_match<wstring::const_iterator> wssub_match;
48387a984708SDavid Chisnall
48397a984708SDavid Chisnalltemplate <class _BiIter>
48407a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
48417a984708SDavid Chisnallbool
48427a984708SDavid Chisnalloperator==(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
48437a984708SDavid Chisnall{
48447a984708SDavid Chisnall    return __x.compare(__y) == 0;
48457a984708SDavid Chisnall}
48467a984708SDavid Chisnall
48477a984708SDavid Chisnalltemplate <class _BiIter>
48487a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
48497a984708SDavid Chisnallbool
48507a984708SDavid Chisnalloperator!=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
48517a984708SDavid Chisnall{
48527a984708SDavid Chisnall    return !(__x == __y);
48537a984708SDavid Chisnall}
48547a984708SDavid Chisnall
48557a984708SDavid Chisnalltemplate <class _BiIter>
48567a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
48577a984708SDavid Chisnallbool
48587a984708SDavid Chisnalloperator<(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
48597a984708SDavid Chisnall{
48607a984708SDavid Chisnall    return __x.compare(__y) < 0;
48617a984708SDavid Chisnall}
48627a984708SDavid Chisnall
48637a984708SDavid Chisnalltemplate <class _BiIter>
48647a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
48657a984708SDavid Chisnallbool
48667a984708SDavid Chisnalloperator<=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
48677a984708SDavid Chisnall{
48687a984708SDavid Chisnall    return !(__y < __x);
48697a984708SDavid Chisnall}
48707a984708SDavid Chisnall
48717a984708SDavid Chisnalltemplate <class _BiIter>
48727a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
48737a984708SDavid Chisnallbool
48747a984708SDavid Chisnalloperator>=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
48757a984708SDavid Chisnall{
48767a984708SDavid Chisnall    return !(__x < __y);
48777a984708SDavid Chisnall}
48787a984708SDavid Chisnall
48797a984708SDavid Chisnalltemplate <class _BiIter>
48807a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
48817a984708SDavid Chisnallbool
48827a984708SDavid Chisnalloperator>(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
48837a984708SDavid Chisnall{
48847a984708SDavid Chisnall    return __y < __x;
48857a984708SDavid Chisnall}
48867a984708SDavid Chisnall
48877a984708SDavid Chisnalltemplate <class _BiIter, class _ST, class _SA>
48887a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
48897a984708SDavid Chisnallbool
48907a984708SDavid Chisnalloperator==(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
48917a984708SDavid Chisnall           const sub_match<_BiIter>& __y)
48927a984708SDavid Chisnall{
4893d72607e9SDimitry Andric    return __y.compare(typename sub_match<_BiIter>::string_type(__x.data(), __x.size())) == 0;
48947a984708SDavid Chisnall}
48957a984708SDavid Chisnall
48967a984708SDavid Chisnalltemplate <class _BiIter, class _ST, class _SA>
48977a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
48987a984708SDavid Chisnallbool
48997a984708SDavid Chisnalloperator!=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
49007a984708SDavid Chisnall           const sub_match<_BiIter>& __y)
49017a984708SDavid Chisnall{
49027a984708SDavid Chisnall    return !(__x == __y);
49037a984708SDavid Chisnall}
49047a984708SDavid Chisnall
49057a984708SDavid Chisnalltemplate <class _BiIter, class _ST, class _SA>
49067a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
49077a984708SDavid Chisnallbool
49087a984708SDavid Chisnalloperator<(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
49097a984708SDavid Chisnall          const sub_match<_BiIter>& __y)
49107a984708SDavid Chisnall{
4911d72607e9SDimitry Andric    return __y.compare(typename sub_match<_BiIter>::string_type(__x.data(), __x.size())) > 0;
49127a984708SDavid Chisnall}
49137a984708SDavid Chisnall
49147a984708SDavid Chisnalltemplate <class _BiIter, class _ST, class _SA>
49157a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
49167a984708SDavid Chisnallbool
49177a984708SDavid Chisnalloperator>(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
49187a984708SDavid Chisnall          const sub_match<_BiIter>& __y)
49197a984708SDavid Chisnall{
49207a984708SDavid Chisnall    return __y < __x;
49217a984708SDavid Chisnall}
49227a984708SDavid Chisnall
49237a984708SDavid Chisnalltemplate <class _BiIter, class _ST, class _SA>
49247a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
49257a984708SDavid Chisnallbool operator>=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
49267a984708SDavid Chisnall                const sub_match<_BiIter>& __y)
49277a984708SDavid Chisnall{
49287a984708SDavid Chisnall    return !(__x < __y);
49297a984708SDavid Chisnall}
49307a984708SDavid Chisnall
49317a984708SDavid Chisnalltemplate <class _BiIter, class _ST, class _SA>
49327a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
49337a984708SDavid Chisnallbool
49347a984708SDavid Chisnalloperator<=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
49357a984708SDavid Chisnall           const sub_match<_BiIter>& __y)
49367a984708SDavid Chisnall{
49377a984708SDavid Chisnall    return !(__y < __x);
49387a984708SDavid Chisnall}
49397a984708SDavid Chisnall
49407a984708SDavid Chisnalltemplate <class _BiIter, class _ST, class _SA>
49417a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
49427a984708SDavid Chisnallbool
49437a984708SDavid Chisnalloperator==(const sub_match<_BiIter>& __x,
49447a984708SDavid Chisnall           const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
49457a984708SDavid Chisnall{
4946d72607e9SDimitry Andric    return __x.compare(typename sub_match<_BiIter>::string_type(__y.data(), __y.size())) == 0;
49477a984708SDavid Chisnall}
49487a984708SDavid Chisnall
49497a984708SDavid Chisnalltemplate <class _BiIter, class _ST, class _SA>
49507a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
49517a984708SDavid Chisnallbool
49527a984708SDavid Chisnalloperator!=(const sub_match<_BiIter>& __x,
49537a984708SDavid Chisnall           const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
49547a984708SDavid Chisnall{
49557a984708SDavid Chisnall    return !(__x == __y);
49567a984708SDavid Chisnall}
49577a984708SDavid Chisnall
49587a984708SDavid Chisnalltemplate <class _BiIter, class _ST, class _SA>
49597a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
49607a984708SDavid Chisnallbool
49617a984708SDavid Chisnalloperator<(const sub_match<_BiIter>& __x,
49627a984708SDavid Chisnall          const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
49637a984708SDavid Chisnall{
4964d72607e9SDimitry Andric    return __x.compare(typename sub_match<_BiIter>::string_type(__y.data(), __y.size())) < 0;
49657a984708SDavid Chisnall}
49667a984708SDavid Chisnall
49677a984708SDavid Chisnalltemplate <class _BiIter, class _ST, class _SA>
49687a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
49697a984708SDavid Chisnallbool operator>(const sub_match<_BiIter>& __x,
49707a984708SDavid Chisnall               const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
49717a984708SDavid Chisnall{
49727a984708SDavid Chisnall    return __y < __x;
49737a984708SDavid Chisnall}
49747a984708SDavid Chisnall
49757a984708SDavid Chisnalltemplate <class _BiIter, class _ST, class _SA>
49767a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
49777a984708SDavid Chisnallbool
49787a984708SDavid Chisnalloperator>=(const sub_match<_BiIter>& __x,
49797a984708SDavid Chisnall           const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
49807a984708SDavid Chisnall{
49817a984708SDavid Chisnall    return !(__x < __y);
49827a984708SDavid Chisnall}
49837a984708SDavid Chisnall
49847a984708SDavid Chisnalltemplate <class _BiIter, class _ST, class _SA>
49857a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
49867a984708SDavid Chisnallbool
49877a984708SDavid Chisnalloperator<=(const sub_match<_BiIter>& __x,
49887a984708SDavid Chisnall           const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
49897a984708SDavid Chisnall{
49907a984708SDavid Chisnall    return !(__y < __x);
49917a984708SDavid Chisnall}
49927a984708SDavid Chisnall
49937a984708SDavid Chisnalltemplate <class _BiIter>
49947a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
49957a984708SDavid Chisnallbool
49967a984708SDavid Chisnalloperator==(typename iterator_traits<_BiIter>::value_type const* __x,
49977a984708SDavid Chisnall           const sub_match<_BiIter>& __y)
49987a984708SDavid Chisnall{
49997a984708SDavid Chisnall    return __y.compare(__x) == 0;
50007a984708SDavid Chisnall}
50017a984708SDavid Chisnall
50027a984708SDavid Chisnalltemplate <class _BiIter>
50037a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
50047a984708SDavid Chisnallbool
50057a984708SDavid Chisnalloperator!=(typename iterator_traits<_BiIter>::value_type const* __x,
50067a984708SDavid Chisnall           const sub_match<_BiIter>& __y)
50077a984708SDavid Chisnall{
50087a984708SDavid Chisnall    return !(__x == __y);
50097a984708SDavid Chisnall}
50107a984708SDavid Chisnall
50117a984708SDavid Chisnalltemplate <class _BiIter>
50127a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
50137a984708SDavid Chisnallbool
50147a984708SDavid Chisnalloperator<(typename iterator_traits<_BiIter>::value_type const* __x,
50157a984708SDavid Chisnall          const sub_match<_BiIter>& __y)
50167a984708SDavid Chisnall{
50177a984708SDavid Chisnall    return __y.compare(__x) > 0;
50187a984708SDavid Chisnall}
50197a984708SDavid Chisnall
50207a984708SDavid Chisnalltemplate <class _BiIter>
50217a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
50227a984708SDavid Chisnallbool
50237a984708SDavid Chisnalloperator>(typename iterator_traits<_BiIter>::value_type const* __x,
50247a984708SDavid Chisnall          const sub_match<_BiIter>& __y)
50257a984708SDavid Chisnall{
50267a984708SDavid Chisnall    return __y < __x;
50277a984708SDavid Chisnall}
50287a984708SDavid Chisnall
50297a984708SDavid Chisnalltemplate <class _BiIter>
50307a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
50317a984708SDavid Chisnallbool
50327a984708SDavid Chisnalloperator>=(typename iterator_traits<_BiIter>::value_type const* __x,
50337a984708SDavid Chisnall           const sub_match<_BiIter>& __y)
50347a984708SDavid Chisnall{
50357a984708SDavid Chisnall    return !(__x < __y);
50367a984708SDavid Chisnall}
50377a984708SDavid Chisnall
50387a984708SDavid Chisnalltemplate <class _BiIter>
50397a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
50407a984708SDavid Chisnallbool
50417a984708SDavid Chisnalloperator<=(typename iterator_traits<_BiIter>::value_type const* __x,
50427a984708SDavid Chisnall           const sub_match<_BiIter>& __y)
50437a984708SDavid Chisnall{
50447a984708SDavid Chisnall    return !(__y < __x);
50457a984708SDavid Chisnall}
50467a984708SDavid Chisnall
50477a984708SDavid Chisnalltemplate <class _BiIter>
50487a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
50497a984708SDavid Chisnallbool
50507a984708SDavid Chisnalloperator==(const sub_match<_BiIter>& __x,
50517a984708SDavid Chisnall           typename iterator_traits<_BiIter>::value_type const* __y)
50527a984708SDavid Chisnall{
50537a984708SDavid Chisnall    return __x.compare(__y) == 0;
50547a984708SDavid Chisnall}
50557a984708SDavid Chisnall
50567a984708SDavid Chisnalltemplate <class _BiIter>
50577a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
50587a984708SDavid Chisnallbool
50597a984708SDavid Chisnalloperator!=(const sub_match<_BiIter>& __x,
50607a984708SDavid Chisnall           typename iterator_traits<_BiIter>::value_type const* __y)
50617a984708SDavid Chisnall{
50627a984708SDavid Chisnall    return !(__x == __y);
50637a984708SDavid Chisnall}
50647a984708SDavid Chisnall
50657a984708SDavid Chisnalltemplate <class _BiIter>
50667a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
50677a984708SDavid Chisnallbool
50687a984708SDavid Chisnalloperator<(const sub_match<_BiIter>& __x,
50697a984708SDavid Chisnall          typename iterator_traits<_BiIter>::value_type const* __y)
50707a984708SDavid Chisnall{
50717a984708SDavid Chisnall    return __x.compare(__y) < 0;
50727a984708SDavid Chisnall}
50737a984708SDavid Chisnall
50747a984708SDavid Chisnalltemplate <class _BiIter>
50757a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
50767a984708SDavid Chisnallbool
50777a984708SDavid Chisnalloperator>(const sub_match<_BiIter>& __x,
50787a984708SDavid Chisnall          typename iterator_traits<_BiIter>::value_type const* __y)
50797a984708SDavid Chisnall{
50807a984708SDavid Chisnall    return __y < __x;
50817a984708SDavid Chisnall}
50827a984708SDavid Chisnall
50837a984708SDavid Chisnalltemplate <class _BiIter>
50847a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
50857a984708SDavid Chisnallbool
50867a984708SDavid Chisnalloperator>=(const sub_match<_BiIter>& __x,
50877a984708SDavid Chisnall           typename iterator_traits<_BiIter>::value_type const* __y)
50887a984708SDavid Chisnall{
50897a984708SDavid Chisnall    return !(__x < __y);
50907a984708SDavid Chisnall}
50917a984708SDavid Chisnall
50927a984708SDavid Chisnalltemplate <class _BiIter>
50937a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
50947a984708SDavid Chisnallbool
50957a984708SDavid Chisnalloperator<=(const sub_match<_BiIter>& __x,
50967a984708SDavid Chisnall           typename iterator_traits<_BiIter>::value_type const* __y)
50977a984708SDavid Chisnall{
50987a984708SDavid Chisnall    return !(__y < __x);
50997a984708SDavid Chisnall}
51007a984708SDavid Chisnall
51017a984708SDavid Chisnalltemplate <class _BiIter>
51027a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
51037a984708SDavid Chisnallbool
51047a984708SDavid Chisnalloperator==(typename iterator_traits<_BiIter>::value_type const& __x,
51057a984708SDavid Chisnall           const sub_match<_BiIter>& __y)
51067a984708SDavid Chisnall{
51077a984708SDavid Chisnall    typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
51087a984708SDavid Chisnall    return __y.compare(string_type(1, __x)) == 0;
51097a984708SDavid Chisnall}
51107a984708SDavid Chisnall
51117a984708SDavid Chisnalltemplate <class _BiIter>
51127a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
51137a984708SDavid Chisnallbool
51147a984708SDavid Chisnalloperator!=(typename iterator_traits<_BiIter>::value_type const& __x,
51157a984708SDavid Chisnall           const sub_match<_BiIter>& __y)
51167a984708SDavid Chisnall{
51177a984708SDavid Chisnall    return !(__x == __y);
51187a984708SDavid Chisnall}
51197a984708SDavid Chisnall
51207a984708SDavid Chisnalltemplate <class _BiIter>
51217a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
51227a984708SDavid Chisnallbool
51237a984708SDavid Chisnalloperator<(typename iterator_traits<_BiIter>::value_type const& __x,
51247a984708SDavid Chisnall          const sub_match<_BiIter>& __y)
51257a984708SDavid Chisnall{
51267a984708SDavid Chisnall    typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
51277a984708SDavid Chisnall    return __y.compare(string_type(1, __x)) > 0;
51287a984708SDavid Chisnall}
51297a984708SDavid Chisnall
51307a984708SDavid Chisnalltemplate <class _BiIter>
51317a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
51327a984708SDavid Chisnallbool
51337a984708SDavid Chisnalloperator>(typename iterator_traits<_BiIter>::value_type const& __x,
51347a984708SDavid Chisnall          const sub_match<_BiIter>& __y)
51357a984708SDavid Chisnall{
51367a984708SDavid Chisnall    return __y < __x;
51377a984708SDavid Chisnall}
51387a984708SDavid Chisnall
51397a984708SDavid Chisnalltemplate <class _BiIter>
51407a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
51417a984708SDavid Chisnallbool
51427a984708SDavid Chisnalloperator>=(typename iterator_traits<_BiIter>::value_type const& __x,
51437a984708SDavid Chisnall           const sub_match<_BiIter>& __y)
51447a984708SDavid Chisnall{
51457a984708SDavid Chisnall    return !(__x < __y);
51467a984708SDavid Chisnall}
51477a984708SDavid Chisnall
51487a984708SDavid Chisnalltemplate <class _BiIter>
51497a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
51507a984708SDavid Chisnallbool
51517a984708SDavid Chisnalloperator<=(typename iterator_traits<_BiIter>::value_type const& __x,
51527a984708SDavid Chisnall           const sub_match<_BiIter>& __y)
51537a984708SDavid Chisnall{
51547a984708SDavid Chisnall    return !(__y < __x);
51557a984708SDavid Chisnall}
51567a984708SDavid Chisnall
51577a984708SDavid Chisnalltemplate <class _BiIter>
51587a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
51597a984708SDavid Chisnallbool
51607a984708SDavid Chisnalloperator==(const sub_match<_BiIter>& __x,
51617a984708SDavid Chisnall           typename iterator_traits<_BiIter>::value_type const& __y)
51627a984708SDavid Chisnall{
51637a984708SDavid Chisnall    typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
51647a984708SDavid Chisnall    return __x.compare(string_type(1, __y)) == 0;
51657a984708SDavid Chisnall}
51667a984708SDavid Chisnall
51677a984708SDavid Chisnalltemplate <class _BiIter>
51687a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
51697a984708SDavid Chisnallbool
51707a984708SDavid Chisnalloperator!=(const sub_match<_BiIter>& __x,
51717a984708SDavid Chisnall           typename iterator_traits<_BiIter>::value_type const& __y)
51727a984708SDavid Chisnall{
51737a984708SDavid Chisnall    return !(__x == __y);
51747a984708SDavid Chisnall}
51757a984708SDavid Chisnall
51767a984708SDavid Chisnalltemplate <class _BiIter>
51777a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
51787a984708SDavid Chisnallbool
51797a984708SDavid Chisnalloperator<(const sub_match<_BiIter>& __x,
51807a984708SDavid Chisnall          typename iterator_traits<_BiIter>::value_type const& __y)
51817a984708SDavid Chisnall{
51827a984708SDavid Chisnall    typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
51837a984708SDavid Chisnall    return __x.compare(string_type(1, __y)) < 0;
51847a984708SDavid Chisnall}
51857a984708SDavid Chisnall
51867a984708SDavid Chisnalltemplate <class _BiIter>
51877a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
51887a984708SDavid Chisnallbool
51897a984708SDavid Chisnalloperator>(const sub_match<_BiIter>& __x,
51907a984708SDavid Chisnall          typename iterator_traits<_BiIter>::value_type const& __y)
51917a984708SDavid Chisnall{
51927a984708SDavid Chisnall    return __y < __x;
51937a984708SDavid Chisnall}
51947a984708SDavid Chisnall
51957a984708SDavid Chisnalltemplate <class _BiIter>
51967a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
51977a984708SDavid Chisnallbool
51987a984708SDavid Chisnalloperator>=(const sub_match<_BiIter>& __x,
51997a984708SDavid Chisnall           typename iterator_traits<_BiIter>::value_type const& __y)
52007a984708SDavid Chisnall{
52017a984708SDavid Chisnall    return !(__x < __y);
52027a984708SDavid Chisnall}
52037a984708SDavid Chisnall
52047a984708SDavid Chisnalltemplate <class _BiIter>
52057a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
52067a984708SDavid Chisnallbool
52077a984708SDavid Chisnalloperator<=(const sub_match<_BiIter>& __x,
52087a984708SDavid Chisnall           typename iterator_traits<_BiIter>::value_type const& __y)
52097a984708SDavid Chisnall{
52107a984708SDavid Chisnall    return !(__y < __x);
52117a984708SDavid Chisnall}
52127a984708SDavid Chisnall
52137a984708SDavid Chisnalltemplate <class _CharT, class _ST, class _BiIter>
52147a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
52157a984708SDavid Chisnallbasic_ostream<_CharT, _ST>&
52167a984708SDavid Chisnalloperator<<(basic_ostream<_CharT, _ST>& __os, const sub_match<_BiIter>& __m)
52177a984708SDavid Chisnall{
52187a984708SDavid Chisnall    return __os << __m.str();
52197a984708SDavid Chisnall}
52207a984708SDavid Chisnall
52217a984708SDavid Chisnalltemplate <class _BidirectionalIterator, class _Allocator>
5222aed8d94eSDimitry Andricclass _LIBCPP_TEMPLATE_VIS match_results
52237a984708SDavid Chisnall{
52247a984708SDavid Chisnallpublic:
52257a984708SDavid Chisnall    typedef _Allocator                                        allocator_type;
52267a984708SDavid Chisnall    typedef sub_match<_BidirectionalIterator>                 value_type;
52277a984708SDavid Chisnallprivate:
52287a984708SDavid Chisnall    typedef vector<value_type, allocator_type>                __container_type;
52297a984708SDavid Chisnall
52307a984708SDavid Chisnall    __container_type  __matches_;
52317a984708SDavid Chisnall    value_type __unmatched_;
52327a984708SDavid Chisnall    value_type __prefix_;
52337a984708SDavid Chisnall    value_type __suffix_;
52347a984708SDavid Chisnall    bool       __ready_;
52357a984708SDavid Chisnallpublic:
52367a984708SDavid Chisnall    _BidirectionalIterator __position_start_;
52377a984708SDavid Chisnall    typedef const value_type&                                 const_reference;
5238d72607e9SDimitry Andric    typedef value_type&                                       reference;
52397a984708SDavid Chisnall    typedef typename __container_type::const_iterator         const_iterator;
52407a984708SDavid Chisnall    typedef const_iterator                                    iterator;
52417a984708SDavid Chisnall    typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type;
52427a984708SDavid Chisnall    typedef typename allocator_traits<allocator_type>::size_type size_type;
52437a984708SDavid Chisnall    typedef typename iterator_traits<_BidirectionalIterator>::value_type char_type;
52447a984708SDavid Chisnall    typedef basic_string<char_type>                           string_type;
52457a984708SDavid Chisnall
52467a984708SDavid Chisnall    // construct/copy/destroy:
52477a984708SDavid Chisnall    explicit match_results(const allocator_type& __a = allocator_type());
52487a984708SDavid Chisnall//    match_results(const match_results&) = default;
52497a984708SDavid Chisnall//    match_results& operator=(const match_results&) = default;
52507a984708SDavid Chisnall//    match_results(match_results&& __m) = default;
52517a984708SDavid Chisnall//    match_results& operator=(match_results&& __m) = default;
52527a984708SDavid Chisnall//    ~match_results() = default;
52537a984708SDavid Chisnall
52547a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
52557a984708SDavid Chisnall    bool ready() const {return __ready_;}
52567a984708SDavid Chisnall
52577a984708SDavid Chisnall    // size:
52587a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
5259b2c7081bSDimitry Andric    size_type size() const _NOEXCEPT {return __matches_.size();}
52607a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
5261b2c7081bSDimitry Andric    size_type max_size() const _NOEXCEPT {return __matches_.max_size();}
5262b2c7081bSDimitry Andric    _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
5263b2c7081bSDimitry Andric    bool empty() const _NOEXCEPT {return size() == 0;}
52647a984708SDavid Chisnall
52657a984708SDavid Chisnall    // element access:
52667a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
52677a984708SDavid Chisnall    difference_type length(size_type __sub = 0) const
52687a984708SDavid Chisnall        {return (*this)[__sub].length();}
52697a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
52707a984708SDavid Chisnall    difference_type position(size_type __sub = 0) const
52717a984708SDavid Chisnall        {return _VSTD::distance(__position_start_, (*this)[__sub].first);}
52727a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
52737a984708SDavid Chisnall    string_type str(size_type __sub = 0) const
52747a984708SDavid Chisnall        {return (*this)[__sub].str();}
52757a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
52767a984708SDavid Chisnall    const_reference operator[](size_type __n) const
52777a984708SDavid Chisnall        {return __n < __matches_.size() ? __matches_[__n] : __unmatched_;}
52787a984708SDavid Chisnall
52797a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
52807a984708SDavid Chisnall    const_reference prefix() const {return __prefix_;}
52817a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
52827a984708SDavid Chisnall    const_reference suffix() const {return __suffix_;}
52837a984708SDavid Chisnall
52847a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
52857a984708SDavid Chisnall    const_iterator begin() const {return empty() ? __matches_.end() : __matches_.begin();}
52867a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
52877a984708SDavid Chisnall    const_iterator end() const {return __matches_.end();}
52887a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
52897a984708SDavid Chisnall    const_iterator cbegin() const {return empty() ? __matches_.end() : __matches_.begin();}
52907a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
52917a984708SDavid Chisnall    const_iterator cend() const {return __matches_.end();}
52927a984708SDavid Chisnall
52937a984708SDavid Chisnall    // format:
52947a984708SDavid Chisnall    template <class _OutputIter>
52957a984708SDavid Chisnall        _OutputIter
5296b2c7081bSDimitry Andric        format(_OutputIter __output_iter, const char_type* __fmt_first,
52977a984708SDavid Chisnall               const char_type* __fmt_last,
52987a984708SDavid Chisnall               regex_constants::match_flag_type __flags = regex_constants::format_default) const;
52997a984708SDavid Chisnall    template <class _OutputIter, class _ST, class _SA>
53007a984708SDavid Chisnall        _LIBCPP_INLINE_VISIBILITY
53017a984708SDavid Chisnall        _OutputIter
5302b2c7081bSDimitry Andric        format(_OutputIter __output_iter, const basic_string<char_type, _ST, _SA>& __fmt,
53037a984708SDavid Chisnall               regex_constants::match_flag_type __flags = regex_constants::format_default) const
5304b2c7081bSDimitry Andric            {return format(__output_iter, __fmt.data(), __fmt.data() + __fmt.size(), __flags);}
53057a984708SDavid Chisnall    template <class _ST, class _SA>
53067a984708SDavid Chisnall        _LIBCPP_INLINE_VISIBILITY
53077a984708SDavid Chisnall        basic_string<char_type, _ST, _SA>
53087a984708SDavid Chisnall        format(const basic_string<char_type, _ST, _SA>& __fmt,
53097a984708SDavid Chisnall               regex_constants::match_flag_type __flags = regex_constants::format_default) const
53107a984708SDavid Chisnall        {
53117a984708SDavid Chisnall            basic_string<char_type, _ST, _SA> __r;
53127a984708SDavid Chisnall            format(back_inserter(__r), __fmt.data(), __fmt.data() + __fmt.size(),
53137a984708SDavid Chisnall                   __flags);
53147a984708SDavid Chisnall            return __r;
53157a984708SDavid Chisnall        }
53167a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
53177a984708SDavid Chisnall    string_type
53187a984708SDavid Chisnall        format(const char_type* __fmt,
53197a984708SDavid Chisnall               regex_constants::match_flag_type __flags = regex_constants::format_default) const
53207a984708SDavid Chisnall        {
53217a984708SDavid Chisnall            string_type __r;
53227a984708SDavid Chisnall            format(back_inserter(__r), __fmt,
53237a984708SDavid Chisnall                   __fmt + char_traits<char_type>::length(__fmt), __flags);
53247a984708SDavid Chisnall            return __r;
53257a984708SDavid Chisnall        }
53267a984708SDavid Chisnall
53277a984708SDavid Chisnall    // allocator:
53287a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
53297a984708SDavid Chisnall    allocator_type get_allocator() const {return __matches_.get_allocator();}
53307a984708SDavid Chisnall
53317a984708SDavid Chisnall    // swap:
53327a984708SDavid Chisnall    void swap(match_results& __m);
53337a984708SDavid Chisnall
533494e3ee44SDavid Chisnall    template <class _Bp, class _Ap>
53357a984708SDavid Chisnall        _LIBCPP_INLINE_VISIBILITY
53367a984708SDavid Chisnall        void __assign(_BidirectionalIterator __f, _BidirectionalIterator __l,
533794e3ee44SDavid Chisnall                      const match_results<_Bp, _Ap>& __m, bool __no_update_pos)
53387a984708SDavid Chisnall    {
533994e3ee44SDavid Chisnall        _Bp __mf = __m.prefix().first;
53407a984708SDavid Chisnall        __matches_.resize(__m.size());
53417a984708SDavid Chisnall        for (size_type __i = 0; __i < __matches_.size(); ++__i)
53427a984708SDavid Chisnall        {
53437a984708SDavid Chisnall            __matches_[__i].first = _VSTD::next(__f, _VSTD::distance(__mf, __m[__i].first));
53447a984708SDavid Chisnall            __matches_[__i].second = _VSTD::next(__f, _VSTD::distance(__mf, __m[__i].second));
53457a984708SDavid Chisnall            __matches_[__i].matched = __m[__i].matched;
53467a984708SDavid Chisnall        }
53477a984708SDavid Chisnall        __unmatched_.first   = __l;
53487a984708SDavid Chisnall        __unmatched_.second  = __l;
53497a984708SDavid Chisnall        __unmatched_.matched = false;
53507a984708SDavid Chisnall        __prefix_.first = _VSTD::next(__f, _VSTD::distance(__mf, __m.prefix().first));
53517a984708SDavid Chisnall        __prefix_.second = _VSTD::next(__f, _VSTD::distance(__mf, __m.prefix().second));
53527a984708SDavid Chisnall        __prefix_.matched = __m.prefix().matched;
53537a984708SDavid Chisnall        __suffix_.first = _VSTD::next(__f, _VSTD::distance(__mf, __m.suffix().first));
53547a984708SDavid Chisnall        __suffix_.second = _VSTD::next(__f, _VSTD::distance(__mf, __m.suffix().second));
53557a984708SDavid Chisnall        __suffix_.matched = __m.suffix().matched;
53567a984708SDavid Chisnall        if (!__no_update_pos)
53577a984708SDavid Chisnall            __position_start_ = __prefix_.first;
53587a984708SDavid Chisnall        __ready_ = __m.ready();
53597a984708SDavid Chisnall    }
53607a984708SDavid Chisnall
53617a984708SDavid Chisnallprivate:
53627a984708SDavid Chisnall    void __init(unsigned __s,
53637a984708SDavid Chisnall                _BidirectionalIterator __f, _BidirectionalIterator __l,
53647a984708SDavid Chisnall                bool __no_update_pos = false);
53657a984708SDavid Chisnall
53667a984708SDavid Chisnall    template <class, class> friend class basic_regex;
53677a984708SDavid Chisnall
536894e3ee44SDavid Chisnall    template <class _Bp, class _Ap, class _Cp, class _Tp>
53697a984708SDavid Chisnall    friend
53707a984708SDavid Chisnall    bool
537194e3ee44SDavid Chisnall    regex_match(_Bp, _Bp, match_results<_Bp, _Ap>&, const basic_regex<_Cp, _Tp>&,
53727a984708SDavid Chisnall                regex_constants::match_flag_type);
53737a984708SDavid Chisnall
537494e3ee44SDavid Chisnall    template <class _Bp, class _Ap>
53757a984708SDavid Chisnall    friend
53767a984708SDavid Chisnall    bool
537794e3ee44SDavid Chisnall    operator==(const match_results<_Bp, _Ap>&, const match_results<_Bp, _Ap>&);
53787a984708SDavid Chisnall
53797a984708SDavid Chisnall    template <class, class> friend class __lookahead;
53807a984708SDavid Chisnall};
53817a984708SDavid Chisnall
53827a984708SDavid Chisnalltemplate <class _BidirectionalIterator, class _Allocator>
53837a984708SDavid Chisnallmatch_results<_BidirectionalIterator, _Allocator>::match_results(
53847a984708SDavid Chisnall        const allocator_type& __a)
53857a984708SDavid Chisnall    : __matches_(__a),
53867a984708SDavid Chisnall      __unmatched_(),
53877a984708SDavid Chisnall      __prefix_(),
53887a984708SDavid Chisnall      __suffix_(),
53899729cf09SDimitry Andric      __ready_(false),
53909729cf09SDimitry Andric      __position_start_()
53917a984708SDavid Chisnall{
53927a984708SDavid Chisnall}
53937a984708SDavid Chisnall
53947a984708SDavid Chisnalltemplate <class _BidirectionalIterator, class _Allocator>
53957a984708SDavid Chisnallvoid
53967a984708SDavid Chisnallmatch_results<_BidirectionalIterator, _Allocator>::__init(unsigned __s,
53977a984708SDavid Chisnall                         _BidirectionalIterator __f, _BidirectionalIterator __l,
53987a984708SDavid Chisnall                         bool __no_update_pos)
53997a984708SDavid Chisnall{
54007a984708SDavid Chisnall    __unmatched_.first   = __l;
54017a984708SDavid Chisnall    __unmatched_.second  = __l;
54027a984708SDavid Chisnall    __unmatched_.matched = false;
54037a984708SDavid Chisnall    __matches_.assign(__s, __unmatched_);
54047a984708SDavid Chisnall    __prefix_.first      = __f;
54057a984708SDavid Chisnall    __prefix_.second     = __f;
54067a984708SDavid Chisnall    __prefix_.matched    = false;
54077a984708SDavid Chisnall    __suffix_ = __unmatched_;
54087a984708SDavid Chisnall    if (!__no_update_pos)
54097a984708SDavid Chisnall        __position_start_ = __prefix_.first;
54107a984708SDavid Chisnall    __ready_ = true;
54117a984708SDavid Chisnall}
54127a984708SDavid Chisnall
54137a984708SDavid Chisnalltemplate <class _BidirectionalIterator, class _Allocator>
54147a984708SDavid Chisnalltemplate <class _OutputIter>
54157a984708SDavid Chisnall_OutputIter
5416b2c7081bSDimitry Andricmatch_results<_BidirectionalIterator, _Allocator>::format(_OutputIter __output_iter,
54177a984708SDavid Chisnall        const char_type* __fmt_first, const char_type* __fmt_last,
54187a984708SDavid Chisnall        regex_constants::match_flag_type __flags) const
54197a984708SDavid Chisnall{
54207a984708SDavid Chisnall    if (__flags & regex_constants::format_sed)
54217a984708SDavid Chisnall    {
54227a984708SDavid Chisnall        for (; __fmt_first != __fmt_last; ++__fmt_first)
54237a984708SDavid Chisnall        {
54247a984708SDavid Chisnall            if (*__fmt_first == '&')
5425b2c7081bSDimitry Andric                __output_iter = _VSTD::copy(__matches_[0].first, __matches_[0].second,
5426b2c7081bSDimitry Andric                                   __output_iter);
54277a984708SDavid Chisnall            else if (*__fmt_first == '\\' && __fmt_first + 1 != __fmt_last)
54287a984708SDavid Chisnall            {
54297a984708SDavid Chisnall                ++__fmt_first;
54307a984708SDavid Chisnall                if ('0' <= *__fmt_first && *__fmt_first <= '9')
54317a984708SDavid Chisnall                {
54327a984708SDavid Chisnall                    size_t __i = *__fmt_first - '0';
5433b2c7081bSDimitry Andric                    __output_iter = _VSTD::copy((*this)[__i].first,
5434b2c7081bSDimitry Andric                                        (*this)[__i].second, __output_iter);
54357a984708SDavid Chisnall                }
54367a984708SDavid Chisnall                else
54377a984708SDavid Chisnall                {
5438b2c7081bSDimitry Andric                    *__output_iter = *__fmt_first;
5439b2c7081bSDimitry Andric                    ++__output_iter;
54407a984708SDavid Chisnall                }
54417a984708SDavid Chisnall            }
54427a984708SDavid Chisnall            else
54437a984708SDavid Chisnall            {
5444b2c7081bSDimitry Andric                *__output_iter = *__fmt_first;
5445b2c7081bSDimitry Andric                ++__output_iter;
54467a984708SDavid Chisnall            }
54477a984708SDavid Chisnall        }
54487a984708SDavid Chisnall    }
54497a984708SDavid Chisnall    else
54507a984708SDavid Chisnall    {
54517a984708SDavid Chisnall        for (; __fmt_first != __fmt_last; ++__fmt_first)
54527a984708SDavid Chisnall        {
54537a984708SDavid Chisnall            if (*__fmt_first == '$' && __fmt_first + 1 != __fmt_last)
54547a984708SDavid Chisnall            {
54557a984708SDavid Chisnall                switch (__fmt_first[1])
54567a984708SDavid Chisnall                {
54577a984708SDavid Chisnall                case '$':
5458b2c7081bSDimitry Andric                    *__output_iter = *++__fmt_first;
5459b2c7081bSDimitry Andric                    ++__output_iter;
54607a984708SDavid Chisnall                    break;
54617a984708SDavid Chisnall                case '&':
54627a984708SDavid Chisnall                    ++__fmt_first;
5463b2c7081bSDimitry Andric                    __output_iter = _VSTD::copy(__matches_[0].first, __matches_[0].second,
5464b2c7081bSDimitry Andric                                       __output_iter);
54657a984708SDavid Chisnall                    break;
54667a984708SDavid Chisnall                case '`':
54677a984708SDavid Chisnall                    ++__fmt_first;
5468b2c7081bSDimitry Andric                    __output_iter = _VSTD::copy(__prefix_.first, __prefix_.second, __output_iter);
54697a984708SDavid Chisnall                    break;
54707a984708SDavid Chisnall                case '\'':
54717a984708SDavid Chisnall                    ++__fmt_first;
5472b2c7081bSDimitry Andric                    __output_iter = _VSTD::copy(__suffix_.first, __suffix_.second, __output_iter);
54737a984708SDavid Chisnall                    break;
54747a984708SDavid Chisnall                default:
54757a984708SDavid Chisnall                    if ('0' <= __fmt_first[1] && __fmt_first[1] <= '9')
54767a984708SDavid Chisnall                    {
54777a984708SDavid Chisnall                        ++__fmt_first;
5478b2c7081bSDimitry Andric                        size_t __idx = *__fmt_first - '0';
54797a984708SDavid Chisnall                        if (__fmt_first + 1 != __fmt_last &&
54807a984708SDavid Chisnall                            '0' <= __fmt_first[1] && __fmt_first[1] <= '9')
54817a984708SDavid Chisnall                        {
54827a984708SDavid Chisnall                            ++__fmt_first;
5483b2c7081bSDimitry Andric                            if (__idx >= std::numeric_limits<size_t>::max() / 10)
5484b2c7081bSDimitry Andric                                __throw_regex_error<regex_constants::error_escape>();
5485b2c7081bSDimitry Andric                            __idx = 10 * __idx + *__fmt_first - '0';
54867a984708SDavid Chisnall                        }
5487b2c7081bSDimitry Andric                        __output_iter = _VSTD::copy((*this)[__idx].first,
5488b2c7081bSDimitry Andric                                            (*this)[__idx].second, __output_iter);
54897a984708SDavid Chisnall                    }
54907a984708SDavid Chisnall                    else
54917a984708SDavid Chisnall                    {
5492b2c7081bSDimitry Andric                        *__output_iter = *__fmt_first;
5493b2c7081bSDimitry Andric                        ++__output_iter;
54947a984708SDavid Chisnall                    }
54957a984708SDavid Chisnall                    break;
54967a984708SDavid Chisnall                }
54977a984708SDavid Chisnall            }
54987a984708SDavid Chisnall            else
54997a984708SDavid Chisnall            {
5500b2c7081bSDimitry Andric                *__output_iter = *__fmt_first;
5501b2c7081bSDimitry Andric                ++__output_iter;
55027a984708SDavid Chisnall            }
55037a984708SDavid Chisnall        }
55047a984708SDavid Chisnall    }
5505b2c7081bSDimitry Andric    return __output_iter;
55067a984708SDavid Chisnall}
55077a984708SDavid Chisnall
55087a984708SDavid Chisnalltemplate <class _BidirectionalIterator, class _Allocator>
55097a984708SDavid Chisnallvoid
55107a984708SDavid Chisnallmatch_results<_BidirectionalIterator, _Allocator>::swap(match_results& __m)
55117a984708SDavid Chisnall{
55127a984708SDavid Chisnall    using _VSTD::swap;
55137a984708SDavid Chisnall    swap(__matches_, __m.__matches_);
55147a984708SDavid Chisnall    swap(__unmatched_, __m.__unmatched_);
55157a984708SDavid Chisnall    swap(__prefix_, __m.__prefix_);
55167a984708SDavid Chisnall    swap(__suffix_, __m.__suffix_);
55177a984708SDavid Chisnall    swap(__position_start_, __m.__position_start_);
55187a984708SDavid Chisnall    swap(__ready_, __m.__ready_);
55197a984708SDavid Chisnall}
55207a984708SDavid Chisnall
55217a984708SDavid Chisnalltypedef match_results<const char*>             cmatch;
55227a984708SDavid Chisnalltypedef match_results<const wchar_t*>          wcmatch;
55237a984708SDavid Chisnalltypedef match_results<string::const_iterator>  smatch;
55247a984708SDavid Chisnalltypedef match_results<wstring::const_iterator> wsmatch;
55257a984708SDavid Chisnall
55267a984708SDavid Chisnalltemplate <class _BidirectionalIterator, class _Allocator>
55277a984708SDavid Chisnallbool
55287a984708SDavid Chisnalloperator==(const match_results<_BidirectionalIterator, _Allocator>& __x,
55297a984708SDavid Chisnall           const match_results<_BidirectionalIterator, _Allocator>& __y)
55307a984708SDavid Chisnall{
55317a984708SDavid Chisnall    if (__x.__ready_ != __y.__ready_)
55327a984708SDavid Chisnall        return false;
55337a984708SDavid Chisnall    if (!__x.__ready_)
55347a984708SDavid Chisnall        return true;
55357a984708SDavid Chisnall    return __x.__matches_ == __y.__matches_ &&
55367a984708SDavid Chisnall           __x.__prefix_ == __y.__prefix_ &&
55377a984708SDavid Chisnall           __x.__suffix_ == __y.__suffix_;
55387a984708SDavid Chisnall}
55397a984708SDavid Chisnall
55407a984708SDavid Chisnalltemplate <class _BidirectionalIterator, class _Allocator>
55417a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
55427a984708SDavid Chisnallbool
55437a984708SDavid Chisnalloperator!=(const match_results<_BidirectionalIterator, _Allocator>& __x,
55447a984708SDavid Chisnall           const match_results<_BidirectionalIterator, _Allocator>& __y)
55457a984708SDavid Chisnall{
55467a984708SDavid Chisnall    return !(__x == __y);
55477a984708SDavid Chisnall}
55487a984708SDavid Chisnall
55497a984708SDavid Chisnalltemplate <class _BidirectionalIterator, class _Allocator>
55507a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
55517a984708SDavid Chisnallvoid
55527a984708SDavid Chisnallswap(match_results<_BidirectionalIterator, _Allocator>& __x,
55537a984708SDavid Chisnall     match_results<_BidirectionalIterator, _Allocator>& __y)
55547a984708SDavid Chisnall{
55557a984708SDavid Chisnall    __x.swap(__y);
55567a984708SDavid Chisnall}
55577a984708SDavid Chisnall
55587a984708SDavid Chisnall// regex_search
55597a984708SDavid Chisnall
55607a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
55617a984708SDavid Chisnalltemplate <class _Allocator>
55627a984708SDavid Chisnallbool
55637a984708SDavid Chisnallbasic_regex<_CharT, _Traits>::__match_at_start_ecma(
55647a984708SDavid Chisnall        const _CharT* __first, const _CharT* __last,
55657a984708SDavid Chisnall        match_results<const _CharT*, _Allocator>& __m,
55667a984708SDavid Chisnall        regex_constants::match_flag_type __flags, bool __at_first) const
55677a984708SDavid Chisnall{
55687a984708SDavid Chisnall    vector<__state> __states;
55697a984708SDavid Chisnall    __node* __st = __start_.get();
55707a984708SDavid Chisnall    if (__st)
55717a984708SDavid Chisnall    {
5572854fa44bSDimitry Andric        sub_match<const _CharT*> __unmatched;
5573854fa44bSDimitry Andric        __unmatched.first   = __last;
5574854fa44bSDimitry Andric        __unmatched.second  = __last;
5575854fa44bSDimitry Andric        __unmatched.matched = false;
5576854fa44bSDimitry Andric
55777a984708SDavid Chisnall        __states.push_back(__state());
55787a984708SDavid Chisnall        __states.back().__do_ = 0;
55797a984708SDavid Chisnall        __states.back().__first_ = __first;
55807a984708SDavid Chisnall        __states.back().__current_ = __first;
55817a984708SDavid Chisnall        __states.back().__last_ = __last;
5582854fa44bSDimitry Andric        __states.back().__sub_matches_.resize(mark_count(), __unmatched);
55837a984708SDavid Chisnall        __states.back().__loop_data_.resize(__loop_count());
55847a984708SDavid Chisnall        __states.back().__node_ = __st;
55857a984708SDavid Chisnall        __states.back().__flags_ = __flags;
55867a984708SDavid Chisnall        __states.back().__at_first_ = __at_first;
5587b2c7081bSDimitry Andric        int __counter = 0;
5588b2c7081bSDimitry Andric        int __length = __last - __first;
55897a984708SDavid Chisnall        do
55907a984708SDavid Chisnall        {
5591b2c7081bSDimitry Andric            ++__counter;
5592b2c7081bSDimitry Andric            if (__counter % _LIBCPP_REGEX_COMPLEXITY_FACTOR == 0 &&
5593b2c7081bSDimitry Andric                __counter / _LIBCPP_REGEX_COMPLEXITY_FACTOR >= __length)
5594b2c7081bSDimitry Andric              __throw_regex_error<regex_constants::error_complexity>();
55957a984708SDavid Chisnall            __state& __s = __states.back();
55967a984708SDavid Chisnall            if (__s.__node_)
55977a984708SDavid Chisnall                __s.__node_->__exec(__s);
55987a984708SDavid Chisnall            switch (__s.__do_)
55997a984708SDavid Chisnall            {
56007a984708SDavid Chisnall            case __state::__end_state:
5601aed8d94eSDimitry Andric                if ((__flags & regex_constants::match_not_null) &&
5602aed8d94eSDimitry Andric                    __s.__current_ == __first)
5603aed8d94eSDimitry Andric                {
5604aed8d94eSDimitry Andric                  __states.pop_back();
5605aed8d94eSDimitry Andric                  break;
5606aed8d94eSDimitry Andric                }
5607aed8d94eSDimitry Andric                if ((__flags & regex_constants::__full_match) &&
5608aed8d94eSDimitry Andric                    __s.__current_ != __last)
5609aed8d94eSDimitry Andric                {
5610aed8d94eSDimitry Andric                  __states.pop_back();
5611aed8d94eSDimitry Andric                  break;
5612aed8d94eSDimitry Andric                }
56137a984708SDavid Chisnall                __m.__matches_[0].first = __first;
56147a984708SDavid Chisnall                __m.__matches_[0].second = _VSTD::next(__first, __s.__current_ - __first);
56157a984708SDavid Chisnall                __m.__matches_[0].matched = true;
56167a984708SDavid Chisnall                for (unsigned __i = 0; __i < __s.__sub_matches_.size(); ++__i)
56177a984708SDavid Chisnall                    __m.__matches_[__i+1] = __s.__sub_matches_[__i];
56187a984708SDavid Chisnall                return true;
56197a984708SDavid Chisnall            case __state::__accept_and_consume:
56207a984708SDavid Chisnall            case __state::__repeat:
56217a984708SDavid Chisnall            case __state::__accept_but_not_consume:
56227a984708SDavid Chisnall                break;
56237a984708SDavid Chisnall            case __state::__split:
56247a984708SDavid Chisnall                {
56257a984708SDavid Chisnall                __state __snext = __s;
56267a984708SDavid Chisnall                __s.__node_->__exec_split(true, __s);
56277a984708SDavid Chisnall                __snext.__node_->__exec_split(false, __snext);
56287a984708SDavid Chisnall                __states.push_back(_VSTD::move(__snext));
56297a984708SDavid Chisnall                }
56307a984708SDavid Chisnall                break;
56317a984708SDavid Chisnall            case __state::__reject:
56327a984708SDavid Chisnall                __states.pop_back();
56337a984708SDavid Chisnall                break;
56347a984708SDavid Chisnall            default:
56359729cf09SDimitry Andric                __throw_regex_error<regex_constants::__re_err_unknown>();
56367a984708SDavid Chisnall                break;
56377a984708SDavid Chisnall
56387a984708SDavid Chisnall            }
56397a984708SDavid Chisnall        } while (!__states.empty());
56407a984708SDavid Chisnall    }
56417a984708SDavid Chisnall    return false;
56427a984708SDavid Chisnall}
56437a984708SDavid Chisnall
56447a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
56457a984708SDavid Chisnalltemplate <class _Allocator>
56467a984708SDavid Chisnallbool
56477a984708SDavid Chisnallbasic_regex<_CharT, _Traits>::__match_at_start_posix_nosubs(
56487a984708SDavid Chisnall        const _CharT* __first, const _CharT* __last,
56497a984708SDavid Chisnall        match_results<const _CharT*, _Allocator>& __m,
56507a984708SDavid Chisnall        regex_constants::match_flag_type __flags, bool __at_first) const
56517a984708SDavid Chisnall{
56527a984708SDavid Chisnall    deque<__state> __states;
56537a984708SDavid Chisnall    ptrdiff_t __highest_j = 0;
565494e3ee44SDavid Chisnall    ptrdiff_t _Np = _VSTD::distance(__first, __last);
56557a984708SDavid Chisnall    __node* __st = __start_.get();
56567a984708SDavid Chisnall    if (__st)
56577a984708SDavid Chisnall    {
56587a984708SDavid Chisnall        __states.push_back(__state());
56597a984708SDavid Chisnall        __states.back().__do_ = 0;
56607a984708SDavid Chisnall        __states.back().__first_ = __first;
56617a984708SDavid Chisnall        __states.back().__current_ = __first;
56627a984708SDavid Chisnall        __states.back().__last_ = __last;
56637a984708SDavid Chisnall        __states.back().__loop_data_.resize(__loop_count());
56647a984708SDavid Chisnall        __states.back().__node_ = __st;
56657a984708SDavid Chisnall        __states.back().__flags_ = __flags;
56667a984708SDavid Chisnall        __states.back().__at_first_ = __at_first;
56677a984708SDavid Chisnall        bool __matched = false;
5668b2c7081bSDimitry Andric        int __counter = 0;
5669b2c7081bSDimitry Andric        int __length = __last - __first;
56707a984708SDavid Chisnall        do
56717a984708SDavid Chisnall        {
5672b2c7081bSDimitry Andric            ++__counter;
5673b2c7081bSDimitry Andric            if (__counter % _LIBCPP_REGEX_COMPLEXITY_FACTOR == 0 &&
5674b2c7081bSDimitry Andric                __counter / _LIBCPP_REGEX_COMPLEXITY_FACTOR >= __length)
5675b2c7081bSDimitry Andric              __throw_regex_error<regex_constants::error_complexity>();
56767a984708SDavid Chisnall            __state& __s = __states.back();
56777a984708SDavid Chisnall            if (__s.__node_)
56787a984708SDavid Chisnall                __s.__node_->__exec(__s);
56797a984708SDavid Chisnall            switch (__s.__do_)
56807a984708SDavid Chisnall            {
56817a984708SDavid Chisnall            case __state::__end_state:
5682aed8d94eSDimitry Andric                if ((__flags & regex_constants::match_not_null) &&
5683aed8d94eSDimitry Andric                    __s.__current_ == __first)
5684aed8d94eSDimitry Andric                {
5685aed8d94eSDimitry Andric                  __states.pop_back();
5686aed8d94eSDimitry Andric                  break;
5687aed8d94eSDimitry Andric                }
5688aed8d94eSDimitry Andric                if ((__flags & regex_constants::__full_match) &&
5689aed8d94eSDimitry Andric                    __s.__current_ != __last)
5690aed8d94eSDimitry Andric                {
5691aed8d94eSDimitry Andric                  __states.pop_back();
5692aed8d94eSDimitry Andric                  break;
5693aed8d94eSDimitry Andric                }
56947a984708SDavid Chisnall                if (!__matched || __highest_j < __s.__current_ - __s.__first_)
56957a984708SDavid Chisnall                    __highest_j = __s.__current_ - __s.__first_;
56967a984708SDavid Chisnall                __matched = true;
569794e3ee44SDavid Chisnall                if (__highest_j == _Np)
56987a984708SDavid Chisnall                    __states.clear();
56997a984708SDavid Chisnall                else
57007a984708SDavid Chisnall                    __states.pop_back();
57017a984708SDavid Chisnall                break;
57027a984708SDavid Chisnall            case __state::__consume_input:
57037a984708SDavid Chisnall                break;
57047a984708SDavid Chisnall            case __state::__accept_and_consume:
57057a984708SDavid Chisnall                __states.push_front(_VSTD::move(__s));
57067a984708SDavid Chisnall                __states.pop_back();
57077a984708SDavid Chisnall                break;
57087a984708SDavid Chisnall            case __state::__repeat:
57097a984708SDavid Chisnall            case __state::__accept_but_not_consume:
57107a984708SDavid Chisnall                break;
57117a984708SDavid Chisnall            case __state::__split:
57127a984708SDavid Chisnall                {
57137a984708SDavid Chisnall                __state __snext = __s;
57147a984708SDavid Chisnall                __s.__node_->__exec_split(true, __s);
57157a984708SDavid Chisnall                __snext.__node_->__exec_split(false, __snext);
57167a984708SDavid Chisnall                __states.push_back(_VSTD::move(__snext));
57177a984708SDavid Chisnall                }
57187a984708SDavid Chisnall                break;
57197a984708SDavid Chisnall            case __state::__reject:
57207a984708SDavid Chisnall                __states.pop_back();
57217a984708SDavid Chisnall                break;
57227a984708SDavid Chisnall            default:
57239729cf09SDimitry Andric                __throw_regex_error<regex_constants::__re_err_unknown>();
57247a984708SDavid Chisnall                break;
57257a984708SDavid Chisnall            }
57267a984708SDavid Chisnall        } while (!__states.empty());
57277a984708SDavid Chisnall        if (__matched)
57287a984708SDavid Chisnall        {
57297a984708SDavid Chisnall            __m.__matches_[0].first = __first;
57307a984708SDavid Chisnall            __m.__matches_[0].second = _VSTD::next(__first, __highest_j);
57317a984708SDavid Chisnall            __m.__matches_[0].matched = true;
57327a984708SDavid Chisnall            return true;
57337a984708SDavid Chisnall        }
57347a984708SDavid Chisnall    }
57357a984708SDavid Chisnall    return false;
57367a984708SDavid Chisnall}
57377a984708SDavid Chisnall
57387a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
57397a984708SDavid Chisnalltemplate <class _Allocator>
57407a984708SDavid Chisnallbool
57417a984708SDavid Chisnallbasic_regex<_CharT, _Traits>::__match_at_start_posix_subs(
57427a984708SDavid Chisnall        const _CharT* __first, const _CharT* __last,
57437a984708SDavid Chisnall        match_results<const _CharT*, _Allocator>& __m,
57447a984708SDavid Chisnall        regex_constants::match_flag_type __flags, bool __at_first) const
57457a984708SDavid Chisnall{
57467a984708SDavid Chisnall    vector<__state> __states;
57477a984708SDavid Chisnall    __state __best_state;
57487a984708SDavid Chisnall    ptrdiff_t __j = 0;
57497a984708SDavid Chisnall    ptrdiff_t __highest_j = 0;
575094e3ee44SDavid Chisnall    ptrdiff_t _Np = _VSTD::distance(__first, __last);
57517a984708SDavid Chisnall    __node* __st = __start_.get();
57527a984708SDavid Chisnall    if (__st)
57537a984708SDavid Chisnall    {
5754854fa44bSDimitry Andric        sub_match<const _CharT*> __unmatched;
5755854fa44bSDimitry Andric        __unmatched.first   = __last;
5756854fa44bSDimitry Andric        __unmatched.second  = __last;
5757854fa44bSDimitry Andric        __unmatched.matched = false;
5758854fa44bSDimitry Andric
57597a984708SDavid Chisnall        __states.push_back(__state());
57607a984708SDavid Chisnall        __states.back().__do_ = 0;
57617a984708SDavid Chisnall        __states.back().__first_ = __first;
57627a984708SDavid Chisnall        __states.back().__current_ = __first;
57637a984708SDavid Chisnall        __states.back().__last_ = __last;
5764854fa44bSDimitry Andric        __states.back().__sub_matches_.resize(mark_count(), __unmatched);
57657a984708SDavid Chisnall        __states.back().__loop_data_.resize(__loop_count());
57667a984708SDavid Chisnall        __states.back().__node_ = __st;
57677a984708SDavid Chisnall        __states.back().__flags_ = __flags;
57687a984708SDavid Chisnall        __states.back().__at_first_ = __at_first;
57697a984708SDavid Chisnall        const _CharT* __current = __first;
57707a984708SDavid Chisnall        bool __matched = false;
5771b2c7081bSDimitry Andric        int __counter = 0;
5772b2c7081bSDimitry Andric        int __length = __last - __first;
57737a984708SDavid Chisnall        do
57747a984708SDavid Chisnall        {
5775b2c7081bSDimitry Andric            ++__counter;
5776b2c7081bSDimitry Andric            if (__counter % _LIBCPP_REGEX_COMPLEXITY_FACTOR == 0 &&
5777b2c7081bSDimitry Andric                __counter / _LIBCPP_REGEX_COMPLEXITY_FACTOR >= __length)
5778b2c7081bSDimitry Andric              __throw_regex_error<regex_constants::error_complexity>();
57797a984708SDavid Chisnall            __state& __s = __states.back();
57807a984708SDavid Chisnall            if (__s.__node_)
57817a984708SDavid Chisnall                __s.__node_->__exec(__s);
57827a984708SDavid Chisnall            switch (__s.__do_)
57837a984708SDavid Chisnall            {
57847a984708SDavid Chisnall            case __state::__end_state:
5785aed8d94eSDimitry Andric                if ((__flags & regex_constants::match_not_null) &&
5786aed8d94eSDimitry Andric                    __s.__current_ == __first)
5787aed8d94eSDimitry Andric                {
5788aed8d94eSDimitry Andric                  __states.pop_back();
5789aed8d94eSDimitry Andric                  break;
5790aed8d94eSDimitry Andric                }
5791aed8d94eSDimitry Andric                if ((__flags & regex_constants::__full_match) &&
5792aed8d94eSDimitry Andric                    __s.__current_ != __last)
5793aed8d94eSDimitry Andric                {
5794aed8d94eSDimitry Andric                  __states.pop_back();
5795aed8d94eSDimitry Andric                  break;
5796aed8d94eSDimitry Andric                }
57977a984708SDavid Chisnall                if (!__matched || __highest_j < __s.__current_ - __s.__first_)
57987a984708SDavid Chisnall                {
57997a984708SDavid Chisnall                    __highest_j = __s.__current_ - __s.__first_;
58007a984708SDavid Chisnall                    __best_state = __s;
58017a984708SDavid Chisnall                }
58027a984708SDavid Chisnall                __matched = true;
580394e3ee44SDavid Chisnall                if (__highest_j == _Np)
58047a984708SDavid Chisnall                    __states.clear();
58057a984708SDavid Chisnall                else
58067a984708SDavid Chisnall                    __states.pop_back();
58077a984708SDavid Chisnall                break;
58087a984708SDavid Chisnall            case __state::__accept_and_consume:
58097a984708SDavid Chisnall                __j += __s.__current_ - __current;
58107a984708SDavid Chisnall                __current = __s.__current_;
58117a984708SDavid Chisnall                break;
58127a984708SDavid Chisnall            case __state::__repeat:
58137a984708SDavid Chisnall            case __state::__accept_but_not_consume:
58147a984708SDavid Chisnall                break;
58157a984708SDavid Chisnall            case __state::__split:
58167a984708SDavid Chisnall                {
58177a984708SDavid Chisnall                __state __snext = __s;
58187a984708SDavid Chisnall                __s.__node_->__exec_split(true, __s);
58197a984708SDavid Chisnall                __snext.__node_->__exec_split(false, __snext);
58207a984708SDavid Chisnall                __states.push_back(_VSTD::move(__snext));
58217a984708SDavid Chisnall                }
58227a984708SDavid Chisnall                break;
58237a984708SDavid Chisnall            case __state::__reject:
58247a984708SDavid Chisnall                __states.pop_back();
58257a984708SDavid Chisnall                break;
58267a984708SDavid Chisnall            default:
58279729cf09SDimitry Andric                __throw_regex_error<regex_constants::__re_err_unknown>();
58287a984708SDavid Chisnall                break;
58297a984708SDavid Chisnall            }
58307a984708SDavid Chisnall        } while (!__states.empty());
58317a984708SDavid Chisnall        if (__matched)
58327a984708SDavid Chisnall        {
58337a984708SDavid Chisnall            __m.__matches_[0].first = __first;
58347a984708SDavid Chisnall            __m.__matches_[0].second = _VSTD::next(__first, __highest_j);
58357a984708SDavid Chisnall            __m.__matches_[0].matched = true;
58367a984708SDavid Chisnall            for (unsigned __i = 0; __i < __best_state.__sub_matches_.size(); ++__i)
58377a984708SDavid Chisnall                __m.__matches_[__i+1] = __best_state.__sub_matches_[__i];
58387a984708SDavid Chisnall            return true;
58397a984708SDavid Chisnall        }
58407a984708SDavid Chisnall    }
58417a984708SDavid Chisnall    return false;
58427a984708SDavid Chisnall}
58437a984708SDavid Chisnall
58447a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
58457a984708SDavid Chisnalltemplate <class _Allocator>
58467a984708SDavid Chisnallbool
58477a984708SDavid Chisnallbasic_regex<_CharT, _Traits>::__match_at_start(
58487a984708SDavid Chisnall        const _CharT* __first, const _CharT* __last,
58497a984708SDavid Chisnall        match_results<const _CharT*, _Allocator>& __m,
58507a984708SDavid Chisnall        regex_constants::match_flag_type __flags, bool __at_first) const
58517a984708SDavid Chisnall{
58527a984708SDavid Chisnall    if ((__flags_ & 0x1F0) == ECMAScript)
58537a984708SDavid Chisnall        return __match_at_start_ecma(__first, __last, __m, __flags, __at_first);
58547a984708SDavid Chisnall    if (mark_count() == 0)
58557a984708SDavid Chisnall        return __match_at_start_posix_nosubs(__first, __last, __m, __flags, __at_first);
58567a984708SDavid Chisnall    return __match_at_start_posix_subs(__first, __last, __m, __flags, __at_first);
58577a984708SDavid Chisnall}
58587a984708SDavid Chisnall
58597a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
58607a984708SDavid Chisnalltemplate <class _Allocator>
58617a984708SDavid Chisnallbool
58627a984708SDavid Chisnallbasic_regex<_CharT, _Traits>::__search(
58637a984708SDavid Chisnall        const _CharT* __first, const _CharT* __last,
58647a984708SDavid Chisnall        match_results<const _CharT*, _Allocator>& __m,
58657a984708SDavid Chisnall        regex_constants::match_flag_type __flags) const
58667a984708SDavid Chisnall{
58677a984708SDavid Chisnall    __m.__init(1 + mark_count(), __first, __last,
58687a984708SDavid Chisnall                                    __flags & regex_constants::__no_update_pos);
58694f7ab58eSDimitry Andric    if (__match_at_start(__first, __last, __m, __flags,
58704f7ab58eSDimitry Andric                                    !(__flags & regex_constants::__no_update_pos)))
58717a984708SDavid Chisnall    {
58727a984708SDavid Chisnall        __m.__prefix_.second = __m[0].first;
58737a984708SDavid Chisnall        __m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second;
58747a984708SDavid Chisnall        __m.__suffix_.first = __m[0].second;
58757a984708SDavid Chisnall        __m.__suffix_.matched = __m.__suffix_.first != __m.__suffix_.second;
58767a984708SDavid Chisnall        return true;
58777a984708SDavid Chisnall    }
58787a984708SDavid Chisnall    if (__first != __last && !(__flags & regex_constants::match_continuous))
58797a984708SDavid Chisnall    {
58807a984708SDavid Chisnall        __flags |= regex_constants::match_prev_avail;
58817a984708SDavid Chisnall        for (++__first; __first != __last; ++__first)
58827a984708SDavid Chisnall        {
58837a984708SDavid Chisnall            __m.__matches_.assign(__m.size(), __m.__unmatched_);
58847a984708SDavid Chisnall            if (__match_at_start(__first, __last, __m, __flags, false))
58857a984708SDavid Chisnall            {
58867a984708SDavid Chisnall                __m.__prefix_.second = __m[0].first;
58877a984708SDavid Chisnall                __m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second;
58887a984708SDavid Chisnall                __m.__suffix_.first = __m[0].second;
58897a984708SDavid Chisnall                __m.__suffix_.matched = __m.__suffix_.first != __m.__suffix_.second;
58907a984708SDavid Chisnall                return true;
58917a984708SDavid Chisnall            }
58927a984708SDavid Chisnall            __m.__matches_.assign(__m.size(), __m.__unmatched_);
58937a984708SDavid Chisnall        }
58947a984708SDavid Chisnall    }
58957a984708SDavid Chisnall    __m.__matches_.clear();
58967a984708SDavid Chisnall    return false;
58977a984708SDavid Chisnall}
58987a984708SDavid Chisnall
58997a984708SDavid Chisnalltemplate <class _BidirectionalIterator, class _Allocator, class _CharT, class _Traits>
59007a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
59017a984708SDavid Chisnallbool
59027a984708SDavid Chisnallregex_search(_BidirectionalIterator __first, _BidirectionalIterator __last,
59037a984708SDavid Chisnall             match_results<_BidirectionalIterator, _Allocator>& __m,
59047a984708SDavid Chisnall             const basic_regex<_CharT, _Traits>& __e,
59057a984708SDavid Chisnall             regex_constants::match_flag_type __flags = regex_constants::match_default)
59067a984708SDavid Chisnall{
59074f7ab58eSDimitry Andric    int __offset = (__flags & regex_constants::match_prev_avail) ? 1 : 0;
59084f7ab58eSDimitry Andric    basic_string<_CharT> __s(_VSTD::prev(__first, __offset), __last);
59097a984708SDavid Chisnall    match_results<const _CharT*> __mc;
59104f7ab58eSDimitry Andric    bool __r = __e.__search(__s.data() + __offset, __s.data() + __s.size(), __mc, __flags);
59117a984708SDavid Chisnall    __m.__assign(__first, __last, __mc, __flags & regex_constants::__no_update_pos);
59127a984708SDavid Chisnall    return __r;
59137a984708SDavid Chisnall}
59147a984708SDavid Chisnall
59154bab9fd9SDavid Chisnalltemplate <class _Iter, class _Allocator, class _CharT, class _Traits>
59164bab9fd9SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
59174bab9fd9SDavid Chisnallbool
59184bab9fd9SDavid Chisnallregex_search(__wrap_iter<_Iter> __first,
59194bab9fd9SDavid Chisnall             __wrap_iter<_Iter> __last,
59204bab9fd9SDavid Chisnall             match_results<__wrap_iter<_Iter>, _Allocator>& __m,
59214bab9fd9SDavid Chisnall             const basic_regex<_CharT, _Traits>& __e,
59224bab9fd9SDavid Chisnall             regex_constants::match_flag_type __flags = regex_constants::match_default)
59234bab9fd9SDavid Chisnall{
59244bab9fd9SDavid Chisnall    match_results<const _CharT*> __mc;
59254bab9fd9SDavid Chisnall    bool __r = __e.__search(__first.base(), __last.base(), __mc, __flags);
59264bab9fd9SDavid Chisnall    __m.__assign(__first, __last, __mc, __flags & regex_constants::__no_update_pos);
59274bab9fd9SDavid Chisnall    return __r;
59284bab9fd9SDavid Chisnall}
59294bab9fd9SDavid Chisnall
59307a984708SDavid Chisnalltemplate <class _Allocator, class _CharT, class _Traits>
59317a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
59327a984708SDavid Chisnallbool
59337a984708SDavid Chisnallregex_search(const _CharT* __first, const _CharT* __last,
59347a984708SDavid Chisnall             match_results<const _CharT*, _Allocator>& __m,
59357a984708SDavid Chisnall             const basic_regex<_CharT, _Traits>& __e,
59367a984708SDavid Chisnall             regex_constants::match_flag_type __flags = regex_constants::match_default)
59377a984708SDavid Chisnall{
59387a984708SDavid Chisnall    return __e.__search(__first, __last, __m, __flags);
59397a984708SDavid Chisnall}
59407a984708SDavid Chisnall
59417a984708SDavid Chisnalltemplate <class _BidirectionalIterator, class _CharT, class _Traits>
59427a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
59437a984708SDavid Chisnallbool
59447a984708SDavid Chisnallregex_search(_BidirectionalIterator __first, _BidirectionalIterator __last,
59457a984708SDavid Chisnall             const basic_regex<_CharT, _Traits>& __e,
59467a984708SDavid Chisnall             regex_constants::match_flag_type __flags = regex_constants::match_default)
59477a984708SDavid Chisnall{
59487a984708SDavid Chisnall    basic_string<_CharT> __s(__first, __last);
59497a984708SDavid Chisnall    match_results<const _CharT*> __mc;
59507a984708SDavid Chisnall    return __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags);
59517a984708SDavid Chisnall}
59527a984708SDavid Chisnall
59537a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
59547a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
59557a984708SDavid Chisnallbool
59567a984708SDavid Chisnallregex_search(const _CharT* __first, const _CharT* __last,
59577a984708SDavid Chisnall             const basic_regex<_CharT, _Traits>& __e,
59587a984708SDavid Chisnall             regex_constants::match_flag_type __flags = regex_constants::match_default)
59597a984708SDavid Chisnall{
59607a984708SDavid Chisnall    match_results<const _CharT*> __mc;
59617a984708SDavid Chisnall    return __e.__search(__first, __last, __mc, __flags);
59627a984708SDavid Chisnall}
59637a984708SDavid Chisnall
59647a984708SDavid Chisnalltemplate <class _CharT, class _Allocator, class _Traits>
59657a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
59667a984708SDavid Chisnallbool
59677a984708SDavid Chisnallregex_search(const _CharT* __str, match_results<const _CharT*, _Allocator>& __m,
59687a984708SDavid Chisnall             const basic_regex<_CharT, _Traits>& __e,
59697a984708SDavid Chisnall             regex_constants::match_flag_type __flags = regex_constants::match_default)
59707a984708SDavid Chisnall{
59717a984708SDavid Chisnall    return __e.__search(__str, __str + _Traits::length(__str), __m, __flags);
59727a984708SDavid Chisnall}
59737a984708SDavid Chisnall
59747a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
59757a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
59767a984708SDavid Chisnallbool
59777a984708SDavid Chisnallregex_search(const _CharT* __str, const basic_regex<_CharT, _Traits>& __e,
59787a984708SDavid Chisnall             regex_constants::match_flag_type __flags = regex_constants::match_default)
59797a984708SDavid Chisnall{
59807a984708SDavid Chisnall    match_results<const _CharT*> __m;
59817a984708SDavid Chisnall    return _VSTD::regex_search(__str, __m, __e, __flags);
59827a984708SDavid Chisnall}
59837a984708SDavid Chisnall
59847a984708SDavid Chisnalltemplate <class _ST, class _SA, class _CharT, class _Traits>
59857a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
59867a984708SDavid Chisnallbool
59877a984708SDavid Chisnallregex_search(const basic_string<_CharT, _ST, _SA>& __s,
59887a984708SDavid Chisnall             const basic_regex<_CharT, _Traits>& __e,
59897a984708SDavid Chisnall             regex_constants::match_flag_type __flags = regex_constants::match_default)
59907a984708SDavid Chisnall{
59917a984708SDavid Chisnall    match_results<const _CharT*> __mc;
59927a984708SDavid Chisnall    return __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags);
59937a984708SDavid Chisnall}
59947a984708SDavid Chisnall
59957a984708SDavid Chisnalltemplate <class _ST, class _SA, class _Allocator, class _CharT, class _Traits>
59967a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
59977a984708SDavid Chisnallbool
59987a984708SDavid Chisnallregex_search(const basic_string<_CharT, _ST, _SA>& __s,
59997a984708SDavid Chisnall             match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m,
60007a984708SDavid Chisnall             const basic_regex<_CharT, _Traits>& __e,
60017a984708SDavid Chisnall             regex_constants::match_flag_type __flags = regex_constants::match_default)
60027a984708SDavid Chisnall{
60037a984708SDavid Chisnall    match_results<const _CharT*> __mc;
60047a984708SDavid Chisnall    bool __r = __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags);
60057a984708SDavid Chisnall    __m.__assign(__s.begin(), __s.end(), __mc, __flags & regex_constants::__no_update_pos);
60067a984708SDavid Chisnall    return __r;
60077a984708SDavid Chisnall}
60087a984708SDavid Chisnall
6009d72607e9SDimitry Andric#if _LIBCPP_STD_VER > 11
6010d72607e9SDimitry Andrictemplate <class _ST, class _SA, class _Ap, class _Cp, class _Tp>
6011d72607e9SDimitry Andricbool
6012d72607e9SDimitry Andricregex_search(const basic_string<_Cp, _ST, _SA>&& __s,
6013d72607e9SDimitry Andric             match_results<typename basic_string<_Cp, _ST, _SA>::const_iterator, _Ap>&,
6014d72607e9SDimitry Andric             const basic_regex<_Cp, _Tp>& __e,
6015d72607e9SDimitry Andric             regex_constants::match_flag_type __flags = regex_constants::match_default) = delete;
6016d72607e9SDimitry Andric#endif
6017d72607e9SDimitry Andric
60187a984708SDavid Chisnall// regex_match
60197a984708SDavid Chisnall
60207a984708SDavid Chisnalltemplate <class _BidirectionalIterator, class _Allocator, class _CharT, class _Traits>
60217a984708SDavid Chisnallbool
60227a984708SDavid Chisnallregex_match(_BidirectionalIterator __first, _BidirectionalIterator __last,
60237a984708SDavid Chisnall            match_results<_BidirectionalIterator, _Allocator>& __m,
60247a984708SDavid Chisnall            const basic_regex<_CharT, _Traits>& __e,
60257a984708SDavid Chisnall            regex_constants::match_flag_type __flags = regex_constants::match_default)
60267a984708SDavid Chisnall{
6027aed8d94eSDimitry Andric    bool __r = _VSTD::regex_search(
6028aed8d94eSDimitry Andric        __first, __last, __m, __e,
6029aed8d94eSDimitry Andric        __flags | regex_constants::match_continuous |
6030aed8d94eSDimitry Andric        regex_constants::__full_match);
60317a984708SDavid Chisnall    if (__r)
60327a984708SDavid Chisnall    {
60337a984708SDavid Chisnall        __r = !__m.suffix().matched;
60347a984708SDavid Chisnall        if (!__r)
60357a984708SDavid Chisnall            __m.__matches_.clear();
60367a984708SDavid Chisnall    }
60377a984708SDavid Chisnall    return __r;
60387a984708SDavid Chisnall}
60397a984708SDavid Chisnall
60407a984708SDavid Chisnalltemplate <class _BidirectionalIterator, class _CharT, class _Traits>
60417a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
60427a984708SDavid Chisnallbool
60437a984708SDavid Chisnallregex_match(_BidirectionalIterator __first, _BidirectionalIterator __last,
60447a984708SDavid Chisnall            const basic_regex<_CharT, _Traits>& __e,
60457a984708SDavid Chisnall            regex_constants::match_flag_type __flags = regex_constants::match_default)
60467a984708SDavid Chisnall{
60477a984708SDavid Chisnall    match_results<_BidirectionalIterator> __m;
60487a984708SDavid Chisnall    return _VSTD::regex_match(__first, __last, __m, __e, __flags);
60497a984708SDavid Chisnall}
60507a984708SDavid Chisnall
60517a984708SDavid Chisnalltemplate <class _CharT, class _Allocator, class _Traits>
60527a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
60537a984708SDavid Chisnallbool
60547a984708SDavid Chisnallregex_match(const _CharT* __str, match_results<const _CharT*, _Allocator>& __m,
60557a984708SDavid Chisnall            const basic_regex<_CharT, _Traits>& __e,
60567a984708SDavid Chisnall            regex_constants::match_flag_type __flags = regex_constants::match_default)
60577a984708SDavid Chisnall{
60587a984708SDavid Chisnall    return _VSTD::regex_match(__str, __str + _Traits::length(__str), __m, __e, __flags);
60597a984708SDavid Chisnall}
60607a984708SDavid Chisnall
60617a984708SDavid Chisnalltemplate <class _ST, class _SA, class _Allocator, class _CharT, class _Traits>
60627a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
60637a984708SDavid Chisnallbool
60647a984708SDavid Chisnallregex_match(const basic_string<_CharT, _ST, _SA>& __s,
60657a984708SDavid Chisnall            match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m,
60667a984708SDavid Chisnall            const basic_regex<_CharT, _Traits>& __e,
60677a984708SDavid Chisnall            regex_constants::match_flag_type __flags = regex_constants::match_default)
60687a984708SDavid Chisnall{
60697a984708SDavid Chisnall    return _VSTD::regex_match(__s.begin(), __s.end(), __m, __e, __flags);
60707a984708SDavid Chisnall}
60717a984708SDavid Chisnall
6072d72607e9SDimitry Andric#if _LIBCPP_STD_VER > 11
6073d72607e9SDimitry Andrictemplate <class _ST, class _SA, class _Allocator, class _CharT, class _Traits>
6074d72607e9SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
6075d72607e9SDimitry Andricbool
6076d72607e9SDimitry Andricregex_match(const basic_string<_CharT, _ST, _SA>&& __s,
6077d72607e9SDimitry Andric            match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m,
6078d72607e9SDimitry Andric            const basic_regex<_CharT, _Traits>& __e,
6079d72607e9SDimitry Andric            regex_constants::match_flag_type __flags = regex_constants::match_default) = delete;
6080d72607e9SDimitry Andric#endif
6081d72607e9SDimitry Andric
60827a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
60837a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
60847a984708SDavid Chisnallbool
60857a984708SDavid Chisnallregex_match(const _CharT* __str, const basic_regex<_CharT, _Traits>& __e,
60867a984708SDavid Chisnall            regex_constants::match_flag_type __flags = regex_constants::match_default)
60877a984708SDavid Chisnall{
60887a984708SDavid Chisnall    return _VSTD::regex_match(__str, __str + _Traits::length(__str), __e, __flags);
60897a984708SDavid Chisnall}
60907a984708SDavid Chisnall
60917a984708SDavid Chisnalltemplate <class _ST, class _SA, class _CharT, class _Traits>
60927a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
60937a984708SDavid Chisnallbool
60947a984708SDavid Chisnallregex_match(const basic_string<_CharT, _ST, _SA>& __s,
60957a984708SDavid Chisnall            const basic_regex<_CharT, _Traits>& __e,
60967a984708SDavid Chisnall            regex_constants::match_flag_type __flags = regex_constants::match_default)
60977a984708SDavid Chisnall{
60987a984708SDavid Chisnall    return _VSTD::regex_match(__s.begin(), __s.end(), __e, __flags);
60997a984708SDavid Chisnall}
61007a984708SDavid Chisnall
61017a984708SDavid Chisnall// regex_iterator
61027a984708SDavid Chisnall
61037a984708SDavid Chisnalltemplate <class _BidirectionalIterator,
61047a984708SDavid Chisnall          class _CharT = typename iterator_traits<_BidirectionalIterator>::value_type,
61057a984708SDavid Chisnall          class _Traits = regex_traits<_CharT> >
6106aed8d94eSDimitry Andricclass _LIBCPP_TEMPLATE_VIS regex_iterator
61077a984708SDavid Chisnall{
61087a984708SDavid Chisnallpublic:
61097a984708SDavid Chisnall    typedef basic_regex<_CharT, _Traits>          regex_type;
61107a984708SDavid Chisnall    typedef match_results<_BidirectionalIterator> value_type;
61117a984708SDavid Chisnall    typedef ptrdiff_t                             difference_type;
61127a984708SDavid Chisnall    typedef const value_type*                     pointer;
61137a984708SDavid Chisnall    typedef const value_type&                     reference;
61147a984708SDavid Chisnall    typedef forward_iterator_tag                  iterator_category;
61157a984708SDavid Chisnall
61167a984708SDavid Chisnallprivate:
61177a984708SDavid Chisnall    _BidirectionalIterator           __begin_;
61187a984708SDavid Chisnall    _BidirectionalIterator           __end_;
61197a984708SDavid Chisnall    const regex_type*                __pregex_;
61207a984708SDavid Chisnall    regex_constants::match_flag_type __flags_;
61217a984708SDavid Chisnall    value_type                       __match_;
61227a984708SDavid Chisnall
61237a984708SDavid Chisnallpublic:
61247a984708SDavid Chisnall    regex_iterator();
61257a984708SDavid Chisnall    regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
61267a984708SDavid Chisnall                   const regex_type& __re,
6127d72607e9SDimitry Andric                   regex_constants::match_flag_type __m
6128d72607e9SDimitry Andric                                              = regex_constants::match_default);
6129d72607e9SDimitry Andric#if _LIBCPP_STD_VER > 11
6130d72607e9SDimitry Andric    regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6131d72607e9SDimitry Andric                   const regex_type&& __re,
6132d72607e9SDimitry Andric                   regex_constants::match_flag_type __m
6133d72607e9SDimitry Andric                                     = regex_constants::match_default) = delete;
6134d72607e9SDimitry Andric#endif
61357a984708SDavid Chisnall
61367a984708SDavid Chisnall    bool operator==(const regex_iterator& __x) const;
61377a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
61387a984708SDavid Chisnall    bool operator!=(const regex_iterator& __x) const {return !(*this == __x);}
61397a984708SDavid Chisnall
61407a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
61417a984708SDavid Chisnall    reference operator*() const {return  __match_;}
61427a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
61437a984708SDavid Chisnall    pointer operator->() const  {return &__match_;}
61447a984708SDavid Chisnall
61457a984708SDavid Chisnall    regex_iterator& operator++();
61467a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
61477a984708SDavid Chisnall    regex_iterator operator++(int)
61487a984708SDavid Chisnall    {
61497a984708SDavid Chisnall        regex_iterator __t(*this);
61507a984708SDavid Chisnall        ++(*this);
61517a984708SDavid Chisnall        return __t;
61527a984708SDavid Chisnall    }
61537a984708SDavid Chisnall};
61547a984708SDavid Chisnall
61557a984708SDavid Chisnalltemplate <class _BidirectionalIterator, class _CharT, class _Traits>
61567a984708SDavid Chisnallregex_iterator<_BidirectionalIterator, _CharT, _Traits>::regex_iterator()
61577a984708SDavid Chisnall    : __begin_(), __end_(), __pregex_(nullptr), __flags_(), __match_()
61587a984708SDavid Chisnall{
61597a984708SDavid Chisnall}
61607a984708SDavid Chisnall
61617a984708SDavid Chisnalltemplate <class _BidirectionalIterator, class _CharT, class _Traits>
61627a984708SDavid Chisnallregex_iterator<_BidirectionalIterator, _CharT, _Traits>::
61637a984708SDavid Chisnall    regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
61647a984708SDavid Chisnall                   const regex_type& __re, regex_constants::match_flag_type __m)
61657a984708SDavid Chisnall    : __begin_(__a),
61667a984708SDavid Chisnall      __end_(__b),
61677a984708SDavid Chisnall      __pregex_(&__re),
61687a984708SDavid Chisnall      __flags_(__m)
61697a984708SDavid Chisnall{
61707a984708SDavid Chisnall    _VSTD::regex_search(__begin_, __end_, __match_, *__pregex_, __flags_);
61717a984708SDavid Chisnall}
61727a984708SDavid Chisnall
61737a984708SDavid Chisnalltemplate <class _BidirectionalIterator, class _CharT, class _Traits>
61747a984708SDavid Chisnallbool
61757a984708SDavid Chisnallregex_iterator<_BidirectionalIterator, _CharT, _Traits>::
61767a984708SDavid Chisnall    operator==(const regex_iterator& __x) const
61777a984708SDavid Chisnall{
61787a984708SDavid Chisnall    if (__match_.empty() && __x.__match_.empty())
61797a984708SDavid Chisnall        return true;
61807a984708SDavid Chisnall    if (__match_.empty() || __x.__match_.empty())
61817a984708SDavid Chisnall        return false;
61827a984708SDavid Chisnall    return __begin_ == __x.__begin_       &&
61837a984708SDavid Chisnall           __end_ == __x.__end_           &&
61847a984708SDavid Chisnall           __pregex_ == __x.__pregex_     &&
61857a984708SDavid Chisnall           __flags_ == __x.__flags_       &&
61867a984708SDavid Chisnall           __match_[0] == __x.__match_[0];
61877a984708SDavid Chisnall}
61887a984708SDavid Chisnall
61897a984708SDavid Chisnalltemplate <class _BidirectionalIterator, class _CharT, class _Traits>
61907a984708SDavid Chisnallregex_iterator<_BidirectionalIterator, _CharT, _Traits>&
61917a984708SDavid Chisnallregex_iterator<_BidirectionalIterator, _CharT, _Traits>::operator++()
61927a984708SDavid Chisnall{
61937a984708SDavid Chisnall    __flags_ |= regex_constants::__no_update_pos;
61947a984708SDavid Chisnall    _BidirectionalIterator __start = __match_[0].second;
6195c4394386SDimitry Andric    if (__match_[0].first == __match_[0].second)
61967a984708SDavid Chisnall    {
61977a984708SDavid Chisnall        if (__start == __end_)
61987a984708SDavid Chisnall        {
61997a984708SDavid Chisnall            __match_ = value_type();
62007a984708SDavid Chisnall            return *this;
62017a984708SDavid Chisnall        }
62027a984708SDavid Chisnall        else if (_VSTD::regex_search(__start, __end_, __match_, *__pregex_,
62037a984708SDavid Chisnall                                    __flags_ | regex_constants::match_not_null |
62047a984708SDavid Chisnall                                    regex_constants::match_continuous))
62057a984708SDavid Chisnall            return *this;
62067a984708SDavid Chisnall        else
62077a984708SDavid Chisnall            ++__start;
62087a984708SDavid Chisnall    }
62097a984708SDavid Chisnall    __flags_ |= regex_constants::match_prev_avail;
62107a984708SDavid Chisnall    if (!_VSTD::regex_search(__start, __end_, __match_, *__pregex_, __flags_))
62117a984708SDavid Chisnall        __match_ = value_type();
62127a984708SDavid Chisnall    return *this;
62137a984708SDavid Chisnall}
62147a984708SDavid Chisnall
62157a984708SDavid Chisnalltypedef regex_iterator<const char*>             cregex_iterator;
62167a984708SDavid Chisnalltypedef regex_iterator<const wchar_t*>          wcregex_iterator;
62177a984708SDavid Chisnalltypedef regex_iterator<string::const_iterator>  sregex_iterator;
62187a984708SDavid Chisnalltypedef regex_iterator<wstring::const_iterator> wsregex_iterator;
62197a984708SDavid Chisnall
62207a984708SDavid Chisnall// regex_token_iterator
62217a984708SDavid Chisnall
62227a984708SDavid Chisnalltemplate <class _BidirectionalIterator,
62237a984708SDavid Chisnall          class _CharT = typename iterator_traits<_BidirectionalIterator>::value_type,
62247a984708SDavid Chisnall          class _Traits = regex_traits<_CharT> >
6225aed8d94eSDimitry Andricclass _LIBCPP_TEMPLATE_VIS regex_token_iterator
62267a984708SDavid Chisnall{
62277a984708SDavid Chisnallpublic:
62287a984708SDavid Chisnall    typedef basic_regex<_CharT, _Traits>      regex_type;
62297a984708SDavid Chisnall    typedef sub_match<_BidirectionalIterator> value_type;
62307a984708SDavid Chisnall    typedef ptrdiff_t                         difference_type;
62317a984708SDavid Chisnall    typedef const value_type*                 pointer;
62327a984708SDavid Chisnall    typedef const value_type&                 reference;
62337a984708SDavid Chisnall    typedef forward_iterator_tag              iterator_category;
62347a984708SDavid Chisnall
62357a984708SDavid Chisnallprivate:
62367a984708SDavid Chisnall    typedef regex_iterator<_BidirectionalIterator, _CharT, _Traits> _Position;
62377a984708SDavid Chisnall
62387a984708SDavid Chisnall    _Position         __position_;
62397a984708SDavid Chisnall    const value_type* __result_;
62407a984708SDavid Chisnall    value_type        __suffix_;
6241aed8d94eSDimitry Andric    ptrdiff_t         __n_;
62427a984708SDavid Chisnall    vector<int>       __subs_;
62437a984708SDavid Chisnall
62447a984708SDavid Chisnallpublic:
62457a984708SDavid Chisnall    regex_token_iterator();
62467a984708SDavid Chisnall    regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
62477a984708SDavid Chisnall                         const regex_type& __re, int __submatch = 0,
62487a984708SDavid Chisnall                         regex_constants::match_flag_type __m =
62497a984708SDavid Chisnall                                                regex_constants::match_default);
6250d72607e9SDimitry Andric#if _LIBCPP_STD_VER > 11
6251d72607e9SDimitry Andric    regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6252d72607e9SDimitry Andric                         const regex_type&& __re, int __submatch = 0,
6253d72607e9SDimitry Andric                         regex_constants::match_flag_type __m =
6254d72607e9SDimitry Andric                                       regex_constants::match_default) = delete;
6255d72607e9SDimitry Andric#endif
6256d72607e9SDimitry Andric
62577a984708SDavid Chisnall    regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
62587a984708SDavid Chisnall                         const regex_type& __re, const vector<int>& __submatches,
62597a984708SDavid Chisnall                         regex_constants::match_flag_type __m =
62607a984708SDavid Chisnall                                                regex_constants::match_default);
6261d72607e9SDimitry Andric#if _LIBCPP_STD_VER > 11
6262d72607e9SDimitry Andric    regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6263d72607e9SDimitry Andric                         const regex_type&& __re, const vector<int>& __submatches,
6264d72607e9SDimitry Andric                         regex_constants::match_flag_type __m =
6265d72607e9SDimitry Andric                                     regex_constants::match_default) = delete;
6266d72607e9SDimitry Andric#endif
6267d72607e9SDimitry Andric
6268540d2a8bSDimitry Andric#ifndef _LIBCPP_CXX03_LANG
62697a984708SDavid Chisnall    regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
62707a984708SDavid Chisnall                         const regex_type& __re,
62717a984708SDavid Chisnall                         initializer_list<int> __submatches,
62727a984708SDavid Chisnall                         regex_constants::match_flag_type __m =
62737a984708SDavid Chisnall                                                regex_constants::match_default);
6274d72607e9SDimitry Andric
6275d72607e9SDimitry Andric#if _LIBCPP_STD_VER > 11
6276d72607e9SDimitry Andric    regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6277d72607e9SDimitry Andric                         const regex_type&& __re,
6278d72607e9SDimitry Andric                         initializer_list<int> __submatches,
6279d72607e9SDimitry Andric                         regex_constants::match_flag_type __m =
6280d72607e9SDimitry Andric                                       regex_constants::match_default) = delete;
6281d72607e9SDimitry Andric#endif
6282540d2a8bSDimitry Andric#endif  // _LIBCPP_CXX03_LANG
628394e3ee44SDavid Chisnall    template <size_t _Np>
62847a984708SDavid Chisnall        regex_token_iterator(_BidirectionalIterator __a,
62857a984708SDavid Chisnall                             _BidirectionalIterator __b,
62867a984708SDavid Chisnall                             const regex_type& __re,
628794e3ee44SDavid Chisnall                             const int (&__submatches)[_Np],
62887a984708SDavid Chisnall                             regex_constants::match_flag_type __m =
62897a984708SDavid Chisnall                                                regex_constants::match_default);
6290d72607e9SDimitry Andric#if _LIBCPP_STD_VER > 11
6291d72607e9SDimitry Andric    template <std::size_t _Np>
6292d72607e9SDimitry Andric        regex_token_iterator(_BidirectionalIterator __a,
6293d72607e9SDimitry Andric                             _BidirectionalIterator __b,
6294d72607e9SDimitry Andric                             const regex_type&& __re,
6295d72607e9SDimitry Andric                             const int (&__submatches)[_Np],
6296d72607e9SDimitry Andric                             regex_constants::match_flag_type __m =
6297d72607e9SDimitry Andric                                      regex_constants::match_default) = delete;
6298d72607e9SDimitry Andric#endif
6299d72607e9SDimitry Andric
63007a984708SDavid Chisnall    regex_token_iterator(const regex_token_iterator&);
63017a984708SDavid Chisnall    regex_token_iterator& operator=(const regex_token_iterator&);
63027a984708SDavid Chisnall
63037a984708SDavid Chisnall    bool operator==(const regex_token_iterator& __x) const;
63047a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
63057a984708SDavid Chisnall    bool operator!=(const regex_token_iterator& __x) const {return !(*this == __x);}
63067a984708SDavid Chisnall
63077a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
63087a984708SDavid Chisnall    const value_type& operator*() const {return *__result_;}
63097a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
63107a984708SDavid Chisnall    const value_type* operator->() const {return __result_;}
63117a984708SDavid Chisnall
63127a984708SDavid Chisnall    regex_token_iterator& operator++();
63137a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
63147a984708SDavid Chisnall    regex_token_iterator operator++(int)
63157a984708SDavid Chisnall    {
63167a984708SDavid Chisnall        regex_token_iterator __t(*this);
63177a984708SDavid Chisnall        ++(*this);
63187a984708SDavid Chisnall        return __t;
63197a984708SDavid Chisnall    }
63207a984708SDavid Chisnall
63217a984708SDavid Chisnallprivate:
63227a984708SDavid Chisnall    void __init(_BidirectionalIterator __a, _BidirectionalIterator __b);
6323d72607e9SDimitry Andric    void __establish_result () {
6324aed8d94eSDimitry Andric        if (__subs_[__n_] == -1)
6325d72607e9SDimitry Andric            __result_ = &__position_->prefix();
6326d72607e9SDimitry Andric        else
6327aed8d94eSDimitry Andric            __result_ = &(*__position_)[__subs_[__n_]];
6328d72607e9SDimitry Andric        }
63297a984708SDavid Chisnall};
63307a984708SDavid Chisnall
63317a984708SDavid Chisnalltemplate <class _BidirectionalIterator, class _CharT, class _Traits>
63327a984708SDavid Chisnallregex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
63337a984708SDavid Chisnall    regex_token_iterator()
63347a984708SDavid Chisnall    : __result_(nullptr),
63357a984708SDavid Chisnall      __suffix_(),
6336aed8d94eSDimitry Andric      __n_(0)
63377a984708SDavid Chisnall{
63387a984708SDavid Chisnall}
63397a984708SDavid Chisnall
63407a984708SDavid Chisnalltemplate <class _BidirectionalIterator, class _CharT, class _Traits>
63417a984708SDavid Chisnallvoid
63427a984708SDavid Chisnallregex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
63437a984708SDavid Chisnall    __init(_BidirectionalIterator __a, _BidirectionalIterator __b)
63447a984708SDavid Chisnall{
63457a984708SDavid Chisnall    if (__position_ != _Position())
6346d72607e9SDimitry Andric        __establish_result ();
6347aed8d94eSDimitry Andric    else if (__subs_[__n_] == -1)
63487a984708SDavid Chisnall    {
63497a984708SDavid Chisnall        __suffix_.matched = true;
63507a984708SDavid Chisnall        __suffix_.first = __a;
63517a984708SDavid Chisnall        __suffix_.second = __b;
63527a984708SDavid Chisnall        __result_ = &__suffix_;
63537a984708SDavid Chisnall    }
63547a984708SDavid Chisnall    else
63557a984708SDavid Chisnall        __result_ = nullptr;
63567a984708SDavid Chisnall}
63577a984708SDavid Chisnall
63587a984708SDavid Chisnalltemplate <class _BidirectionalIterator, class _CharT, class _Traits>
63597a984708SDavid Chisnallregex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
63607a984708SDavid Chisnall    regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
63617a984708SDavid Chisnall                         const regex_type& __re, int __submatch,
63627a984708SDavid Chisnall                         regex_constants::match_flag_type __m)
63637a984708SDavid Chisnall    : __position_(__a, __b, __re, __m),
6364aed8d94eSDimitry Andric      __n_(0),
63657a984708SDavid Chisnall      __subs_(1, __submatch)
63667a984708SDavid Chisnall{
63677a984708SDavid Chisnall    __init(__a, __b);
63687a984708SDavid Chisnall}
63697a984708SDavid Chisnall
63707a984708SDavid Chisnalltemplate <class _BidirectionalIterator, class _CharT, class _Traits>
63717a984708SDavid Chisnallregex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
63727a984708SDavid Chisnall    regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
63737a984708SDavid Chisnall                         const regex_type& __re, const vector<int>& __submatches,
63747a984708SDavid Chisnall                         regex_constants::match_flag_type __m)
63757a984708SDavid Chisnall    : __position_(__a, __b, __re, __m),
6376aed8d94eSDimitry Andric      __n_(0),
63777a984708SDavid Chisnall      __subs_(__submatches)
63787a984708SDavid Chisnall{
63797a984708SDavid Chisnall    __init(__a, __b);
63807a984708SDavid Chisnall}
63817a984708SDavid Chisnall
6382540d2a8bSDimitry Andric#ifndef _LIBCPP_CXX03_LANG
63837a984708SDavid Chisnall
63847a984708SDavid Chisnalltemplate <class _BidirectionalIterator, class _CharT, class _Traits>
63857a984708SDavid Chisnallregex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
63867a984708SDavid Chisnall    regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
63877a984708SDavid Chisnall                         const regex_type& __re,
63887a984708SDavid Chisnall                         initializer_list<int> __submatches,
63897a984708SDavid Chisnall                         regex_constants::match_flag_type __m)
63907a984708SDavid Chisnall    : __position_(__a, __b, __re, __m),
6391aed8d94eSDimitry Andric      __n_(0),
63927a984708SDavid Chisnall      __subs_(__submatches)
63937a984708SDavid Chisnall{
63947a984708SDavid Chisnall    __init(__a, __b);
63957a984708SDavid Chisnall}
63967a984708SDavid Chisnall
6397540d2a8bSDimitry Andric#endif  // _LIBCPP_CXX03_LANG
63987a984708SDavid Chisnall
63997a984708SDavid Chisnalltemplate <class _BidirectionalIterator, class _CharT, class _Traits>
640094e3ee44SDavid Chisnalltemplate <size_t _Np>
64017a984708SDavid Chisnallregex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
64027a984708SDavid Chisnall    regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
64037a984708SDavid Chisnall                             const regex_type& __re,
640494e3ee44SDavid Chisnall                             const int (&__submatches)[_Np],
64057a984708SDavid Chisnall                             regex_constants::match_flag_type __m)
64067a984708SDavid Chisnall    : __position_(__a, __b, __re, __m),
6407aed8d94eSDimitry Andric      __n_(0),
640894e3ee44SDavid Chisnall      __subs_(__submatches, __submatches + _Np)
64097a984708SDavid Chisnall{
64107a984708SDavid Chisnall    __init(__a, __b);
64117a984708SDavid Chisnall}
64127a984708SDavid Chisnall
64137a984708SDavid Chisnalltemplate <class _BidirectionalIterator, class _CharT, class _Traits>
64147a984708SDavid Chisnallregex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
64157a984708SDavid Chisnall    regex_token_iterator(const regex_token_iterator& __x)
64167a984708SDavid Chisnall    : __position_(__x.__position_),
64177a984708SDavid Chisnall      __result_(__x.__result_),
64187a984708SDavid Chisnall      __suffix_(__x.__suffix_),
6419aed8d94eSDimitry Andric      __n_(__x.__n_),
64207a984708SDavid Chisnall      __subs_(__x.__subs_)
64217a984708SDavid Chisnall{
64227a984708SDavid Chisnall    if (__x.__result_ == &__x.__suffix_)
6423d72607e9SDimitry Andric        __result_ = &__suffix_;
6424d72607e9SDimitry Andric    else if ( __result_ != nullptr )
6425d72607e9SDimitry Andric        __establish_result ();
64267a984708SDavid Chisnall}
64277a984708SDavid Chisnall
64287a984708SDavid Chisnalltemplate <class _BidirectionalIterator, class _CharT, class _Traits>
64297a984708SDavid Chisnallregex_token_iterator<_BidirectionalIterator, _CharT, _Traits>&
64307a984708SDavid Chisnallregex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
64317a984708SDavid Chisnall    operator=(const regex_token_iterator& __x)
64327a984708SDavid Chisnall{
64337a984708SDavid Chisnall    if (this != &__x)
64347a984708SDavid Chisnall    {
64357a984708SDavid Chisnall        __position_ = __x.__position_;
64367a984708SDavid Chisnall        if (__x.__result_ == &__x.__suffix_)
6437d72607e9SDimitry Andric            __result_ = &__suffix_;
64387a984708SDavid Chisnall        else
64397a984708SDavid Chisnall            __result_ = __x.__result_;
64407a984708SDavid Chisnall        __suffix_ = __x.__suffix_;
6441aed8d94eSDimitry Andric        __n_ = __x.__n_;
64427a984708SDavid Chisnall        __subs_ = __x.__subs_;
6443d72607e9SDimitry Andric
6444d72607e9SDimitry Andric        if ( __result_ != nullptr && __result_ != &__suffix_ )
6445d72607e9SDimitry Andric            __establish_result();
64467a984708SDavid Chisnall    }
64477a984708SDavid Chisnall    return *this;
64487a984708SDavid Chisnall}
64497a984708SDavid Chisnall
64507a984708SDavid Chisnalltemplate <class _BidirectionalIterator, class _CharT, class _Traits>
64517a984708SDavid Chisnallbool
64527a984708SDavid Chisnallregex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
64537a984708SDavid Chisnall    operator==(const regex_token_iterator& __x) const
64547a984708SDavid Chisnall{
64557a984708SDavid Chisnall    if (__result_ == nullptr && __x.__result_ == nullptr)
64567a984708SDavid Chisnall        return true;
64577a984708SDavid Chisnall    if (__result_ == &__suffix_ && __x.__result_ == &__x.__suffix_ &&
64587a984708SDavid Chisnall            __suffix_ == __x.__suffix_)
64597a984708SDavid Chisnall        return true;
64607a984708SDavid Chisnall    if (__result_ == nullptr || __x.__result_ == nullptr)
64617a984708SDavid Chisnall        return false;
64627a984708SDavid Chisnall    if (__result_ == &__suffix_ || __x.__result_ == &__x.__suffix_)
64637a984708SDavid Chisnall        return false;
6464aed8d94eSDimitry Andric    return __position_ == __x.__position_ && __n_ == __x.__n_ &&
64657a984708SDavid Chisnall           __subs_ == __x.__subs_;
64667a984708SDavid Chisnall}
64677a984708SDavid Chisnall
64687a984708SDavid Chisnalltemplate <class _BidirectionalIterator, class _CharT, class _Traits>
64697a984708SDavid Chisnallregex_token_iterator<_BidirectionalIterator, _CharT, _Traits>&
64707a984708SDavid Chisnallregex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::operator++()
64717a984708SDavid Chisnall{
64727a984708SDavid Chisnall    _Position __prev = __position_;
64737a984708SDavid Chisnall    if (__result_ == &__suffix_)
64747a984708SDavid Chisnall        __result_ = nullptr;
6475aed8d94eSDimitry Andric    else if (static_cast<size_t>(__n_ + 1) < __subs_.size())
64767a984708SDavid Chisnall    {
6477aed8d94eSDimitry Andric        ++__n_;
6478d72607e9SDimitry Andric        __establish_result();
64797a984708SDavid Chisnall    }
64807a984708SDavid Chisnall    else
64817a984708SDavid Chisnall    {
6482aed8d94eSDimitry Andric        __n_ = 0;
64837a984708SDavid Chisnall        ++__position_;
64847a984708SDavid Chisnall        if (__position_ != _Position())
6485d72607e9SDimitry Andric            __establish_result();
64867a984708SDavid Chisnall        else
64877a984708SDavid Chisnall        {
64887a984708SDavid Chisnall            if (_VSTD::find(__subs_.begin(), __subs_.end(), -1) != __subs_.end()
64897a984708SDavid Chisnall                && __prev->suffix().length() != 0)
64907a984708SDavid Chisnall            {
64917a984708SDavid Chisnall                __suffix_.matched = true;
64927a984708SDavid Chisnall                __suffix_.first = __prev->suffix().first;
64937a984708SDavid Chisnall                __suffix_.second = __prev->suffix().second;
64947a984708SDavid Chisnall                __result_ = &__suffix_;
64957a984708SDavid Chisnall            }
64967a984708SDavid Chisnall            else
64977a984708SDavid Chisnall                __result_ = nullptr;
64987a984708SDavid Chisnall        }
64997a984708SDavid Chisnall    }
65007a984708SDavid Chisnall    return *this;
65017a984708SDavid Chisnall}
65027a984708SDavid Chisnall
65037a984708SDavid Chisnalltypedef regex_token_iterator<const char*>             cregex_token_iterator;
65047a984708SDavid Chisnalltypedef regex_token_iterator<const wchar_t*>          wcregex_token_iterator;
65057a984708SDavid Chisnalltypedef regex_token_iterator<string::const_iterator>  sregex_token_iterator;
65067a984708SDavid Chisnalltypedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator;
65077a984708SDavid Chisnall
65087a984708SDavid Chisnall// regex_replace
65097a984708SDavid Chisnall
65107a984708SDavid Chisnalltemplate <class _OutputIterator, class _BidirectionalIterator,
65117a984708SDavid Chisnall          class _Traits, class _CharT>
65127a984708SDavid Chisnall_OutputIterator
6513b2c7081bSDimitry Andricregex_replace(_OutputIterator __output_iter,
65147a984708SDavid Chisnall              _BidirectionalIterator __first, _BidirectionalIterator __last,
65157a984708SDavid Chisnall              const basic_regex<_CharT, _Traits>& __e, const _CharT* __fmt,
65167a984708SDavid Chisnall              regex_constants::match_flag_type __flags = regex_constants::match_default)
65177a984708SDavid Chisnall{
65187a984708SDavid Chisnall    typedef regex_iterator<_BidirectionalIterator, _CharT, _Traits> _Iter;
65197a984708SDavid Chisnall    _Iter __i(__first, __last, __e, __flags);
65207a984708SDavid Chisnall    _Iter __eof;
65217a984708SDavid Chisnall    if (__i == __eof)
65227a984708SDavid Chisnall    {
65237a984708SDavid Chisnall        if (!(__flags & regex_constants::format_no_copy))
6524b2c7081bSDimitry Andric            __output_iter = _VSTD::copy(__first, __last, __output_iter);
65257a984708SDavid Chisnall    }
65267a984708SDavid Chisnall    else
65277a984708SDavid Chisnall    {
65287a984708SDavid Chisnall        sub_match<_BidirectionalIterator> __lm;
65297a984708SDavid Chisnall        for (size_t __len = char_traits<_CharT>::length(__fmt); __i != __eof; ++__i)
65307a984708SDavid Chisnall        {
65317a984708SDavid Chisnall            if (!(__flags & regex_constants::format_no_copy))
6532b2c7081bSDimitry Andric                __output_iter = _VSTD::copy(__i->prefix().first, __i->prefix().second, __output_iter);
6533b2c7081bSDimitry Andric            __output_iter = __i->format(__output_iter, __fmt, __fmt + __len, __flags);
65347a984708SDavid Chisnall            __lm = __i->suffix();
65357a984708SDavid Chisnall            if (__flags & regex_constants::format_first_only)
65367a984708SDavid Chisnall                break;
65377a984708SDavid Chisnall        }
65387a984708SDavid Chisnall        if (!(__flags & regex_constants::format_no_copy))
6539b2c7081bSDimitry Andric            __output_iter = _VSTD::copy(__lm.first, __lm.second, __output_iter);
65407a984708SDavid Chisnall    }
6541b2c7081bSDimitry Andric    return __output_iter;
65427a984708SDavid Chisnall}
65437a984708SDavid Chisnall
65447a984708SDavid Chisnalltemplate <class _OutputIterator, class _BidirectionalIterator,
65457a984708SDavid Chisnall          class _Traits, class _CharT, class _ST, class _SA>
65467a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
65477a984708SDavid Chisnall_OutputIterator
6548b2c7081bSDimitry Andricregex_replace(_OutputIterator __output_iter,
65497a984708SDavid Chisnall              _BidirectionalIterator __first, _BidirectionalIterator __last,
65507a984708SDavid Chisnall              const basic_regex<_CharT, _Traits>& __e,
65517a984708SDavid Chisnall              const basic_string<_CharT, _ST, _SA>& __fmt,
65527a984708SDavid Chisnall              regex_constants::match_flag_type __flags = regex_constants::match_default)
65537a984708SDavid Chisnall{
6554b2c7081bSDimitry Andric    return _VSTD::regex_replace(__output_iter, __first, __last, __e, __fmt.c_str(), __flags);
65557a984708SDavid Chisnall}
65567a984708SDavid Chisnall
65577a984708SDavid Chisnalltemplate <class _Traits, class _CharT, class _ST, class _SA, class _FST,
65587a984708SDavid Chisnall          class _FSA>
65597a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
65607a984708SDavid Chisnallbasic_string<_CharT, _ST, _SA>
65617a984708SDavid Chisnallregex_replace(const basic_string<_CharT, _ST, _SA>& __s,
65627a984708SDavid Chisnall              const basic_regex<_CharT, _Traits>& __e,
65637a984708SDavid Chisnall              const basic_string<_CharT, _FST, _FSA>& __fmt,
65647a984708SDavid Chisnall              regex_constants::match_flag_type __flags = regex_constants::match_default)
65657a984708SDavid Chisnall{
65667a984708SDavid Chisnall    basic_string<_CharT, _ST, _SA> __r;
65677a984708SDavid Chisnall    _VSTD::regex_replace(back_inserter(__r), __s.begin(), __s.end(), __e,
65687a984708SDavid Chisnall                        __fmt.c_str(), __flags);
65697a984708SDavid Chisnall    return __r;
65707a984708SDavid Chisnall}
65717a984708SDavid Chisnall
65727a984708SDavid Chisnalltemplate <class _Traits, class _CharT, class _ST, class _SA>
65737a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
65747a984708SDavid Chisnallbasic_string<_CharT, _ST, _SA>
65757a984708SDavid Chisnallregex_replace(const basic_string<_CharT, _ST, _SA>& __s,
65767a984708SDavid Chisnall              const basic_regex<_CharT, _Traits>& __e, const _CharT* __fmt,
65777a984708SDavid Chisnall              regex_constants::match_flag_type __flags = regex_constants::match_default)
65787a984708SDavid Chisnall{
65797a984708SDavid Chisnall    basic_string<_CharT, _ST, _SA> __r;
65807a984708SDavid Chisnall    _VSTD::regex_replace(back_inserter(__r), __s.begin(), __s.end(), __e,
65817a984708SDavid Chisnall                        __fmt, __flags);
65827a984708SDavid Chisnall    return __r;
65837a984708SDavid Chisnall}
65847a984708SDavid Chisnall
65857a984708SDavid Chisnalltemplate <class _Traits, class _CharT, class _ST, class _SA>
65867a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
65877a984708SDavid Chisnallbasic_string<_CharT>
65887a984708SDavid Chisnallregex_replace(const _CharT* __s,
65897a984708SDavid Chisnall              const basic_regex<_CharT, _Traits>& __e,
65907a984708SDavid Chisnall              const basic_string<_CharT, _ST, _SA>& __fmt,
65917a984708SDavid Chisnall              regex_constants::match_flag_type __flags = regex_constants::match_default)
65927a984708SDavid Chisnall{
65937a984708SDavid Chisnall    basic_string<_CharT> __r;
65947a984708SDavid Chisnall    _VSTD::regex_replace(back_inserter(__r), __s,
65957a984708SDavid Chisnall                        __s + char_traits<_CharT>::length(__s), __e,
65967a984708SDavid Chisnall                        __fmt.c_str(), __flags);
65977a984708SDavid Chisnall    return __r;
65987a984708SDavid Chisnall}
65997a984708SDavid Chisnall
66007a984708SDavid Chisnalltemplate <class _Traits, class _CharT>
66017a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
66027a984708SDavid Chisnallbasic_string<_CharT>
66037a984708SDavid Chisnallregex_replace(const _CharT* __s,
66047a984708SDavid Chisnall              const basic_regex<_CharT, _Traits>& __e,
66057a984708SDavid Chisnall              const _CharT* __fmt,
66067a984708SDavid Chisnall              regex_constants::match_flag_type __flags = regex_constants::match_default)
66077a984708SDavid Chisnall{
66087a984708SDavid Chisnall    basic_string<_CharT> __r;
66097a984708SDavid Chisnall    _VSTD::regex_replace(back_inserter(__r), __s,
66107a984708SDavid Chisnall                        __s + char_traits<_CharT>::length(__s), __e,
66117a984708SDavid Chisnall                        __fmt, __flags);
66127a984708SDavid Chisnall    return __r;
66137a984708SDavid Chisnall}
66147a984708SDavid Chisnall
66157a984708SDavid Chisnall_LIBCPP_END_NAMESPACE_STD
66167a984708SDavid Chisnall
6617f9448bf3SDimitry Andric_LIBCPP_POP_MACROS
6618f9448bf3SDimitry Andric
66197a984708SDavid Chisnall#endif  // _LIBCPP_REGEX
6620