parse_query.ipp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. //
  2. // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
  3. // Copyright (c) 2022 Alan de Freitas (alandefreitas@gmail.com)
  4. //
  5. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  6. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. //
  8. // Official repository: https://github.com/CPPAlliance/url
  9. //
  10. #ifndef BOOST_URL_IMPL_PARSE_QUERY_IPP
  11. #define BOOST_URL_IMPL_PARSE_QUERY_IPP
  12. #include <boost/url/parse_query.hpp>
  13. #include <boost/url/rfc/query_rule.hpp>
  14. #include <boost/url/grammar/parse.hpp>
  15. #include <boost/url/error.hpp>
  16. namespace boost {
  17. namespace urls {
  18. result<params_encoded_view>
  19. parse_query(string_view s) noexcept
  20. {
  21. // Handle empty strings differently.
  22. // We produce {}, versus empty but
  23. // present query in URL (e.g. "http:?")
  24. // which produces {{"", none}}.
  25. if(s.empty())
  26. return params_encoded_view(
  27. detail::query_ref(
  28. s.data(), 0, 0));
  29. auto rv = grammar::parse(s, query_rule);
  30. if(! rv)
  31. return rv.error();
  32. return params_encoded_view(
  33. detail::query_ref(
  34. s.data(), s.size(), rv->size()));
  35. }
  36. } // urls
  37. } // boost
  38. #endif