not_empty_rule.hpp 1.1 KB

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