diff --git a/uri.cpp b/uri.cpp index c52c5b13..43fc4a50 100644 --- a/uri.cpp +++ b/uri.cpp @@ -211,14 +211,14 @@ void uri::clear_fragment () /////////////////////////////////////////////////////////////////////////////// -std::map -cruft::query_to_map (std::string_view val) +std::vector> +cruft::query_to_vector (std::string_view val) { - std::map res; + std::vector> res; for (auto const tok: cruft::tokeniser (val, '&')) { auto const &[k, v] = cruft::split_on (tok, '='); - res.emplace ( + res.emplace_back ( std::string (k.begin (), k.size ()), std::string (v.begin (), v.size ()) ); @@ -230,7 +230,7 @@ cruft::query_to_map (std::string_view val) //----------------------------------------------------------------------------- std::string -cruft::map_to_query (std::map const &val) +cruft::vector_to_query (std::vector> const &val) { // Test for empty up front so that we can simplify the string // concatenation below. diff --git a/uri.hpp b/uri.hpp index 83ee9769..c84a1b2f 100644 --- a/uri.hpp +++ b/uri.hpp @@ -114,8 +114,18 @@ namespace cruft { std::string m_value; }; - std::map query_to_map (std::string_view); - std::string map_to_query (std::map const&); + /// Break a query string into a sequence of key-value pairs. + /// Duplicates are possible. + /// vector is used to that order can be preserved + /// The is the inverse of vector_to_query + std::vector> + query_to_vector (std::string_view); + + /// Convert a sequence of key-value pairs into a query string + /// All pairs, including duplicates, are serialised in the provided order. + /// This is the inverse of query_to_vector + std::string + vector_to_query (std::vector> const&); bool operator== (uri const&, uri const&) noexcept;