1 // class template regex -*- C++ -*-
3 // Copyright (C) 2013-2014 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
26 * @file bits/regex_executor.h
27 * This is an internal header file, included by other library headers.
28 * Do not attempt to use it directly. @headername{regex}
31 // FIXME convert comments to doxygen format.
33 namespace std
_GLIBCXX_VISIBILITY(default)
35 _GLIBCXX_BEGIN_NAMESPACE_VERSION
36 template<typename
, typename
>
42 template<typename
, typename
>
44 _GLIBCXX_END_NAMESPACE_VERSION
48 _GLIBCXX_BEGIN_NAMESPACE_VERSION
51 * @addtogroup regex-detail
55 template<typename _BiIter
, typename _Alloc
, typename _TraitsT
,
60 typedef typename iterator_traits
<_BiIter
>::value_type _CharT
;
61 typedef basic_regex
<_CharT
, _TraitsT
> _RegexT
;
62 typedef std::vector
<sub_match
<_BiIter
>, _Alloc
> _ResultsVec
;
63 typedef regex_constants::match_flag_type _FlagT
;
64 typedef typename
_TraitsT::char_class_type _ClassT
;
65 typedef _NFA
<_TraitsT
> _NFAT
;
68 _Executor(_BiIter __begin
,
70 _ResultsVec
& __results
,
76 _M_nfa(*__re
._M_automaton
),
77 _M_results(__results
),
78 _M_match_queue(__dfs_mode
? nullptr
79 : new queue
<pair
<_StateIdT
, _ResultsVec
>>()),
80 _M_visited(__dfs_mode
? nullptr : new vector
<bool>(_M_nfa
.size())),
81 _M_flags((__flags
& regex_constants::match_prev_avail
)
83 & ~regex_constants::match_not_bol
84 & ~regex_constants::match_not_bow
)
86 _M_start_state(_M_nfa
._M_start())
89 // Set matched when string exactly match the pattern.
93 _M_current
= _M_begin
;
94 return _M_main
<true>();
97 // Set matched when some prefix of the string matches the pattern.
99 _M_search_from_first()
101 _M_current
= _M_begin
;
102 return _M_main
<false>();
109 template<bool __match_mode
>
111 _M_dfs(_StateIdT __start
);
113 template<bool __match_mode
>
118 _M_is_word(_CharT __ch
) const
120 static const _CharT __s
[2] = { 'w' };
121 return _M_re
._M_traits
.isctype
122 (__ch
, _M_re
._M_traits
.lookup_classname(__s
, __s
+1));
128 return _M_current
== _M_begin
129 && !(_M_flags
& (regex_constants::match_not_bol
130 | regex_constants::match_prev_avail
));
136 return _M_current
== _M_end
137 && !(_M_flags
& regex_constants::match_not_eol
);
141 _M_word_boundary(_State
<_TraitsT
> __state
) const;
144 _M_lookahead(_State
<_TraitsT
> __state
);
147 _ResultsVec _M_cur_results
;
149 const _BiIter _M_begin
;
150 const _BiIter _M_end
;
151 const _RegexT
& _M_re
;
153 _ResultsVec
& _M_results
;
154 // Used in BFS, saving states that need to be considered for the next
156 std::unique_ptr
<queue
<pair
<_StateIdT
, _ResultsVec
>>> _M_match_queue
;
157 // Used in BFS, indicating that which state is already visited.
158 std::unique_ptr
<vector
<bool>> _M_visited
;
160 // To record current solution.
161 _StateIdT _M_start_state
;
162 // Do we have a solution so far?
167 _GLIBCXX_END_NAMESPACE_VERSION
168 } // namespace __detail
171 #include <bits/regex_executor.tcc>