1 /// Contains the definition of the basic_regex\<\> class template and its associated helper functions.
3 // Copyright 2008 Eric Niebler. Distributed under the Boost
4 // Software License, Version 1.0. (See accompanying file
5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 #ifndef BOOST_XPRESSIVE_DETAIL_CORE_FINDER_HPP_EAN_10_04_2005
8 #define BOOST_XPRESSIVE_DETAIL_CORE_FINDER_HPP_EAN_10_04_2005
10 // MS compatible compilers support #pragma once
13 # pragma warning(push)
14 # pragma warning(disable : 4189) // local variable is initialized but not referenced
17 #include <boost/xpressive/detail/detail_fwd.hpp>
18 #include <boost/xpressive/detail/core/regex_impl.hpp>
19 #include <boost/xpressive/detail/utility/boyer_moore.hpp>
20 #include <boost/xpressive/detail/utility/hash_peek_bitset.hpp>
22 namespace boost { namespace xpressive { namespace detail
25 ///////////////////////////////////////////////////////////////////////////////
28 template<typename BidiIter, typename Traits>
29 struct boyer_moore_finder
32 typedef typename iterator_value<BidiIter>::type char_type;
34 boyer_moore_finder(char_type const *begin, char_type const *end, Traits const &tr, bool icase)
35 : bm_(begin, end, tr, icase)
39 bool ok_for_partial_matches() const
44 bool operator ()(match_state<BidiIter> &state) const
46 Traits const &tr = traits_cast<Traits>(state);
47 state.cur_ = this->bm_.find(state.cur_, state.end_, tr);
48 return state.cur_ != state.end_;
52 boyer_moore_finder(boyer_moore_finder const &);
53 boyer_moore_finder &operator =(boyer_moore_finder const &);
55 boyer_moore<BidiIter, Traits> bm_;
58 ///////////////////////////////////////////////////////////////////////////////
61 template<typename BidiIter, typename Traits>
62 struct hash_peek_finder
65 typedef typename iterator_value<BidiIter>::type char_type;
67 hash_peek_finder(hash_peek_bitset<char_type> const &bset)
72 bool operator ()(match_state<BidiIter> &state) const
74 Traits const &tr = traits_cast<Traits>(state);
75 state.cur_ = (this->bset_.icase()
76 ? this->find_(state.cur_, state.end_, tr, mpl::true_())
77 : this->find_(state.cur_, state.end_, tr, mpl::false_()));
78 return state.cur_ != state.end_;
82 hash_peek_finder(hash_peek_finder const &);
83 hash_peek_finder &operator =(hash_peek_finder const &);
85 template<typename ICase>
86 BidiIter find_(BidiIter begin, BidiIter end, Traits const &tr, ICase) const
88 for(; begin != end && !this->bset_.test(*begin, tr, ICase()); ++begin)
93 hash_peek_bitset<char_type> bset_;
96 ///////////////////////////////////////////////////////////////////////////////
99 template<typename BidiIter, typename Traits, std::size_t Size = sizeof(typename iterator_value<BidiIter>::type)>
100 struct line_start_finder
103 typedef typename iterator_value<BidiIter>::type char_type;
104 typedef typename iterator_difference<BidiIter>::type diff_type;
105 typedef typename Traits::char_class_type char_class_type;
107 line_start_finder(Traits const &tr)
108 : newline_(lookup_classname(tr, "newline"))
112 bool operator ()(match_state<BidiIter> &state) const
114 if(state.bos() && state.flags_.match_bol_)
119 Traits const &tr = traits_cast<Traits>(state);
120 BidiIter cur = state.cur_;
121 BidiIter const end = state.end_;
122 std::advance(cur, static_cast<diff_type>(-!state.bos()));
124 for(; cur != end; ++cur)
126 if(tr.isctype(*cur, this->newline_))
137 line_start_finder(line_start_finder const &);
138 line_start_finder &operator =(line_start_finder const &);
140 char_class_type newline_;
143 ///////////////////////////////////////////////////////////////////////////////
146 template<typename BidiIter, typename Traits>
147 struct line_start_finder<BidiIter, Traits, 1u>
150 typedef typename iterator_value<BidiIter>::type char_type;
151 typedef typename iterator_difference<BidiIter>::type diff_type;
152 typedef typename Traits::char_class_type char_class_type;
154 line_start_finder(Traits const &tr)
156 char_class_type newline = lookup_classname(tr, "newline");
157 for(int j = 0; j < 256; ++j)
159 this->bits_[j] = tr.isctype(static_cast<char_type>(static_cast<unsigned char>(j)), newline);
163 bool operator ()(match_state<BidiIter> &state) const
165 if(state.bos() && state.flags_.match_bol_)
170 BidiIter cur = state.cur_;
171 BidiIter const end = state.end_;
172 std::advance(cur, static_cast<diff_type>(-!state.bos()));
174 for(; cur != end; ++cur)
176 if(this->bits_[static_cast<unsigned char>(*cur)])
187 line_start_finder(line_start_finder const &);
188 line_start_finder &operator =(line_start_finder const &);
193 ///////////////////////////////////////////////////////////////////////////////
194 // leading_simple_repeat_finder
196 template<typename BidiIter>
197 struct leading_simple_repeat_finder
200 leading_simple_repeat_finder()
204 bool operator ()(match_state<BidiIter> &state) const
206 state.cur_ = state.next_search_;
211 leading_simple_repeat_finder(leading_simple_repeat_finder const &);
212 leading_simple_repeat_finder &operator =(leading_simple_repeat_finder const &);
217 #if defined(_MSC_VER)
218 # pragma warning(pop)