mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 02:37:36 +00:00
AK+Everywhere: Remove the null state of DeprecatedString
This commit removes DeprecatedString's "null" state, and replaces all its users with one of the following: - A normal, empty DeprecatedString - Optional<DeprecatedString> Note that null states of DeprecatedFlyString/StringView/etc are *not* affected by this commit. However, DeprecatedString::empty() is now considered equal to a null StringView.
This commit is contained in:
parent
daf6d8173c
commit
aeee98b3a1
189 changed files with 597 additions and 652 deletions
|
@ -17,7 +17,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
StringView path;
|
||||
DeprecatedString group;
|
||||
DeprecatedString key;
|
||||
DeprecatedString value_to_write;
|
||||
StringView value_to_write;
|
||||
|
||||
Core::ArgsParser args_parser;
|
||||
args_parser.add_positional_argument(path, "Path to INI file", "path");
|
||||
|
|
|
@ -248,15 +248,15 @@ static int print_escaped(StringView name)
|
|||
|
||||
static DeprecatedString& hostname()
|
||||
{
|
||||
static DeprecatedString s_hostname;
|
||||
if (s_hostname.is_null()) {
|
||||
static Optional<DeprecatedString> s_hostname;
|
||||
if (!s_hostname.has_value()) {
|
||||
char buffer[HOST_NAME_MAX];
|
||||
if (gethostname(buffer, sizeof(buffer)) == 0)
|
||||
s_hostname = buffer;
|
||||
else
|
||||
s_hostname = "localhost";
|
||||
}
|
||||
return s_hostname;
|
||||
return *s_hostname;
|
||||
}
|
||||
|
||||
static size_t print_name(const struct stat& st, DeprecatedString const& name, Optional<StringView> path_for_link_resolution, StringView path_for_hyperlink)
|
||||
|
@ -470,7 +470,6 @@ static int do_file_system_object_long(DeprecatedString const& path)
|
|||
builder.append('/');
|
||||
builder.append(metadata.name);
|
||||
metadata.path = builder.to_deprecated_string();
|
||||
VERIFY(!metadata.path.is_null());
|
||||
int rc = lstat(metadata.path.characters(), &metadata.stat);
|
||||
if (rc < 0)
|
||||
perror("lstat");
|
||||
|
@ -595,7 +594,6 @@ int do_file_system_object_short(DeprecatedString const& path)
|
|||
builder.append('/');
|
||||
builder.append(metadata.name);
|
||||
metadata.path = builder.to_deprecated_string();
|
||||
VERIFY(!metadata.path.is_null());
|
||||
int rc = lstat(metadata.path.characters(), &metadata.stat);
|
||||
if (rc < 0)
|
||||
perror("lstat");
|
||||
|
|
|
@ -179,10 +179,11 @@ RecursionDecision MarkdownLinkage::visit(Markdown::Heading const& heading)
|
|||
RecursionDecision MarkdownLinkage::visit(Markdown::Text::LinkNode const& link_node)
|
||||
{
|
||||
DeprecatedString const& href = link_node.href;
|
||||
if (href.is_null()) {
|
||||
if (href.is_empty()) {
|
||||
// Nothing to do here.
|
||||
return RecursionDecision::Recurse;
|
||||
}
|
||||
|
||||
auto url = URL::create_with_url_or_path(href);
|
||||
if (url.is_valid()) {
|
||||
if (url.scheme() == "https" || url.scheme() == "http") {
|
||||
|
|
|
@ -30,7 +30,7 @@ static DeprecatedString generate_random_filename(DeprecatedString const& pattern
|
|||
return new_filename.to_deprecated_string();
|
||||
}
|
||||
|
||||
static ErrorOr<DeprecatedString> make_temp(DeprecatedString const& pattern, bool directory, bool dry_run)
|
||||
static ErrorOr<Optional<DeprecatedString>> make_temp(DeprecatedString const& pattern, bool directory, bool dry_run)
|
||||
{
|
||||
for (int i = 0; i < 100; ++i) {
|
||||
auto path = generate_random_filename(pattern);
|
||||
|
@ -49,7 +49,7 @@ static ErrorOr<DeprecatedString> make_temp(DeprecatedString const& pattern, bool
|
|||
}
|
||||
}
|
||||
}
|
||||
return DeprecatedString {};
|
||||
return OptionalNone {};
|
||||
}
|
||||
|
||||
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
|
@ -100,7 +100,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
auto target_path = LexicalPath::join(final_target_directory->to_deprecated_string(), final_file_template->to_deprecated_string()).string();
|
||||
|
||||
auto final_path = TRY(make_temp(target_path, create_directory, dry_run));
|
||||
if (final_path.is_null()) {
|
||||
if (!final_path.has_value()) {
|
||||
if (!quiet) {
|
||||
if (create_directory)
|
||||
warnln("Failed to create directory via template {}", target_path.characters());
|
||||
|
@ -110,7 +110,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
return 1;
|
||||
}
|
||||
|
||||
outln("{}", final_path);
|
||||
outln("{}", *final_path);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -72,7 +72,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
clipboard.on_change = [&](DeprecatedString const&) {
|
||||
// Technically there's a race here...
|
||||
auto data_and_type = clipboard.fetch_data_and_type();
|
||||
if (data_and_type.mime_type.is_null()) {
|
||||
if (data_and_type.mime_type.is_empty()) {
|
||||
spawn_command(watch_command, {}, "clear");
|
||||
} else {
|
||||
spawn_command(watch_command, data_and_type.data, "data");
|
||||
|
@ -87,7 +87,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
|
||||
auto data_and_type = clipboard.fetch_data_and_type();
|
||||
|
||||
if (data_and_type.mime_type.is_null()) {
|
||||
if (data_and_type.mime_type.is_empty()) {
|
||||
warnln("Nothing copied");
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
|
||||
StringView first_positional;
|
||||
StringView second_positional;
|
||||
DeprecatedString command;
|
||||
StringView command;
|
||||
bool simulate_login = false;
|
||||
|
||||
Core::ArgsParser args_parser;
|
||||
|
@ -65,7 +65,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
if (command.is_null()) {
|
||||
TRY(Core::System::exec(account.shell(), Array<StringView, 1> { account.shell().view() }, Core::System::SearchInPath::No));
|
||||
} else {
|
||||
TRY(Core::System::exec(account.shell(), Array<StringView, 3> { account.shell().view(), "-c"sv, command.view() }, Core::System::SearchInPath::No));
|
||||
TRY(Core::System::exec(account.shell(), Array<StringView, 3> { account.shell().view(), "-c"sv, command }, Core::System::SearchInPath::No));
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
static bool s_set_variable = false;
|
||||
|
||||
static DeprecatedString get_variable(StringView name)
|
||||
static Optional<DeprecatedString> get_variable(StringView name)
|
||||
{
|
||||
auto path = DeprecatedString::formatted("/sys/kernel/conf/{}", name);
|
||||
auto file = Core::File::open(path, Core::File::OpenMode::Read);
|
||||
|
@ -25,22 +25,22 @@ static DeprecatedString get_variable(StringView name)
|
|||
warnln("Failed to read {}: {}", path, buffer.error());
|
||||
return {};
|
||||
}
|
||||
return { (char const*)buffer.value().data(), buffer.value().size(), Chomp };
|
||||
return DeprecatedString { (char const*)buffer.value().data(), buffer.value().size(), Chomp };
|
||||
}
|
||||
|
||||
static bool read_variable(StringView name)
|
||||
{
|
||||
auto value = get_variable(name);
|
||||
if (value.is_null())
|
||||
if (!value.has_value())
|
||||
return false;
|
||||
outln("{} = {}", name, value);
|
||||
outln("{} = {}", name, *value);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool write_variable(StringView name, StringView value)
|
||||
{
|
||||
auto old_value = get_variable(name);
|
||||
if (old_value.is_null())
|
||||
if (!old_value.has_value())
|
||||
return false;
|
||||
auto path = DeprecatedString::formatted("/sys/kernel/conf/{}", name);
|
||||
auto file = Core::File::open(path, Core::File::OpenMode::Write);
|
||||
|
@ -52,7 +52,7 @@ static bool write_variable(StringView name, StringView value)
|
|||
warnln("Failed to write {}: {}", path, result.error());
|
||||
return false;
|
||||
}
|
||||
outln("{}: {} -> {}", name, old_value, value);
|
||||
outln("{}: {} -> {}", name, *old_value, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
bool show_all = false;
|
||||
bool show_current = false;
|
||||
bool set_random = false;
|
||||
DeprecatedString path;
|
||||
StringView path;
|
||||
|
||||
Core::ArgsParser args_parser;
|
||||
args_parser.add_option(show_all, "Show all wallpapers", "show-all", 'a');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue