LibURL: Add helper for getting array of the special schemes

This is useful for iterating over all of the special schemes, as
needed in the URLPattern implementation.
This commit is contained in:
Shannon Booth 2025-03-18 19:22:16 +13:00 committed by Tim Flynn
commit 45d852d14b
Notes: github-actions[bot] 2025-04-06 12:27:44 +00:00
2 changed files with 16 additions and 1 deletions

View file

@ -207,9 +207,23 @@ URL create_with_data(StringView mime_type, StringView payload, bool is_base64)
}
// https://url.spec.whatwg.org/#special-scheme
ReadonlySpan<StringView> special_schemes()
{
static auto const schemes = to_array<StringView>({
"ftp"sv,
"file"sv,
"http"sv,
"https"sv,
"ws"sv,
"wss"sv,
});
return schemes;
}
// https://url.spec.whatwg.org/#is-special
bool is_special_scheme(StringView scheme)
{
return scheme.is_one_of("ftp", "file", "http", "https", "ws", "wss");
return special_schemes().contains_slow(scheme);
}
// https://url.spec.whatwg.org/#url-path-serializer

View file

@ -61,6 +61,7 @@ void append_percent_encoded_if_necessary(StringBuilder&, u32 code_point, Percent
void append_percent_encoded(StringBuilder&, u32 code_point);
bool code_point_is_in_percent_encode_set(u32 code_point, PercentEncodeSet);
Optional<u16> default_port_for_scheme(StringView);
ReadonlySpan<StringView> special_schemes();
bool is_special_scheme(StringView);
enum class SpaceAsPlus {