not_empty_rule.hpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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_NOT_EMPTY_RULE_HPP
  10. #define BOOST_URL_GRAMMAR_IMPL_NOT_EMPTY_RULE_HPP
  11. #include <boost/url/grammar/error.hpp>
  12. #include <boost/url/grammar/parse.hpp>
  13. namespace boost {
  14. namespace urls {
  15. namespace grammar {
  16. template<class R>
  17. auto
  18. not_empty_rule_t<R>::
  19. parse(
  20. char const*& it,
  21. char const* end) const ->
  22. system::result<value_type>
  23. {
  24. if(it == end)
  25. {
  26. // empty
  27. BOOST_URL_RETURN_EC(
  28. error::mismatch);
  29. }
  30. auto const it0 = it;
  31. auto rv = r_.parse(it, end);
  32. if( !rv )
  33. {
  34. // error
  35. return rv;
  36. }
  37. if(it == it0)
  38. {
  39. // empty
  40. BOOST_URL_RETURN_EC(
  41. error::mismatch);
  42. }
  43. // value
  44. return rv;
  45. }
  46. } // grammar
  47. } // urls
  48. } // boost
  49. #endif