Chris@16
|
1 ///////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
2 // assert_eol_matcher.hpp
|
Chris@16
|
3 //
|
Chris@16
|
4 // Copyright 2008 Eric Niebler. Distributed under the Boost
|
Chris@16
|
5 // Software License, Version 1.0. (See accompanying file
|
Chris@16
|
6 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
7
|
Chris@16
|
8 #ifndef BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_ASSERT_EOL_MATCHER_HPP_EAN_10_04_2005
|
Chris@16
|
9 #define BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_ASSERT_EOL_MATCHER_HPP_EAN_10_04_2005
|
Chris@16
|
10
|
Chris@16
|
11 // MS compatible compilers support #pragma once
|
Chris@101
|
12 #if defined(_MSC_VER)
|
Chris@16
|
13 # pragma once
|
Chris@16
|
14 #endif
|
Chris@16
|
15
|
Chris@16
|
16 #include <boost/next_prior.hpp>
|
Chris@16
|
17 #include <boost/xpressive/detail/detail_fwd.hpp>
|
Chris@16
|
18 #include <boost/xpressive/detail/core/quant_style.hpp>
|
Chris@16
|
19 #include <boost/xpressive/detail/core/state.hpp>
|
Chris@16
|
20 #include <boost/xpressive/detail/core/matcher/assert_line_base.hpp>
|
Chris@16
|
21
|
Chris@16
|
22 namespace boost { namespace xpressive { namespace detail
|
Chris@16
|
23 {
|
Chris@16
|
24
|
Chris@16
|
25 ///////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
26 // assert_eol_matcher
|
Chris@16
|
27 //
|
Chris@16
|
28 template<typename Traits>
|
Chris@16
|
29 struct assert_eol_matcher
|
Chris@16
|
30 : assert_line_base<Traits>
|
Chris@16
|
31 {
|
Chris@16
|
32 typedef typename Traits::char_type char_type;
|
Chris@16
|
33
|
Chris@16
|
34 assert_eol_matcher(Traits const &tr)
|
Chris@16
|
35 : assert_line_base<Traits>(tr)
|
Chris@16
|
36 {
|
Chris@16
|
37 }
|
Chris@16
|
38
|
Chris@16
|
39 template<typename BidiIter, typename Next>
|
Chris@16
|
40 bool match(match_state<BidiIter> &state, Next const &next) const
|
Chris@16
|
41 {
|
Chris@16
|
42 if(state.eos())
|
Chris@16
|
43 {
|
Chris@16
|
44 if(!state.flags_.match_eol_)
|
Chris@16
|
45 {
|
Chris@16
|
46 return false;
|
Chris@16
|
47 }
|
Chris@16
|
48 }
|
Chris@16
|
49 else
|
Chris@16
|
50 {
|
Chris@16
|
51 char_type ch = *state.cur_;
|
Chris@16
|
52
|
Chris@16
|
53 // If the current character is not a newline, we're not at the end of a line
|
Chris@16
|
54 if(!traits_cast<Traits>(state).isctype(ch, this->newline_))
|
Chris@16
|
55 {
|
Chris@16
|
56 return false;
|
Chris@16
|
57 }
|
Chris@16
|
58 // There is no line-break between \r and \n
|
Chris@16
|
59 else if(ch == this->nl_ && (!state.bos() || state.flags_.match_prev_avail_) && *boost::prior(state.cur_) == this->cr_)
|
Chris@16
|
60 {
|
Chris@16
|
61 return false;
|
Chris@16
|
62 }
|
Chris@16
|
63 }
|
Chris@16
|
64
|
Chris@16
|
65 return next.match(state);
|
Chris@16
|
66 }
|
Chris@16
|
67 };
|
Chris@16
|
68
|
Chris@16
|
69 }}}
|
Chris@16
|
70
|
Chris@16
|
71 #endif
|