1 ///////////////////////////////////////////////////////////////////////////////
4 // Copyright 2008 Eric Niebler.
5 // Copyright 2008 David Jenkins.
7 // Distributed under the Boost Software License, Version 1.0. (See
8 // accompanying file LICENSE_1_0.txt or copy at
9 // http://www.boost.org/LICENSE_1_0.txt)
11 #ifndef BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_ATTR_MATCHER_HPP_EAN_06_09_2007
12 #define BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_ATTR_MATCHER_HPP_EAN_06_09_2007
14 // MS compatible compilers support #pragma once
19 #include <boost/xpressive/detail/detail_fwd.hpp>
20 #include <boost/xpressive/detail/core/quant_style.hpp>
21 #include <boost/xpressive/detail/core/state.hpp>
22 #include <boost/xpressive/detail/utility/symbols.hpp>
24 namespace boost { namespace xpressive { namespace detail
27 ///////////////////////////////////////////////////////////////////////////////
30 template<typename Traits, bool ICase>
33 typedef typename Traits::char_type char_type;
34 Traits const &traits_;
36 explicit char_translate(Traits const &tr)
40 char_type operator ()(char_type ch1) const
42 return this->traits_.translate(ch1);
45 char_translate &operator =(char_translate const &);
48 ///////////////////////////////////////////////////////////////////////////////
51 template<typename Traits>
52 struct char_translate<Traits, true>
54 typedef typename Traits::char_type char_type;
55 Traits const &traits_;
57 explicit char_translate(Traits const &tr)
61 char_type operator ()(char_type ch1) const
63 return this->traits_.translate_nocase(ch1);
66 char_translate &operator =(char_translate const &);
69 ///////////////////////////////////////////////////////////////////////////////
71 // Note: the Matcher is a std::map
72 template<typename Matcher, typename Traits, typename ICase>
74 : quant_style<quant_none, 0, false>
76 typedef typename Matcher::value_type::second_type const* result_type;
78 attr_matcher(int slot, Matcher const &matcher, Traits const& tr)
81 char_translate<Traits, ICase::value> trans(tr);
82 this->sym_.load(matcher, trans);
85 template<typename BidiIter, typename Next>
86 bool match(match_state<BidiIter> &state, Next const &next) const
88 BidiIter tmp = state.cur_;
89 char_translate<Traits, ICase::value> trans(traits_cast<Traits>(state));
90 result_type const &result = this->sym_(state.cur_, state.end_, trans);
93 void const *old_slot = state.attr_context_.attr_slots_[this->slot_];
94 state.attr_context_.attr_slots_[this->slot_] = &*result;
99 state.attr_context_.attr_slots_[this->slot_] = old_slot;
106 boost::xpressive::detail::symbols<Matcher> sym_;