File indexing completed on 2025-01-18 09:53:48
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_ATTR_MATCHER_HPP_EAN_06_09_2007
0012 #define BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_ATTR_MATCHER_HPP_EAN_06_09_2007
0013
0014
0015 #if defined(_MSC_VER)
0016 # pragma once
0017 #endif
0018
0019 #include <boost/xpressive/detail/detail_fwd.hpp>
0020 #include <boost/xpressive/detail/core/quant_style.hpp>
0021 #include <boost/xpressive/detail/core/state.hpp>
0022 #include <boost/xpressive/detail/utility/symbols.hpp>
0023
0024 namespace boost { namespace xpressive { namespace detail
0025 {
0026
0027
0028
0029
0030 template<typename Traits, bool ICase>
0031 struct char_translate
0032 {
0033 typedef typename Traits::char_type char_type;
0034 Traits const &traits_;
0035
0036 explicit char_translate(Traits const &tr)
0037 : traits_(tr)
0038 {}
0039
0040 char_type operator ()(char_type ch1) const
0041 {
0042 return this->traits_.translate(ch1);
0043 }
0044 private:
0045 char_translate &operator =(char_translate const &);
0046 };
0047
0048
0049
0050
0051 template<typename Traits>
0052 struct char_translate<Traits, true>
0053 {
0054 typedef typename Traits::char_type char_type;
0055 Traits const &traits_;
0056
0057 explicit char_translate(Traits const &tr)
0058 : traits_(tr)
0059 {}
0060
0061 char_type operator ()(char_type ch1) const
0062 {
0063 return this->traits_.translate_nocase(ch1);
0064 }
0065 private:
0066 char_translate &operator =(char_translate const &);
0067 };
0068
0069
0070
0071
0072 template<typename Matcher, typename Traits, typename ICase>
0073 struct attr_matcher
0074 : quant_style<quant_none, 0, false>
0075 {
0076 typedef typename Matcher::value_type::second_type const* result_type;
0077
0078 attr_matcher(int slot, Matcher const &matcher, Traits const& tr)
0079 : slot_(slot-1)
0080 {
0081 char_translate<Traits, ICase::value> trans(tr);
0082 this->sym_.load(matcher, trans);
0083 }
0084
0085 template<typename BidiIter, typename Next>
0086 bool match(match_state<BidiIter> &state, Next const &next) const
0087 {
0088 BidiIter tmp = state.cur_;
0089 char_translate<Traits, ICase::value> trans(traits_cast<Traits>(state));
0090 result_type const &result = this->sym_(state.cur_, state.end_, trans);
0091 if(result)
0092 {
0093 void const *old_slot = state.attr_context_.attr_slots_[this->slot_];
0094 state.attr_context_.attr_slots_[this->slot_] = &*result;
0095 if(next.match(state))
0096 {
0097 return true;
0098 }
0099 state.attr_context_.attr_slots_[this->slot_] = old_slot;
0100 }
0101 state.cur_ = tmp;
0102 return false;
0103 }
0104
0105 int slot_;
0106 boost::xpressive::detail::symbols<Matcher> sym_;
0107 };
0108
0109 }}}
0110
0111 #endif