mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:07:35 +00:00
AK: URL should support file:// URL's
Also add some setters since this class was very setter-less.
This commit is contained in:
parent
4f47146433
commit
d64c054d25
2 changed files with 14 additions and 4 deletions
13
AK/URL.cpp
13
AK/URL.cpp
|
@ -61,7 +61,10 @@ bool URL::parse(const StringView& string)
|
||||||
return false;
|
return false;
|
||||||
m_protocol = String::copy(buffer);
|
m_protocol = String::copy(buffer);
|
||||||
buffer.clear();
|
buffer.clear();
|
||||||
state = State::InHostname;
|
if (m_protocol == "file")
|
||||||
|
state = State::InPath;
|
||||||
|
else
|
||||||
|
state = State::InHostname;
|
||||||
continue;
|
continue;
|
||||||
case State::InHostname:
|
case State::InHostname:
|
||||||
if (is_valid_hostname_character(peek())) {
|
if (is_valid_hostname_character(peek())) {
|
||||||
|
@ -120,9 +123,11 @@ String URL::to_string() const
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
builder.append(m_protocol);
|
builder.append(m_protocol);
|
||||||
builder.append("://");
|
builder.append("://");
|
||||||
builder.append(m_host);
|
if (protocol() != "file") {
|
||||||
builder.append(':');
|
builder.append(m_host);
|
||||||
builder.append(String::number(m_port));
|
builder.append(':');
|
||||||
|
builder.append(String::number(m_port));
|
||||||
|
}
|
||||||
builder.append(m_path);
|
builder.append(m_path);
|
||||||
return builder.to_string();
|
return builder.to_string();
|
||||||
}
|
}
|
||||||
|
|
5
AK/URL.h
5
AK/URL.h
|
@ -24,6 +24,11 @@ public:
|
||||||
String path() const { return m_path; }
|
String path() const { return m_path; }
|
||||||
u16 port() const { return m_port; }
|
u16 port() const { return m_port; }
|
||||||
|
|
||||||
|
void set_protocol(const String& protocol) { m_protocol = protocol; }
|
||||||
|
void set_host(const String& host) { m_host = host; }
|
||||||
|
void set_path(const String& path) { m_path = path; }
|
||||||
|
void set_port(u16 port) { m_port = port; }
|
||||||
|
|
||||||
String to_string() const;
|
String to_string() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue