-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathurl_encoding.hpp
More file actions
31 lines (26 loc) · 809 Bytes
/
Copy pathurl_encoding.hpp
File metadata and controls
31 lines (26 loc) · 809 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#pragma once
#include <iomanip>
#include <sstream>
#include <string>
#include <string_view>
namespace acecode::utils {
inline std::string percent_encode_query_component(std::string_view raw) {
const auto is_unreserved = [](unsigned char ch) {
return (ch >= 'A' && ch <= 'Z') ||
(ch >= 'a' && ch <= 'z') ||
(ch >= '0' && ch <= '9') ||
ch == '-' || ch == '.' || ch == '_' || ch == '~';
};
std::ostringstream output;
output.fill('0');
output << std::hex << std::uppercase;
for (unsigned char ch : raw) {
if (is_unreserved(ch)) {
output << static_cast<char>(ch);
} else {
output << '%' << std::setw(2) << static_cast<int>(ch);
}
}
return output.str();
}
} // namespace acecode::utils