From 570d722951a0f45585504465b24485bbae3a15c4 Mon Sep 17 00:00:00 2001 From: Daniel Lemire Date: Wed, 20 Mar 2024 08:40:10 -0400 Subject: [PATCH] improves slightly the style of url_search_params, makes to_string() const (credit to @the-moisrex for pointing out this issue). --- include/ada/url_search_params-inl.h | 8 ++++---- include/ada/url_search_params.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/ada/url_search_params-inl.h b/include/ada/url_search_params-inl.h index 776f30814..af3a06ea1 100644 --- a/include/ada/url_search_params-inl.h +++ b/include/ada/url_search_params-inl.h @@ -31,12 +31,12 @@ inline void url_search_params::initialize(std::string_view input) { auto equal = current.find('='); if (equal == std::string_view::npos) { - auto name = std::string(current); + std::string name(current); std::replace(name.begin(), name.end(), '+', ' '); params.emplace_back(unicode::percent_decode(name, name.find('%')), ""); } else { - auto name = std::string(current.substr(0, equal)); - auto value = std::string(current.substr(equal + 1)); + std::string name(current.substr(0, equal)); + std::string value(current.substr(equal + 1)); std::replace(name.begin(), name.end(), '+', ' '); std::replace(value.begin(), value.end(), '+', ' '); @@ -109,7 +109,7 @@ inline bool url_search_params::has(std::string_view key, return entry != params.end(); } -inline std::string url_search_params::to_string() { +inline std::string url_search_params::to_string() const { auto character_set = ada::character_sets::WWW_FORM_URLENCODED_PERCENT_ENCODE; std::string out{}; for (size_t i = 0; i < params.size(); i++) { diff --git a/include/ada/url_search_params.h b/include/ada/url_search_params.h index 8e48d3346..b9397ad40 100644 --- a/include/ada/url_search_params.h +++ b/include/ada/url_search_params.h @@ -92,7 +92,7 @@ struct url_search_params { /** * @see https://url.spec.whatwg.org/#urlsearchparams-stringification-behavior */ - inline std::string to_string(); + inline std::string to_string() const; /** * Returns a simple JS-style iterator over all of the keys in this