parse.hpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. //
  2. // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
  3. //
  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. // Official repository: https://github.com/boostorg/url
  8. //
  9. #ifndef BOOST_URL_GRAMMAR_IMPL_PARSE_HPP
  10. #define BOOST_URL_GRAMMAR_IMPL_PARSE_HPP
  11. #include <boost/url/grammar/error.hpp>
  12. #include <boost/url/grammar/type_traits.hpp>
  13. namespace boost {
  14. namespace urls {
  15. namespace grammar {
  16. template<class R>
  17. BOOST_URL_NO_INLINE
  18. auto
  19. parse(
  20. char const*& it,
  21. char const* end,
  22. R const& r) ->
  23. system::result<typename R::value_type>
  24. {
  25. // If this goes off, it means the rule
  26. // passed in did not meet the requirements.
  27. // Please check the documentation.
  28. static_assert(
  29. is_rule<R>::value,
  30. "Rule requirements not met");
  31. return r.parse(it, end);
  32. }
  33. template<class R>
  34. BOOST_URL_NO_INLINE
  35. auto
  36. parse(
  37. core::string_view s,
  38. R const& r) ->
  39. system::result<typename R::value_type>
  40. {
  41. // If this goes off, it means the rule
  42. // passed in did not meet the requirements.
  43. // Please check the documentation.
  44. static_assert(
  45. is_rule<R>::value,
  46. "Rule requirements not met");
  47. auto it = s.data();
  48. auto const end = it + s.size();
  49. auto rv = r.parse(it, end);
  50. if( rv &&
  51. it != end)
  52. return error::leftover;
  53. return rv;
  54. }
  55. } // grammar
  56. } // urls
  57. } // boost
  58. #endif