• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
8 #ifndef BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_ASSERT_BOL_MATCHER_HPP_EAN_10_04_2005
9 #define BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_ASSERT_BOL_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_bol_matcher
27     //
28     template<typename Traits>
29     struct assert_bol_matcher
30       : assert_line_base<Traits>
31     {
32         typedef typename Traits::char_type char_type;
33 
assert_bol_matcherboost::xpressive::detail::assert_bol_matcher34         assert_bol_matcher(Traits const &tr)
35           : assert_line_base<Traits>(tr)
36         {
37         }
38 
39         template<typename BidiIter, typename Next>
matchboost::xpressive::detail::assert_bol_matcher40         bool match(match_state<BidiIter> &state, Next const &next) const
41         {
42             if(state.bos())
43             {
44                 if(!state.flags_.match_bol_)
45                 {
46                     return false;
47                 }
48             }
49             else
50             {
51                 char_type ch = *boost::prior(state.cur_);
52 
53                 // If the previous character is not a newline, we're not at the start 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->cr_ && !state.eos() && *state.cur_ == this->nl_)
60                 {
61                     return false;
62                 }
63             }
64 
65             return next.match(state);
66         }
67     };
68 
69 }}}
70 
71 #endif
72