mark_begin_matcher.hpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // mark_begin_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_BEGIN_MATCHER_HPP_EAN_10_04_2005
  8. #define BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_MARK_BEGIN_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_begin_matcher
  20. //
  21. struct mark_begin_matcher
  22. : quant_style<quant_fixed_width, 0, false>
  23. {
  24. int mark_number_; // signed because it could be negative
  25. mark_begin_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_begin = br.begin_;
  34. br.begin_ = state.cur_;
  35. if(next.match(state))
  36. {
  37. return true;
  38. }
  39. br.begin_ = old_begin;
  40. return false;
  41. }
  42. };
  43. }}}
  44. #endif