mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 05:37:34 +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:
parent
f74251606d
commit
6e19ab2bbc
2006 changed files with 11635 additions and 11636 deletions
|
@ -25,9 +25,9 @@
|
|||
namespace LaunchServer {
|
||||
|
||||
static Launcher* s_the;
|
||||
static bool spawn(String executable, Vector<String> const& arguments);
|
||||
static bool spawn(DeprecatedString executable, Vector<DeprecatedString> const& arguments);
|
||||
|
||||
String Handler::name_from_executable(StringView executable)
|
||||
DeprecatedString Handler::name_from_executable(StringView executable)
|
||||
{
|
||||
auto separator = executable.find_last('/');
|
||||
if (separator.has_value()) {
|
||||
|
@ -37,14 +37,14 @@ String Handler::name_from_executable(StringView executable)
|
|||
return executable;
|
||||
}
|
||||
|
||||
void Handler::from_executable(Type handler_type, String const& executable)
|
||||
void Handler::from_executable(Type handler_type, DeprecatedString const& executable)
|
||||
{
|
||||
this->handler_type = handler_type;
|
||||
this->name = name_from_executable(executable);
|
||||
this->executable = executable;
|
||||
}
|
||||
|
||||
String Handler::to_details_str() const
|
||||
DeprecatedString Handler::to_details_str() const
|
||||
{
|
||||
StringBuilder builder;
|
||||
auto obj = MUST(JsonObjectSerializer<>::try_create(builder));
|
||||
|
@ -79,18 +79,18 @@ Launcher& Launcher::the()
|
|||
return *s_the;
|
||||
}
|
||||
|
||||
void Launcher::load_handlers(String const& af_dir)
|
||||
void Launcher::load_handlers(DeprecatedString const& af_dir)
|
||||
{
|
||||
Desktop::AppFile::for_each([&](auto af) {
|
||||
auto app_name = af->name();
|
||||
auto app_executable = af->executable();
|
||||
HashTable<String> mime_types;
|
||||
HashTable<DeprecatedString> mime_types;
|
||||
for (auto& mime_type : af->launcher_mime_types())
|
||||
mime_types.set(mime_type);
|
||||
HashTable<String> file_types;
|
||||
HashTable<DeprecatedString> file_types;
|
||||
for (auto& file_type : af->launcher_file_types())
|
||||
file_types.set(file_type);
|
||||
HashTable<String> protocols;
|
||||
HashTable<DeprecatedString> protocols;
|
||||
for (auto& protocol : af->launcher_protocols())
|
||||
protocols.set(protocol);
|
||||
if (access(app_executable.characters(), X_OK) == 0)
|
||||
|
@ -129,7 +129,7 @@ void Launcher::load_config(Core::ConfigFile const& cfg)
|
|||
}
|
||||
}
|
||||
|
||||
bool Launcher::has_mime_handlers(String const& mime_type)
|
||||
bool Launcher::has_mime_handlers(DeprecatedString const& mime_type)
|
||||
{
|
||||
for (auto& handler : m_handlers)
|
||||
if (handler.value.mime_types.contains(mime_type))
|
||||
|
@ -137,9 +137,9 @@ bool Launcher::has_mime_handlers(String const& mime_type)
|
|||
return false;
|
||||
}
|
||||
|
||||
Vector<String> Launcher::handlers_for_url(const URL& url)
|
||||
Vector<DeprecatedString> Launcher::handlers_for_url(const URL& url)
|
||||
{
|
||||
Vector<String> handlers;
|
||||
Vector<DeprecatedString> handlers;
|
||||
if (url.scheme() == "file") {
|
||||
for_each_handler_for_path(url.path(), [&](auto& handler) -> bool {
|
||||
handlers.append(handler.executable);
|
||||
|
@ -157,9 +157,9 @@ Vector<String> Launcher::handlers_for_url(const URL& url)
|
|||
return handlers;
|
||||
}
|
||||
|
||||
Vector<String> Launcher::handlers_with_details_for_url(const URL& url)
|
||||
Vector<DeprecatedString> Launcher::handlers_with_details_for_url(const URL& url)
|
||||
{
|
||||
Vector<String> handlers;
|
||||
Vector<DeprecatedString> handlers;
|
||||
if (url.scheme() == "file") {
|
||||
for_each_handler_for_path(url.path(), [&](auto& handler) -> bool {
|
||||
handlers.append(handler.to_details_str());
|
||||
|
@ -177,7 +177,7 @@ Vector<String> Launcher::handlers_with_details_for_url(const URL& url)
|
|||
return handlers;
|
||||
}
|
||||
|
||||
Optional<String> Launcher::mime_type_for_file(String path)
|
||||
Optional<DeprecatedString> Launcher::mime_type_for_file(DeprecatedString path)
|
||||
{
|
||||
auto file_or_error = Core::File::open(path, Core::OpenMode::ReadOnly);
|
||||
if (file_or_error.is_error()) {
|
||||
|
@ -191,7 +191,7 @@ Optional<String> Launcher::mime_type_for_file(String path)
|
|||
}
|
||||
}
|
||||
|
||||
bool Launcher::open_url(const URL& url, String const& handler_name)
|
||||
bool Launcher::open_url(const URL& url, DeprecatedString const& handler_name)
|
||||
{
|
||||
if (!handler_name.is_null())
|
||||
return open_with_handler_name(url, handler_name);
|
||||
|
@ -202,14 +202,14 @@ bool Launcher::open_url(const URL& url, String const& handler_name)
|
|||
return open_with_user_preferences(m_protocol_handlers, url.scheme(), { url.to_string() });
|
||||
}
|
||||
|
||||
bool Launcher::open_with_handler_name(const URL& url, String const& handler_name)
|
||||
bool Launcher::open_with_handler_name(const URL& url, DeprecatedString const& handler_name)
|
||||
{
|
||||
auto handler_optional = m_handlers.get(handler_name);
|
||||
if (!handler_optional.has_value())
|
||||
return false;
|
||||
|
||||
auto& handler = handler_optional.value();
|
||||
String argument;
|
||||
DeprecatedString argument;
|
||||
if (url.scheme() == "file")
|
||||
argument = url.path();
|
||||
else
|
||||
|
@ -217,12 +217,12 @@ bool Launcher::open_with_handler_name(const URL& url, String const& handler_name
|
|||
return spawn(handler.executable, { argument });
|
||||
}
|
||||
|
||||
bool spawn(String executable, Vector<String> const& arguments)
|
||||
bool spawn(DeprecatedString executable, Vector<DeprecatedString> const& arguments)
|
||||
{
|
||||
return !Core::Process::spawn(executable, arguments).is_error();
|
||||
}
|
||||
|
||||
Handler Launcher::get_handler_for_executable(Handler::Type handler_type, String const& executable) const
|
||||
Handler Launcher::get_handler_for_executable(Handler::Type handler_type, DeprecatedString const& executable) const
|
||||
{
|
||||
Handler handler;
|
||||
auto existing_handler = m_handlers.get(executable);
|
||||
|
@ -235,13 +235,13 @@ Handler Launcher::get_handler_for_executable(Handler::Type handler_type, String
|
|||
return handler;
|
||||
}
|
||||
|
||||
bool Launcher::open_with_user_preferences(HashMap<String, String> const& user_preferences, String const& key, Vector<String> const& arguments, String const& default_program)
|
||||
bool Launcher::open_with_user_preferences(HashMap<DeprecatedString, DeprecatedString> const& user_preferences, DeprecatedString const& key, Vector<DeprecatedString> const& arguments, DeprecatedString const& default_program)
|
||||
{
|
||||
auto program_path = user_preferences.get(key);
|
||||
if (program_path.has_value())
|
||||
return spawn(program_path.value(), arguments);
|
||||
|
||||
String executable = "";
|
||||
DeprecatedString executable = "";
|
||||
if (for_each_handler(key, user_preferences, [&](auto const& handler) -> bool {
|
||||
if (executable.is_empty() && (handler.mime_types.contains(key) || handler.file_types.contains(key) || handler.protocols.contains(key))) {
|
||||
executable = handler.executable;
|
||||
|
@ -264,7 +264,7 @@ bool Launcher::open_with_user_preferences(HashMap<String, String> const& user_pr
|
|||
return false;
|
||||
}
|
||||
|
||||
size_t Launcher::for_each_handler(String const& key, HashMap<String, String> const& user_preference, Function<bool(Handler const&)> f)
|
||||
size_t Launcher::for_each_handler(DeprecatedString const& key, HashMap<DeprecatedString, DeprecatedString> const& user_preference, Function<bool(Handler const&)> f)
|
||||
{
|
||||
auto user_preferred = user_preference.get(key);
|
||||
if (user_preferred.has_value())
|
||||
|
@ -287,7 +287,7 @@ size_t Launcher::for_each_handler(String const& key, HashMap<String, String> con
|
|||
return counted;
|
||||
}
|
||||
|
||||
void Launcher::for_each_handler_for_path(String const& path, Function<bool(Handler const&)> f)
|
||||
void Launcher::for_each_handler_for_path(DeprecatedString const& path, Function<bool(Handler const&)> f)
|
||||
{
|
||||
struct stat st;
|
||||
if (lstat(path.characters(), &st) < 0) {
|
||||
|
@ -352,13 +352,13 @@ bool Launcher::open_file_url(const URL& url)
|
|||
}
|
||||
|
||||
if (S_ISDIR(st.st_mode)) {
|
||||
Vector<String> fm_arguments;
|
||||
Vector<DeprecatedString> fm_arguments;
|
||||
if (url.fragment().is_empty()) {
|
||||
fm_arguments.append(url.path());
|
||||
} else {
|
||||
fm_arguments.append("-s");
|
||||
fm_arguments.append("-r");
|
||||
fm_arguments.append(String::formatted("{}/{}", url.path(), url.fragment()));
|
||||
fm_arguments.append(DeprecatedString::formatted("{}/{}", url.path(), url.fragment()));
|
||||
}
|
||||
|
||||
auto handler_optional = m_file_handlers.get("directory");
|
||||
|
@ -381,13 +381,13 @@ bool Launcher::open_file_url(const URL& url)
|
|||
mime_type_or_extension = mime_type.value();
|
||||
|
||||
auto handler_optional = m_file_handlers.get("txt");
|
||||
String default_handler = "";
|
||||
DeprecatedString default_handler = "";
|
||||
if (handler_optional.has_value())
|
||||
default_handler = handler_optional.value();
|
||||
|
||||
// Additional parameters parsing, specific for the file protocol and txt file handlers
|
||||
Vector<String> additional_parameters;
|
||||
String filepath = url.path();
|
||||
Vector<DeprecatedString> additional_parameters;
|
||||
DeprecatedString filepath = url.path();
|
||||
|
||||
auto parameters = url.query().split('&');
|
||||
for (auto const& parameter : parameters) {
|
||||
|
@ -396,7 +396,7 @@ bool Launcher::open_file_url(const URL& url)
|
|||
auto line = pair[1].to_int();
|
||||
if (line.has_value())
|
||||
// TextEditor uses file:line:col to open a file at a specific line number
|
||||
filepath = String::formatted("{}:{}", filepath, line.value());
|
||||
filepath = DeprecatedString::formatted("{}:{}", filepath, line.value());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue