1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 06:47:35 +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.

View file

@ -7,7 +7,7 @@
#pragma once
#include <AK/String.h>
#include <AK/DeprecatedString.h>
#include <AK/URL.h>
#include <LibWeb/Bindings/PlatformObject.h>
#include <LibWeb/URL/URLSearchParams.h>
@ -20,47 +20,47 @@ class URL : public Bindings::PlatformObject {
public:
static JS::NonnullGCPtr<URL> create(JS::Realm&, AK::URL url, JS::NonnullGCPtr<URLSearchParams> query);
static WebIDL::ExceptionOr<JS::NonnullGCPtr<URL>> construct_impl(JS::Realm&, String const& url, String const& base);
static WebIDL::ExceptionOr<JS::NonnullGCPtr<URL>> construct_impl(JS::Realm&, DeprecatedString const& url, DeprecatedString const& base);
virtual ~URL() override;
String href() const;
WebIDL::ExceptionOr<void> set_href(String const&);
DeprecatedString href() const;
WebIDL::ExceptionOr<void> set_href(DeprecatedString const&);
String origin() const;
DeprecatedString origin() const;
String protocol() const;
void set_protocol(String const&);
DeprecatedString protocol() const;
void set_protocol(DeprecatedString const&);
String username() const;
void set_username(String const&);
DeprecatedString username() const;
void set_username(DeprecatedString const&);
String password() const;
void set_password(String const&);
DeprecatedString password() const;
void set_password(DeprecatedString const&);
String host() const;
void set_host(String const&);
DeprecatedString host() const;
void set_host(DeprecatedString const&);
String hostname() const;
void set_hostname(String const&);
DeprecatedString hostname() const;
void set_hostname(DeprecatedString const&);
String port() const;
void set_port(String const&);
DeprecatedString port() const;
void set_port(DeprecatedString const&);
String pathname() const;
void set_pathname(String const&);
DeprecatedString pathname() const;
void set_pathname(DeprecatedString const&);
String search() const;
void set_search(String const&);
DeprecatedString search() const;
void set_search(DeprecatedString const&);
URLSearchParams const* search_params() const;
String hash() const;
void set_hash(String const&);
DeprecatedString hash() const;
void set_hash(DeprecatedString const&);
String to_json() const;
DeprecatedString to_json() const;
void set_query(Badge<URLSearchParams>, String query) { m_url.set_query(move(query)); }
void set_query(Badge<URLSearchParams>, DeprecatedString query) { m_url.set_query(move(query)); }
private:
URL(JS::Realm&, AK::URL, JS::NonnullGCPtr<URLSearchParams> query);

View file

@ -28,7 +28,7 @@ void URLSearchParams::visit_edges(Cell::Visitor& visitor)
visitor.visit(m_url);
}
String url_encode(Vector<QueryParam> const& pairs, AK::URL::PercentEncodeSet percent_encode_set)
DeprecatedString url_encode(Vector<QueryParam> const& pairs, AK::URL::PercentEncodeSet percent_encode_set)
{
StringBuilder builder;
for (size_t i = 0; i < pairs.size(); ++i) {
@ -89,7 +89,7 @@ JS::NonnullGCPtr<URLSearchParams> URLSearchParams::create(JS::Realm& realm, Vect
// https://url.spec.whatwg.org/#dom-urlsearchparams-urlsearchparams
// https://url.spec.whatwg.org/#urlsearchparams-initialize
WebIDL::ExceptionOr<JS::NonnullGCPtr<URLSearchParams>> URLSearchParams::construct_impl(JS::Realm& realm, Variant<Vector<Vector<String>>, OrderedHashMap<String, String>, String> const& init)
WebIDL::ExceptionOr<JS::NonnullGCPtr<URLSearchParams>> URLSearchParams::construct_impl(JS::Realm& realm, Variant<Vector<Vector<DeprecatedString>>, OrderedHashMap<DeprecatedString, DeprecatedString>, DeprecatedString> const& init)
{
// 1. If init is a string and starts with U+003F (?), then remove the first code point from init.
// NOTE: We do this when we know that it's a string on step 3 of initialization.
@ -99,8 +99,8 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<URLSearchParams>> URLSearchParams::construc
// URLSearchParams init from this point forward
// 1. If init is a sequence, then for each pair in init:
if (init.has<Vector<Vector<String>>>()) {
auto const& init_sequence = init.get<Vector<Vector<String>>>();
if (init.has<Vector<Vector<DeprecatedString>>>()) {
auto const& init_sequence = init.get<Vector<Vector<DeprecatedString>>>();
Vector<QueryParam> list;
list.ensure_capacity(init_sequence.size());
@ -108,7 +108,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<URLSearchParams>> URLSearchParams::construc
for (auto const& pair : init_sequence) {
// a. If pair does not contain exactly two items, then throw a TypeError.
if (pair.size() != 2)
return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, String::formatted("Expected only 2 items in pair, got {}", pair.size()) };
return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, DeprecatedString::formatted("Expected only 2 items in pair, got {}", pair.size()) };
// b. Append a new name-value pair whose name is pairs first item, and value is pairs second item, to querys list.
list.append(QueryParam { .name = pair[0], .value = pair[1] });
@ -118,8 +118,8 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<URLSearchParams>> URLSearchParams::construc
}
// 2. Otherwise, if init is a record, then for each name → value of init, append a new name-value pair whose name is name and value is value, to querys list.
if (init.has<OrderedHashMap<String, String>>()) {
auto const& init_record = init.get<OrderedHashMap<String, String>>();
if (init.has<OrderedHashMap<DeprecatedString, DeprecatedString>>()) {
auto const& init_record = init.get<OrderedHashMap<DeprecatedString, DeprecatedString>>();
Vector<QueryParam> list;
list.ensure_capacity(init_record.size());
@ -133,7 +133,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<URLSearchParams>> URLSearchParams::construc
// 3. Otherwise:
// a. Assert: init is a string.
// NOTE: `get` performs `VERIFY(has<T>())`
auto const& init_string = init.get<String>();
auto const& init_string = init.get<DeprecatedString>();
// See NOTE at the start of this function.
StringView stripped_init = init_string.substring_view(init_string.starts_with('?'));
@ -142,7 +142,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<URLSearchParams>> URLSearchParams::construc
return URLSearchParams::create(realm, url_decode(stripped_init));
}
void URLSearchParams::append(String const& name, String const& value)
void URLSearchParams::append(DeprecatedString const& name, DeprecatedString const& value)
{
// 1. Append a new name-value pair whose name is name and value is value, to list.
m_list.empend(name, value);
@ -164,7 +164,7 @@ void URLSearchParams::update()
m_url->set_query({}, move(serialized_query));
}
void URLSearchParams::delete_(String const& name)
void URLSearchParams::delete_(DeprecatedString const& name)
{
// 1. Remove all name-value pairs whose name is name from list.
m_list.remove_all_matching([&name](auto& entry) {
@ -174,7 +174,7 @@ void URLSearchParams::delete_(String const& name)
update();
}
String URLSearchParams::get(String const& name)
DeprecatedString URLSearchParams::get(DeprecatedString const& name)
{
// return the value of the first name-value pair whose name is name in thiss list, if there is such a pair, and null otherwise.
auto result = m_list.find_if([&name](auto& entry) {
@ -186,10 +186,10 @@ String URLSearchParams::get(String const& name)
}
// https://url.spec.whatwg.org/#dom-urlsearchparams-getall
Vector<String> URLSearchParams::get_all(String const& name)
Vector<DeprecatedString> URLSearchParams::get_all(DeprecatedString const& name)
{
// return the values of all name-value pairs whose name is name, in thiss list, in list order, and the empty sequence otherwise.
Vector<String> values;
Vector<DeprecatedString> values;
for (auto& entry : m_list) {
if (entry.name == name)
values.append(entry.value);
@ -197,7 +197,7 @@ Vector<String> URLSearchParams::get_all(String const& name)
return values;
}
bool URLSearchParams::has(String const& name)
bool URLSearchParams::has(DeprecatedString const& name)
{
// return true if there is a name-value pair whose name is name in thiss list, and false otherwise.
return !m_list.find_if([&name](auto& entry) {
@ -206,7 +206,7 @@ bool URLSearchParams::has(String const& name)
.is_end();
}
void URLSearchParams::set(String const& name, String const& value)
void URLSearchParams::set(DeprecatedString const& name, DeprecatedString const& value)
{
// 1. If thiss list contains any name-value pairs whose name is name, then set the value of the first such name-value pair to value and remove the others.
auto existing = m_list.find_if([&name](auto& entry) {
@ -255,7 +255,7 @@ void URLSearchParams::sort()
update();
}
String URLSearchParams::to_string() const
DeprecatedString URLSearchParams::to_string() const
{
// return the serialization of thiss list.
return url_encode(m_list, AK::URL::PercentEncodeSet::ApplicationXWWWFormUrlencoded);

View file

@ -13,10 +13,10 @@
namespace Web::URL {
struct QueryParam {
String name;
String value;
DeprecatedString name;
DeprecatedString value;
};
String url_encode(Vector<QueryParam> const&, AK::URL::PercentEncodeSet);
DeprecatedString url_encode(Vector<QueryParam> const&, AK::URL::PercentEncodeSet);
Vector<QueryParam> url_decode(StringView);
class URLSearchParams : public Bindings::PlatformObject {
@ -24,22 +24,22 @@ class URLSearchParams : public Bindings::PlatformObject {
public:
static JS::NonnullGCPtr<URLSearchParams> create(JS::Realm&, Vector<QueryParam> list);
static WebIDL::ExceptionOr<JS::NonnullGCPtr<URLSearchParams>> construct_impl(JS::Realm&, Variant<Vector<Vector<String>>, OrderedHashMap<String, String>, String> const& init);
static WebIDL::ExceptionOr<JS::NonnullGCPtr<URLSearchParams>> construct_impl(JS::Realm&, Variant<Vector<Vector<DeprecatedString>>, OrderedHashMap<DeprecatedString, DeprecatedString>, DeprecatedString> const& init);
virtual ~URLSearchParams() override;
void append(String const& name, String const& value);
void delete_(String const& name);
String get(String const& name);
Vector<String> get_all(String const& name);
bool has(String const& name);
void set(String const& name, String const& value);
void append(DeprecatedString const& name, DeprecatedString const& value);
void delete_(DeprecatedString const& name);
DeprecatedString get(DeprecatedString const& name);
Vector<DeprecatedString> get_all(DeprecatedString const& name);
bool has(DeprecatedString const& name);
void set(DeprecatedString const& name, DeprecatedString const& value);
void sort();
String to_string() const;
DeprecatedString to_string() const;
using ForEachCallback = Function<JS::ThrowCompletionOr<void>(String const&, String const&)>;
using ForEachCallback = Function<JS::ThrowCompletionOr<void>(DeprecatedString const&, DeprecatedString const&)>;
JS::ThrowCompletionOr<void> for_each(ForEachCallback);
private: