mark_end_matcher.hpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // mark_end_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_MARK_END_MATCHER_HPP_EAN_10_04_2005
  8. #define BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_MARK_END_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. namespace boost { namespace xpressive { namespace detail
  17. {
  18. ///////////////////////////////////////////////////////////////////////////////
  19. // mark_end_matcher
  20. //
  21. struct mark_end_matcher
  22. : quant_style<quant_none, 0, false>
  23. {
  24. int mark_number_;
  25. mark_end_matcher(int mark_number)
  26. : mark_number_(mark_number)
  27. {
  28. }
  29. template<typename BidiIter, typename Next>
  30. bool match(match_state<BidiIter> &state, Next const &next) const
  31. {
  32. sub_match_impl<BidiIter> &br = state.sub_match(this->mark_number_);
  33. BidiIter old_first = br.first;
  34. BidiIter old_second = br.second;
  35. bool old_matched = br.matched;
  36. br.first = br.begin_;
  37. br.second = state.cur_;
  38. br.matched = true;
  39. if(next.match(state))
  40. {
  41. return true;
  42. }
  43. br.first = old_first;
  44. br.second = old_second;
  45. br.matched = old_matched;
  46. return false;
  47. }
  48. };
  49. }}}
  50. #endif