literal_matcher.hpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // literal_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. #ifndef BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_LITERAL_MATCHER_HPP_EAN_10_04_2005
  8. #define BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_LITERAL_MATCHER_HPP_EAN_10_04_2005
  9. // MS compatible compilers support #pragma once
  10. #if defined(_MSC_VER)
  11. # pragma once
  12. #endif
  13. #include <boost/xpressive/detail/detail_fwd.hpp>
  14. #include <boost/xpressive/detail/core/quant_style.hpp>
  15. #include <boost/xpressive/detail/core/state.hpp>
  16. #include <boost/xpressive/detail/utility/traits_utils.hpp>
  17. namespace boost { namespace xpressive { namespace detail
  18. {
  19. ///////////////////////////////////////////////////////////////////////////////
  20. // literal_matcher
  21. //
  22. template<typename Traits, typename ICase, typename Not>
  23. struct literal_matcher
  24. : quant_style_fixed_width<1>
  25. {
  26. typedef typename Traits::char_type char_type;
  27. typedef Not not_type;
  28. typedef ICase icase_type;
  29. char_type ch_;
  30. explicit literal_matcher(char_type ch)
  31. : ch_(ch)
  32. {}
  33. literal_matcher(char_type ch, Traits const &tr)
  34. : ch_(detail::translate(ch, tr, icase_type()))
  35. {}
  36. template<typename BidiIter, typename Next>
  37. bool match(match_state<BidiIter> &state, Next const &next) const
  38. {
  39. if(state.eos() || Not::value ==
  40. (detail::translate(*state.cur_, traits_cast<Traits>(state), icase_type()) == this->ch_))
  41. {
  42. return false;
  43. }
  44. ++state.cur_;
  45. if(next.match(state))
  46. {
  47. return true;
  48. }
  49. --state.cur_;
  50. return false;
  51. }
  52. };
  53. }}}
  54. #endif