1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 09:24:57 +00:00

Everywhere: Convert a handful of String::format() => formatted()

This commit is contained in:
Andreas Kling 2021-01-16 12:00:33 +01:00
parent c90b7881a7
commit c71807a3fc
23 changed files with 24 additions and 24 deletions

View file

@ -120,7 +120,7 @@ void DirectoryView::handle_activation(const GUI::ModelIndex& index)
if (default_launcher) {
launch(url, *default_launcher);
} else {
auto error_message = String::format("Could not open %s", path.characters());
auto error_message = String::formatted("Could not open {}", path);
GUI::MessageBox::show(window(), error_message, "File Manager", GUI::MessageBox::Type::Error);
}
}

View file

@ -172,7 +172,7 @@ void DevicesModel::update()
Core::DirIterator dir_iter { dir, Core::DirIterator::Flags::SkipDots };
while (dir_iter.has_next()) {
auto name = dir_iter.next_path();
auto path = String::format("%s/%s", dir.characters(), name.characters());
auto path = String::formatted("{}/{}", dir, name);
struct stat statbuf;
if (lstat(path.characters(), &statbuf) != 0) {
ASSERT_NOT_REACHED();

View file

@ -245,7 +245,7 @@ int main(int argc, char** argv)
Gfx::Bitmap::load_from_file("/res/icons/16x16/app-profiler.png"), [&](auto&) {
pid_t pid = selected_id(ProcessModel::Column::PID);
if (pid != -1) {
auto pid_string = String::format("%d", pid);
auto pid_string = String::number(pid);
pid_t child;
const char* argv[] = { "/bin/Profiler", "--pid", pid_string.characters(), nullptr };
if ((errno = posix_spawn(&child, "/bin/Profiler", nullptr, nullptr, const_cast<char**>(argv), environ))) {
@ -261,7 +261,7 @@ int main(int argc, char** argv)
Gfx::Bitmap::load_from_file("/res/icons/16x16/app-inspector.png"), [&](auto&) {
pid_t pid = selected_id(ProcessModel::Column::PID);
if (pid != -1) {
auto pid_string = String::format("%d", pid);
auto pid_string = String::number(pid);
pid_t child;
const char* argv[] = { "/bin/Inspector", pid_string.characters(), nullptr };
if ((errno = posix_spawn(&child, "/bin/Inspector", nullptr, nullptr, const_cast<char**>(argv), environ))) {

View file

@ -172,7 +172,7 @@ void Fire::timer_event(Core::TimerEvent&)
if ((cycles % 50) == 0) {
dbgln("{} total cycles. finished 50 in {} ms, avg {} ms", cycles, timeAvg, timeAvg / 50);
stats->set_text(String::format("%d ms", timeAvg / 50));
stats->set_text(String::formatted("{} ms", timeAvg / 50));
timeAvg = 0;
}

View file

@ -191,7 +191,7 @@ void RemoteProcess::update()
}
};
auto success = m_socket->connect(Core::SocketAddress::local(String::format("/tmp/rpc/%d", m_pid)));
auto success = m_socket->connect(Core::SocketAddress::local(String::formatted("/tmp/rpc/{}", m_pid)));
if (!success) {
warnln("Couldn't connect to PID {}", m_pid);
exit(1);

View file

@ -44,7 +44,7 @@ NonnullOwnPtr<MmapRegion> MmapRegion::create_file_backed(u32 base, u32 size, u32
auto region = adopt_own(*new MmapRegion(base, size, prot));
region->m_file_backed = true;
if (!name.is_empty()) {
name = String::format("%s (Emulated)", name.characters());
name = String::formatted("{} (Emulated)", name);
region->m_name = name;
}
region->m_data = (u8*)mmap_with_name(nullptr, size, prot, flags, fd, offset, name.is_empty() ? nullptr : name.characters());

View file

@ -142,7 +142,7 @@ Field::Field(GUI::Label& flag_label, GUI::Label& time_label, GUI::Button& face_b
m_good_face_bitmap = Gfx::Bitmap::load_from_file("/res/icons/minesweeper/face-good.png");
m_bad_face_bitmap = Gfx::Bitmap::load_from_file("/res/icons/minesweeper/face-bad.png");
for (int i = 0; i < 8; ++i)
m_number_bitmap[i] = Gfx::Bitmap::load_from_file(String::format("/res/icons/minesweeper/%u.png", i + 1));
m_number_bitmap[i] = Gfx::Bitmap::load_from_file(String::formatted("/res/icons/minesweeper/{}.png", i + 1));
set_fill_with_background_color(true);
reset();

View file

@ -136,7 +136,7 @@ void Game::reset_ball(int serve_to_player)
void Game::game_over(int winner)
{
GUI::MessageBox::show(window(), String::format("Player %d wins!", winner), "Pong", GUI::MessageBox::Type::Warning, GUI::MessageBox::InputType::OK);
GUI::MessageBox::show(window(), String::formatted("Player {} wins!", winner), "Pong", GUI::MessageBox::Type::Warning, GUI::MessageBox::InputType::OK);
}
void Game::round_over(int winner)

View file

@ -161,7 +161,7 @@ private:
painter.blit({}, audio_bitmap, audio_bitmap.rect());
if (m_show_percent) {
auto volume_text = m_audio_muted ? "mute" : String::format("%d%%", m_audio_volume);
auto volume_text = m_audio_muted ? "mute" : String::formatted("{}%", m_audio_volume);
painter.draw_text({ 16, 3, 24, 16 }, volume_text, Gfx::FontDatabase::default_fixed_width_font(), Gfx::TextAlignment::TopLeft, palette().window_text());
}
}

View file

@ -160,7 +160,7 @@ void LookupServer::service_client(RefPtr<Core::LocalSocket> socket)
return;
}
for (auto& response : responses) {
auto line = String::format("%s\n", response.characters());
auto line = String::formatted("{}\n", response);
int nsent = socket->write(line);
if (nsent < 0) {
perror("write");

View file

@ -176,7 +176,7 @@ NonnullRefPtr<GUI::Menu> build_system_menu()
Core::DirIterator dt("/res/themes", Core::DirIterator::SkipDots);
while (dt.has_next()) {
auto theme_name = dt.next_path();
auto theme_path = String::format("/res/themes/%s", theme_name.characters());
auto theme_path = String::formatted("/res/themes/{}", theme_name);
g_themes.append({ LexicalPath(theme_name).title(), theme_path });
}
quick_sort(g_themes, [](auto& a, auto& b) { return a.name < b.name; });

View file

@ -276,7 +276,7 @@ Service::Service(const Core::ConfigFile& config, const StringView& name)
ASSERT(config.has_group(name));
set_name(name);
m_executable_path = config.read_entry(name, "Executable", String::format("/bin/%s", this->name().characters()));
m_executable_path = config.read_entry(name, "Executable", String::formatted("/bin/{}", this->name()));
m_extra_arguments = config.read_entry(name, "Arguments", "").split(' ');
m_stdio_file_path = config.read_entry(name, "StdIO");

View file

@ -761,7 +761,7 @@ bool Compositor::draw_geometry_label(Gfx::IntRect& geometry_label_damage_rect)
if (!window_being_moved_or_resized->size_increment().is_null()) {
int width_steps = (window_being_moved_or_resized->width() - window_being_moved_or_resized->base_size().width()) / window_being_moved_or_resized->size_increment().width();
int height_steps = (window_being_moved_or_resized->height() - window_being_moved_or_resized->base_size().height()) / window_being_moved_or_resized->size_increment().height();
geometry_string = String::format("%s (%dx%d)", geometry_string.characters(), width_steps, height_steps);
geometry_string = String::formatted("{} ({}x{})", geometry_string, width_steps, height_steps);
}
auto geometry_label_rect = Gfx::IntRect { 0, 0, wm.font().width(geometry_string) + 16, wm.font().glyph_height() + 10 };
geometry_label_rect.center_within(window_being_moved_or_resized->rect());

View file

@ -77,7 +77,7 @@ int main(int, char**)
auto wm_config = Core::ConfigFile::open("/etc/WindowServer/WindowServer.ini");
auto theme_name = wm_config->read_entry("Theme", "Name", "Default");
auto theme = Gfx::load_system_theme(String::format("/res/themes/%s.ini", theme_name.characters()));
auto theme = Gfx::load_system_theme(String::formatted("/res/themes/{}.ini", theme_name));
ASSERT(theme);
Gfx::set_system_theme(*theme);
auto palette = Gfx::PaletteImpl::create_with_shared_buffer(*theme);

View file

@ -55,7 +55,7 @@ int main(int argc, char** argv)
}
auto hash_name = program_name.substring_view(0, program_name.length() - 3).to_string().to_uppercase();
auto paths_help_string = String::format("File(s) to print %s checksum of", hash_name.characters());
auto paths_help_string = String::formatted("File(s) to print {} checksum of", hash_name);
Vector<const char*> paths;

View file

@ -108,7 +108,7 @@ int main(int argc, char** argv)
umask(0644);
auto filename = String::format("%s/disk_benchmark.tmp", directory);
auto filename = String::formatted("{}/disk_benchmark.tmp", directory);
for (auto file_size : file_sizes) {
for (auto block_size : block_sizes) {

View file

@ -57,7 +57,7 @@ int main(int argc, char** argv)
for (String filename : filenames) {
if (!filename.ends_with(".gz"))
filename = String::format("%s.gz", filename.characters());
filename = String::formatted("{}.gz", filename);
const auto input_filename = filename;
const auto output_filename = filename.substring_view(0, filename.length() - 3);

View file

@ -84,7 +84,7 @@ static bool parse_name(StringView name, OpenFile& file)
static Vector<OpenFile> get_open_files_by_pid(pid_t pid)
{
auto file = Core::File::open(String::format("/proc/%d/fds", pid), Core::IODevice::OpenMode::ReadOnly);
auto file = Core::File::open(String::formatted("/proc/{}/fds", pid), Core::IODevice::OpenMode::ReadOnly);
if (file.is_error()) {
printf("lsof: PID %d: %s\n", pid, file.error().characters());
return Vector<OpenFile>();

View file

@ -68,7 +68,7 @@ int main(int argc, char* argv[])
args_parser.parse(argc, argv);
auto make_path = [name](const char* section) {
return String::format("/usr/share/man/man%s/%s.md", section, name);
return String::formatted("/usr/share/man/man{}/{}.md", section, name);
};
if (!section) {
const char* sections[] = {

View file

@ -75,7 +75,7 @@ static int get_source_fd(const char* source)
fd = open(source, O_RDONLY);
if (fd < 0) {
int saved_errno = errno;
auto message = String::format("Failed to open: %s\n", source);
auto message = String::formatted("Failed to open: {}\n", source);
errno = saved_errno;
perror(message.characters());
}

View file

@ -76,7 +76,7 @@ int main(int argc, char** argv)
const char* new_path = original_new_path;
if (rc == 0 && S_ISDIR(st.st_mode)) {
auto old_basename = LexicalPath(old_path).basename();
combined_new_path = String::format("%s/%s", original_new_path, old_basename.characters());
combined_new_path = String::formatted("{}/{}", original_new_path, old_basename);
new_path = combined_new_path.characters();
}

View file

@ -53,7 +53,7 @@ int main(int argc, char** argv)
args_parser.add_positional_argument(pid, "PID", "PID", Core::ArgsParser::Required::Yes);
args_parser.parse(argc, argv);
auto file = Core::File::construct(String::format("/proc/%s/vm", pid));
auto file = Core::File::construct(String::formatted("/proc/{}/vm", pid));
if (!file->open(Core::IODevice::ReadOnly)) {
fprintf(stderr, "Error: %s\n", file->error_string());
return 1;

View file

@ -265,7 +265,7 @@ int main(int argc, char** argv)
do {
output_name = url.host();
if (i > -1)
output_name = String::format("%s.%d", output_name.characters(), i);
output_name = String::formatted("{}.{}", output_name, i);
++i;
} while (Core::File::exists(output_name));
}