Browse Source

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

Andreas Kling 4 năm trước cách đây
mục cha
commit
c71807a3fc

+ 1 - 1
Userland/Applications/FileManager/DirectoryView.cpp

@@ -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);
     }
 }

+ 1 - 1
Userland/Applications/SystemMonitor/DevicesModel.cpp

@@ -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();

+ 2 - 2
Userland/Applications/SystemMonitor/main.cpp

@@ -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))) {

+ 1 - 1
Userland/Demos/Fire/Fire.cpp

@@ -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;
     }
 

+ 1 - 1
Userland/DevTools/Inspector/RemoteProcess.cpp

@@ -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);

+ 1 - 1
Userland/DevTools/UserspaceEmulator/MmapRegion.cpp

@@ -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());

+ 1 - 1
Userland/Games/Minesweeper/Field.cpp

@@ -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();

+ 1 - 1
Userland/Games/Pong/Game.cpp

@@ -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)

+ 1 - 1
Userland/MenuApplets/Audio/main.cpp

@@ -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());
         }
     }

+ 1 - 1
Userland/Services/LookupServer/LookupServer.cpp

@@ -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");

+ 1 - 1
Userland/Services/SystemMenu/main.cpp

@@ -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; });

+ 1 - 1
Userland/Services/SystemServer/Service.cpp

@@ -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");
 

+ 1 - 1
Userland/Services/WindowServer/Compositor.cpp

@@ -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());

+ 1 - 1
Userland/Services/WindowServer/main.cpp

@@ -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);

+ 1 - 1
Userland/Utilities/checksum.cpp

@@ -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;
 

+ 1 - 1
Userland/Utilities/disk_benchmark.cpp

@@ -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) {

+ 1 - 1
Userland/Utilities/gunzip.cpp

@@ -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);

+ 1 - 1
Userland/Utilities/lsof.cpp

@@ -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>();

+ 1 - 1
Userland/Utilities/man.cpp

@@ -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[] = {

+ 1 - 1
Userland/Utilities/mount.cpp

@@ -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());
     }

+ 1 - 1
Userland/Utilities/mv.cpp

@@ -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();
         }
 

+ 1 - 1
Userland/Utilities/pmap.cpp

@@ -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;

+ 1 - 1
Userland/Utilities/pro.cpp

@@ -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));
             }