query_part_rule.hpp 1.5 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_QUERY_PART_RULE_HPP
  10. #define BOOST_URL_RFC_DETAIL_QUERY_PART_RULE_HPP
  11. #include <boost/url/detail/config.hpp>
  12. #include <boost/url/error_types.hpp>
  13. #include <boost/url/pct_string_view.hpp>
  14. #include <boost/url/rfc/query_rule.hpp>
  15. #include <boost/url/grammar/parse.hpp>
  16. #include <cstdlib>
  17. namespace boost {
  18. namespace urls {
  19. namespace detail {
  20. /** Rule for query-part
  21. @par BNF
  22. @code
  23. query-part = [ "?" query ]
  24. @endcode
  25. */
  26. struct query_part_rule_t
  27. {
  28. struct value_type
  29. {
  30. pct_string_view query;
  31. std::size_t count = 0;
  32. bool has_query = false;
  33. };
  34. auto
  35. parse(
  36. char const*& it,
  37. char const* end
  38. ) const noexcept ->
  39. system::result<value_type>
  40. {
  41. if( it == end ||
  42. *it != '?')
  43. return {};
  44. ++it;
  45. auto rv = grammar::parse(
  46. it, end, query_rule);
  47. if(! rv)
  48. return rv.error();
  49. value_type t;
  50. t.query = rv->buffer();
  51. t.count = rv->size();
  52. t.has_query = true;
  53. return t;
  54. }
  55. };
  56. constexpr query_part_rule_t query_part_rule{};
  57. } // detail
  58. } // urls
  59. } // boost
  60. #endif