Share the query pair splitting between its two callers (#2526)

parse_query_text() and normalize_query_string() both walk a query string
and both open with the same eight lines to cut one "key=value" span at
its first '='. Give that a name and call it from both.

divide() puts everything before the first delimiter in the left half and
the rest in the right, so a span with no '=' lands entirely in key and
leaves val empty. Both callers rely on that: parse_query_text() records
a bare "flag" with an empty value, and normalize_query_string() emits it
back without an '='. The helper's comment says so, since that is the
part of divide()'s behaviour a reader has to know to follow either
caller.
This commit is contained in:
yhirose
2026-08-02 19:31:46 -04:00
committed by GitHub
parent 8d428361fb
commit c48ed1ed9a
+15 -12
View File
@@ -8291,6 +8291,19 @@ inline std::string params_to_query_str(const Params &params) {
return query;
}
// Splits one "key=value" span of a query string at its first '='. A span with
// no '=' at all lands entirely in key, leaving val empty, which is how a bare
// "?flag" keeps its name.
inline void divide_query_pair(const char *b, const char *e, std::string &key,
std::string &val) {
divide(b, static_cast<std::size_t>(e - b), '=',
[&](const char *lhs_data, std::size_t lhs_size, const char *rhs_data,
std::size_t rhs_size) {
key.assign(lhs_data, lhs_size);
val.assign(rhs_data, rhs_size);
});
}
inline void parse_query_text(const char *data, std::size_t size,
Params &params) {
std::set<std::string> cache;
@@ -8301,12 +8314,7 @@ inline void parse_query_text(const char *data, std::size_t size,
std::string key;
std::string val;
divide(b, static_cast<std::size_t>(e - b), '=',
[&](const char *lhs_data, std::size_t lhs_size, const char *rhs_data,
std::size_t rhs_size) {
key.assign(lhs_data, lhs_size);
val.assign(rhs_data, rhs_size);
});
divide_query_pair(b, e, key, val);
if (!key.empty()) {
params.emplace(decode_query_component(key), decode_query_component(val));
@@ -8331,12 +8339,7 @@ inline std::string normalize_query_string(const std::string &query) {
[&](const char *b, const char *e) {
std::string key;
std::string val;
divide(b, static_cast<std::size_t>(e - b), '=',
[&](const char *lhs_data, std::size_t lhs_size,
const char *rhs_data, std::size_t rhs_size) {
key.assign(lhs_data, lhs_size);
val.assign(rhs_data, rhs_size);
});
divide_query_pair(b, e, key, val);
if (!key.empty()) {
auto dec_key = decode_query_component(key);