diff options
| author | 2026-04-03 19:56:53 +0100 | |
|---|---|---|
| committer | 2026-04-03 19:56:53 +0100 | |
| commit | 7550deaa481d962244b6e509152ac90ab022434e (patch) | |
| tree | 899b74d258331111944a877d55fab046fa6f2971 /src/stringutils.cpp | |
| parent | Abolish SSLIOHookProvider now it doesn't do anything special. (diff) | |
Move query string code from spanningtree to stringutils.
Diffstat (limited to 'src/stringutils.cpp')
| -rw-r--r-- | src/stringutils.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/stringutils.cpp b/src/stringutils.cpp index 71ad8f396..120f8b465 100644 --- a/src/stringutils.cpp +++ b/src/stringutils.cpp @@ -24,6 +24,9 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#include <sstream> + #include <fmt/format.cc> #include "inspircd.h" @@ -61,6 +64,21 @@ std::string Percent::Encode(const void* data, size_t length, const char* table, return buffer; } +std::string Percent::EncodeQuery(const Percent::QueryData& data) +{ + std::stringstream buffer; + for (auto iter = data.begin(); iter != data.end(); ++iter) + { + if (iter != data.begin()) + buffer << '&'; + + buffer << iter->first; + if (!iter->second.empty()) + buffer << '=' << Percent::Encode(iter->second); + } + return buffer.str(); +} + std::string Percent::Decode(const void* data, size_t length) { // Preallocate the output buffer to avoid constant reallocations. @@ -91,6 +109,23 @@ std::string Percent::Decode(const void* data, size_t length) return buffer; } +Percent::QueryData Percent::DecodeQuery(const std::string_view& str) +{ + Percent::QueryData data; + + StringSplitter datastream(str, '&'); + for (std::string_view datapair; datastream.GetToken(datapair); ) + { + size_t split = datapair.find('='); + if (split == std::string::npos) + data.emplace(datapair, ""); + else + data.emplace(datapair.substr(0, split), Percent::Decode(datapair.substr(split + 1))); + } + + return data; +} + std::string Hex::Encode(const void* data, size_t length, const char* table, char separator) { if (!table) |
