not_empty_rule.hpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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_NOT_EMPTY_RULE_HPP
  10. #define BOOST_URL_GRAMMAR_NOT_EMPTY_RULE_HPP
  11. #include <boost/url/detail/config.hpp>
  12. #include <boost/url/error_types.hpp>
  13. #include <boost/url/grammar/type_traits.hpp>
  14. namespace boost {
  15. namespace urls {
  16. namespace grammar {
  17. namespace implementation_defined {
  18. template<class R>
  19. struct not_empty_rule_t
  20. {
  21. using value_type =
  22. typename R::value_type;
  23. auto
  24. parse(
  25. char const*& it,
  26. char const* end) const ->
  27. system::result<value_type>;
  28. constexpr
  29. not_empty_rule_t(
  30. R const& r) noexcept
  31. : r_(r)
  32. {
  33. }
  34. private:
  35. R r_;
  36. };
  37. } // implementation_defined
  38. /** Match another rule, if the result is not empty
  39. This adapts another rule such that
  40. when an empty string is successfully
  41. parsed, the result is an error.
  42. @par Value Type
  43. @code
  44. using value_type = typename Rule::value_type;
  45. @endcode
  46. @par Example
  47. Rules are used with the function @ref parse.
  48. @code
  49. system::result< decode_view > rv = parse( "Program%20Files",
  50. not_empty_rule( pct_encoded_rule( unreserved_chars ) ) );
  51. @endcode
  52. @param r The rule to match
  53. @return The adapted rule
  54. @see
  55. @ref parse,
  56. @ref pct_encoded_rule,
  57. @ref unreserved_chars.
  58. */
  59. template<BOOST_URL_CONSTRAINT(Rule) R>
  60. auto
  61. constexpr
  62. not_empty_rule(
  63. R const& r) ->
  64. implementation_defined::not_empty_rule_t<R>
  65. {
  66. // If you get a compile error here it
  67. // means that your rule does not meet
  68. // the type requirements. Please check
  69. // the documentation.
  70. static_assert(
  71. is_rule<R>::value,
  72. "Rule requirements not met");
  73. return { r };
  74. }
  75. } // grammar
  76. } // urls
  77. } // boost
  78. #include <boost/url/grammar/impl/not_empty_rule.hpp>
  79. #endif