replacement_field_rule.hpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. //
  2. // Copyright (c) 2022 Alan de Freitas ([email protected])
  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_DETAIL_REPLACEMENT_FIELD_RULE_HPP
  10. #define BOOST_URL_DETAIL_REPLACEMENT_FIELD_RULE_HPP
  11. #include <boost/url/error.hpp>
  12. #include <boost/core/detail/string_view.hpp>
  13. #include <boost/url/grammar/variant_rule.hpp>
  14. #include <boost/url/grammar/unsigned_rule.hpp>
  15. namespace boost {
  16. namespace urls {
  17. namespace detail {
  18. // replacement_field ::= "{" [arg_id] [":" format_spec "}"
  19. struct replacement_field_rule_t
  20. {
  21. using value_type = core::string_view;
  22. BOOST_URL_DECL
  23. system::result<value_type>
  24. parse(
  25. char const*& it,
  26. char const* end) const noexcept;
  27. };
  28. constexpr replacement_field_rule_t replacement_field_rule{};
  29. // identifier ::= id_start id_continue*
  30. // id_start ::= "a"..."z" | "A"..."Z" | "_"
  31. // id_continue ::= id_start | digit
  32. struct identifier_rule_t
  33. {
  34. using value_type = core::string_view;
  35. BOOST_URL_DECL
  36. system::result<value_type>
  37. parse(
  38. char const*& it,
  39. char const* end) const noexcept;
  40. };
  41. constexpr identifier_rule_t identifier_rule{};
  42. // arg_id ::= integer | identifier
  43. // integer ::= digit+
  44. // digit ::= "0"..."9"
  45. static constexpr auto arg_id_rule =
  46. grammar::variant_rule(
  47. identifier_rule,
  48. grammar::unsigned_rule<std::size_t>{});
  49. struct format_spec_rule_t
  50. {
  51. using value_type = core::string_view;
  52. system::result<value_type>
  53. parse(
  54. char const*& it,
  55. char const* end) const noexcept;
  56. };
  57. constexpr format_spec_rule_t format_spec_rule{};
  58. } // detail
  59. } // urls
  60. } // boost
  61. #endif