mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 07:07:34 +00:00
AK: Add optional parameter for excluding chars to urlencode()
This commit is contained in:
parent
1320b9351e
commit
50e3b122c7
2 changed files with 4 additions and 4 deletions
|
@ -90,11 +90,11 @@ static inline bool in_userinfo_set(u32 c)
|
||||||
return in_path_set(c) || c == '/' || c == ':' || c == ';' || c == '=' || c == '@' || (c >= '[' && c <= '^') || c == '|';
|
return in_path_set(c) || c == '/' || c == ':' || c == ';' || c == '=' || c == '@' || (c >= '[' && c <= '^') || c == '|';
|
||||||
}
|
}
|
||||||
|
|
||||||
String urlencode(const StringView& input)
|
String urlencode(const StringView& input, const StringView& exclude)
|
||||||
{
|
{
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
for (unsigned char ch : input) {
|
for (unsigned char ch : input) {
|
||||||
if (in_userinfo_set((u8)ch)) {
|
if (in_userinfo_set((u8)ch) && !exclude.contains(ch)) {
|
||||||
builder.append('%');
|
builder.append('%');
|
||||||
builder.appendff("{:02X}", ch);
|
builder.appendff("{:02X}", ch);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -26,11 +26,11 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AK/Forward.h>
|
#include <AK/StringView.h>
|
||||||
|
|
||||||
namespace AK {
|
namespace AK {
|
||||||
|
|
||||||
String urlencode(const StringView&);
|
String urlencode(const StringView&, const StringView& exclude = {});
|
||||||
String urldecode(const StringView&);
|
String urldecode(const StringView&);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue