1 /////////////////////////////////////////////////////////////////////////////// 2 // assert_eol_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 8 #ifndef BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_ASSERT_EOL_MATCHER_HPP_EAN_10_04_2005 9 #define BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_ASSERT_EOL_MATCHER_HPP_EAN_10_04_2005 10 11 // MS compatible compilers support #pragma once 12 #if defined(_MSC_VER) 13 # pragma once 14 #endif 15 16 #include <boost/next_prior.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/matcher/assert_line_base.hpp> 21 22 namespace boost { namespace xpressive { namespace detail 23 { 24 25 /////////////////////////////////////////////////////////////////////////////// 26 // assert_eol_matcher 27 // 28 template<typename Traits> 29 struct assert_eol_matcher 30 : assert_line_base<Traits> 31 { 32 typedef typename Traits::char_type char_type; 33 assert_eol_matcherboost::xpressive::detail::assert_eol_matcher34 assert_eol_matcher(Traits const &tr) 35 : assert_line_base<Traits>(tr) 36 { 37 } 38 39 template<typename BidiIter, typename Next> matchboost::xpressive::detail::assert_eol_matcher40 bool match(match_state<BidiIter> &state, Next const &next) const 41 { 42 if(state.eos()) 43 { 44 if(!state.flags_.match_eol_) 45 { 46 return false; 47 } 48 } 49 else 50 { 51 char_type ch = *state.cur_; 52 53 // If the current character is not a newline, we're not at the end of a line 54 if(!traits_cast<Traits>(state).isctype(ch, this->newline_)) 55 { 56 return false; 57 } 58 // There is no line-break between \r and \n 59 else if(ch == this->nl_ && (!state.bos() || state.flags_.match_prev_avail_) && *boost::prior(state.cur_) == this->cr_) 60 { 61 return false; 62 } 63 } 64 65 return next.match(state); 66 } 67 }; 68 69 }}} 70 71 #endif 72