assert_bol_matcher.hpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // assert_bol_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_ASSERT_BOL_MATCHER_HPP_EAN_10_04_2005
  8. #define BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_ASSERT_BOL_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/next_prior.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/core/matcher/assert_line_base.hpp>
  18. namespace boost { namespace xpressive { namespace detail
  19. {
  20. ///////////////////////////////////////////////////////////////////////////////
  21. // assert_bol_matcher
  22. //
  23. template<typename Traits>
  24. struct assert_bol_matcher
  25. : assert_line_base<Traits>
  26. {
  27. typedef typename Traits::char_type char_type;
  28. assert_bol_matcher(Traits const &tr)
  29. : assert_line_base<Traits>(tr)
  30. {
  31. }
  32. template<typename BidiIter, typename Next>
  33. bool match(match_state<BidiIter> &state, Next const &next) const
  34. {
  35. if(state.bos())
  36. {
  37. if(!state.flags_.match_bol_)
  38. {
  39. return false;
  40. }
  41. }
  42. else
  43. {
  44. char_type ch = *boost::prior(state.cur_);
  45. // If the previous character is not a newline, we're not at the start of a line
  46. if(!traits_cast<Traits>(state).isctype(ch, this->newline_))
  47. {
  48. return false;
  49. }
  50. // There is no line-break between \r and \n
  51. else if(ch == this->cr_ && !state.eos() && *state.cur_ == this->nl_)
  52. {
  53. return false;
  54. }
  55. }
  56. return next.match(state);
  57. }
  58. };
  59. }}}
  60. #endif