1 ///////////////////////////////////////////////////////////////////////////////
2 // assert_word_matcher.hpp
4 // Copyright 2008 Eric Niebler. Distributed under the Boost
5 // Software License, Version 1.0. (See accompanying file
6 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8 #ifndef BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_ASSERT_WORD_MATCHER_HPP_EAN_10_04_2005
9 #define BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_ASSERT_WORD_MATCHER_HPP_EAN_10_04_2005
11 // MS compatible compilers support #pragma once
16 #include <boost/assert.hpp>
17 #include <boost/xpressive/detail/detail_fwd.hpp>
18 #include <boost/xpressive/detail/core/quant_style.hpp>
19 #include <boost/xpressive/detail/utility/ignore_unused.hpp>
20 #include <boost/xpressive/detail/core/state.hpp>
22 namespace boost { namespace xpressive { namespace detail
25 ///////////////////////////////////////////////////////////////////////////////
28 template<typename IsBoundary>
31 template<typename BidiIter>
32 static bool eval(bool prevword, bool thisword, match_state<BidiIter> &state)
34 if((state.flags_.match_not_bow_ && state.bos()) || (state.flags_.match_not_eow_ && state.eos()))
36 return !IsBoundary::value;
39 return IsBoundary::value == (prevword != thisword);
43 ///////////////////////////////////////////////////////////////////////////////
48 template<typename BidiIter>
49 static bool eval(bool prevword, bool thisword, match_state<BidiIter> &state)
51 if(state.flags_.match_not_bow_ && state.bos())
56 return !prevword && thisword;
60 ///////////////////////////////////////////////////////////////////////////////
65 template<typename BidiIter>
66 static bool eval(bool prevword, bool thisword, match_state<BidiIter> &state)
68 if(state.flags_.match_not_eow_ && state.eos())
73 return prevword && !thisword;
77 ///////////////////////////////////////////////////////////////////////////////
78 // assert_word_matcher
80 template<typename Cond, typename Traits>
81 struct assert_word_matcher
82 : quant_style_assertion
84 typedef typename Traits::char_type char_type;
85 typedef typename Traits::char_class_type char_class_type;
87 assert_word_matcher(Traits const &tr)
88 : word_(lookup_classname(tr, "w"))
90 BOOST_ASSERT(0 != this->word_);
93 assert_word_matcher(char_class_type word)
97 bool is_word(Traits const &tr, char_type ch) const
99 detail::ignore_unused(tr);
100 return tr.isctype(tr.translate(ch), this->word_);
103 template<typename BidiIter, typename Next>
104 bool match(match_state<BidiIter> &state, Next const &next) const
106 BidiIter cur = state.cur_;
107 bool const thisword = !state.eos() && this->is_word(traits_cast<Traits>(state), *cur);
108 bool const prevword = (!state.bos() || state.flags_.match_prev_avail_)
109 && this->is_word(traits_cast<Traits>(state), *--cur);
111 return Cond::eval(prevword, thisword, state) && next.match(state);
114 char_class_type word() const
120 char_class_type word_;