mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-28 05:35:52 +03:00
AK: Replace URL::to_string() with new serialize() implementation
This commit is contained in:
parent
1c4854824b
commit
b7c6af0a04
Notes:
sideshowbarker
2024-07-18 17:04:03 +09:00
Author: https://github.com/MaxWipfli Commit: https://github.com/SerenityOS/serenity/commit/b7c6af0a041 Pull-request: https://github.com/SerenityOS/serenity/pull/7478 Reviewed-by: https://github.com/awesomekling
47
AK/URL.cpp
47
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)
|
||||
|
14
AK/URL.h
14
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<URL> : Formatter<StringView> {
|
||||
void format(FormatBuilder& builder, const URL& value)
|
||||
{
|
||||
Formatter<StringView>::format(builder, value.to_string());
|
||||
Formatter<StringView>::format(builder, value.serialize());
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user