/Src/Dependencies/Boost/boost/xpressive/detail/core/matcher/mark_matcher.hpp

http://hadesmem.googlecode.com/ · C++ Header · 78 lines · 52 code · 14 blank · 12 comment · 8 complexity · a9a4124a6ff0761f120e748d4d1f9100 MD5 · raw file

  1. ///////////////////////////////////////////////////////////////////////////////
  2. // mark_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_MATCHER_HPP_EAN_10_04_2005
  8. #define BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_MARK_MATCHER_HPP_EAN_10_04_2005
  9. // MS compatible compilers support #pragma once
  10. #if defined(_MSC_VER) && (_MSC_VER >= 1020)
  11. # pragma once
  12. #endif
  13. #include <boost/assert.hpp>
  14. #include <boost/xpressive/detail/detail_fwd.hpp>
  15. #include <boost/xpressive/detail/core/quant_style.hpp>
  16. #include <boost/xpressive/detail/core/state.hpp>
  17. #include <boost/xpressive/detail/utility/traits_utils.hpp>
  18. namespace boost { namespace xpressive { namespace detail
  19. {
  20. // TODO: the mark matcher is acually a fixed-width matcher, but the width is
  21. // not known until pattern match time.
  22. ///////////////////////////////////////////////////////////////////////////////
  23. // mark_matcher
  24. //
  25. template<typename Traits, typename ICase>
  26. struct mark_matcher
  27. : quant_style_variable_width
  28. {
  29. typedef ICase icase_type;
  30. int mark_number_;
  31. mark_matcher(int mark_number, Traits const &)
  32. : mark_number_(mark_number)
  33. {
  34. }
  35. template<typename BidiIter, typename Next>
  36. bool match(match_state<BidiIter> &state, Next const &next) const
  37. {
  38. BOOST_ASSERT(this->mark_number_ < static_cast<int>(state.mark_count_));
  39. sub_match_impl<BidiIter> const &br = state.sub_match(this->mark_number_);
  40. if(!br.matched)
  41. {
  42. return false;
  43. }
  44. BidiIter const tmp = state.cur_;
  45. for(BidiIter begin = br.first, end = br.second; begin != end; ++begin, ++state.cur_)
  46. {
  47. if(state.eos()
  48. || detail::translate(*state.cur_, traits_cast<Traits>(state), icase_type())
  49. != detail::translate(*begin, traits_cast<Traits>(state), icase_type()))
  50. {
  51. state.cur_ = tmp;
  52. return false;
  53. }
  54. }
  55. if(next.match(state))
  56. {
  57. return true;
  58. }
  59. state.cur_ = tmp;
  60. return false;
  61. }
  62. };
  63. }}}
  64. #endif