1*e4b17023SJohn Marino // class template regex -*- C++ -*- 2*e4b17023SJohn Marino 3*e4b17023SJohn Marino // Copyright (C) 2010, 2011 Free Software Foundation, Inc. 4*e4b17023SJohn Marino // 5*e4b17023SJohn Marino // This file is part of the GNU ISO C++ Library. This library is free 6*e4b17023SJohn Marino // software; you can redistribute it and/or modify it under the 7*e4b17023SJohn Marino // terms of the GNU General Public License as published by the 8*e4b17023SJohn Marino // Free Software Foundation; either version 3, or (at your option) 9*e4b17023SJohn Marino // any later version. 10*e4b17023SJohn Marino 11*e4b17023SJohn Marino // This library is distributed in the hope that it will be useful, 12*e4b17023SJohn Marino // but WITHOUT ANY WARRANTY; without even the implied warranty of 13*e4b17023SJohn Marino // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14*e4b17023SJohn Marino // GNU General Public License for more details. 15*e4b17023SJohn Marino 16*e4b17023SJohn Marino // Under Section 7 of GPL version 3, you are granted additional 17*e4b17023SJohn Marino // permissions described in the GCC Runtime Library Exception, version 18*e4b17023SJohn Marino // 3.1, as published by the Free Software Foundation. 19*e4b17023SJohn Marino 20*e4b17023SJohn Marino // You should have received a copy of the GNU General Public License and 21*e4b17023SJohn Marino // a copy of the GCC Runtime Library Exception along with this program; 22*e4b17023SJohn Marino // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 23*e4b17023SJohn Marino // <http://www.gnu.org/licenses/>. 24*e4b17023SJohn Marino 25*e4b17023SJohn Marino /** 26*e4b17023SJohn Marino * @file bits/regex_grep_matcher.h 27*e4b17023SJohn Marino * This is an internal header file, included by other library headers. 28*e4b17023SJohn Marino * Do not attempt to use it directly. @headername{regex} 29*e4b17023SJohn Marino */ 30*e4b17023SJohn Marino 31*e4b17023SJohn Marino namespace std _GLIBCXX_VISIBILITY(default) 32*e4b17023SJohn Marino { 33*e4b17023SJohn Marino _GLIBCXX_BEGIN_NAMESPACE_VERSION 34*e4b17023SJohn Marino 35*e4b17023SJohn Marino template<typename _BiIter> 36*e4b17023SJohn Marino class sub_match; 37*e4b17023SJohn Marino 38*e4b17023SJohn Marino template<typename _Bi_iter, typename _Allocator> 39*e4b17023SJohn Marino class match_results; 40*e4b17023SJohn Marino 41*e4b17023SJohn Marino _GLIBCXX_END_NAMESPACE_VERSION 42*e4b17023SJohn Marino 43*e4b17023SJohn Marino namespace __regex 44*e4b17023SJohn Marino { 45*e4b17023SJohn Marino _GLIBCXX_BEGIN_NAMESPACE_VERSION 46*e4b17023SJohn Marino 47*e4b17023SJohn Marino // A _Results facade specialized for wrapping a templated match_results. 48*e4b17023SJohn Marino template<typename _FwdIterT, typename _Alloc> 49*e4b17023SJohn Marino class _SpecializedResults 50*e4b17023SJohn Marino : public _Results 51*e4b17023SJohn Marino { 52*e4b17023SJohn Marino public: 53*e4b17023SJohn Marino _SpecializedResults(const _Automaton::_SizeT __size, 54*e4b17023SJohn Marino const _SpecializedCursor<_FwdIterT>& __cursor, 55*e4b17023SJohn Marino match_results<_FwdIterT, _Alloc>& __m); 56*e4b17023SJohn Marino 57*e4b17023SJohn Marino void 58*e4b17023SJohn Marino _M_set_pos(int __i, int __j, const _PatternCursor& __pc); 59*e4b17023SJohn Marino 60*e4b17023SJohn Marino void 61*e4b17023SJohn Marino _M_set_matched(int __i, bool __is_matched) 62*e4b17023SJohn Marino { _M_results.at(__i).matched = __is_matched; } 63*e4b17023SJohn Marino 64*e4b17023SJohn Marino private: 65*e4b17023SJohn Marino match_results<_FwdIterT, _Alloc>& _M_results; 66*e4b17023SJohn Marino }; 67*e4b17023SJohn Marino 68*e4b17023SJohn Marino template<typename _FwdIterT, typename _Alloc> 69*e4b17023SJohn Marino _SpecializedResults<_FwdIterT, _Alloc>:: 70*e4b17023SJohn Marino _SpecializedResults(const _Automaton::_SizeT __size, 71*e4b17023SJohn Marino const _SpecializedCursor<_FwdIterT>& __cursor, 72*e4b17023SJohn Marino match_results<_FwdIterT, _Alloc>& __m) 73*e4b17023SJohn Marino : _M_results(__m) 74*e4b17023SJohn Marino { 75*e4b17023SJohn Marino _M_results.clear(); 76*e4b17023SJohn Marino _M_results.reserve(__size + 2); 77*e4b17023SJohn Marino _M_results.resize(__size); 78*e4b17023SJohn Marino typename match_results<_FwdIterT, _Alloc>::value_type __sm; 79*e4b17023SJohn Marino __sm.first = __sm.second = __cursor._M_begin(); 80*e4b17023SJohn Marino _M_results.push_back(__sm); 81*e4b17023SJohn Marino __sm.first = __sm.second = __cursor._M_end(); 82*e4b17023SJohn Marino _M_results.push_back(__sm); 83*e4b17023SJohn Marino } 84*e4b17023SJohn Marino 85*e4b17023SJohn Marino template<typename _FwdIterT, typename _Alloc> 86*e4b17023SJohn Marino void 87*e4b17023SJohn Marino _SpecializedResults<_FwdIterT, _Alloc>:: 88*e4b17023SJohn Marino _M_set_pos(int __i, int __j, const _PatternCursor& __pc) 89*e4b17023SJohn Marino { 90*e4b17023SJohn Marino typedef const _SpecializedCursor<_FwdIterT>& _CursorT; 91*e4b17023SJohn Marino _CursorT __c = static_cast<_CursorT>(__pc); 92*e4b17023SJohn Marino if (__j == 0) 93*e4b17023SJohn Marino _M_results.at(__i).first = __c._M_pos(); 94*e4b17023SJohn Marino else 95*e4b17023SJohn Marino _M_results.at(__i).second = __c._M_pos()+1; 96*e4b17023SJohn Marino } 97*e4b17023SJohn Marino 98*e4b17023SJohn Marino // A stack of states used in evaluating the NFA. 99*e4b17023SJohn Marino typedef std::stack<_StateIdT, std::vector<_StateIdT> > _StateStack; 100*e4b17023SJohn Marino 101*e4b17023SJohn Marino // Executes a regular expression NFA/DFA over a range using a variant of 102*e4b17023SJohn Marino // the parallel execution algorithm featured in the grep utility, modified 103*e4b17023SJohn Marino // to use Laurikari tags. 104*e4b17023SJohn Marino class _Grep_matcher 105*e4b17023SJohn Marino { 106*e4b17023SJohn Marino public: 107*e4b17023SJohn Marino _Grep_matcher(_PatternCursor& __p, 108*e4b17023SJohn Marino _Results& __r, 109*e4b17023SJohn Marino const _AutomatonPtr& __automaton, 110*e4b17023SJohn Marino regex_constants::match_flag_type __flags); 111*e4b17023SJohn Marino 112*e4b17023SJohn Marino private: 113*e4b17023SJohn Marino _StateSet 114*e4b17023SJohn Marino _M_e_closure(_StateIdT __i); 115*e4b17023SJohn Marino 116*e4b17023SJohn Marino _StateSet 117*e4b17023SJohn Marino _M_e_closure(const _StateSet& __s); 118*e4b17023SJohn Marino 119*e4b17023SJohn Marino _StateSet 120*e4b17023SJohn Marino _M_e_closure(_StateStack& __stack, const _StateSet& __s); 121*e4b17023SJohn Marino 122*e4b17023SJohn Marino private: 123*e4b17023SJohn Marino const std::shared_ptr<_Nfa> _M_nfa; 124*e4b17023SJohn Marino _PatternCursor& _M_pattern; 125*e4b17023SJohn Marino _Results& _M_results; 126*e4b17023SJohn Marino }; 127*e4b17023SJohn Marino 128*e4b17023SJohn Marino _GLIBCXX_END_NAMESPACE_VERSION 129*e4b17023SJohn Marino } // namespace __regex 130*e4b17023SJohn Marino } // namespace 131*e4b17023SJohn Marino 132*e4b17023SJohn Marino #include <bits/regex_grep_matcher.tcc> 133