not_empty_rule.hpp 2.2 KB

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