token_rule.hpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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/http_proto
  8. //
  9. #ifndef BOOST_URL_GRAMMAR_TOKEN_RULE_HPP
  10. #define BOOST_URL_GRAMMAR_TOKEN_RULE_HPP
  11. #include <boost/url/detail/config.hpp>
  12. #include <boost/url/grammar/charset.hpp>
  13. #include <boost/url/error_types.hpp>
  14. #include <boost/core/detail/string_view.hpp>
  15. namespace boost {
  16. namespace urls {
  17. namespace grammar {
  18. namespace implementation_defined {
  19. template<class CharSet>
  20. struct token_rule_t
  21. {
  22. using value_type = core::string_view;
  23. static_assert(
  24. is_charset<CharSet>::value,
  25. "CharSet requirements not met");
  26. auto
  27. parse(
  28. char const*& it,
  29. char const* end
  30. ) const noexcept ->
  31. system::result<value_type>;
  32. constexpr
  33. token_rule_t(
  34. CharSet const& cs) noexcept
  35. : cs_(cs)
  36. {
  37. }
  38. private:
  39. CharSet const cs_;
  40. };
  41. }
  42. /** Match a non-empty string of characters from a set
  43. If there is no more input, the error code
  44. @ref error::need_more is returned.
  45. @par Value Type
  46. @code
  47. using value_type = core::string_view;
  48. @endcode
  49. @par Example
  50. Rules are used with the function @ref parse.
  51. @code
  52. system::result< core::string_view > rv = parse( "abcdef", token_rule( alpha_chars ) );
  53. @endcode
  54. @par BNF
  55. @code
  56. token = 1*( ch )
  57. @endcode
  58. @param cs The character set to use
  59. @return The token rule
  60. @see
  61. @ref alpha_chars,
  62. @ref parse.
  63. */
  64. template<BOOST_URL_CONSTRAINT(CharSet) CS>
  65. constexpr
  66. auto
  67. token_rule(
  68. CS const& cs) noexcept ->
  69. implementation_defined::token_rule_t<CS>
  70. {
  71. return {cs};
  72. }
  73. } // grammar
  74. } // urls
  75. } // boost
  76. #include <boost/url/grammar/impl/token_rule.hpp>
  77. #endif