1 /*=============================================================================
2     Copyright (c) 2001-2014 Joel de Guzman
3     Copyright (c) 2001-2011 Hartmut Kaiser
4 
5     Distributed under the Boost Software License, Version 1.0. (See accompanying
6     file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 ==============================================================================*/
8 #if !defined(BOOST_SPIRIT_X3_EOL_MARCH_23_2007_0454PM)
9 #define BOOST_SPIRIT_X3_EOL_MARCH_23_2007_0454PM
10 
11 #include <boost/spirit/home/x3/core/skip_over.hpp>
12 #include <boost/spirit/home/x3/core/parser.hpp>
13 #include <boost/spirit/home/x3/support/unused.hpp>
14 
15 namespace boost { namespace spirit { namespace x3
16 {
17     struct eol_parser : parser<eol_parser>
18     {
19         typedef unused_type attribute_type;
20         static bool const has_attribute = false;
21 
22         template <typename Iterator, typename Context, typename Attribute>
parseboost::spirit::x3::eol_parser23         bool parse(Iterator& first, Iterator const& last
24          , Context const& context, unused_type, Attribute& /*attr*/) const
25         {
26             x3::skip_over(first, last, context);
27             Iterator iter = first;
28             bool matched = false;
29             if (iter != last && *iter == '\r')  // CR
30             {
31                 matched = true;
32                 ++iter;
33             }
34             if (iter != last && *iter == '\n')  // LF
35             {
36                 matched = true;
37                 ++iter;
38             }
39 
40             if (matched) first = iter;
41             return matched;
42         }
43     };
44 
45     template<>
46     struct get_info<eol_parser>
47     {
48         typedef std::string result_type;
operator ()boost::spirit::x3::get_info49         result_type operator()(eol_parser const &) const { return "eol"; }
50     };
51 
52     auto const eol = eol_parser{};
53 }}}
54 
55 #endif
56