Skip to content

Commit

Permalink
improves slightly the style of url_search_params, makes to_string() c…
Browse files Browse the repository at this point in the history
…onst (credit to @the-moisrex for pointing out this issue).
  • Loading branch information
lemire committed Mar 20, 2024
1 parent 0170547 commit 570d722
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions include/ada/url_search_params-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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(), '+', ' ');
Expand Down Expand Up @@ -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++) {
Expand Down
2 changes: 1 addition & 1 deletion include/ada/url_search_params.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

This comment has been minimized.

Copy link
@the-moisrex

the-moisrex Mar 20, 2024

Contributor

This is used here as well:
image


/**
* Returns a simple JS-style iterator over all of the keys in this
Expand Down

0 comments on commit 570d722

Please sign in to comment.