charset_matcher.hpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // charset_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_CHARSET_MATCHER_HPP_EAN_10_04_2005
  8. #define BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_CHARSET_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. // charset_matcher
  20. //
  21. template<typename Traits, typename ICase, typename CharSet>
  22. struct charset_matcher
  23. : quant_style_fixed_width<1>
  24. {
  25. typedef typename Traits::char_type char_type;
  26. typedef Traits traits_type;
  27. typedef ICase icase_type;
  28. charset_matcher(CharSet const &charset = CharSet())
  29. : charset_(charset)
  30. {
  31. }
  32. void inverse()
  33. {
  34. this->charset_.inverse();
  35. }
  36. template<typename BidiIter, typename Next>
  37. bool match(match_state<BidiIter> &state, Next const &next) const
  38. {
  39. if(state.eos() || !this->charset_.test(*state.cur_, traits_cast<Traits>(state), icase_type()))
  40. {
  41. return false;
  42. }
  43. ++state.cur_;
  44. if(next.match(state))
  45. {
  46. return true;
  47. }
  48. --state.cur_;
  49. return false;
  50. }
  51. CharSet charset_;
  52. };
  53. }}}
  54. #endif