regex_matcher.hpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // regex_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_REGEX_MATCHER_HPP_EAN_10_04_2005
  8. #define BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_REGEX_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/mpl/assert.hpp>
  14. #include <boost/xpressive/regex_error.hpp>
  15. #include <boost/xpressive/regex_constants.hpp>
  16. #include <boost/xpressive/detail/core/regex_impl.hpp>
  17. #include <boost/xpressive/detail/detail_fwd.hpp>
  18. #include <boost/xpressive/detail/core/quant_style.hpp>
  19. #include <boost/xpressive/detail/core/state.hpp>
  20. #include <boost/xpressive/detail/core/adaptor.hpp>
  21. namespace boost { namespace xpressive { namespace detail
  22. {
  23. ///////////////////////////////////////////////////////////////////////////////
  24. // regex_matcher
  25. //
  26. template<typename BidiIter>
  27. struct regex_matcher
  28. : quant_style<quant_variable_width, unknown_width::value, false>
  29. {
  30. regex_impl<BidiIter> impl_;
  31. regex_matcher(shared_ptr<regex_impl<BidiIter> > const &impl)
  32. : impl_()
  33. {
  34. this->impl_.xpr_ = impl->xpr_;
  35. this->impl_.traits_ = impl->traits_;
  36. this->impl_.mark_count_ = impl->mark_count_;
  37. this->impl_.hidden_mark_count_ = impl->hidden_mark_count_;
  38. BOOST_XPR_ENSURE_(this->impl_.xpr_, regex_constants::error_badref, "bad regex reference");
  39. }
  40. template<typename Next>
  41. bool match(match_state<BidiIter> &state, Next const &next) const
  42. {
  43. // regex_matcher is used for embeding a dynamic regex in a static regex. As such,
  44. // Next will always point to a static regex.
  45. BOOST_MPL_ASSERT((is_static_xpression<Next>));
  46. // wrap the static xpression in a matchable interface
  47. xpression_adaptor<reference_wrapper<Next const>, matchable<BidiIter> > adaptor(boost::cref(next));
  48. return push_context_match(this->impl_, state, adaptor);
  49. }
  50. };
  51. }}}
  52. #endif