posix_charset_matcher.hpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // posix_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_POSIX_CHARSET_MATCHER_HPP_EAN_10_04_2005
  8. #define BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_POSIX_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/assert.hpp>
  14. #include <boost/mpl/bool.hpp>
  15. #include <boost/xpressive/detail/detail_fwd.hpp>
  16. #include <boost/xpressive/detail/core/quant_style.hpp>
  17. #include <boost/xpressive/detail/core/state.hpp>
  18. #include <boost/xpressive/detail/utility/traits_utils.hpp>
  19. namespace boost { namespace xpressive { namespace detail
  20. {
  21. ///////////////////////////////////////////////////////////////////////////////
  22. // posix_charset_matcher
  23. //
  24. template<typename Traits>
  25. struct posix_charset_matcher
  26. : quant_style_fixed_width<1>
  27. {
  28. typedef Traits traits_type;
  29. typedef typename Traits::char_class_type char_class_type;
  30. posix_charset_matcher(char_class_type m, bool no)
  31. : not_(no)
  32. , mask_(m)
  33. {
  34. BOOST_ASSERT(0 != this->mask_);
  35. }
  36. void inverse()
  37. {
  38. this->not_ = !this->not_;
  39. }
  40. template<typename BidiIter, typename Next>
  41. bool match(match_state<BidiIter> &state, Next const &next) const
  42. {
  43. if(state.eos() || this->not_ == traits_cast<Traits>(state).isctype(
  44. *state.cur_, this->mask_))
  45. {
  46. return false;
  47. }
  48. ++state.cur_;
  49. if(next.match(state))
  50. {
  51. return true;
  52. }
  53. --state.cur_;
  54. return false;
  55. }
  56. bool not_;
  57. char_class_type mask_;
  58. };
  59. }}}
  60. #endif