eol.hpp 1.7 KB

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