mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 03:37:45 +00:00
AK: Update URLParser.{cpp,h} to use east const
This commit is contained in:
parent
0f8ed6183b
commit
44937e2dfc
2 changed files with 13 additions and 13 deletions
|
@ -22,12 +22,12 @@ constexpr bool is_url_code_point(u32 code_point)
|
||||||
return is_ascii_alphanumeric(code_point) || code_point >= 0xA0 || "!$&'()*+,-./:;=?@_~"sv.contains(code_point);
|
return is_ascii_alphanumeric(code_point) || code_point >= 0xA0 || "!$&'()*+,-./:;=?@_~"sv.contains(code_point);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void report_validation_error(const SourceLocation& location = SourceLocation::current())
|
static void report_validation_error(SourceLocation const& location = SourceLocation::current())
|
||||||
{
|
{
|
||||||
dbgln_if(URL_PARSER_DEBUG, "URLParser::parse: Validation error! {}", location);
|
dbgln_if(URL_PARSER_DEBUG, "URLParser::parse: Validation error! {}", location);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Optional<String> parse_opaque_host(const StringView& input)
|
static Optional<String> parse_opaque_host(StringView const& input)
|
||||||
{
|
{
|
||||||
auto forbidden_host_code_points_excluding_percent = "\0\t\n\r #/:<>?@[\\]^|"sv;
|
auto forbidden_host_code_points_excluding_percent = "\0\t\n\r #/:<>?@[\\]^|"sv;
|
||||||
for (auto code_point : forbidden_host_code_points_excluding_percent) {
|
for (auto code_point : forbidden_host_code_points_excluding_percent) {
|
||||||
|
@ -41,7 +41,7 @@ static Optional<String> parse_opaque_host(const StringView& input)
|
||||||
return URL::percent_encode(input, URL::PercentEncodeSet::C0Control);
|
return URL::percent_encode(input, URL::PercentEncodeSet::C0Control);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Optional<String> parse_ipv4_address(const StringView& input)
|
static Optional<String> parse_ipv4_address(StringView const& input)
|
||||||
{
|
{
|
||||||
// FIXME: Implement the correct IPv4 parser as specified by https://url.spec.whatwg.org/#concept-ipv4-parser.
|
// FIXME: Implement the correct IPv4 parser as specified by https://url.spec.whatwg.org/#concept-ipv4-parser.
|
||||||
return input;
|
return input;
|
||||||
|
@ -49,7 +49,7 @@ static Optional<String> parse_ipv4_address(const StringView& input)
|
||||||
|
|
||||||
// https://url.spec.whatwg.org/#concept-host-parser
|
// https://url.spec.whatwg.org/#concept-host-parser
|
||||||
// NOTE: This is a very bare-bones implementation.
|
// NOTE: This is a very bare-bones implementation.
|
||||||
static Optional<String> parse_host(const StringView& input, bool is_not_special = false)
|
static Optional<String> parse_host(StringView const& input, bool is_not_special = false)
|
||||||
{
|
{
|
||||||
if (input.starts_with('[')) {
|
if (input.starts_with('[')) {
|
||||||
if (!input.ends_with(']')) {
|
if (!input.ends_with(']')) {
|
||||||
|
@ -81,7 +81,7 @@ static Optional<String> parse_host(const StringView& input, bool is_not_special
|
||||||
return ipv4_host;
|
return ipv4_host;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr bool starts_with_windows_drive_letter(const StringView& input)
|
constexpr bool starts_with_windows_drive_letter(StringView const& input)
|
||||||
{
|
{
|
||||||
if (input.length() < 2)
|
if (input.length() < 2)
|
||||||
return false;
|
return false;
|
||||||
|
@ -92,29 +92,29 @@ constexpr bool starts_with_windows_drive_letter(const StringView& input)
|
||||||
return "/\\?#"sv.contains(input[2]);
|
return "/\\?#"sv.contains(input[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr bool is_windows_drive_letter(const StringView& input)
|
constexpr bool is_windows_drive_letter(StringView const& input)
|
||||||
{
|
{
|
||||||
return input.length() == 2 && is_ascii_alpha(input[0]) && (input[1] == ':' || input[1] == '|');
|
return input.length() == 2 && is_ascii_alpha(input[0]) && (input[1] == ':' || input[1] == '|');
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr bool is_normalized_windows_drive_letter(const StringView& input)
|
constexpr bool is_normalized_windows_drive_letter(StringView const& input)
|
||||||
{
|
{
|
||||||
return input.length() == 2 && is_ascii_alpha(input[0]) && input[1] == ':';
|
return input.length() == 2 && is_ascii_alpha(input[0]) && input[1] == ':';
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr bool is_single_dot_path_segment(const StringView& input)
|
constexpr bool is_single_dot_path_segment(StringView const& input)
|
||||||
{
|
{
|
||||||
return input == "."sv || input.equals_ignoring_case("%2e"sv);
|
return input == "."sv || input.equals_ignoring_case("%2e"sv);
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr bool is_double_dot_path_segment(const StringView& input)
|
constexpr bool is_double_dot_path_segment(StringView const& input)
|
||||||
{
|
{
|
||||||
return input == ".."sv || input.equals_ignoring_case(".%2e"sv) || input.equals_ignoring_case("%2e."sv) || input.equals_ignoring_case("%2e%2e"sv);
|
return input == ".."sv || input.equals_ignoring_case(".%2e"sv) || input.equals_ignoring_case("%2e."sv) || input.equals_ignoring_case("%2e%2e"sv);
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://fetch.spec.whatwg.org/#data-urls
|
// https://fetch.spec.whatwg.org/#data-urls
|
||||||
// FIXME: This only loosely follow the spec, as we use the same class for "regular" and data URLs, unlike the spec.
|
// FIXME: This only loosely follow the spec, as we use the same class for "regular" and data URLs, unlike the spec.
|
||||||
Optional<URL> URLParser::parse_data_url(const StringView& raw_input)
|
Optional<URL> URLParser::parse_data_url(StringView const& raw_input)
|
||||||
{
|
{
|
||||||
dbgln_if(URL_PARSER_DEBUG, "URLParser::parse_data_url: Parsing '{}'.", raw_input);
|
dbgln_if(URL_PARSER_DEBUG, "URLParser::parse_data_url: Parsing '{}'.", raw_input);
|
||||||
VERIFY(raw_input.starts_with("data:"));
|
VERIFY(raw_input.starts_with("data:"));
|
||||||
|
@ -154,7 +154,7 @@ Optional<URL> URLParser::parse_data_url(const StringView& raw_input)
|
||||||
// NOTE: Since the URL class's member variables contain percent decoded data, we have to deviate from the URL parser specification when setting
|
// NOTE: Since the URL class's member variables contain percent decoded data, we have to deviate from the URL parser specification when setting
|
||||||
// some of those values. Because the specification leaves all values percent encoded in their URL data structure, we have to percent decode
|
// some of those values. Because the specification leaves all values percent encoded in their URL data structure, we have to percent decode
|
||||||
// everything before setting the member variables.
|
// everything before setting the member variables.
|
||||||
URL URLParser::parse(Badge<URL>, const StringView& raw_input, URL const* base_url)
|
URL URLParser::parse(Badge<URL>, StringView const& raw_input, URL const* base_url)
|
||||||
{
|
{
|
||||||
dbgln_if(URL_PARSER_DEBUG, "URLParser::parse: Parsing '{}'", raw_input);
|
dbgln_if(URL_PARSER_DEBUG, "URLParser::parse: Parsing '{}'", raw_input);
|
||||||
if (raw_input.is_empty())
|
if (raw_input.is_empty())
|
||||||
|
|
|
@ -38,10 +38,10 @@ public:
|
||||||
Fragment
|
Fragment
|
||||||
};
|
};
|
||||||
|
|
||||||
static URL parse(Badge<URL>, const StringView& input, const URL* base_url = nullptr);
|
static URL parse(Badge<URL>, StringView const& input, URL const* base_url = nullptr);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static Optional<URL> parse_data_url(const StringView& raw_input);
|
static Optional<URL> parse_data_url(StringView const& raw_input);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue