AK: Replace URL::to_string() with new serialize() implementation

This commit is contained in:
Max Wipfli 2021-05-27 21:38:16 +02:00 committed by Andreas Kling
parent 1c4854824b
commit b7c6af0a04
Notes: sideshowbarker 2024-07-18 17:04:03 +09:00
2 changed files with 14 additions and 47 deletions

View File

@ -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)

View File

@ -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<URL> : Formatter<StringView> {
void format(FormatBuilder& builder, const URL& value)
{
Formatter<StringView>::format(builder, value.to_string());
Formatter<StringView>::format(builder, value.serialize());
}
};