AK: Add optional parameter for excluding chars to urlencode()

This commit is contained in:
Linus Groh 2021-01-31 18:35:11 +01:00 committed by Andreas Kling
parent 1320b9351e
commit 50e3b122c7
2 changed files with 4 additions and 4 deletions

View file

@ -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 == '|';
}
String urlencode(const StringView& input)
String urlencode(const StringView& input, const StringView& exclude)
{
StringBuilder builder;
for (unsigned char ch : input) {
if (in_userinfo_set((u8)ch)) {
if (in_userinfo_set((u8)ch) && !exclude.contains(ch)) {
builder.append('%');
builder.appendff("{:02X}", ch);
} else {

View file

@ -26,11 +26,11 @@
#pragma once
#include <AK/Forward.h>
#include <AK/StringView.h>
namespace AK {
String urlencode(const StringView&);
String urlencode(const StringView&, const StringView& exclude = {});
String urldecode(const StringView&);
}