diff --git a/AK/URL.cpp b/AK/URL.cpp index d68b372b669..8288f7abe69 100644 --- a/AK/URL.cpp +++ b/AK/URL.cpp @@ -60,46 +60,6 @@ String URL::path() const return builder.to_string(); } -String URL::to_string() const -{ - StringBuilder builder; - builder.append(m_scheme); - - if (m_scheme == "about") { - builder.append(':'); - builder.append(m_path); - return builder.to_string(); - } - - if (m_scheme == "data") { - builder.append(':'); - builder.append(m_data_mime_type); - if (m_data_payload_is_base64) - builder.append(";base64"); - builder.append(','); - builder.append(m_data_payload); - return builder.to_string(); - } - - builder.append("://"); - builder.append(m_host); - if (default_port_for_scheme(scheme()) != port()) { - builder.append(':'); - builder.append(String::number(m_port)); - } - - builder.append(path()); - if (!m_query.is_empty()) { - builder.append('?'); - builder.append(m_query); - } - if (!m_fragment.is_empty()) { - builder.append('#'); - builder.append(m_fragment); - } - return builder.to_string(); -} - URL URL::complete_url(const String& string) const { if (!is_valid()) @@ -377,6 +337,13 @@ String URL::serialize_for_display() const return builder.to_string(); } +bool URL::equals(const URL& other, ExcludeFragment exclude_fragments) const +{ + if (!m_valid || !other.m_valid) + return false; + return serialize(exclude_fragments) == other.serialize(exclude_fragments); +} + String URL::basename() const { if (!m_valid) diff --git a/AK/URL.h b/AK/URL.h index eedf0ce4e2c..f7e1c0276dd 100644 --- a/AK/URL.h +++ b/AK/URL.h @@ -77,15 +77,15 @@ public: String path() const; String basename() const; - String to_string() const; - String to_string_encoded() const - { - return percent_encode(to_string(), PercentEncodeSet::EncodeURI); - } String serialize(ExcludeFragment = ExcludeFragment::No) const; String serialize_for_display() const; + String to_string() const { return serialize(); } + String to_string_encoded() const { return serialize(); } + + bool equals(const URL& other, ExcludeFragment = ExcludeFragment::No) const; + URL complete_url(const String&) const; bool data_payload_is_base64() const { return m_data_payload_is_base64; } @@ -108,7 +108,7 @@ public: { if (this == &other) return true; - return to_string() == other.to_string(); + return equals(other, ExcludeFragment::No); } private: @@ -151,7 +151,7 @@ template<> struct Formatter : Formatter { void format(FormatBuilder& builder, const URL& value) { - Formatter::format(builder, value.to_string()); + Formatter::format(builder, value.serialize()); } };