1 /////////////////////////////////////////////////////////////////////////////// 2 // charset_matcher.hpp 3 // 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) 7 8 #ifndef BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_CHARSET_MATCHER_HPP_EAN_10_04_2005 9 #define BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_CHARSET_MATCHER_HPP_EAN_10_04_2005 10 11 // MS compatible compilers support #pragma once 12 #if defined(_MSC_VER) 13 # pragma once 14 #endif 15 16 #include <boost/xpressive/detail/detail_fwd.hpp> 17 #include <boost/xpressive/detail/core/quant_style.hpp> 18 #include <boost/xpressive/detail/core/state.hpp> 19 20 namespace boost { namespace xpressive { namespace detail 21 { 22 23 /////////////////////////////////////////////////////////////////////////////// 24 // charset_matcher 25 // 26 template<typename Traits, typename ICase, typename CharSet> 27 struct charset_matcher 28 : quant_style_fixed_width<1> 29 { 30 typedef typename Traits::char_type char_type; 31 typedef Traits traits_type; 32 typedef ICase icase_type; 33 charset_matcherboost::xpressive::detail::charset_matcher34 charset_matcher(CharSet const &charset = CharSet()) 35 : charset_(charset) 36 { 37 } 38 inverseboost::xpressive::detail::charset_matcher39 void inverse() 40 { 41 this->charset_.inverse(); 42 } 43 44 template<typename BidiIter, typename Next> matchboost::xpressive::detail::charset_matcher45 bool match(match_state<BidiIter> &state, Next const &next) const 46 { 47 if(state.eos() || !this->charset_.test(*state.cur_, traits_cast<Traits>(state), icase_type())) 48 { 49 return false; 50 } 51 52 ++state.cur_; 53 if(next.match(state)) 54 { 55 return true; 56 } 57 58 --state.cur_; 59 return false; 60 } 61 62 CharSet charset_; 63 }; 64 65 }}} 66 67 #endif 68