port_rule.hpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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_RFC_DETAIL_PORT_RULE_HPP
  10. #define BOOST_URL_RFC_DETAIL_PORT_RULE_HPP
  11. #include <boost/url/detail/config.hpp>
  12. #include <boost/url/error_types.hpp>
  13. #include <boost/core/detail/string_view.hpp>
  14. #include <cstdint>
  15. namespace boost {
  16. namespace urls {
  17. namespace detail {
  18. /** Rule for port
  19. @par BNF
  20. @code
  21. port = *DIGIT
  22. @endcode
  23. @par Specification
  24. @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2"
  25. >3.2.2. Host (rfc3986)</a>
  26. @see
  27. @ref port_part_rule.
  28. */
  29. struct port_rule
  30. {
  31. struct value_type
  32. {
  33. core::string_view str;
  34. std::uint16_t number = 0;
  35. bool has_number = false;
  36. };
  37. system::result<value_type>
  38. parse(
  39. char const*& it,
  40. char const* end) const noexcept;
  41. };
  42. //------------------------------------------------
  43. /** Rule for port-part
  44. @par BNF
  45. @code
  46. port-part = [ ":" port ]
  47. port = *DIGIT
  48. @endcode
  49. @par Specification
  50. @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2"
  51. >3.2.2. Host (rfc3986)</a>
  52. @see
  53. @ref port_rule.
  54. */
  55. struct port_part_rule_t
  56. {
  57. struct value_type
  58. {
  59. bool has_port = false;
  60. core::string_view port;
  61. bool has_number = false;
  62. std::uint16_t port_number = 0;
  63. };
  64. auto
  65. parse(
  66. char const*& it,
  67. char const* end
  68. ) const noexcept ->
  69. system::result<value_type>;
  70. };
  71. constexpr port_part_rule_t port_part_rule{};
  72. } // detail
  73. } // urls
  74. } // boost
  75. #endif