fragment_part_rule.hpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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_FRAGMENT_PART_RULE_HPP
  10. #define BOOST_URL_RFC_DETAIL_FRAGMENT_PART_RULE_HPP
  11. #include <boost/url/rfc/pct_encoded_rule.hpp>
  12. #include <boost/url/rfc/detail/charsets.hpp>
  13. #include <boost/url/grammar/parse.hpp>
  14. namespace boost {
  15. namespace urls {
  16. namespace detail {
  17. /** Rule for fragment-part
  18. @par BNF
  19. @code
  20. fragment-part = [ "#" fragment ]
  21. fragment = *( pchar / "/" / "?" )
  22. @endcode
  23. @par Specification
  24. @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.5"
  25. >3.5. Fragment (rfc3986)</a>
  26. */
  27. struct fragment_part_rule_t
  28. {
  29. struct value_type
  30. {
  31. pct_string_view fragment;
  32. bool has_fragment = false;
  33. };
  34. system::result<value_type>
  35. parse(
  36. char const*& it,
  37. char const* end
  38. ) const noexcept
  39. {
  40. if( it == end ||
  41. *it != '#')
  42. return {};
  43. ++it;
  44. auto rv = grammar::parse(
  45. it, end, pct_encoded_rule(
  46. fragment_chars));
  47. if(! rv)
  48. return rv.error();
  49. value_type t;
  50. t.fragment = *rv;
  51. t.has_fragment = true;
  52. return t;
  53. }
  54. };
  55. constexpr fragment_part_rule_t fragment_part_rule{};
  56. } // detail
  57. } // urls
  58. } // boost
  59. #endif