#include "core/UrlCodec.hpp" namespace dp { std::string UrlCodec::encode(const std::string& text) { static const char* hex = "0123456789ABCDEF"; std::string out; out.reserve(text.size()); for (unsigned char c : text) { const bool keep = (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '-' || c == '.' || c == '_' || c == '~'; if (keep) { out.push_back(static_cast(c)); } else { out.push_back('%'); out.push_back(hex[c >> 4]); out.push_back(hex[c & 15]); } } return out; } std::string UrlCodec::buildQuery(const std::vector>& params) { std::string out; for (const auto& [k, v] : params) { if (!out.empty()) out.push_back('&'); out += encode(k) + "=" + encode(v); } return out; } std::string UrlCodec::toWebSocketScheme(const std::string& url) { if (url.rfind("https://", 0) == 0) return "wss://" + url.substr(8); if (url.rfind("http://", 0) == 0) return "ws://" + url.substr(7); return url; } } // namespace dp