Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:53:48

0001 ///////////////////////////////////////////////////////////////////////////////
0002 // assert_bol_matcher.hpp
0003 //
0004 //  Copyright 2008 Eric Niebler. Distributed under the Boost
0005 //  Software License, Version 1.0. (See accompanying file
0006 //  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0007 
0008 #ifndef BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_ASSERT_BOL_MATCHER_HPP_EAN_10_04_2005
0009 #define BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_ASSERT_BOL_MATCHER_HPP_EAN_10_04_2005
0010 
0011 // MS compatible compilers support #pragma once
0012 #if defined(_MSC_VER)
0013 # pragma once
0014 #endif
0015 
0016 #include <boost/next_prior.hpp>
0017 #include <boost/xpressive/detail/detail_fwd.hpp>
0018 #include <boost/xpressive/detail/core/quant_style.hpp>
0019 #include <boost/xpressive/detail/core/state.hpp>
0020 #include <boost/xpressive/detail/core/matcher/assert_line_base.hpp>
0021 
0022 namespace boost { namespace xpressive { namespace detail
0023 {
0024 
0025     ///////////////////////////////////////////////////////////////////////////////
0026     // assert_bol_matcher
0027     //
0028     template<typename Traits>
0029     struct assert_bol_matcher
0030       : assert_line_base<Traits>
0031     {
0032         typedef typename Traits::char_type char_type;
0033 
0034         assert_bol_matcher(Traits const &tr)
0035           : assert_line_base<Traits>(tr)
0036         {
0037         }
0038 
0039         template<typename BidiIter, typename Next>
0040         bool match(match_state<BidiIter> &state, Next const &next) const
0041         {
0042             if(state.bos())
0043             {
0044                 if(!state.flags_.match_bol_)
0045                 {
0046                     return false;
0047                 }
0048             }
0049             else
0050             {
0051                 char_type ch = *boost::prior(state.cur_);
0052 
0053                 // If the previous character is not a newline, we're not at the start of a line
0054                 if(!traits_cast<Traits>(state).isctype(ch, this->newline_))
0055                 {
0056                     return false;
0057                 }
0058                 // There is no line-break between \r and \n
0059                 else if(ch == this->cr_ && !state.eos() && *state.cur_ == this->nl_)
0060                 {
0061                     return false;
0062                 }
0063             }
0064 
0065             return next.match(state);
0066         }
0067     };
0068 
0069 }}}
0070 
0071 #endif