1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 08:48:11 +00:00

FileManager: Use new format functions.

This commit is contained in:
asynts 2020-10-05 14:59:50 +02:00 committed by Andreas Kling
parent 2d4cd5b49b
commit ee9c18c118
4 changed files with 44 additions and 56 deletions

View file

@ -42,9 +42,9 @@ void delete_paths(const Vector<String>& paths, bool should_confirm, GUI::Window*
{
String message;
if (paths.size() == 1) {
message = String::format("Really delete %s?", LexicalPath(paths[0]).basename().characters());
message = String::formatted("Really delete {}?", LexicalPath(paths[0]).basename());
} else {
message = String::format("Really delete %d files?", paths.size());
message = String::formatted("Really delete {} files?", paths.size());
}
if (should_confirm) {
@ -61,7 +61,7 @@ void delete_paths(const Vector<String>& paths, bool should_confirm, GUI::Window*
struct stat st;
if (lstat(path.characters(), &st)) {
GUI::MessageBox::show(parent_window,
String::format("lstat(%s) failed: %s", path.characters(), strerror(errno)),
String::formatted("lstat({}) failed: {}", path, strerror(errno)),
"Delete failed",
GUI::MessageBox::Type::Error);
break;
@ -73,7 +73,7 @@ void delete_paths(const Vector<String>& paths, bool should_confirm, GUI::Window*
if (error) {
GUI::MessageBox::show(parent_window,
String::format("Failed to delete directory \"%s\": %s", error_path.characters(), strerror(error)),
String::formatted("Failed to delete directory \"{}\": {}", error_path, strerror(error)),
"Delete failed",
GUI::MessageBox::Type::Error);
break;
@ -81,7 +81,7 @@ void delete_paths(const Vector<String>& paths, bool should_confirm, GUI::Window*
} else if (unlink(path.characters()) < 0) {
int saved_errno = errno;
GUI::MessageBox::show(parent_window,
String::format("unlink(%s) failed: %s", path.characters(), strerror(saved_errno)),
String::formatted("unlink(\"{}\") failed: {}", path, strerror(saved_errno)),
"Delete failed",
GUI::MessageBox::Type::Error);
break;
@ -98,7 +98,7 @@ int delete_directory(String directory, String& file_that_caused_error)
}
while (iterator.has_next()) {
auto file_to_delete = String::format("%s/%s", directory.characters(), iterator.next_path().characters());
auto file_to_delete = String::formatted("{}/{}", directory, iterator.next_path());
struct stat st;
if (lstat(file_to_delete.characters(), &st)) {
@ -165,8 +165,8 @@ bool copy_directory(const String& src_path, const String& dst_path, const struct
while (di.has_next()) {
String filename = di.next_path();
bool is_copied = copy_file_or_directory(
String::format("%s/%s", src_path.characters(), filename.characters()),
String::format("%s/%s", dst_path.characters(), filename.characters()));
String::formatted("{}/{}", src_path, filename),
String::formatted("{}/{}", dst_path, filename));
if (!is_copied) {
return false;
}
@ -188,7 +188,7 @@ bool copy_file(const String& dst_path, const struct stat& src_stat, Core::File&
if (errno != EISDIR) {
return false;
}
auto dst_dir_path = String::format("%s/%s", dst_path.characters(), LexicalPath(source.filename()).basename().characters());
auto dst_dir_path = String::formatted("{}/{}", dst_path, LexicalPath(source.filename()).basename());
dst_fd = creat(dst_dir_path.characters(), 0666);
if (dst_fd < 0) {
return false;
@ -244,17 +244,17 @@ String get_duplicate_name(const String& path, int duplicate_count)
StringBuilder duplicated_name;
duplicated_name.append('/');
for (size_t i = 0; i < lexical_path.parts().size() - 1; ++i) {
duplicated_name.appendf("%s/", lexical_path.parts()[i].characters());
duplicated_name.appendff("{}/", lexical_path.parts()[i]);
}
auto prev_duplicate_tag = String::format("(%d)", duplicate_count);
auto prev_duplicate_tag = String::formatted("({})", duplicate_count);
auto title = lexical_path.title();
if (title.ends_with(prev_duplicate_tag)) {
// remove the previous duplicate tag "(n)" so we can add a new tag.
title = title.substring(0, title.length() - prev_duplicate_tag.length());
}
duplicated_name.appendf("%s (%d)", lexical_path.title().characters(), duplicate_count);
duplicated_name.appendff("{} ({})", lexical_path.title(), duplicate_count);
if (!lexical_path.extension().is_empty()) {
duplicated_name.appendf(".%s", lexical_path.extension().characters());
duplicated_name.appendff(".{}", lexical_path.extension());
}
return duplicated_name.build();
}