optional_rule.hpp 879 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  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_OPTIONAL_RULE_HPP
  10. #define BOOST_URL_GRAMMAR_IMPL_OPTIONAL_RULE_HPP
  11. #include <boost/url/grammar/error.hpp>
  12. namespace boost {
  13. namespace urls {
  14. namespace grammar {
  15. template<class R>
  16. auto
  17. optional_rule_t<R>::
  18. parse(
  19. char const*& it,
  20. char const* end) const ->
  21. system::result<value_type>
  22. {
  23. if(it == end)
  24. return boost::none;
  25. auto const it0 = it;
  26. auto rv =
  27. this->get().parse(it, end);
  28. if(rv)
  29. return value_type(*rv);
  30. it = it0;
  31. return boost::none;
  32. }
  33. } // grammar
  34. } // urls
  35. } // boost
  36. #endif