1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 02:57:42 +00:00

AK+Everywhere: Rename String to DeprecatedString

We have a new, improved string type coming up in AK (OOM aware, no null
state), and while it's going to use UTF-8, the name UTF8String is a
mouthful - so let's free up the String name by renaming the existing
class.
Making the old one have an annoying name will hopefully also help with
quick adoption :^)
This commit is contained in:
Linus Groh 2022-12-04 18:02:33 +00:00 committed by Andreas Kling
parent f74251606d
commit 6e19ab2bbc
2006 changed files with 11635 additions and 11636 deletions

View file

@ -18,7 +18,7 @@ JS::NonnullGCPtr<URL> URL::create(JS::Realm& realm, AK::URL url, JS::NonnullGCPt
return *realm.heap().allocate<URL>(realm, realm, move(url), move(query));
}
WebIDL::ExceptionOr<JS::NonnullGCPtr<URL>> URL::construct_impl(JS::Realm& realm, String const& url, String const& base)
WebIDL::ExceptionOr<JS::NonnullGCPtr<URL>> URL::construct_impl(JS::Realm& realm, DeprecatedString const& url, DeprecatedString const& base)
{
// 1. Let parsedBase be null.
Optional<AK::URL> parsed_base;
@ -40,7 +40,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<URL>> URL::construct_impl(JS::Realm& realm,
if (!parsed_url.is_valid())
return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Invalid URL"sv };
// 5. Let query be parsedURLs query, if that is non-null, and the empty string otherwise.
auto& query = parsed_url.query().is_null() ? String::empty() : parsed_url.query();
auto& query = parsed_url.query().is_null() ? DeprecatedString::empty() : parsed_url.query();
// 6. Set thiss URL to parsedURL.
// 7. Set thiss query object to a new URLSearchParams object.
auto query_object = MUST(URLSearchParams::construct_impl(realm, query));
@ -68,19 +68,19 @@ void URL::visit_edges(Cell::Visitor& visitor)
visitor.visit(m_query.ptr());
}
String URL::href() const
DeprecatedString URL::href() const
{
// return the serialization of thiss URL.
return m_url.serialize();
}
String URL::to_json() const
DeprecatedString URL::to_json() const
{
// return the serialization of thiss URL.
return m_url.serialize();
}
WebIDL::ExceptionOr<void> URL::set_href(String const& href)
WebIDL::ExceptionOr<void> URL::set_href(DeprecatedString const& href)
{
// 1. Let parsedURL be the result of running the basic URL parser on the given value.
AK::URL parsed_url = href;
@ -99,33 +99,33 @@ WebIDL::ExceptionOr<void> URL::set_href(String const& href)
return {};
}
String URL::origin() const
DeprecatedString URL::origin() const
{
// return the serialization of thiss URLs origin.
return m_url.serialize_origin();
}
String URL::protocol() const
DeprecatedString URL::protocol() const
{
// return thiss URLs scheme, followed by U+003A (:).
return String::formatted("{}:", m_url.scheme());
return DeprecatedString::formatted("{}:", m_url.scheme());
}
void URL::set_protocol(String const& protocol)
void URL::set_protocol(DeprecatedString const& protocol)
{
// basic URL parse the given value, followed by U+003A (:), with thiss URL as url and scheme start state as state override.
auto result_url = URLParser::parse(String::formatted("{}:", protocol), nullptr, m_url, URLParser::State::SchemeStart);
auto result_url = URLParser::parse(DeprecatedString::formatted("{}:", protocol), nullptr, m_url, URLParser::State::SchemeStart);
if (result_url.is_valid())
m_url = move(result_url);
}
String URL::username() const
DeprecatedString URL::username() const
{
// return thiss URLs username.
return m_url.username();
}
void URL::set_username(String const& username)
void URL::set_username(DeprecatedString const& username)
{
// 1. If thiss URL cannot have a username/password/port, then return.
if (m_url.cannot_have_a_username_or_password_or_port())
@ -134,13 +134,13 @@ void URL::set_username(String const& username)
m_url.set_username(AK::URL::percent_encode(username, AK::URL::PercentEncodeSet::Userinfo));
}
String URL::password() const
DeprecatedString URL::password() const
{
// return thiss URLs password.
return m_url.password();
}
void URL::set_password(String const& password)
void URL::set_password(DeprecatedString const& password)
{
// 1. If thiss URL cannot have a username/password/port, then return.
if (m_url.cannot_have_a_username_or_password_or_port())
@ -149,21 +149,21 @@ void URL::set_password(String const& password)
m_url.set_password(AK::URL::percent_encode(password, AK::URL::PercentEncodeSet::Userinfo));
}
String URL::host() const
DeprecatedString URL::host() const
{
// 1. Let url be thiss URL.
auto& url = m_url;
// 2. If urls host is null, then return the empty string.
if (url.host().is_null())
return String::empty();
return DeprecatedString::empty();
// 3. If urls port is null, return urls host, serialized.
if (!url.port().has_value())
return url.host();
// 4. Return urls host, serialized, followed by U+003A (:) and urls port, serialized.
return String::formatted("{}:{}", url.host(), *url.port());
return DeprecatedString::formatted("{}:{}", url.host(), *url.port());
}
void URL::set_host(String const& host)
void URL::set_host(DeprecatedString const& host)
{
// 1. If thiss URLs cannot-be-a-base-URL is true, then return.
if (m_url.cannot_be_a_base_url())
@ -174,16 +174,16 @@ void URL::set_host(String const& host)
m_url = move(result_url);
}
String URL::hostname() const
DeprecatedString URL::hostname() const
{
// 1. If thiss URLs host is null, then return the empty string.
if (m_url.host().is_null())
return String::empty();
return DeprecatedString::empty();
// 2. Return thiss URLs host, serialized.
return m_url.host();
}
void URL::set_hostname(String const& hostname)
void URL::set_hostname(DeprecatedString const& hostname)
{
// 1. If thiss URLs cannot-be-a-base-URL is true, then return.
if (m_url.cannot_be_a_base_url())
@ -194,17 +194,17 @@ void URL::set_hostname(String const& hostname)
m_url = move(result_url);
}
String URL::port() const
DeprecatedString URL::port() const
{
// 1. If thiss URLs port is null, then return the empty string.
if (!m_url.port().has_value())
return {};
// 2. Return thiss URLs port, serialized.
return String::formatted("{}", *m_url.port());
return DeprecatedString::formatted("{}", *m_url.port());
}
void URL::set_port(String const& port)
void URL::set_port(DeprecatedString const& port)
{
// 1. If thiss URL cannot have a username/password/port, then return.
if (m_url.cannot_have_a_username_or_password_or_port())
@ -222,7 +222,7 @@ void URL::set_port(String const& port)
m_url = move(result_url);
}
String URL::pathname() const
DeprecatedString URL::pathname() const
{
// 1. If thiss URLs cannot-be-a-base-URL is true, then return thiss URLs path[0].
// 2. If thiss URLs path is empty, then return the empty string.
@ -230,7 +230,7 @@ String URL::pathname() const
return m_url.path();
}
void URL::set_pathname(String const& pathname)
void URL::set_pathname(DeprecatedString const& pathname)
{
// 1. If thiss URLs cannot-be-a-base-URL is true, then return.
if (m_url.cannot_be_a_base_url())
@ -244,16 +244,16 @@ void URL::set_pathname(String const& pathname)
m_url = move(result_url);
}
String URL::search() const
DeprecatedString URL::search() const
{
// 1. If thiss URLs query is either null or the empty string, then return the empty string.
if (m_url.query().is_null() || m_url.query().is_empty())
return String::empty();
return DeprecatedString::empty();
// 2. Return U+003F (?), followed by thiss URLs query.
return String::formatted("?{}", m_url.query());
return DeprecatedString::formatted("?{}", m_url.query());
}
void URL::set_search(String const& search)
void URL::set_search(DeprecatedString const& search)
{
// 1. Let url be thiss URL.
auto& url = m_url;
@ -267,7 +267,7 @@ void URL::set_search(String const& search)
auto input = search.substring_view(search.starts_with('?'));
// 3. Set urls query to the empty string.
auto url_copy = url; // We copy the URL here to follow other browser's behaviour of reverting the search change if the parse failed.
url_copy.set_query(String::empty());
url_copy.set_query(DeprecatedString::empty());
// 4. Basic URL parse input with url as url and query state as state override.
auto result_url = URLParser::parse(input, nullptr, move(url_copy), URLParser::State::Query);
if (result_url.is_valid()) {
@ -282,16 +282,16 @@ URLSearchParams const* URL::search_params() const
return m_query;
}
String URL::hash() const
DeprecatedString URL::hash() const
{
// 1. If thiss URLs fragment is either null or the empty string, then return the empty string.
if (m_url.fragment().is_null() || m_url.fragment().is_empty())
return String::empty();
return DeprecatedString::empty();
// 2. Return U+0023 (#), followed by thiss URLs fragment.
return String::formatted("#{}", m_url.fragment());
return DeprecatedString::formatted("#{}", m_url.fragment());
}
void URL::set_hash(String const& hash)
void URL::set_hash(DeprecatedString const& hash)
{
// 1. If the given value is the empty string, then set thiss URLs fragment to null and return.
if (hash.is_empty()) {
@ -302,7 +302,7 @@ void URL::set_hash(String const& hash)
auto input = hash.substring_view(hash.starts_with('#'));
// 3. Set thiss URLs fragment to the empty string.
auto url = m_url; // We copy the URL here to follow other browser's behaviour of reverting the hash change if the parse failed.
url.set_fragment(String::empty());
url.set_fragment(DeprecatedString::empty());
// 4. Basic URL parse input with thiss URL as url and fragment state as state override.
auto result_url = URLParser::parse(input, nullptr, move(url), URLParser::State::Fragment);
if (result_url.is_valid())
@ -335,7 +335,7 @@ HTML::Origin url_origin(AK::URL const& url)
if (url.scheme() == "file"sv) {
// Unfortunate as it is, this is left as an exercise to the reader. When in doubt, return a new opaque origin.
// Note: We must return an origin with the `file://' protocol for `file://' iframes to work from `file://' pages.
return HTML::Origin(url.scheme(), String(), 0);
return HTML::Origin(url.scheme(), DeprecatedString(), 0);
}
// Return a new opaque origin.