PageRenderTime 12ms CodeModel.GetById 7ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/Src/Dependencies/Boost/boost/xpressive/detail/core/matcher/assert_eol_matcher.hpp

http://hadesmem.googlecode.com/
C++ Header | 71 lines | 48 code | 11 blank | 12 comment | 11 complexity | f2caa61012dd8a12602d67f95d82df1d MD5 | raw file
 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) && (_MSC_VER >= 1020)
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
22namespace 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        
34        assert_eol_matcher(Traits const &tr)
35          : assert_line_base<Traits>(tr)
36        {
37        }
38
39        template<typename BidiIter, typename Next>
40        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